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

96 lines
2.1 KiB
C++
Raw Normal View History

2014-02-14 14:32:17 +01:00
#include "NetLoadState.h"
#include "NetworkClient.h"
2014-02-17 11:50:51 +01:00
#include "OysterMath.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;
2014-02-17 11:50:51 +01:00
using namespace ::Oyster::Math;
2014-02-14 14:32:17 +01:00
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;
2014-02-17 11:27:43 +01:00
Graphics::API::Texture background;
2014-02-14 17:12:38 +01:00
bool loading;
2014-02-14 14:32:17 +01:00
};
NetLoadState::NetLoadState(void) {}
NetLoadState::~NetLoadState(void)
{
if( this->privData )
this->Release();
}
2014-02-17 11:27:43 +01:00
bool NetLoadState::Init( SharedStateContent &shared )
2014-02-14 14:32:17 +01:00
{
this->privData = new MyData();
this->privData->nextState = GameClientState::ClientState_Same;
2014-02-17 11:27:43 +01:00
this->privData->nwClient = shared.network;
this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" );
2014-02-14 17:12:38 +01:00
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
2014-02-17 11:27:43 +01:00
this->privData->nwClient->Send( Protocol_QuerryGameType() );
2014-02-14 14:32:17 +01:00
return true;
}
2014-02-17 11:27:43 +01:00
GameClientState::ClientState NetLoadState::Update( float deltaTime )
2014-02-14 14:32:17 +01:00
{
return this->privData->nextState;
}
bool NetLoadState::Render()
{
2014-02-17 11:27:43 +01:00
Graphics::API::NewFrame();
Graphics::API::StartGuiRender();
Graphics::API::RenderGuiElement( this->privData->background, Float3(0.5f, 0.5f, 1.0f), Float2(1.0f) );
Graphics::API::EndFrame();
2014-02-14 14:32:17 +01:00
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 )
{
2014-02-18 08:55:38 +01:00
this->LoadGame( Protocol_LobbyCreateGame(e.args.data.protocol).mapName );
2014-02-14 17:12:38 +01:00
}
}
void NetLoadState::LoadGame( const ::std::string &fileName )
{
this->privData->loading = true;
// TODO: ask Sam about level loader
this->privData->nextState = ClientState::ClientState_Game;
}