From c460bae943556737747b27ac728c18727fecfa60 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Fri, 21 Feb 2014 11:23:38 +0100 Subject: [PATCH] Updated dmg protocol --- .../GameClient/GameClientState/GameState.cpp | 34 ++++++++++++++----- Code/Game/GameProtocols/ObjectProtocols.h | 31 +++++++++++------ 2 files changed, 45 insertions(+), 20 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 078bc74b..508d9d4f 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -553,17 +553,33 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState case protocol_Gameplay_ObjectWeaponEnergy: break; /** @todo TODO: implement */ case protocol_Gameplay_ObjectRespawn: { - // set player pos Protocol_ObjectRespawn decoded(data); - // move player. Remember to change camera - this->privData->camera.SetPosition( decoded.position ); - this->privData->player.setPos( decoded.position ); - this->privData->player.updateWorld(); - // RB DEBUG - this->privData->player.setRBPos ( decoded.position ); - this->privData->player.updateRBWorld(); - // !RB DEBUG + if( this->privData->myId == decoded.objectID ) + { + // move player. Remember to change camera + this->privData->camera.SetPosition( decoded.position ); + this->privData->player.setPos( decoded.position ); + this->privData->player.updateWorld(); + // RB DEBUG + this->privData->player.setRBPos ( decoded.position ); + this->privData->player.updateRBWorld(); + // !RB DEBUG + } + else + { + C_DynamicObj *object = (*this->privData->dynamicObjects)[decoded.objectID]; + + if( object ) + { + object->setPos( decoded.position ); + object->updateWorld(); + // RB DEBUG + object->setRBPos ( decoded.position ); + object->updateRBWorld(); + // !RB DEBUG + } + } this->currGameUI = this->gameUI; } return GameClientState::event_processed; diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index cae7c7f5..d92afc60 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -812,39 +812,48 @@ namespace GameLogic //#define protocol_Gameplay_ObjectRespawn 364 struct Protocol_ObjectRespawn :public Oyster::Network::CustomProtocolObject { + int objectID; float position[3]; Protocol_ObjectRespawn() { this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].value.netShort = protocol_Gameplay_ObjectRespawn; - - this->protocol[1].type = Oyster::Network::NetAttributeType_Float; + // ID + this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + // POSITION this->protocol[2].type = Oyster::Network::NetAttributeType_Float; this->protocol[3].type = Oyster::Network::NetAttributeType_Float; + this->protocol[4].type = Oyster::Network::NetAttributeType_Float; + this->objectID = 0; memset(&this->position[0], 0, sizeof(float) * 3); } - Protocol_ObjectRespawn(float position[3]) + Protocol_ObjectRespawn(int id, float position[3]) { this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[0].value.netShort = protocol_Gameplay_ObjectRespawn; - this->protocol[1].type = Oyster::Network::NetAttributeType_Float; + // ID + this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + // POSITION this->protocol[2].type = Oyster::Network::NetAttributeType_Float; this->protocol[3].type = Oyster::Network::NetAttributeType_Float; - + this->protocol[4].type = Oyster::Network::NetAttributeType_Float; + this->objectID = id; memcpy(&this->position[0], &position[0], sizeof(float) * 3); } Protocol_ObjectRespawn(Oyster::Network::CustomNetProtocol& p) { - this->position[0] = p[1].value.netFloat; - this->position[1] = p[2].value.netFloat; - this->position[2] = p[3].value.netFloat; + this->objectID = p[1].value.netInt; + this->position[0] = p[2].value.netFloat; + this->position[1] = p[3].value.netFloat; + this->position[2] = p[4].value.netFloat; } Oyster::Network::CustomNetProtocol GetProtocol() override { - this->protocol[1].value = this->position[0]; - this->protocol[2].value = this->position[1]; - this->protocol[3].value = this->position[2]; + this->protocol[1].value = this->objectID; + this->protocol[2].value = this->position[0]; + this->protocol[3].value = this->position[1]; + this->protocol[4].value = this->position[2]; return protocol; }