Danbias/Code/Game/DanBiasGame/GameClientState/NetLoadState.cpp

85 lines
1.7 KiB
C++
Raw Normal View History

2014-02-14 14:32:17 +01:00
#include "NetLoadState.h"
#include "NetworkClient.h"
2014-02-14 17:12:38 +01:00
#include "../Game/GameProtocols/Protocols.h"
2014-02-14 14:32:17 +01:00
using namespace ::DanBias::Client;
using namespace ::Oyster;
using namespace ::Oyster::Network;
2014-02-14 17:12:38 +01:00
using namespace ::GameLogic;
2014-02-14 14:32:17 +01:00
struct NetLoadState::MyData
{
MyData() {}
GameClientState::ClientState nextState;
2014-02-14 17:12:38 +01:00
NetworkClient *nwClient;
bool loading;
2014-02-14 14:32:17 +01:00
};
NetLoadState::NetLoadState(void) {}
NetLoadState::~NetLoadState(void)
{
if( this->privData )
this->Release();
}
bool NetLoadState::Init( NetworkClient* nwClient )
{
this->privData = new MyData();
this->privData->nextState = GameClientState::ClientState_Same;
2014-02-14 17:12:38 +01:00
this->privData->nwClient = nwClient;
this->privData->loading = false;
2014-02-14 14:32:17 +01:00
// we may assume that nwClient is properly connected to the server
2014-02-14 17:12:38 +01:00
// signals querry to server for loading instructions
nwClient->Send( Protocol_QuerryGameType() );
2014-02-14 14:32:17 +01:00
return true;
}
GameClientState::ClientState NetLoadState::Update(float deltaTime, InputClass* KeyInput)
{
return this->privData->nextState;
}
bool NetLoadState::Render()
{
return true;
}
bool NetLoadState::Release()
{
if( this->privData )
{
this->privData = NULL;
}
return true;
}
void NetLoadState::ChangeState( ClientState next )
{
this->privData->nextState = next;
}
void NetLoadState::DataRecieved( NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e )
{
2014-02-14 17:12:38 +01:00
// fetching the id data.
short ID = e.args.data.protocol[0].value.netShort;
2014-02-14 17:12:38 +01:00
if( ID == protocol_Lobby_CreateGame && !this->privData->loading )
{
this->LoadGame( Protocol_LobbyCreateGame(e.args.data.protocol).modelName );
}
}
void NetLoadState::LoadGame( const ::std::string &fileName )
{
this->privData->loading = true;
// TODO: ask Sam about level loader
this->privData->nextState = ClientState::ClientState_Game;
}