From 7d7975644369e393d44950d3b0083743b39db173 Mon Sep 17 00:00:00 2001 From: Magnus Auvinen Date: Wed, 12 Dec 2007 20:05:18 +0000 Subject: solved corner case issue --- src/game/game.cpp | 22 +++++++++++++++++----- src/game/server/game_server.cpp | 10 ++++++---- 2 files changed, 23 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/game/game.cpp b/src/game/game.cpp index cb00ae0e..29e4da14 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -75,18 +75,30 @@ void move_box(vec2 *inout_pos, vec2 *inout_vel, vec2 size, float elasticity) vec2 new_pos = pos + vel*fraction; // TODO: this row is not nice - // make sure that we quantize. this is to make sure that when we set - // the final position that we don't move it into the ground. - if(test_box(vec2((int)new_pos.x,(int) new_pos.y), size)) + if(test_box(vec2(new_pos.x, new_pos.y), size)) { - if(test_box(vec2((int)pos.x, (int)new_pos.y), size)) + int hits = 0; + + if(test_box(vec2(pos.x, new_pos.y), size)) { new_pos.y = pos.y; vel.y *= -elasticity; + hits++; + } + + if(test_box(vec2(new_pos.x, pos.y), size)) + { + new_pos.x = pos.x; + vel.x *= -elasticity; + hits++; } - if(test_box(vec2((int)new_pos.x, (int)pos.y), size)) + // neither of the tests got a collision. + // this is a real _corner case_! + if(hits == 0) { + new_pos.y = pos.y; + vel.y *= -elasticity; new_pos.x = pos.x; vel.x *= -elasticity; } diff --git a/src/game/server/game_server.cpp b/src/game/server/game_server.cpp index 7a075039..5ca2b3db 100644 --- a/src/game/server/game_server.cpp +++ b/src/game/server/game_server.cpp @@ -1011,7 +1011,6 @@ void player::tick_defered() vec2 start_pos = core.pos; vec2 start_vel = core.vel; bool stuck_before = test_box(core.pos, vec2(28.0f, 28.0f)); - core.move(); bool stuck_after_move = test_box(core.pos, vec2(28.0f, 28.0f)); core.quantize(); @@ -1020,11 +1019,14 @@ void player::tick_defered() if(!stuck_before && (stuck_after_move || stuck_after_quant)) { - dbg_msg("player", "STUCK!!! %f %f %f %f %x %x %x %x", + dbg_msg("player", "STUCK!!! %d %d %d %f %f %f %f %x %x %x %x", + stuck_before, + stuck_after_move, + stuck_after_quant, start_pos.x, start_pos.y, start_vel.x, start_vel.y, - start_pos.x, start_pos.y, - start_vel.x, start_vel.y); + *((unsigned *)&start_pos.x), *((unsigned *)&start_pos.y), + *((unsigned *)&start_vel.x), *((unsigned *)&start_vel.y)); } -- cgit 1.4.1