diff options
| author | Magnus Auvinen <magnus.auvinen@gmail.com> | 2008-09-23 07:43:41 +0000 |
|---|---|---|
| committer | Magnus Auvinen <magnus.auvinen@gmail.com> | 2008-09-23 07:43:41 +0000 |
| commit | 33b50738e63a3c79861bcfd88cb39377f85776c4 (patch) | |
| tree | a7857f0b219e02337da6d8a1a6b66693760b9b6e /src/game/server | |
| parent | e21b6983abaefd0037435c76e9b41cfbbfbe51d5 (diff) | |
| download | zcatch-33b50738e63a3c79861bcfd88cb39377f85776c4.tar.gz zcatch-33b50738e63a3c79861bcfd88cb39377f85776c4.zip | |
added dead reckoning to the characters
Diffstat (limited to 'src/game/server')
| -rw-r--r-- | src/game/server/entities/character.cpp | 59 | ||||
| -rw-r--r-- | src/game/server/entities/character.hpp | 5 | ||||
| -rw-r--r-- | src/game/server/gamecontext.cpp | 17 | ||||
| -rw-r--r-- | src/game/server/gamecontext.hpp | 2 |
4 files changed, 64 insertions, 19 deletions
diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index 463b6640..362eecf0 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -34,7 +34,8 @@ static INPUT_COUNT count_input(int prev, int cur) // player CHARACTER::CHARACTER() : ENTITY(NETOBJTYPE_CHARACTER) -{} +{ +} void CHARACTER::reset() { @@ -59,6 +60,10 @@ bool CHARACTER::spawn(PLAYER *player, vec2 pos, int team) core.world = &game.world.core; core.pos = pos; game.world.core.characters[player->client_id] = &core; + + reckoning_tick = 0; + mem_zero(&sendcore, sizeof(sendcore)); + mem_zero(&reckoningcore, sizeof(reckoningcore)); game.world.insert_entity(this); alive = true; @@ -578,7 +583,7 @@ void CHARACTER::tick() //core.pos = pos; //core.jumped = jumped; core.input = input; - core.tick(); + core.tick(true); // handle weapons handle_weapons(); @@ -592,6 +597,16 @@ void CHARACTER::tick() void CHARACTER::tick_defered() { + // advance the dummy + { + WORLD_CORE tempworld; + reckoningcore.world = &tempworld; + reckoningcore.tick(false); + reckoningcore.move(); + reckoningcore.quantize(); + } + + //lastsentcore; /*if(!dead) {*/ vec2 start_pos = core.pos; @@ -642,6 +657,23 @@ void CHARACTER::tick_defered() pos.x = input.target_x; pos.y = input.target_y; } + + // update the sendcore if needed + { + NETOBJ_CHARACTER predicted; + NETOBJ_CHARACTER current; + mem_zero(&predicted, sizeof(predicted)); + mem_zero(¤t, sizeof(current)); + reckoningcore.write(&predicted); + core.write(¤t); + + if(mem_comp(&predicted, ¤t, sizeof(NETOBJ_CHARACTER)) != 0) + { + reckoning_tick = server_tick(); + sendcore = core; + reckoningcore = core; + } + } } bool CHARACTER::increase_health(int amount) @@ -784,16 +816,12 @@ void CHARACTER::snap(int snaping_client) return; NETOBJ_CHARACTER *character = (NETOBJ_CHARACTER *)snap_new_item(NETOBJTYPE_CHARACTER, player->client_id, sizeof(NETOBJ_CHARACTER)); - - core.write(character); - - // this is to make sure that players that are just standing still - // isn't sent. this is because the physics keep bouncing between - // 0-128 when just standing. - // TODO: fix the physics so this isn't needed - if(snaping_client != player->client_id && abs(character->vy) < 256.0f) - character->vy = 0; - + + // write down the core + character->tick = reckoning_tick; + sendcore.write(character); + + // set emote if (emote_stop < server_tick()) { emote_type = EMOTE_NORMAL; @@ -809,12 +837,7 @@ void CHARACTER::snap(int snaping_client) character->weapon = active_weapon; character->attacktick = attack_tick; - character->wanted_direction = input.direction; - /* - if(input.left && !input.right) - character->wanted_direction = -1; - else if(!input.left && input.right) - character->wanted_direction = 1;*/ + character->direction = input.direction; if(player->client_id == snaping_client) { diff --git a/src/game/server/entities/character.hpp b/src/game/server/entities/character.hpp index 2536bb79..e9909c96 100644 --- a/src/game/server/entities/character.hpp +++ b/src/game/server/entities/character.hpp @@ -79,6 +79,11 @@ public: // the player core for the physics CHARACTER_CORE core; + + // info for dead reckoning + int reckoning_tick; // tick that we are performing dead reckoning from + CHARACTER_CORE sendcore; // core that we should send + CHARACTER_CORE reckoningcore; // the dead reckoning core // CHARACTER(); diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index dfea7e91..0f81167d 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -1,3 +1,4 @@ +#include <new> #include <engine/e_server_interface.h> #include "gamecontext.hpp" @@ -5,14 +6,28 @@ GAMECONTEXT game; GAMECONTEXT::GAMECONTEXT() { - clear(); + for(int i = 0; i < MAX_CLIENTS; i++) + players[i].init(-1); +} + +GAMECONTEXT::~GAMECONTEXT() +{ } void GAMECONTEXT::clear() { + this->~GAMECONTEXT(); + mem_zero(this, sizeof(*this)); + new (this) GAMECONTEXT(); // reset all players + /* for(int i = 0; i < MAX_CLIENTS; i++) players[i].init(-1); + + world.~GAMEWORLD(); + mem_zero(&world, sizeof(world)); + world.GAMEWORLD(); + */ } diff --git a/src/game/server/gamecontext.hpp b/src/game/server/gamecontext.hpp index 85414183..4ef495fd 100644 --- a/src/game/server/gamecontext.hpp +++ b/src/game/server/gamecontext.hpp @@ -32,6 +32,8 @@ class GAMECONTEXT { public: GAMECONTEXT(); + ~GAMECONTEXT(); + void clear(); EVENTHANDLER events; |