about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2007-10-07 15:32:54 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2007-10-07 15:32:54 +0000
commit982db98faec1ba28ff74fdd594ced77e4197cc02 (patch)
tree6ac32c6bd44dcf11cff6fffd8e7a5488f922e788
parentf055f15ae7ef67069d51251b43c8bda22622018d (diff)
downloadzcatch-982db98faec1ba28ff74fdd594ced77e4197cc02.tar.gz
zcatch-982db98faec1ba28ff74fdd594ced77e4197cc02.zip
added sniperscope.. press F to test
-rw-r--r--src/engine/client/gfx.c46
-rw-r--r--src/engine/interface.h9
-rw-r--r--src/engine/server/server.c5
-rw-r--r--src/game/client/game_client.cpp302
-rw-r--r--src/game/game.h5
-rw-r--r--src/game/game_protocol.h3
6 files changed, 259 insertions, 111 deletions
diff --git a/src/engine/client/gfx.c b/src/engine/client/gfx.c
index c34ac0cb..f30e5099 100644
--- a/src/engine/client/gfx.c
+++ b/src/engine/client/gfx.c
@@ -146,7 +146,7 @@ int gfx_init()
 	}
 	else
 	{
-		int result = glfwOpenWindow(screen_width, screen_height, 0, 0, 0, 0, 0, 0, GLFW_WINDOW);
+		int result = glfwOpenWindow(screen_width, screen_height, 0, 0, 0, 0, 24, 0, GLFW_WINDOW);
 		if(result != GL_TRUE)
 		{
 			dbg_msg("game", "failed to create gl context");
@@ -154,6 +154,9 @@ int gfx_init()
 		}
 	}
 	
+	glGetIntegerv(GL_DEPTH_BITS, &i);
+	dbg_msg("gfx", "depthbits = %d", i);
+	
 	glfwSetWindowTitle("Teewars");
 	
 	/* We don't want to see the window when we run the stress testing */
@@ -176,8 +179,11 @@ int gfx_init()
 
 	/* set some default settings */	
 	glEnable(GL_BLEND);
+	glDisable(GL_CULL_FACE);
+	glDisable(GL_DEPTH_TEST);
 	glMatrixMode(GL_MODELVIEW);
 	glLoadIdentity();
+	gfx_mask_op(MASK_NONE, 0);
 	
 	/* Set all z to -5.0f */
 	for (i = 0; i < vertex_buffer_size; i++)
@@ -204,6 +210,36 @@ int gfx_init()
 	return 1;
 }
 
+void gfx_clear_mask(int fill)
+{
+	/*if(fill)
+		glClearDepth(0.0f);
+	else*/
+	
+	int i;
+	glGetIntegerv(GL_DEPTH_WRITEMASK, &i);
+	glDepthMask(GL_TRUE);
+	glClearDepth(0.0f);
+	glClear(GL_DEPTH_BUFFER_BIT);
+	glDepthMask(i);
+}
+
+void gfx_mask_op(int mask, int write)
+{
+	glEnable(GL_DEPTH_TEST);
+	
+	if(write)
+		glDepthMask(GL_TRUE);
+	else
+		glDepthMask(GL_FALSE);
+	
+	if(mask == MASK_NONE)
+		glDepthFunc(GL_ALWAYS);
+	else if(mask == MASK_SET)
+		glDepthFunc(GL_LEQUAL);
+	else if(mask == MASK_ZERO)
+		glDepthFunc(GL_NOTEQUAL);
+}
 
 int gfx_window_active()
 {
@@ -689,13 +725,13 @@ void gfx_quads_draw_freeform(
 
 	vertices[num_vertices + 2].pos.x = x3;
 	vertices[num_vertices + 2].pos.y = y3;
-	vertices[num_vertices + 2].tex = texture[2];
-	vertices[num_vertices + 2].color = color[2];
+	vertices[num_vertices + 2].tex = texture[3];
+	vertices[num_vertices + 2].color = color[3];
 
 	vertices[num_vertices + 3].pos.x = x2;
 	vertices[num_vertices + 3].pos.y = y2;
-	vertices[num_vertices + 3].tex = texture[3];
-	vertices[num_vertices + 3].color = color[3];
+	vertices[num_vertices + 3].tex = texture[2];
+	vertices[num_vertices + 3].color = color[2];
 	
 	draw_quad();
 }
diff --git a/src/engine/interface.h b/src/engine/interface.h
index af892dba..9f0ee144 100644
--- a/src/engine/interface.h
+++ b/src/engine/interface.h
@@ -21,6 +21,11 @@ enum
 	IMG_RGB=0,
 	IMG_RGBA=1,
 	
+	MASK_NONE=0,
+	MASK_SET,
+	MASK_ZERO,
+
+	
 	CLIENTSTATE_OFFLINE=0,
 	CLIENTSTATE_CONNECTING,
 	CLIENTSTATE_LOADING,
@@ -826,6 +831,10 @@ void gfx_lines_begin();
 void gfx_lines_draw(float x0, float y0, float x1, float y1);
 void gfx_lines_end();
 
+void gfx_mask_op(int mask, int write);
+void gfx_clear_mask(int fill);
+
+
 /* server snap id */
 int snap_new_id();
 void snap_free_id(int id);
diff --git a/src/engine/server/server.c b/src/engine/server/server.c
index 721c345b..afbcc0dd 100644
--- a/src/engine/server/server.c
+++ b/src/engine/server/server.c
@@ -765,13 +765,12 @@ static int server_run()
 			{
 				if(config.debug)
 				{
-					dbg_msg("server", "sim=%.02fms snap=%.02fms net=%.02fms total=%.02fms load=%.02f%% ids=%d/%d",
+					dbg_msg("server", "sim=%.02fms snap=%.02fms net=%.02fms total=%.02fms load=%.02f%%",
 						(simulationtime/reportinterval)/(double)time_freq()*1000,
 						(snaptime/reportinterval)/(double)time_freq()*1000,
 						(networktime/reportinterval)/(double)time_freq()*1000,
 						(totaltime/reportinterval)/(double)time_freq()*1000,
-						(totaltime)/reportinterval/(double)time_freq()*100.0f,
-						snap_id_inusage, snap_id_usage);
+						(totaltime)/reportinterval/(double)time_freq()*100.0f);
 				}
 	
 				simulationtime = 0;
diff --git a/src/game/client/game_client.cpp b/src/game/client/game_client.cpp
index a6eac2e7..f97c32ca 100644
--- a/src/game/client/game_client.cpp
+++ b/src/game/client/game_client.cpp
@@ -4,6 +4,7 @@
 #include <string.h>
 
 extern "C" {
+	#include <engine/external/glfw/include/GL/glfw.h> // DEBUG TESTING
 	#include <engine/client/ui.h>
 	#include <engine/config.h>
 };
@@ -1673,8 +1674,123 @@ void render_scoreboard(obj_game *gameobj, float x, float y, float w, int team, c
 	}
 }
 
+void mapscreen_to_world(float center_x, float center_y, float zoom)
+{
+	const float default_zoom = 3.0f;
+	float width = 400*default_zoom*zoom;
+	float height = 300*default_zoom*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)
+{
+	const float default_zoom = 3.0f;
+	float width = 400*default_zoom*zoom;
+	float height = 300*default_zoom*zoom;
+	
+	gfx_mapscreen(center_x-width/2, center_y-height/2, center_x+width/2, center_y+height/2);
+	
+	// draw background
+
+	// draw the sun
+	if(config.gfx_high_detail)
+	{
+		render_sun(20+center_x*0.6f, 20+center_y*0.6f);
+		
+		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 *)prev, (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)
+			{
+				const void *prev = snap_find_item(SNAP_PREV, item.type, item.id);
+				if(prev)
+				{
+					client_datas[((const obj_player *)data)->clientid].team = ((const obj_player *)data)->team;
+					render_player((const obj_player *)prev, (const obj_player *)data);
+				}
+			}
+		}	
+	}
+
+	// render particles
+	temp_system.update(client_frametime());
+	temp_system.render();
+
+	// render foreground tilemaps
+	tilemap_render(32.0f, 1);
+	
+	// render damage indications
+	damageind.render();	
+}
+
 void render_game()
 {	
+	float width = 400*3.0f;
+	float height = 300*3.0f;
+		
 	animstate idlestate;
 	anim_eval(&data->animations[ANIM_BASE], 0, &idlestate);
 	anim_eval_add(&idlestate, &data->animations[ANIM_IDLE], 0, 1.0f);	
@@ -1687,6 +1803,7 @@ void render_game()
 			menu_active = !menu_active;
 	}
 	
+	// handle chat input
 	if (!menu_active)
 	{
 		if(chat_mode != CHATMODE_NONE)
@@ -1696,14 +1813,16 @@ void render_game()
 				// send message
 				if(chat_input_len)
 				{
-					if(chat_input[0] == '/')
+					if(chat_input[0] == '/') // check for local command
 						config_set(&chat_input[1]);
 					else
 					{
+						// check for remote command
 						if(inp_key_pressed(KEY_RSHIFT) || inp_key_pressed(KEY_LSHIFT))
 							client_rcon(chat_input);
 						else
 						{
+							// send chat message
 							msg_pack_start(MSG_SAY, MSGFLAG_VITAL);
 							if(chat_mode == CHATMODE_ALL)
 								msg_pack_int(0);
@@ -1762,9 +1881,7 @@ void render_game()
 	}
 	
 	if (!menu_active)
-	{
 		inp_clear();
-	}
 	
 	// fetch new input
 	if(!menu_active && (!emoticon_selector_active || emoticon_selector_inactive_override))
@@ -1865,20 +1982,6 @@ void render_game()
 	if(must_process_events)
 		process_events(SNAP_PREV);
 
-	// pseudo format
-	float zoom = 3.0f;
-	
-	if(config.debug)
-	{
-		if(chat_mode != CHATMODE_NONE && inp_key_pressed(KEY_F8))
-			zoom = 1.0f;
-	}
-	
-	float width = 400*zoom;
-	float height = 300*zoom;
-	float screen_x = 0;
-	float screen_y = 0;
-	
 	// center at char but can be moved when mouse is far away
 	float offx = 0, offy = 0;
 	if (config.dynamic_camera)
@@ -1891,105 +1994,98 @@ void render_game()
 		offx = offx*2/3;
 		offy = offy*2/3;
 	}
-		
-	screen_x = local_player_pos.x+offx;
-	screen_y = local_player_pos.y+offy;
 	
-	gfx_mapscreen(screen_x-width/2, screen_y-height/2, screen_x+width/2, screen_y+height/2);
-	
-	// draw background
+	// render the world
 	gfx_clear(0.65f,0.78f,0.9f);
+	render_world(local_player_pos.x+offx, local_player_pos.y+offy, 1.0f);
 
-	// draw the sun
-	if(config.gfx_high_detail)
+	// DEBUG TESTING
+	if(inp_key_pressed('F'))
 	{
-		render_sun(20+screen_x*0.6f, 20+screen_y*0.6f);
+		gfx_clear_mask(0);
+
+		gfx_texture_set(-1);
+		gfx_blend_normal();
 		
-		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_mask_op(MASK_NONE, 1);
 		
-		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))+screen_x*parallax_amount,
-				cloud_pos[i].y+screen_y*parallax_amount, 300);
-		}
-		gfx_quads_end();
+		gfx_setcolor(0.65f,0.78f,0.9f,1.0f);
+		
+		float fov = pi/4.0f;
+		float fade = 0.7f;
+		
+		
+		float a = get_angle(normalize(vec2(mouse_pos.x, mouse_pos.y)));
+		vec2 d = get_dir(a);
+		vec2 d0 = get_dir(a-fov/2.0f);
+		vec2 d1 = get_dir(a+fov/2.0f);
 
+		vec2 cd0 = get_dir(a-(fov*fade)/2.0f); // center direction
+		vec2 cd1 = get_dir(a+(fov*fade)/2.0f);
 		
-		// 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+screen_x*parallax_amount, (screen_y)*parallax_amount+150+512, 1024, 512);
+		vec2 p0n = local_player_pos + d0*32.0f;
+		vec2 p1n = local_player_pos + d1*32.0f;
+		vec2 p0f = local_player_pos + d0*1000.0f;
+		vec2 p1f = local_player_pos + d1*1000.0f;
+
+		vec2 cn = local_player_pos + d*32.0f;
+		vec2 cf = local_player_pos + d*1000.0f;
+
+		vec2 cp0n = local_player_pos + cd0*32.0f;
+		vec2 cp0f = local_player_pos + cd0*1000.0f;
+		vec2 cp1n = local_player_pos + cd1*32.0f;
+		vec2 cp1f = local_player_pos + cd1*1000.0f;
+
+		gfx_quads_draw_freeform(
+			p0n.x,p0n.y,
+			p1n.x,p1n.y,
+			p0f.x,p0f.y,
+			p1f.x,p1f.y);
 		gfx_quads_end();
-	}
-	
-	// render map
-	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 *)prev, (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);
-			}
-		}
-	}
+		
+		gfx_mask_op(MASK_SET, 0);
+		
+		render_world(local_player_pos.x+offx, local_player_pos.y+offy, 2.0f);
+		
+		gfx_mask_op(MASK_NONE, 0);
+		
+		mapscreen_to_world(local_player_pos.x+offx, local_player_pos.y+offy, 1.0f);
 
-	// 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);
+		gfx_texture_set(-1);
+		gfx_blend_normal();
+		gfx_quads_begin();
+		gfx_setcolor(0.5f,0.9f,0.5f,0.25f);
+		float r=0.5f, g=1.0f, b=0.5f;
+		
+		gfx_setcolor(r,g,b,0.1f);
+		gfx_quads_draw_freeform(
+			cn.x,cn.y,
+			cn.x,cn.y,
+			cp0f.x,cp0f.y,
+			cp1f.x,cp1f.y);
+
+		gfx_setcolorvertex(0, r, g, b, 0.1f);
+		gfx_setcolorvertex(1, 0, 0, 0, 0.9f);
+		gfx_setcolorvertex(2, r, g, b, 0.1f);
+		gfx_setcolorvertex(3, 0, 0, 0, 0.9f);
+		gfx_quads_draw_freeform(
+			cn.x,cn.y,
+			p0n.x,p0n.y,
+			cp0f.x,cp0f.y,
+			p0f.x,p0f.y);
+
+		gfx_quads_draw_freeform(
+			cn.x,cn.y,
+			p1n.x,p1n.y,
+			cp1f.x,cp1f.y,
+			p1f.x,p1f.y);
 			
-			if(item.type == OBJTYPE_PLAYER)
-			{
-				const void *prev = snap_find_item(SNAP_PREV, item.type, item.id);
-				if(prev)
-				{
-					client_datas[((const obj_player *)data)->clientid].team = ((const obj_player *)data)->team;
-					render_player((const obj_player *)prev, (const obj_player *)data);
-				}
-			}
-		}	
+		gfx_quads_end();
+				
+		
+		//gfx_mapscreen(0,0,400*3,300*3);
 	}
-
-	// render particles
-	temp_system.update(client_frametime());
-	temp_system.render();
-
-	tilemap_render(32.0f, 1);
-	
-	// render damage indications
-	damageind.render();
 	
 	if(local_player)
 	{
diff --git a/src/game/game.h b/src/game/game.h
index 2a35bf97..d3b491fc 100644
--- a/src/game/game.h
+++ b/src/game/game.h
@@ -12,6 +12,11 @@ inline vec2 get_direction(int angle)
 	return vec2(cosf(a), sinf(a));
 }
 
+inline vec2 get_dir(float a)
+{
+	return vec2(cosf(a), sinf(a));
+}
+
 inline float get_angle(vec2 dir)
 {
 	float a = atan(dir.y/dir.x);
diff --git a/src/game/game_protocol.h b/src/game/game_protocol.h
index da3b424b..7172e8a5 100644
--- a/src/game/game_protocol.h
+++ b/src/game/game_protocol.h
@@ -84,6 +84,9 @@ struct player_input
 	int blink;
 	int activeweapon;
 	int state;
+	
+	int next_weapon;
+	int prev_weapon;
 };