This commit is contained in:
Dander7BD 2014-02-17 11:27:43 +01:00 committed by Robin Engman
parent 7395a0a495
commit 0a6cb9a43c
22 changed files with 182 additions and 109 deletions

View File

@ -18,12 +18,15 @@
#include "WinTimer.h"
#include "vld.h"
#include "EventHandler/EventHandler.h"
#include "../Misc/EventHandler/EventHandler.h"
#include "GameClientState\SharedStateContent.h"
using namespace ::Oyster;
using namespace ::Oyster::Event;
using namespace ::Oyster::Network;
using namespace ::Utility::DynamicMemory;
using namespace ::DanBias::Client;
void ClientEventFunction( NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e );
@ -32,15 +35,17 @@ namespace DanBias
#pragma region Game Data
class DanBiasGamePrivateData
{
public:
WindowShell* window;
InputClass* inputObj;
InputClass inputObj;
Utility::WinTimer timer;
UniquePointer<Client::GameClientState> state;
NetworkClient networkClient;
bool serverOwner;
UniquePointer<Client::GameClientState> state;
SharedStateContent sharedStateContent;
NetworkClient networkClient;
bool serverOwner;
float capFrame;
DanBiasGamePrivateData()
@ -72,10 +77,13 @@ namespace DanBias
data.networkClient.SetMessagePump( ClientEventFunction );
data.sharedStateContent.network = &data.networkClient;
data.sharedStateContent.input = &data.inputObj;
// Start in main menu state
data.state = new Client::MainState();
if( !data.state->Init( &data.networkClient ) )
if( !data.state->Init( data.sharedStateContent ) )
return DanBiasClientReturn_Error;
data.timer.reset();
@ -140,8 +148,7 @@ namespace DanBias
//-------------------------------------------------------------------------------------
HRESULT DanBiasGame::InitInput()
{
data.inputObj = new InputClass;
if(!data.inputObj->Initialize(data.window->GetHINSTANCE(), data.window->GetHWND(), data.window->GetHeight(), data.window->GetWidth()))
if(!data.inputObj.Initialize(data.window->GetHINSTANCE(), data.window->GetHWND(), data.window->GetHeight(), data.window->GetWidth()))
{
MessageBox(0, L"Could not initialize the input object.", L"Error", MB_OK);
return E_FAIL;
@ -164,7 +171,7 @@ namespace DanBias
float mouseNormalisedY = (float)(mousePos.y - windowVertex.top);
mouseNormalisedY /= (float)(windowVertex.bottom - windowVertex.top);
data.inputObj->Update( mouseNormalisedX, mouseNormalisedY );
data.inputObj.Update( mouseNormalisedX, mouseNormalisedY );
}
if( data.serverOwner )
@ -174,7 +181,7 @@ namespace DanBias
DanBias::Client::GameClientState::ClientState state = DanBias::Client::GameClientState::ClientState_Same;
state = data.state->Update( deltaTime, data.inputObj );
state = data.state->Update( deltaTime );
if( state != Client::GameClientState::ClientState_Same )
{
@ -217,7 +224,7 @@ namespace DanBias
if( stateChanged )
{
data.state->Init( &data.networkClient ); // send game client
data.state->Init( data.sharedStateContent ); // send game client
}
}
return Result_continue;
@ -235,8 +242,6 @@ namespace DanBias
if( data.networkClient.IsConnected() )
data.networkClient.Disconnect();
delete data.inputObj;
data.state = nullptr;
EventHandler::Instance().Clean();
Graphics::API::Clean();

View File

@ -5,8 +5,8 @@
#ifndef DANBIAS_CLIENT_EVENT_BUTTON_GUI_H
#define DANBIAS_CLIENT_EVENT_BUTTON_GUI_H
#include "EventHandler/EventButton.h"
#include "DllInterfaces/GFXAPI.h"
#include "../Misc/EventHandler/EventButton.h"
#include "../OysterGraphics/DllInterfaces/GFXAPI.h"

View File

@ -99,6 +99,10 @@ void C_Object::Render()
Oyster::Graphics::API::RenderModel(model);
}
void C_Object::Release()
{
if( this->model )
{
Oyster::Graphics::API::DeleteModel(model);
this->model = nullptr;
}
}

View File

@ -48,5 +48,23 @@ public:
virtual void Render();
virtual void Release();
virtual int GetId() const;
};};};
};
}
}
#include "Utilities.h"
namespace Utility { namespace DynamicMemory
{
template<>
inline void SafeDeleteInstance( ::DanBias::Client::C_Object *dynamicInstance )
{
if( dynamicInstance )
{
dynamicInstance->Release();
delete dynamicInstance;
}
}
} }
#endif

View File

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

View File

@ -2,8 +2,7 @@
#define DANBIAS_CLIENT_GAMECLIENTSTATE_H
#define NOMINMAX
#include "L_inputClass.h"
#include "NetworkClient.h"
#include "SharedStateContent.h"
namespace DanBias { namespace Client
{
@ -24,10 +23,10 @@ namespace DanBias { namespace Client
};
public:
GameClientState(void);
virtual ~GameClientState(void);
virtual bool Init(Oyster::Network::NetworkClient* nwClient) = 0;
virtual ClientState Update(float deltaTime, InputClass* KeyInput) = 0;
GameClientState();
virtual ~GameClientState();
virtual bool Init( SharedStateContent &shared ) = 0;
virtual ClientState Update( float deltaTime ) = 0;
virtual bool Render() = 0;
virtual bool Release() = 0;
virtual void ChangeState( ClientState next ) = 0;

View File

@ -15,9 +15,10 @@ struct GameState::MyData
MyData(){}
GameClientState::ClientState nextState;
NetworkClient *nwClient;
InputClass *input;
} privData;
GameState::GameState(void)
GameState::GameState()
{
key_forward = false;
key_backward = false;
@ -25,24 +26,25 @@ GameState::GameState(void)
key_strafeLeft = false;
}
GameState::~GameState(void)
GameState::~GameState()
{
if( this->privData )
this->Release();
}
bool GameState::Init(NetworkClient* nwClient)
bool GameState::Init( SharedStateContent &shared )
{
// load models
privData = new MyData();
this->privData->nextState = GameClientState::ClientState_Same;
this->privData->nwClient = nwClient;
this->privData->nwClient = shared.network;
this->privData->input = shared.input;
LoadGame();
//tell server ready
nwClient->Send( GameLogic::Protocol_General_Status(GameLogic::Protocol_General_Status::States_ready) );
this->privData->nwClient->Send( GameLogic::Protocol_General_Status(GameLogic::Protocol_General_Status::States_ready) );
return true;
}
@ -180,7 +182,7 @@ void GameState::InitiatePlayer(int id, std::wstring modelName, Float4x4 world)
camera.UpdateOrientation();
}
GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyInput)
GameClientState::ClientState GameState::Update( float deltaTime )
{
//switch (privData->state)
//{

View File

@ -25,8 +25,8 @@ namespace DanBias { namespace Client
GameState(void);
~GameState(void);
bool Init(Oyster::Network::NetworkClient* nwClient);
GameClientState::ClientState Update(float deltaTime, InputClass* KeyInput) override;
bool Init( SharedStateContent &shared );
GameClientState::ClientState Update( float deltaTime ) override;
bool LoadModels(std::string mapFile);
bool InitCamera(Oyster::Math::Float3 startPos) ;

View File

@ -28,6 +28,7 @@ struct LanMenuState::MyData
GameClientState::ClientState nextState;
NetworkClient *nwClient;
InputClass *input;
Graphics::API::Texture background;
EventButtonCollection guiElements;
@ -46,12 +47,13 @@ LanMenuState::~LanMenuState()
this->Release();
}
bool LanMenuState::Init(Network::NetworkClient* nwClient)
bool LanMenuState::Init( SharedStateContent &shared )
{
this->privData = new MyData();
this->privData->nextState = GameClientState::ClientState_Same;
this->privData->nwClient = nwClient;
this->privData->nwClient = shared.network;
this->privData->input = shared.input;
this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" );
@ -80,12 +82,12 @@ bool LanMenuState::Init(Network::NetworkClient* nwClient)
return true;
}
GameClientState::ClientState LanMenuState::Update(float deltaTime, InputClass* KeyInput)
GameClientState::ClientState LanMenuState::Update( float deltaTime )
{
MouseInput mouseState;
{
KeyInput->GetMousePos( mouseState.x, mouseState.y );
mouseState.mouseButtonPressed = KeyInput->IsMousePressed();
this->privData->input->GetMousePos( mouseState.x, mouseState.y );
mouseState.mouseButtonPressed = this->privData->input->IsMousePressed();
}
EventHandler::Instance().Update( mouseState );

View File

@ -14,8 +14,8 @@ namespace DanBias
LanMenuState();
virtual ~LanMenuState();
virtual bool Init(Oyster::Network::NetworkClient* nwClient);
virtual ClientState Update(float deltaTime, InputClass* KeyInput);
bool Init( SharedStateContent &shared );
virtual ClientState Update( float deltaTime );
virtual bool Render();
virtual bool Release();

View File

@ -7,7 +7,7 @@
#include <string>
#include <vector>
#include "Utilities.h"
#include "../Misc/Utilities.h"
#include "ObjectDefines.h"
namespace GameLogic

View File

@ -4,7 +4,7 @@
#include <string>
#include <vector>
#include "ObjectDefines.h"
#include "Utilities.h"
#include "../Misc/Utilities.h"
namespace GameLogic
{

View File

@ -5,7 +5,7 @@
#ifndef LOADER_H
#define LOADER_H
#include "Resource\OysterResource.h"
#include "..\Misc\Resource\OysterResource.h"
#include <string>
namespace GameLogic

View File

@ -22,6 +22,7 @@ struct LobbyAdminState::MyData
GameClientState::ClientState nextState;
NetworkClient *nwClient;
InputClass *input;
Graphics::API::Texture background;
EventButtonCollection guiElements;
} privData;
@ -36,12 +37,13 @@ LobbyAdminState::~LobbyAdminState(void)
this->Release();
}
bool LobbyAdminState::Init(NetworkClient* nwClient)
bool LobbyAdminState::Init( SharedStateContent &shared )
{
privData = new MyData();
this->privData->nextState = GameClientState::ClientState_Same;
this->privData->nwClient = nwClient;
this->privData->nwClient = shared.network;
this->privData->input = shared.input;
this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" );
@ -57,7 +59,7 @@ bool LobbyAdminState::Init(NetworkClient* nwClient)
return true;
}
GameClientState::ClientState LobbyAdminState::Update(float deltaTime, InputClass* KeyInput)
GameClientState::ClientState LobbyAdminState::Update( float deltaTime )
{
// Wishlist:
// picking
@ -70,8 +72,8 @@ GameClientState::ClientState LobbyAdminState::Update(float deltaTime, InputClass
MouseInput mouseState;
{
KeyInput->GetMousePos( mouseState.x, mouseState.y );
mouseState.mouseButtonPressed = KeyInput->IsMousePressed();
this->privData->input->GetMousePos( mouseState.x, mouseState.y );
mouseState.mouseButtonPressed = this->privData->input->IsMousePressed();
}
EventHandler::Instance().Update( mouseState );

View File

@ -24,8 +24,8 @@ namespace DanBias
LobbyAdminState();
~LobbyAdminState();
bool Init( Oyster::Network::NetworkClient* nwClient );
ClientState Update( float deltaTime, InputClass* KeyInput );
bool Init( SharedStateContent &shared );
ClientState Update( float deltaTime );
bool Render();
bool Release();
void ChangeState( ClientState next );

View File

@ -22,6 +22,7 @@ struct LobbyState::MyData
GameClientState::ClientState nextState;
NetworkClient *nwClient;
InputClass *input;
Graphics::API::Texture background;
EventButtonCollection guiElements;
} privData;
@ -36,12 +37,13 @@ LobbyState::~LobbyState(void)
this->Release();
}
bool LobbyState::Init(NetworkClient* nwClient)
bool LobbyState::Init( SharedStateContent &shared )
{
privData = new MyData();
this->privData->nextState = GameClientState::ClientState_Same;
this->privData->nwClient = nwClient;
this->privData->nwClient = shared.network;
this->privData->input = shared.input;
this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" );
@ -57,7 +59,7 @@ bool LobbyState::Init(NetworkClient* nwClient)
return true;
}
GameClientState::ClientState LobbyState::Update(float deltaTime, InputClass* KeyInput)
GameClientState::ClientState LobbyState::Update( float deltaTime )
{
// Wishlist:
// picking
@ -70,8 +72,8 @@ GameClientState::ClientState LobbyState::Update(float deltaTime, InputClass* Key
MouseInput mouseState;
{
KeyInput->GetMousePos( mouseState.x, mouseState.y );
mouseState.mouseButtonPressed = KeyInput->IsMousePressed();
this->privData->input->GetMousePos( mouseState.x, mouseState.y );
mouseState.mouseButtonPressed = this->privData->input->IsMousePressed();
}
EventHandler::Instance().Update( mouseState );

View File

@ -23,11 +23,11 @@ namespace DanBias
class LobbyState : public GameClientState
{
public:
LobbyState(void);
~LobbyState(void);
LobbyState();
~LobbyState();
bool Init( Oyster::Network::NetworkClient* nwClient );
ClientState Update( float deltaTime, InputClass* KeyInput );
bool Init( SharedStateContent &shared );
ClientState Update( float deltaTime );
bool Render();
bool Release();
void ChangeState( ClientState next );

View File

@ -24,6 +24,7 @@ struct MainState::MyData
GameClientState::ClientState nextState;
NetworkClient *nwClient;
InputClass *input;
Graphics::API::Texture background;
EventButtonCollection guiElements;
};
@ -32,20 +33,21 @@ void OnButtonInteract_Create( Oyster::Event::ButtonEvent<MainState*>& e );
void OnButtonInteract_Join( Oyster::Event::ButtonEvent<MainState*>& e );
void OnButtonInteract_Quit( Oyster::Event::ButtonEvent<MainState*>& e );
MainState::MainState(void) {}
MainState::MainState() {}
MainState::~MainState(void)
MainState::~MainState()
{
if( this->privData )
this->Release();
}
bool MainState::Init( NetworkClient* nwClient )
bool MainState::Init( SharedStateContent &shared )
{
this->privData = new MyData();
this->privData->nextState = GameClientState::ClientState_Same;
this->privData->nwClient = nwClient;
this->privData->nwClient = shared.network;
this->privData->input = shared.input;
this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" );
@ -67,12 +69,12 @@ bool MainState::Init( NetworkClient* nwClient )
return true;
}
GameClientState::ClientState MainState::Update(float deltaTime, InputClass* KeyInput)
GameClientState::ClientState MainState::Update( float deltaTime )
{
MouseInput mouseState;
{
KeyInput->GetMousePos( mouseState.x, mouseState.y );
mouseState.mouseButtonPressed = KeyInput->IsMousePressed();
this->privData->input->GetMousePos( mouseState.x, mouseState.y );
mouseState.mouseButtonPressed = this->privData->input->IsMousePressed();
}
EventHandler::Instance().Update( mouseState );

View File

@ -11,18 +11,18 @@ namespace DanBias
{
class MainState : public GameClientState
{
private:
struct MyData;
::Utility::DynamicMemory::UniquePointer<MyData> privData;
public:
MainState(void);
~MainState(void);
bool Init( Oyster::Network::NetworkClient* nwClient );
ClientState Update(float deltaTime, InputClass* KeyInput);
MainState();
~MainState();
bool Init( SharedStateContent &shared );
ClientState Update( float deltaTime );
bool Render();
bool Release();
void ChangeState( ClientState next );
private:
struct MyData;
::Utility::DynamicMemory::UniquePointer<MyData> privData;
};
}
}

View File

@ -13,6 +13,7 @@ struct NetLoadState::MyData
GameClientState::ClientState nextState;
NetworkClient *nwClient;
Graphics::API::Texture background;
bool loading;
};
@ -24,28 +25,36 @@ NetLoadState::~NetLoadState(void)
this->Release();
}
bool NetLoadState::Init( NetworkClient* nwClient )
bool NetLoadState::Init( SharedStateContent &shared )
{
this->privData = new MyData();
this->privData->nextState = GameClientState::ClientState_Same;
this->privData->nwClient = nwClient;
this->privData->nwClient = shared.network;
this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" );
this->privData->loading = false;
// we may assume that nwClient is properly connected to the server
// signals querry to server for loading instructions
nwClient->Send( Protocol_QuerryGameType() );
this->privData->nwClient->Send( Protocol_QuerryGameType() );
return true;
}
GameClientState::ClientState NetLoadState::Update(float deltaTime, InputClass* KeyInput)
GameClientState::ClientState NetLoadState::Update( float deltaTime )
{
return this->privData->nextState;
}
bool NetLoadState::Render()
{
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();
return true;
}

View File

@ -14,8 +14,8 @@ namespace DanBias
NetLoadState( );
virtual ~NetLoadState( );
bool Init( Oyster::Network::NetworkClient* nwClient );
ClientState Update( float deltaTime, InputClass* KeyInput );
bool Init( SharedStateContent &shared );
ClientState Update( float deltaTime );
bool Render();
bool Release();

View File

@ -0,0 +1,28 @@
/********************************************************************
* Created by Dan Andersson, 2014
* Contains a shared memory struct.
* Whihc reference passed seamlessly between the game states
* at their Init calls.
********************************************************************/
#ifndef SHAREDSTATECONTENT_H
#define SHAREDSTATECONTENT_H
#include <map>
#include "Utilities.h"
#include "C_Object.h"
#include "NetworkClient.h"
#include "L_inputClass.h"
namespace DanBias { namespace Client
{
struct SharedStateContent
{
public:
::std::map<int, ::Utility::DynamicMemory::UniquePointer<::DanBias::Client::C_Object>> scene;
::Oyster::Network::NetworkClient *network;
InputClass* input;
};
} }
#endif