diff --git a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp index 2aa4fdbc..51082518 100644 --- a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp +++ b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp @@ -6,6 +6,7 @@ #include "GameClientState\GameState.h" #include "GameClientState\LobbyState.h" #include "PlayerProtocols.h" +#include "ControlProtocols.h" #include "NetworkClient.h" #include "../WindowManager/WindowShell.h" @@ -29,9 +30,15 @@ namespace DanBias int pType = p[0].value.netInt; switch (pType) { - case protocol_Gamplay_PlayerNavigation: + case protocol_Status: + { + GameLogic::Protocol_Status::States state; + state = (GameLogic::Protocol_Status::States)p[1].value.netShort; + + } + break; + case protocol_Gameplay_PlayerNavigation: { - Client::GameClientState::KeyInput* protocolData = new Client::GameClientState::KeyInput; for(int i = 0; i< 6; i++) { @@ -44,7 +51,7 @@ namespace DanBias protocolData = NULL; } break; - case protocol_Gamplay_PlayerPosition: + case protocol_Gameplay_PlayerPosition: { Client::GameClientState::PlayerPos* protocolData = new Client::GameClientState::PlayerPos; for(int i = 0; i< 3; i++) @@ -58,7 +65,7 @@ namespace DanBias } break; - case protocol_Gamplay_CreateObject: + case protocol_Gameplay_CreateObject: { Client::GameClientState::NewObj* protocolData = new Client::GameClientState::NewObj; @@ -76,7 +83,19 @@ namespace DanBias protocolData = NULL; } break; - case protocol_Gamplay_ObjectPosition: + case protocol_Gameplay_RemoveObject: + { + Client::GameClientState::RemoveObj* protocolData = new Client::GameClientState::RemoveObj; + protocolData->object_ID = p[1].value.netInt; + + if(dynamic_cast(gameClientState)) + ((Client::GameState*)gameClientState)->Protocol(protocolData); + + delete protocolData; + protocolData = NULL; + } + break; + case protocol_Gameplay_ObjectPosition: { Client::GameClientState::ObjPos* protocolData = new Client::GameClientState::ObjPos; @@ -113,7 +132,6 @@ namespace DanBias } public: - //Client::GameClientState* gameClientState; WindowShell* window; InputClass* inputObj; Utility::WinTimer* timer; diff --git a/Code/Game/DanBiasGame/GameClientState/GameClientState.h b/Code/Game/DanBiasGame/GameClientState/GameClientState.h index fedf95df..2ba930b7 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameClientState.h +++ b/Code/Game/DanBiasGame/GameClientState/GameClientState.h @@ -28,6 +28,11 @@ public: char* path; float worldPos[16]; }; + struct RemoveObj :public ProtocolStruct + { + int object_ID; + //particle effect + }; struct KeyInput :public ProtocolStruct { bool key[6]; diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index 89c320d0..cfbc13cf 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -4,6 +4,7 @@ #include "C_obj/C_DynamicObj.h" #include "NetworkClient.h" #include "PlayerProtocols.h" +#include "ControlProtocols.h" using namespace DanBias::Client; @@ -83,10 +84,15 @@ GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyI switch (privData->state) { case gameStateState_loading: - // load map - // wait for all players - LoadGame(); - privData->state = gameStateState_playing; + { + // load map + // wait for all players + LoadGame(); + GameLogic::Protocol_Status gameStatus; + gameStatus.status = GameLogic::Protocol_Status::States_ready; + privData->nwClient->Send(gameStatus); + privData->state = gameStateState_playing; + } break; case gameStateState_playing: // read server data @@ -180,15 +186,7 @@ bool GameState::Release() void GameState::Protocol(ProtocolStruct* pos) { - // move message - /* - if ((KeyInput*)pos) - { - } - if((ObjPos*)pos) - ObjectPosProtocol((ObjPos*)pos); - else if((PlayerPos*)pos) - PlayerPosProtocol((PlayerPos*)pos);*/ + } void GameState::Protocol( PlayerPos* pos ) @@ -224,6 +222,7 @@ void GameState::Protocol( NewObj* pos ) modelData.world = world; modelData.visible = true; + //not sure if this is good parsing rom char* to wstring const char* path = pos->path; modelData.modelPath = std::wstring(path, path + strlen(path)); // load models @@ -240,6 +239,11 @@ void GameState::Protocol( KeyInput* pos ) } } +void DanBias::Client::GameState::Protocol( RemoveObj* obj ) +{ + privData->object[obj->object_ID]->Release( ); +} + void GameState::PlayerPosProtocol(PlayerPos* pos) { Oyster::Math::Float4x4 world, translate; diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.h b/Code/Game/DanBiasGame/GameClientState/GameState.h index 1da091ea..bc0e8dba 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.h +++ b/Code/Game/DanBiasGame/GameClientState/GameState.h @@ -36,6 +36,7 @@ public: void Protocol(ObjPos* pos); void Protocol(KeyInput* pos); void Protocol( NewObj* pos ); + void Protocol(RemoveObj* obj); void PlayerPosProtocol(PlayerPos* pos); void ObjectPosProtocol(ObjPos* pos); //void Protocol(LightPos pos); diff --git a/Code/Game/GameProtocols/ControlProtocols.h b/Code/Game/GameProtocols/ControlProtocols.h new file mode 100644 index 00000000..93c6b528 --- /dev/null +++ b/Code/Game/GameProtocols/ControlProtocols.h @@ -0,0 +1,38 @@ +#ifndef GAMELOGIC_CONTROL_PROTOCOLS_H +#define GAMELOGIC_CONTROL_PROTOCOLS_H + +#include +#include "ProtocolIdentificationID.h" + +namespace GameLogic +{ + struct Protocol_Status :public Oyster::Network::CustomProtocolObject + { + enum States + { + States_ready, + States_idle, + States_bussy, + States_disconected, + }; + States status; + + Protocol_Status() + { + this->protocol[0].value = protocol_Status; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + + this->protocol[1].type = Oyster::Network::NetAttributeType_Short; + } + Oyster::Network::CustomNetProtocol* GetProtocol() override + { + this->protocol[1].value = status; + + return &protocol; + } + + private: + Oyster::Network::CustomNetProtocol protocol; + }; +} +#endif //!GAMELOGIC_CONTROL_PROTOCOLS_H \ No newline at end of file diff --git a/Code/Game/GameProtocols/GameProtocols.vcxproj b/Code/Game/GameProtocols/GameProtocols.vcxproj index 12584afb..da83ab6c 100644 --- a/Code/Game/GameProtocols/GameProtocols.vcxproj +++ b/Code/Game/GameProtocols/GameProtocols.vcxproj @@ -154,6 +154,7 @@ + diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index 50dbf530..38ab11a2 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -17,8 +17,8 @@ namespace GameLogic Protocol_CreateObject() { - this->protocol[0].value = protocol_Gamplay_CreateObject; - this->protocol[0].type = Oyster::Network::NetAttributeType_Int; + this->protocol[0].value = protocol_Gameplay_CreateObject; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Int; this->protocol[2].type = Oyster::Network::NetAttributeType_CharArray; @@ -79,7 +79,7 @@ namespace GameLogic Protocol_ObjectPosition() { - this->protocol[0].value = protocol_Gamplay_ObjectPosition; + this->protocol[0].value = protocol_Gameplay_ObjectPosition; this->protocol[0].type = Oyster::Network::NetAttributeType_Int; this->protocol[1].type = Oyster::Network::NetAttributeType_Int; @@ -129,6 +129,27 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; + struct Protocol_RemoveObject :public Oyster::Network::CustomProtocolObject + { + int object_ID; + + Protocol_RemoveObject() + { + this->protocol[0].value = protocol_Gameplay_RemoveObject; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + + this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + } + Oyster::Network::CustomNetProtocol* GetProtocol() override + { + + this->protocol[1].value = object_ID; + return &protocol; + } + + private: + Oyster::Network::CustomNetProtocol protocol; + }; } #endif // !GAMELOGIC_PLAYER_PROTOCOLS_H \ No newline at end of file diff --git a/Code/Game/GameProtocols/PlayerProtocols.h b/Code/Game/GameProtocols/PlayerProtocols.h index 159d9403..c578f69e 100644 --- a/Code/Game/GameProtocols/PlayerProtocols.h +++ b/Code/Game/GameProtocols/PlayerProtocols.h @@ -25,7 +25,7 @@ namespace GameLogic Protocol_PlayerMovement() { - this->protocol[0].value = protocol_Gamplay_PlayerNavigation; + this->protocol[0].value = protocol_Gameplay_PlayerNavigation; this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Bool; @@ -60,7 +60,7 @@ namespace GameLogic Protocol_PlayerMouse() { - this->protocol[0].value = protocol_Gamplay_PlayerMouseMovement; + this->protocol[0].value = protocol_Gameplay_PlayerMouseMovement; this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Float; @@ -87,7 +87,7 @@ namespace GameLogic Protocol_PlayerPosition() { - this->protocol[0].value = protocol_Gamplay_PlayerPosition; + this->protocol[0].value = protocol_Gameplay_PlayerPosition; this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Float; diff --git a/Code/Game/GameProtocols/ProtocolIdentificationID.h b/Code/Game/GameProtocols/ProtocolIdentificationID.h index 8e575502..91a960b0 100644 --- a/Code/Game/GameProtocols/ProtocolIdentificationID.h +++ b/Code/Game/GameProtocols/ProtocolIdentificationID.h @@ -7,12 +7,14 @@ /* THERE CAN ABSOLUTLEY NOT BE TWO DEFINITIONS WITH THE SAME ID!! */ -#define protocol_Gamplay_PlayerNavigation 0 -#define protocol_Gamplay_PlayerMouseMovement 1 -#define protocol_Gamplay_PlayerPosition 2 -#define protocol_Gamplay_CreateObject 3 -#define protocol_Gamplay_ObjectPosition 4 +#define protocol_Gameplay_PlayerNavigation 0 +#define protocol_Gameplay_PlayerMouseMovement 1 +#define protocol_Gameplay_PlayerPosition 2 +#define protocol_Gameplay_CreateObject 3 +#define protocol_Gameplay_RemoveObject 4 +#define protocol_Gameplay_ObjectPosition 5 +#define protocol_Status 50 #define protocol_Lobby_Msg 100