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

View File

@ -251,6 +251,7 @@
<ClInclude Include="GameClientState\NetLoadState.h" />
<ClInclude Include="GameClientState\RespawnUI.h" />
<ClInclude Include="GameClientState\SharedStateContent.h" />
<ClInclude Include="Include\DanBiasGame.h" />
<ClInclude Include="Include\GameClient.h" />
<ClInclude Include="GameClientState\LobbyState.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->keyboardInput_app->Deactivate();
this->privData->mouseInput->Enable();
Graphics::API::Option gfxOp = Graphics::API::GetOption();
Float aspectRatio = gfxOp.Resolution.x / gfxOp.Resolution.y;
@ -100,7 +101,7 @@ bool GameState::Init( SharedStateContent &shared )
}
// 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->currGameUI = gameUI;
((GamingUI*)gameUI)->Init();
@ -267,6 +268,8 @@ bool GameState::Release()
Graphics::API::Option o = Graphics::API::GetOption();
if( privData )
{
this->privData->mouseInput->Disable();
auto staticObject = this->privData->staticObjects->begin();
for( ; staticObject != this->privData->staticObjects->end(); ++staticObject )
{
@ -317,80 +320,6 @@ void GameState::ChangeState( ClientState next )
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
// Reload shaders

View File

@ -79,39 +79,39 @@ bool GamingUI::Release()
void GamingUI::ReadKeyInput()
{
if( this->input->IsKeyPressed(DIK_W) )
{
if( this->keyboardInput->IsKeyDown(::Input::Enum::SAKI_W) )
{ // move forward
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() );
}
if( this->input->IsKeyPressed(DIK_A) )
{
if( this->keyboardInput->IsKeyDown(::Input::Enum::SAKI_A) )
{ // strafe left
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() );
}
//send delta mouse movement
{
static const float mouseSensitivity = Radian( 1.0f );
this->camera->PitchDown( this->input->GetPitch() * mouseSensitivity );
float yaw = this->input->GetYaw();
//if( yaw != 0.0f ) //This made the camera reset to a specific rotation.
if( this->keyboardInput->IsKeyDown(::Input::Enum::SAKI_Space) )
{ // jump
if(!this->key_Jump)
{
this->netClient->Send( Protocol_PlayerLeftTurn(yaw * mouseSensitivity) );
this->netClient->Send( Protocol_PlayerJump() );
this->key_Jump = true;
}
}
else
this->key_Jump = false;
// shoot
if( this->input->IsKeyPressed(DIK_Z) )
if( this->mouseInput->IsBtnDown(::Input::Enum::SAMI_MouseLeftBtn) )
{
if( !this->key_Shoot )
{
@ -125,7 +125,8 @@ void GamingUI::ReadKeyInput()
}
else
this->key_Shoot = false;
if( this->input->IsKeyPressed(DIK_X) )
if( this->mouseInput->IsBtnDown(::Input::Enum::SAMI_MouseRightBtn) )
{
if( !this->key_Shoot )
{
@ -139,7 +140,8 @@ void GamingUI::ReadKeyInput()
}
else
this->key_Shoot = false;
if( this->input->IsKeyPressed(DIK_C) )
if( this->mouseInput->IsBtnDown(::Input::Enum::SAMI_MouseMiddleBtn) )
{
if( !this->key_Shoot )
{
@ -154,23 +156,22 @@ void GamingUI::ReadKeyInput()
else
this->key_Shoot = false;
// jump
if( this->input->IsKeyPressed(DIK_SPACE) )
//send delta mouse movement
{
if(!this->key_Jump)
static const float mouseSensitivity = Radian( 1.0f );
::Input::Struct::SAIPoint2D deltaPos;
this->mouseInput->GetDeltaPosition( deltaPos );
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_PlayerJump() );
this->key_Jump = true;
this->netClient->Send( Protocol_PlayerLeftTurn(deltaPos.x * mouseSensitivity) );
}
}
else
this->key_Jump = false;
if( this->input->IsKeyPressed(DIK_ESCAPE) )
if( this->keyboardInput->IsKeyDown(::Input::Enum::SAKI_Escape) )
{
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 InitInput( HINSTANCE *handle );
static HRESULT InitInput( HWND handle );
static Result Update(float deltaTime);
static HRESULT Render();