about summary refs log tree commit diff
path: root/src/game/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/client')
-rw-r--r--src/game/client/gc_client.cpp181
-rw-r--r--src/game/client/gc_client.h1
-rw-r--r--src/game/client/gc_hooks.cpp11
-rw-r--r--src/game/client/gc_map_image.cpp (renamed from src/game/client/gc_mapres_image.cpp)15
-rw-r--r--src/game/client/gc_map_image.h (renamed from src/game/client/gc_mapres_image.h)9
-rw-r--r--src/game/client/gc_mapres_tilemap.cpp9
-rw-r--r--src/game/client/gc_menu.cpp3
-rw-r--r--src/game/client/gc_render.cpp149
-rw-r--r--src/game/client/gc_render.h4
-rw-r--r--src/game/client/gc_render_map.cpp33
10 files changed, 208 insertions, 207 deletions
diff --git a/src/game/client/gc_client.cpp b/src/game/client/gc_client.cpp
index 556fabee..d3e3009a 100644
--- a/src/game/client/gc_client.cpp
+++ b/src/game/client/gc_client.cpp
@@ -12,7 +12,8 @@ extern "C" {
 #include "../g_game.h"
 #include "../g_version.h"
 #include "../g_mapres.h"
-#include "gc_mapres_image.h"
+#include "../g_layers.h"
+#include "gc_map_image.h"
 #include "gc_mapres_tilemap.h"
 #include "../generated/gc_data.h"
 #include "gc_menu.h"
@@ -166,7 +167,17 @@ public:
 
 };
 
-static damage_indicators damageind;
+static damage_indicators dmgind;
+
+void effect_damage_indicator(vec2 pos, vec2 dir)
+{
+	dmgind.create(pos, dir);
+}
+
+void render_damage_indicators()
+{
+	dmgind.render();
+}
 
 class particle_system
 {
@@ -404,7 +415,7 @@ void process_events(int snaptype)
 		if(item.type == EVENT_DAMAGEINDICATION)
 		{
 			ev_damageind *ev = (ev_damageind *)data;
-			damageind.create(vec2(ev->x, ev->y), get_direction(ev->angle));
+			effect_damage_indicator(vec2(ev->x, ev->y), get_direction(ev->angle));
 		}
 		else if(item.type == EVENT_AIR_JUMP)
 		{
@@ -1106,163 +1117,6 @@ void render_scoreboard(float x, float y, float w, int team, const char *title)
 	}
 }
 
-void mapscreen_to_world(float center_x, float center_y, float zoom)
-{
-	//const float default_zoom = 1.5f;
-	float width = 300*3*zoom*gfx_screenaspect();
-	float height = 300*3*zoom;
-	gfx_mapscreen(center_x-width/2, center_y-height/2, center_x+width/2, center_y+height/2);
-}
-
-// renders the complete game world
-void render_world(float center_x, float center_y, float zoom)
-{
-	mapscreen_to_world(center_x, center_y, zoom);
-	//gfx_mapscreen(center_x-width/2, center_y-height/2, center_x+width/2, center_y+height/2);
-
-	// render background environment
-	int theme_id = 0;
-	mapres_theme *t = (mapres_theme *)map_find_item(MAPRES_TEMP_THEME, 0);
-	if(t)
-		theme_id = t->id;
-	
-	if(config.gfx_high_detail)
-	{
-		if(theme_id == 1)
-		{
-			// Winter night
-			gfx_mapscreen(0,0,1,1);
-			gfx_texture_set(-1);
-			gfx_quads_begin();
-				vec4 top(0x11/(float)0xff, 0x1a/(float)0xff, 0x21/(float)0xff, 1.0f);
-				vec4 bottom(0x2a/(float)0xff, 0x40/(float)0xff, 0x52/(float)0xff, 1.0f);
-				gfx_setcolorvertex(0, top.r, top.g, top.b, top.a);
-				gfx_setcolorvertex(1, top.r, top.g, top.b, top.a);
-				gfx_setcolorvertex(2, bottom.r, bottom.g, bottom.b, bottom.a);
-				gfx_setcolorvertex(3, bottom.r, bottom.g, bottom.b, bottom.a);
-				gfx_quads_drawTL(0, 0, 1, 1);
-			gfx_quads_end();
-
-			mapscreen_to_world(center_x*0.1f, center_y*0.1f, zoom);
-			render_stars();
-			
-			mapscreen_to_world(center_x, center_y, zoom);
-			
-			render_moon(center_x*0.8f, center_y*0.8f);
-			
-			mapscreen_to_world(center_x, center_y, zoom);
-		}
-		else
-		{
-			// Summer day
-			render_sun(20+center_x*0.6f, 20+center_y*0.6f);
-
-			// draw clouds
-			static vec2 cloud_pos[6] = {vec2(-500,0),vec2(-500,200),vec2(-500,400)};
-			static float cloud_speed[6] = {30, 20, 10};
-			static int cloud_sprites[6] = {SPRITE_CLOUD1, SPRITE_CLOUD2, SPRITE_CLOUD3};
-
-			gfx_texture_set(data->images[IMAGE_CLOUDS].id);
-			gfx_quads_begin();
-			for(int i = 0; i < 3; i++)
-			{
-				float parallax_amount = 0.55f;
-				select_sprite(cloud_sprites[i]);
-				draw_sprite((cloud_pos[i].x+fmod(client_localtime()*cloud_speed[i]+i*100.0f, 3000.0f))+center_x*parallax_amount,
-					cloud_pos[i].y+center_y*parallax_amount, 300);
-			}
-			gfx_quads_end();
-
-			// draw backdrop
-			gfx_texture_set(data->images[IMAGE_BACKDROP].id);
-			gfx_quads_begin();
-			float parallax_amount = 0.25f;
-			for(int x = -1; x < 3; x++)
-				gfx_quads_drawTL(1024*x+center_x*parallax_amount, (center_y)*parallax_amount+150+512, 1024, 512);
-			gfx_quads_end();
-		}
-	}
-	
-	// render background tilemaps
-	tilemap_render(32.0f, 0);
-
-	// render items
-	{
-		int num = snap_num_items(SNAP_CURRENT);
-		for(int i = 0; i < num; i++)
-		{
-			SNAP_ITEM item;
-			const void *data = snap_get_item(SNAP_CURRENT, i, &item);
-
-			if(item.type == OBJTYPE_PROJECTILE)
-			{
-				//const void *prev = snap_find_item(SNAP_PREV, item.type, item.id);
-				//if(prev)
-				render_projectile((const obj_projectile *)data, item.id);
-			}
-			else if(item.type == OBJTYPE_POWERUP)
-			{
-				const void *prev = snap_find_item(SNAP_PREV, item.type, item.id);
-				if(prev)
-					render_powerup((const obj_powerup *)prev, (const obj_powerup *)data);
-			}
-			else if(item.type == OBJTYPE_FLAG)
-			{
-				const void *prev = snap_find_item(SNAP_PREV, item.type, item.id);
-				if (prev)
-					render_flag((const obj_flag *)prev, (const obj_flag *)data);
-			}
-		}
-	}
-
-	// render players above all
-	{
-		int num = snap_num_items(SNAP_CURRENT);
-		for(int i = 0; i < num; i++)
-		{
-			SNAP_ITEM item;
-			const void *data = snap_get_item(SNAP_CURRENT, i, &item);
-
-			if(item.type == OBJTYPE_PLAYER_CHARACTER)
-			{
-				const void *prev = snap_find_item(SNAP_PREV, item.type, item.id);
-				const void *prev_info = snap_find_item(SNAP_PREV, OBJTYPE_PLAYER_INFO, item.id);
-				const void *info = snap_find_item(SNAP_CURRENT, OBJTYPE_PLAYER_INFO, item.id);
-
-				if(prev && prev_info && info)
-				{
-					render_player(
-							(const obj_player_character *)prev,
-							(const obj_player_character *)data,
-							(const obj_player_info *)prev_info,
-							(const obj_player_info *)info
-						);
-				}
-			}
-		}
-	}
-
-	// render particles
-	temp_system.update(client_frametime());
-	temp_system.render();
-
-	// render foreground tilemaps
-	tilemap_render(32.0f, 1);
-	
-	// render front environment effects
-	if(config.gfx_high_detail)
-	{
-		if(theme_id == 1)
-		{
-			//mapscreen_to_world(center_x, center_y, zoom);
-			render_snow();
-		}
-	}
-
-	// render damage indications
-	damageind.render();
-}
-
 static int do_input(int *v, int key)
 {
 	*v += inp_key_presses(key) + inp_key_releases(key);
@@ -1534,6 +1388,7 @@ void render_game()
 
 	// pseudo format
 	// ZOOM ZOOM
+	/*
 	float zoom = 3.0;
 
 	// DEBUG TESTING
@@ -1625,7 +1480,7 @@ void render_game()
 			p1f.x,p1f.y);
 
 		gfx_quads_end();
-	}
+	}*/
 
 	if(local_character && !spectate && !(gameobj && gameobj->game_over))
 	{
@@ -1993,8 +1848,8 @@ void render_game()
 			vec2(local_character->x, local_character->y));
 		
 		char buf[512];
-		sprintf(buf, "%f", speed);
-		gfx_text(0, 150, 50, 24, buf, -1);
+		sprintf(buf, "%.2f", speed);
+		gfx_text(0, 150, 50, 12, buf, -1);
 	}
 
 	// render score board
diff --git a/src/game/client/gc_client.h b/src/game/client/gc_client.h
index d34ccc78..f1ff02b1 100644
--- a/src/game/client/gc_client.h
+++ b/src/game/client/gc_client.h
@@ -91,3 +91,4 @@ void reset_projectile_particles();
 void send_info(bool start);
 
 void effect_air_jump(vec2 pos);
+void effect_damage_indicator(vec2 pos, vec2 dir);
diff --git a/src/game/client/gc_hooks.cpp b/src/game/client/gc_hooks.cpp
index febb6478..d0754c09 100644
--- a/src/game/client/gc_hooks.cpp
+++ b/src/game/client/gc_hooks.cpp
@@ -11,10 +11,12 @@ extern "C" {
 #include <game/g_game.h>
 #include <game/g_version.h>
 
+#include <game/g_layers.h>
+
 #include "gc_client.h"
 #include "gc_skin.h"
 #include "gc_render.h"
-#include "gc_mapres_image.h"
+#include "gc_map_image.h"
 #include "gc_mapres_tilemap.h"
 
 extern unsigned char internal_data[];
@@ -472,10 +474,11 @@ extern "C" void modc_message(int msg)
 extern "C" void modc_connected()
 {
 	// init some stuff
-	col_init(32);
-	
+	layers_init();
+	col_init();
 	img_init();
-	tilemap_init();
+	
+	//tilemap_init();
 	chat_reset();
 
 	reset_projectile_particles();
diff --git a/src/game/client/gc_mapres_image.cpp b/src/game/client/gc_map_image.cpp
index d8de8a1e..ab4d9aa7 100644
--- a/src/game/client/gc_mapres_image.cpp
+++ b/src/game/client/gc_map_image.cpp
@@ -1,8 +1,8 @@
 /* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
 #include <engine/e_system.h>
 #include <engine/e_interface.h>
-#include "gc_mapres_image.h"
-#include "../g_mapres.h"
+#include <game/g_mapitems.h>
+#include "gc_map_image.h"
 
 static int map_textures[64] = {0};
 static int count = 0;
@@ -83,14 +83,15 @@ static void calc_mipmaps(void *data_in, unsigned width, unsigned height, void *d
 		mip_h = mip_h>>1;
 	}
 }
-*/
 extern int DEBUGTEST_MAPIMAGE;
+*/
+
 
 int img_init()
 {
 	int start, count;
-	map_get_type(MAPRES_IMAGE, &start, &count);
-	dbg_msg("mapres_image", "start=%d count=%d", start, count);
+	map_get_type(MAPITEMTYPE_IMAGE, &start, &count);
+	dbg_msg("image", "start=%d count=%d", start, count);
 	for(int i = 0; i < 64; i++)
 	{
 		if(map_textures[i])
@@ -103,14 +104,12 @@ int img_init()
 	//void *data_res = (void*)mem_alloc(1024*1024*4*2, 16);
 	for(int i = 0; i < count; i++)
 	{
-		mapres_image *img = (mapres_image *)map_get_item(start+i, 0, 0);
+		MAPITEM_IMAGE *img = (MAPITEM_IMAGE *)map_get_item(start+i, 0, 0);
 		void *data = map_get_data(img->image_data);
-		//calc_mipmaps(data, img->width, img->height, data_res);
 		map_textures[i] = gfx_load_texture_raw(img->width, img->height, IMG_RGBA, data, IMG_RGBA);
 		map_unload_data(img->image_data);
 	}
 
-	//mem_free(data_res);
 	return count;
 }
 
diff --git a/src/game/client/gc_mapres_image.h b/src/game/client/gc_map_image.h
index f841ca53..d73f43d3 100644
--- a/src/game/client/gc_mapres_image.h
+++ b/src/game/client/gc_map_image.h
@@ -8,12 +8,3 @@ int img_num();
 
 // fetches the texture id for the image
 int img_get(int index);
-
-
-class mapres_image
-{
-public:
-	int width;
-	int height;
-	int image_data;
-};
diff --git a/src/game/client/gc_mapres_tilemap.cpp b/src/game/client/gc_mapres_tilemap.cpp
index 99976b64..239d2d92 100644
--- a/src/game/client/gc_mapres_tilemap.cpp
+++ b/src/game/client/gc_mapres_tilemap.cpp
@@ -1,4 +1,5 @@
 /* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
+/*
 #include <engine/e_interface.h>
 #include <engine/e_config.h>
 #include "gc_mapres_tilemap.h"
@@ -15,13 +16,6 @@ int tilemap_init()
 {
 	return 0;
 }
-/*
-struct render_info
-{
-	unsigned char *data;
-};
-
-void tilemap_render_one()*/
 
 void tilemap_render(float scale, int fg)
 {
@@ -113,3 +107,4 @@ void tilemap_render(float scale, int fg)
 		}
 	}
 }
+*/
diff --git a/src/game/client/gc_menu.cpp b/src/game/client/gc_menu.cpp
index e0c2a19f..cc9eaaea 100644
--- a/src/game/client/gc_menu.cpp
+++ b/src/game/client/gc_menu.cpp
@@ -18,9 +18,6 @@ extern "C" {
 #include "../g_version.h"
 #include "../g_protocol.h"
 
-#include "gc_mapres_image.h"
-#include "gc_mapres_tilemap.h"
-
 #include "../generated/gc_data.h"
 #include "gc_render.h"
 #include "gc_anim.h"
diff --git a/src/game/client/gc_render.cpp b/src/game/client/gc_render.cpp
index 9a4c35d5..9f55ec5f 100644
--- a/src/game/client/gc_render.cpp
+++ b/src/game/client/gc_render.cpp
@@ -2,12 +2,14 @@
 #include <math.h>
 #include <engine/e_interface.h>
 #include <engine/e_config.h>
-#include "../generated/gc_data.h"
-#include "../g_protocol.h"
-#include "../g_math.h"
+#include <game/generated/gc_data.h>
+#include <game/g_protocol.h>
+#include <game/g_math.h>
+#include <game/g_layers.h>
 #include "gc_render.h"
 #include "gc_anim.h"
 #include "gc_client.h"
+#include "gc_map_image.h"
 
 static float sprite_w_scale;
 static float sprite_h_scale;
@@ -235,3 +237,144 @@ void mapscreen_to_world(float center_x, float center_y, float parallax_x, float
 	points[2] = offset_x+center_x+width/2;
 	points[3] = offset_y+center_y+height/2;
 }
+
+static void mapscreen_to_group(float center_x, float center_y, MAPITEM_GROUP *group)
+{
+	float points[4];
+	mapscreen_to_world(center_x, center_y, group->parallax_x/100.0f, group->parallax_y/100.0f,
+		group->offset_x, group->offset_y, gfx_screenaspect(), 1.0f, points);
+	gfx_mapscreen(points[0], points[1], points[2], points[3]);
+}
+
+void render_layers(float center_x, float center_y, int pass)
+{
+	bool passed_gamelayer = false;
+	for(int g = 0; g < layers_num_groups(); g++)
+	{
+		MAPITEM_GROUP *group = layers_get_group(g);
+		
+		mapscreen_to_group(center_x, center_y, group);
+		
+		for(int l = 0; l < group->num_layers; l++)
+		{
+			MAPITEM_LAYER *layer = layers_get_layer(group->start_layer+l);
+			bool render = false;
+			bool is_game_layer = false;
+			
+			if(layer == (MAPITEM_LAYER*)layers_game())
+			{
+				is_game_layer = true;
+				passed_gamelayer = 1;
+			}
+				
+			if(pass == 0)
+			{
+				if(passed_gamelayer)
+					return;
+				render = true;
+			}
+			else
+			{
+				if(passed_gamelayer && !is_game_layer)
+					render = true;
+			}
+			
+			if(render)
+			{
+				if(layer->type == LAYERTYPE_TILES)
+				{
+					MAPITEM_LAYER_TILEMAP *tmap = (MAPITEM_LAYER_TILEMAP *)layer;
+					if(tmap->image == -1)
+						gfx_texture_set(-1);
+					else
+						gfx_texture_set(img_get(tmap->image));
+					TILE *tiles = (TILE *)map_get_data(tmap->data);
+					render_tilemap(tiles, tmap->width, tmap->height, 32.0f, 1);
+				}
+				else if(layer->type == LAYERTYPE_QUADS)
+				{
+					MAPITEM_LAYER_QUADS *qlayer = (MAPITEM_LAYER_QUADS *)layer;
+					if(qlayer->image == -1)
+						gfx_texture_set(-1);
+					else
+						gfx_texture_set(img_get(qlayer->image));
+					QUAD *quads = (QUAD *)map_get_data_swapped(qlayer->data);
+					render_quads(quads, qlayer->num_quads);
+				}
+			}
+		}
+	}
+}
+
+// renders the complete game world
+void render_world(float center_x, float center_y, float zoom)
+{
+	// render background layers
+	render_layers(center_x, center_y, 0);
+
+	// render items
+	{
+		int num = snap_num_items(SNAP_CURRENT);
+		for(int i = 0; i < num; i++)
+		{
+			SNAP_ITEM item;
+			const void *data = snap_get_item(SNAP_CURRENT, i, &item);
+
+			if(item.type == OBJTYPE_PROJECTILE)
+			{
+				//const void *prev = snap_find_item(SNAP_PREV, item.type, item.id);
+				//if(prev)
+				render_projectile((const obj_projectile *)data, item.id);
+			}
+			else if(item.type == OBJTYPE_POWERUP)
+			{
+				const void *prev = snap_find_item(SNAP_PREV, item.type, item.id);
+				if(prev)
+					render_powerup((const obj_powerup *)prev, (const obj_powerup *)data);
+			}
+			else if(item.type == OBJTYPE_FLAG)
+			{
+				const void *prev = snap_find_item(SNAP_PREV, item.type, item.id);
+				if (prev)
+					render_flag((const obj_flag *)prev, (const obj_flag *)data);
+			}
+		}
+	}
+
+	// render players above all
+	{
+		int num = snap_num_items(SNAP_CURRENT);
+		for(int i = 0; i < num; i++)
+		{
+			SNAP_ITEM item;
+			const void *data = snap_get_item(SNAP_CURRENT, i, &item);
+
+			if(item.type == OBJTYPE_PLAYER_CHARACTER)
+			{
+				const void *prev = snap_find_item(SNAP_PREV, item.type, item.id);
+				const void *prev_info = snap_find_item(SNAP_PREV, OBJTYPE_PLAYER_INFO, item.id);
+				const void *info = snap_find_item(SNAP_CURRENT, OBJTYPE_PLAYER_INFO, item.id);
+
+				if(prev && prev_info && info)
+				{
+					render_player(
+							(const obj_player_character *)prev,
+							(const obj_player_character *)data,
+							(const obj_player_info *)prev_info,
+							(const obj_player_info *)info
+						);
+				}
+			}
+		}
+	}
+
+	// render particles
+	//temp_system.update(client_frametime());
+	//temp_system.render();
+
+	// render foreground layers
+	render_layers(center_x, center_y, 1);
+
+	// render damage indications
+	render_damage_indicators();
+}
diff --git a/src/game/client/gc_render.h b/src/game/client/gc_render.h
index 2f17f6b5..feb04641 100644
--- a/src/game/client/gc_render.h
+++ b/src/game/client/gc_render.h
@@ -37,6 +37,8 @@ void render_game();
 void render_world(float center_x, float center_y, float zoom);
 void render_loading(float percent);
 
+void render_damage_indicators();
+
 // object render methods (gc_render_obj.cpp)
 void render_tee(class animstate *anim, tee_render_info *info, int emote, vec2 dir, vec2 pos);
 void render_flag(const struct obj_flag *prev, const struct obj_flag *current);
@@ -48,7 +50,7 @@ void render_player(
 	
 // map render methods (gc_render_map.cpp)
 void render_quads(QUAD *quads, int num_quads);
-void render_tilemap(TILE *tiles, int w, int h, float scale);
+void render_tilemap(TILE *tiles, int w, int h, float scale, int flags);
 
 // helpers
 void mapscreen_to_world(float center_x, float center_y, float parallax_x, float parallax_y,
diff --git a/src/game/client/gc_render_map.cpp b/src/game/client/gc_render_map.cpp
index fcb8c272..4345aa03 100644
--- a/src/game/client/gc_render_map.cpp
+++ b/src/game/client/gc_render_map.cpp
@@ -88,7 +88,7 @@ void render_quads(QUAD *quads, int num_quads)
 }
 
 
-void render_tilemap(TILE *tiles, int w, int h, float scale)
+void render_tilemap(TILE *tiles, int w, int h, float scale, int flags)
 {
 			//gfx_texture_set(img_get(tmap->image));
 	float screen_x0, screen_y0, screen_x1, screen_y1;
@@ -116,14 +116,29 @@ void render_tilemap(TILE *tiles, int w, int h, float scale)
 		{
 			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;
+			
+			if(flags)
+			{
+				if(mx<0)
+					mx = 0;
+				if(mx>=w)
+					mx = w-1;
+				if(my<0)
+					my = 0;
+				if(my>=h)
+					my = h-1;
+			}
+			else
+			{
+				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;