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.
******************************************************************/
This commit is contained in:
Dander7BD 2014-02-18 17:28:24 +01:00
parent f2cbbfcf69
commit a85b803e5c
12 changed files with 55 additions and 44 deletions

View File

@ -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<NetworkClient*, NetworkClient::ClientEventArgs> e )
{ /* do nothing */ }
const GameClientState::NetEvent & GameClientState::DataRecieved( const GameClientState::NetEvent &message )
{
/* do nothing */
return message;
}

View File

@ -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 );
};
} }

View File

@ -312,20 +312,22 @@ void GameState::ReadKeyInput()
// TODO: implement sub-menu
}
void GameState::DataRecieved( NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> 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( NetEvent<NetworkClient*, NetworkClient::ClientEven
(*this->privData->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( NetEvent<NetworkClient*, NetworkClient::ClientEven
(*this->privData->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( NetEvent<NetworkClient*, NetworkClient::ClientEven
object->setRot( 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( NetEvent<NetworkClient*, NetworkClient::ClientEven
this->privData->dynamicObjects->erase( object );
}
}
break;
return GameClientState::event_processed;
case protocol_Gameplay_ObjectCreate:
{
Protocol_ObjectCreate decoded(data);
@ -414,13 +416,13 @@ void GameState::DataRecieved( NetEvent<NetworkClient*, NetworkClient::ClientEven
(*this->privData->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<NetworkClient*, NetworkClient::ClientEven
default: break;
}
}
return message;
}

View File

@ -26,7 +26,7 @@ namespace DanBias { namespace Client
bool Release()override;
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;

View File

@ -133,16 +133,6 @@ void LanMenuState::ChangeState( ClientState next )
this->privData->nextState = next;
}
void LanMenuState::DataRecieved( NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> 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<LanMenuState*>& e )
{
switch( e.state )

View File

@ -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<MyData> privData;

View File

@ -112,10 +112,10 @@ void LobbyAdminState::ChangeState( ClientState next )
using namespace ::Oyster::Network;
void LobbyAdminState::DataRecieved( NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> 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<NetworkClient*, NetworkClient::Clie
default: break;
}
}
return message;
}
void OnButtonInteract_Ready( Oyster::Event::ButtonEvent<LobbyAdminState*>& e )

View File

@ -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<MyData> privData;

View File

@ -112,10 +112,10 @@ void LobbyState::ChangeState( ClientState next )
using namespace ::Oyster::Network;
void LobbyState::DataRecieved( NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> 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<NetworkClient*, NetworkClient::ClientEve
default: break;
}
}
return message;
}
void OnButtonInteract_Ready( Oyster::Event::ButtonEvent<LobbyState*>& e )

View File

@ -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;

View File

@ -90,20 +90,25 @@ void NetLoadState::ChangeState( ClientState next )
this->privData->nextState = next;
}
void NetLoadState::DataRecieved( NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> 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;
}
}

View File

@ -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;