about summary refs log tree commit diff
path: root/src/game/editor
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2008-03-29 11:44:03 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2008-03-29 11:44:03 +0000
commit7a3874745ca370a799d95b5f86e85fcc8eadefbb (patch)
tree16f1e28f2f499279496866a63cabf88e2f2ad6c4 /src/game/editor
parent171d6b1c206c0488b59d157bc266319bf4ab482b (diff)
downloadzcatch-7a3874745ca370a799d95b5f86e85fcc8eadefbb.tar.gz
zcatch-7a3874745ca370a799d95b5f86e85fcc8eadefbb.zip
fixed loads of graphical optimizations
Diffstat (limited to 'src/game/editor')
-rw-r--r--src/game/editor/ed_editor.cpp125
-rw-r--r--src/game/editor/ed_editor.hpp11
-rw-r--r--src/game/editor/ed_io.cpp27
-rw-r--r--src/game/editor/ed_layer_quads.cpp2
-rw-r--r--src/game/editor/ed_layer_tiles.cpp16
-rw-r--r--src/game/editor/ed_popups.cpp28
6 files changed, 177 insertions, 32 deletions
diff --git a/src/game/editor/ed_editor.cpp b/src/game/editor/ed_editor.cpp
index 1e9a0de9..7ae46f0b 100644
--- a/src/game/editor/ed_editor.cpp
+++ b/src/game/editor/ed_editor.cpp
@@ -37,6 +37,12 @@ LAYERGROUP::LAYERGROUP()
 	offset_y = 0;
 	parallax_x = 100;
 	parallax_y = 100;
+	
+	use_clipping = 0;
+	clip_x = 0;
+	clip_y = 0;
+	clip_w = 0;
+	clip_h = 0;
 }
 
 LAYERGROUP::~LAYERGROUP()
@@ -75,6 +81,19 @@ void LAYERGROUP::render()
 {
 	mapscreen();
 	
+	if(use_clipping)
+	{
+		float points[4];
+		editor.map.game_group->mapping(points);
+		float x0 = (clip_x - points[0]) / (points[2]-points[0]);
+		float y0 = (clip_y - points[1]) / (points[3]-points[1]);
+		float x1 = ((clip_x+clip_w) - points[0]) / (points[2]-points[0]);
+		float y1 = ((clip_y+clip_h) - points[1]) / (points[3]-points[1]);
+		
+		gfx_clip_enable((int)(x0*gfx_screenwidth()), (int)(y0*gfx_screenheight()),
+			(int)((x1-x0)*gfx_screenwidth()), (int)((y1-y0)*gfx_screenheight()));
+	}
+	
 	for(int i = 0; i < layers.len(); i++)
 	{
 		if(layers[i]->visible && layers[i] != editor.map.game_layer)
@@ -83,6 +102,8 @@ void LAYERGROUP::render()
 				layers[i]->render();
 		}
 	}
+	
+	gfx_clip_disable();
 }
 
 bool LAYERGROUP::is_empty() const { return layers.len() == 0; }
@@ -116,7 +137,37 @@ int LAYERGROUP::swap_layers(int index0, int index1)
 	if(index0 == index1) return index0;
 	swap(layers[index0], layers[index1]);
 	return index1;
-}	
+}
+
+void IMAGE::analyse_tileflags()
+{
+	mem_zero(tileflags, sizeof(tileflags));
+	
+	int tw = width/16; // tilesizes
+	int th = height/16;
+	unsigned char *pixeldata = (unsigned char *)data;
+	
+	int tile_id = 0;
+	for(int ty = 0; ty < 16; ty++)
+		for(int tx = 0; tx < 16; tx++, tile_id++)
+		{
+			bool opaque = true;
+			for(int x = 0; x < tw; x++)
+				for(int y = 0; y < th; y++)
+				{
+					int p = (ty*tw+y)*width + tx*tw+x;
+					if(pixeldata[p*4+3] < 250)
+					{
+						opaque = false;
+						break;
+					}
+				}
+				
+			if(opaque)
+				tileflags[tile_id] |= TILEFLAG_OPAQUE;
+		}
+	
+}
 
 /********************************************************
  OTHER
@@ -777,11 +828,7 @@ static void do_quad_point(QUAD *q, int quad_index, int v)
 
 static void do_map_editor(RECT view, RECT toolbar)
 {
-	// do the toolbar
-	if(editor.gui_active)
-		do_toolbar(toolbar);
-	
-	ui_clip_enable(&view);
+	//ui_clip_enable(&view);
 	
 	bool show_picker = inp_key_pressed(KEY_SPACE) != 0;
 
@@ -792,6 +839,7 @@ static void do_map_editor(RECT view, RECT toolbar)
 		{
 			if(editor.map.groups[g]->visible)
 				editor.map.groups[g]->render();
+			//ui_clip_enable(&view);
 		}
 		
 		// render the game above everything else
@@ -805,7 +853,7 @@ static void do_map_editor(RECT view, RECT toolbar)
 	static void *editor_id = (void *)&editor_id;
 	int inside = ui_mouse_inside(&view);
 
-	// fetch mouse position		
+	// fetch mouse position
 	float wx = ui_mouse_world_x();
 	float wy = ui_mouse_world_y();
 	float mx = ui_mouse_x();
@@ -1084,6 +1132,29 @@ static void do_map_editor(RECT view, RECT toolbar)
 			}
 		}
 	}
+	
+	if(editor.get_selected_group() && editor.get_selected_group()->use_clipping)
+	{
+		LAYERGROUP *g = editor.map.game_group;
+		g->mapscreen();
+		
+		gfx_texture_set(-1);
+		gfx_lines_begin();
+
+			RECT r;
+			r.x = editor.get_selected_group()->clip_x;
+			r.y = editor.get_selected_group()->clip_y;
+			r.w = editor.get_selected_group()->clip_w;
+			r.h = editor.get_selected_group()->clip_h;
+			
+			gfx_setcolor(1,0,0,1);
+			gfx_lines_draw(r.x, r.y, r.x+r.w, r.y);
+			gfx_lines_draw(r.x+r.w, r.y, r.x+r.w, r.y+r.h);
+			gfx_lines_draw(r.x+r.w, r.y+r.h, r.x, r.y+r.h);
+			gfx_lines_draw(r.x, r.y+r.h, r.x, r.y);
+			
+		gfx_lines_end();
+	}
 
 	// render screen sizes	
 	if(editor.proof_borders)
@@ -1161,7 +1232,7 @@ static void do_map_editor(RECT view, RECT toolbar)
 	}
 	
 	gfx_mapscreen(ui_screen()->x, ui_screen()->y, ui_screen()->w, ui_screen()->h);
-	ui_clip_disable();
+	//ui_clip_disable();
 }
 
 
@@ -1282,8 +1353,6 @@ static void render_layers(RECT toolbox, RECT toolbar, RECT view)
 {
 	RECT layersbox = toolbox;
 
-	do_map_editor(view, toolbar);
-	
 	if(!editor.gui_active)
 		return;
 			
@@ -1317,7 +1386,7 @@ static void render_layers(RECT toolbox, RECT toolbar, RECT view)
 				
 				static int group_popup_id = 0;
 				if(result == 2)
-					ui_invoke_popup_menu(&group_popup_id, 0, ui_mouse_x(), ui_mouse_y(), 120, 150, popup_group);
+					ui_invoke_popup_menu(&group_popup_id, 0, ui_mouse_x(), ui_mouse_y(), 120, 200, popup_group);
 			}
 			
 			
@@ -2163,12 +2232,27 @@ void EDITOR::render()
 		ui_hsplit_t(&view, 16.0f, &toolbar, &view);
 		ui_hsplit_b(&view, 16.0f, &view, &statusbar);
 
-				
+		if(editor.show_envelope_editor)
+		{
+			float size = 125.0f;
+			if(editor.show_envelope_editor == 2)
+				size *= 2.0f;
+			else if(editor.show_envelope_editor == 3)
+				size *= 3.0f;
+			ui_hsplit_b(&view, size, &view, &envelope_editor);
+		}
+	}
+	
+	//	a little hack for now
+	if(editor.mode == MODE_LAYERS)
+		do_map_editor(view, toolbar);
+	
+	if(editor.gui_active)
+	{
 		float brightness = 0.25f;
-
 		render_background(menubar, background_texture, 128.0f, brightness*0);
 		ui_margin(&menubar, 2.0f, &menubar);
-		
+
 		render_background(toolbox, background_texture, 128.0f, brightness);
 		ui_margin(&toolbox, 2.0f, &toolbox);
 		
@@ -2179,24 +2263,23 @@ void EDITOR::render()
 		render_background(statusbar, background_texture, 128.0f, brightness);
 		ui_margin(&statusbar, 2.0f, &statusbar);
 		
+		// do the toolbar
+		if(editor.mode == MODE_LAYERS)
+			do_toolbar(toolbar);
+		
 		if(editor.show_envelope_editor)
 		{
-			float size = 125.0f;
-			if(editor.show_envelope_editor == 2)
-				size *= 2.0f;
-			else if(editor.show_envelope_editor == 3)
-				size *= 3.0f;
-			ui_hsplit_b(&view, size, &view, &envelope_editor);
 			render_background(envelope_editor, background_texture, 128.0f, brightness);
 			ui_margin(&envelope_editor, 2.0f, &envelope_editor);
 		}
 	}
+		
 	
 	if(editor.mode == MODE_LAYERS)
 		render_layers(toolbox, toolbar, view);
 	else if(editor.mode == MODE_IMAGES)
 		render_images(toolbox, toolbar, view);
-		
+
 	gfx_mapscreen(ui_screen()->x, ui_screen()->y, ui_screen()->w, ui_screen()->h);
 
 	if(editor.gui_active)
diff --git a/src/game/editor/ed_editor.hpp b/src/game/editor/ed_editor.hpp
index e2fda9ef..23dbd382 100644
--- a/src/game/editor/ed_editor.hpp
+++ b/src/game/editor/ed_editor.hpp
@@ -177,6 +177,12 @@ public:
 	int parallax_x;
 	int parallax_y;
 	
+	int use_clipping;
+	int clip_x;
+	int clip_y;
+	int clip_w;
+	int clip_h;
+	
 	const char *name;
 	bool game_group;
 	bool visible;
@@ -230,9 +236,12 @@ public:
 		gfx_unload_texture(tex_id);
 	}
 	
+	void analyse_tileflags();
+	
 	int tex_id;
 	int external;
 	char name[128];
+	unsigned char tileflags[256];
 };
 
 class MAP
@@ -443,6 +452,8 @@ public:
 
 	virtual void modify_image_index(INDEX_MODIFY_FUNC func);
 	virtual void modify_envelope_index(INDEX_MODIFY_FUNC func);
+	
+	void prepare_for_save();
 
 	void get_size(float *w, float *h) { *w = width*32.0f;  *h = height*32.0f; }
 	
diff --git a/src/game/editor/ed_io.cpp b/src/game/editor/ed_io.cpp
index b805b0b5..3fd4fcac 100644
--- a/src/game/editor/ed_io.cpp
+++ b/src/game/editor/ed_io.cpp
@@ -214,6 +214,11 @@ int MAP::save(const char *filename)
 	for(int i = 0; i < images.len(); i++)
 	{
 		IMAGE *img = images[i];
+		
+		// analyse the image for when saving (should be done when we load the image)
+		// TODO!
+		img->analyse_tileflags();
+		
 		MAPITEM_IMAGE item;
 		item.version = 1;
 		
@@ -234,12 +239,17 @@ int MAP::save(const char *filename)
 	{
 		LAYERGROUP *group = groups[g];
 		MAPITEM_GROUP gitem;
-		gitem.version = 1;
+		gitem.version = MAPITEM_GROUP::CURRENT_VERSION;
 		
 		gitem.parallax_x = group->parallax_x;
 		gitem.parallax_y = group->parallax_y;
 		gitem.offset_x = group->offset_x;
 		gitem.offset_y = group->offset_y;
+		gitem.use_clipping = group->use_clipping;
+		gitem.clip_x = group->clip_x;
+		gitem.clip_y = group->clip_y;
+		gitem.clip_w = group->clip_w;
+		gitem.clip_h = group->clip_h;
 		gitem.start_layer = layer_count;
 		gitem.num_layers = 0;
 		
@@ -249,6 +259,8 @@ int MAP::save(const char *filename)
 			{
 				dbg_msg("editor", "saving tiles layer");
 				LAYER_TILES *layer = (LAYER_TILES *)group->layers[l];
+				layer->prepare_for_save();
+				
 				MAPITEM_LAYER_TILEMAP item;
 				item.version = 2;
 				
@@ -432,12 +444,25 @@ int MAP::load(const char *filename)
 			for(int g = 0; g < num; g++)
 			{
 				MAPITEM_GROUP *gitem = (MAPITEM_GROUP *)datafile_get_item(df, start+g, 0, 0);
+				
+				if(gitem->version < 1 || gitem->version > MAPITEM_GROUP::CURRENT_VERSION)
+					continue;
+				
 				LAYERGROUP *group = new_group();
 				group->parallax_x = gitem->parallax_x;
 				group->parallax_y = gitem->parallax_y;
 				group->offset_x = gitem->offset_x;
 				group->offset_y = gitem->offset_y;
 				
+				if(gitem->version >= 2)
+				{
+					group->use_clipping = gitem->use_clipping;
+					group->clip_x = gitem->clip_x;
+					group->clip_y = gitem->clip_y;
+					group->clip_w = gitem->clip_w;
+					group->clip_h = gitem->clip_h;
+				}
+				
 				for(int l = 0; l < gitem->num_layers; l++)
 				{
 					LAYER *layer = 0;
diff --git a/src/game/editor/ed_layer_quads.cpp b/src/game/editor/ed_layer_quads.cpp
index bf203ebb..f3df3818 100644
--- a/src/game/editor/ed_layer_quads.cpp
+++ b/src/game/editor/ed_layer_quads.cpp
@@ -36,7 +36,7 @@ void LAYER_QUADS::render()
 	if(image >= 0 && image < editor.map.images.len())
 		gfx_texture_set(editor.map.images[image]->tex_id);
 		
-	render_quads(quads.getptr(), quads.len(), envelope_eval);
+	render_quads(quads.getptr(), quads.len(), envelope_eval, LAYERRENDERFLAG_OPAQUE|LAYERRENDERFLAG_TRANSPARENT);
 }
 
 QUAD *LAYER_QUADS::new_quad()
diff --git a/src/game/editor/ed_layer_tiles.cpp b/src/game/editor/ed_layer_tiles.cpp
index 555c26a3..18e3b695 100644
--- a/src/game/editor/ed_layer_tiles.cpp
+++ b/src/game/editor/ed_layer_tiles.cpp
@@ -22,6 +22,20 @@ LAYER_TILES::~LAYER_TILES()
 	delete [] tiles;
 }
 
+void LAYER_TILES::prepare_for_save()
+{
+	for(int y = 0; y < height; y++)
+		for(int x = 0; x < width; x++)
+			tiles[y*width+x].flags &= TILEFLAG_VFLIP|TILEFLAG_HFLIP;
+
+	if(image != -1)
+	{
+		for(int y = 0; y < height; y++)
+			for(int x = 0; x < width; x++)
+				tiles[y*width+x].flags |= editor.map.images[image]->tileflags[tiles[y*width+x].index];
+	}
+}
+
 void LAYER_TILES::make_palette()
 {
 	for(int y = 0; y < height; y++)
@@ -34,7 +48,7 @@ void LAYER_TILES::render()
 	if(image >= 0 && image < editor.map.images.len())
 		tex_id = editor.map.images[image]->tex_id;
 	gfx_texture_set(tex_id);
-	render_tilemap(tiles, width, height, 32.0f, vec4(1,1,1,1), 0);
+	render_tilemap(tiles, width, height, 32.0f, vec4(1,1,1,1), LAYERRENDERFLAG_OPAQUE|LAYERRENDERFLAG_TRANSPARENT);
 }
 
 int LAYER_TILES::convert_x(float x) const { return (int)(x/32.0f); }
diff --git a/src/game/editor/ed_popups.cpp b/src/game/editor/ed_popups.cpp
index bcd26092..813dfd50 100644
--- a/src/game/editor/ed_popups.cpp
+++ b/src/game/editor/ed_popups.cpp
@@ -115,6 +115,11 @@ int popup_group(RECT view)
 		PROP_POS_Y,
 		PROP_PARA_X,
 		PROP_PARA_Y,
+		PROP_USE_CLIPPING,
+		PROP_CLIP_X,
+		PROP_CLIP_Y,
+		PROP_CLIP_W,
+		PROP_CLIP_H,
 		NUM_PROPS,
 	};
 	
@@ -124,6 +129,12 @@ int popup_group(RECT view)
 		{"Pos Y", -editor.map.groups[editor.selected_group]->offset_y, PROPTYPE_INT_SCROLL, -1000000, 1000000},
 		{"Para X", editor.map.groups[editor.selected_group]->parallax_x, PROPTYPE_INT_SCROLL, -1000000, 1000000},
 		{"Para Y", editor.map.groups[editor.selected_group]->parallax_y, PROPTYPE_INT_SCROLL, -1000000, 1000000},
+
+		{"Use Clipping", editor.map.groups[editor.selected_group]->use_clipping, PROPTYPE_BOOL, 0, 1},
+		{"Clip X", editor.map.groups[editor.selected_group]->clip_x, PROPTYPE_INT_SCROLL, -1000000, 1000000},
+		{"Clip Y", editor.map.groups[editor.selected_group]->clip_y, PROPTYPE_INT_SCROLL, -1000000, 1000000},
+		{"Clip W", editor.map.groups[editor.selected_group]->clip_w, PROPTYPE_INT_SCROLL, -1000000, 1000000},
+		{"Clip H", editor.map.groups[editor.selected_group]->clip_h, PROPTYPE_INT_SCROLL, -1000000, 1000000},
 		{0},
 	};
 	
@@ -141,14 +152,15 @@ int popup_group(RECT view)
 	// these can not be changed on the game group
 	if(!editor.get_selected_group()->game_group)
 	{
-		if(prop == PROP_PARA_X)
-			editor.map.groups[editor.selected_group]->parallax_x = new_val;
-		else if(prop == PROP_PARA_Y)
-			editor.map.groups[editor.selected_group]->parallax_y = new_val;
-		else if(prop == PROP_POS_X)
-			editor.map.groups[editor.selected_group]->offset_x = -new_val;
-		else if(prop == PROP_POS_Y)
-			editor.map.groups[editor.selected_group]->offset_y = -new_val;
+		if(prop == PROP_PARA_X) editor.map.groups[editor.selected_group]->parallax_x = new_val;
+		else if(prop == PROP_PARA_Y) editor.map.groups[editor.selected_group]->parallax_y = new_val;
+		else if(prop == PROP_POS_X) editor.map.groups[editor.selected_group]->offset_x = -new_val;
+		else if(prop == PROP_POS_Y) editor.map.groups[editor.selected_group]->offset_y = -new_val;
+		else if(prop == PROP_USE_CLIPPING) editor.map.groups[editor.selected_group]->use_clipping = new_val;
+		else if(prop == PROP_CLIP_X) editor.map.groups[editor.selected_group]->clip_x = new_val;
+		else if(prop == PROP_CLIP_Y) editor.map.groups[editor.selected_group]->clip_y = new_val;
+		else if(prop == PROP_CLIP_W) editor.map.groups[editor.selected_group]->clip_w = new_val;
+		else if(prop == PROP_CLIP_H) editor.map.groups[editor.selected_group]->clip_h = new_val;
 	}
 	
 	return 0;