diff --git a/Code/Game/GameClient/DanBiasGame_Impl.cpp b/Code/Game/GameClient/DanBiasGame_Impl.cpp index f2ea8251..1dd6e8c6 100644 --- a/Code/Game/GameClient/DanBiasGame_Impl.cpp +++ b/Code/Game/GameClient/DanBiasGame_Impl.cpp @@ -14,13 +14,13 @@ #include #include "../WindowManager/WindowShell.h" -#include "Win32\Win32Input.h" #include "WinTimer.h" #include "vld.h" #include "EventHandler/EventHandler.h" -#include "GameClientState\SharedStateContent.h" +#include "GameClientState/SharedStateContent.h" +#include "Win32/Win32ApplicationKeyboard.h" using namespace ::Oyster; using namespace ::Oyster::Event; @@ -38,13 +38,13 @@ namespace DanBias { public: WindowShell* window; - InputClass inputObj; Utility::WinTimer timer; UniquePointer state; - SharedStateContent sharedStateContent; NetworkClient networkClient; + SharedStateContent sharedStateContent; + ::Input::Win32ApplicationKeyboard *keyboardDevice_application; bool serverOwner; float capFrame; @@ -61,7 +61,7 @@ namespace DanBias //-------------------------------------------------------------------------------------- // Interface API functions //-------------------------------------------------------------------------------------- - DanBiasClientReturn DanBiasGame::Initiate(DanBiasGameDesc& desc) + DanBiasClientReturn DanBiasGame::Initiate( DanBiasGameDesc& desc ) { WindowShell::CreateConsoleWindow(); //if(! data.window->CreateWin(WindowShell::WINDOW_INIT_DESC(L"Window", cPOINT(1600, 900), cPOINT()))) @@ -77,7 +77,7 @@ namespace DanBias if( FAILED( InitDirect3D() ) ) return DanBiasClientReturn_Error; - if( FAILED( InitInput() ) ) + if( FAILED( InitInput(&desc.hinst) ) ) return DanBiasClientReturn_Error; data.serverOwner = false; @@ -85,7 +85,6 @@ 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(); @@ -155,35 +154,50 @@ namespace DanBias //-------------------------------------------------------------------------------------- // Init the input //------------------------------------------------------------------------------------- - HRESULT DanBiasGame::InitInput() + HRESULT DanBiasGame::InitInput( HINSTANCE *handle ) { - if(!data.inputObj.Initialize(data.window->GetHINSTANCE(), data.window->GetHWND(), data.window->GetHeight(), data.window->GetWidth())) + data.sharedStateContent.mouseDevice = (Input::Mouse*)::Input::InputManager::Instance()->CreateDevice( Input::Enum::SAIType_Mouse, handle ); + if( !data.sharedStateContent.mouseDevice ) { - MessageBox(0, L"Could not initialize the input object.", L"Error", MB_OK); + data.sharedStateContent.mouseDevice = nullptr; + + MessageBox( 0, L"Could not initialize the mouseDevice.", L"Error", MB_OK ); return E_FAIL; } + + data.sharedStateContent.keyboardDevice_raw = (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; } DanBiasGame::Result DanBiasGame::Update(float deltaTime) { - { // updating mouse input - // TODO: Is obosolete when Dennis's input system is wired in - POINT mousePos; - GetCursorPos( &mousePos ); - - RECT windowVertex; - GetWindowRect( data.window->GetHWND(), &windowVertex ); - - float mouseNormalisedX = (float)(mousePos.x - windowVertex.left); - mouseNormalisedX /= (float)(windowVertex.right - windowVertex.left); - - float mouseNormalisedY = (float)(mousePos.y - windowVertex.top); - mouseNormalisedY /= (float)(windowVertex.bottom - windowVertex.top); - - data.inputObj.Update( mouseNormalisedX, mouseNormalisedY ); - } - if( data.serverOwner ) { DanBias::GameServerAPI::ServerUpdate(); @@ -253,6 +267,11 @@ 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; + EventHandler::Instance().Clean(); Graphics::API::Clean(); diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 532bd29d..656dde7f 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -24,7 +24,9 @@ struct GameState::MyData MyData(){} GameClientState::ClientState nextState; NetworkClient *nwClient; - InputClass *input; + ::Input::Mouse *mouseInput; + ::Input::Keyboard *keyboardInput_raw; + ::Input::ApplicationKeyboard *keyboardInput_app; ::std::map> *staticObjects; ::std::map> *dynamicObjects; @@ -80,11 +82,15 @@ bool GameState::Init( SharedStateContent &shared ) this->privData->nextState = GameClientState::ClientState_Same; this->privData->nwClient = shared.network; - this->privData->input = shared.input; + this->privData->mouseInput = shared.mouseDevice; + this->privData->keyboardInput_raw = shared.keyboardDevice_raw; + this->privData->keyboardInput_app = shared.keyboardDevice_application; this->privData->staticObjects = &shared.staticObjects; this->privData->dynamicObjects = &shared.dynamicObjects; this->privData->lights = &shared.lights; + this->privData->keyboardInput_app->Deactivate(); + Graphics::API::Option gfxOp = Graphics::API::GetOption(); Float aspectRatio = gfxOp.Resolution.x / gfxOp.Resolution.y; this->privData->camera.SetPerspectiveProjection( Utility::Value::Radian(90.0f), aspectRatio, 0.1f, 1000.0f ); @@ -285,29 +291,19 @@ void GameState::ChangeState( ClientState next ) void GameState::ReadKeyInput() { - if( this->privData->input->IsKeyPressed(DIK_W) ) + if( this->privData->keyboardInput_raw->IsKeyDown(::Input::Enum::SAKI_W) ) { - //if(!this->privData->key_forward) - { - this->privData->nwClient->Send( Protocol_PlayerMovementForward() ); - this->privData->key_forward = true; - } + this->privData->nwClient->Send( Protocol_PlayerMovementForward() ); + this->privData->key_forward = true; } - else - this->privData->key_forward = false; - if( this->privData->input->IsKeyPressed(DIK_S) ) + if( this->privData->keyboardInput_raw->IsKeyDown(::Input::Enum::SAKI_S) ) { - //if( !this->privData->key_backward ) - { - this->privData->nwClient->Send( Protocol_PlayerMovementBackward() ); - this->privData->key_backward = true; - } + this->privData->nwClient->Send( Protocol_PlayerMovementBackward() ); + this->privData->key_backward = true; } - else - this->privData->key_backward = false; - if( this->privData->input->IsKeyPressed(DIK_A) ) + if( this->privData->mouseInput->IsKeyPressed(DIK_A) ) { //if( !this->privData->key_strafeLeft ) { @@ -318,7 +314,7 @@ void GameState::ReadKeyInput() else this->privData->key_strafeLeft = false; - if( this->privData->input->IsKeyPressed(DIK_D) ) + if( this->privData->mouseInput->IsKeyPressed(DIK_D) ) { //if( !this->privData->key_strafeRight ) { @@ -332,8 +328,8 @@ void GameState::ReadKeyInput() //send delta mouse movement { static const float mouseSensitivity = Radian( 1.0f ); - this->privData->camera.PitchDown( this->privData->input->GetPitch() * mouseSensitivity ); - float yaw = this->privData->input->GetYaw(); + this->privData->camera.PitchDown( this->privData->mouseInput->GetPitch() * mouseSensitivity ); + float yaw = this->privData->mouseInput->GetYaw(); //if( yaw != 0.0f ) //This made the camera reset to a specific rotation. { this->privData->nwClient->Send( Protocol_PlayerLeftTurn(yaw * mouseSensitivity) ); @@ -341,7 +337,7 @@ void GameState::ReadKeyInput() } // shoot - if( this->privData->input->IsKeyPressed(DIK_Z) ) + if( this->privData->mouseInput->IsKeyPressed(DIK_Z) ) { if( !this->privData->key_Shoot ) { @@ -355,7 +351,7 @@ void GameState::ReadKeyInput() } else this->privData->key_Shoot = false; - if( this->privData->input->IsKeyPressed(DIK_X) ) + if( this->privData->mouseInput->IsKeyPressed(DIK_X) ) { if( !this->privData->key_Shoot ) { @@ -369,7 +365,7 @@ void GameState::ReadKeyInput() } else this->privData->key_Shoot = false; - if( this->privData->input->IsKeyPressed(DIK_C) ) + if( this->privData->mouseInput->IsKeyPressed(DIK_C) ) { if( !this->privData->key_Shoot ) { @@ -385,7 +381,7 @@ void GameState::ReadKeyInput() this->privData->key_Shoot = false; // jump - if( this->privData->input->IsKeyPressed(DIK_SPACE) ) + if( this->privData->mouseInput->IsKeyPressed(DIK_SPACE) ) { if(!this->privData->key_Jump) { @@ -400,7 +396,7 @@ void GameState::ReadKeyInput() // DEGUG KEYS // Reload shaders - if( this->privData->input->IsKeyPressed(DIK_R) ) + if( this->privData->mouseInput->IsKeyPressed(DIK_R) ) { if( !this->privData->key_Reload_Shaders ) { @@ -414,7 +410,7 @@ void GameState::ReadKeyInput() this->privData->key_Reload_Shaders = false; // toggle wire frame render - if( this->privData->input->IsKeyPressed(DIK_T) ) + if( this->privData->mouseInput->IsKeyPressed(DIK_T) ) { if( !this->privData->key_Wireframe_Toggle ) { diff --git a/Code/Game/GameClient/GameClientState/LanMenuState.cpp b/Code/Game/GameClient/GameClientState/LanMenuState.cpp index 8c096617..dd49dd23 100644 --- a/Code/Game/GameClient/GameClientState/LanMenuState.cpp +++ b/Code/Game/GameClient/GameClientState/LanMenuState.cpp @@ -28,7 +28,8 @@ struct LanMenuState::MyData GameClientState::ClientState nextState; NetworkClient *nwClient; - InputClass *input; + ::Input::Mouse *mouseInput; + ::Input::ApplicationKeyboard *keyboardInput; Graphics::API::Texture background; EventButtonCollection guiElements; @@ -53,7 +54,9 @@ bool LanMenuState::Init( SharedStateContent &shared ) this->privData->nextState = GameClientState::ClientState_Same; this->privData->nwClient = shared.network; - this->privData->input = shared.input; + this->privData->mouseInput = shared.mouseDevice; + this->privData->keyboardInput = shared.keyboardDevice_application; + this->privData->keyboardInput->Activate(); this->privData->background = Graphics::API::CreateTexture( L"color_white.png" ); @@ -80,6 +83,9 @@ bool LanMenuState::Init( SharedStateContent &shared ) this->privData->connectPort = 15151; + this->privData->keyboardInput->BindTextTarget( &(*this->privData->connectIP)[0] ); + this->privData->keyboardInput->Activate(); + return true; } @@ -87,10 +93,13 @@ GameClientState::ClientState LanMenuState::Update( float deltaTime ) { MouseInput mouseState; { - this->privData->input->GetMousePos( mouseState.x, mouseState.y ); - mouseState.mouseButtonPressed = this->privData->input->IsMousePressed(); - } + ::Input::Struct::SAIPoint2D pos; + this->privData->mouseInput->GetPixelPosition( pos ); + mouseState.x = pos.x; + mouseState.y = pos.y; + mouseState.mouseButtonPressed = this->privData->mouseInput->IsBtnDown( ::Input::Enum::SAMI_MouseLeftBtn ); + } EventHandler::Instance().Update( mouseState ); return this->privData->nextState; diff --git a/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp b/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp index 43419e88..bac7e4cb 100644 --- a/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp +++ b/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp @@ -22,7 +22,7 @@ struct LobbyAdminState::MyData GameClientState::ClientState nextState; NetworkClient *nwClient; - InputClass *input; + ::Input::Mouse *mouseInput; Graphics::API::Texture background; EventButtonCollection guiElements; } privData; @@ -43,7 +43,7 @@ bool LobbyAdminState::Init( SharedStateContent &shared ) this->privData->nextState = GameClientState::ClientState_Same; this->privData->nwClient = shared.network; - this->privData->input = shared.input; + this->privData->mouseInput = shared.mouseDevice; this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" ); @@ -61,21 +61,15 @@ bool LobbyAdminState::Init( SharedStateContent &shared ) GameClientState::ClientState LobbyAdminState::Update( float deltaTime ) { - // Wishlist: - // picking - // mouse events - // different menus - // play sounds - // update animation - // send data to server - // check data from server - MouseInput mouseState; { - this->privData->input->GetMousePos( mouseState.x, mouseState.y ); - mouseState.mouseButtonPressed = this->privData->input->IsMousePressed(); - } + ::Input::Struct::SAIPoint2D pos; + this->privData->mouseInput->GetPixelPosition( pos ); + mouseState.x = pos.x; + mouseState.y = pos.y; + mouseState.mouseButtonPressed = this->privData->mouseInput->IsBtnDown( ::Input::Enum::SAMI_MouseLeftBtn ); + } EventHandler::Instance().Update( mouseState ); return this->privData->nextState; diff --git a/Code/Game/GameClient/GameClientState/LobbyState.cpp b/Code/Game/GameClient/GameClientState/LobbyState.cpp index 0b117016..3db9b341 100644 --- a/Code/Game/GameClient/GameClientState/LobbyState.cpp +++ b/Code/Game/GameClient/GameClientState/LobbyState.cpp @@ -22,7 +22,7 @@ struct LobbyState::MyData GameClientState::ClientState nextState; NetworkClient *nwClient; - InputClass *input; + ::Input::Mouse *mouseInput; Graphics::API::Texture background; EventButtonCollection guiElements; } privData; @@ -43,7 +43,7 @@ bool LobbyState::Init( SharedStateContent &shared ) this->privData->nextState = GameClientState::ClientState_Same; this->privData->nwClient = shared.network; - this->privData->input = shared.input; + this->privData->mouseInput = shared.mouseDevice; this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" ); @@ -61,21 +61,15 @@ bool LobbyState::Init( SharedStateContent &shared ) GameClientState::ClientState LobbyState::Update( float deltaTime ) { - // Wishlist: - // picking - // mouse events - // different menus - // play sounds - // update animation - // send data to server - // check data from server - MouseInput mouseState; { - this->privData->input->GetMousePos( mouseState.x, mouseState.y ); - mouseState.mouseButtonPressed = this->privData->input->IsMousePressed(); - } + ::Input::Struct::SAIPoint2D pos; + this->privData->mouseInput->GetPixelPosition( pos ); + mouseState.x = pos.x; + mouseState.y = pos.y; + mouseState.mouseButtonPressed = this->privData->mouseInput->IsBtnDown( ::Input::Enum::SAMI_MouseLeftBtn ); + } EventHandler::Instance().Update( mouseState ); return this->privData->nextState; diff --git a/Code/Game/GameClient/GameClientState/MainState.cpp b/Code/Game/GameClient/GameClientState/MainState.cpp index 5b96b385..e4c1fe0e 100644 --- a/Code/Game/GameClient/GameClientState/MainState.cpp +++ b/Code/Game/GameClient/GameClientState/MainState.cpp @@ -24,7 +24,7 @@ struct MainState::MyData GameClientState::ClientState nextState; NetworkClient *nwClient; - InputClass *input; + ::Input::Mouse *mouseInput; Graphics::API::Texture background; EventButtonCollection guiElements; }; @@ -47,7 +47,7 @@ bool MainState::Init( SharedStateContent &shared ) this->privData->nextState = GameClientState::ClientState_Same; this->privData->nwClient = shared.network; - this->privData->input = shared.input; + this->privData->mouseInput = shared.mouseDevice; this->privData->background = Graphics::API::CreateTexture( L"color_white.png" ); @@ -77,16 +77,13 @@ GameClientState::ClientState MainState::Update( float deltaTime ) { MouseInput mouseState; { - bool test = this->privData->input->IsMousePressed(); - if(test) - { // HACK: debug trap still in use? - int i = 0; - }; + ::Input::Struct::SAIPoint2D pos; + this->privData->mouseInput->GetPixelPosition( pos ); - this->privData->input->GetMousePos( mouseState.x, mouseState.y ); - mouseState.mouseButtonPressed = this->privData->input->IsMousePressed(); + mouseState.x = pos.x; + mouseState.y = pos.y; + mouseState.mouseButtonPressed = this->privData->mouseInput->IsBtnDown( ::Input::Enum::SAMI_MouseLeftBtn ); } - EventHandler::Instance().Update( mouseState ); return this->privData->nextState; diff --git a/Code/Game/GameClient/GameClientState/SharedStateContent.h b/Code/Game/GameClient/GameClientState/SharedStateContent.h index 49d01775..293213d6 100644 --- a/Code/Game/GameClient/GameClientState/SharedStateContent.h +++ b/Code/Game/GameClient/GameClientState/SharedStateContent.h @@ -15,7 +15,7 @@ #include "C_obj\C_DynamicObj.h" #include "C_Light.h" #include "NetworkClient.h" -#include "L_inputClass.h" +#include "Input.h" namespace DanBias { namespace Client { @@ -26,7 +26,10 @@ namespace DanBias { namespace Client ::std::map> dynamicObjects; ::std::map> lights; ::Oyster::Network::NetworkClient *network; - InputClass* input; + + ::Input::Mouse *mouseDevice; + ::Input::Keyboard *keyboardDevice_raw; + ::Input::ApplicationKeyboard *keyboardDevice_application; }; } } diff --git a/Code/Game/GameClient/Include/DanBiasGame.h b/Code/Game/GameClient/Include/DanBiasGame.h index 74248d47..b0af07c7 100644 --- a/Code/Game/GameClient/Include/DanBiasGame.h +++ b/Code/Game/GameClient/Include/DanBiasGame.h @@ -55,7 +55,7 @@ namespace DanBias }; static HRESULT InitDirect3D(); - static HRESULT InitInput(); + static HRESULT InitInput( HINSTANCE *handle ); static Result Update(float deltaTime); static HRESULT Render(); diff --git a/Code/Misc/Input/Include/ApplicationKeyboard.h b/Code/Misc/Input/Include/ApplicationKeyboard.h index d28140b3..b03e5abb 100644 --- a/Code/Misc/Input/Include/ApplicationKeyboard.h +++ b/Code/Misc/Input/Include/ApplicationKeyboard.h @@ -12,6 +12,8 @@ namespace Input class ApplicationKeyboard : public InputObject { public: + virtual ~ApplicationKeyboard(); + bool IsActive() const; void Activate(); @@ -25,7 +27,6 @@ namespace Input ::std::wstring::size_type writePos; ApplicationKeyboard(); - ~ApplicationKeyboard(); private: bool active; diff --git a/Code/Misc/Input/Include/Input.h b/Code/Misc/Input/Include/Input.h index 3de235ca..bd3c7a33 100644 --- a/Code/Misc/Input/Include/Input.h +++ b/Code/Misc/Input/Include/Input.h @@ -7,6 +7,7 @@ #include "InputManager.h" #include "InputObject.h" #include "Keyboard.h" +#include "ApplicationKeyboard.h" #include "Mouse.h" #endif // !INPUT_INPUT_H diff --git a/Code/Misc/Input/Include/Keyboard.h b/Code/Misc/Input/Include/Keyboard.h index 6f561eba..60ad20fc 100644 --- a/Code/Misc/Input/Include/Keyboard.h +++ b/Code/Misc/Input/Include/Keyboard.h @@ -151,6 +151,8 @@ namespace Input }; public: /* Manual check functions */ + virtual ~Keyboard(); + virtual bool IsKeyUp (Enum::SAKI key) = 0; virtual bool IsKeyDown (Enum::SAKI key) = 0; virtual const wchar_t* GetAsText(Enum::SAKI key) = 0; @@ -170,7 +172,6 @@ namespace Input protected: Keyboard(); - ~Keyboard(); protected: struct KeyboardCallbackList diff --git a/Code/Misc/Input/Include/Mouse.h b/Code/Misc/Input/Include/Mouse.h index b657604b..82643df7 100644 --- a/Code/Misc/Input/Include/Mouse.h +++ b/Code/Misc/Input/Include/Mouse.h @@ -66,6 +66,8 @@ namespace Input }; public: + virtual ~Mouse(); + virtual bool IsBtnUp(Enum::SAMI key) = 0; virtual bool IsBtnDown(Enum::SAMI key) = 0; virtual int GetWheelDelta() = 0; @@ -93,7 +95,6 @@ namespace Input protected: Mouse(); - ~Mouse(); protected: struct MouseCallbackList