This commit is contained in:
Dander7BD 2014-02-12 16:31:15 +01:00
parent 587fe62b8e
commit 63bc360645
11 changed files with 323 additions and 482 deletions

View File

@ -18,8 +18,9 @@
#include "../Misc/EventHandler/EventHandler.h"
using namespace ::Oyster::Event;
using namespace Oyster::Network;
using namespace ::Oyster;
using namespace Event;
using namespace Network;
using namespace ::Utility::DynamicMemory;
void ClientEventFunction( NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e );
@ -87,7 +88,8 @@ namespace DanBias
float dt = (float)data.timer.getElapsedSeconds();
data.timer.reset();
::Oyster::Graphics::API::Update( dt );
Graphics::API::Update( dt );
EventHandler::Instance().Update( nullptr );
if(data.networkClient.IsConnected())
data.networkClient.Update();
@ -161,7 +163,7 @@ namespace DanBias
switch (state)
{
case Client::GameClientState::ClientState_LobbyCreated:
case Client::GameClientState::ClientState_LobbyCreate:
data.serverOwner = true;
stateVal = true;
case Client::GameClientState::ClientState_Lobby:

View File

@ -3,13 +3,9 @@
using namespace DanBias::Client;
using namespace ::Oyster::Network;
GameClientState::GameClientState(void)
{
}
GameClientState::GameClientState(void) {}
GameClientState::~GameClientState(void)
{
}
GameClientState::~GameClientState(void) {}
void GameClientState::DataRecieved( NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e )
{ /* do nothing */ }

View File

@ -15,9 +15,10 @@ namespace DanBias { namespace Client
ClientState_Login,
ClientState_Lobby,
ClientState_Lan,
ClientState_LobbyCreated,
ClientState_LobbyCreate,
ClientState_Game,
ClientState_Same,
ClientState_Quit
};
public:
@ -27,6 +28,7 @@ namespace DanBias { namespace Client
virtual ClientState Update(float deltaTime, InputClass* KeyInput) = 0;
virtual bool Render() = 0;
virtual bool Release() = 0;
virtual void ChangeState( ClientState next ) = 0;
virtual void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e );
};

View File

@ -5,15 +5,17 @@
#include "Camera_FPS.h"
#include <GameServerAPI.h>
using namespace DanBias::Client;
using namespace Oyster::Math3D;
using namespace ::DanBias::Client;
using namespace ::Oyster;
using namespace ::Oyster::Network;
using namespace ::Oyster::Math3D;
struct GameState::myData
struct GameState::MyData
{
myData(){}
int modelCount;
Oyster::Network::NetworkClient* nwClient;
gameStateState state;
MyData(){}
GameClientState::ClientState nextState;
NetworkClient *nwClient;
} privData;
GameState::GameState(void)
@ -26,151 +28,64 @@ GameState::GameState(void)
GameState::~GameState(void)
{
delete this->privData;
if( this->privData )
this->Release();
}
bool GameState::Init(Oyster::Network::NetworkClient* nwClient)
bool GameState::Init(NetworkClient* nwClient)
{
// load models
privData = new myData();
privData->state = gameStateState_loading;
privData->nwClient = nwClient;
privData->state = LoadGame();
privData = new MyData();
//tELL SERver ready
this->privData->nextState = GameClientState::ClientState_Same;
this->privData->nwClient = nwClient;
LoadGame();
//tell server ready
nwClient->Send(GameLogic::Protocol_General_Status(GameLogic::Protocol_General_Status::States_ready));
return true;
}
GameState::gameStateState GameState::LoadGame()
{
Oyster::Graphics::Definitions::Pointlight plight;
plight.Pos = Float3(315.0f, 0.0f ,5.0f);
plight.Color = Float3(0.9f,0.7f,0.2f);
plight.Radius = 100.0f;
plight.Bright = 0.9f;
Oyster::Graphics::API::AddLight(plight);
plight.Pos = Float3(10.0f,350.0f,5.0f);
plight.Color = Float3(0.9f,0.7f,0.3f);
plight.Radius = 200.0f;
plight.Bright = 0.7f;
Oyster::Graphics::API::AddLight(plight);
plight.Pos = Float3(350.0f,350.0f,5.0f);
plight.Color = Float3(0.9f,0.7f,0.3f);
plight.Radius = 200.0f;
plight.Bright = 0.7f;
Oyster::Graphics::API::AddLight(plight);
plight.Pos = Float3(10.0f,350.0f,350.0f);
plight.Color = Float3(0.9f,0.7f,0.3f);
plight.Radius = 200.0f;
plight.Bright = 0.7f;
Oyster::Graphics::API::AddLight(plight);
plight.Pos = Float3(10.0f,-15.0f,5.0f);
plight.Color = Float3(0.0f,0.0f,1.0f);
plight.Radius = 50.0f;
plight.Bright = 2.0f;
Oyster::Graphics::API::AddLight(plight);
LoadModels();
InitCamera(Float3(0.0f,0.0f,20.0f));
// hardcoded objects
LoadModels();
Float3 startPos = Float3(0,0,20.0f);
InitCamera(startPos);
// Oyster::Graphics::Definitions::Pointlight plight;
// plight.Pos = Float3(315.0f, 0.0f ,5.0f);
// plight.Color = Float3(0.9f,0.7f,0.2f);
// plight.Radius = 100.0f;
// plight.Bright = 0.9f;
// Oyster::Graphics::API::AddLight(plight);
// plight.Pos = Float3(10.0f,350.0f,5.0f);
// plight.Color = Float3(0.9f,0.7f,0.3f);
// plight.Radius = 200.0f;
// plight.Bright = 0.7f;
// Oyster::Graphics::API::AddLight(plight);
// plight.Pos = Float3(350.0f,350.0f,5.0f);
// plight.Color = Float3(0.9f,0.7f,0.3f);
// plight.Radius = 200.0f;
// plight.Bright = 0.7f;
// Oyster::Graphics::API::AddLight(plight);
// plight.Pos = Float3(10.0f,350.0f,350.0f);
// plight.Color = Float3(0.9f,0.7f,0.3f);
// plight.Radius = 200.0f;
// plight.Bright = 0.7f;
// Oyster::Graphics::API::AddLight(plight);
// plight.Pos = Float3(10.0f,-15.0f,5.0f);
// plight.Color = Float3(0.0f,0.0f,1.0f);
// plight.Radius = 50.0f;
// plight.Bright = 2.0f;
//
// Oyster::Graphics::API::AddLight(plight);
//// LoadModels();
// InitCamera(Float3(0.0f,0.0f,20.0f));
// // hardcoded objects
//// LoadModels();
// Float3 startPos = Float3(0,0,20.0f);
// InitCamera(startPos);
return gameStateState_playing;
}
bool GameState::LoadModels()
{
// open file
// read file
// init models
int nrOfBoxex = 5;
int id = 100;
// add world model
ModelInitData modelData;
modelData.position = Float3(0,0,0);
modelData.rotation = Quaternion::identity;
modelData.scale = Float3(2,2,2);
modelData.modelPath = L"world_earth.dan";
modelData.id = id++;
this->staticObjects.Push(new C_StaticObj());
this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData);
/*
// add box model
modelData.position = Float3(0,0,0);
modelData.rotation = Quaternion::identity;
modelData.scale = Float3(1,1,1);
modelData.modelPath = L"crate_colonists.dan";
for(int i =0; i< nrOfBoxex; i ++)
{
modelData.position = Float3(4,320,0);
modelData.id = id++;
this->dynamicObjects.Push(new C_DynamicObj());
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
}
// add crystal model
modelData.position = Float3(10, 301, 0);
modelData.modelPath = L"crystalformation_b.dan";
modelData.id = id++;
// load models
this->dynamicObjects.Push(new C_DynamicObj());
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
// add house model
modelData.position = Float3(-50, 290, 0);
//Oyster::Math3D::Float4x4 rot = Oyster::Math3D::RotationMatrix(Float3(0 ,Utility::Value::Radian(90.0f), 0));
modelData.visible = true;
modelData.modelPath = L"building_corporation.dan";
modelData.id = id++;
// load models
this->dynamicObjects.Push(new C_DynamicObj());
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
// add player model
modelData.position = Float3(0, 320, 0);
modelData.modelPath = L"char_still_sizeref.dan";
modelData.id = id++;
// load models
this->dynamicObjects.Push(new C_DynamicObj());
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
// add player model 2
modelData.position = Float3(50, 320, 0);
modelData.modelPath = L"char_still_sizeref.dan";
modelData.id = id++;
// load models
this->dynamicObjects.Push(new C_DynamicObj());
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
// add jumppad
modelData.position = Float3(4, 300.3, 0);
modelData.modelPath = L"jumppad_round.dan";
modelData.id = id++;
// load models
this->dynamicObjects.Push(new C_DynamicObj());
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
// add sky sphere
modelData.position = Float3(0,0,0);
modelData.scale = Float3(800,800,800);
modelData.modelPath = L"skysphere.dan";
modelData.id = id++;
// load models
this->dynamicObjects.Push(new C_DynamicObj());
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);*/
return true;
}
bool GameState::LoadModels(std::string mapFile)
{
GameLogic::LevelLoader levelLoader;
@ -258,6 +173,7 @@ bool GameState::LoadModels(std::string mapFile)
return true;
}
bool GameState::InitCamera(Float3 startPos)
{
camera.SetHeadOffset( Float3(0.0f, 1.0f, 1.0f) );
@ -267,6 +183,7 @@ bool GameState::InitCamera(Float3 startPos)
return true;
}
void GameState::InitiatePlayer(int id, std::wstring modelName, Float4x4 world)
{
myId = id;
@ -290,39 +207,43 @@ void GameState::InitiatePlayer(int id, std::wstring modelName, Float4x4 world)
camera.SetPosition( pos );
camera.UpdateOrientation();
}
GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyInput)
{
switch (privData->state)
{
case gameStateState_loading: //Will this ever happen in this scope??
{
// load map
// wait for all players
LoadGame();
GameLogic::Protocol_General_Status gameStatus;
gameStatus.status = GameLogic::Protocol_General_Status::States_ready;
privData->nwClient->Send(gameStatus);
privData->state = gameStateState_playing;
}
break;
case gameStateState_playing:
// read server data
// update objects
{
readKeyInput(KeyInput);
camera.UpdateOrientation();
}
break;
case gameStateState_end:
return ClientState_Lobby;
break;
default:
break;
}
// send key input to server.
return ClientState_Same;
//switch (privData->state)
//{
//case gameStateState_loading: //Will this ever happen in this scope??
// {
// // load map
// // wait for all players
// LoadGame();
// GameLogic::Protocol_General_Status gameStatus;
// gameStatus.status = GameLogic::Protocol_General_Status::States_ready;
// privData->nwClient->Send(gameStatus);
// privData->state = gameStateState_playing;
// }
// break;
//case gameStateState_playing:
// // read server data
// // update objects
// {
// readKeyInput(KeyInput);
// camera.UpdateOrientation();
// }
// break;
//case gameStateState_end:
// return ClientState_Lobby;
// break;
//default:
// break;
//}
//
//// send key input to server.
//return ClientState_Same;
return this->privData->nextState;
}
bool GameState::Render()
{
Oyster::Graphics::API::SetView( camera.GetViewMatrix() );
@ -340,19 +261,19 @@ bool GameState::Render()
Oyster::Graphics::API::EndFrame();
return true;
}
bool GameState::Release()
{
/*for (unsigned int i = 0; i < privData->object.size(); i++)
{
privData->object[i]->Release();
delete privData->object[i];
privData->object[i] = NULL;
}*/
delete privData;
privData = NULL;
return true;
}
void GameState::ChangeState( ClientState next )
{
this->privData->nextState = next;
}
void GameState::readKeyInput(InputClass* KeyInput)
{
if(KeyInput->IsKeyPressed(DIK_W))
@ -471,8 +392,8 @@ void GameState::readKeyInput(InputClass* KeyInput)
// send event data
//
if(KeyInput->IsKeyPressed(DIK_L))
privData->state = GameState::gameStateState_end;
//if(KeyInput->IsKeyPressed(DIK_L))
// privData->state = GameState::gameStateState_end;
}
using namespace ::Oyster::Network;

View File

@ -23,6 +23,8 @@ namespace Client
gameStateState_end,
};
private:
struct MyData;
::Utility::DynamicMemory::UniquePointer<MyData> privData;
bool key_forward;
bool key_backward;
@ -33,8 +35,7 @@ namespace Client
Camera_FPS camera;
int myId;
struct myData;
myData* privData;
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<C_StaticObj>> staticObjects;
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<C_Object>> dynamicObjects;
//Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<C_Player>> playObjects;
@ -44,13 +45,13 @@ namespace Client
bool Init(Oyster::Network::NetworkClient* nwClient);
GameClientState::ClientState Update(float deltaTime, InputClass* KeyInput) override;
bool LoadModels(std::string mapFile);
bool LoadModels();
bool InitCamera(Oyster::Math::Float3 startPos) ;
void InitiatePlayer(int id, std::wstring modelName, Oyster::Math::Float4x4 world);
gameStateState LoadGame();
void readKeyInput(InputClass* KeyInput);
bool Render()override;
bool Release()override;
void ChangeState( ClientState next );
void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e );
};

View File

@ -12,77 +12,29 @@
#include <GameServerAPI.h>
using namespace ::DanBias::Client;
using namespace ::Oyster;
using namespace ::Oyster::Network;
struct LanMenuState::myData
struct LanMenuState::MyData
{
myData(){}
Oyster::Math3D::Float4x4 view;
Oyster::Math3D::Float4x4 proj;
C_Object* object[2];
int modelCount;
MyData(){}
NetworkClient* recieverObj;
bool serverOwner;
GameClientState::ClientState nextState;
NetworkClient *nwClient;
// UI object
// game client*
} privData;
LanMenuState::LanMenuState() {}
LanMenuState::~LanMenuState() {}
bool LanMenuState::Init(Oyster::Network::NetworkClient* nwClient)
bool LanMenuState::Init(Network::NetworkClient* nwClient)
{
privData = new myData();
this->nwClient = nwClient;
// load models
LoadModels(L"UImodels.txt");
InitCamera(Oyster::Math::Float3(0,0,5.4f));
privData = new MyData();
return true;
}
this->privData->nextState = GameClientState::ClientState_Same;
this->privData->nwClient = nwClient;
bool LanMenuState::LoadModels(std::wstring file)
{
Oyster::Graphics::Definitions::Pointlight plight;
plight.Pos = Oyster::Math::Float3(-2,3,0);
plight.Color = Oyster::Math::Float3(0,1,0);
plight.Radius = 10;
plight.Bright = 1;
Oyster::Graphics::API::AddLight(plight);
// open file
// read file
// init models
privData->modelCount = 2;
ModelInitData modelData;
modelData.position = Oyster::Math::Float3(0,0,0);
modelData.rotation = Oyster::Math::Quaternion::identity;
modelData.scale = Oyster::Math::Float3(1,1,1);
modelData.visible = true;
modelData.modelPath = L"..\\Content\\Models\\box_2.dan";
// load models
privData->object[0] = new C_StaticObj();
privData->object[0]->Init(modelData);
modelData.position = Oyster::Math::Float3(-2, -2, -2);
privData->object[1] = new C_DynamicObj();
privData->object[1]->Init(modelData);
return true;
}
bool LanMenuState::InitCamera(Oyster::Math::Float3 startPos)
{
privData->proj = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1024.0f/768.0f,.1f,1000);
//privData->proj = Oyster::Math3D::ProjectionMatrix_Orthographic(1024, 768, 1, 1000);
Oyster::Graphics::API::SetProjection(privData->proj);
privData->view = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),startPos);
privData->view = Oyster::Math3D::InverseOrientationMatrix(privData->view);
return true;
}
@ -126,76 +78,65 @@ GameClientState::ClientState LanMenuState::Update(float deltaTime, InputClass* K
}*/
return ChangeState(KeyInput);
//return ChangeState(KeyInput);
return this->privData->nextState;
}
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;
}
//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;
//}
bool LanMenuState::Render( )
{
Oyster::Graphics::API::SetView(privData->view);
Oyster::Graphics::API::SetProjection( privData->proj);
Graphics::API::NewFrame();
Graphics::API::StartGuiRender();
Oyster::Graphics::API::NewFrame();
// render objects
for (int i = 0; i < privData->modelCount; i++)
{
privData->object[i]->Render();
}
// render effects
// render lights
Oyster::Graphics::API::EndFrame();
Graphics::API::EndFrame();
return true;
}
bool LanMenuState::Release()
{
for (int i = 0; i < privData->modelCount; i++)
{
privData->object[i]->Release();
delete privData->object[i];
privData->object[i] = NULL;
}
delete privData;
privData = NULL;
return true;
}
void LanMenuState::ChangeState( ClientState next )
{
this->privData->nextState = next;
}

View File

@ -17,18 +17,15 @@ namespace DanBias
virtual bool Init(Oyster::Network::NetworkClient* nwClient);
virtual ClientState Update(float deltaTime, InputClass* KeyInput);
ClientState ChangeState(InputClass* KeyInput);
bool LoadModels(std::wstring file);
bool InitCamera(Oyster::Math::Float3 startPos);
//ClientState ChangeState(InputClass* KeyInput);
virtual bool Render();
virtual bool Release();
void ChangeState( ClientState next );
private:
Oyster::Network::NetworkClient* nwClient;
struct myData;
myData* privData;
struct MyData;
::Utility::DynamicMemory::UniquePointer<MyData> privData;
};
}
}

View File

@ -7,132 +7,80 @@
#include <GameServerAPI.h>
#include <Protocols.h>
using namespace DanBias::Client;
using namespace ::Oyster;
using namespace ::Oyster::Network;
using namespace ::DanBias::Client;
struct LobbyState::myData
struct LobbyState::MyData
{
myData(){}
Oyster::Math3D::Float4x4 view;
Oyster::Math3D::Float4x4 proj;
C_Object* object[2];
int modelCount;
// UI object
// game client*
MyData(){}
GameClientState::ClientState nextState;
NetworkClient *nwClient;
} privData;
LobbyState::LobbyState(void) {}
LobbyState::~LobbyState(void) {}
bool LobbyState::Init(Oyster::Network::NetworkClient* nwClient)
LobbyState::~LobbyState(void)
{
privData = new myData();
this->nwClient = nwClient;
// load models
LoadModels(L"UImodels.txt");
InitCamera(Oyster::Math::Float3(0,0,5.4f));
if( this->privData )
this->Release();
}
bool LobbyState::Init(NetworkClient* nwClient)
{
privData = new MyData();
this->privData->nextState = GameClientState::ClientState_Same;
this->privData->nwClient = nwClient;
return true;
}
bool LobbyState::LoadModels(std::wstring file)
{
Oyster::Graphics::Definitions::Pointlight plight;
plight.Pos = Oyster::Math::Float3(-2,3,0);
plight.Color = Oyster::Math::Float3(0,1,0);
plight.Radius = 10;
plight.Bright = 1;
Oyster::Graphics::API::AddLight(plight);
// open file
// read file
// init models
privData->modelCount = 2;
ModelInitData modelData;
modelData.position = Oyster::Math::Float3(0,0,0);
modelData.rotation = Oyster::Math::Quaternion::identity;
modelData.scale = Oyster::Math::Float3(1,1,1);
modelData.visible = true;
modelData.modelPath = L"crate_colonists.dan";
// load models
privData->object[0] = new C_StaticObj();
privData->object[0]->Init(modelData);
modelData.position = Oyster::Math::Float3(2,2,2);
privData->object[1] = new C_StaticObj();
privData->object[1]->Init(modelData);
return true;
}
bool LobbyState::InitCamera(Oyster::Math::Float3 startPos)
{
privData->proj = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1024.0f/768.0f,.1f,1000);
//privData->proj = Oyster::Math3D::ProjectionMatrix_Orthographic(1024, 768, 1, 1000);
Oyster::Graphics::API::SetProjection(privData->proj);
privData->view = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),startPos);
privData->view = Oyster::Math3D::InverseOrientationMatrix(privData->view);
return true;
}
GameClientState::ClientState LobbyState::Update(float deltaTime, InputClass* KeyInput)
{
// picking
// mouse events
// different menus
// play sounds
// update animation
// send data to server
// check data from server
//// picking
//// mouse events
//// different menus
//// play sounds
//// update animation
//// send data to server
//// check data from server
if(GameServerAPI::ServerIsRunning() && GameServerAPI::ServerIsRunning()) //May be a problem if server is not shut down properly after lan session.
{
if( KeyInput->IsKeyPressed(DIK_G))
{
if(!DanBias::GameServerAPI::GameStart())
{
}
}
}
//if(GameServerAPI::ServerIsRunning() && GameServerAPI::ServerIsRunning()) //May be a problem if server is not shut down properly after lan session.
//{
// if( KeyInput->IsKeyPressed(DIK_G))
// {
// if(!DanBias::GameServerAPI::GameStart())
// {
//
// }
// }
//}
return ClientState_Same;
//return ClientState_Same;
return this->privData->nextState;
}
bool LobbyState::Render( )
{
Oyster::Graphics::API::SetView(privData->view);
Oyster::Graphics::API::SetProjection( privData->proj);
Graphics::API::NewFrame();
Graphics::API::StartGuiRender();
Oyster::Graphics::API::NewFrame();
// render objects
for (int i = 0; i < privData->modelCount; i++)
{
privData->object[i]->Render();
}
// render effects
// render lights
Oyster::Graphics::API::EndFrame();
Graphics::API::EndFrame();
return true;
}
bool LobbyState::Release()
{
Oyster::Graphics::API::ClearLights();
for (int i = 0; i < privData->modelCount; i++)
{
privData->object[i]->Release();
delete privData->object[i];
privData->object[i] = NULL;
}
delete privData;
privData = NULL;
return true;
}
void LobbyState::ChangeState( ClientState next )
{
this->privData->nextState = next;
}
using namespace ::Oyster::Network;
void LobbyState::DataRecieved( NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e )

View File

@ -12,15 +12,12 @@ namespace DanBias
class LobbyState : public GameClientState
{
private:
Oyster::Network::NetworkClient* nwClient;
struct myData;
myData* privData;
struct MyData;
::Utility::DynamicMemory::UniquePointer<MyData> privData;
public:
LobbyState(void);
~LobbyState(void);
bool Init(Oyster::Network::NetworkClient* nwClient);
bool LoadModels(std::wstring file);
bool InitCamera(Oyster::Math::Float3 startPos);
ClientState Update(float deltaTime, InputClass* KeyInput);
// create session lobby
// join session lobby
@ -33,6 +30,7 @@ namespace DanBias
bool Render();
bool Release();
void ChangeState( ClientState next );
void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e );
};

View File

@ -22,27 +22,35 @@ struct MainState::MyData
{
MyData() {}
Float4x4 view;
Float4x4 proj;
UniquePointer<C_Object> object[2];
GameClientState::ClientState nextState;
NetworkClient *nwClient;
Graphics::API::Texture background;
EventButtonCollection button;
};
void OnButtonInteract( Oyster::Event::ButtonEvent<GameClientState*>& e );
void OnButtonInteract_Create( Oyster::Event::ButtonEvent<GameClientState*>& e );
void OnButtonInteract_Join( Oyster::Event::ButtonEvent<GameClientState*>& e );
void OnButtonInteract_Quit( Oyster::Event::ButtonEvent<GameClientState*>& e );
MainState::MainState(void) {}
MainState::~MainState(void) {}
MainState::~MainState(void)
{
if( this->privData )
this->Release();
}
bool MainState::Init( NetworkClient* nwClient )
{
this->privData = new MyData();
this->privData->nextState = GameClientState::ClientState_Same;
this->privData->nwClient = nwClient;
this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" );
// create buttons
ButtonRectangle<GameClientState*> *button = new ButtonRectangle<GameClientState*>( L"earth_md.png", OnButtonInteract, this, 0.5f, 0.5f, 0.1f, 0.1f, true );
ButtonRectangle<GameClientState*> *button = new ButtonRectangle<GameClientState*>( L"earth_md.png", OnButtonInteract_Quit, this, 0.5f, 0.5f, 0.1f, 0.1f, true );
this->privData->button.AddButton( button );
// bind button collection to the singleton eventhandler
@ -53,78 +61,64 @@ bool MainState::Init( NetworkClient* nwClient )
GameClientState::ClientState MainState::Update(float deltaTime, InputClass* KeyInput)
{
// picking
// mouse events
// different menus
// play sounds
// update animation
// send data to server
// check data from server
//// 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;
//// create game
//if( KeyInput->IsKeyPressed(DIK_C))
//{
// DanBias::GameServerAPI::ServerInitDesc desc;
DanBias::GameServerAPI::ServerInitiate(desc);
DanBias::GameServerAPI::ServerStart();
// my ip
this->privData->nwClient->Connect(15152, "127.0.0.1");
// DanBias::GameServerAPI::ServerInitiate(desc);
// DanBias::GameServerAPI::ServerStart();
// // my ip
// this->privData->nwClient->Connect(15152, "127.0.0.1");
if (!this->privData->nwClient->IsConnected())
{
// failed to connect
return ClientState_Same;
}
return ClientState_LobbyCreated;
}
// join game
if( KeyInput->IsKeyPressed(DIK_J))
{
// game ip
this->privData->nwClient->Connect(15152, "127.0.0.1");
//nwClient->Connect(15152, "83.254.217.248");
// if (!this->privData->nwClient->IsConnected())
// {
// // failed to connect
// return ClientState_Same;
// }
// return ClientState_LobbyCreated;
//}
//// join game
//if( KeyInput->IsKeyPressed(DIK_J))
//{
// // game ip
// this->privData->nwClient->Connect(15152, "127.0.0.1");
// //nwClient->Connect(15152, "83.254.217.248");
if (!this->privData->nwClient->IsConnected())
{
// failed to connect
return ClientState_Same;
}
return ClientState_Lobby;
}
return ClientState_Same;
// if (!this->privData->nwClient->IsConnected())
// {
// // failed to connect
// return ClientState_Same;
// }
// return ClientState_Lobby;
//}
return this->privData->nextState;
}
bool MainState::Render()
{
Graphics::API::SetView(privData->view);
Graphics::API::SetProjection( privData->proj);
Graphics::API::NewFrame();
// render objects
//for (int i = 0; i < NumElementsOf(privData->object); i++)
//{
// privData->object[i]->Render();
//}
Graphics::API::StartGuiRender();
Graphics::API::RenderGuiElement( this->privData->background, Float2(0.5f), Float2(1.0f) );
this->privData->button.Render();
// render effects
// render lights
Graphics::API::EndFrame();
return true;
}
bool MainState::Release()
{
for (int i = 0; i < NumElementsOf(privData->object); i++)
{
privData->object[i] = NULL;
}
Graphics::API::DeleteTexture( this->privData->background );
privData = NULL;
// button collection will be autoreleased from EventHandler
@ -132,8 +126,48 @@ bool MainState::Release()
return true;
}
/// button actions
void OnButtonInteract( Oyster::Event::ButtonEvent<GameClientState*>& e )
void MainState::ChangeState( ClientState next )
{
this->privData->nextState = next;
}
/// button actions
//ButtonState_None, // onExit
//ButtonState_Hover,
//ButtonState_Pressed,
//ButtonState_Down,
//ButtonState_Released,
void OnButtonInteract_Create( Oyster::Event::ButtonEvent<GameClientState*>& e )
{
switch( e.state )
{
case ButtonState_Released:
e.owner->ChangeState( GameClientState::ClientState_LobbyCreate );
break;
default: break;
}
}
void OnButtonInteract_Join( Oyster::Event::ButtonEvent<GameClientState*>& e )
{
switch( e.state )
{
case ButtonState_Released:
e.owner->ChangeState( GameClientState::ClientState_Lan );
break;
default: break;
}
}
void OnButtonInteract_Quit( Oyster::Event::ButtonEvent<GameClientState*>& e )
{
switch( e.state )
{
case ButtonState_Released:
e.owner->ChangeState( GameClientState::ClientState_Quit );
break;
default: break;
}
}

View File

@ -22,6 +22,7 @@ namespace DanBias
bool Render();
bool Release();
void ChangeState( ClientState next );
};
}
}