implementations

This commit is contained in:
Dander7BD 2014-02-21 09:36:43 +01:00
parent ab70cb53c4
commit ac492b413b
5 changed files with 79 additions and 160 deletions

View File

@ -21,19 +21,21 @@
#include "GameClientState/SharedStateContent.h" #include "GameClientState/SharedStateContent.h"
#include "Win32/Win32ApplicationKeyboard.h" #include "Win32/Win32ApplicationKeyboard.h"
#include "Utilities.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; using namespace ::DanBias::Client;
using namespace ::Utility::DynamicMemory;
LRESULT CALLBACK WindowCallBack(HWND handle, UINT message, WPARAM wParam, LPARAM lParam ); LRESULT CALLBACK WindowCallBack(HWND handle, UINT message, WPARAM wParam, LPARAM lParam );
void ClientEventFunction( NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e ); void ClientEventFunction( NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e );
#pragma region Game Data
namespace DanBias namespace DanBias
{ {
#pragma region Game Data
class DanBiasGamePrivateData class DanBiasGamePrivateData
{ {
public: public:
@ -51,13 +53,27 @@ namespace DanBias
DanBiasGamePrivateData() DanBiasGamePrivateData()
{ {
this->sharedStateContent.network = nullptr;
this->sharedStateContent.mouseDevice = nullptr;
this->sharedStateContent.keyboardDevice_raw = nullptr;
this->sharedStateContent.keyboardDevice_application =
this->keyboardDevice_application = new ::Input::Win32ApplicationKeyboard();
this->serverOwner = false;
this->capFrame = 0; this->capFrame = 0;
} }
} data;
~DanBiasGamePrivateData()
{
SafeDeleteInstance( this->sharedStateContent.mouseDevice );
SafeDeleteInstance( this->sharedStateContent.keyboardDevice_raw );
SafeDeleteInstance( this->sharedStateContent.keyboardDevice_application );
}
} data;
}
#pragma endregion #pragma endregion
namespace DanBias
{
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Interface API functions // Interface API functions
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -74,10 +90,10 @@ namespace DanBias
if(! data.window->CreateWin(winDesc) ) if(! data.window->CreateWin(winDesc) )
return DanBiasClientReturn_Error; return DanBiasClientReturn_Error;
if( FAILED( InitDirect3D() ) ) if( FAILED( InitInput(data.window->GetHWND()) ) )
return DanBiasClientReturn_Error; return DanBiasClientReturn_Error;
if( FAILED( InitInput(&desc.hinst) ) ) if( FAILED( InitDirect3D() ) )
return DanBiasClientReturn_Error; return DanBiasClientReturn_Error;
data.serverOwner = false; data.serverOwner = false;
@ -138,7 +154,6 @@ namespace DanBias
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
HRESULT DanBiasGame::InitDirect3D() HRESULT DanBiasGame::InitDirect3D()
{ {
Oyster::Graphics::API::Option p; Oyster::Graphics::API::Option p;
p.modelPath = L"..\\Content\\Models\\"; p.modelPath = L"..\\Content\\Models\\";
p.texturePath = L"..\\Content\\Textures\\"; p.texturePath = L"..\\Content\\Textures\\";
@ -154,44 +169,23 @@ namespace DanBias
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Init the input // Init the input
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
HRESULT DanBiasGame::InitInput( HINSTANCE *handle ) HRESULT DanBiasGame::InitInput( HWND handle )
{ {
data.sharedStateContent.mouseDevice = (Input::Mouse*)::Input::InputManager::Instance()->CreateDevice( Input::Enum::SAIType_Mouse, handle ); data.sharedStateContent.mouseDevice = dynamic_cast<Input::Mouse*>( ::Input::InputManager::Instance()->CreateDevice(Input::Enum::SAIType_Mouse, handle) );
if( !data.sharedStateContent.mouseDevice ) if( !data.sharedStateContent.mouseDevice )
{ {
data.sharedStateContent.mouseDevice = nullptr;
MessageBox( 0, L"Could not initialize the mouseDevice.", L"Error", MB_OK ); MessageBox( 0, L"Could not initialize the mouseDevice.", L"Error", MB_OK );
return E_FAIL; return E_FAIL;
} }
data.sharedStateContent.mouseDevice->Disable();
data.sharedStateContent.keyboardDevice_raw = (Input::Keyboard*)::Input::InputManager::Instance()->CreateDevice( Input::Enum::SAIType_Keyboard, handle ); data.sharedStateContent.keyboardDevice_raw = dynamic_cast<Input::Keyboard*>( ::Input::InputManager::Instance()->CreateDevice(Input::Enum::SAIType_Keyboard, handle) );
if( !data.sharedStateContent.keyboardDevice_raw ) if( !data.sharedStateContent.keyboardDevice_raw )
{ {
delete data.sharedStateContent.mouseDevice;
data.sharedStateContent.mouseDevice = nullptr;
data.sharedStateContent.keyboardDevice_raw = nullptr;
MessageBox( 0, L"Could not initialize the raw keyboard device.", L"Error", MB_OK ); MessageBox( 0, L"Could not initialize the raw keyboard device.", L"Error", MB_OK );
return E_FAIL; return E_FAIL;
} }
data.keyboardDevice_application = (Input::Win32ApplicationKeyboard*)::Input::InputManager::Instance()->CreateDevice( Input::Enum::SAIType_ApplicationKeyboard, handle );
data.sharedStateContent.keyboardDevice_application = data.keyboardDevice_application;
if( !data.sharedStateContent.keyboardDevice_application )
{
delete data.sharedStateContent.mouseDevice;
data.sharedStateContent.mouseDevice = nullptr;
delete data.sharedStateContent.keyboardDevice_raw;
data.sharedStateContent.keyboardDevice_raw = nullptr;
data.sharedStateContent.keyboardDevice_application = data.keyboardDevice_application = nullptr;
MessageBox( 0, L"Could not initialize the application keyboard device.", L"Error", MB_OK );
return E_FAIL;
}
data.keyboardDevice_application->Disable(); data.keyboardDevice_application->Disable();
return S_OK; return S_OK;
} }
@ -267,10 +261,7 @@ namespace DanBias
data.networkClient.Disconnect(); data.networkClient.Disconnect();
data.state = nullptr; data.state = nullptr;
delete data.sharedStateContent.network; SafeDeleteInstance( data.sharedStateContent.network );
delete data.sharedStateContent.mouseDevice;
delete data.sharedStateContent.keyboardDevice_raw;
delete data.sharedStateContent.keyboardDevice_application;
EventHandler::Instance().Clean(); EventHandler::Instance().Clean();
Graphics::API::Clean(); Graphics::API::Clean();
@ -284,26 +275,23 @@ namespace DanBias
LRESULT CALLBACK WindowCallBack(HWND handle, UINT message, WPARAM wParam, LPARAM lParam ) LRESULT CALLBACK WindowCallBack(HWND handle, UINT message, WPARAM wParam, LPARAM lParam )
{ {
PAINTSTRUCT ps; //PAINTSTRUCT ps;
HDC hdc; //HDC hdc;
switch ( message ) switch ( message )
{ {
case WM_PAINT: //case WM_PAINT:
hdc = BeginPaint( handle, &ps ); // hdc = BeginPaint( handle, &ps );
EndPaint( handle, &ps ); // EndPaint( handle, &ps );
break; //break;
case WM_DESTROY: case WM_DESTROY:
PostQuitMessage( 0 ); PostQuitMessage( 0 );
break; break;
default:
case WM_KEYDOWN: if( DanBias::data.keyboardDevice_application->IsActive() )
switch( wParam )
{ {
case VK_ESCAPE: DanBias::data.keyboardDevice_application->CaptureText( message, wParam );
PostQuitMessage( 0 );
break;
} }
break; break;
} }

View File

@ -251,6 +251,7 @@
<ClInclude Include="GameClientState\NetLoadState.h" /> <ClInclude Include="GameClientState\NetLoadState.h" />
<ClInclude Include="GameClientState\RespawnUI.h" /> <ClInclude Include="GameClientState\RespawnUI.h" />
<ClInclude Include="GameClientState\SharedStateContent.h" /> <ClInclude Include="GameClientState\SharedStateContent.h" />
<ClInclude Include="Include\DanBiasGame.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

@ -74,6 +74,7 @@ bool GameState::Init( SharedStateContent &shared )
this->privData->lights = &shared.lights; this->privData->lights = &shared.lights;
this->privData->keyboardInput_app->Deactivate(); this->privData->keyboardInput_app->Deactivate();
this->privData->mouseInput->Enable();
Graphics::API::Option gfxOp = Graphics::API::GetOption(); Graphics::API::Option gfxOp = Graphics::API::GetOption();
Float aspectRatio = gfxOp.Resolution.x / gfxOp.Resolution.y; Float aspectRatio = gfxOp.Resolution.x / gfxOp.Resolution.y;
@ -100,7 +101,7 @@ bool GameState::Init( SharedStateContent &shared )
} }
// create UI states // create UI states
this->gameUI = new GamingUI(this->privData->input, this->privData->nwClient, &this->privData->camera); this->gameUI = new GamingUI(this->privData->mouseInput, this->privData->keyboardInput_raw, this->privData->nwClient, &this->privData->camera);
this->respawnUI = new RespawnUI(this->privData->nwClient, 20); this->respawnUI = new RespawnUI(this->privData->nwClient, 20);
this->currGameUI = gameUI; this->currGameUI = gameUI;
((GamingUI*)gameUI)->Init(); ((GamingUI*)gameUI)->Init();
@ -267,6 +268,8 @@ bool GameState::Release()
Graphics::API::Option o = Graphics::API::GetOption(); Graphics::API::Option o = Graphics::API::GetOption();
if( privData ) if( privData )
{ {
this->privData->mouseInput->Disable();
auto staticObject = this->privData->staticObjects->begin(); auto staticObject = this->privData->staticObjects->begin();
for( ; staticObject != this->privData->staticObjects->end(); ++staticObject ) for( ; staticObject != this->privData->staticObjects->end(); ++staticObject )
{ {
@ -317,80 +320,6 @@ void GameState::ChangeState( ClientState next )
void GameState::ReadKeyInput() void GameState::ReadKeyInput()
{ {
if( this->privData->keyboardInput_raw->IsKeyDown(::Input::Enum::SAKI_W) )
{ // move forward
this->privData->nwClient->Send( Protocol_PlayerMovementForward() );
this->privData->key_forward = true;
}
if( this->privData->keyboardInput_raw->IsKeyDown(::Input::Enum::SAKI_S) )
{ // move backward
this->privData->nwClient->Send( Protocol_PlayerMovementBackward() );
this->privData->key_backward = true;
}
if( this->privData->keyboardInput_raw->IsKeyDown(::Input::Enum::SAKI_A) )
{ // strafe left
this->privData->nwClient->Send( Protocol_PlayerMovementLeft() );
this->privData->key_strafeLeft = true;
}
if( this->privData->keyboardInput_raw->IsKeyDown(::Input::Enum::SAKI_D) )
{ // strafe right
this->privData->nwClient->Send( Protocol_PlayerMovementRight() );
this->privData->key_strafeRight = true;
}
if( this->privData->keyboardInput_raw->IsKeyDown(::Input::Enum::SAKI_Space) )
{ // jump
this->privData->nwClient->Send( Protocol_PlayerJump() );
this->privData->key_Jump = true;
}
//send delta mouse movement
{
static const float mouseSensitivity = Radian( 1.0f );
::Input::Struct::SAIPoint2D deltaPos;
this->privData->mouseInput->GetDeltaPosition( deltaPos );
this->privData->camera.PitchDown( deltaPos.y * mouseSensitivity );;
//if( deltaPos.x != 0.0f ) //This made the camera reset to a specific rotation. Why?
{
this->privData->nwClient->Send( Protocol_PlayerLeftTurn(deltaPos.x * mouseSensitivity) );
}
}
}
// shoot
if( this->privData->mouseInput->IsBtnDown(::Input::Enum::SAMI_MouseLeftBtn) )
{
Protocol_PlayerShot playerShot;
playerShot.primaryPressed = true;
playerShot.secondaryPressed = false;
playerShot.utilityPressed = false;
this->privData->nwClient->Send( playerShot );
this->privData->key_Shoot = true;
}
else if( this->privData->mouseInput->IsBtnDown(::Input::Enum::SAMI_MouseRightBtn) )
{
Protocol_PlayerShot playerShot;
playerShot.primaryPressed = false;
playerShot.secondaryPressed = true;
playerShot.utilityPressed = false;
this->privData->nwClient->Send( playerShot );
this->privData->key_Shoot = true;
}
else if( this->privData->mouseInput->IsBtnDown(::Input::Enum::SAMI_MouseMiddleBtn) )
{
Protocol_PlayerShot playerShot;
playerShot.primaryPressed = false;
playerShot.secondaryPressed = false;
playerShot.utilityPressed = true;
this->privData->nwClient->Send( playerShot );
this->privData->key_Shoot = true;
}
#ifdef _DEBUG // DEGUG KEYS #ifdef _DEBUG // DEGUG KEYS
// Reload shaders // Reload shaders

View File

@ -79,39 +79,39 @@ bool GamingUI::Release()
void GamingUI::ReadKeyInput() void GamingUI::ReadKeyInput()
{ {
if( this->input->IsKeyPressed(DIK_W) ) if( this->keyboardInput->IsKeyDown(::Input::Enum::SAKI_W) )
{ { // move forward
this->netClient->Send( Protocol_PlayerMovementForward() ); this->netClient->Send( Protocol_PlayerMovementForward() );
} }
if( this->input->IsKeyPressed(DIK_S) ) if( this->keyboardInput->IsKeyDown(::Input::Enum::SAKI_S) )
{ { // move backward
this->netClient->Send( Protocol_PlayerMovementBackward() ); this->netClient->Send( Protocol_PlayerMovementBackward() );
} }
if( this->input->IsKeyPressed(DIK_A) ) if( this->keyboardInput->IsKeyDown(::Input::Enum::SAKI_A) )
{ { // strafe left
this->netClient->Send( Protocol_PlayerMovementLeft() ); this->netClient->Send( Protocol_PlayerMovementLeft() );
} }
if( this->input->IsKeyPressed(DIK_D) ) if( this->keyboardInput->IsKeyDown(::Input::Enum::SAKI_D) )
{ { // strafe right
this->netClient->Send( Protocol_PlayerMovementRight() ); this->netClient->Send( Protocol_PlayerMovementRight() );
} }
//send delta mouse movement if( this->keyboardInput->IsKeyDown(::Input::Enum::SAKI_Space) )
{ // jump
if(!this->key_Jump)
{ {
static const float mouseSensitivity = Radian( 1.0f ); this->netClient->Send( Protocol_PlayerJump() );
this->camera->PitchDown( this->input->GetPitch() * mouseSensitivity ); this->key_Jump = true;
float yaw = this->input->GetYaw();
//if( yaw != 0.0f ) //This made the camera reset to a specific rotation.
{
this->netClient->Send( Protocol_PlayerLeftTurn(yaw * mouseSensitivity) );
} }
} }
else
this->key_Jump = false;
// shoot // shoot
if( this->input->IsKeyPressed(DIK_Z) ) if( this->mouseInput->IsBtnDown(::Input::Enum::SAMI_MouseLeftBtn) )
{ {
if( !this->key_Shoot ) if( !this->key_Shoot )
{ {
@ -125,7 +125,8 @@ void GamingUI::ReadKeyInput()
} }
else else
this->key_Shoot = false; this->key_Shoot = false;
if( this->input->IsKeyPressed(DIK_X) )
if( this->mouseInput->IsBtnDown(::Input::Enum::SAMI_MouseRightBtn) )
{ {
if( !this->key_Shoot ) if( !this->key_Shoot )
{ {
@ -139,7 +140,8 @@ void GamingUI::ReadKeyInput()
} }
else else
this->key_Shoot = false; this->key_Shoot = false;
if( this->input->IsKeyPressed(DIK_C) )
if( this->mouseInput->IsBtnDown(::Input::Enum::SAMI_MouseMiddleBtn) )
{ {
if( !this->key_Shoot ) if( !this->key_Shoot )
{ {
@ -154,23 +156,22 @@ void GamingUI::ReadKeyInput()
else else
this->key_Shoot = false; this->key_Shoot = false;
// jump //send delta mouse movement
if( this->input->IsKeyPressed(DIK_SPACE) )
{ {
if(!this->key_Jump) static const float mouseSensitivity = Radian( 1.0f );
{ ::Input::Struct::SAIPoint2D deltaPos;
this->netClient->Send( Protocol_PlayerJump() ); this->mouseInput->GetDeltaPosition( deltaPos );
this->key_Jump = true;
}
}
else
this->key_Jump = false;
if( this->input->IsKeyPressed(DIK_ESCAPE) ) this->camera->PitchDown( deltaPos.y * mouseSensitivity );;
//if( deltaPos.x != 0.0f ) //This made the camera reset to a specific rotation. Why?
{
this->netClient->Send( Protocol_PlayerLeftTurn(deltaPos.x * mouseSensitivity) );
}
}
if( this->keyboardInput->IsKeyDown(::Input::Enum::SAKI_Escape) )
{ {
this->nextState = GameStateUI::UIState_shut_down; this->nextState = GameStateUI::UIState_shut_down;
} }
// !DEGUG KEYS
// TODO: implement sub-menu
} }

View File

@ -55,7 +55,7 @@ namespace DanBias
}; };
static HRESULT InitDirect3D(); static HRESULT InitDirect3D();
static HRESULT InitInput( HINSTANCE *handle ); static HRESULT InitInput( HWND handle );
static Result Update(float deltaTime); static Result Update(float deltaTime);
static HRESULT Render(); static HRESULT Render();