fixed correction count. fixed miss-behaving server

This commit is contained in:
Magnus Auvinen 2008-02-24 18:41:02 +00:00
parent 4739966e14
commit 91eda24ddc
6 changed files with 30 additions and 6 deletions

View file

@ -184,6 +184,7 @@ def emit_header_file(f, p):
print >>f, "int netobj_secure(int type, void *data, int size);"
print >>f, "const char *netobj_get_name(int type);"
print >>f, "int netobj_num_corrections();"
print >>f, ""
for obj in p.objects:
@ -199,11 +200,15 @@ def emit_source_file(f, p, protofilename):
for l in p.source_raw:
print >>f, l
print >>f, ""
print >>f, "static int num_corrections = 0;"
print >>f, "int netobj_num_corrections() { return num_corrections; }"
print >>f, ""
print >>f, "static int netobj_clamp_int(int v, int min, int max)"
print >>f, "{"
print >>f, "if(v<min) return min;"
print >>f, "if(v>max) return max;"
print >>f, "return v;"
print >>f, "\tif(v<min) { num_corrections++; return min; }"
print >>f, "\tif(v>max) { num_corrections++; return max; }"
print >>f, "\treturn v;"
print >>f, "}"
print >>f, ""

View file

@ -1448,7 +1448,7 @@ void render_game()
vec2(netobjects.local_character->x, netobjects.local_character->y));
char buf[512];
str_format(buf, sizeof(buf), "%.2f", speed/2);
str_format(buf, sizeof(buf), "%.2f %d", speed/2, netobj_num_corrections());
gfx_text(0, 150, 50, 12, buf, -1);
}

View file

@ -154,6 +154,20 @@ void move_box(vec2 *inout_pos, vec2 *inout_vel, vec2 size, float elasticity)
*inout_vel = vel;
}
void player_core::reset()
{
pos = vec2(0,0);
vel = vec2(0,0);
hook_pos = vec2(0,0);
hook_dir = vec2(0,0);
hook_tick = 0;
hook_state = HOOK_IDLE;
hooked_player = -1;
jumped = 0;
triggered_events = 0;
}
void player_core::tick()
{
float phys_size = 28.0f;

View file

@ -137,6 +137,7 @@ public:
int triggered_events;
void reset();
void tick();
void move();

View file

@ -130,7 +130,7 @@ object player_core
any vx, vy
any angle
range(0, 2) jumped
range(0, 3) jumped
clientid hooked_player
range(0, 3) hook_state

View file

@ -595,7 +595,11 @@ void player::init()
void player::reset()
{
pos = vec2(0.0f, 0.0f);
core.vel = vec2(0.0f, 0.0f);
core.reset();
emote_type = 0;
emote_stop = -1;
//direction = vec2(0.0f, 1.0f);
score = 0;
dead = true;