about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2007-11-11 21:02:36 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2007-11-11 21:02:36 +0000
commit7efefe27163548b7f61c516d6b650258a3c7d033 (patch)
tree3615438a87ead4a9552db85b871b82ac5972b53e /src
parent5702b3bfd0e20a0f99c8fecdada033e8d8802f01 (diff)
downloadzcatch-7efefe27163548b7f61c516d6b650258a3c7d033.tar.gz
zcatch-7efefe27163548b7f61c516d6b650258a3c7d033.zip
many smaller changes. changed how projectiles are handled. fixed joining bug
Diffstat (limited to 'src')
-rw-r--r--src/engine/client/client.c5
-rw-r--r--src/game/client/game_client.cpp12
-rw-r--r--src/game/client/menu2.cpp68
-rw-r--r--src/game/game.h9
-rw-r--r--src/game/game_protocol.h2
-rw-r--r--src/game/server/game_server.cpp45
-rw-r--r--src/game/server/srv_common.h1
7 files changed, 100 insertions, 42 deletions
diff --git a/src/engine/client/client.c b/src/engine/client/client.c
index 43f3fb3d..19ddf9e4 100644
--- a/src/engine/client/client.c
+++ b/src/engine/client/client.c
@@ -555,8 +555,6 @@ static void client_process_packet(NETPACKET *packet)
 			SERVER_INFO info = {0};
 			int i;
 
-			dbg_msg("temp", "got server info");
-
 			unpacker_reset(&up, (unsigned char*)packet->data+sizeof(SERVERBROWSE_INFO), packet->data_size-sizeof(SERVERBROWSE_INFO));
 
 			strncpy(info.version, unpacker_get_string(&up), 32);
@@ -567,6 +565,9 @@ static void client_process_packet(NETPACKET *packet)
 			info.progression = atol(unpacker_get_string(&up));
 			info.num_players = atol(unpacker_get_string(&up));
 			info.max_players = atol(unpacker_get_string(&up));
+			sprintf(info.address, "%d.%d.%d.%d:%d",
+				packet->address.ip[0], packet->address.ip[1], packet->address.ip[2],
+				packet->address.ip[3], packet->address.port);
 			
 			for(i = 0; i < info.num_players; i++)
 			{
diff --git a/src/game/client/game_client.cpp b/src/game/client/game_client.cpp
index f04d7712..7d01311e 100644
--- a/src/game/client/game_client.cpp
+++ b/src/game/client/game_client.cpp
@@ -932,9 +932,17 @@ static void render_projectile(const obj_projectile *prev, const obj_projectile *
 	gfx_texture_set(data->images[IMAGE_GAME].id);
 	gfx_quads_begin();
 
+	// get positions
+	float gravity = -400;
+	float ct = (client_tick()-current->start_tick)/(float)SERVER_TICK_SPEED + client_intratick()*1/(float)SERVER_TICK_SPEED;
+	vec2 startpos(current->x, current->y);
+	vec2 startvel(current->vx, current->vy);
+	vec2 pos = calc_pos(startpos, startvel, gravity, ct);
+	vec2 prevpos = calc_pos(startpos, startvel, gravity, ct-0.001f);
+
 	select_sprite(data->weapons[current->type%data->num_weapons].sprite_proj);
-	vec2 vel = mix(vec2(prev->vx, prev->vy), vec2(current->vx, current->vy), client_intratick());
-	vec2 pos = mix(vec2(prev->x, prev->y), vec2(current->x, current->y), client_intratick());
+	vec2 vel = pos-prevpos;
+	//vec2 pos = mix(vec2(prev->x, prev->y), vec2(current->x, current->y), client_intratick());
 
 	// add particle for this projectile
 	proj_particles.addparticle(current->type, itemid, pos, vel);
diff --git a/src/game/client/menu2.cpp b/src/game/client/menu2.cpp
index aaf170de..10e66f4f 100644
--- a/src/game/client/menu2.cpp
+++ b/src/game/client/menu2.cpp
@@ -62,6 +62,7 @@ enum
 	PAGE_FAVORITES,
 	PAGE_SETTINGS,
 	PAGE_GAME,
+	PAGE_SYSTEM,
 };
 
 typedef struct 
@@ -72,6 +73,8 @@ typedef struct
 static float scale = 1.0f;
 static RECT screen = { 0.0f, 0.0f, 800.0f, 600.0f };
 
+extern void select_sprite(int id, int flags=0, int sx=0, int sy=0);
+
 RECT *ui2_screen()
 {
     return &screen;
@@ -270,6 +273,27 @@ static void ui2_draw_rect(const RECT *r, vec4 color, int corners, float rounding
 	gfx_quads_end();
 }
 
+static void ui2_draw_browse_icon(const void *id, const char *text, int checked, const RECT *r, void *extra)
+{
+	gfx_texture_set(data->images[IMAGE_BROWSEICONS].id);
+	gfx_quads_begin();
+	if(text[0] == 'L')
+		select_sprite(SPRITE_BROWSE_LOCK);
+	else
+	{
+		int i = atoi(text);
+		if(i < 33)
+			select_sprite(SPRITE_BROWSE_PROGRESS1);
+		else if(i < 66)
+			select_sprite(SPRITE_BROWSE_PROGRESS2);
+		else
+			select_sprite(SPRITE_BROWSE_PROGRESS3);
+	}
+	//draw_round_rect_ext(r->x,r->y,r->w,r->h,rounding*ui2_scale(), corners);
+	gfx_quads_drawTL(r->x,r->y,r->w,r->h);
+	gfx_quads_end();
+}
+
 static void ui2_draw_menu_button(const void *id, const char *text, int checked, const RECT *r, void *extra)
 {
 	ui2_draw_rect(r, vec4(1,1,1,0.5f), CORNER_ALL, 5.0f);
@@ -313,12 +337,16 @@ static void ui2_draw_grid_header(const void *id, const char *text, int checked,
 	ui2_do_label(&t, text, 18, -1);
 }
 
-static void ui2_draw_grid_cell(const void *id, const char *text, int checked, const RECT *r, void *extra)
+static void ui2_draw_grid_cell_l(const void *id, const char *text, int checked, const RECT *r, void *extra)
 {
-	//ui2_draw_round_rect(r, 2.0f, vec4(1,1,1,1));
 	ui2_do_label(r, text, 18, -1);
 }
 
+static void ui2_draw_grid_cell_r(const void *id, const char *text, int checked, const RECT *r, void *extra)
+{
+	ui2_do_label(r, text, 18, 1);
+}
+
 static void ui2_draw_list_row(const void *id, const char *text, int checked, const RECT *r, void *extra)
 {
 	if(checked)
@@ -581,7 +609,7 @@ static int menu2_render_menubar(RECT r)
 		static int game_button=0;
 		if (ui2_do_button(&game_button, "Game", config.ui_page==PAGE_GAME, &button, ui2_draw_menu_tab_button, 0))
 			config.ui_page = PAGE_GAME;
-		ui2_vsplit_l(&box, 30.0f, 0, &box); 
+		ui2_vsplit_l(&box, 30.0f, 0, &box);
 	}
 		
 	ui2_vsplit_l(&box, 110.0f, &button, &box);
@@ -610,6 +638,14 @@ static int menu2_render_menubar(RECT r)
 			config.ui_page = PAGE_FAVORITES;
 	}
 
+	/*
+	ui2_vsplit_r(&box, 110.0f, &box, &button);
+	static int system_button=0;
+	if (ui2_do_button(&system_button, "System", config.ui_page==PAGE_SYSTEM, &button, ui2_draw_menu_tab_button, 0))
+		config.ui_page = PAGE_SYSTEM;
+		
+	ui2_vsplit_r(&box, 30.0f, &box, 0);
+	*/
 	ui2_vsplit_r(&box, 110.0f, &box, &button);
 	static int settings_button=0;
 	if (ui2_do_button(&settings_button, "Settings", config.ui_page==PAGE_SETTINGS, &button, ui2_draw_menu_tab_button, 0))
@@ -685,12 +721,13 @@ static void menu2_render_serverbrowser(RECT main_view)
 	
 	static column cols[] = {
 		{-1,			-1,						" ",		-1, 10.0f, 0, {0}, {0}},
-		{COL_FLAGS,		-1,						" ",		-1, 15.0f, 0, {0}, {0}},
+		{COL_FLAGS,		-1,						" ",		-1, 20.0f, 0, {0}, {0}},
 		{COL_NAME,		BROWSESORT_NAME,		"Name",		0, 300.0f, 0, {0}, {0}},
 		{COL_GAMETYPE,	BROWSESORT_GAMETYPE,	"Type",		1, 50.0f, 0, {0}, {0}},
 		{COL_MAP,		BROWSESORT_MAP,			"Map", 		1, 100.0f, 0, {0}, {0}},
 		{COL_PLAYERS,	BROWSESORT_NUMPLAYERS,	"Players",	1, 60.0f, 0, {0}, {0}},
-		{COL_PROGRESS,	BROWSESORT_PROGRESSION,	"%",		1, 40.0f, FIXED, {0}, {0}},
+		{-1,			-1,						" ",		1, 10.0f, 0, {0}, {0}},
+		{COL_PROGRESS,	BROWSESORT_PROGRESSION,	"%",		1, 20.0f, FIXED, {0}, {0}},
 		{COL_PING,		BROWSESORT_PING,		"Ping",		1, 40.0f, FIXED, {0}, {0}},
 	};
 	
@@ -804,7 +841,6 @@ static void menu2_render_serverbrowser(RECT main_view)
 			}
 			
 			k += h*3/4;
-			i += h*3/4;
 		}
 		else
 			ui2_hsplit_t(&view, 20.0f, &row, &view);
@@ -824,26 +860,26 @@ static void menu2_render_serverbrowser(RECT main_view)
 			if(id == COL_FLAGS)
 			{
 				if(item->flags&1)
-					s = ui2_do_button(item, "P", l, &button, ui2_draw_grid_cell, 0);
+					s = ui2_do_button(item, "L", l, &button, ui2_draw_browse_icon, 0);
 			}
 			else if(id == COL_NAME)
-				s = ui2_do_button(item, item->name, l, &button, ui2_draw_grid_cell, 0);
+				s = ui2_do_button(item, item->name, l, &button, ui2_draw_grid_cell_l, 0);
 			else if(id == COL_MAP)
-				s = ui2_do_button(item, item->map, l, &button, ui2_draw_grid_cell, 0);
+				s = ui2_do_button(item, item->map, l, &button, ui2_draw_grid_cell_l, 0);
 			else if(id == COL_PLAYERS)
 			{
 				sprintf(temp, "%i/%i", item->num_players, item->max_players);
-				s = ui2_do_button(item, temp, l, &button, ui2_draw_grid_cell, 0);
+				s = ui2_do_button(item, temp, l, &button, ui2_draw_grid_cell_r, 0);
 			}
 			else if(id == COL_PING)
 			{
 				sprintf(temp, "%i", item->latency);
-				s = ui2_do_button(item, temp, l, &button, ui2_draw_grid_cell, 0);
+				s = ui2_do_button(item, temp, l, &button, ui2_draw_grid_cell_r, 0);
 			}
 			else if(id == COL_PROGRESS)
 			{
 				sprintf(temp, "%i", item->progression);
-				s = ui2_do_button(item, temp, l, &button, ui2_draw_grid_cell, 0);
+				s = ui2_do_button(item, temp, l, &button, ui2_draw_browse_icon, 0);
 			}
 			else if(id == COL_GAMETYPE)
 			{
@@ -851,12 +887,13 @@ static void menu2_render_serverbrowser(RECT main_view)
 				if(item->game_type == GAMETYPE_DM) type = "DM";
 				else if(item->game_type == GAMETYPE_TDM) type = "TDM";
 				else if(item->game_type == GAMETYPE_CTF) type = "CTF";
-				s = ui2_do_button(item, type, l, &button, ui2_draw_grid_cell, 0);
+				s = ui2_do_button(item, type, l, &button, ui2_draw_grid_cell_l, 0);
 			}
 			
 			if(s)
 			{
 				new_selected = item_index;
+				dbg_msg("dbg", "addr = %s", item->address);
 				strncpy(config.ui_server_address, item->address, sizeof(config.ui_server_address));
 			}
 		}
@@ -1215,6 +1252,9 @@ int menu2_render()
 	ui2_hsplit_t(&screen, 26.0f, &tab_bar, &main_view);
 	ui2_vmargin(&tab_bar, 20.0f, &tab_bar);
 	menu2_render_menubar(tab_bar);
+
+	// do bottom bar
+	//ui2_hsplit_b(&main_view, 26.0f, &main_view, &bottom_bar);
 		
 	// render current page
 	if(config.ui_page == PAGE_GAME)
@@ -1232,3 +1272,5 @@ int menu2_render()
 	
 	return 0;
 }
+
+
diff --git a/src/game/game.h b/src/game/game.h
index 62d67cb7..53036d3d 100644
--- a/src/game/game.h
+++ b/src/game/game.h
@@ -26,6 +26,15 @@ inline float get_angle(vec2 dir)
 }
 
 
+inline vec2 calc_pos(vec2 p, vec2 v, float gravity, float t)
+{
+	vec2 n;
+	n.x = p.x + v.x*t;
+	n.y = p.y + v.y*t - gravity*(t*t);
+	return n;
+}
+
+
 template<typename T>
 inline T saturated_add(T min, T max, T current, T modifier)
 {
diff --git a/src/game/game_protocol.h b/src/game/game_protocol.h
index 7c9f648f..d2f2b6e5 100644
--- a/src/game/game_protocol.h
+++ b/src/game/game_protocol.h
@@ -143,8 +143,10 @@ struct obj_game
 struct obj_projectile
 {
 	int type;
+	int tick;
 	int x, y;
 	int vx, vy; // should be an angle instead
+	int start_tick;
 };
 
 struct obj_powerup
diff --git a/src/game/server/game_server.cpp b/src/game/server/game_server.cpp
index f88eefa9..06dafb72 100644
--- a/src/game/server/game_server.cpp
+++ b/src/game/server/game_server.cpp
@@ -270,7 +270,7 @@ projectile::projectile(int type, int owner, vec2 pos, vec2 vel, int span, entity
 {
 	this->type = type;
 	this->pos = pos;
-	this->vel = vel;
+	this->vel = vel * SERVER_TICK_SPEED; // TODO: remove this
 	this->lifespan = span;
 	this->owner = owner;
 	this->powner = powner;
@@ -280,6 +280,7 @@ projectile::projectile(int type, int owner, vec2 pos, vec2 vel, int span, entity
 	this->sound_impact = sound_impact;
 	this->weapon = weapon;
 	this->bounce = 0;
+	this->start_tick = server_tick();
 	world->insert_entity(this);
 }
 
@@ -290,36 +291,26 @@ void projectile::reset()
 
 void projectile::tick()
 {
-	vec2 oldpos = pos;
-
-	int collide = 0;
-	if(bounce)
-	{
-		int numbounces;
-		vel.y += 0.25f;
-		move_point(&pos, &vel, 0.25f, &numbounces);
-		bounce -= numbounces;
-	}
-	else
-	{
-		vel.y += 0.25f;
-		pos += vel;
-		collide = col_check_point((int)pos.x, (int)pos.y);
-	}
+	float gravity = -400;
+	float pt = (server_tick()-start_tick-1)/(float)SERVER_TICK_SPEED;
+	float ct = (server_tick()-start_tick)/(float)SERVER_TICK_SPEED;
+	vec2 prevpos = calc_pos(pos, vel, gravity, pt);
+	vec2 curpos = calc_pos(pos, vel, gravity, ct);
 
 	lifespan--;
-
-	// check player intersection as well
+	
+	int collide = col_check_point((int)curpos.x, (int)curpos.y);
+	
 	vec2 new_pos;
-	entity *targetplayer = (entity*)intersect_player(oldpos, pos, new_pos, powner);
-
-	if(targetplayer || lifespan < 0 || collide || bounce < 0)
+	entity *targetplayer = (entity*)intersect_player(prevpos, curpos, new_pos, powner);
+	
+	if(targetplayer || collide || lifespan < 0 )
 	{
 		if (lifespan >= 0 || weapon == WEAPON_ROCKET)
 			create_sound(pos, sound_impact);
 
 		if (flags & PROJECTILE_FLAGS_EXPLODE)
-			create_explosion(oldpos, owner, weapon, false);
+			create_explosion(prevpos, owner, weapon, false);
 		else if (targetplayer)
 		{
 			targetplayer->take_damage(normalize(vel) * max(0.001f, force), damage, owner, weapon);
@@ -331,14 +322,18 @@ void projectile::tick()
 
 void projectile::snap(int snapping_client)
 {
-	if(distance(players[snapping_client].pos, pos) > 1000.0f)
+	float ct = (server_tick()-start_tick)/(float)SERVER_TICK_SPEED;
+	vec2 curpos = calc_pos(pos, vel, -7.5f*SERVER_TICK_SPEED, ct);
+
+	if(distance(players[snapping_client].pos, curpos) > 1000.0f)
 		return;
 
 	obj_projectile *proj = (obj_projectile *)snap_new_item(OBJTYPE_PROJECTILE, id, sizeof(obj_projectile));
 	proj->x = (int)pos.x;
 	proj->y = (int)pos.y;
-	proj->vx = (int)vel.x; // TODO: should be an angle
+	proj->vx = (int)vel.x;
 	proj->vy = (int)vel.y;
+	proj->start_tick = start_tick;
 	proj->type = type;
 }
 
diff --git a/src/game/server/srv_common.h b/src/game/server/srv_common.h
index 46c17ed8..4b84b272 100644
--- a/src/game/server/srv_common.h
+++ b/src/game/server/srv_common.h
@@ -186,6 +186,7 @@ public:
 	int weapon;
 	int bounce;
 	float force;
+	int start_tick;
 	
 	projectile(int type, int owner, vec2 pos, vec2 vel, int span, entity* powner,
 		int damage, int flags, float force, int sound_impact, int weapon);