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

140 lines
3.0 KiB
C++
Raw Normal View History

2014-02-12 09:49:08 +01:00
#include "MainState.h"
2014-01-30 11:58:44 +01:00
#include "DllInterfaces/GFXAPI.h"
#include "OysterMath.h"
#include "C_obj/C_Player.h"
#include "C_obj/C_StaticObj.h"
#include "C_obj/C_DynamicObj.h"
#include <GameServerAPI.h>
2014-02-12 10:43:06 +01:00
#include "NetworkClient.h"
2014-01-30 11:58:44 +01:00
2014-02-12 14:33:56 +01:00
#include "EventHandler\EventHandler.h"
#include "Buttons\ButtonRectangle.h"
2014-02-12 10:43:06 +01:00
using namespace ::DanBias::Client;
2014-02-12 15:05:36 +01:00
using namespace ::Oyster;
2014-02-12 10:43:06 +01:00
using namespace ::Oyster::Math3D;
using namespace ::Oyster::Network;
2014-02-12 15:05:36 +01:00
using namespace ::Oyster::Event;
2014-02-12 10:43:06 +01:00
using namespace ::Utility::DynamicMemory;
2014-02-12 14:33:56 +01:00
using namespace ::Utility::StaticArray;
2014-01-30 11:58:44 +01:00
2014-02-12 10:43:06 +01:00
struct MainState::MyData
2014-01-30 11:58:44 +01:00
{
2014-02-12 10:43:06 +01:00
MyData() {}
Float4x4 view;
Float4x4 proj;
UniquePointer<C_Object> object[2];
NetworkClient *nwClient;
2014-02-12 15:05:36 +01:00
2014-02-12 14:33:56 +01:00
EventButtonCollection button;
2014-02-12 10:43:06 +01:00
};
2014-01-30 11:58:44 +01:00
2014-02-12 14:33:56 +01:00
void OnButtonInteract( Oyster::Event::ButtonEvent<GameClientState*>& e );
2014-02-12 09:49:08 +01:00
MainState::MainState(void) {}
2014-01-30 11:58:44 +01:00
2014-02-12 09:49:08 +01:00
MainState::~MainState(void) {}
2014-01-30 11:58:44 +01:00
2014-02-12 10:43:06 +01:00
bool MainState::Init( NetworkClient* nwClient )
2014-01-30 11:58:44 +01:00
{
2014-02-12 10:43:06 +01:00
this->privData = new MyData();
2014-02-12 14:33:56 +01:00
// create buttons
2014-02-12 15:02:29 +01:00
ButtonRectangle<GameClientState*> *button = new ButtonRectangle<GameClientState*>( L"earth_md.png", OnButtonInteract, this, 0.5f, 0.5f, 0.1f, 0.1f, true );
2014-02-12 14:33:56 +01:00
this->privData->button.AddButton( button );
// bind button collection to the singleton eventhandler
EventHandler::Instance().AddCollection( &this->privData->button );
2014-01-30 11:58:44 +01:00
return true;
}
2014-02-12 09:49:08 +01:00
GameClientState::ClientState MainState::Update(float deltaTime, InputClass* KeyInput)
2014-01-30 11:58:44 +01:00
{
// picking
// mouse events
// different menus
// play sounds
// update animation
// send data to server
// check data from server
// create game
if( KeyInput->IsKeyPressed(DIK_C))
{
DanBias::GameServerAPI::ServerInitDesc desc;
DanBias::GameServerAPI::ServerInitiate(desc);
DanBias::GameServerAPI::ServerStart();
// my ip
2014-02-12 10:43:06 +01:00
this->privData->nwClient->Connect(15152, "127.0.0.1");
2014-01-30 11:58:44 +01:00
2014-02-12 10:43:06 +01:00
if (!this->privData->nwClient->IsConnected())
2014-01-30 11:58:44 +01:00
{
// failed to connect
return ClientState_Same;
}
return ClientState_LobbyCreated;
2014-01-30 11:58:44 +01:00
}
// join game
if( KeyInput->IsKeyPressed(DIK_J))
{
// game ip
2014-02-12 10:43:06 +01:00
this->privData->nwClient->Connect(15152, "127.0.0.1");
2014-02-10 22:25:31 +01:00
//nwClient->Connect(15152, "83.254.217.248");
2014-01-30 11:58:44 +01:00
2014-02-12 10:43:06 +01:00
if (!this->privData->nwClient->IsConnected())
2014-01-30 11:58:44 +01:00
{
// failed to connect
return ClientState_Same;
}
return ClientState_Lobby;
}
return ClientState_Same;
}
2014-02-12 09:49:08 +01:00
bool MainState::Render()
2014-01-30 11:58:44 +01:00
{
2014-02-12 15:05:36 +01:00
Graphics::API::SetView(privData->view);
Graphics::API::SetProjection( privData->proj);
2014-01-30 11:58:44 +01:00
2014-02-12 15:05:36 +01:00
Graphics::API::NewFrame();
2014-01-30 11:58:44 +01:00
// render objects
2014-02-12 14:33:56 +01:00
//for (int i = 0; i < NumElementsOf(privData->object); i++)
//{
// privData->object[i]->Render();
//}
2014-02-12 15:05:36 +01:00
Graphics::API::StartGuiRender();
2014-02-12 14:33:56 +01:00
this->privData->button.Render();
2014-01-30 11:58:44 +01:00
// render effects
// render lights
2014-02-12 15:05:36 +01:00
Graphics::API::EndFrame();
2014-01-30 11:58:44 +01:00
return true;
}
2014-02-12 09:49:08 +01:00
bool MainState::Release()
2014-01-30 11:58:44 +01:00
{
2014-02-12 14:33:56 +01:00
for (int i = 0; i < NumElementsOf(privData->object); i++)
2014-01-30 11:58:44 +01:00
{
privData->object[i] = NULL;
}
privData = NULL;
2014-02-12 14:33:56 +01:00
// button collection will be autoreleased from EventHandler
2014-01-30 11:58:44 +01:00
return true;
}
2014-02-12 14:33:56 +01:00
/// button actions
void OnButtonInteract( Oyster::Event::ButtonEvent<GameClientState*>& e )
{
}