parent
af85a6efdc
commit
6becd58833
|
@ -216,7 +216,6 @@
|
||||||
<ClCompile Include="GameClientState\MainState.cpp" />
|
<ClCompile Include="GameClientState\MainState.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="GameClientRecieverFunc.h" />
|
|
||||||
<ClInclude Include="GameClientState\Camera_Basic.h" />
|
<ClInclude Include="GameClientState\Camera_Basic.h" />
|
||||||
<ClInclude Include="GameClientState\Camera.h" />
|
<ClInclude Include="GameClientState\Camera.h" />
|
||||||
<ClInclude Include="GameClientState\Camera_FPS.h" />
|
<ClInclude Include="GameClientState\Camera_FPS.h" />
|
||||||
|
|
|
@ -15,40 +15,39 @@
|
||||||
#include "L_inputClass.h"
|
#include "L_inputClass.h"
|
||||||
#include "WinTimer.h"
|
#include "WinTimer.h"
|
||||||
#include "vld.h"
|
#include "vld.h"
|
||||||
#include "GameClientRecieverFunc.h"
|
|
||||||
|
|
||||||
#include "../Misc/EventHandler/EventHandler.h"
|
#include "../Misc/EventHandler/EventHandler.h"
|
||||||
|
|
||||||
using namespace ::Oyster::Event;
|
using namespace ::Oyster::Event;
|
||||||
|
using namespace Oyster::Network;
|
||||||
using namespace ::Utility::DynamicMemory;
|
using namespace ::Utility::DynamicMemory;
|
||||||
|
|
||||||
|
void ClientEventFunction( NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e );
|
||||||
|
|
||||||
namespace DanBias
|
namespace DanBias
|
||||||
{
|
{
|
||||||
|
|
||||||
#pragma region Game Data
|
#pragma region Game Data
|
||||||
|
|
||||||
class DanBiasGamePrivateData
|
class DanBiasGamePrivateData
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
|
||||||
DanBiasGamePrivateData() {}
|
|
||||||
|
|
||||||
~DanBiasGamePrivateData() {}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
WindowShell* window;
|
WindowShell* window;
|
||||||
InputClass* inputObj;
|
InputClass* inputObj;
|
||||||
Utility::WinTimer timer;
|
Utility::WinTimer timer;
|
||||||
UniquePointer<Client::GameClientState> state;
|
UniquePointer<Client::GameClientState> state;
|
||||||
|
NetworkClient networkClient;
|
||||||
bool serverOwner;
|
bool serverOwner;
|
||||||
|
|
||||||
|
float capFrame;
|
||||||
|
|
||||||
|
DanBiasGamePrivateData()
|
||||||
|
{
|
||||||
|
this->capFrame = 0;
|
||||||
|
}
|
||||||
} data;
|
} data;
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
|
|
||||||
DanBiasGamePrivateData* DanBiasGame::m_data = new DanBiasGamePrivateData();
|
|
||||||
float DanBiasGame::capFrame = 0;
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
// Interface API functions
|
// Interface API functions
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
@ -56,8 +55,8 @@ namespace DanBias
|
||||||
{
|
{
|
||||||
|
|
||||||
WindowShell::CreateConsoleWindow();
|
WindowShell::CreateConsoleWindow();
|
||||||
//if(! m_data->window->CreateWin(WindowShell::WINDOW_INIT_DESC(L"Window", cPOINT(1600, 900), cPOINT())))
|
//if(! data.window->CreateWin(WindowShell::WINDOW_INIT_DESC(L"Window", cPOINT(1600, 900), cPOINT())))
|
||||||
if(! m_data->window->CreateWin(WindowShell::WINDOW_INIT_DESC()))
|
if(! data.window->CreateWin(WindowShell::WINDOW_INIT_DESC()))
|
||||||
return DanBiasClientReturn_Error;
|
return DanBiasClientReturn_Error;
|
||||||
|
|
||||||
if( FAILED( InitDirect3D() ) )
|
if( FAILED( InitDirect3D() ) )
|
||||||
|
@ -66,37 +65,39 @@ namespace DanBias
|
||||||
if( FAILED( InitInput() ) )
|
if( FAILED( InitInput() ) )
|
||||||
return DanBiasClientReturn_Error;
|
return DanBiasClientReturn_Error;
|
||||||
|
|
||||||
//m_data->serverOwner = false;
|
data.serverOwner = false;
|
||||||
|
|
||||||
// Start in lobby state
|
data.networkClient.SetMessagePump( ClientEventFunction );
|
||||||
m_data->state = new Client::MainState();
|
|
||||||
|
|
||||||
if( !m_data->state->Init() )
|
// Start in main menu state
|
||||||
|
data.state = new Client::MainState();
|
||||||
|
|
||||||
|
if( !data.state->Init( &data.networkClient ) )
|
||||||
return DanBiasClientReturn_Error;
|
return DanBiasClientReturn_Error;
|
||||||
|
|
||||||
m_data->timer.reset();
|
data.timer.reset();
|
||||||
return DanBiasClientReturn_Sucess;
|
return DanBiasClientReturn_Sucess;
|
||||||
}
|
}
|
||||||
|
|
||||||
DanBiasClientReturn DanBiasGame::Run()
|
DanBiasClientReturn DanBiasGame::Run()
|
||||||
{
|
{
|
||||||
// Main message loop
|
// Main message loop
|
||||||
while(m_data->window->Frame())
|
while(data.window->Frame())
|
||||||
{
|
{
|
||||||
float dt = (float)m_data->timer.getElapsedSeconds();
|
float dt = (float)data.timer.getElapsedSeconds();
|
||||||
m_data->timer.reset();
|
data.timer.reset();
|
||||||
|
|
||||||
if(m_data->recieverObj->IsConnected())
|
if(data.networkClient.IsConnected())
|
||||||
m_data->recieverObj->Update();
|
data.networkClient.Update();
|
||||||
|
|
||||||
capFrame += dt;
|
data.capFrame += dt;
|
||||||
if(capFrame > 0.03)
|
if(data.capFrame > 0.03)
|
||||||
{
|
{
|
||||||
if(Update(dt) != S_OK)
|
if(Update(dt) != S_OK)
|
||||||
return DanBiasClientReturn_Error;
|
return DanBiasClientReturn_Error;
|
||||||
if(Render(dt) != S_OK)
|
if(Render(dt) != S_OK)
|
||||||
return DanBiasClientReturn_Error;
|
return DanBiasClientReturn_Error;
|
||||||
capFrame = 0;
|
data.capFrame = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -113,7 +114,7 @@ namespace DanBias
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
HRESULT DanBiasGame::InitDirect3D()
|
HRESULT DanBiasGame::InitDirect3D()
|
||||||
{
|
{
|
||||||
if(Oyster::Graphics::API::Init(m_data->window->GetHWND(), false, false, Oyster::Math::Float2( 1024, 768)) != Oyster::Graphics::API::Sucsess)
|
if(Oyster::Graphics::API::Init(data.window->GetHWND(), false, false, Oyster::Math::Float2( 1024, 768)) != Oyster::Graphics::API::Sucsess)
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
Oyster::Graphics::API::Option p;
|
Oyster::Graphics::API::Option p;
|
||||||
p.modelPath = L"..\\Content\\Models\\";
|
p.modelPath = L"..\\Content\\Models\\";
|
||||||
|
@ -127,8 +128,8 @@ namespace DanBias
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
HRESULT DanBiasGame::InitInput()
|
HRESULT DanBiasGame::InitInput()
|
||||||
{
|
{
|
||||||
m_data->inputObj = new InputClass;
|
data.inputObj = new InputClass;
|
||||||
if(!m_data->inputObj->Initialize(m_data->window->GetHINSTANCE(), m_data->window->GetHWND(), m_data->window->GetHeight(), m_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;
|
||||||
|
@ -138,30 +139,29 @@ namespace DanBias
|
||||||
|
|
||||||
HRESULT DanBiasGame::Update(float deltaTime)
|
HRESULT DanBiasGame::Update(float deltaTime)
|
||||||
{
|
{
|
||||||
m_data->inputObj->Update();
|
data.inputObj->Update();
|
||||||
|
|
||||||
if(m_data->serverOwner)
|
if(data.serverOwner)
|
||||||
{
|
{
|
||||||
DanBias::GameServerAPI::ServerUpdate();
|
DanBias::GameServerAPI::ServerUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
DanBias::Client::GameClientState::ClientState state = DanBias::Client::GameClientState::ClientState_Same;
|
DanBias::Client::GameClientState::ClientState state = DanBias::Client::GameClientState::ClientState_Same;
|
||||||
state = m_data->recieverObj->gameClientState->Update(deltaTime, m_data->inputObj);
|
|
||||||
|
state = data.state->Update( deltaTime, data.inputObj );
|
||||||
|
|
||||||
if(state != Client::GameClientState::ClientState_Same)
|
if(state != Client::GameClientState::ClientState_Same)
|
||||||
{
|
{
|
||||||
bool stateVal = false;
|
bool stateVal = false;
|
||||||
m_data->recieverObj->gameClientState->Release();
|
data.state->Release();
|
||||||
delete m_data->recieverObj->gameClientState;
|
|
||||||
m_data->recieverObj->gameClientState = NULL;
|
|
||||||
|
|
||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case Client::GameClientState::ClientState_LobbyCreated:
|
case Client::GameClientState::ClientState_LobbyCreated:
|
||||||
m_data->serverOwner = true;
|
data.serverOwner = true;
|
||||||
stateVal = true;
|
stateVal = true;
|
||||||
case Client::GameClientState::ClientState_Lobby:
|
case Client::GameClientState::ClientState_Lobby:
|
||||||
m_data->recieverObj->gameClientState = new Client::LobbyState();
|
data.state = new Client::LobbyState();
|
||||||
stateVal = true;
|
stateVal = true;
|
||||||
break;
|
break;
|
||||||
case Client::GameClientState::ClientState_Game:
|
case Client::GameClientState::ClientState_Game:
|
||||||
|
@ -174,7 +174,7 @@ namespace DanBias
|
||||||
|
|
||||||
if(stateVal)
|
if(stateVal)
|
||||||
{
|
{
|
||||||
m_data->recieverObj->gameClientState->Init(m_data->recieverObj); // send game client
|
data.state->Init( &data.networkClient ); // send game client
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -187,21 +187,15 @@ namespace DanBias
|
||||||
|
|
||||||
HRESULT DanBiasGame::Render(float deltaTime)
|
HRESULT DanBiasGame::Render(float deltaTime)
|
||||||
{
|
{
|
||||||
|
data.state->Render();
|
||||||
|
|
||||||
m_data->recieverObj->gameClientState->Render();
|
|
||||||
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT DanBiasGame::CleanUp()
|
HRESULT DanBiasGame::CleanUp()
|
||||||
{
|
{
|
||||||
m_data->recieverObj->gameClientState->Release();
|
data.networkClient.Disconnect();
|
||||||
delete m_data->recieverObj->gameClientState;
|
delete data.inputObj;
|
||||||
m_data->recieverObj->Disconnect();
|
|
||||||
delete m_data->recieverObj;
|
|
||||||
delete m_data->inputObj;
|
|
||||||
delete m_data;
|
|
||||||
|
|
||||||
Oyster::Graphics::API::Clean();
|
Oyster::Graphics::API::Clean();
|
||||||
|
|
||||||
|
@ -210,4 +204,10 @@ namespace DanBias
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
} //End namespace DanBias
|
} //End namespace DanBias
|
||||||
|
|
||||||
|
void ClientEventFunction( NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e )
|
||||||
|
{
|
||||||
|
if( DanBias::data.state )
|
||||||
|
DanBias::data.state->DataRecieved( e );
|
||||||
|
}
|
||||||
|
|
|
@ -31,4 +31,18 @@ namespace DanBias { namespace Client
|
||||||
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 );
|
||||||
};
|
};
|
||||||
} }
|
} }
|
||||||
|
|
||||||
|
namespace Utility { namespace DynamicMemory
|
||||||
|
{ // template specializationto allowuse of dynamicmemory tools
|
||||||
|
template<>
|
||||||
|
inline void SafeDeleteInstance( ::DanBias::Client::GameClientState *dynamicInstance )
|
||||||
|
{
|
||||||
|
if( dynamicInstance )
|
||||||
|
{
|
||||||
|
dynamicInstance->Release();
|
||||||
|
delete dynamicInstance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} }
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -15,8 +15,6 @@
|
||||||
#define NOMINMAX
|
#define NOMINMAX
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace DanBias
|
namespace DanBias
|
||||||
{
|
{
|
||||||
extern "C"
|
extern "C"
|
||||||
|
@ -56,12 +54,6 @@ namespace DanBias
|
||||||
static HRESULT Update(float deltaTime);
|
static HRESULT Update(float deltaTime);
|
||||||
static HRESULT Render(float deltaTime);
|
static HRESULT Render(float deltaTime);
|
||||||
static HRESULT CleanUp();
|
static HRESULT CleanUp();
|
||||||
|
|
||||||
static float capFrame;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static DanBiasGamePrivateData* m_data;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue