fixed some problems with the snapshot handling. added fps meter. fixed error when connecting to several servers

This commit is contained in:
Magnus Auvinen 2007-07-29 13:21:33 +00:00
parent 25c0ffb4f4
commit e6c4db94d8
6 changed files with 49 additions and 20 deletions

View file

@ -398,7 +398,7 @@ bool client::load_data()
debug_font = gfx_load_texture("data/debug_font.png");
return true;
}
extern int memory_alloced;
void client::debug_render()
{
if(!config.debug)
@ -417,12 +417,14 @@ void client::debug_render()
net.stats(&current);
}
static float frametime_avg = 0;
frametime_avg = frametime_avg*0.9f + frametime*0.1f;
char buffer[512];
sprintf(buffer, "send: %8d recv: %8d latency: %4.0f %c",
sprintf(buffer, "send: %6d recv: %6d latency: %4.0f %c fps: %d",
(current.send_bytes-prev.send_bytes)*10,
(current.recv_bytes-prev.recv_bytes)*10,
latency*1000.0f, extra_polating?'E':' ');
gfx_quads_text(10, 10, 16, buffer);
latency*1000.0f, extra_polating?'E':' ', (int)(1.0f/frametime_avg));
gfx_quads_text(2, 2, 16, buffer);
}
@ -538,25 +540,36 @@ void client::run(const char *direct_connect_server)
// switch snapshot
if(recived_snapshots >= 3)
{
snapshot_info *cur = snapshots[SNAP_CURRENT];
int64 t = game_start_time + (cur->tick+1)*time_freq()/50;
if(latency > 0)
t += (int64)(time_freq()*(latency*1.1f));
if(t < time_get())
int64 now = time_get();
while(1)
{
snapshot_info *next = snapshots[SNAP_CURRENT]->next;
if(next)
snapshot_info *cur = snapshots[SNAP_CURRENT];
int64 tickstart = game_start_time + (cur->tick+1)*time_freq()/50;
int64 t = tickstart;
if(latency > 0)
t += (int64)(time_freq()*(latency*1.1f));
if(t < now)
{
snapshots[SNAP_PREV] = snapshots[SNAP_CURRENT];
snapshots[SNAP_CURRENT] = next;
snapshot_start_time = t;
snapshot_info *next = snapshots[SNAP_CURRENT]->next;
if(next)
{
snapshots[SNAP_PREV] = snapshots[SNAP_CURRENT];
snapshots[SNAP_CURRENT] = next;
snapshot_start_time = t;
}
else
{
extra_polating = 1;
break;
}
}
else
extra_polating = 1;
{
extra_polating = 0;
break;
}
}
else
extra_polating = 0;
}
// send input

View file

@ -111,6 +111,13 @@ struct batch
int num;
};
void gfx_destoy_batch(void *in_b)
{
batch *b = (batch*)in_b;
delete b;
}
void gfx_quads_draw_batch(void *in_b)
{
batch *b = (batch*)in_b;
@ -152,6 +159,7 @@ void *gfx_quads_create_batch()
batch *b = new batch;
b->num = num_vertices;
b->vb.data(vertices, num_vertices*sizeof(custom_vertex), GL_STATIC_DRAW);
dbg_msg("gfx", "created batch. num=%d size=%d", num_vertices, num_vertices*sizeof(custom_vertex));
num_vertices = 0;
gfx_quads_end();
return b;

View file

@ -756,6 +756,7 @@ void gfx_getscreen(float *tl_x, float *tl_y, float *br_x, float *br_y);
void gfx_quads_draw_batch(void *batch);
void *gfx_quads_create_batch();
void gfx_destoy_batch(void *batch);
void mods_message(int msg, int client_id);
void modc_message(int msg);

View file

@ -1205,6 +1205,7 @@ void modc_render()
{
menu_active = !menu_active;
}
if (!menu_active)
{
if(inp_key_down(input::enter))

View file

@ -5,12 +5,16 @@
#include <baselib/opengl.h>
bool must_init = true;
void *batches[32] = {0};
int tilemap_init()
{
must_init = true;
for(int i = 0; i < 32; i++)
if(batches[i])
{
gfx_destoy_batch(batches[i]);
batches[i] = 0;
}
return 0;
}

View file

@ -1826,6 +1826,8 @@ void mods_init()
if(type != -1)
{
// LOL, the only new in the entire game code
// perhaps we can get rid of it. seams like a stupid thing to have
powerup *ppower = new powerup(type, subtype);
ppower->pos = vec2(it->x, it->y);
}