From 5d1d64bebbfc04a83d64ddb1d26095157c7c88e5 Mon Sep 17 00:00:00 2001 From: Linda Andersson Date: Tue, 17 Dec 2013 10:07:46 +0100 Subject: [PATCH] GL - trying to send move protocol --- Code/Game/DanBiasGame/DanBiasGame_Impl.cpp | 3 +- .../GameClientState/GameClientState.h | 1 + .../DanBiasGame/GameClientState/GameState.cpp | 20 +++++----- Code/Game/DanBiasLauncher/Launcher.cpp | 1 - Code/Game/GameProtocols/ObjectProtocols.h | 38 ++++++++++--------- Code/Game/GameProtocols/PlayerProtocols.h | 9 +++-- .../NetworkDependencies/Connection.cpp | 8 ++-- 7 files changed, 44 insertions(+), 36 deletions(-) diff --git a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp index e804838a..ebd2f715 100644 --- a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp +++ b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp @@ -52,9 +52,10 @@ namespace DanBias case protocol_Gamplay_ObjectPosition: protocolData = new Client::GameClientState::ObjPos; + ((Client::GameClientState::ObjPos*)protocolData)->object_ID = p[1].value.netInt; for(int i = 0; i< 16; i++) { - ((Client::GameClientState::ObjPos*)protocolData)->worldPos[i] = p[i].value.netFloat; + ((Client::GameClientState::ObjPos*)protocolData)->worldPos[i] = p[i+2].value.netFloat; } if(dynamic_cast(gameClientState)) diff --git a/Code/Game/DanBiasGame/GameClientState/GameClientState.h b/Code/Game/DanBiasGame/GameClientState/GameClientState.h index 368fca6a..1082125a 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameClientState.h +++ b/Code/Game/DanBiasGame/GameClientState/GameClientState.h @@ -19,6 +19,7 @@ public: }; struct ObjPos :public ProtocolStruct { + int object_ID; float worldPos[16]; }; struct PlayerPos :public ProtocolStruct diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index dbde1e75..bbcd36a4 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -91,7 +91,6 @@ GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyI case gameStateState_playing: // read server data // update objects - // Client.send(obj); { GameLogic::Protocol_PlayerMovement movePlayer; movePlayer.bForward = false; @@ -117,12 +116,15 @@ GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyI if(KeyInput->IsKeyPressed(DIK_D)) { movePlayer.bStrafeRight = true; + } + + if (privData->nwClient->IsConnected()) + { + privData->nwClient->Send(movePlayer); } - //PlayerPos* posPlayer; - //Protocol(posPlayer); - - privData->nwClient->Send(movePlayer); - + + // send event data + // if(KeyInput->IsKeyPressed(DIK_L)) privData->state = GameState::gameStateState_end; } @@ -177,8 +179,8 @@ void DanBias::Client::GameState::Protocol( PlayerPos* pos ) world = Oyster::Math::Float4x4::identity; translate = Oyster::Math::Float4x4::identity; - translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(pos->playerPos[0],pos->playerPos[1],pos->playerPos[2] )); - world = translate; + translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(pos->playerPos[0],pos->playerPos[1],pos->playerPos[2])); + world = world * translate; privData->object[0]->setPos( world ); } @@ -189,7 +191,7 @@ void DanBias::Client::GameState::Protocol( ObjPos* pos ) { world[i] = pos->worldPos[i]; } - privData->object[1]->setPos(world); + privData->object[pos->object_ID]->setPos(world); } void GameState::PlayerPosProtocol(PlayerPos* pos) diff --git a/Code/Game/DanBiasLauncher/Launcher.cpp b/Code/Game/DanBiasLauncher/Launcher.cpp index 9fc5e4c9..a8a39eee 100644 --- a/Code/Game/DanBiasLauncher/Launcher.cpp +++ b/Code/Game/DanBiasLauncher/Launcher.cpp @@ -5,7 +5,6 @@ #include #include - //#include "DanBiasServerAPI.h" #include "DanBiasGame.h" diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index 101c5f42..2d2118bb 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -10,15 +10,17 @@ namespace GameLogic { struct Protocol_ObjectPosition :public Oyster::Network::CustomProtocolObject { + int object_ID; float worldMatrix[16]; // look at dir Protocol_ObjectPosition() { - this->protocol[0].value = protocol_PlayerPosition; + this->protocol[0].value = protocol_Gamplay_ObjectPosition; this->protocol[0].type = Oyster::Network::NetAttributeType_Int; - this->protocol[1].type = Oyster::Network::NetAttributeType_Float; + this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + this->protocol[2].type = Oyster::Network::NetAttributeType_Float; this->protocol[3].type = Oyster::Network::NetAttributeType_Float; this->protocol[4].type = Oyster::Network::NetAttributeType_Float; @@ -34,27 +36,29 @@ namespace GameLogic this->protocol[14].type = Oyster::Network::NetAttributeType_Float; this->protocol[15].type = Oyster::Network::NetAttributeType_Float; this->protocol[16].type = Oyster::Network::NetAttributeType_Float; + this->protocol[17].type = Oyster::Network::NetAttributeType_Float; } Oyster::Network::CustomNetProtocol* GetProtocol() override { - this->protocol[1].value = worldMatrix[0]; + this->protocol[1].value = object_ID; this->protocol[2].value = worldMatrix[1]; - this->protocol[3].value = worldMatrix[2]; //Forgot? - this->protocol[4].value = worldMatrix[4]; //Forgot? - this->protocol[5].value = worldMatrix[5]; - this->protocol[6].value = worldMatrix[6]; - this->protocol[7].value = worldMatrix[7]; - this->protocol[8].value = worldMatrix[8]; - this->protocol[9].value = worldMatrix[9]; - this->protocol[10].value = worldMatrix[10]; - this->protocol[11].value = worldMatrix[11]; - this->protocol[12].value = worldMatrix[12]; - this->protocol[13].value = worldMatrix[13]; - this->protocol[14].value = worldMatrix[14]; - this->protocol[15].value = worldMatrix[15]; - this->protocol[16].value = worldMatrix[16]; + this->protocol[3].value = worldMatrix[2]; + this->protocol[4].value = worldMatrix[3]; + this->protocol[5].value = worldMatrix[4]; + this->protocol[6].value = worldMatrix[5]; + this->protocol[7].value = worldMatrix[6]; + this->protocol[8].value = worldMatrix[7]; + this->protocol[9].value = worldMatrix[8]; + this->protocol[10].value = worldMatrix[9]; + this->protocol[11].value = worldMatrix[10]; + this->protocol[12].value = worldMatrix[11]; + this->protocol[13].value = worldMatrix[12]; + this->protocol[14].value = worldMatrix[13]; + this->protocol[15].value = worldMatrix[14]; + this->protocol[16].value = worldMatrix[15]; + this->protocol[17].value = worldMatrix[16]; return &protocol; } diff --git a/Code/Game/GameProtocols/PlayerProtocols.h b/Code/Game/GameProtocols/PlayerProtocols.h index f0464ffc..26422fd1 100644 --- a/Code/Game/GameProtocols/PlayerProtocols.h +++ b/Code/Game/GameProtocols/PlayerProtocols.h @@ -15,7 +15,7 @@ namespace GameLogic { struct Protocol_PlayerMovement :public Oyster::Network::CustomProtocolObject { - int ProtocolID; + bool bForward; bool bBackward; bool bTurnLeft; @@ -25,9 +25,9 @@ namespace GameLogic Protocol_PlayerMovement() { - this->protocol[0].value = ProtocolID = protocol_Gamplay_PlayerNavigation; + this->protocol[0].value = protocol_Gamplay_PlayerNavigation; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; - this->protocol[0].type = Oyster::Network::NetAttributeType_Int; this->protocol[1].type = Oyster::Network::NetAttributeType_Bool; this->protocol[2].type = Oyster::Network::NetAttributeType_Bool; this->protocol[3].type = Oyster::Network::NetAttributeType_Bool; @@ -53,13 +53,14 @@ namespace GameLogic struct Protocol_PlayerPosition :public Oyster::Network::CustomProtocolObject { + float position[3]; // look at dir Protocol_PlayerPosition() { this->protocol[0].value = protocol_Gamplay_PlayerPosition; - this->protocol[0].type = Oyster::Network::NetAttributeType_Int; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Float; this->protocol[2].type = Oyster::Network::NetAttributeType_Float; diff --git a/Code/Network/NetworkDependencies/Connection.cpp b/Code/Network/NetworkDependencies/Connection.cpp index 84a0cbcc..7c893110 100644 --- a/Code/Network/NetworkDependencies/Connection.cpp +++ b/Code/Network/NetworkDependencies/Connection.cpp @@ -10,15 +10,15 @@ using namespace Oyster::Network; Connection::Connection() { this->socket = -1; - bool stillSending = false; - bool closed = true; + this->stillSending = false; + this->closed = true; } Connection::Connection(int socket) { this->socket = socket; - bool stillSending = false; - bool closed = true; + this->stillSending = true; + this->closed = false; } Connection::~Connection()