From a85b803e5cbfea72144ea478db457c560fb092ae Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 18 Feb 2014 17:28:24 +0100 Subject: [PATCH] GameClientState Patch virtual void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e ); changed to virtual const NetEvent & DataRecieved( const NetEvent &message ); /****************************************************************** * @param message of the event * @return message or GameClientState::event_processed. ******************************************************************/ --- .../GameClientState/GameClientState.cpp | 9 +++++-- .../GameClientState/GameClientState.h | 10 +++++-- .../GameClient/GameClientState/GameState.cpp | 26 +++++++++++-------- .../GameClient/GameClientState/GameState.h | 2 +- .../GameClientState/LanMenuState.cpp | 10 ------- .../GameClient/GameClientState/LanMenuState.h | 2 -- .../GameClientState/LobbyAdminState.cpp | 7 ++--- .../GameClientState/LobbyAdminState.h | 4 +-- .../GameClient/GameClientState/LobbyState.cpp | 8 +++--- .../GameClient/GameClientState/LobbyState.h | 2 +- .../GameClientState/NetLoadState.cpp | 17 +++++++----- .../GameClient/GameClientState/NetLoadState.h | 2 +- 12 files changed, 55 insertions(+), 44 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameClientState.cpp b/Code/Game/GameClient/GameClientState/GameClientState.cpp index dab88b2e..add8c15b 100644 --- a/Code/Game/GameClient/GameClientState/GameClientState.cpp +++ b/Code/Game/GameClient/GameClientState/GameClientState.cpp @@ -3,9 +3,14 @@ using namespace DanBias::Client; using namespace ::Oyster::Network; +const GameClientState::NetEvent GameClientState::event_processed = GameClientState::NetEvent(); + GameClientState::GameClientState() {} GameClientState::~GameClientState() {} -void GameClientState::DataRecieved( NetEvent e ) -{ /* do nothing */ } \ No newline at end of file +const GameClientState::NetEvent & GameClientState::DataRecieved( const GameClientState::NetEvent &message ) +{ + /* do nothing */ + return message; +} \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/GameClientState.h b/Code/Game/GameClient/GameClientState/GameClientState.h index 3822c7b0..9891a16c 100644 --- a/Code/Game/GameClient/GameClientState/GameClientState.h +++ b/Code/Game/GameClient/GameClientState/GameClientState.h @@ -22,7 +22,9 @@ namespace DanBias { namespace Client ClientState_Quit }; - public: + typedef ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> NetEvent; + static const NetEvent event_processed; + GameClientState(); virtual ~GameClientState(); virtual bool Init( SharedStateContent &shared ) = 0; @@ -31,7 +33,11 @@ namespace DanBias { namespace Client virtual bool Release() = 0; virtual void ChangeState( ClientState next ) = 0; - virtual void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e ); + /****************************************************************** + * @param message of the event + * @return message or GameClientState::event_processed. + ******************************************************************/ + virtual const NetEvent & DataRecieved( const NetEvent &message ); }; } } diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 9a0bd4db..c6d77f76 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -312,20 +312,22 @@ void GameState::ReadKeyInput() // TODO: implement sub-menu } -void GameState::DataRecieved( NetEvent e ) +const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState::NetEvent &message ) { - if( e.args.type == NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend ) + if( message.args.type == NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend ) { // TODO: Reconnect const char *breakpoint = "temp trap"; this->privData->nwClient->Disconnect(); this->ChangeState( GameClientState::ClientState_Main ); } - CustomNetProtocol data = e.args.data.protocol; - short ID = data[0].value.netShort; // fetching the id data. + // fetching the id data. + short ID = message.args.data.protocol[0].value.netShort; if( ProtocolIsGameplay(ID) ) { + CustomNetProtocol data = message.args.data.protocol; + switch(ID) { case protocol_Gameplay_ObjectPickup: break; /** @todo TODO: implement */ @@ -341,13 +343,13 @@ void GameState::DataRecieved( NetEventprivData->dynamicObjects)[decoded.object_ID]->setPos( decoded.position ); } - break; + return GameClientState::event_processed; case protocol_Gameplay_ObjectScale: { Protocol_ObjectScale decoded(data); (*this->privData->dynamicObjects)[decoded.object_ID]->setScale( decoded.scale ); } - break; + return GameClientState::event_processed; case protocol_Gameplay_ObjectRotation: { Protocol_ObjectRotation decoded(data); @@ -359,7 +361,7 @@ void GameState::DataRecieved( NetEventprivData->dynamicObjects)[decoded.object_ID]->setRot( rotation ); } - break; + return GameClientState::event_processed; case protocol_Gameplay_ObjectPositionRotation: { Protocol_ObjectPositionRotation decoded(data); @@ -380,7 +382,7 @@ void GameState::DataRecieved( NetEventsetRot( rotation ); } } - break; + return GameClientState::event_processed; case protocol_Gameplay_ObjectEnabled: break; /** @todo TODO: implement */ case protocol_Gameplay_ObjectDisabled: { @@ -393,7 +395,7 @@ void GameState::DataRecieved( NetEventprivData->dynamicObjects->erase( object ); } } - break; + return GameClientState::event_processed; case protocol_Gameplay_ObjectCreate: { Protocol_ObjectCreate decoded(data); @@ -414,13 +416,13 @@ void GameState::DataRecieved( NetEventprivData->dynamicObjects)[decoded.object_ID] = object; } - break; + return GameClientState::event_processed; case protocol_Gameplay_ObjectCreatePlayer: { Protocol_ObjectCreatePlayer decoded(data); this->InitiatePlayer( decoded.object_ID, decoded.meshName, decoded.position, decoded.rotationQ, decoded.scale, decoded.owner ); } - break; + return GameClientState::event_processed; case protocol_Gameplay_ObjectJoinTeam: break; /** @todo TODO: implement */ case protocol_Gameplay_ObjectLeaveTeam: break; /** @todo TODO: implement */ case protocol_Gameplay_ObjectWeaponCooldown: break; /** @todo TODO: implement */ @@ -439,4 +441,6 @@ void GameState::DataRecieved( NetEvent e ); + const NetEvent & DataRecieved( const NetEvent &message ); private: struct MyData; diff --git a/Code/Game/GameClient/GameClientState/LanMenuState.cpp b/Code/Game/GameClient/GameClientState/LanMenuState.cpp index 178739d3..11ca95da 100644 --- a/Code/Game/GameClient/GameClientState/LanMenuState.cpp +++ b/Code/Game/GameClient/GameClientState/LanMenuState.cpp @@ -133,16 +133,6 @@ void LanMenuState::ChangeState( ClientState next ) this->privData->nextState = next; } -void LanMenuState::DataRecieved( NetEvent e ) -{ - if( e.args.type == NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend ) - { // TODO: Reconnect - const char *breakpoint = "temp trap"; - this->privData->nwClient->Disconnect(); - this->ChangeState( GameClientState::ClientState_Same ); - } -} - void OnButtonInteract_Connect( Oyster::Event::ButtonEvent& e ) { switch( e.state ) diff --git a/Code/Game/GameClient/GameClientState/LanMenuState.h b/Code/Game/GameClient/GameClientState/LanMenuState.h index 9c6a8ec4..57889eee 100644 --- a/Code/Game/GameClient/GameClientState/LanMenuState.h +++ b/Code/Game/GameClient/GameClientState/LanMenuState.h @@ -21,8 +21,6 @@ namespace DanBias virtual bool Release(); void ChangeState( ClientState next ); - void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e ); - private: struct MyData; ::Utility::DynamicMemory::UniquePointer privData; diff --git a/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp b/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp index 070d8b48..43419e88 100644 --- a/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp +++ b/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp @@ -112,10 +112,10 @@ void LobbyAdminState::ChangeState( ClientState next ) using namespace ::Oyster::Network; -void LobbyAdminState::DataRecieved( NetEvent e ) +const GameClientState::NetEvent & LobbyAdminState::DataRecieved( const GameClientState::NetEvent &message ) { - CustomNetProtocol data = e.args.data.protocol; - short ID = data[0].value.netShort; // fetching the id data. + // fetching the id data. + short ID = message.args.data.protocol[0].value.netShort; // Block irrelevant messages. if( ProtocolIsLobby(ID) ) @@ -141,6 +141,7 @@ void LobbyAdminState::DataRecieved( NetEvent& e ) diff --git a/Code/Game/GameClient/GameClientState/LobbyAdminState.h b/Code/Game/GameClient/GameClientState/LobbyAdminState.h index 49ae9274..7e201e94 100644 --- a/Code/Game/GameClient/GameClientState/LobbyAdminState.h +++ b/Code/Game/GameClient/GameClientState/LobbyAdminState.h @@ -29,8 +29,8 @@ namespace DanBias bool Render(); bool Release(); void ChangeState( ClientState next ); - void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e ); - + const NetEvent & DataRecieved( const NetEvent &message ); + private: struct MyData; ::Utility::DynamicMemory::UniquePointer privData; diff --git a/Code/Game/GameClient/GameClientState/LobbyState.cpp b/Code/Game/GameClient/GameClientState/LobbyState.cpp index a6d03527..0b117016 100644 --- a/Code/Game/GameClient/GameClientState/LobbyState.cpp +++ b/Code/Game/GameClient/GameClientState/LobbyState.cpp @@ -112,10 +112,10 @@ void LobbyState::ChangeState( ClientState next ) using namespace ::Oyster::Network; -void LobbyState::DataRecieved( NetEvent e ) +const GameClientState::NetEvent & LobbyState::DataRecieved( const GameClientState::NetEvent &message ) { - CustomNetProtocol data = e.args.data.protocol; - short ID = data[0].value.netShort; // fetching the id data. + // fetching the id data. + short ID = message.args.data.protocol[0].value.netShort; // Block irrelevant messages. if( ProtocolIsLobby(ID) ) @@ -141,6 +141,8 @@ void LobbyState::DataRecieved( NetEvent& e ) diff --git a/Code/Game/GameClient/GameClientState/LobbyState.h b/Code/Game/GameClient/GameClientState/LobbyState.h index 694aaa38..496c54ed 100644 --- a/Code/Game/GameClient/GameClientState/LobbyState.h +++ b/Code/Game/GameClient/GameClientState/LobbyState.h @@ -31,7 +31,7 @@ namespace DanBias bool Render(); bool Release(); void ChangeState( ClientState next ); - void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e ); + const NetEvent & DataRecieved( const NetEvent &message ); private: struct MyData; diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.cpp b/Code/Game/GameClient/GameClientState/NetLoadState.cpp index 9a88072c..29906d77 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.cpp +++ b/Code/Game/GameClient/GameClientState/NetLoadState.cpp @@ -90,20 +90,25 @@ void NetLoadState::ChangeState( ClientState next ) this->privData->nextState = next; } -void NetLoadState::DataRecieved( NetEvent e ) +const GameClientState::NetEvent & NetLoadState::DataRecieved( const GameClientState::NetEvent &message ) { // fetching the id data. - short ID = e.args.data.protocol[0].value.netShort; + short ID = message.args.data.protocol[0].value.netShort; - if( ID == protocol_Lobby_CreateGame && !this->privData->loading ) + if( ID == protocol_Lobby_CreateGame ) { - this->LoadGame( Protocol_LobbyCreateGame(e.args.data.protocol).mapName ); - this->ChangeState( ClientState_Game ); - this->privData->loading = false; + if( !this->privData->loading ) + { + this->LoadGame( Protocol_LobbyCreateGame(message.args.data.protocol).mapName ); + this->ChangeState( ClientState_Game ); + this->privData->loading = false; + } + return GameClientState::event_processed; } else { // HACK: Debug trap const char *breakPoint = "Being greedy."; + return message; } } diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.h b/Code/Game/GameClient/GameClientState/NetLoadState.h index ea9f9f6a..16e32867 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.h +++ b/Code/Game/GameClient/GameClientState/NetLoadState.h @@ -21,7 +21,7 @@ namespace DanBias bool Release(); void ChangeState( ClientState next ); - void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e ); + const NetEvent & DataRecieved( const NetEvent &message ); private: struct MyData;