From aa2518a4f6a7ea511b11352ebec0387c87ea7868 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Mon, 17 Feb 2014 11:27:43 +0100 Subject: [PATCH] Patch --- Code/Game/GameClient/DanBiasGame_Impl.cpp | 33 ++++---- .../GameClientState/Buttons/EventButtonGUI.h | 4 +- .../GameClient/GameClientState/C_Object.cpp | 6 +- .../GameClient/GameClientState/C_Object.h | 78 ++++++++++++------- .../GameClientState/GameClientState.cpp | 4 +- .../GameClientState/GameClientState.h | 11 ++- .../GameClient/GameClientState/GameState.cpp | 14 ++-- .../GameClient/GameClientState/GameState.h | 4 +- .../GameClientState/LanMenuState.cpp | 12 +-- .../GameClient/GameClientState/LanMenuState.h | 4 +- .../GameClientState/LevelLoader/LevelLoader.h | 2 +- .../GameClientState/LevelLoader/LevelParser.h | 2 +- .../GameClientState/LevelLoader/Loader.h | 2 +- .../GameClientState/LobbyAdminState.cpp | 12 +-- .../GameClientState/LobbyAdminState.h | 4 +- .../GameClient/GameClientState/LobbyState.cpp | 12 +-- .../GameClient/GameClientState/LobbyState.h | 8 +- .../GameClient/GameClientState/MainState.cpp | 16 ++-- .../GameClient/GameClientState/MainState.h | 14 ++-- .../GameClientState/NetLoadState.cpp | 17 +++- .../GameClient/GameClientState/NetLoadState.h | 4 +- .../GameClientState/SharedStateContent.h | 28 +++++++ 22 files changed, 182 insertions(+), 109 deletions(-) create mode 100644 Code/Game/GameClient/GameClientState/SharedStateContent.h diff --git a/Code/Game/GameClient/DanBiasGame_Impl.cpp b/Code/Game/GameClient/DanBiasGame_Impl.cpp index 21d5589f..244568c2 100644 --- a/Code/Game/GameClient/DanBiasGame_Impl.cpp +++ b/Code/Game/GameClient/DanBiasGame_Impl.cpp @@ -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 e ); @@ -32,15 +35,17 @@ namespace DanBias #pragma region Game Data class DanBiasGamePrivateData { - public: WindowShell* window; - InputClass* inputObj; + InputClass inputObj; Utility::WinTimer timer; - UniquePointer state; - NetworkClient networkClient; - bool serverOwner; + UniquePointer 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(); diff --git a/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h b/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h index c770cb9c..d4981c23 100644 --- a/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h +++ b/Code/Game/GameClient/GameClientState/Buttons/EventButtonGUI.h @@ -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" diff --git a/Code/Game/GameClient/GameClientState/C_Object.cpp b/Code/Game/GameClient/GameClientState/C_Object.cpp index d44d9201..92b55c53 100644 --- a/Code/Game/GameClient/GameClientState/C_Object.cpp +++ b/Code/Game/GameClient/GameClientState/C_Object.cpp @@ -100,5 +100,9 @@ void C_Object::Render() } void C_Object::Release() { - Oyster::Graphics::API::DeleteModel(model); + if( this->model ) + { + Oyster::Graphics::API::DeleteModel(model); + this->model = nullptr; + } } \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/C_Object.h b/Code/Game/GameClient/GameClientState/C_Object.h index ae9dc3a5..20e0eb60 100644 --- a/Code/Game/GameClient/GameClientState/C_Object.h +++ b/Code/Game/GameClient/GameClientState/C_Object.h @@ -16,37 +16,55 @@ namespace DanBias bool visible; }; -class C_Object -{ -private: - Oyster::Math::Float4x4 world; - Oyster::Math::Float3 position; - Oyster::Math::Quaternion rotation; - Oyster::Math::Float3 scale; + class C_Object + { + private: + Oyster::Math::Float4x4 world; + Oyster::Math::Float3 position; + Oyster::Math::Quaternion rotation; + Oyster::Math::Float3 scale; - int id; - void updateWorld(); -protected: - Oyster::Graphics::Model::Model *model; -public: - C_Object(); - virtual ~C_Object(); - virtual bool Init(ModelInitData modelInit); + int id; + void updateWorld(); + protected: + Oyster::Graphics::Model::Model *model; + public: + C_Object(); + virtual ~C_Object(); + virtual bool Init(ModelInitData modelInit); - void setWorld(Oyster::Math::Float4x4 world); - Oyster::Math::Float4x4 getWorld() const; - void setPos(Oyster::Math::Float3 newPos); - Oyster::Math::Float3 getPos() const; - void addPos(Oyster::Math::Float3 deltaPos); - void setRot(Oyster::Math::Quaternion newRot); - Oyster::Math::Quaternion getRotation() const; - void addRot(Oyster::Math::Quaternion deltaRot); - void setScale(Oyster::Math::Float3 newScale); - void addScale(Oyster::Math::Float3 deltaScale); - Oyster::Math::Float3 getScale() const; + void setWorld(Oyster::Math::Float4x4 world); + Oyster::Math::Float4x4 getWorld() const; + void setPos(Oyster::Math::Float3 newPos); + Oyster::Math::Float3 getPos() const; + void addPos(Oyster::Math::Float3 deltaPos); + void setRot(Oyster::Math::Quaternion newRot); + Oyster::Math::Quaternion getRotation() const; + void addRot(Oyster::Math::Quaternion deltaRot); + void setScale(Oyster::Math::Float3 newScale); + void addScale(Oyster::Math::Float3 deltaScale); + Oyster::Math::Float3 getScale() const; + + 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; + } + } +} } - virtual void Render(); - virtual void Release(); - virtual int GetId() const; -};};}; #endif diff --git a/Code/Game/GameClient/GameClientState/GameClientState.cpp b/Code/Game/GameClient/GameClientState/GameClientState.cpp index 9db00f9d..dab88b2e 100644 --- a/Code/Game/GameClient/GameClientState/GameClientState.cpp +++ b/Code/Game/GameClient/GameClientState/GameClientState.cpp @@ -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 e ) { /* do nothing */ } \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/GameClientState.h b/Code/Game/GameClient/GameClientState/GameClientState.h index 9317413e..3822c7b0 100644 --- a/Code/Game/GameClient/GameClientState/GameClientState.h +++ b/Code/Game/GameClient/GameClientState/GameClientState.h @@ -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; diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 66ca6c12..349eaaeb 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -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) //{ diff --git a/Code/Game/GameClient/GameClientState/GameState.h b/Code/Game/GameClient/GameClientState/GameState.h index 6366bb8c..5a3b3c1a 100644 --- a/Code/Game/GameClient/GameClientState/GameState.h +++ b/Code/Game/GameClient/GameClientState/GameState.h @@ -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) ; diff --git a/Code/Game/GameClient/GameClientState/LanMenuState.cpp b/Code/Game/GameClient/GameClientState/LanMenuState.cpp index 6a836a36..7faf5d55 100644 --- a/Code/Game/GameClient/GameClientState/LanMenuState.cpp +++ b/Code/Game/GameClient/GameClientState/LanMenuState.cpp @@ -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 ); diff --git a/Code/Game/GameClient/GameClientState/LanMenuState.h b/Code/Game/GameClient/GameClientState/LanMenuState.h index 8f3e8e67..57889eee 100644 --- a/Code/Game/GameClient/GameClientState/LanMenuState.h +++ b/Code/Game/GameClient/GameClientState/LanMenuState.h @@ -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(); diff --git a/Code/Game/GameClient/GameClientState/LevelLoader/LevelLoader.h b/Code/Game/GameClient/GameClientState/LevelLoader/LevelLoader.h index aa67c4f5..184a7005 100644 --- a/Code/Game/GameClient/GameClientState/LevelLoader/LevelLoader.h +++ b/Code/Game/GameClient/GameClientState/LevelLoader/LevelLoader.h @@ -7,7 +7,7 @@ #include #include -#include "Utilities.h" +#include "../Misc/Utilities.h" #include "ObjectDefines.h" namespace GameLogic diff --git a/Code/Game/GameClient/GameClientState/LevelLoader/LevelParser.h b/Code/Game/GameClient/GameClientState/LevelLoader/LevelParser.h index 8f2a9150..346b75b5 100644 --- a/Code/Game/GameClient/GameClientState/LevelLoader/LevelParser.h +++ b/Code/Game/GameClient/GameClientState/LevelLoader/LevelParser.h @@ -4,7 +4,7 @@ #include #include #include "ObjectDefines.h" -#include "Utilities.h" +#include "../Misc/Utilities.h" namespace GameLogic { diff --git a/Code/Game/GameClient/GameClientState/LevelLoader/Loader.h b/Code/Game/GameClient/GameClientState/LevelLoader/Loader.h index 0433194e..198c2a87 100644 --- a/Code/Game/GameClient/GameClientState/LevelLoader/Loader.h +++ b/Code/Game/GameClient/GameClientState/LevelLoader/Loader.h @@ -5,7 +5,7 @@ #ifndef LOADER_H #define LOADER_H -#include "Resource\OysterResource.h" +#include "..\Misc\Resource\OysterResource.h" #include namespace GameLogic diff --git a/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp b/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp index c157226e..6cc1f15f 100644 --- a/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp +++ b/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp @@ -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 ); diff --git a/Code/Game/GameClient/GameClientState/LobbyAdminState.h b/Code/Game/GameClient/GameClientState/LobbyAdminState.h index 06a9aced..49ae9274 100644 --- a/Code/Game/GameClient/GameClientState/LobbyAdminState.h +++ b/Code/Game/GameClient/GameClientState/LobbyAdminState.h @@ -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 ); diff --git a/Code/Game/GameClient/GameClientState/LobbyState.cpp b/Code/Game/GameClient/GameClientState/LobbyState.cpp index 47a3cebb..6c5b2606 100644 --- a/Code/Game/GameClient/GameClientState/LobbyState.cpp +++ b/Code/Game/GameClient/GameClientState/LobbyState.cpp @@ -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 ); diff --git a/Code/Game/GameClient/GameClientState/LobbyState.h b/Code/Game/GameClient/GameClientState/LobbyState.h index 7b6e5909..694aaa38 100644 --- a/Code/Game/GameClient/GameClientState/LobbyState.h +++ b/Code/Game/GameClient/GameClientState/LobbyState.h @@ -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 ); diff --git a/Code/Game/GameClient/GameClientState/MainState.cpp b/Code/Game/GameClient/GameClientState/MainState.cpp index 81794252..1fd1d813 100644 --- a/Code/Game/GameClient/GameClientState/MainState.cpp +++ b/Code/Game/GameClient/GameClientState/MainState.cpp @@ -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& e ); void OnButtonInteract_Join( Oyster::Event::ButtonEvent& e ); void OnButtonInteract_Quit( Oyster::Event::ButtonEvent& 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 ); diff --git a/Code/Game/GameClient/GameClientState/MainState.h b/Code/Game/GameClient/GameClientState/MainState.h index 7255e917..22589686 100644 --- a/Code/Game/GameClient/GameClientState/MainState.h +++ b/Code/Game/GameClient/GameClientState/MainState.h @@ -11,18 +11,18 @@ namespace DanBias { class MainState : public GameClientState { - private: - struct MyData; - ::Utility::DynamicMemory::UniquePointer 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 privData; }; } } diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.cpp b/Code/Game/GameClient/GameClientState/NetLoadState.cpp index c8fd1e64..ac7dd78b 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.cpp +++ b/Code/Game/GameClient/GameClientState/NetLoadState.cpp @@ -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; } diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.h b/Code/Game/GameClient/GameClientState/NetLoadState.h index ff2d1acc..ea9f9f6a 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.h +++ b/Code/Game/GameClient/GameClientState/NetLoadState.h @@ -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(); diff --git a/Code/Game/GameClient/GameClientState/SharedStateContent.h b/Code/Game/GameClient/GameClientState/SharedStateContent.h new file mode 100644 index 00000000..567be2fa --- /dev/null +++ b/Code/Game/GameClient/GameClientState/SharedStateContent.h @@ -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 +#include "Utilities.h" +#include "C_Object.h" +#include "NetworkClient.h" +#include "L_inputClass.h" + +namespace DanBias { namespace Client +{ + struct SharedStateContent + { + public: + ::std::map> scene; + ::Oyster::Network::NetworkClient *network; + InputClass* input; + }; +} } + +#endif \ No newline at end of file