about summary refs log tree commit diff
path: root/src/game/editor
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2008-01-12 17:09:00 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2008-01-12 17:09:00 +0000
commit906ece7894927983b8ac69e37dd3cb82cfe7aad1 (patch)
treec3e83b60f04c5f26975106d807ad5185d20827be /src/game/editor
parent99f0a47d6b03b005d0a7dae064cb6eb7cb4f60b5 (diff)
downloadzcatch-906ece7894927983b8ac69e37dd3cb82cfe7aad1.tar.gz
zcatch-906ece7894927983b8ac69e37dd3cb82cfe7aad1.zip
continued the cleanup
Diffstat (limited to 'src/game/editor')
-rw-r--r--src/game/editor/ed_editor.cpp (renamed from src/game/editor/editor.cpp)72
-rw-r--r--src/game/editor/ed_editor.hpp (renamed from src/game/editor/editor.hpp)101
-rw-r--r--src/game/editor/ed_layer_game.cpp2
-rw-r--r--src/game/editor/ed_layer_quads.cpp86
-rw-r--r--src/game/editor/ed_layer_tiles.cpp82
5 files changed, 16 insertions, 327 deletions
diff --git a/src/game/editor/editor.cpp b/src/game/editor/ed_editor.cpp
index 5a9ebf45..8c6c0c73 100644
--- a/src/game/editor/editor.cpp
+++ b/src/game/editor/ed_editor.cpp
@@ -1,3 +1,5 @@
+/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -15,8 +17,9 @@ extern "C" {
 //#include "game/mapres_col.h"
 #include <game/g_mapres.h>
 #include <game/g_game.h>
+#include <game/client/gc_render.h>
 
-#include "editor.hpp"
+#include "ed_editor.hpp"
 
 static int checker_texture = 0;
 static int background_texture = 0;
@@ -116,9 +119,6 @@ int LAYERGROUP::swap_layers(int index0, int index1)
 /********************************************************
  OTHER
 *********************************************************/
-extern void draw_round_rect_ext(float x, float y, float w, float h, float r, int corners);
-extern void draw_round_rect(float x, float y, float w, float h, float r);
-
 static void ui_draw_rect(const RECT *r, vec4 color, int corners, float rounding)
 {
 	gfx_texture_set(-1);
@@ -1961,67 +1961,6 @@ void EDITOR::make_game_group(LAYERGROUP *group)
 	editor.game_group->name = "Game";
 }
 
-typedef struct 
-{
-	int version;
-	int width;
-	int height;
-	int external;
-	int image_name;
-	int image_data;
-} MAPITEM_IMAGE;
-
-typedef struct
-{
-	int version;
-	int offset_x;
-	int offset_y;
-	int parallax_x;
-	int parallax_y;
-
-	int start_layer;
-	int num_layers;
-} MAPITEM_GROUP;
-
-typedef struct
-{
-	int version;
-	int type;
-	int flags;
-} MAPITEM_LAYER;
-
-typedef struct
-{
-	MAPITEM_LAYER layer;
-	int version;
-	
-	int width;
-	int height;
-	int flags;
-	
-	COLOR color;
-	int color_env;
-	int color_env_offset;
-	
-	int image;
-	int data;
-} MAPITEM_LAYER_TILEMAP;
-
-typedef struct
-{
-	MAPITEM_LAYER layer;
-	int version;
-	
-	int num_quads;
-	int data;
-	int image;
-} MAPITEM_LAYER_QUADS;
-
-typedef struct
-{
-	int version;
-} MAPITEM_VERSION;
-
 template<typename T>
 static int make_version(int i, const T &v)
 { return (i<<16)+sizeof(T); }
@@ -2411,6 +2350,7 @@ extern "C" void editor_init()
 	editor.show_envelope_editor = 1;
 #endif
 
+/*
 	if(1)
 	{
 		float w, h;
@@ -2426,7 +2366,7 @@ extern "C" void editor_init()
 		calc_screen_params(amount, max, max, 9.0f/16.0f, &w, &h); dbg_msg("", "%f %f %f", w, h, w*h);
 		calc_screen_params(amount, max, max, 16.0f/3.0f, &w, &h); dbg_msg("", "%f %f %f", w, h, w*h);
 		calc_screen_params(amount, max, max, 3.0f/16.0f, &w, &h); dbg_msg("", "%f %f %f", w, h, w*h);
-	}
+	}*/
 }
 
 extern "C" void editor_update_and_render()
diff --git a/src/game/editor/editor.hpp b/src/game/editor/ed_editor.hpp
index 0d2af5e1..15ba1dad 100644
--- a/src/game/editor/editor.hpp
+++ b/src/game/editor/ed_editor.hpp
@@ -1,6 +1,9 @@
+/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
+
 #include <stdlib.h>
 #include <math.h>
 #include "array.h"
+#include "../g_mapitems.h"
 
 extern "C" {
 	#include <engine/e_system.h>
@@ -28,40 +31,8 @@ enum
 	
 	DIALOG_NONE=0,
 	DIALOG_LOAD_IMAGE,
-	
-	LAYERTYPE_INVALID=0,
-	LAYERTYPE_GAME,
-	LAYERTYPE_TILES,
-	LAYERTYPE_QUADS,
 };
 
-typedef struct
-{
-	int x, y; // 22.10 fixed point
-} POINT;
-
-// float to fixed
-inline int f2fx(float v) { return (int)(v*(float)(1<<10)); }
-inline float fx2f(int v) { return v*(1.0f/(1<<10)); }
-
-typedef struct // as in file
-{
-	int r, g, b, a;
-} COLOR;
-
-typedef struct // as in file
-{
-	POINT points[5];
-	COLOR colors[4];
-	POINT texcoords[4];
-	
-	int pos_env;
-	int pos_env_offset;
-	
-	int color_env;
-	int color_env_offset;
-} QUAD;
-
 typedef struct // as in file
 {
 	POINT position;
@@ -70,36 +41,6 @@ typedef struct // as in file
 
 enum
 {
-	ENTITY_NULL=0,
-	ENTITY_SPAWN,
-	ENTITY_SPAWN_RED,
-	ENTITY_SPAWN_BLUE,
-	ENTITY_FLAGSTAND_RED,
-	ENTITY_FLAGSTAND_BLUE,
-	ENTITY_ARMOR_1,
-	ENTITY_HEATH_1,
-	ENTITY_WEAPON_SHOTGUN,
-	ENTITY_WEAPON_ROCKET,
-	ENTITY_POWERUP_NINJA,
-	NUM_ENTITIES,
-	
-	TILE_AIR=0,
-	TILE_SOLID,
-	TILE_NOHOOK,
-	
-	ENTITY_OFFSET=255-16*4,
-};
-
-typedef struct // as in file
-{
-	unsigned char index;
-	unsigned char flags;
-	unsigned char reserved1;
-	unsigned char reserved2;
-} TILE;
-
-enum
-{
 	CURVETYPE_STEP=0,
 	CURVETYPE_LINEAR,
 	CURVETYPE_SLOW,
@@ -531,39 +472,3 @@ public:
 
 	virtual void render_properties(RECT *toolbox);
 };
-
-
-inline void calc_screen_params(float amount, float wmax, float hmax, float aspect, float *w, float *h)
-{
-	float f = sqrt(amount) / sqrt(aspect);
-	*w = f*aspect;
-	*h = f;
-	
-	// limit the view
-	if(*w > wmax)
-	{
-		*w = wmax;
-		*h = *w/aspect;
-	}
-	
-	if(*h > hmax)
-	{
-		*h = hmax;
-		*w = *h*aspect;
-	}
-}
-
-inline void mapscreen_to_world(float center_x, float center_y, float parallax_x, float parallax_y,
-	float offset_x, float offset_y, float aspect, float zoom, float *points)
-{
-	float width, height;
-	calc_screen_params(1300*1000, 1500, 1050, aspect, &width, &height);
-	center_x *= parallax_x;
-	center_y *= parallax_y;
-	width *= zoom;
-	height *= zoom;
-	points[0] = offset_x+center_x-width/2;
-	points[1] = offset_y+center_y-height/2;
-	points[2] = offset_x+center_x+width/2;
-	points[3] = offset_y+center_y+height/2;
-}
diff --git a/src/game/editor/ed_layer_game.cpp b/src/game/editor/ed_layer_game.cpp
index 0e002559..4524cb80 100644
--- a/src/game/editor/ed_layer_game.cpp
+++ b/src/game/editor/ed_layer_game.cpp
@@ -1,5 +1,5 @@
 #include <game/client/gc_mapres_tilemap.h>
-#include "editor.hpp"
+#include "ed_editor.hpp"
 
 
 LAYER_GAME::LAYER_GAME(int w, int h)
diff --git a/src/game/editor/ed_layer_quads.cpp b/src/game/editor/ed_layer_quads.cpp
index d58a9e0f..5625876c 100644
--- a/src/game/editor/ed_layer_quads.cpp
+++ b/src/game/editor/ed_layer_quads.cpp
@@ -1,5 +1,7 @@
-#include "editor.hpp"
+#include "ed_editor.hpp"
 #include <game/g_math.h>
+#include <game/generated/gc_data.h>
+#include <game/client/gc_render.h>
 
 LAYER_QUADS::LAYER_QUADS()
 {
@@ -12,88 +14,6 @@ LAYER_QUADS::~LAYER_QUADS()
 {
 }
 
-static void rotate(POINT *center, POINT *point, float rotation)
-{
-	int x = point->x - center->x;
-	int y = point->y - center->y;
-	point->x = (int)(x * cosf(rotation) - y * sinf(rotation) + center->x);
-	point->y = (int)(x * sinf(rotation) + y * cosf(rotation) + center->y);
-}
-
-static void render_quads(QUAD *quads, int num_quads)
-{
-	gfx_quads_begin();
-	float conv = 1/255.0f;
-	for(int i = 0; i < num_quads; i++)
-	{
-		QUAD *q = &quads[i];
-		
-		gfx_quads_setsubset_free(
-			fx2f(q->texcoords[0].x), fx2f(q->texcoords[0].y),
-			fx2f(q->texcoords[1].x), fx2f(q->texcoords[1].y),
-			fx2f(q->texcoords[2].x), fx2f(q->texcoords[2].y),
-			fx2f(q->texcoords[3].x), fx2f(q->texcoords[3].y)
-		);
-
-		float r=1, g=1, b=1, a=1;
-		float offset_x = 0;
-		float offset_y = 0;
-		float rot = 0;
-		
-		if(editor.animate)
-		{
-			if(q->pos_env >= 0 && q->pos_env < editor.map.envelopes.len())
-			{
-				ENVELOPE *e = editor.map.envelopes[q->pos_env];
-				float t = editor.animate_time+q->pos_env_offset/1000.0f;
-				offset_x = e->eval(t, 0);
-				offset_y = e->eval(t, 1);
-				rot = e->eval(t, 2);
-			}
-			
-			if(q->color_env >= 0 && q->color_env < editor.map.envelopes.len())
-			{
-				ENVELOPE *e = editor.map.envelopes[q->color_env];
-				float t = editor.animate_time+q->color_env_offset/1000.0f;
-				r = e->eval(t, 0);
-				g = e->eval(t, 1);
-				b = e->eval(t, 2);
-				a = e->eval(t, 3);
-			}
-		}
-		
-		gfx_setcolorvertex(0, q->colors[0].r*conv*r, q->colors[0].g*conv*g, q->colors[0].b*conv*b, q->colors[0].a*conv*a);
-		gfx_setcolorvertex(1, q->colors[1].r*conv*r, q->colors[1].g*conv*g, q->colors[1].b*conv*b, q->colors[1].a*conv*a);
-		gfx_setcolorvertex(2, q->colors[2].r*conv*r, q->colors[2].g*conv*g, q->colors[2].b*conv*b, q->colors[2].a*conv*a);
-		gfx_setcolorvertex(3, q->colors[3].r*conv*r, q->colors[3].g*conv*g, q->colors[3].b*conv*b, q->colors[3].a*conv*a);
-
-		POINT *points = q->points;
-	
-		if(rot != 0)
-		{
-			static POINT rotated[4];
-			rotated[0] = q->points[0];
-			rotated[1] = q->points[1];
-			rotated[2] = q->points[2];
-			rotated[3] = q->points[3];
-			points = rotated;
-			
-			rotate(&q->points[4], &rotated[0], rot);
-			rotate(&q->points[4], &rotated[1], rot);
-			rotate(&q->points[4], &rotated[2], rot);
-			rotate(&q->points[4], &rotated[3], rot);
-		}
-		
-		gfx_quads_draw_freeform(
-			fx2f(points[0].x)+offset_x, fx2f(points[0].y)+offset_y,
-			fx2f(points[1].x)+offset_x, fx2f(points[1].y)+offset_y,
-			fx2f(points[2].x)+offset_x, fx2f(points[2].y)+offset_y,
-			fx2f(points[3].x)+offset_x, fx2f(points[3].y)+offset_y
-		);
-	}
-	gfx_quads_end();	
-}
-
 void LAYER_QUADS::render()
 {
 	gfx_texture_set(-1);
diff --git a/src/game/editor/ed_layer_tiles.cpp b/src/game/editor/ed_layer_tiles.cpp
index f697e56e..583426e3 100644
--- a/src/game/editor/ed_layer_tiles.cpp
+++ b/src/game/editor/ed_layer_tiles.cpp
@@ -1,84 +1,8 @@
 #include <game/client/gc_mapres_tilemap.h>
 #include <game/g_math.h>
-#include "editor.hpp"
-
-static void render_tilemap(TILE *tiles, int w, int h, float scale)
-{
-			//gfx_texture_set(img_get(tmap->image));
-	float screen_x0, screen_y0, screen_x1, screen_y1;
-	gfx_getscreen(&screen_x0, &screen_y0, &screen_x1, &screen_y1);
-
-	// calculate the final pixelsize for the tiles	
-	float tile_pixelsize = 1024/32.0f;
-	float final_tilesize = scale/(screen_x1-screen_x0) * gfx_screenwidth();
-	float final_tilesize_scale = final_tilesize/tile_pixelsize;
-	
-	gfx_quads_begin();
-	
-	int starty = (int)(screen_y0/scale)-1;
-	int startx = (int)(screen_x0/scale)-1;
-	int endy = (int)(screen_y1/scale)+1;
-	int endx = (int)(screen_x1/scale)+1;
-	
-	// adjust the texture shift according to mipmap level
-	float texsize = 1024.0f;
-	float frac = (1.25f/texsize) * (1/final_tilesize_scale);
-	float nudge = (0.5f/texsize) * (1/final_tilesize_scale);
-
-	for(int y = starty; y < endy; y++)
-		for(int x = startx; x < endx; x++)
-		{
-			int mx = x;
-			int my = y;
-			if(mx<0)
-				continue; // mx = 0;
-			if(mx>=w)
-				continue; // mx = w-1;
-			if(my<0)
-				continue; // my = 0;
-			if(my>=h)
-				continue; // my = h-1;
-			
-			int c = mx + my*w;
-				
-			unsigned char index = tiles[c].index;
-			if(index)
-			{
-				unsigned char flags = tiles[c].flags;
-				int tx = index%16;
-				int ty = index/16;
-				int px0 = tx*(1024/16);
-				int py0 = ty*(1024/16);
-				int px1 = (tx+1)*(1024/16)-1;
-				int py1 = (ty+1)*(1024/16)-1;
-				
-				float u0 = nudge + px0/texsize+frac;
-				float v0 = nudge + py0/texsize+frac;
-				float u1 = nudge + px1/texsize-frac;
-				float v1 = nudge + py1/texsize-frac;
-				
-				if(flags&TILEFLAG_VFLIP)
-				{
-					float tmp = u0;
-					u0 = u1;
-					u1 = tmp;
-				}
-
-				if(flags&TILEFLAG_HFLIP)
-				{
-					float tmp = v0;
-					v0 = v1;
-					v1 = tmp;
-				}
-				
-				gfx_quads_setsubset(u0,v0,u1,v1);
-
-				gfx_quads_drawTL(x*scale, y*scale, scale, scale);
-			}
-		}
-	
-	gfx_quads_end();
-}
+#include <game/generated/gc_data.h>
+#include <game/client/gc_render.h>
+#include "ed_editor.hpp"
 
 LAYER_TILES::LAYER_TILES(int w, int h)
 {