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

142 lines
3.1 KiB
C++
Raw Normal View History

2014-01-30 23:23:37 +01:00
#include "LanMenuState.h"
#include "C_obj/C_Player.h"
#include "C_obj/C_StaticObj.h"
#include "C_obj/C_DynamicObj.h"
#include "DllInterfaces/GFXAPI.h"
2014-01-31 14:14:20 +01:00
#include "LobbyState.h"
#include "GameState.h"
2014-02-12 10:43:06 +01:00
#include "../Network/NetworkAPI/NetworkClient.h"
2014-01-31 14:14:20 +01:00
2014-01-30 23:23:37 +01:00
#include <GameServerAPI.h>
2014-02-12 10:43:06 +01:00
using namespace ::DanBias::Client;
2014-02-12 16:31:15 +01:00
using namespace ::Oyster;
2014-02-12 10:43:06 +01:00
using namespace ::Oyster::Network;
2014-01-30 23:23:37 +01:00
2014-02-12 16:31:15 +01:00
struct LanMenuState::MyData
2014-01-30 23:23:37 +01:00
{
2014-02-12 16:31:15 +01:00
MyData(){}
2014-01-31 14:14:20 +01:00
2014-02-12 16:31:15 +01:00
GameClientState::ClientState nextState;
NetworkClient *nwClient;
2014-01-31 14:14:20 +01:00
2014-02-12 09:49:08 +01:00
} privData;
2014-01-30 23:23:37 +01:00
2014-02-12 09:49:08 +01:00
LanMenuState::LanMenuState() {}
2014-01-30 23:23:37 +01:00
2014-02-12 09:49:08 +01:00
LanMenuState::~LanMenuState() {}
2014-01-30 23:23:37 +01:00
2014-02-12 16:31:15 +01:00
bool LanMenuState::Init(Network::NetworkClient* nwClient)
2014-01-30 23:23:37 +01:00
{
2014-02-12 16:31:15 +01:00
privData = new MyData();
2014-01-30 23:23:37 +01:00
2014-02-12 16:31:15 +01:00
this->privData->nextState = GameClientState::ClientState_Same;
this->privData->nwClient = nwClient;
2014-01-30 23:23:37 +01:00
return true;
}
GameClientState::ClientState LanMenuState::Update(float deltaTime, InputClass* KeyInput)
2014-01-31 14:14:20 +01:00
{
/*ChangeState(KeyInput);
if(privData->recieverObj->IsConnected())
privData->recieverObj->Update();
KeyInput->Update();
if(privData->serverOwner)
{
DanBias::GameServerAPI::ServerUpdate();
}
DanBias::Client::GameClientState::ClientState state = DanBias::Client::GameClientState::ClientState_Same;
state = privData->recieverObj->gameClientState->Update(deltaTime, KeyInput);
if(state != Client::GameClientState::ClientState_Same)
{
privData->recieverObj->gameClientState->Release();
delete privData->recieverObj->gameClientState;
privData->recieverObj->gameClientState = NULL;
switch (state)
{
case Client::GameClientState::ClientState_LobbyCreated:
privData->serverOwner = true;
case Client::GameClientState::ClientState_Lobby:
privData->recieverObj->gameClientState = new Client::LobbyState();
break;
case Client::GameClientState::ClientState_Game:
privData->recieverObj->gameClientState = new Client::GameState();
break;
default:
//return E_FAIL;
break;
}
privData->recieverObj->gameClientState->Init(privData->recieverObj); // send game client
}*/
2014-02-12 16:31:15 +01:00
//return ChangeState(KeyInput);
return this->privData->nextState;
2014-01-31 14:14:20 +01:00
}
2014-02-12 16:31:15 +01:00
//GameClientState::ClientState LanMenuState::ChangeState(InputClass* KeyInput)
//{
// // create game
// if( KeyInput->IsKeyPressed(DIK_C))
// {
// DanBias::GameServerAPI::ServerInitDesc desc;
//
// DanBias::GameServerAPI::ServerInitiate(desc);
// DanBias::GameServerAPI::ServerStart();
// // my ip
// nwClient->Connect(15151, "127.0.0.1");
//
// if (!nwClient->IsConnected())
// {
// // failed to connect
// return ClientState_Same;
// }
// return ClientState_Lobby;
// }
// // join game
// if( KeyInput->IsKeyPressed(DIK_J))
// {
// // game ip
// nwClient->Connect(15151, "194.47.150.56");
//
// if (!nwClient->IsConnected())
// {
// // failed to connect
// return ClientState_Same;
// }
// return ClientState_Lobby;
// }
// return ClientState_Same;
//}
2014-01-30 23:23:37 +01:00
2014-02-12 14:33:56 +01:00
bool LanMenuState::Render( )
2014-01-30 23:23:37 +01:00
{
2014-02-12 16:31:15 +01:00
Graphics::API::NewFrame();
2014-01-30 23:23:37 +01:00
2014-02-12 16:31:15 +01:00
Graphics::API::StartGuiRender();
2014-01-30 23:23:37 +01:00
2014-02-12 16:31:15 +01:00
Graphics::API::EndFrame();
2014-01-30 23:23:37 +01:00
return true;
}
bool LanMenuState::Release()
{
privData = NULL;
return true;
2014-02-12 16:31:15 +01:00
}
void LanMenuState::ChangeState( ClientState next )
{
this->privData->nextState = next;
2014-01-30 23:23:37 +01:00
}