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

View File

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

View File

@ -15,9 +15,10 @@ namespace DanBias { namespace Client
ClientState_Login, ClientState_Login,
ClientState_Lobby, ClientState_Lobby,
ClientState_Lan, ClientState_Lan,
ClientState_LobbyCreated, ClientState_LobbyCreate,
ClientState_Game, ClientState_Game,
ClientState_Same, ClientState_Same,
ClientState_Quit
}; };
public: public:
@ -27,6 +28,7 @@ namespace DanBias { namespace Client
virtual ClientState Update(float deltaTime, InputClass* KeyInput) = 0; virtual ClientState Update(float deltaTime, InputClass* KeyInput) = 0;
virtual bool Render() = 0; virtual bool Render() = 0;
virtual bool Release() = 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 ); 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 "Camera_FPS.h"
#include <GameServerAPI.h> #include <GameServerAPI.h>
using namespace DanBias::Client; using namespace ::DanBias::Client;
using namespace Oyster::Math3D; using namespace ::Oyster;
using namespace ::Oyster::Network;
using namespace ::Oyster::Math3D;
struct GameState::myData struct GameState::MyData
{ {
myData(){} MyData(){}
int modelCount; GameClientState::ClientState nextState;
Oyster::Network::NetworkClient* nwClient; NetworkClient *nwClient;
gameStateState state;
} privData; } privData;
GameState::GameState(void) GameState::GameState(void)
@ -26,151 +28,64 @@ GameState::GameState(void)
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 // load models
privData = new myData(); privData = new MyData();
privData->state = gameStateState_loading;
privData->nwClient = nwClient;
privData->state = LoadGame();
//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)); nwClient->Send(GameLogic::Protocol_General_Status(GameLogic::Protocol_General_Status::States_ready));
return true; return true;
} }
GameState::gameStateState GameState::LoadGame() GameState::gameStateState GameState::LoadGame()
{ {
Oyster::Graphics::Definitions::Pointlight plight; // Oyster::Graphics::Definitions::Pointlight plight;
plight.Pos = Float3(315.0f, 0.0f ,5.0f); // plight.Pos = Float3(315.0f, 0.0f ,5.0f);
plight.Color = Float3(0.9f,0.7f,0.2f); // plight.Color = Float3(0.9f,0.7f,0.2f);
plight.Radius = 100.0f; // plight.Radius = 100.0f;
plight.Bright = 0.9f; // plight.Bright = 0.9f;
Oyster::Graphics::API::AddLight(plight); // Oyster::Graphics::API::AddLight(plight);
plight.Pos = Float3(10.0f,350.0f,5.0f); // plight.Pos = Float3(10.0f,350.0f,5.0f);
plight.Color = Float3(0.9f,0.7f,0.3f); // plight.Color = Float3(0.9f,0.7f,0.3f);
plight.Radius = 200.0f; // plight.Radius = 200.0f;
plight.Bright = 0.7f; // plight.Bright = 0.7f;
Oyster::Graphics::API::AddLight(plight); // Oyster::Graphics::API::AddLight(plight);
plight.Pos = Float3(350.0f,350.0f,5.0f); // plight.Pos = Float3(350.0f,350.0f,5.0f);
plight.Color = Float3(0.9f,0.7f,0.3f); // plight.Color = Float3(0.9f,0.7f,0.3f);
plight.Radius = 200.0f; // plight.Radius = 200.0f;
plight.Bright = 0.7f; // plight.Bright = 0.7f;
Oyster::Graphics::API::AddLight(plight); // Oyster::Graphics::API::AddLight(plight);
plight.Pos = Float3(10.0f,350.0f,350.0f); // plight.Pos = Float3(10.0f,350.0f,350.0f);
plight.Color = Float3(0.9f,0.7f,0.3f); // plight.Color = Float3(0.9f,0.7f,0.3f);
plight.Radius = 200.0f; // plight.Radius = 200.0f;
plight.Bright = 0.7f; // plight.Bright = 0.7f;
Oyster::Graphics::API::AddLight(plight); // Oyster::Graphics::API::AddLight(plight);
plight.Pos = Float3(10.0f,-15.0f,5.0f); // plight.Pos = Float3(10.0f,-15.0f,5.0f);
plight.Color = Float3(0.0f,0.0f,1.0f); // plight.Color = Float3(0.0f,0.0f,1.0f);
plight.Radius = 50.0f; // plight.Radius = 50.0f;
plight.Bright = 2.0f; // plight.Bright = 2.0f;
//
Oyster::Graphics::API::AddLight(plight); // Oyster::Graphics::API::AddLight(plight);
LoadModels(); //// LoadModels();
InitCamera(Float3(0.0f,0.0f,20.0f)); // InitCamera(Float3(0.0f,0.0f,20.0f));
// hardcoded objects // // hardcoded objects
LoadModels(); //// LoadModels();
Float3 startPos = Float3(0,0,20.0f); // Float3 startPos = Float3(0,0,20.0f);
InitCamera(startPos); // InitCamera(startPos);
return gameStateState_playing; 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) bool GameState::LoadModels(std::string mapFile)
{ {
GameLogic::LevelLoader levelLoader; GameLogic::LevelLoader levelLoader;
@ -258,6 +173,7 @@ bool GameState::LoadModels(std::string mapFile)
return true; return true;
} }
bool GameState::InitCamera(Float3 startPos) bool GameState::InitCamera(Float3 startPos)
{ {
camera.SetHeadOffset( Float3(0.0f, 1.0f, 1.0f) ); camera.SetHeadOffset( Float3(0.0f, 1.0f, 1.0f) );
@ -267,6 +183,7 @@ bool GameState::InitCamera(Float3 startPos)
return true; return true;
} }
void GameState::InitiatePlayer(int id, std::wstring modelName, Float4x4 world) void GameState::InitiatePlayer(int id, std::wstring modelName, Float4x4 world)
{ {
myId = id; myId = id;
@ -290,39 +207,43 @@ void GameState::InitiatePlayer(int id, std::wstring modelName, Float4x4 world)
camera.SetPosition( pos ); camera.SetPosition( pos );
camera.UpdateOrientation(); camera.UpdateOrientation();
} }
GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyInput) GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyInput)
{ {
switch (privData->state) //switch (privData->state)
{ //{
case gameStateState_loading: //Will this ever happen in this scope?? //case gameStateState_loading: //Will this ever happen in this scope??
{ // {
// load map // // load map
// wait for all players // // wait for all players
LoadGame(); // LoadGame();
GameLogic::Protocol_General_Status gameStatus; // GameLogic::Protocol_General_Status gameStatus;
gameStatus.status = GameLogic::Protocol_General_Status::States_ready; // gameStatus.status = GameLogic::Protocol_General_Status::States_ready;
privData->nwClient->Send(gameStatus); // privData->nwClient->Send(gameStatus);
privData->state = gameStateState_playing; // privData->state = gameStateState_playing;
} // }
break; // break;
case gameStateState_playing: //case gameStateState_playing:
// read server data // // read server data
// update objects // // update objects
{ // {
readKeyInput(KeyInput); // readKeyInput(KeyInput);
camera.UpdateOrientation(); // camera.UpdateOrientation();
} // }
break; // break;
case gameStateState_end: //case gameStateState_end:
return ClientState_Lobby; // return ClientState_Lobby;
break; // break;
default: //default:
break; // break;
//}
//
//// send key input to server.
//return ClientState_Same;
return this->privData->nextState;
} }
// send key input to server.
return ClientState_Same;
}
bool GameState::Render() bool GameState::Render()
{ {
Oyster::Graphics::API::SetView( camera.GetViewMatrix() ); Oyster::Graphics::API::SetView( camera.GetViewMatrix() );
@ -340,19 +261,19 @@ bool GameState::Render()
Oyster::Graphics::API::EndFrame(); Oyster::Graphics::API::EndFrame();
return true; return true;
} }
bool GameState::Release() 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; privData = NULL;
return true; return true;
} }
void GameState::ChangeState( ClientState next )
{
this->privData->nextState = next;
}
void GameState::readKeyInput(InputClass* KeyInput) void GameState::readKeyInput(InputClass* KeyInput)
{ {
if(KeyInput->IsKeyPressed(DIK_W)) if(KeyInput->IsKeyPressed(DIK_W))
@ -471,8 +392,8 @@ void GameState::readKeyInput(InputClass* KeyInput)
// send event data // send event data
// //
if(KeyInput->IsKeyPressed(DIK_L)) //if(KeyInput->IsKeyPressed(DIK_L))
privData->state = GameState::gameStateState_end; // privData->state = GameState::gameStateState_end;
} }
using namespace ::Oyster::Network; using namespace ::Oyster::Network;

View File

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

View File

@ -12,77 +12,29 @@
#include <GameServerAPI.h> #include <GameServerAPI.h>
using namespace ::DanBias::Client; using namespace ::DanBias::Client;
using namespace ::Oyster;
using namespace ::Oyster::Network; using namespace ::Oyster::Network;
struct LanMenuState::myData struct LanMenuState::MyData
{ {
myData(){} MyData(){}
Oyster::Math3D::Float4x4 view;
Oyster::Math3D::Float4x4 proj;
C_Object* object[2];
int modelCount;
NetworkClient* recieverObj; GameClientState::ClientState nextState;
bool serverOwner; NetworkClient *nwClient;
// UI object
// game client*
} privData; } privData;
LanMenuState::LanMenuState() {} LanMenuState::LanMenuState() {}
LanMenuState::~LanMenuState() {} LanMenuState::~LanMenuState() {}
bool LanMenuState::Init(Oyster::Network::NetworkClient* nwClient) bool LanMenuState::Init(Network::NetworkClient* nwClient)
{ {
privData = new myData(); privData = new MyData();
this->nwClient = nwClient;
// load models
LoadModels(L"UImodels.txt");
InitCamera(Oyster::Math::Float3(0,0,5.4f));
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; 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) //GameClientState::ClientState LanMenuState::ChangeState(InputClass* KeyInput)
{ //{
// create game // // create game
if( KeyInput->IsKeyPressed(DIK_C)) // if( KeyInput->IsKeyPressed(DIK_C))
{ // {
DanBias::GameServerAPI::ServerInitDesc desc; // DanBias::GameServerAPI::ServerInitDesc desc;
//
DanBias::GameServerAPI::ServerInitiate(desc); // DanBias::GameServerAPI::ServerInitiate(desc);
DanBias::GameServerAPI::ServerStart(); // DanBias::GameServerAPI::ServerStart();
// my ip // // my ip
nwClient->Connect(15151, "127.0.0.1"); // nwClient->Connect(15151, "127.0.0.1");
//
if (!nwClient->IsConnected()) // if (!nwClient->IsConnected())
{ // {
// failed to connect // // failed to connect
return ClientState_Same; // return ClientState_Same;
} // }
return ClientState_Lobby; // return ClientState_Lobby;
} // }
// join game // // join game
if( KeyInput->IsKeyPressed(DIK_J)) // if( KeyInput->IsKeyPressed(DIK_J))
{ // {
// game ip // // game ip
nwClient->Connect(15151, "194.47.150.56"); // nwClient->Connect(15151, "194.47.150.56");
//
if (!nwClient->IsConnected()) // if (!nwClient->IsConnected())
{ // {
// failed to connect // // failed to connect
return ClientState_Same; // return ClientState_Same;
} // }
return ClientState_Lobby; // return ClientState_Lobby;
} // }
return ClientState_Same; // return ClientState_Same;
} //}
bool LanMenuState::Render( ) bool LanMenuState::Render( )
{ {
Oyster::Graphics::API::SetView(privData->view); Graphics::API::NewFrame();
Oyster::Graphics::API::SetProjection( privData->proj);
Graphics::API::StartGuiRender();
Oyster::Graphics::API::NewFrame();
// render objects
for (int i = 0; i < privData->modelCount; i++)
{
privData->object[i]->Render();
}
// render effects Graphics::API::EndFrame();
// render lights
Oyster::Graphics::API::EndFrame();
return true; return true;
} }
bool LanMenuState::Release() 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; privData = NULL;
return true; 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 bool Init(Oyster::Network::NetworkClient* nwClient);
virtual ClientState Update(float deltaTime, InputClass* KeyInput); virtual ClientState Update(float deltaTime, InputClass* KeyInput);
ClientState ChangeState(InputClass* KeyInput); //ClientState ChangeState(InputClass* KeyInput);
bool LoadModels(std::wstring file);
bool InitCamera(Oyster::Math::Float3 startPos);
virtual bool Render(); virtual bool Render();
virtual bool Release(); virtual bool Release();
void ChangeState( ClientState next );
private: private:
Oyster::Network::NetworkClient* nwClient; struct MyData;
struct myData; ::Utility::DynamicMemory::UniquePointer<MyData> privData;
myData* privData;
}; };
} }
} }

View File

@ -7,132 +7,80 @@
#include <GameServerAPI.h> #include <GameServerAPI.h>
#include <Protocols.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(){} MyData(){}
Oyster::Math3D::Float4x4 view;
Oyster::Math3D::Float4x4 proj; GameClientState::ClientState nextState;
C_Object* object[2]; NetworkClient *nwClient;
int modelCount;
// UI object
// game client*
} privData; } privData;
LobbyState::LobbyState(void) {} LobbyState::LobbyState(void) {}
LobbyState::~LobbyState(void) {} LobbyState::~LobbyState(void)
bool LobbyState::Init(Oyster::Network::NetworkClient* nwClient)
{ {
privData = new myData(); if( this->privData )
this->nwClient = nwClient; this->Release();
// load models }
LoadModels(L"UImodels.txt");
InitCamera(Oyster::Math::Float3(0,0,5.4f)); bool LobbyState::Init(NetworkClient* nwClient)
{
privData = new MyData();
this->privData->nextState = GameClientState::ClientState_Same;
this->privData->nwClient = nwClient;
return true; 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) GameClientState::ClientState LobbyState::Update(float deltaTime, InputClass* KeyInput)
{ {
// picking //// picking
// mouse events //// mouse events
// different menus //// different menus
// play sounds //// play sounds
// update animation //// update animation
// send data to server //// send data to server
// check data from 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(GameServerAPI::ServerIsRunning() && GameServerAPI::ServerIsRunning()) //May be a problem if server is not shut down properly after lan session.
{ //{
if( KeyInput->IsKeyPressed(DIK_G)) // if( KeyInput->IsKeyPressed(DIK_G))
{ // {
if(!DanBias::GameServerAPI::GameStart()) // if(!DanBias::GameServerAPI::GameStart())
{ // {
//
// }
// }
//}
} //return ClientState_Same;
}
}
return ClientState_Same; return this->privData->nextState;
} }
bool LobbyState::Render( ) bool LobbyState::Render( )
{ {
Oyster::Graphics::API::SetView(privData->view); Graphics::API::NewFrame();
Oyster::Graphics::API::SetProjection( privData->proj); Graphics::API::StartGuiRender();
Graphics::API::EndFrame();
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();
return true; return true;
} }
bool LobbyState::Release() 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; privData = NULL;
return true; return true;
} }
void LobbyState::ChangeState( ClientState next )
{
this->privData->nextState = next;
}
using namespace ::Oyster::Network; using namespace ::Oyster::Network;
void LobbyState::DataRecieved( NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e ) void LobbyState::DataRecieved( NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e )

View File

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

View File

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