made everything as const on the client so its more clear that you shouldn't change the snapshots

This commit is contained in:
Magnus Auvinen 2007-07-31 06:23:24 +00:00
parent 3014707fe5
commit 3c1d46c048
3 changed files with 38 additions and 37 deletions

View file

@ -157,7 +157,7 @@ float client_localtime()
return (time_get()-local_start_time)/(float)(time_freq()); return (time_get()-local_start_time)/(float)(time_freq());
} }
void *snap_get_item(int snapid, int index, snap_item *item) const void *snap_get_item(int snapid, int index, snap_item *item)
{ {
dbg_assert(snapid >= 0 && snapid < NUM_SNAPSHOT_TYPES, "invalid snapid"); dbg_assert(snapid >= 0 && snapid < NUM_SNAPSHOT_TYPES, "invalid snapid");
snapshot::item *i = snapshots[snapid]->snap->get_item(index); snapshot::item *i = snapshots[snapid]->snap->get_item(index);
@ -166,6 +166,18 @@ void *snap_get_item(int snapid, int index, snap_item *item)
return (void *)i->data(); return (void *)i->data();
} }
const void *snap_find_item(int snapid, int type, int id)
{
// TODO: linear search. should be fixed.
for(int i = 0; i < snapshots[snapid]->snap->num_items; i++)
{
snapshot::item *itm = snapshots[snapid]->snap->get_item(i);
if(itm->type() == type && itm->id() == id)
return (void *)itm->data();
}
return 0x0;
}
int snap_num_items(int snapid) int snap_num_items(int snapid)
{ {
dbg_assert(snapid >= 0 && snapid < NUM_SNAPSHOT_TYPES, "invalid snapid"); dbg_assert(snapid >= 0 && snapid < NUM_SNAPSHOT_TYPES, "invalid snapid");
@ -202,17 +214,6 @@ float client_frametime()
return frametime; return frametime;
} }
void *snap_find_item(int snapid, int type, int id)
{
// TODO: linear search. should be fixed.
for(int i = 0; i < snapshots[snapid]->snap->num_items; i++)
{
snapshot::item *itm = snapshots[snapid]->snap->get_item(i);
if(itm->type() == type && itm->id() == id)
return (void *)itm->data();
}
return 0x0;
}
int menu_loop(); // TODO: what is this? int menu_loop(); // TODO: what is this?

View file

@ -490,7 +490,7 @@ int snap_num_items(int snapid);
Returns: Returns:
Returns a pointer to the item if it exists, otherwise NULL. Returns a pointer to the item if it exists, otherwise NULL.
*/ */
void *snap_get_item(int snapid, int index, snap_item *item); const void *snap_get_item(int snapid, int index, snap_item *item);
/* /*
Function: snap_find_item Function: snap_find_item
@ -506,7 +506,7 @@ void *snap_get_item(int snapid, int index, snap_item *item);
Returns: Returns:
Returns a pointer to the item if it exists, otherwise NULL. Returns a pointer to the item if it exists, otherwise NULL.
*/ */
void *snap_find_item(int snapid, int type, int id); const void *snap_find_item(int snapid, int type, int id);
/* /*
Function: snap_input Function: snap_input

View file

@ -471,7 +471,7 @@ void modc_newsnapshot()
for(int i = 0; i < num; i++) for(int i = 0; i < num; i++)
{ {
snap_item item; snap_item item;
void *data = snap_get_item(SNAP_CURRENT, i, &item); const void *data = snap_get_item(SNAP_CURRENT, i, &item);
if(item.type == EVENT_DAMAGEINDICATION) if(item.type == EVENT_DAMAGEINDICATION)
{ {
@ -602,7 +602,7 @@ void modc_newsnapshot()
} }
} }
static void render_projectile(obj_projectile *prev, obj_projectile *current, int itemid) static void render_projectile(const obj_projectile *prev, const obj_projectile *current, int itemid)
{ {
gfx_texture_set(data->images[IMAGE_GAME].id); gfx_texture_set(data->images[IMAGE_GAME].id);
gfx_quads_begin(); gfx_quads_begin();
@ -627,7 +627,7 @@ static void render_projectile(obj_projectile *prev, obj_projectile *current, int
gfx_quads_end(); gfx_quads_end();
} }
static void render_powerup(obj_powerup *prev, obj_powerup *current) static void render_powerup(const obj_powerup *prev, const obj_powerup *current)
{ {
gfx_texture_set(data->images[IMAGE_GAME].id); gfx_texture_set(data->images[IMAGE_GAME].id);
gfx_quads_begin(); gfx_quads_begin();
@ -670,7 +670,7 @@ static void render_powerup(obj_powerup *prev, obj_powerup *current)
gfx_quads_end(); gfx_quads_end();
} }
static void render_flag(obj_flag *prev, obj_flag *current) static void render_flag(const obj_flag *prev, const obj_flag *current)
{ {
float angle = 0.0f; float angle = 0.0f;
float size = 64.0f; float size = 64.0f;
@ -877,7 +877,7 @@ static void draw_round_rect(float x, float y, float w, float h, float r)
gfx_quads_drawTL(x+w-r, y+r, r, h-r*2); // right gfx_quads_drawTL(x+w-r, y+r, r, h-r*2); // right
} }
static void render_player(obj_player *prev, obj_player *player) static void render_player(const obj_player *prev, const obj_player *player)
{ {
if(player->health < 0) // dont render dead players if(player->health < 0) // dont render dead players
return; return;
@ -1324,7 +1324,7 @@ void modc_render()
for(int i = 0; i < num; i++) for(int i = 0; i < num; i++)
{ {
snap_item item; snap_item item;
void *data = snap_get_item(SNAP_CURRENT, i, &item); const void *data = snap_get_item(SNAP_CURRENT, i, &item);
if(item.type == OBJTYPE_PLAYER) if(item.type == OBJTYPE_PLAYER)
{ {
@ -1334,7 +1334,7 @@ void modc_render()
local_player = player; local_player = player;
local_player_pos = vec2(player->x, player->y); local_player_pos = vec2(player->x, player->y);
void *p = snap_find_item(SNAP_PREV, item.type, item.id); const void *p = snap_find_item(SNAP_PREV, item.type, item.id);
if(p) if(p)
local_player_pos = mix(vec2(((obj_player *)p)->x, ((obj_player *)p)->y), local_player_pos, client_intratick()); local_player_pos = mix(vec2(((obj_player *)p)->x, ((obj_player *)p)->y), local_player_pos, client_intratick());
} }
@ -1414,34 +1414,34 @@ void modc_render()
for(int i = 0; i < num; i++) for(int i = 0; i < num; i++)
{ {
snap_item item; snap_item item;
void *data = snap_get_item(SNAP_CURRENT, i, &item); const void *data = snap_get_item(SNAP_CURRENT, i, &item);
if(item.type == OBJTYPE_PLAYER) if(item.type == OBJTYPE_PLAYER)
{ {
void *prev = snap_find_item(SNAP_PREV, item.type, item.id); const void *prev = snap_find_item(SNAP_PREV, item.type, item.id);
if(prev) if(prev)
{ {
client_datas[((obj_player *)data)->clientid].team = ((obj_player *)data)->team; client_datas[((const obj_player *)data)->clientid].team = ((const obj_player *)data)->team;
render_player((obj_player *)prev, (obj_player *)data); render_player((const obj_player *)prev, (const obj_player *)data);
} }
} }
else if(item.type == OBJTYPE_PROJECTILE) else if(item.type == OBJTYPE_PROJECTILE)
{ {
void *prev = snap_find_item(SNAP_PREV, item.type, item.id); const void *prev = snap_find_item(SNAP_PREV, item.type, item.id);
if(prev) if(prev)
render_projectile((obj_projectile *)prev, (obj_projectile *)data, item.id); render_projectile((const obj_projectile *)prev, (const obj_projectile *)data, item.id);
} }
else if(item.type == OBJTYPE_POWERUP) else if(item.type == OBJTYPE_POWERUP)
{ {
void *prev = snap_find_item(SNAP_PREV, item.type, item.id); const void *prev = snap_find_item(SNAP_PREV, item.type, item.id);
if(prev) if(prev)
render_powerup((obj_powerup *)prev, (obj_powerup *)data); render_powerup((const obj_powerup *)prev, (const obj_powerup *)data);
} }
else if(item.type == OBJTYPE_FLAG) else if(item.type == OBJTYPE_FLAG)
{ {
void *prev = snap_find_item(SNAP_PREV, item.type, item.id); const void *prev = snap_find_item(SNAP_PREV, item.type, item.id);
if (prev) if (prev)
render_flag((obj_flag *)prev, (obj_flag *)data); render_flag((const obj_flag *)prev, (const obj_flag *)data);
} }
} }
@ -1670,11 +1670,11 @@ void modc_render()
for(int i = 0; i < num; i++) for(int i = 0; i < num; i++)
{ {
snap_item item; snap_item item;
void *data = snap_get_item(SNAP_CURRENT, i, &item); const void *data = snap_get_item(SNAP_CURRENT, i, &item);
if(item.type == OBJTYPE_PLAYER) if(item.type == OBJTYPE_PLAYER)
{ {
obj_player *player = (obj_player *)data; const obj_player *player = (const obj_player *)data;
if(player) if(player)
{ {
char buf[128]; char buf[128];
@ -1732,11 +1732,11 @@ void modc_render()
for(int i = 0; i < num; i++) for(int i = 0; i < num; i++)
{ {
snap_item item; snap_item item;
void *data = snap_get_item(SNAP_CURRENT, i, &item); const void *data = snap_get_item(SNAP_CURRENT, i, &item);
if(item.type == OBJTYPE_PLAYER) if(item.type == OBJTYPE_PLAYER)
{ {
obj_player *player = (obj_player *)data; const obj_player *player = (const obj_player *)data;
if(player && player->team >= 0 && player->team < 2) if(player && player->team >= 0 && player->team < 2)
{ {
teamscore[player->team] += player->score; teamscore[player->team] += player->score;
@ -1762,11 +1762,11 @@ void modc_render()
for(int i = 0; i < num; i++) for(int i = 0; i < num; i++)
{ {
snap_item item; snap_item item;
void *data = snap_get_item(SNAP_CURRENT, i, &item); const void *data = snap_get_item(SNAP_CURRENT, i, &item);
if(item.type == OBJTYPE_PLAYER) if(item.type == OBJTYPE_PLAYER)
{ {
obj_player *player = (obj_player *)data; const obj_player *player = (const obj_player *)data;
if(player && player->team >= 0 && player->team < 2) if(player && player->team >= 0 && player->team < 2)
{ {
sprintf(buf, "%4d", player->score); sprintf(buf, "%4d", player->score);