Merge branch 'GameClient' of https://github.com/dean11/Danbias into GameClient

This commit is contained in:
lanariel 2014-02-17 13:06:54 +01:00
commit 52301021f6
21 changed files with 198 additions and 110 deletions

View File

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

View File

@ -111,7 +111,7 @@
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>Misc\Misc_$(PlatformShortName)D.lib;WindowManager\WindowManager_$(PlatformShortName)D.lib;OysterGraphics_$(PlatformShortName)D.lib;Input\Input_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<DelayLoadDLLs>NetworkAPI_$(PlatformShortName)D.dll;OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs> <DelayLoadDLLs>NetworkAPI_$(PlatformShortName)D.dll;OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
@ -128,7 +128,7 @@
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>Misc\Misc_$(PlatformShortName)D.lib;WindowManager\WindowManager_$(PlatformShortName)D.lib;OysterGraphics_$(PlatformShortName)D.lib;Input\Input_$(PlatformShortName)D.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<DelayLoadDLLs>NetworkAPI_$(PlatformShortName)D.dll;OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs> <DelayLoadDLLs>NetworkAPI_$(PlatformShortName)D.dll;OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
@ -149,7 +149,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>Misc\Misc_$(PlatformShortName).lib;WindowManager\WindowManager_$(PlatformShortName).lib;OysterGraphics_$(PlatformShortName).lib;Input\Input_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<DelayLoadDLLs>NetworkAPI_$(PlatformShortName).dll;OysterGraphics_$(PlatformShortName).dll;%(DelayLoadDLLs)</DelayLoadDLLs> <DelayLoadDLLs>NetworkAPI_$(PlatformShortName).dll;OysterGraphics_$(PlatformShortName).dll;%(DelayLoadDLLs)</DelayLoadDLLs>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
@ -170,14 +170,23 @@
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>Misc\Misc_$(PlatformShortName).lib;WindowManager\WindowManager_$(PlatformShortName).lib;OysterGraphics_$(PlatformShortName).lib;Input\Input_$(PlatformShortName).lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<DelayLoadDLLs>NetworkAPI_$(PlatformShortName).dll;OysterGraphics_$(PlatformShortName).dll;%(DelayLoadDLLs)</DelayLoadDLLs> <DelayLoadDLLs>NetworkAPI_$(PlatformShortName).dll;OysterGraphics_$(PlatformShortName).dll;%(DelayLoadDLLs)</DelayLoadDLLs>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\Misc\Input\Input.vcxproj">
<Project>{7e3990d2-3d94-465c-b58d-64a74b3ecf9b}</Project>
</ProjectReference>
<ProjectReference Include="..\..\Misc\OysterMath\OysterMath.vcxproj"> <ProjectReference Include="..\..\Misc\OysterMath\OysterMath.vcxproj">
<Project>{f10cbc03-9809-4cba-95d8-327c287b18ee}</Project> <Project>{f10cbc03-9809-4cba-95d8-327c287b18ee}</Project>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\..\Misc\Utilities\Utilities.vcxproj">
<Project>{2ec4dded-8f75-4c86-a10b-e1e8eb29f3ee}</Project>
</ProjectReference>
<ProjectReference Include="..\..\Misc\WindowManager\WindowManager.vcxproj">
<Project>{35aea3c0-e0a7-4e1e-88cd-514aa5a442b1}</Project>
</ProjectReference>
<ProjectReference Include="..\..\Network\NetworkAPI\NetworkAPI.vcxproj"> <ProjectReference Include="..\..\Network\NetworkAPI\NetworkAPI.vcxproj">
<Project>{460d625f-2ac9-4559-b809-0ba89ceaedf4}</Project> <Project>{460d625f-2ac9-4559-b809-0ba89ceaedf4}</Project>
</ProjectReference> </ProjectReference>
@ -233,6 +242,7 @@
<ClInclude Include="GameClientState\LobbyAdminState.h" /> <ClInclude Include="GameClientState\LobbyAdminState.h" />
<ClInclude Include="GameClientState\MainState.h" /> <ClInclude Include="GameClientState\MainState.h" />
<ClInclude Include="GameClientState\NetLoadState.h" /> <ClInclude Include="GameClientState\NetLoadState.h" />
<ClInclude Include="GameClientState\SharedStateContent.h" />
<ClInclude Include="Include\GameClient.h" /> <ClInclude Include="Include\GameClient.h" />
<ClInclude Include="GameClientState\LobbyState.h" /> <ClInclude Include="GameClientState\LobbyState.h" />
<ClInclude Include="GameClientState\C_Object.h" /> <ClInclude Include="GameClientState\C_Object.h" />

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<ShowAllFiles>true</ShowAllFiles> <ShowAllFiles>false</ShowAllFiles>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory> <LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>

View File

@ -8,8 +8,6 @@
#include "EventHandler/EventButton.h" #include "EventHandler/EventButton.h"
#include "DllInterfaces/GFXAPI.h" #include "DllInterfaces/GFXAPI.h"
namespace DanBias namespace DanBias
{ {
namespace Client namespace Client

View File

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

View File

@ -48,5 +48,23 @@ public:
virtual void Render(); virtual void Render();
virtual void Release(); virtual void Release();
virtual int GetId() const; 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 #endif

View File

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

View File

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

View File

@ -15,9 +15,14 @@ struct GameState::MyData
MyData(){} MyData(){}
GameClientState::ClientState nextState; GameClientState::ClientState nextState;
NetworkClient *nwClient; NetworkClient *nwClient;
InputClass *input;
::std::map<int, ::Utility::DynamicMemory::UniquePointer<::DanBias::Client::C_Object>> *staticObjects;
::std::map<int, ::Utility::DynamicMemory::UniquePointer<::DanBias::Client::C_Object>> *dynamicObjects;
} privData; } privData;
GameState::GameState(void) GameState::GameState()
{ {
key_forward = false; key_forward = false;
key_backward = false; key_backward = false;
@ -25,24 +30,25 @@ GameState::GameState(void)
key_strafeLeft = false; key_strafeLeft = false;
} }
GameState::~GameState(void) GameState::~GameState()
{ {
if( this->privData ) if( this->privData )
this->Release(); this->Release();
} }
bool GameState::Init(NetworkClient* nwClient) bool GameState::Init( SharedStateContent &shared )
{ {
// load models // load models
privData = new MyData(); privData = new MyData();
this->privData->nextState = GameClientState::ClientState_Same; this->privData->nextState = GameClientState::ClientState_Same;
this->privData->nwClient = nwClient; this->privData->nwClient = shared.network;
this->privData->input = shared.input;
LoadGame(); LoadGame();
//tell server ready //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; return true;
} }
@ -180,7 +186,7 @@ void GameState::InitiatePlayer(int id, std::wstring modelName, Float4x4 world)
camera.UpdateOrientation(); camera.UpdateOrientation();
} }
GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyInput) GameClientState::ClientState GameState::Update( float deltaTime )
{ {
//switch (privData->state) //switch (privData->state)
//{ //{

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,9 +1,11 @@
#include "NetLoadState.h" #include "NetLoadState.h"
#include "NetworkClient.h" #include "NetworkClient.h"
#include "OysterMath.h"
#include "../Game/GameProtocols/Protocols.h" #include "../Game/GameProtocols/Protocols.h"
using namespace ::DanBias::Client; using namespace ::DanBias::Client;
using namespace ::Oyster; using namespace ::Oyster;
using namespace ::Oyster::Math;
using namespace ::Oyster::Network; using namespace ::Oyster::Network;
using namespace ::GameLogic; using namespace ::GameLogic;
@ -13,6 +15,7 @@ struct NetLoadState::MyData
GameClientState::ClientState nextState; GameClientState::ClientState nextState;
NetworkClient *nwClient; NetworkClient *nwClient;
Graphics::API::Texture background;
bool loading; bool loading;
}; };
@ -24,28 +27,36 @@ NetLoadState::~NetLoadState(void)
this->Release(); this->Release();
} }
bool NetLoadState::Init( NetworkClient* nwClient ) bool NetLoadState::Init( SharedStateContent &shared )
{ {
this->privData = new MyData(); this->privData = new MyData();
this->privData->nextState = GameClientState::ClientState_Same; 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; this->privData->loading = false;
// we may assume that nwClient is properly connected to the server // we may assume that nwClient is properly connected to the server
// signals querry to server for loading instructions // signals querry to server for loading instructions
nwClient->Send( Protocol_QuerryGameType() ); this->privData->nwClient->Send( Protocol_QuerryGameType() );
return true; return true;
} }
GameClientState::ClientState NetLoadState::Update(float deltaTime, InputClass* KeyInput) GameClientState::ClientState NetLoadState::Update( float deltaTime )
{ {
return this->privData->nextState; return this->privData->nextState;
} }
bool NetLoadState::Render() 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; return true;
} }

View File

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

View File

@ -0,0 +1,29 @@
/********************************************************************
* 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>> staticObjects;
::std::map<int, ::Utility::DynamicMemory::UniquePointer<::DanBias::Client::C_Object>> dynamicObjects;
::Oyster::Network::NetworkClient *network;
InputClass* input;
};
} }
#endif