From 53dc42ffc4f445dcab03417e1272e81fd8d0f7a1 Mon Sep 17 00:00:00 2001 From: dean11 Date: Thu, 20 Feb 2014 11:27:43 +0100 Subject: [PATCH 01/32] Input - Added normalized cordinates --- Code/Game/GameClient/GameClient.vcxproj.user | 2 +- Code/Misc/Input/Include/Common.h | 14 ++++-- Code/Misc/Input/Include/Mouse.h | 16 +++--- Code/Misc/Input/Include/Win32/Win32Mouse.h | 8 ++- Code/Misc/Input/Source/Mouse.cpp | 3 ++ Code/Misc/Input/Source/Win32/Win32Input.cpp | 21 +++----- Code/Misc/Input/Source/Win32/Win32Mouse.cpp | 51 ++++++++++++++++++-- 7 files changed, 85 insertions(+), 30 deletions(-) diff --git a/Code/Game/GameClient/GameClient.vcxproj.user b/Code/Game/GameClient/GameClient.vcxproj.user index 4b847ee6..2e28d6f7 100644 --- a/Code/Game/GameClient/GameClient.vcxproj.user +++ b/Code/Game/GameClient/GameClient.vcxproj.user @@ -1,7 +1,7 @@  - false + true $(OutDir) diff --git a/Code/Misc/Input/Include/Common.h b/Code/Misc/Input/Include/Common.h index 18999b41..9bb9f2cf 100644 --- a/Code/Misc/Input/Include/Common.h +++ b/Code/Misc/Input/Include/Common.h @@ -36,14 +36,22 @@ namespace Input /*********************************************************************/ namespace Struct { - struct SAIPoint2D + struct SAIPointInt2D { int x; int y; - SAIPoint2D() :x(0), y(0) { } - SAIPoint2D(int _x, int _y) :x(_x), y(_y) { } + SAIPointInt2D() :x(0), y(0) { } + SAIPointInt2D(int _x, int _y) :x(_x), y(_y) { } int Length() { return (abs(x) + abs(y)); } }; + struct SAIPointFloat2D + { + float x; + float y; + SAIPointFloat2D() :x(0.0f), y(0.0f) { } + SAIPointFloat2D(float _x, float _y) :x(_x), y(_y) { } + float Length() { return (fabs(x) + fabs(y)); } + }; struct InputData; } diff --git a/Code/Misc/Input/Include/Mouse.h b/Code/Misc/Input/Include/Mouse.h index b657604b..6c58ec97 100644 --- a/Code/Misc/Input/Include/Mouse.h +++ b/Code/Misc/Input/Include/Mouse.h @@ -47,7 +47,7 @@ namespace Input typedef void(*OnMousePressCallback)(Enum::SAMI btn, Mouse* sender); typedef void(*OnMouseDownCallback)(Enum::SAMI btn, Mouse* sender); typedef void(*OnMouseReleaseCallback)(Enum::SAMI btn, Mouse* sender); - typedef void(*OnMouseMoveCallback)(Struct::SAIPoint2D, Mouse* sender); + typedef void(*OnMouseMoveCallback)(Struct::SAIPointInt2D, Mouse* sender); typedef void(*OnMouseScrollCallback)(int delta, Mouse* sender); } //----------------------------------------------------------------------------------------------------------------------------- @@ -61,15 +61,16 @@ namespace Input virtual void OnMousePress ( Enum::SAMI key, Mouse* sender ) { } virtual void OnMouseDown ( Enum::SAMI key, Mouse* sender ) { } virtual void OnMouseRelease ( Enum::SAMI key, Mouse* sender ) { } - virtual void OnMouseMove ( Struct::SAIPoint2D coordinate, Mouse* sender ) { } + virtual void OnMouseMove ( Struct::SAIPointInt2D coordinate, Mouse* sender ) { } virtual void OnMouseScroll ( int delta, Mouse* sender ) { } }; public: - virtual bool IsBtnUp(Enum::SAMI key) = 0; - virtual bool IsBtnDown(Enum::SAMI key) = 0; - virtual int GetWheelDelta() = 0; - virtual Struct::SAIPoint2D GetPixelPosition(Struct::SAIPoint2D targetMem = Struct::SAIPoint2D()) = 0; + virtual bool IsBtnUp(Enum::SAMI key) = 0; + virtual bool IsBtnDown(Enum::SAMI key) = 0; + virtual int GetWheelDelta() = 0; + virtual Struct::SAIPointInt2D GetPixelPosition(Struct::SAIPointInt2D targetMem = Struct::SAIPointInt2D()) = 0; + virtual Struct::SAIPointFloat2D GetNormalizedPosition(Struct::SAIPointFloat2D targetMem = Struct::SAIPointFloat2D()) = 0; public: void AddOnMousePressCallback( Typedefs::OnMousePressCallback func); @@ -135,7 +136,8 @@ namespace Input protected: std::vector mouseSubscribers; MouseCallbackList* callbackList; - Struct::SAIPoint2D pixelPos; + Struct::SAIPointInt2D pixelPos; + Struct::SAIPointFloat2D normalPos; bool isCurorLocked; int wheelDelta; }; diff --git a/Code/Misc/Input/Include/Win32/Win32Mouse.h b/Code/Misc/Input/Include/Win32/Win32Mouse.h index 10c04a28..278a76a4 100644 --- a/Code/Misc/Input/Include/Win32/Win32Mouse.h +++ b/Code/Misc/Input/Include/Win32/Win32Mouse.h @@ -18,9 +18,12 @@ namespace Input bool IsBtnUp(Enum::SAMI key) override; bool IsBtnDown(Enum::SAMI key) override; int GetWheelDelta() override; - Struct::SAIPoint2D GetPixelPosition(Struct::SAIPoint2D targetMem = Struct::SAIPoint2D()) override; + Struct::SAIPointInt2D GetPixelPosition(Struct::SAIPointInt2D targetMem = Struct::SAIPointInt2D()) override; + Struct::SAIPointFloat2D GetNormalizedPosition(Struct::SAIPointFloat2D targetMem = Struct::SAIPointFloat2D()) override; - void ProccessMouseData (bool isDown, Enum::SAMI btn, int delta, Struct::SAIPoint2D velocity, unsigned int makeCode); + void ProccessMouseData (bool isDown, Enum::SAMI btn, int delta, Struct::SAIPointInt2D velocity, unsigned int makeCode); + + bool Create(HWND target); private: struct Buttons @@ -30,6 +33,7 @@ namespace Input }; static const int MAXBUTTONS = 25; Buttons buttons[25]; + RAWINPUTDEVICE device; }; } diff --git a/Code/Misc/Input/Source/Mouse.cpp b/Code/Misc/Input/Source/Mouse.cpp index 36bd8330..de1cf26f 100644 --- a/Code/Misc/Input/Source/Mouse.cpp +++ b/Code/Misc/Input/Source/Mouse.cpp @@ -81,6 +81,7 @@ Mouse::Mouse() , wheelDelta(0) , isCurorLocked(0) , pixelPos() + , normalPos() { } Mouse::~Mouse() @@ -149,6 +150,8 @@ void Mouse::SetPixelPos(int x, int y) { this->pixelPos.x = x; this->pixelPos.y = y; + + // TODO: Update normalized position } void Mouse::ToggleCursor(bool toggler) { diff --git a/Code/Misc/Input/Source/Win32/Win32Input.cpp b/Code/Misc/Input/Source/Win32/Win32Input.cpp index c6be3c9d..edf85729 100644 --- a/Code/Misc/Input/Source/Win32/Win32Input.cpp +++ b/Code/Misc/Input/Source/Win32/Win32Input.cpp @@ -556,7 +556,7 @@ void MapKey(RAWKEYBOARD& rawKB, bool& out_isUp, SAKI& out_key, unsigned int& sCo rawKB.MakeCode = scanCode; sCode = scanCode; } -void MapButton(RAWMOUSE& rawMouse, bool &isUp, Enum::SAMI& btn, int& delta, Struct::SAIPoint2D& vel, unsigned int& mcode) +void MapButton(RAWMOUSE& rawMouse, bool &isUp, Enum::SAMI& btn, int& delta, Struct::SAIPointInt2D& vel, unsigned int& mcode) { if(rawMouse.lLastX != 0 || rawMouse.lLastY != 0) { @@ -647,7 +647,7 @@ void Win32Input::RawInputParser(HWND h, LPARAM l) bool isUp = true; Enum::SAMI btn = Enum::SAMI_Unknown; int delta = 0; - Struct::SAIPoint2D vel; + Struct::SAIPointInt2D vel; unsigned int mcode = 0; MapButton(raw->data.mouse, isUp, btn, delta, vel, mcode); @@ -759,20 +759,15 @@ InputObject* Win32Input::CreateDevice(const SAIType inputType, Typedefs::WindowH case SAIType_Mouse: { - rid.usUsage = RawInput_Usage_mouse; - rid.dwFlags = RIDEV_NOLEGACY | RIDEV_CAPTUREMOUSE; - if(RegisterRawInputDevices(&rid, 1, sizeof(RAWINPUTDEVICE)) == TRUE) - { - int i = 0; - val = (InputObject*)1; - Win32Mouse* obj = new Win32Mouse(); - this->mouse.push_back(obj); - val = obj; - } - else + Win32Mouse* obj = new Win32Mouse(); + if(!obj->Create(this->targetHwin)) { + delete obj; return 0; } + + this->mouse.push_back(obj); + val = obj; } break; } diff --git a/Code/Misc/Input/Source/Win32/Win32Mouse.cpp b/Code/Misc/Input/Source/Win32/Win32Mouse.cpp index ef6d9edf..50d55a91 100644 --- a/Code/Misc/Input/Source/Win32/Win32Mouse.cpp +++ b/Code/Misc/Input/Source/Win32/Win32Mouse.cpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////// // Created by [Dennis Andersen] [2013] ///////////////////////////////////////////////////////////////////// -#include "..\..\Include\Win32\Win32Mouse.h" +#include "..\..\Include\Win32\Win32Input.h" using namespace Input; using namespace Input::Enum; @@ -11,6 +11,7 @@ using namespace Input::Typedefs; Win32Mouse::Win32Mouse() { + memset(&this->device, 0, sizeof(RAWINPUTDEVICE)); memset(&this->buttons[0], 0, sizeof(Buttons) * MAXBUTTONS); } Win32Mouse::~Win32Mouse() @@ -34,13 +35,29 @@ int Win32Mouse::GetWheelDelta() { return this->wheelDelta; } -Struct::SAIPoint2D Win32Mouse::GetPixelPosition(Struct::SAIPoint2D targetMem) +Struct::SAIPointInt2D Win32Mouse::GetPixelPosition(Struct::SAIPointInt2D targetMem) { targetMem = this->pixelPos; return targetMem; } +Struct::SAIPointFloat2D Win32Mouse::GetNormalizedPosition(Struct::SAIPointFloat2D targetMem) +{ + POINT mousePos; + GetCursorPos( &mousePos ); + + RECT windowVertex; + GetWindowRect( this->device.hwndTarget, &windowVertex ); + + this->normalPos.x = (float)(mousePos.x - windowVertex.left); + this->normalPos.x /= (float)(windowVertex.right - windowVertex.left); + + this->normalPos.y = (float)(mousePos.y - windowVertex.top); + this->normalPos.y /= (float)(windowVertex.bottom - windowVertex.top); -void Win32Mouse::ProccessMouseData (bool isUp, Enum::SAMI btn, int delta, Struct::SAIPoint2D velocity, unsigned int makeCode) + return targetMem; +} + +void Win32Mouse::ProccessMouseData (bool isUp, Enum::SAMI btn, int delta, Struct::SAIPointInt2D velocity, unsigned int makeCode) { if(velocity.Length() != 0) { @@ -138,4 +155,30 @@ void Win32Mouse::ProccessMouseData (bool isUp, Enum::SAMI btn, int delta, Struct } } } -} \ No newline at end of file + + +} + +bool Win32Mouse::Create(HWND target) +{ + this->device.usUsagePage = 0x01; + this->device.hwndTarget = target; + this->device.usUsage = Input::RawInput_Usage_mouse; + this->device.dwFlags = RIDEV_NOLEGACY | RIDEV_CAPTUREMOUSE; + + if(RegisterRawInputDevices(&this->device, 1, sizeof(RAWINPUTDEVICE)) == TRUE) + { + return true; + } + + memset(&this->device, 0, sizeof(RAWINPUTDEVICE)); + + return false; +} + + + + + + + From 2c8b52e0fa739d25dca1fd1d37e8161f0f15ec75 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Thu, 20 Feb 2014 13:27:21 +0100 Subject: [PATCH 02/32] some implementations --- Code/Misc/Input/Include/ApplicationKeyboard.h | 19 ++++++++--- Code/Misc/Input/Include/Common.h | 1 + .../Include/Win32/Win32ApplicationKeyboard.h | 6 ++-- Code/Misc/Input/Input.vcxproj | 4 +++ .../Misc/Input/Source/ApplicationKeyboard.cpp | 33 +++++++++++++++++++ .../Source/Win32/Win32ApplicationKeyboard.cpp | 20 +++++++++++ 6 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 Code/Misc/Input/Source/ApplicationKeyboard.cpp create mode 100644 Code/Misc/Input/Source/Win32/Win32ApplicationKeyboard.cpp diff --git a/Code/Misc/Input/Include/ApplicationKeyboard.h b/Code/Misc/Input/Include/ApplicationKeyboard.h index 3e506e22..a6a41b6a 100644 --- a/Code/Misc/Input/Include/ApplicationKeyboard.h +++ b/Code/Misc/Input/Include/ApplicationKeyboard.h @@ -5,17 +5,28 @@ #define INPUT_APPLICATION_KEBOARD_H #include "InputObject.h" -#include +#include namespace Input { - class AplicationKeyboard : public InputObject + class ApplicationKeyboard : public InputObject { public: + bool IsActive() const; + + void Activate(); + void Deactivate(); + + void SetTargetText( ::std::wstring *field ); protected: - AplicationKeyboard(); - ~AplicationKeyboard(); + ::std::wstring *targetText; + + ApplicationKeyboard(); + ~ApplicationKeyboard(); + + private: + bool active; }; } diff --git a/Code/Misc/Input/Include/Common.h b/Code/Misc/Input/Include/Common.h index 18999b41..a82ad47b 100644 --- a/Code/Misc/Input/Include/Common.h +++ b/Code/Misc/Input/Include/Common.h @@ -21,6 +21,7 @@ namespace Input { SAIType_Keyboard, SAIType_Mouse, + SAIType_ApplicationKeyboard, SAIType_futureExample1, SAIType_futureExample2, SAIType_futureExample3, diff --git a/Code/Misc/Input/Include/Win32/Win32ApplicationKeyboard.h b/Code/Misc/Input/Include/Win32/Win32ApplicationKeyboard.h index f19f5940..c1896a45 100644 --- a/Code/Misc/Input/Include/Win32/Win32ApplicationKeyboard.h +++ b/Code/Misc/Input/Include/Win32/Win32ApplicationKeyboard.h @@ -4,17 +4,19 @@ #ifndef INPUT_WIN32_APPLICATION_KEBOARD_H #define INPUT_WIN32_APPLICATION_KEBOARD_H +#define NOMINMAX +#include #include "..\ApplicationKeyboard.h" -//#include namespace Input { - class Win32ApplicationKeyboard :public AplicationKeyboard + class Win32ApplicationKeyboard : public ApplicationKeyboard { public: Win32ApplicationKeyboard(); ~Win32ApplicationKeyboard(); + LRESULT CALLBACK WindowCallback( HWND h, UINT m, WPARAM w, LPARAM l ); private: diff --git a/Code/Misc/Input/Input.vcxproj b/Code/Misc/Input/Input.vcxproj index 8642e69e..2ecf7bfa 100644 --- a/Code/Misc/Input/Input.vcxproj +++ b/Code/Misc/Input/Input.vcxproj @@ -20,14 +20,17 @@ + + + @@ -35,6 +38,7 @@ + diff --git a/Code/Misc/Input/Source/ApplicationKeyboard.cpp b/Code/Misc/Input/Source/ApplicationKeyboard.cpp new file mode 100644 index 00000000..287785db --- /dev/null +++ b/Code/Misc/Input/Source/ApplicationKeyboard.cpp @@ -0,0 +1,33 @@ +#include "../Include/ApplicationKeyboard.h" + +using namespace ::Input; + +ApplicationKeyboard::ApplicationKeyboard() : + InputObject( Enum::SAIType_ApplicationKeyboard ) +{ + this->targetText = nullptr; + this->isEnabled = true; +} + +ApplicationKeyboard::~ApplicationKeyboard() +{ /* DO nothing */ } + +bool ApplicationKeyboard::IsActive() const +{ + return this->isEnabled; +} + +void ApplicationKeyboard::Activate() +{ + this->isEnabled = true; +} + +void ApplicationKeyboard::Deactivate() +{ + this->isEnabled = false; +} + +void ApplicationKeyboard::SetTargetText( ::std::wstring *field ) +{ + this->targetText = field; +} \ No newline at end of file diff --git a/Code/Misc/Input/Source/Win32/Win32ApplicationKeyboard.cpp b/Code/Misc/Input/Source/Win32/Win32ApplicationKeyboard.cpp new file mode 100644 index 00000000..30b585c9 --- /dev/null +++ b/Code/Misc/Input/Source/Win32/Win32ApplicationKeyboard.cpp @@ -0,0 +1,20 @@ +#include "../../Include/Win32/Win32ApplicationKeyboard.h" + +using namespace ::Input; + + +//{ +// class Win32ApplicationKeyboard : public ApplicationKeyboard +// { +// public: +// Win32ApplicationKeyboard(); +// ~Win32ApplicationKeyboard(); +// +// LRESULT CALLBACK WindowCallback( HWND h, UINT m, WPARAM w, LPARAM l ); +// +// private: +// +// }; +//} +// +//#endif // !INPUT_WIN32_APPLICATION_KEBOARD_H From 899324140843da18ad961a2df0bb13a40a139658 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Thu, 20 Feb 2014 14:39:12 +0100 Subject: [PATCH 03/32] Win32ApplicationKeyboard fully implemented ApplicationKeyboard, Win32ApplicationKeyboard & implemented into the CreateDevice function --- Code/Misc/Input/Include/ApplicationKeyboard.h | 6 +- .../Include/Win32/Win32ApplicationKeyboard.h | 5 +- Code/Misc/Input/Include/Win32/Win32Input.h | 1 + Code/Misc/Input/Input.vcxproj | 17 ++++-- .../Misc/Input/Source/ApplicationKeyboard.cpp | 17 +++++- .../Source/Win32/Win32ApplicationKeyboard.cpp | 61 ++++++++++++++----- Code/Misc/Input/Source/Win32/Win32Input.cpp | 4 ++ 7 files changed, 83 insertions(+), 28 deletions(-) diff --git a/Code/Misc/Input/Include/ApplicationKeyboard.h b/Code/Misc/Input/Include/ApplicationKeyboard.h index a6a41b6a..d28140b3 100644 --- a/Code/Misc/Input/Include/ApplicationKeyboard.h +++ b/Code/Misc/Input/Include/ApplicationKeyboard.h @@ -17,10 +17,12 @@ namespace Input void Activate(); void Deactivate(); - void SetTargetText( ::std::wstring *field ); + void BindTextTarget( ::std::wstring *field ); + void ReleaseTextTarget(); protected: - ::std::wstring *targetText; + ::std::wstring *textTarget; + ::std::wstring::size_type writePos; ApplicationKeyboard(); ~ApplicationKeyboard(); diff --git a/Code/Misc/Input/Include/Win32/Win32ApplicationKeyboard.h b/Code/Misc/Input/Include/Win32/Win32ApplicationKeyboard.h index c1896a45..98bcc0e9 100644 --- a/Code/Misc/Input/Include/Win32/Win32ApplicationKeyboard.h +++ b/Code/Misc/Input/Include/Win32/Win32ApplicationKeyboard.h @@ -16,10 +16,7 @@ namespace Input Win32ApplicationKeyboard(); ~Win32ApplicationKeyboard(); - LRESULT CALLBACK WindowCallback( HWND h, UINT m, WPARAM w, LPARAM l ); - - private: - + void CaptureText( UINT msg, WPARAM param ); }; } diff --git a/Code/Misc/Input/Include/Win32/Win32Input.h b/Code/Misc/Input/Include/Win32/Win32Input.h index c420e3a7..b7a41ce0 100644 --- a/Code/Misc/Input/Include/Win32/Win32Input.h +++ b/Code/Misc/Input/Include/Win32/Win32Input.h @@ -8,6 +8,7 @@ #include "..\InputManager.h" #include "Win32Keyboard.h" #include "Win32Mouse.h" +#include "Win32ApplicationKeyboard.h" #include #include #include diff --git a/Code/Misc/Input/Input.vcxproj b/Code/Misc/Input/Input.vcxproj index 2ecf7bfa..d930acdb 100644 --- a/Code/Misc/Input/Input.vcxproj +++ b/Code/Misc/Input/Input.vcxproj @@ -44,6 +44,11 @@ + + + {2ec4dded-8f75-4c86-a10b-e1e8eb29f3ee} + + {7E3990D2-3D94-465C-B58D-64A74B3ECF9B} Input @@ -95,28 +100,32 @@ $(SolutionDir)..\External\Lib\$(ProjectName)\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName)D + $(IncludePath) $(SolutionDir)..\External\Lib\$(ProjectName)\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName) + $(IncludePath) $(SolutionDir)..\External\Lib\$(ProjectName)\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName)D + $(IncludePath) $(SolutionDir)..\External\Lib\$(ProjectName)\ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName) + $(IncludePath) Level3 Disabled true - %(AdditionalIncludeDirectories) + $(SolutionDir)Misc\Utilities;%(AdditionalIncludeDirectories) true @@ -127,7 +136,7 @@ Level3 Disabled true - %(AdditionalIncludeDirectories) + $(SolutionDir)Misc\Utilities;%(AdditionalIncludeDirectories) true @@ -140,7 +149,7 @@ true true true - %(AdditionalIncludeDirectories) + $(SolutionDir)Misc\Utilities;%(AdditionalIncludeDirectories) true @@ -155,7 +164,7 @@ true true true - %(AdditionalIncludeDirectories) + $(SolutionDir)Misc\Utilities;%(AdditionalIncludeDirectories) true diff --git a/Code/Misc/Input/Source/ApplicationKeyboard.cpp b/Code/Misc/Input/Source/ApplicationKeyboard.cpp index 287785db..66ddb042 100644 --- a/Code/Misc/Input/Source/ApplicationKeyboard.cpp +++ b/Code/Misc/Input/Source/ApplicationKeyboard.cpp @@ -5,7 +5,8 @@ using namespace ::Input; ApplicationKeyboard::ApplicationKeyboard() : InputObject( Enum::SAIType_ApplicationKeyboard ) { - this->targetText = nullptr; + this->textTarget = nullptr; + this->writePos = 0; this->isEnabled = true; } @@ -27,7 +28,17 @@ void ApplicationKeyboard::Deactivate() this->isEnabled = false; } -void ApplicationKeyboard::SetTargetText( ::std::wstring *field ) +void ApplicationKeyboard::BindTextTarget( ::std::wstring *field ) { - this->targetText = field; + this->textTarget = field; + + if( field ) + { + this->writePos = field->size(); + } +} + +void ApplicationKeyboard::ReleaseTextTarget( ) +{ + this->BindTextTarget( nullptr ); } \ No newline at end of file diff --git a/Code/Misc/Input/Source/Win32/Win32ApplicationKeyboard.cpp b/Code/Misc/Input/Source/Win32/Win32ApplicationKeyboard.cpp index 30b585c9..3b58a032 100644 --- a/Code/Misc/Input/Source/Win32/Win32ApplicationKeyboard.cpp +++ b/Code/Misc/Input/Source/Win32/Win32ApplicationKeyboard.cpp @@ -1,20 +1,51 @@ #include "../../Include/Win32/Win32ApplicationKeyboard.h" +#include "Utilities.h" using namespace ::Input; +using namespace ::Utility::Value; +using ::std::wstring; +Win32ApplicationKeyboard::Win32ApplicationKeyboard() : ApplicationKeyboard() { /* DO nothing */ } -//{ -// class Win32ApplicationKeyboard : public ApplicationKeyboard -// { -// public: -// Win32ApplicationKeyboard(); -// ~Win32ApplicationKeyboard(); -// -// LRESULT CALLBACK WindowCallback( HWND h, UINT m, WPARAM w, LPARAM l ); -// -// private: -// -// }; -//} -// -//#endif // !INPUT_WIN32_APPLICATION_KEBOARD_H +Win32ApplicationKeyboard::~Win32ApplicationKeyboard() { /* DO nothing */ } + +void Win32ApplicationKeyboard::CaptureText( UINT msg, WPARAM param ) +{ + if( !this->textTarget | !this->isEnabled ) + return; + + switch( msg ) + { + case WM_CHAR: + this->textTarget->insert( this->writePos, 1, (wchar_t)param ); + ++this->writePos; + break; + case WM_KEYDOWN: + { + switch( param ) + { + case VK_BACK: + if( this->writePos > 0 ) + { + --this->writePos; + this->textTarget->erase( this->writePos, 1 ); + } + break; + case VK_DELETE: + if( this->writePos < this->textTarget->size() ) + { + this->textTarget->erase( this->writePos, 1 ); + } + break; + case VK_LEFT: + this->writePos = Max( this->writePos - 1, (wstring::size_type)0 ); + break; + case VK_RIGHT: + this->writePos = Min( this->writePos + 1, this->textTarget->size() ); + break; + default: break; + } + } + default: break; + } +} diff --git a/Code/Misc/Input/Source/Win32/Win32Input.cpp b/Code/Misc/Input/Source/Win32/Win32Input.cpp index c6be3c9d..28032070 100644 --- a/Code/Misc/Input/Source/Win32/Win32Input.cpp +++ b/Code/Misc/Input/Source/Win32/Win32Input.cpp @@ -775,6 +775,10 @@ InputObject* Win32Input::CreateDevice(const SAIType inputType, Typedefs::WindowH } } break; + + case SAIType_ApplicationKeyboard: + val = new Win32ApplicationKeyboard(); + break; } return val; From ccd1ce3ab12890b20912e09cf5bc40d6ca3d1c2f Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Thu, 20 Feb 2014 14:58:42 +0100 Subject: [PATCH 04/32] jumping --- Code/Game/GameClient/DanBiasGame_Impl.cpp | 39 ++++++++++++++++++++--- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/Code/Game/GameClient/DanBiasGame_Impl.cpp b/Code/Game/GameClient/DanBiasGame_Impl.cpp index 2a46b8d6..f2ea8251 100644 --- a/Code/Game/GameClient/DanBiasGame_Impl.cpp +++ b/Code/Game/GameClient/DanBiasGame_Impl.cpp @@ -14,7 +14,7 @@ #include #include "../WindowManager/WindowShell.h" -#include "L_inputClass.h" +#include "Win32\Win32Input.h" #include "WinTimer.h" #include "vld.h" @@ -28,6 +28,7 @@ using namespace ::Oyster::Network; using namespace ::Utility::DynamicMemory; using namespace ::DanBias::Client; +LRESULT CALLBACK WindowCallBack(HWND handle, UINT message, WPARAM wParam, LPARAM lParam ); void ClientEventFunction( NetEvent e ); namespace DanBias @@ -66,9 +67,10 @@ namespace DanBias //if(! data.window->CreateWin(WindowShell::WINDOW_INIT_DESC(L"Window", cPOINT(1600, 900), cPOINT()))) WindowShell::WINDOW_INIT_DESC winDesc; - winDesc.windowSize.x = 1280; - winDesc.windowSize.y = 720; - + winDesc.windowSize.x = 1280; + winDesc.windowSize.y = 720; + winDesc.windowProcCallback = WindowCallBack; + if(! data.window->CreateWin(winDesc) ) return DanBiasClientReturn_Error; @@ -261,6 +263,35 @@ namespace DanBias } //End namespace DanBias +LRESULT CALLBACK WindowCallBack(HWND handle, UINT message, WPARAM wParam, LPARAM lParam ) +{ + PAINTSTRUCT ps; + HDC hdc; + + switch ( message ) + { + case WM_PAINT: + hdc = BeginPaint( handle, &ps ); + EndPaint( handle, &ps ); + break; + + case WM_DESTROY: + PostQuitMessage( 0 ); + break; + + case WM_KEYDOWN: + switch( wParam ) + { + case VK_ESCAPE: + PostQuitMessage( 0 ); + break; + } + break; + } + + return DefWindowProc( handle, message, wParam, lParam ); +} + void ClientEventFunction( NetEvent e ) { if( DanBias::data.state ) From fa2c4455f14b6f6f642c00a3d8752efb7581944f Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Thu, 20 Feb 2014 14:59:24 +0100 Subject: [PATCH 05/32] missed file --- Code/Game/GameClient/GameClient.vcxproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Code/Game/GameClient/GameClient.vcxproj b/Code/Game/GameClient/GameClient.vcxproj index c084532d..d9a55892 100644 --- a/Code/Game/GameClient/GameClient.vcxproj +++ b/Code/Game/GameClient/GameClient.vcxproj @@ -106,7 +106,7 @@ Disabled DANBIAS_GAME_DLL_EXPORT;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) true - $(SolutionDir)Misc\OysterMath;$(SolutionDir)Misc\Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc\Utilities;$(SolutionDir)Game\LevelLoader + $(SolutionDir)Misc\OysterMath;$(SolutionDir)Misc\Input\Include;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc\Utilities;$(SolutionDir)Game\LevelLoader Windows @@ -123,7 +123,7 @@ Disabled DANBIAS_GAME_DLL_EXPORT;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) true - $(SolutionDir)Misc\OysterMath;$(SolutionDir)Misc\Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc\Utilities;$(SolutionDir)Game\LevelLoader + $(SolutionDir)Misc\OysterMath;$(SolutionDir)Misc\Input\Include;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc\Utilities;$(SolutionDir)Game\LevelLoader Windows @@ -142,7 +142,7 @@ true DANBIAS_GAME_DLL_EXPORT;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) true - $(SolutionDir)Misc\OysterMath;$(SolutionDir)Misc\Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc\Utilities;$(SolutionDir)Game\LevelLoader + $(SolutionDir)Misc\OysterMath;$(SolutionDir)Misc\Input\Include;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc\Utilities;$(SolutionDir)Game\LevelLoader Windows @@ -163,7 +163,7 @@ true DANBIAS_GAME_DLL_EXPORT;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) true - $(SolutionDir)Misc\OysterMath;$(SolutionDir)Misc\Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc\Utilities;$(SolutionDir)Game\LevelLoader + $(SolutionDir)Misc\OysterMath;$(SolutionDir)Misc\Input\Include;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc\Utilities;$(SolutionDir)Game\LevelLoader Windows From 3e8595f52cc5580b3c411fdc29acbe4f7be11de0 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Thu, 20 Feb 2014 16:15:47 +0100 Subject: [PATCH 06/32] branch jumping --- Code/Game/GameClient/DanBiasGame_Impl.cpp | 73 ++++++++++++------- .../GameClient/GameClientState/GameState.cpp | 52 ++++++------- .../GameClientState/LanMenuState.cpp | 19 +++-- .../GameClientState/LobbyAdminState.cpp | 22 ++---- .../GameClient/GameClientState/LobbyState.cpp | 22 ++---- .../GameClient/GameClientState/MainState.cpp | 17 ++--- .../GameClientState/SharedStateContent.h | 7 +- Code/Game/GameClient/Include/DanBiasGame.h | 2 +- Code/Misc/Input/Include/ApplicationKeyboard.h | 3 +- Code/Misc/Input/Include/Input.h | 1 + Code/Misc/Input/Include/Keyboard.h | 3 +- Code/Misc/Input/Include/Mouse.h | 3 +- 12 files changed, 120 insertions(+), 104 deletions(-) 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 From daa3f84c9c7d198c2a83df794e3718b125c3bd9f Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Thu, 20 Feb 2014 16:34:45 +0100 Subject: [PATCH 07/32] Added feature Input::Mouse::GetDeltaPosition plus a few improvements --- Code/Misc/Input/Include/Mouse.h | 14 ++++++++------ Code/Misc/Input/Include/Win32/Win32Mouse.h | 2 -- Code/Misc/Input/Source/Mouse.cpp | 20 ++++++++++++++++++++ Code/Misc/Input/Source/Win32/Win32Mouse.cpp | 13 ++----------- 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/Code/Misc/Input/Include/Mouse.h b/Code/Misc/Input/Include/Mouse.h index b657604b..510fe3a9 100644 --- a/Code/Misc/Input/Include/Mouse.h +++ b/Code/Misc/Input/Include/Mouse.h @@ -66,12 +66,14 @@ namespace Input }; public: - virtual bool IsBtnUp(Enum::SAMI key) = 0; - virtual bool IsBtnDown(Enum::SAMI key) = 0; - virtual int GetWheelDelta() = 0; - virtual Struct::SAIPoint2D GetPixelPosition(Struct::SAIPoint2D targetMem = Struct::SAIPoint2D()) = 0; - + virtual bool IsBtnUp(Enum::SAMI key) = 0; + virtual bool IsBtnDown(Enum::SAMI key) = 0; + public: + int GetWheelDelta() const; + Struct::SAIPoint2D & GetPixelPosition( Struct::SAIPoint2D &targetMem = Struct::SAIPoint2D() ) const; + Struct::SAIPoint2D & GetDeltaPosition( Struct::SAIPoint2D &targetMem = Struct::SAIPoint2D() ) const; + void AddOnMousePressCallback( Typedefs::OnMousePressCallback func); void AddOnMouseDownCallback( Typedefs::OnMouseDownCallback func ); void AddOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func ); @@ -135,7 +137,7 @@ namespace Input protected: std::vector mouseSubscribers; MouseCallbackList* callbackList; - Struct::SAIPoint2D pixelPos; + Struct::SAIPoint2D pixelPos, deltaPos; bool isCurorLocked; int wheelDelta; }; diff --git a/Code/Misc/Input/Include/Win32/Win32Mouse.h b/Code/Misc/Input/Include/Win32/Win32Mouse.h index 10c04a28..3f1c0f10 100644 --- a/Code/Misc/Input/Include/Win32/Win32Mouse.h +++ b/Code/Misc/Input/Include/Win32/Win32Mouse.h @@ -17,8 +17,6 @@ namespace Input bool IsBtnUp(Enum::SAMI key) override; bool IsBtnDown(Enum::SAMI key) override; - int GetWheelDelta() override; - Struct::SAIPoint2D GetPixelPosition(Struct::SAIPoint2D targetMem = Struct::SAIPoint2D()) override; void ProccessMouseData (bool isDown, Enum::SAMI btn, int delta, Struct::SAIPoint2D velocity, unsigned int makeCode); diff --git a/Code/Misc/Input/Source/Mouse.cpp b/Code/Misc/Input/Source/Mouse.cpp index 36bd8330..f0eaba3b 100644 --- a/Code/Misc/Input/Source/Mouse.cpp +++ b/Code/Misc/Input/Source/Mouse.cpp @@ -81,6 +81,7 @@ Mouse::Mouse() , wheelDelta(0) , isCurorLocked(0) , pixelPos() + , deltaPos() { } Mouse::~Mouse() @@ -88,6 +89,25 @@ Mouse::~Mouse() } +int Mouse::GetWheelDelta() const +{ + return this->wheelDelta; +} + +SAIPoint2D & Mouse::GetPixelPosition( Struct::SAIPoint2D &targetMem ) const +{ + targetMem.x = this->pixelPos.x; + targetMem.y = this->pixelPos.y; + return targetMem; +} + +SAIPoint2D & Mouse::GetDeltaPosition( Struct::SAIPoint2D &targetMem ) const +{ + targetMem.x = this->deltaPos.x; + targetMem.y = this->deltaPos.y; + return targetMem; +} + void Mouse::AddOnMousePressCallback( Typedefs::OnMousePressCallback func) { MouseCallbackList::CallbackData d; diff --git a/Code/Misc/Input/Source/Win32/Win32Mouse.cpp b/Code/Misc/Input/Source/Win32/Win32Mouse.cpp index ef6d9edf..8bf22972 100644 --- a/Code/Misc/Input/Source/Win32/Win32Mouse.cpp +++ b/Code/Misc/Input/Source/Win32/Win32Mouse.cpp @@ -30,22 +30,13 @@ bool Win32Mouse::IsBtnDown(Enum::SAMI btn) return this->buttons[btn].isDown; } -int Win32Mouse::GetWheelDelta() -{ - return this->wheelDelta; -} -Struct::SAIPoint2D Win32Mouse::GetPixelPosition(Struct::SAIPoint2D targetMem) -{ - targetMem = this->pixelPos; - return targetMem; -} void Win32Mouse::ProccessMouseData (bool isUp, Enum::SAMI btn, int delta, Struct::SAIPoint2D velocity, unsigned int makeCode) { if(velocity.Length() != 0) { - this->pixelPos.x += velocity.x; - this->pixelPos.y += velocity.y; + this->pixelPos.x += this->deltaPos.x = velocity.x; + this->pixelPos.y += this->deltaPos.y = velocity.y; for (unsigned int i = 0; i < this->mouseSubscribers.size(); i++) { From 61ce9a9a3eb95a60c33064898cbe4cbb3c14a2ec Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Thu, 20 Feb 2014 16:55:34 +0100 Subject: [PATCH 08/32] New input system integrations --- .../GameClient/GameClientState/GameState.cpp | 141 +++++++----------- .../GameClient/GameClientState/GamingUI.cpp | 9 +- .../GameClient/GameClientState/GamingUI.h | 7 +- 3 files changed, 66 insertions(+), 91 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 656dde7f..ffc1d5da 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -292,117 +292,88 @@ 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->mouseInput->IsKeyPressed(DIK_A) ) - { - //if( !this->privData->key_strafeLeft ) - { - this->privData->nwClient->Send( Protocol_PlayerMovementLeft() ); - this->privData->key_strafeLeft = true; - } + if( this->privData->keyboardInput_raw->IsKeyDown(::Input::Enum::SAKI_A) ) + { // strafe left + this->privData->nwClient->Send( Protocol_PlayerMovementLeft() ); + this->privData->key_strafeLeft = true; } - else - this->privData->key_strafeLeft = false; - if( this->privData->mouseInput->IsKeyPressed(DIK_D) ) - { - //if( !this->privData->key_strafeRight ) - { - this->privData->nwClient->Send( Protocol_PlayerMovementRight() ); - this->privData->key_strafeRight = true; - } - } - else - this->privData->key_strafeRight = false; + 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 ); - 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. + ::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(yaw * mouseSensitivity) ); + this->privData->nwClient->Send( Protocol_PlayerLeftTurn(deltaPos.x * mouseSensitivity) ); } } // shoot - if( this->privData->mouseInput->IsKeyPressed(DIK_Z) ) + if( this->privData->mouseInput->IsBtnDown(::Input::Enum::SAMI_MouseLeftBtn) ) { - if( !this->privData->key_Shoot ) - { - Protocol_PlayerShot playerShot; - playerShot.primaryPressed = true; - playerShot.secondaryPressed = false; - playerShot.utilityPressed = false; - this->privData->nwClient->Send( playerShot ); - this->privData->key_Shoot = true; - } - } - else - this->privData->key_Shoot = false; - if( this->privData->mouseInput->IsKeyPressed(DIK_X) ) - { - if( !this->privData->key_Shoot ) - { - Protocol_PlayerShot playerShot; - playerShot.primaryPressed = false; - playerShot.secondaryPressed = true; - playerShot.utilityPressed = false; - this->privData->nwClient->Send( playerShot ); - this->privData->key_Shoot = true; - } - } - else - this->privData->key_Shoot = false; - if( this->privData->mouseInput->IsKeyPressed(DIK_C) ) - { - if( !this->privData->key_Shoot ) - { - Protocol_PlayerShot playerShot; - playerShot.primaryPressed = false; - playerShot.secondaryPressed = false; - playerShot.utilityPressed = true; - this->privData->nwClient->Send( playerShot ); - this->privData->key_Shoot = true; - } - } - else - this->privData->key_Shoot = false; - - // jump - if( this->privData->mouseInput->IsKeyPressed(DIK_SPACE) ) - { - if(!this->privData->key_Jump) - { - this->privData->nwClient->Send( Protocol_PlayerJump() ); - this->privData->key_Jump = true; - } + Protocol_PlayerShot playerShot; + playerShot.primaryPressed = true; + playerShot.secondaryPressed = false; + playerShot.utilityPressed = false; + this->privData->nwClient->Send( playerShot ); + this->privData->key_Shoot = true; } - else - this->privData->key_Jump = false; + 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; + } - - // DEGUG KEYS + +#ifdef _DEBUG // DEGUG KEYS // Reload shaders - if( this->privData->mouseInput->IsKeyPressed(DIK_R) ) + if( this->privData->keyboardInput_raw->IsKeyDown(::Input::Enum::SAKI_R) ) { if( !this->privData->key_Reload_Shaders ) { -#ifdef _DEBUG + Graphics::API::ReloadShaders(); -#endif + this->privData->key_Reload_Shaders = true; } } @@ -410,7 +381,7 @@ void GameState::ReadKeyInput() this->privData->key_Reload_Shaders = false; // toggle wire frame render - if( this->privData->mouseInput->IsKeyPressed(DIK_T) ) + if( this->privData->keyboardInput_raw->IsKeyDown(::Input::Enum::SAKI_T) ) { if( !this->privData->key_Wireframe_Toggle ) { @@ -420,8 +391,8 @@ void GameState::ReadKeyInput() } else this->privData->key_Wireframe_Toggle = false; - // !DEGUG KEYS - // TODO: implement sub-menu + +#endif // !DEGUG KEYS } const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState::NetEvent &message ) diff --git a/Code/Game/GameClient/GameClientState/GamingUI.cpp b/Code/Game/GameClient/GameClientState/GamingUI.cpp index 8ff43d88..7f1b9fb8 100644 --- a/Code/Game/GameClient/GameClientState/GamingUI.cpp +++ b/Code/Game/GameClient/GameClientState/GamingUI.cpp @@ -6,20 +6,23 @@ using namespace ::DanBias::Client; using namespace ::Oyster::Network; using namespace ::GameLogic; using namespace ::Utility::Value; +using namespace ::Input; GamingUI::GamingUI() : GameStateUI() { /* Should never be called! */ - this->input = nullptr; + this->mouseInput = nullptr; + this->keyboardInput = nullptr; this->netClient = nullptr; this->camera = nullptr; } -GamingUI::GamingUI( InputClass *input, NetworkClient *connection, Camera_FPSV2 *camera ) : +GamingUI::GamingUI( Mouse *mouseInput, Keyboard *keyboardInput, NetworkClient *connection, Camera_FPSV2 *camera ) : GameStateUI() { - this->input = input; + this->mouseInput = mouseInput; + this->keyboardInput = keyboardInput; this->netClient = connection; this->camera = camera; } diff --git a/Code/Game/GameClient/GameClientState/GamingUI.h b/Code/Game/GameClient/GameClientState/GamingUI.h index 9f93674b..05eef65a 100644 --- a/Code/Game/GameClient/GameClientState/GamingUI.h +++ b/Code/Game/GameClient/GameClientState/GamingUI.h @@ -2,7 +2,7 @@ #define DANBIAS_CLIENT_GAMING_UI_H #include "GameStateUI.h" -#include "L_inputClass.h" +#include "Input.h" #include "Camera_FPSV2.h" namespace DanBias { namespace Client @@ -10,7 +10,7 @@ namespace DanBias { namespace Client class GamingUI : public GameStateUI { public: - GamingUI( InputClass *input, ::Oyster::Network::NetworkClient *connection, Camera_FPSV2 *camera ); + GamingUI( ::Input::Mouse *mouseInput, ::Input::Keyboard *keyboardInput, ::Oyster::Network::NetworkClient *connection, Camera_FPSV2 *camera ); virtual ~GamingUI(); UIState Update( float deltaTime ); @@ -21,7 +21,8 @@ namespace DanBias { namespace Client bool Release(); private: - InputClass *input; + ::Input::Mouse *mouseInput; + ::Input::Keyboard *keyboardInput; ::Oyster::Network::NetworkClient *netClient; Camera_FPSV2 *camera; From ac492b413b618c75f643b681f407ec01570a0170 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Fri, 21 Feb 2014 09:36:43 +0100 Subject: [PATCH 09/32] implementations --- Code/Game/GameClient/DanBiasGame_Impl.cpp | 100 ++++++++---------- Code/Game/GameClient/GameClient.vcxproj | 1 + .../GameClient/GameClientState/GameState.cpp | 79 +------------- .../GameClient/GameClientState/GamingUI.cpp | 57 +++++----- Code/Game/GameClient/Include/DanBiasGame.h | 2 +- 5 files changed, 79 insertions(+), 160 deletions(-) diff --git a/Code/Game/GameClient/DanBiasGame_Impl.cpp b/Code/Game/GameClient/DanBiasGame_Impl.cpp index 1dd6e8c6..c89e5db9 100644 --- a/Code/Game/GameClient/DanBiasGame_Impl.cpp +++ b/Code/Game/GameClient/DanBiasGame_Impl.cpp @@ -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 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::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::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 ); } diff --git a/Code/Game/GameClient/GameClient.vcxproj b/Code/Game/GameClient/GameClient.vcxproj index 08cc897f..123bf420 100644 --- a/Code/Game/GameClient/GameClient.vcxproj +++ b/Code/Game/GameClient/GameClient.vcxproj @@ -251,6 +251,7 @@ + diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 9f3e8c31..1e142d6f 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -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 diff --git a/Code/Game/GameClient/GameClientState/GamingUI.cpp b/Code/Game/GameClient/GameClientState/GamingUI.cpp index bf0cbeb5..e29b2f93 100644 --- a/Code/Game/GameClient/GameClientState/GamingUI.cpp +++ b/Code/Game/GameClient/GameClientState/GamingUI.cpp @@ -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 } diff --git a/Code/Game/GameClient/Include/DanBiasGame.h b/Code/Game/GameClient/Include/DanBiasGame.h index b0af07c7..f6f0cdee 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( HINSTANCE *handle ); + static HRESULT InitInput( HWND handle ); static Result Update(float deltaTime); static HRESULT Render(); From ed6f80765e6047074ac4cf72697f489d7fb48e5e Mon Sep 17 00:00:00 2001 From: dean11 Date: Fri, 21 Feb 2014 11:43:05 +0100 Subject: [PATCH 10/32] Misc - Intergrated seperate textual input --- Code/Game/GameClient/GameClient.vcxproj | 1 + Code/Game/GameClient/Win32Input.h | 70 ++ Code/Misc/Input/Include/Common.h | 15 +- Code/Misc/Input/Include/InputManager.h | 8 +- Code/Misc/Input/Include/InputObject.h | 8 +- Code/Misc/Input/Include/Keyboard.h | 57 +- Code/Misc/Input/Include/Mouse.h | 78 +- Code/Misc/Input/Include/Win32/Win32Input.h | 47 +- Code/Misc/Input/Include/Win32/Win32Keyboard.h | 8 +- Code/Misc/Input/Include/Win32/Win32Mouse.h | 8 +- Code/Misc/Input/Input.vcxproj | 15 +- Code/Misc/Input/Main.cpp | 125 +-- Code/Misc/Input/Source/Keyboard.cpp | 130 +++- Code/Misc/Input/Source/Mouse.cpp | 164 +++- Code/Misc/Input/Source/Win32/Win32Input.cpp | 720 ++---------------- .../Misc/Input/Source/Win32/Win32Keyboard.cpp | 682 ++++++++++++++--- Code/Misc/Input/Source/Win32/Win32Mouse.cpp | 195 ++--- 17 files changed, 1161 insertions(+), 1170 deletions(-) create mode 100644 Code/Game/GameClient/Win32Input.h diff --git a/Code/Game/GameClient/GameClient.vcxproj b/Code/Game/GameClient/GameClient.vcxproj index c084532d..b7e0946e 100644 --- a/Code/Game/GameClient/GameClient.vcxproj +++ b/Code/Game/GameClient/GameClient.vcxproj @@ -253,6 +253,7 @@ + diff --git a/Code/Game/GameClient/Win32Input.h b/Code/Game/GameClient/Win32Input.h new file mode 100644 index 00000000..1d2605cf --- /dev/null +++ b/Code/Game/GameClient/Win32Input.h @@ -0,0 +1,70 @@ +///////////////////////////////////////////////////////////////////// +// Created by [Dennis Andersen] [2013] +///////////////////////////////////////////////////////////////////// +#ifndef INCLUDE_GUARD_RAW_INPUT_H +#define INCLUDE_GUARD_RAW_INPUT_H + + +#include "..\InputManager.h" +#include "Win32Keyboard.h" +#include "Win32Mouse.h" +#include +#define NOMINMAX +#include +#include + +/** +* TODO: +* 1. Cordinate system +* 1.1. Pixel cordinates DONE +* 1.2. 0 - 1 cordinate DONW +* 1.3. Origo in middle of the screen ( -1 to 1 ) +*/ + +//RIDEV_INPUTSINK to receive all keyboard input regardless of focus + +//dx = +2*(x/w) -1 +//dx = -2*(y/h) +1 + + +namespace Input +{ + enum RawInput_Usage + { + RawInput_Usage_pointer = 1, + RawInput_Usage_mouse = 2, + RawInput_Usage_joystick = 4, + RawInput_Usage_gamepad = 5, + RawInput_Usage_keyboard = 6, + RawInput_Usage_keypad = 7, + RawInput_Usage_multiAxisController = 8, + RawInput_Usage_TabletPCcontrols = 9, + }; + + class Win32Input :public InputManager + { + public: + Win32Input(); + virtual~Win32Input(); + + InputObject* CreateDevice(const Enum::SAIType inputType, Typedefs::WindowHandle targetApplication) override; + void ToggleInputSystem(bool enable) override; + void Destroy() override; + + private: + std::vector keyboard; + std::vector mouse; + + bool enabled; + bool exclusive; + HWND targetHwin; + + private: + static Win32Input* instance; + static LRESULT RawInputParser(HWND h, LPARAM l); + static LRESULT CALLBACK RawWindowCallback(HWND h, UINT m, WPARAM w, LPARAM l); + static void WindowActivate(bool activate); + }; +} +#endif + diff --git a/Code/Misc/Input/Include/Common.h b/Code/Misc/Input/Include/Common.h index 9bb9f2cf..a82ad47b 100644 --- a/Code/Misc/Input/Include/Common.h +++ b/Code/Misc/Input/Include/Common.h @@ -21,6 +21,7 @@ namespace Input { SAIType_Keyboard, SAIType_Mouse, + SAIType_ApplicationKeyboard, SAIType_futureExample1, SAIType_futureExample2, SAIType_futureExample3, @@ -36,22 +37,14 @@ namespace Input /*********************************************************************/ namespace Struct { - struct SAIPointInt2D + struct SAIPoint2D { int x; int y; - SAIPointInt2D() :x(0), y(0) { } - SAIPointInt2D(int _x, int _y) :x(_x), y(_y) { } + SAIPoint2D() :x(0), y(0) { } + SAIPoint2D(int _x, int _y) :x(_x), y(_y) { } int Length() { return (abs(x) + abs(y)); } }; - struct SAIPointFloat2D - { - float x; - float y; - SAIPointFloat2D() :x(0.0f), y(0.0f) { } - SAIPointFloat2D(float _x, float _y) :x(_x), y(_y) { } - float Length() { return (fabs(x) + fabs(y)); } - }; struct InputData; } diff --git a/Code/Misc/Input/Include/InputManager.h b/Code/Misc/Input/Include/InputManager.h index ee037563..237fb179 100644 --- a/Code/Misc/Input/Include/InputManager.h +++ b/Code/Misc/Input/Include/InputManager.h @@ -18,12 +18,12 @@ namespace Input /** * @return Returns an instance of the default input manager. */ - static InputManager* Instance (); + static InputManager* Instance (); /** * @return Returns a new input manager. Should be destroyd with DestroyInputManager function. */ - static InputManager* CreateInputManager (); + static InputManager* CreateInputManager (); /** * @return Destroys a input manager. @@ -37,7 +37,9 @@ namespace Input * @see InputDescription * @return Returns a handle to a device that can be rethrown to a specific device. */ - virtual InputObject* CreateDevice (const Enum::SAIType inputType, Typedefs::WindowHandle targetApplication = 0) = 0; + virtual InputObject* CreateDevice ( const Enum::SAIType inputType, Typedefs::WindowHandle targetApplication = 0 ) = 0; + virtual Keyboard* CreateKeyboardDevice ( Typedefs::WindowHandle targetApplication = 0 ) { return (Keyboard*)CreateDevice(Enum::SAIType_Keyboard, targetApplication); } + virtual Mouse* CreateMouseDevice ( Typedefs::WindowHandle targetApplication = 0 ) { return (Mouse*)CreateDevice(Enum::SAIType_Mouse, targetApplication); } /** Enables or Disables the Input proccessing. * @param The toggler. diff --git a/Code/Misc/Input/Include/InputObject.h b/Code/Misc/Input/Include/InputObject.h index 75dea07b..3536730b 100644 --- a/Code/Misc/Input/Include/InputObject.h +++ b/Code/Misc/Input/Include/InputObject.h @@ -13,8 +13,9 @@ namespace Input public: inline Enum::SAIType Type() { return type; } - virtual inline void Enable () { isEnabled = true; }; - virtual inline void Disable () { isEnabled = false; }; + virtual void Activate () = 0; + virtual void Deactivate () = 0; + virtual bool IsActive() = 0; protected: InputObject(Enum::SAIType type) { this->type = type; } @@ -22,9 +23,6 @@ namespace Input private: Enum::SAIType type; - - protected: - bool isEnabled; }; } diff --git a/Code/Misc/Input/Include/Keyboard.h b/Code/Misc/Input/Include/Keyboard.h index 6f561eba..54f5c87c 100644 --- a/Code/Misc/Input/Include/Keyboard.h +++ b/Code/Misc/Input/Include/Keyboard.h @@ -133,9 +133,9 @@ namespace Input //----------------------------------------------------------------------------------------------------------------------------- namespace Typedefs { - typedef void(*OnKeyPressCallback)(Enum::SAKI key, const wchar_t[40], Keyboard* sender); - typedef void(*OnKeyDownCallback)(Enum::SAKI key, const wchar_t[40], Keyboard* sender); - typedef void(*OnKeyReleaseCallback)(Enum::SAKI key, const wchar_t[40], Keyboard* sender); + typedef void(*OnKeyPressCallback)(Enum::SAKI key, const wchar_t[16], Keyboard* sender); + typedef void(*OnKeyDownCallback)(Enum::SAKI key, const wchar_t[16], Keyboard* sender); + typedef void(*OnKeyReleaseCallback)(Enum::SAKI key, const wchar_t[16], Keyboard* sender); } //----------------------------------------------------------------------------------------------------------------------------- @@ -153,7 +153,7 @@ namespace Input public: /* Manual check functions */ virtual bool IsKeyUp (Enum::SAKI key) = 0; virtual bool IsKeyDown (Enum::SAKI key) = 0; - virtual const wchar_t* GetAsText(Enum::SAKI key) = 0; + virtual wchar_t* GetAsText(Enum::SAKI key) = 0; public: /* global subscribe callback functions */ void AddOnKeyPressCallback (Typedefs::OnKeyPressCallback func); @@ -164,49 +164,36 @@ namespace Input void RemoveOnKeyDownCallback (Typedefs::OnKeyDownCallback func); void RemoveOnKeyReleaseCallback (Typedefs::OnKeyReleaseCallback func); + public: /* From InputObject */ + virtual void Activate () override { this->active = true; } + virtual void Deactivate () override { this->active = false; } + virtual bool IsActive() override { return this->active; } + public: void operator+= (KeyboardEvent* object); void operator-= (KeyboardEvent* object); + void BindTextTarget( ::std::wstring *field ); + void ReleaseTextTarget(); + + public: + struct KeyboardCallbackList; + protected: Keyboard(); ~Keyboard(); - protected: - struct KeyboardCallbackList - { - enum CallbackDataType - { - CallbackDataType_OnPress, - CallbackDataType_OnDown, - CallbackDataType_OnRelease - } type; - union CallbackData - { - Typedefs::OnKeyPressCallback keyPressCallback; - Typedefs::OnKeyDownCallback keyDownCallback; - Typedefs::OnKeyReleaseCallback keyReleaseCallback; - - CallbackData (){ memset(this, 0, sizeof(CallbackData)); } - CallbackData (Typedefs::OnKeyPressCallback o){ keyPressCallback = o; } - bool operator ==(CallbackData o){ return o.keyDownCallback == keyDownCallback; } - bool operator ==(Typedefs::OnKeyPressCallback o ){ return o == keyPressCallback; } - operator bool(){ return this->keyDownCallback != 0; } - } function; - KeyboardCallbackList *next; - KeyboardCallbackList(CallbackData func, CallbackDataType t) :function(func), next(0), type(t) { } - }; - - protected: - void ClearList(KeyboardCallbackList* first); - void AddToList(Keyboard::KeyboardCallbackList* first, KeyboardCallbackList::CallbackData data, KeyboardCallbackList::CallbackDataType type); - void RemoveFromList(KeyboardCallbackList* first, KeyboardCallbackList::CallbackData data); - bool ExistsInList(KeyboardCallbackList* first, KeyboardCallbackList::CallbackData data); - bool ExistsInList(std::vector& list, KeyboardEvent* data); + protected: /* Internal event proc */ + void InternalOnKeyPress(Enum::SAKI key, wchar_t text[16]); + void InternalOnKeyDown(Enum::SAKI key, wchar_t text[16]); + void InternalOnKeyRelease(Enum::SAKI key, wchar_t text[16]); protected: std::vector keyEventSubscrivers; KeyboardCallbackList* callbackList; + ::std::wstring* textTarget; + ::std::wstring::size_type writePos; + bool active; }; } diff --git a/Code/Misc/Input/Include/Mouse.h b/Code/Misc/Input/Include/Mouse.h index 6c58ec97..3ef9887c 100644 --- a/Code/Misc/Input/Include/Mouse.h +++ b/Code/Misc/Input/Include/Mouse.h @@ -47,7 +47,7 @@ namespace Input typedef void(*OnMousePressCallback)(Enum::SAMI btn, Mouse* sender); typedef void(*OnMouseDownCallback)(Enum::SAMI btn, Mouse* sender); typedef void(*OnMouseReleaseCallback)(Enum::SAMI btn, Mouse* sender); - typedef void(*OnMouseMoveCallback)(Struct::SAIPointInt2D, Mouse* sender); + typedef void(*OnMouseMoveCallback)(Struct::SAIPoint2D cord, Mouse* sender); typedef void(*OnMouseScrollCallback)(int delta, Mouse* sender); } //----------------------------------------------------------------------------------------------------------------------------- @@ -55,24 +55,26 @@ namespace Input class Mouse :public InputObject { public: + class MouseEvent { public: virtual void OnMousePress ( Enum::SAMI key, Mouse* sender ) { } virtual void OnMouseDown ( Enum::SAMI key, Mouse* sender ) { } virtual void OnMouseRelease ( Enum::SAMI key, Mouse* sender ) { } - virtual void OnMouseMove ( Struct::SAIPointInt2D coordinate, Mouse* sender ) { } + virtual void OnMouseMove ( Struct::SAIPoint2D coordinate, Mouse* sender ) { } virtual void OnMouseScroll ( int delta, Mouse* sender ) { } }; - public: - virtual bool IsBtnUp(Enum::SAMI key) = 0; - virtual bool IsBtnDown(Enum::SAMI key) = 0; - virtual int GetWheelDelta() = 0; - virtual Struct::SAIPointInt2D GetPixelPosition(Struct::SAIPointInt2D targetMem = Struct::SAIPointInt2D()) = 0; - virtual Struct::SAIPointFloat2D GetNormalizedPosition(Struct::SAIPointFloat2D targetMem = Struct::SAIPointFloat2D()) = 0; + public: /* Manual check functions */ + virtual bool IsBtnUp(Enum::SAMI key) = 0; + virtual bool IsBtnDown(Enum::SAMI key) = 0; + + public: /* global subscribe callback functions */ + int GetWheelDelta() const; + Struct::SAIPoint2D & GetPixelPosition( Struct::SAIPoint2D &targetMem = Struct::SAIPoint2D() ) const; + Struct::SAIPoint2D & GetDeltaPosition( Struct::SAIPoint2D &targetMem = Struct::SAIPoint2D() ) const; - public: void AddOnMousePressCallback( Typedefs::OnMousePressCallback func); void AddOnMouseDownCallback( Typedefs::OnMouseDownCallback func ); void AddOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func ); @@ -85,61 +87,39 @@ namespace Input void RemoveOnMouseMoveCallback( Typedefs::OnMouseMoveCallback func ); void RemoveOnMouseScrollCallback( Typedefs::OnMouseScrollCallback func ); + public: /* From InputObject */ + virtual void Activate () override { this->active = true; } + virtual void Deactivate () override { this->active = false; } + virtual bool IsActive() override { return this->active; } + + public: + void operator+= (MouseEvent* object); + void operator-= (MouseEvent* object); + void SetPixelPos(int x, int y); void ToggleCursor(bool toggler); - private: - void operator+= (MouseEvent* object); - void operator-= (MouseEvent* object); + public: + struct MouseCallbackList; protected: Mouse(); ~Mouse(); protected: - struct MouseCallbackList - { - enum CallbackDataType - { - CallbackDataType_OnPress, - CallbackDataType_OnDown, - CallbackDataType_OnRelease, - CallbackDataType_OnMove, - CallbackDataType_OnScroll, - } type; - union CallbackData - { - Typedefs::OnMousePressCallback mousePressCallback; - Typedefs::OnMouseDownCallback mouseDownCallback; - Typedefs::OnMouseReleaseCallback mouseReleaseCallback; - Typedefs::OnMouseMoveCallback mouseMoveCallback; - Typedefs::OnMouseScrollCallback mouseScrollCallback; - void* dummy; - - CallbackData (){ memset(this, 0, sizeof(CallbackData)); } - CallbackData (void* d){ dummy = d; } - bool operator ==(CallbackData o){ return o.dummy == dummy; } - bool operator ==(void* o ){ return o == dummy; } - operator bool(){ return this->dummy != 0; } - } function; - MouseCallbackList *next; - MouseCallbackList(CallbackData func, CallbackDataType t) :function(func), next(0), type(t) { } - }; - - protected: - void ClearList(MouseCallbackList* first); - void AddToList(MouseCallbackList* first, MouseCallbackList::CallbackData data, MouseCallbackList::CallbackDataType type); - void RemoveFromList(MouseCallbackList* first, MouseCallbackList::CallbackData data); - bool ExistsInList(MouseCallbackList* first, MouseCallbackList::CallbackData data); - bool ExistsInList(std::vector& list, MouseEvent* data); + void InternalOnBtnPress(Enum::SAMI key); + void InternalOnBtnDown(Enum::SAMI key); + void InternalOnBtnRelease(Enum::SAMI key); + void InternalOnMove(Struct::SAIPoint2D cord); + void InternalOnScroll(int delta); protected: std::vector mouseSubscribers; MouseCallbackList* callbackList; - Struct::SAIPointInt2D pixelPos; - Struct::SAIPointFloat2D normalPos; + Struct::SAIPoint2D pixelPos, deltaPos; bool isCurorLocked; int wheelDelta; + bool active; }; } diff --git a/Code/Misc/Input/Include/Win32/Win32Input.h b/Code/Misc/Input/Include/Win32/Win32Input.h index c420e3a7..1d2605cf 100644 --- a/Code/Misc/Input/Include/Win32/Win32Input.h +++ b/Code/Misc/Input/Include/Win32/Win32Input.h @@ -9,14 +9,15 @@ #include "Win32Keyboard.h" #include "Win32Mouse.h" #include +#define NOMINMAX #include #include /** * TODO: * 1. Cordinate system -* 1.1. Pixel cordinates -* 1.2. 0 - 1 cordinate +* 1.1. Pixel cordinates DONE +* 1.2. 0 - 1 cordinate DONW * 1.3. Origo in middle of the screen ( -1 to 1 ) */ @@ -42,46 +43,6 @@ namespace Input class Win32Input :public InputManager { - // private: - // SubscribeList* _procInput; - // - // bool _enabled; - // bool _mouseEnabled; - // bool _KeyboardEnabled; - // bool _exclusive; - // List _deviceList; - // - // List _mouseInput; - // List _keyboardInput; - // - // HHOOK _msgHook; - // - // private: - // Win32Input (); - // ~Win32Input (); - // - // bool _addDevice (const RAWINPUTDEVICE* k, const int& count); - // RAWINPUT*_TranslateRawInput (LPARAM l); - // void _proccessRawMouseData (RAWMOUSE&); - // void _proccessRawKeyboardData (RAWKEYBOARD&); - // - // static LRESULT CALLBACK WM_INPUT_TRANSLATE (int nCode, WPARAM wParam, LPARAM lParam); - // - // public: - // - // static Win32Input* Self (); - // static void Destroy (); - // - // const wchar_t* Input_GetError () const; - // - // bool Input_AddDevice (IN const HWND& targetApplication); - // bool Input_AddDevice (IN const RAWINPUTDEVICE*, IN const int&); - // - // void Input_Subscribe (IN INPUT_CALLBACK fnc); - // void Input_Unsubscribe (IN INPUT_CALLBACK fnc); - // - // void Input_Disable (); - // void Input_Enable (); public: Win32Input(); virtual~Win32Input(); @@ -100,7 +61,7 @@ namespace Input private: static Win32Input* instance; - static void RawInputParser(HWND h, LPARAM l); + static LRESULT RawInputParser(HWND h, LPARAM l); static LRESULT CALLBACK RawWindowCallback(HWND h, UINT m, WPARAM w, LPARAM l); static void WindowActivate(bool activate); }; diff --git a/Code/Misc/Input/Include/Win32/Win32Keyboard.h b/Code/Misc/Input/Include/Win32/Win32Keyboard.h index 8a8638a4..e2e0442c 100644 --- a/Code/Misc/Input/Include/Win32/Win32Keyboard.h +++ b/Code/Misc/Input/Include/Win32/Win32Keyboard.h @@ -5,6 +5,7 @@ #define INPUT_KEYBOARD_H #include "..\Keyboard.h" +#define NOMINMAX #include namespace Input @@ -17,17 +18,20 @@ namespace Input bool IsKeyUp (Enum::SAKI key) override; bool IsKeyDown (Enum::SAKI key) override; - const wchar_t* GetAsText(Enum::SAKI key) override; + wchar_t* GetAsText(Enum::SAKI key) override; - void ProccessKeyboardData (bool isUp, Enum::SAKI key, unsigned int makeCode, bool isE0); + void ProccessKeyboardData (RAWKEYBOARD keyboard); private: + void MapKey(RAWKEYBOARD& rawKB, Enum::SAKI& out_key, bool& isE0); + struct Keys { bool isE0; bool isDown; unsigned int makecode; }; + static const int MAXKEYS = 256; Keys keys[MAXKEYS]; }; diff --git a/Code/Misc/Input/Include/Win32/Win32Mouse.h b/Code/Misc/Input/Include/Win32/Win32Mouse.h index 278a76a4..71a37b2d 100644 --- a/Code/Misc/Input/Include/Win32/Win32Mouse.h +++ b/Code/Misc/Input/Include/Win32/Win32Mouse.h @@ -17,13 +17,8 @@ namespace Input bool IsBtnUp(Enum::SAMI key) override; bool IsBtnDown(Enum::SAMI key) override; - int GetWheelDelta() override; - Struct::SAIPointInt2D GetPixelPosition(Struct::SAIPointInt2D targetMem = Struct::SAIPointInt2D()) override; - Struct::SAIPointFloat2D GetNormalizedPosition(Struct::SAIPointFloat2D targetMem = Struct::SAIPointFloat2D()) override; - void ProccessMouseData (bool isDown, Enum::SAMI btn, int delta, Struct::SAIPointInt2D velocity, unsigned int makeCode); - - bool Create(HWND target); + void ProccessMouseData (RAWMOUSE mouse); private: struct Buttons @@ -33,7 +28,6 @@ namespace Input }; static const int MAXBUTTONS = 25; Buttons buttons[25]; - RAWINPUTDEVICE device; }; } diff --git a/Code/Misc/Input/Input.vcxproj b/Code/Misc/Input/Input.vcxproj index 8642e69e..9378c5f6 100644 --- a/Code/Misc/Input/Input.vcxproj +++ b/Code/Misc/Input/Input.vcxproj @@ -20,6 +20,7 @@ + @@ -35,37 +36,41 @@ - + + + {35aea3c0-e0a7-4e1e-88cd-514aa5a442b1} + + {7E3990D2-3D94-465C-B58D-64A74B3ECF9B} Input - StaticLibrary + Application true v110 Unicode - StaticLibrary + Application true v110 Unicode - StaticLibrary + Application false v110 true Unicode - StaticLibrary + Application false v110 true diff --git a/Code/Misc/Input/Main.cpp b/Code/Misc/Input/Main.cpp index 65a468d1..77792f1a 100644 --- a/Code/Misc/Input/Main.cpp +++ b/Code/Misc/Input/Main.cpp @@ -1,101 +1,38 @@ -#include "RawInput.h" -// include the basic windows header file -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "Include\Input.h" +#include "..\WindowManager\WindowShell.h" -HWND hWnd; -// this is the main message handler for the program -LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +using namespace std; + +int main(int agrc, char*args) { - // sort through and find what code to run for the message given - switch(message) - { - // this message is read when the window is closed - case WM_DESTROY: - { - // close the application entirely - PostQuitMessage(0); - return 0; - } break; - case WM_KEYUP: - MessageBox(0, L"WM_KEYUP", L"", 0); - break; - case WM_KEYDOWN: - MessageBox(0, L"WM_KEYDOWN", L"", 0); - break; - //case WM_INPUT: - // MessageBox(0, L"WM_INPUT_MAIN", L"", 0); - //break; - } - - // Handle any messages the switch statement didn't - return DefWindowProc (hWnd, message, wParam, lParam); -} -void initWindow(HINSTANCE h, int i) -{ - // this struct holds information for the window class - WNDCLASSEX wc; + WindowShell::CreateWin(WindowShell::WINDOW_INIT_DESC()); - // clear out the window class for use - ZeroMemory(&wc, sizeof(WNDCLASSEX)); + Input::Keyboard* app = Input::InputManager::Instance()->CreateKeyboardDevice(); + app->Deactivate(); + std::wstring text; + app->BindTextTarget( &text ); + int oldLen = 0; - // fill in the struct with the needed information - wc.cbSize = sizeof(WNDCLASSEX); - wc.style = CS_HREDRAW | CS_VREDRAW; - wc.lpfnWndProc = WindowProc; - wc.hInstance = h; - wc.hCursor = LoadCursor(NULL, IDC_ARROW); - wc.hbrBackground = (HBRUSH)COLOR_WINDOW; - wc.lpszClassName = L"WindowClass1"; + while (WindowShell::Frame()) + { + if(text.length() != oldLen) + { + wprintf(text.c_str()); + } + } - // register the window class - RegisterClassEx(&wc); - - // create the window and use the result as the handle - hWnd = CreateWindowEx(NULL, - L"WindowClass1", // name of the window class - L"Our First Windowed Program", // title of the window - WS_OVERLAPPEDWINDOW, // window style - 300, // x-position of the window - 300, // y-position of the window - 500, // width of the window - 400, // height of the window - NULL, // we have no parent window, NULL - NULL, // we aren't using menus, NULL - h, // application handle - NULL); // used with multiple windows, NULL - - // display the window on the screen - ShowWindow(hWnd, i); -} -void initRaw() -{ - //RawInput::Self()->Input_AddDevice(hWnd); -} -// the entry point for any Windows program -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) -{ - initWindow(hInstance, nCmdShow); - initRaw(); - - - // this struct holds Windows event messages - MSG msg; - - // wait for the next message in the queue, store the result in 'msg' - while(GetMessage(&msg, NULL, 0, 0)) - { - // translate keystroke messages into the right format - TranslateMessage(&msg); - // send the message to the WindowProc function - DispatchMessage(&msg); - - //RawInput::Self()->Input_Read(); - } - - RawInput::Destroy(); - - return msg.wParam; + system("pause"); } \ No newline at end of file diff --git a/Code/Misc/Input/Source/Keyboard.cpp b/Code/Misc/Input/Source/Keyboard.cpp index fa3423d8..8f99e8fe 100644 --- a/Code/Misc/Input/Source/Keyboard.cpp +++ b/Code/Misc/Input/Source/Keyboard.cpp @@ -8,11 +8,34 @@ using namespace Input::Enum; using namespace Input::Typedefs; using namespace Input::Struct; - -void Keyboard::ClearList(Keyboard::KeyboardCallbackList* first) +struct Keyboard::KeyboardCallbackList { - KeyboardCallbackList* w = first; - KeyboardCallbackList* removee = 0; + enum CallbackDataType + { + CallbackDataType_OnPress, + CallbackDataType_OnDown, + CallbackDataType_OnRelease + } type; + union CallbackData + { + Typedefs::OnKeyPressCallback keyPressCallback; + Typedefs::OnKeyDownCallback keyDownCallback; + Typedefs::OnKeyReleaseCallback keyReleaseCallback; + + CallbackData (){ memset(this, 0, sizeof(CallbackData)); } + CallbackData (Typedefs::OnKeyPressCallback o){ keyPressCallback = o; } + bool operator ==(CallbackData o){ return o.keyDownCallback == keyDownCallback; } + bool operator ==(Typedefs::OnKeyPressCallback o ){ return o == keyPressCallback; } + operator bool(){ return this->keyDownCallback != 0; } + } function; + KeyboardCallbackList *next; + KeyboardCallbackList(CallbackData func, CallbackDataType t) :function(func), next(0), type(t) { } +}; + +void ClearList(Keyboard::KeyboardCallbackList* first) +{ + Keyboard::KeyboardCallbackList* w = first; + Keyboard::KeyboardCallbackList* removee = 0; while (w) { @@ -21,27 +44,27 @@ void Keyboard::ClearList(Keyboard::KeyboardCallbackList* first) delete removee; } } -void Keyboard::AddToList(Keyboard::KeyboardCallbackList* first, KeyboardCallbackList::CallbackData data, KeyboardCallbackList::CallbackDataType type) +void AddToList(Keyboard::KeyboardCallbackList* first, Keyboard::KeyboardCallbackList::CallbackData data, Keyboard::KeyboardCallbackList::CallbackDataType type) { - KeyboardCallbackList *w = first; - KeyboardCallbackList *prev = first; + Keyboard::KeyboardCallbackList *w = first; + Keyboard::KeyboardCallbackList *prev = first; while (w) { prev = w; w = w->next; } - KeyboardCallbackList::CallbackData f; + Keyboard::KeyboardCallbackList::CallbackData f; f = data; - prev->next = new KeyboardCallbackList(f, type); + prev->next = new Keyboard::KeyboardCallbackList(f, type); } -void Keyboard::RemoveFromList(KeyboardCallbackList* first, KeyboardCallbackList::CallbackData data) +void RemoveFromList(Keyboard::KeyboardCallbackList* first, Keyboard::KeyboardCallbackList::CallbackData data) { - KeyboardCallbackList *w = first; - KeyboardCallbackList *prev = first; + Keyboard::KeyboardCallbackList *w = first; + Keyboard::KeyboardCallbackList *prev = first; while (w) { if(data == w->function) { - KeyboardCallbackList *removee = w; + Keyboard::KeyboardCallbackList *removee = w; w = w->next; prev->next = w; delete removee; @@ -51,9 +74,9 @@ void Keyboard::RemoveFromList(KeyboardCallbackList* first, KeyboardCallbackList: w = w->next; } } -bool Keyboard::ExistsInList(KeyboardCallbackList* first, KeyboardCallbackList::CallbackData data) +bool ExistsInList(Keyboard::KeyboardCallbackList* first, Keyboard::KeyboardCallbackList::CallbackData data) { - KeyboardCallbackList *w = first; + Keyboard::KeyboardCallbackList *w = first; while (w) { if(data == w->function) @@ -64,7 +87,7 @@ bool Keyboard::ExistsInList(KeyboardCallbackList* first, KeyboardCallbackList::C } return true; } -bool Keyboard::ExistsInList(std::vector& list, KeyboardEvent* data) +bool ExistsInList(std::vector& list, Keyboard::KeyboardEvent* data) { for (unsigned int i = 0; i < list.size(); i++) { @@ -74,15 +97,76 @@ bool Keyboard::ExistsInList(std::vector& list, KeyboardEvent* da return false; } + + + Keyboard::Keyboard() : InputObject(SAIType_Keyboard) , callbackList(0) + , active(1) + , textTarget(0) + , writePos(0) {} Keyboard::~Keyboard() { } +void Keyboard::InternalOnKeyPress(Enum::SAKI key, wchar_t text[16]) +{ + for (unsigned int i = 0; i < this->keyEventSubscrivers.size(); i++) + { + if(this->keyEventSubscrivers[i]) + { + this->keyEventSubscrivers[i]->OnKeyPress(key, GetAsText(key), this); + } + } + KeyboardCallbackList *w = this->callbackList; + while (w) + { + if(w->function) + if (w->type == KeyboardCallbackList::CallbackDataType_OnPress) + w->function.keyPressCallback(key, GetAsText(key), this); + w = w->next; + } +} +void Keyboard::InternalOnKeyDown(Enum::SAKI key, wchar_t text[16]) +{ + for (unsigned int i = 0; i < this->keyEventSubscrivers.size(); i++) + { + if(this->keyEventSubscrivers[i]) + { + this->keyEventSubscrivers[i]->OnKeyDown(key, GetAsText(key), this); + } + } + KeyboardCallbackList *w = this->callbackList; + while (w) + { + if(w->function) + if (w->type == KeyboardCallbackList::CallbackDataType_OnDown) + w->function.keyDownCallback(key, GetAsText(key), this); + w = w->next; + } +} +void Keyboard::InternalOnKeyRelease(Enum::SAKI key, wchar_t text[16]) +{ + for (unsigned int i = 0; i < this->keyEventSubscrivers.size(); i++) + { + if(this->keyEventSubscrivers[i]) + { + this->keyEventSubscrivers[i]->OnKeyRelease(key, GetAsText(key), this); + } + } + KeyboardCallbackList *w = this->callbackList; + while (w) + { + if(w->function) + if (w->type == KeyboardCallbackList::CallbackDataType_OnRelease) + w->function.keyReleaseCallback(key, GetAsText(key), this); + w = w->next; + } +} + void Keyboard::AddOnKeyPressCallback (OnKeyPressCallback func) { KeyboardCallbackList::CallbackData d; @@ -134,3 +218,17 @@ void Keyboard::operator-= (KeyboardEvent* object) } } +void Keyboard::BindTextTarget( ::std::wstring *field ) +{ + this->textTarget = field; + + if( field ) + { + this->writePos = field->size(); + } +} +void Keyboard::ReleaseTextTarget( ) +{ + this->BindTextTarget( nullptr ); +} + diff --git a/Code/Misc/Input/Source/Mouse.cpp b/Code/Misc/Input/Source/Mouse.cpp index de1cf26f..103e1342 100644 --- a/Code/Misc/Input/Source/Mouse.cpp +++ b/Code/Misc/Input/Source/Mouse.cpp @@ -9,11 +9,39 @@ using namespace Input::Enum; using namespace Input::Struct; using namespace Input::Typedefs; - -void Mouse::ClearList(Mouse::MouseCallbackList* first) +struct Mouse::MouseCallbackList { - MouseCallbackList* w = first; - MouseCallbackList* removee = 0; + enum CallbackDataType + { + CallbackDataType_OnPress, + CallbackDataType_OnDown, + CallbackDataType_OnRelease, + CallbackDataType_OnMove, + CallbackDataType_OnScroll, + } type; + union CallbackData + { + Typedefs::OnMousePressCallback mousePressCallback; + Typedefs::OnMouseDownCallback mouseDownCallback; + Typedefs::OnMouseReleaseCallback mouseReleaseCallback; + Typedefs::OnMouseMoveCallback mouseMoveCallback; + Typedefs::OnMouseScrollCallback mouseScrollCallback; + void* dummy; + + CallbackData (){ memset(this, 0, sizeof(CallbackData)); } + CallbackData (void* d){ dummy = d; } + bool operator ==(CallbackData o){ return o.dummy == dummy; } + bool operator ==(void* o ){ return o == dummy; } + operator bool(){ return this->dummy != 0; } + } function; + MouseCallbackList *next; + MouseCallbackList(CallbackData func, CallbackDataType t) :function(func), next(0), type(t) { } +}; + +void ClearList(Mouse::MouseCallbackList* first) +{ + Mouse::MouseCallbackList* w = first; + Mouse::MouseCallbackList* removee = 0; while (w) { @@ -22,27 +50,27 @@ void Mouse::ClearList(Mouse::MouseCallbackList* first) delete removee; } } -void Mouse::AddToList(Mouse::MouseCallbackList* first, MouseCallbackList::CallbackData data, MouseCallbackList::CallbackDataType type) +void AddToList(Mouse::MouseCallbackList* first, Mouse::MouseCallbackList::CallbackData data, Mouse::MouseCallbackList::CallbackDataType type) { - MouseCallbackList *w = first; - MouseCallbackList *prev = first; + Mouse::MouseCallbackList *w = first; + Mouse::MouseCallbackList *prev = first; while (w) { prev = w; w = w->next; } - MouseCallbackList::CallbackData f; + Mouse::MouseCallbackList::CallbackData f; f = data; - prev->next = new MouseCallbackList(f, type); + prev->next = new Mouse::MouseCallbackList(f, type); } -void Mouse::RemoveFromList(MouseCallbackList* first, MouseCallbackList::CallbackData data) +void RemoveFromList(Mouse::MouseCallbackList* first, Mouse::MouseCallbackList::CallbackData data) { - MouseCallbackList *w = first; - MouseCallbackList *prev = first; + Mouse::MouseCallbackList *w = first; + Mouse::MouseCallbackList *prev = first; while (w) { if(data == w->function) { - MouseCallbackList *removee = w; + Mouse::MouseCallbackList *removee = w; w = w->next; prev->next = w; delete removee; @@ -52,9 +80,9 @@ void Mouse::RemoveFromList(MouseCallbackList* first, MouseCallbackList::Callback w = w->next; } } -bool Mouse::ExistsInList(MouseCallbackList* first, MouseCallbackList::CallbackData data) +bool ExistsInList(Mouse::MouseCallbackList* first, Mouse::MouseCallbackList::CallbackData data) { - MouseCallbackList *w = first; + Mouse::MouseCallbackList *w = first; while (w) { if(data == w->function) @@ -65,7 +93,7 @@ bool Mouse::ExistsInList(MouseCallbackList* first, MouseCallbackList::CallbackDa } return true; } -bool Mouse::ExistsInList(std::vector& list, MouseEvent* data) +bool ExistsInList(std::vector& list, Mouse::MouseEvent* data) { for (unsigned int i = 0; i < list.size(); i++) { @@ -81,7 +109,7 @@ Mouse::Mouse() , wheelDelta(0) , isCurorLocked(0) , pixelPos() - , normalPos() + , deltaPos() { } Mouse::~Mouse() @@ -89,6 +117,106 @@ Mouse::~Mouse() } +void Mouse::InternalOnBtnPress(Enum::SAMI btn) +{ + for (unsigned int i = 0; i < this->mouseSubscribers.size(); i++) + { + if(this->mouseSubscribers[i]) + this->mouseSubscribers[i]->OnMousePress(btn, this); + } + MouseCallbackList *w = this->callbackList; + while (w) + { + if(w->function) + if (w->type == MouseCallbackList::CallbackDataType_OnPress) + w->function.mousePressCallback(btn, this); + w = w->next; + } +} +void Mouse::InternalOnBtnDown(Enum::SAMI btn) +{ + for (unsigned int i = 0; i < this->mouseSubscribers.size(); i++) + { + if(this->mouseSubscribers[i]) + this->mouseSubscribers[i]->OnMouseDown(btn, this); + } + MouseCallbackList *w = this->callbackList; + while (w) + { + if(w->function) + if (w->type == MouseCallbackList::CallbackDataType_OnDown) + w->function.mouseDownCallback(btn, this); + w = w->next; + } +} +void Mouse::InternalOnBtnRelease(Enum::SAMI btn) +{ + for (unsigned int i = 0; i < this->mouseSubscribers.size(); i++) + { + if(this->mouseSubscribers[i]) + this->mouseSubscribers[i]->OnMouseRelease(btn, this); + } + MouseCallbackList *w = this->callbackList; + while (w) + { + if(w->function) + if (w->type == MouseCallbackList::CallbackDataType_OnRelease) + w->function.mouseReleaseCallback(btn, this); + w = w->next; + } +} +void Mouse::InternalOnMove(Struct::SAIPoint2D cord) +{ + for (unsigned int i = 0; i < this->mouseSubscribers.size(); i++) + { + if(this->mouseSubscribers[i]) + this->mouseSubscribers[i]->OnMouseMove(this->pixelPos, this); + } + MouseCallbackList *w = this->callbackList; + while (w) + { + if(w->function) + if (w->type == MouseCallbackList::CallbackDataType_OnMove) + w->function.mouseMoveCallback(this->pixelPos, this); + w = w->next; + } +} +void Mouse::InternalOnScroll(int delta) +{ + for (unsigned int i = 0; i < this->mouseSubscribers.size(); i++) + { + if(this->mouseSubscribers[i]) + this->mouseSubscribers[i]->OnMouseScroll(delta, this); + } + MouseCallbackList *w = this->callbackList; + while (w) + { + if(w->function) + if (w->type == MouseCallbackList::CallbackDataType_OnMove) + w->function.mouseScrollCallback(delta, this); + w = w->next; + } +} + + + +int Mouse::GetWheelDelta() const +{ + return this->wheelDelta; +} +SAIPoint2D & Mouse::GetPixelPosition( Struct::SAIPoint2D &targetMem ) const +{ + targetMem.x = this->pixelPos.x; + targetMem.y = this->pixelPos.y; + return targetMem; +} +SAIPoint2D & Mouse::GetDeltaPosition( Struct::SAIPoint2D &targetMem ) const +{ + targetMem.x = this->deltaPos.x; + targetMem.y = this->deltaPos.y; + return targetMem; +} + void Mouse::AddOnMousePressCallback( Typedefs::OnMousePressCallback func) { MouseCallbackList::CallbackData d; @@ -150,8 +278,6 @@ void Mouse::SetPixelPos(int x, int y) { this->pixelPos.x = x; this->pixelPos.y = y; - - // TODO: Update normalized position } void Mouse::ToggleCursor(bool toggler) { diff --git a/Code/Misc/Input/Source/Win32/Win32Input.cpp b/Code/Misc/Input/Source/Win32/Win32Input.cpp index edf85729..118e32ea 100644 --- a/Code/Misc/Input/Source/Win32/Win32Input.cpp +++ b/Code/Misc/Input/Source/Win32/Win32Input.cpp @@ -16,608 +16,17 @@ using namespace Input::Enum; using namespace Input::Struct; using namespace Input::Typedefs; -/* -bool Win32Input::Input_AddDevice(IN const HWND& targetApplication) -{ - assert(targetApplication != 0); - static const UINT c = 2; - RAWINPUTDEVICE devices[c] = - { - { 0x01, RawInput_Usage_keyboard, RIDEV_NOLEGACY, targetApplication }, - { 0x01, RawInput_Usage_mouse, RIDEV_NOLEGACY | RIDEV_CAPTUREMOUSE, targetApplication } - }; - - if(! _addDevice( devices , c ) ) return false; - - ShowCursor(FALSE); - //RECT r; - //GetWindow - //GetWindowRect( - - return true; -} -bool Win32Input::Input_AddDevice(IN const RAWINPUTDEVICE* d, const int& count) -{ - for (int i = 0; i < count; i++) - if(!d[i].hwndTarget) - { - this->_errorMsg = L"Must specify target application"; - return false; - } - if(! _addDevice( d, count ) ) return false; - - return true; -} - -//Win32InputDEVICE d = { 0x01, type, RIDEV_REMOVE, NULL }; -//this->_errorMsg = L"Failed to unregister device"; - - -void Win32Input::Input_Disable() -{ - this->_enabled = false; -} -void Win32Input::Input_Enable() -{ - this->_enabled = true; -} - -void Win32Input::Input_Read() -{ - //for (int i = 0; i < this->_idleKeyData.size(); i++) - // this->_proccessRawKeyboardData(this->_idleKeyData.pop()); - //for (int i = 0; i < this->_idleMouseData.size(); i++) - // this->_proccessRawMouseData(this->_idleMouseData.pop()); - // - //this->_idleKeyData.clear(); - //this->_idleMouseData.clear(); -} - - -bool Win32Input::_addDevice (const RAWINPUTDEVICE* k, const int& count) -{ - if(RegisterRawInputDevices(k, count, sizeof(RAWINPUTDEVICE)) == FALSE) - { - DWORD h = GetLastError(); - INPUT_EXCEPT( L"Failed to register device" ); - return false; - } - - for (int q = 0; q < count; q++) - { - RawInputDeviceInstance i; - memcpy(&i.description, &k[q], sizeof(RAWINPUTDEVICE)); - this->_deviceList.push(i); - } - - return true; -} -*/ Win32Input *Win32Input::instance = 0; -void MapKey(RAWKEYBOARD& rawKB, bool& out_isUp, SAKI& out_key, unsigned int& sCode, bool& isE0) -{ - //------------------------------------------------------------------------------------// - // http://molecularmusings.wordpress.com/2011/09/05/properly-handling-keyboard-input/ // - //------------------------------------------------------------------------------------// - - UINT virtualKey = rawKB.VKey; - UINT scanCode = rawKB.MakeCode; - UINT flags = rawKB.Flags; - - if (virtualKey == 255) - { - // discard "fake keys" which are part of an escaped sequence - return; - } - else if (virtualKey == VK_SHIFT) - { - // correct left-hand / right-hand SHIFT - virtualKey = MapVirtualKey(scanCode, MAPVK_VSC_TO_VK_EX); - } - else if (virtualKey == VK_NUMLOCK) - { - // correct PAUSE/BREAK and NUM LOCK silliness, and set the extended bit - scanCode = (MapVirtualKey(virtualKey, MAPVK_VK_TO_VSC) | 0x100); - } - - // e0 and e1 are escape sequences used for certain special keys, such as PRINT and PAUSE/BREAK. - // see http://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html - isE0 = ((flags & RI_KEY_E0) != 0); - const bool isE1 = ((flags & RI_KEY_E1) != 0); - - if (isE1) - { - // for escaped sequences, turn the virtual key into the correct scan code using MapVirtualKey. - // however, MapVirtualKey is unable to map VK_PAUSE (this is a known bug), hence we map that by hand. - if (virtualKey == VK_PAUSE) scanCode = 0x45; - else scanCode = MapVirtualKey(virtualKey, MAPVK_VK_TO_VSC); - } - - switch (virtualKey) - { - // right-hand CONTROL and ALT have their e0 bit set - case VK_CONTROL: - if (isE0) out_key = SAKI_RightCtrl; - else out_key = SAKI_LeftCtrl; - break; - - case VK_MENU: - if (isE0) out_key = SAKI_RightAlt; - else out_key = SAKI_LeftAlt; - break; - - // NUMPAD ENTER has its e0 bit set - case VK_RETURN: - if (isE0) out_key = SAKI_NumpadEnter; - break; - - // the standard INSERT, DELETE, HOME, END, PRIOR and NEXT keys will always have their e0 bit set, but the - // corresponding keys on the NUMPAD will not. - case VK_INSERT: - if (!isE0) out_key = SAKI_Numpad0; - break; - - case VK_DELETE: - if (!isE0) out_key = SAKI_NumpadDecimal; - break; - - case VK_HOME: - if (!isE0) out_key = SAKI_Numpad7; - break; - - case VK_END: - if (!isE0) out_key = SAKI_Numpad1; - break; - - case VK_PRIOR: - if (!isE0) out_key = SAKI_Numpad9; - break; - - case VK_NEXT: - if (!isE0) out_key = SAKI_Numpad3; - break; - - // the standard arrow keys will always have their e0 bit set, but the - // corresponding keys on the NUMPAD will not. - case VK_LEFT: - if (!isE0) out_key = SAKI_Numpad4; - break; - - case VK_RIGHT: - if (!isE0) out_key = SAKI_Numpad6; - break; - - case VK_UP: - if (!isE0) out_key = SAKI_Numpad8; - break; - - case VK_DOWN: - if (!isE0) out_key = SAKI_Numpad2; - break; - - // NUMPAD 5 doesn't have its e0 bit set - case VK_CLEAR: - if (!isE0) out_key = SAKI_Numpad5; - break; - case 0x03 : //VK_CANCEL - break; - case 0x08 : //VK_BACK - out_key = SAKI_Backspace; - break; - case 0x09 : //VK_TAB - out_key = SAKI_Tab; - break; - case 0x10 : //VK_SHIFT - out_key = SAKI_LeftShift; - out_key = SAKI_RightShift; - break; - case 0x13 : //VK_PAUSE - out_key = SAKI_Pause; - break; - case 0x14 : //VK_CAPITAL - out_key = SAKI_CapsLock; - break; - case 0x15 : //VK_KANA - break; - case 0x1B : //VK_ESCAPE - out_key = SAKI_Escape; - break; - case 0x1C : //VK_CONVERT - break; - case 0x1D : //VK_NONCONVERT - break; - case 0x1E : //VK_ACCEPT - break; - case 0x1F : //VK_MODECHANGE - break; - case 0x20 : //VK_SPACE - out_key = SAKI_Space; - break; - case 0x29 : //VK_SELECT - break; - case 0x2A : //VK_PRINT - out_key = SAKI_PrintScreen; - break; - case 0x2B : //VK_EXECUTE - break; - case 0x2C : //VK_SNAPSHOT - break; - case 0x2F : //VK_HELP - break; - case 0x30 : //0 key - out_key = SAKI_0; - break; - case 0x31 : //1 key - out_key = SAKI_1; - break; - case 0x32 : //2 key - out_key = SAKI_2; - break; - case 0x33 : //3 key - out_key = SAKI_3; - break; - case 0x34 : //4 key - out_key = SAKI_4; - break; - case 0x35 : //5 key - out_key = SAKI_5; - break; - case 0x36 : //6 key - out_key = SAKI_6; - break; - case 0x37 : //7 key - out_key = SAKI_7; - break; - case 0x38 : //8 key - out_key = SAKI_8; - break; - case 0x39 : //9 key - out_key = SAKI_9; - break; - case 0x41 : //A key - out_key = SAKI_A; - break; - case 0x42 : //B key - out_key = SAKI_B; - break; - case 0x43 : //C key - out_key = SAKI_C; - break; - case 0x44 : //D key - out_key = SAKI_D; - break; - case 0x45 : //E key - out_key = SAKI_E; - break; - case 0x46 : //F key - out_key = SAKI_F; - break; - case 0x47 : //G key - out_key = SAKI_G; - break; - case 0x48 : //H key - out_key = SAKI_H; - break; - case 0x49 : //I key - out_key = SAKI_I; - break; - case 0x4A : //J key - out_key = SAKI_J; - break; - case 0x4B : //K key - out_key = SAKI_K; - break; - case 0x4C : //L key - out_key = SAKI_L; - break; - case 0x4D : //M key - out_key = SAKI_M; - break; - case 0x4E : //N key - out_key = SAKI_N; - break; - case 0x4F : //O key - out_key = SAKI_O; - break; - case 0x50 : //P key - out_key = SAKI_P; - break; - case 0x51 : //Q key - out_key = SAKI_Q; - break; - case 0x52 : //R key - out_key = SAKI_R; - break; - case 0x53 : //S key - out_key = SAKI_S; - break; - case 0x54 : //T key - out_key = SAKI_T; - break; - case 0x55 : //U key - out_key = SAKI_U; - break; - case 0x56 : //V key - out_key = SAKI_V; - break; - case 0x57 : //W key - out_key = SAKI_W; - break; - case 0x58 : //X key - out_key = SAKI_X; - break; - case 0x59 : //Y key - out_key = SAKI_Y; - break; - case 0x5A : //Z key - out_key = SAKI_Z; - break; - case 0x5B : //VK_LWIN - break; - case 0x5C : //VK_RWIN - break; - case 0x5D : //VK_APPS - break; - case 0x5F : //VK_SLEEP - break; - case 0x60 : //VK_NUMPAD0 - out_key = SAKI_Numpad0; - break; - case 0x61 : //VK_NUMPAD1 - out_key = SAKI_Numpad1; - break; - case 0x62 : //VK_NUMPAD2 - out_key = SAKI_Numpad2; - break; - case 0x63 : //VK_NUMPAD3 - out_key = SAKI_Numpad3; - break; - case 0x64 : //VK_NUMPAD4 - out_key = SAKI_Numpad4; - break; - case 0x65 : //VK_NUMPAD5 - out_key = SAKI_Numpad5; - break; - case 0x66 : //VK_NUMPAD6 - out_key = SAKI_Numpad6; - break; - case 0x67 : //VK_NUMPAD7 - out_key = SAKI_Numpad7; - break; - case 0x68 : //VK_NUMPAD8 - out_key = SAKI_Numpad8; - break; - case 0x69 : //VK_NUMPAD9 - out_key = SAKI_Numpad9; - break; - case 0x6A : //VK_MULTIPLY - out_key = SAKI_NumpadMultiply; - break; - case 0x6B : //VK_ADD - out_key = SAKI_NumpadPlus; - break; - case 0x6C : //VK_SEPARATOR - break; - case 0x6D : //VK_SUBTRACT - out_key = SAKI_NumpadSubtract; - break; - case 0x6E : //VK_DECIMAL - out_key = SAKI_NumpadDecimal; - break; - case 0x6F : //VK_DIVIDE - out_key = SAKI_NumpadDivide; - break; - case 0x70 : //VK_F1 - out_key = SAKI_F1; - break; - case 0x71 : //VK_F2 - out_key = SAKI_F2; - break; - case 0x72 : //VK_F3 - out_key = SAKI_F3; - break; - case 0x73 : //VK_F4 - out_key = SAKI_F4; - break; - case 0x74 : //VK_F5 - out_key = SAKI_F5; - break; - case 0x75 : //VK_F6 - out_key = SAKI_F6; - break; - case 0x76 : //VK_F7 - out_key = SAKI_F7; - break; - case 0x77 : //VK_F8 - out_key = SAKI_F8; - break; - case 0x78 : //VK_F9 - out_key = SAKI_F9; - break; - case 0x79 : //VK_F10 - out_key = SAKI_F10; - break; - case 0x7A : //VK_F11 - out_key = SAKI_F11; - break; - case 0x7B : //VK_F12 - out_key = SAKI_F12; - break; - case 0x7C : //VK_F13 - out_key = SAKI_F13; - break; - case 0x7D : //VK_F14 - out_key = SAKI_F14; - break; - case 0x7E : //VK_F15 - out_key = SAKI_F15; - break; - case 0x7F : //VK_F16 - out_key = SAKI_F16; - break; - case 0x80 : //VK_F17 - out_key = SAKI_F17; - break; - case 0x81 : //VK_F18 - out_key = SAKI_F18; - break; - case 0x82 : //VK_F19 - out_key = SAKI_F19; - break; - case 0x83 : //VK_F20 - out_key = SAKI_F20; - break; - case 0x84 : //VK_F21 - out_key = SAKI_F21; - break; - case 0x85 : //VK_F22 - out_key = SAKI_F22; - break; - case 0x86 : //VK_F23 - out_key = SAKI_F23; - break; - case 0x87 : //VK_F24 - out_key = SAKI_F24; - break; - case 0x90 : //VK_NUMLOCK - out_key = SAKI_Numlock; - break; - case 0x91 : //VK_SCROLL - out_key = SAKI_ScrlLock; - break; - case 0xA0 : //VK_LSHIFT - out_key = SAKI_LeftShift; - break; - case 0xA1 : //VK_RSHIFT - out_key = SAKI_RightShift; - break; - case 0xA2 : //VK_LCONTROL - out_key = SAKI_LeftCtrl; - break; - case 0xA3 : //VK_RCONTROL - out_key = SAKI_RightCtrl; - break; - case 0xA4 : //VK_LMENU - out_key = SAKI_LeftAlt; - break; - case 0xA5 : //VK_RMENU - out_key = SAKI_RightCtrl; - break; - case 0xAD : //VK_VOLUME_MUTE - out_key = SAKI_VolumeMute; - break; - case 0xAE : //VK_VOLUME_DOWN - out_key = SAKI_VolumeDown; - break; - case 0xAF : //VK_VOLUME_UP - out_key = SAKI_VolumeUp; - break; - case 0xB0 : //VK_MEDIA_NEXT_TRACK - out_key = SAKI_MediaNext; - break; - case 0xB1 : //VK_MEDIA_PREV_TRACK - out_key = SAKI_MediaPrev; - break; - case 0xB2 : //VK_MEDIA_STOP - out_key = SAKI_MediaStop; - break; - case 0xB3 : //VK_MEDIA_PLAY_PAUSE - out_key = SAKI_MediaPlayPause; - break; - - case 0xBB://VK_OEM_PLUS - break; - case 0xBC://VK_OEM_COMMA - break; - case 0xBD://VK_OEM_MINUS - break; - case 0xBE://VK_OEM_PERIOD - break; - case 0xBA://VK_OEM_1 - break; - case 0xBF://VK_OEM_2 - break; - case 0xC0://VK_OEM_3 - break; - case 0xDB://VK_OEM_4 - break; - case 0xDC://VK_OEM_5 - break; - case 0xDD://VK_OEM_6 - break; - case 0xDE://VK_OEM_7 - break; - case 0xDF://VK_OEM_8 - break; - } - - out_isUp = ((flags & RI_KEY_BREAK) != 0); - rawKB.MakeCode = scanCode; - sCode = scanCode; -} -void MapButton(RAWMOUSE& rawMouse, bool &isUp, Enum::SAMI& btn, int& delta, Struct::SAIPointInt2D& vel, unsigned int& mcode) -{ - if(rawMouse.lLastX != 0 || rawMouse.lLastY != 0) - { - vel.x = rawMouse.lLastX; - vel.y = rawMouse.lLastY; - } - if( rawMouse.usButtonFlags > 0 ) - { -//-------------------------------------------------------------------------------------- - //Mouse button pressed - if(rawMouse.usButtonFlags == RI_MOUSE_LEFT_BUTTON_DOWN) - { - btn = SAMI_MouseLeftBtn; - isUp = false; - } - else if(rawMouse.usButtonFlags == RI_MOUSE_MIDDLE_BUTTON_DOWN) - { - btn = SAMI_MouseMiddleBtn; - isUp = false; - } - else if(rawMouse.usButtonFlags == RI_MOUSE_RIGHT_BUTTON_DOWN) - { - btn = SAMI_MouseRightBtn; - isUp = false; - } -//-------------------------------------------------------------------------------------- - //Mouse button Released - else if(rawMouse.usButtonFlags == RI_MOUSE_LEFT_BUTTON_UP) - { - btn = SAMI_MouseLeftBtn; - isUp = true; - } - else if(rawMouse.usButtonFlags == RI_MOUSE_MIDDLE_BUTTON_UP) - { - btn = SAMI_MouseMiddleBtn; - isUp = true; - } - else if(rawMouse.usButtonFlags == RI_MOUSE_RIGHT_BUTTON_UP) - { - btn = SAMI_MouseRightBtn; - isUp = true; - } -//-------------------------------------------------------------------------------------- - else if (rawMouse.usButtonFlags == RI_MOUSE_WHEEL) - { - delta = ((int)rawMouse.usButtonData); - - if(delta > 120) delta = -1; - else delta = 1; - } - } -} -void Win32Input::RawInputParser(HWND h, LPARAM l) + +LRESULT Win32Input::RawInputParser(HWND h, LPARAM l) { + LRESULT val = 0; //Get The size of the raw data buffer UINT bufferSize; GetRawInputData((HRAWINPUT)l, RID_INPUT, NULL, &bufferSize, sizeof(RAWINPUTHEADER)); if (bufferSize < 1) - { - return; - } + { return 0; } //Create and read the raw input data LPBYTE rawBufferIn = new BYTE[bufferSize]; @@ -625,58 +34,69 @@ void Win32Input::RawInputParser(HWND h, LPARAM l) if ( readBytes != bufferSize ) { delete [] rawBufferIn; - return; + return 0; } RAWINPUT* raw = (RAWINPUT*)rawBufferIn; - if(!Win32Input::instance->enabled) { - if(FAILED ( DefRawInputProc(&raw, 1, sizeof(RAWINPUTHEADER)) ) ) - { - - } + val = DefRawInputProc(&raw, 1, sizeof(RAWINPUTHEADER)); } else { if(raw->header.dwType == RIM_TYPEMOUSE) { + bool once = false; for (unsigned int i = 0; i < Win32Input::instance->mouse.size(); i++) { - bool isUp = true; - Enum::SAMI btn = Enum::SAMI_Unknown; - int delta = 0; - Struct::SAIPointInt2D vel; - unsigned int mcode = 0; - MapButton(raw->data.mouse, isUp, btn, delta, vel, mcode); - - Win32Input::instance->mouse[i]->ProccessMouseData(isUp, btn, delta, vel, mcode); + if(Win32Input::instance->mouse[i]->IsActive()) + { + Win32Input::instance->mouse[i]->ProccessMouseData(raw->data.mouse); + } + else + { + if(!once) val = DefRawInputProc(&raw, 1, sizeof(RAWINPUTHEADER)); + } } } else if(raw->header.dwType == RIM_TYPEKEYBOARD) { + bool once = false; for (unsigned int i = 0; i < Win32Input::instance->keyboard.size(); i++) { - bool isUp; - SAKI key = SAKI_Unknown; - unsigned int makeCode; - bool isE0; - MapKey(raw->data.keyboard, isUp, key, makeCode, isE0); - Win32Input::instance->keyboard[i]->ProccessKeyboardData(isUp, key, makeCode, isE0); + if(Win32Input::instance->keyboard[i]->IsActive()) + { + Win32Input::instance->keyboard[i]->ProccessKeyboardData(raw->data.keyboard); + } + else + { + if(!once) val = DefRawInputProc(&raw, 1, sizeof(RAWINPUTHEADER)); + } } } } delete raw; + return val; } LRESULT CALLBACK Win32Input::RawWindowCallback(HWND h, UINT m, WPARAM w, LPARAM l) { + LRESULT val = 0; switch (m) { case WM_INPUT: - Win32Input::instance->RawInputParser(h, l); + return Win32Input::instance->RawInputParser(h, l); break; + + case WM_KEYDOWN: + val = 0; + break; + + case WM_CHAR: + val = 0; + break; + case WM_ACTIVATE: Win32Input::instance->WindowActivate((w == TRUE)); break; @@ -702,6 +122,7 @@ void Win32Input::WindowActivate(bool activate) Win32Input::Win32Input() { + this->targetHwin = 0; if(!this->instance) { this->instance = this; @@ -759,21 +180,27 @@ InputObject* Win32Input::CreateDevice(const SAIType inputType, Typedefs::WindowH case SAIType_Mouse: { - Win32Mouse* obj = new Win32Mouse(); - if(!obj->Create(this->targetHwin)) + rid.usUsage = RawInput_Usage_mouse; + rid.dwFlags = RIDEV_NOLEGACY | RIDEV_CAPTUREMOUSE; + if(RegisterRawInputDevices(&rid, 1, sizeof(RAWINPUTDEVICE)) == TRUE) + { + int i = 0; + val = (InputObject*)1; + Win32Mouse* obj = new Win32Mouse(); + this->mouse.push_back(obj); + val = obj; + } + else { - delete obj; return 0; } - - this->mouse.push_back(obj); - val = obj; } break; } return val; } + void Win32Input::ToggleInputSystem(bool enable) { this->enabled = enable; @@ -797,52 +224,3 @@ void Win32Input::Destroy () this->keyboard.resize(0); } - -/* This method is used with hooks! - -LRESULT CALLBACK RawInput::WM_INPUT_TRANSLATE (int nCode, WPARAM wParam, LPARAM lparam) -{ - if (nCode < 0) return CallNextHookEx(RawInput::Self()->_msgHook, nCode, wParam, lparam); - - - MSG *m = (MSG*)lparam; - - if(m->message == WM_INPUT) - { - RAWINPUT* raw = RawInput::Self()->_TranslateRawInput(m->lParam); - - if(!raw) goto nextHook; - if(!RawInput::Self()->Self()->_enabled) - { - if(FAILED ( DefRawInputProc(&raw, 1, sizeof(RAWINPUTHEADER)) ) ) - RawInput::Self()->_errorMsg = L"Failed to proccess default raw input"; - goto _final; - } - // if(raw->header.dwType == RIM_TYPEMOUSE) RawInput::Self()->_idleMouseData.insert(raw->data.mouse); - //else if(raw->header.dwType == RIM_TYPEKEYBOARD) RawInput::Self()->_proccessRawKeyboardData(raw->data.keyboard); - - - _final: - - //if(FAILED ( DefRawInputProc(&raw, 1, sizeof(RAWINPUTHEADER)) ) ) - // RawInput::Self()->_errorMsg = L"Failed to proccess default raw input"; - - delete raw; - } - else if (m->message == WM_QUIT) - { - if(UnhookWindowsHookEx(RawInput::Self()->_msgHook) == FALSE) - { - RawInput::Self()->_errorMsg = L"Failed to unhook message hook!"; - } - } - - - nextHook: - return CallNextHookEx(RawInput::Self()->_msgHook, nCode, wParam, lparam); -} -*/ - - - - diff --git a/Code/Misc/Input/Source/Win32/Win32Keyboard.cpp b/Code/Misc/Input/Source/Win32/Win32Keyboard.cpp index 771f4134..e587f5c8 100644 --- a/Code/Misc/Input/Source/Win32/Win32Keyboard.cpp +++ b/Code/Misc/Input/Source/Win32/Win32Keyboard.cpp @@ -2,10 +2,13 @@ // Created by [Dennis Andersen] [2013] ///////////////////////////////////////////////////////////////////// #include "..\..\Include\Win32\Win32Keyboard.h" +#include #pragma warning ( disable : 4172 ) using namespace Input; using namespace Input::Enum; +using namespace std; + Win32Keyboard::Win32Keyboard() { @@ -24,115 +27,620 @@ bool Win32Keyboard::IsKeyDown (SAKI key) { return this->keys[key].isDown; } -const wchar_t* Win32Keyboard::GetAsText(Enum::SAKI key) +wchar_t* Win32Keyboard::GetAsText(Enum::SAKI key) { if(Enum::SAKI_Unknown == key) return 0; // getting a human-readable string UINT temp = (this->keys[key].makecode << 16) | (this->keys[key].isE0 << 24); - wchar_t buff[56] = {0}; - GetKeyNameTextW((LONG)temp, buff, 64); + wchar_t buff[16] = {0}; + GetKeyNameTextW((LONG)temp, buff, 16); return buff; } -void Win32Keyboard::ProccessKeyboardData (bool isUp, SAKI key, unsigned int makeCode, bool isE0) +void Win32Keyboard::ProccessKeyboardData (RAWKEYBOARD keyboard) { - if(key == SAKI_Unknown) return; - //The key is released. - if(isUp)/*(k.Flags == RI_KEY_BREAK || k.Flags == (RI_KEY_BREAK | RI_KEY_E0) || k.Flags == (RI_KEY_BREAK | RI_KEY_E1))*/ + if(!this->active) { - if(key == SAKI_LeftAlt) - { } - else if(key == SAKI_LeftCtrl) - {} - else if(key == SAKI_LeftShift) - {} - else if(key == SAKI_RightAlt) - {} - else if(key == SAKI_RightCtrl) - {} - else if(key == SAKI_RightShift) - {} - else + return; + } + + bool isUp = (( keyboard.Flags & RI_KEY_BREAK) != 0); + SAKI key = SAKI_Unknown; + bool isE0; + + MapKey(keyboard, key, isE0); + + if(key != SAKI_Unknown) + { + //The key is released. + if(isUp)/*(k.Flags == RI_KEY_BREAK || k.Flags == (RI_KEY_BREAK | RI_KEY_E0) || k.Flags == (RI_KEY_BREAK | RI_KEY_E1))*/ { + InternalOnKeyRelease(key, L""); this->keys[key].isDown = false; this->keys[key].isE0 = isE0; - this->keys[key].makecode = makeCode; - for (unsigned int i = 0; i < this->keyEventSubscrivers.size(); i++) - { - if(this->keyEventSubscrivers[i]) - { - this->keyEventSubscrivers[i]->OnKeyRelease(key, GetAsText(key), this); - } - } - KeyboardCallbackList *w = this->callbackList; - while (w) - { - if(w->function) - if (w->type == KeyboardCallbackList::CallbackDataType_OnRelease) - w->function.keyReleaseCallback(key, GetAsText(key), this); - w = w->next; - } + this->keys[key].makecode = keyboard.MakeCode; } - - //this->_procCollection.kd.key = (RIK)k.VKey; - //this->_procCollection.kd.released = true; - } - //The key is pressed. - else /*if (k.Flags == RI_KEY_MAKE || k.Flags == (RI_KEY_MAKE | RI_KEY_E0) || k.Flags == (RI_KEY_MAKE | RI_KEY_E1))*/ - { - if(key == SAKI_LeftAlt) - {} - else if(key == SAKI_LeftCtrl) - {} - else if(key == SAKI_LeftShift) - {} - else if(key == SAKI_RightAlt) - {} - else if(key == SAKI_RightCtrl) - {} - else if(key == SAKI_RightShift) - {} - else + //The key is pressed. + else /*if (k.Flags == RI_KEY_MAKE || k.Flags == (RI_KEY_MAKE | RI_KEY_E0) || k.Flags == (RI_KEY_MAKE | RI_KEY_E1))*/ { if(this->keys[key].isDown) { - for (unsigned int i = 0; i < this->keyEventSubscrivers.size(); i++) - { - if(this->keyEventSubscrivers[i]) - { - this->keyEventSubscrivers[i]->OnKeyDown(key, GetAsText(key), this); - } - } - KeyboardCallbackList *w = this->callbackList; - while (w) - { - if(w->function) - if (w->type == KeyboardCallbackList::CallbackDataType_OnDown) - w->function.keyDownCallback(key, GetAsText(key), this); - w = w->next; - } + this->InternalOnKeyDown(key, L""); } else { + this->InternalOnKeyPress(key, L""); this->keys[key].isDown = true; this->keys[key].isE0 = isE0; - this->keys[key].makecode = makeCode; - for (unsigned int i = 0; i < this->keyEventSubscrivers.size(); i++) - { - if(this->keyEventSubscrivers[i]) - { - this->keyEventSubscrivers[i]->OnKeyPress(key, GetAsText(key), this); - } - } - KeyboardCallbackList *w = this->callbackList; - while (w) - { - if(w->function) - if (w->type == KeyboardCallbackList::CallbackDataType_OnPress) - w->function.keyPressCallback(key, GetAsText(key), this); - w = w->next; - } + this->keys[key].makecode = keyboard.MakeCode; } } } + + if(this->textTarget) + { //Parse text + UINT virtualKey = MapVirtualKey(keyboard.VKey, MAPVK_VK_TO_CHAR); + + if(this->keys[SAKI_Backspace].isDown) + { + if( this->writePos > 0 ) + { + --this->writePos; + this->textTarget->erase( this->writePos, 1 ); + } + } + else if (this->keys[SAKI_Delete].isDown) + { + if( this->writePos < this->textTarget->size() ) + { + this->textTarget->erase( this->writePos, 1 ); + } + } + else if (this->keys[SAKI_Left].isDown) + { + this->writePos = std::max( this->writePos - 1, (wstring::size_type)0 ); + } + else if (this->keys[SAKI_Right].isDown) + { + this->writePos = std::min( this->writePos + 1, this->textTarget->size() ); + } + else if (virtualKey && !isUp) + { + wchar_t test = towlower((wchar_t)virtualKey); + if( this->keys[SAKI_LeftShift].isDown || this->keys[SAKI_RightShift].isDown ) + test = towupper(test); + + this->textTarget->insert( this->writePos, 1, test); + ++this->writePos; + } + } } + + +void Win32Keyboard::MapKey(RAWKEYBOARD& rawKB, SAKI& out_key, bool& isE0) +{ + //------------------------------------------------------------------------------------// + // http://molecularmusings.wordpress.com/2011/09/05/properly-handling-keyboard-input/ // + //------------------------------------------------------------------------------------// + + UINT virtualKey = rawKB.VKey; + UINT scanCode = rawKB.MakeCode; + UINT flags = rawKB.Flags; + + if (virtualKey == 255) + { + // discard "fake keys" which are part of an escaped sequence + return; + } + else if (virtualKey == VK_SHIFT) + { + // correct left-hand / right-hand SHIFT + virtualKey = MapVirtualKey(scanCode, MAPVK_VSC_TO_VK_EX); + } + else if (virtualKey == VK_NUMLOCK) + { + // correct PAUSE/BREAK and NUM LOCK silliness, and set the extended bit + scanCode = (MapVirtualKey(virtualKey, MAPVK_VK_TO_VSC) | 0x100); + } + + // e0 and e1 are escape sequences used for certain special keys, such as PRINT and PAUSE/BREAK. + // see http://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html + isE0 = ((flags & RI_KEY_E0) != 0); + const bool isE1 = ((flags & RI_KEY_E1) != 0); + + if (isE1) + { + // for escaped sequences, turn the virtual key into the correct scan code using MapVirtualKey. + // however, MapVirtualKey is unable to map VK_PAUSE (this is a known bug), hence we map that by hand. + if (virtualKey == VK_PAUSE) scanCode = 0x45; + else scanCode = MapVirtualKey(virtualKey, MAPVK_VK_TO_VSC); + } + + + + switch (virtualKey) + { + // right-hand CONTROL and ALT have their e0 bit set + case VK_CONTROL: + if (isE0) out_key = SAKI_RightCtrl; + else out_key = SAKI_LeftCtrl; + break; + + case VK_MENU: + if (isE0) out_key = SAKI_RightAlt; + else out_key = SAKI_LeftAlt; + break; + + // NUMPAD ENTER has its e0 bit set + case VK_RETURN: + if (isE0) out_key = SAKI_NumpadEnter; + break; + + // the standard INSERT, DELETE, HOME, END, PRIOR and NEXT keys will always have their e0 bit set, but the + // corresponding keys on the NUMPAD will not. + case VK_INSERT: + if (!isE0) out_key = SAKI_Numpad0; + + break; + + case VK_DELETE: + if (!isE0) out_key = SAKI_NumpadDecimal; + + break; + + case VK_HOME: + if (!isE0) out_key = SAKI_Numpad7; + + break; + + case VK_END: + if (!isE0) out_key = SAKI_Numpad1; + + break; + + case VK_PRIOR: + if (!isE0) out_key = SAKI_Numpad9; + + break; + + case VK_NEXT: + if (!isE0) out_key = SAKI_Numpad3; + + break; + + // the standard arrow keys will always have their e0 bit set, but the + // corresponding keys on the NUMPAD will not. + case VK_LEFT: + if (!isE0) out_key = SAKI_Numpad4; + + break; + + case VK_RIGHT: + if (!isE0) out_key = SAKI_Numpad6; + + break; + + case VK_UP: + if (!isE0) out_key = SAKI_Numpad8; + + break; + + case VK_DOWN: + if (!isE0) out_key = SAKI_Numpad2; + + break; + + // NUMPAD 5 doesn't have its e0 bit set + case VK_CLEAR: + if (!isE0) out_key = SAKI_Numpad5; + + break; + case 0x03 : //VK_CANCEL + break; + case 0x08 : //VK_BACK + out_key = SAKI_Backspace; + break; + case 0x09 : //VK_TAB + out_key = SAKI_Tab; + break; + case 0x10 : //VK_SHIFT + out_key = SAKI_LeftShift; + out_key = SAKI_RightShift; + break; + case 0x13 : //VK_PAUSE + out_key = SAKI_Pause; + break; + case 0x14 : //VK_CAPITAL + out_key = SAKI_CapsLock; + break; + case 0x15 : //VK_KANA + break; + case 0x1B : //VK_ESCAPE + out_key = SAKI_Escape; + break; + case 0x1C : //VK_CONVERT + break; + case 0x1D : //VK_NONCONVERT + break; + case 0x1E : //VK_ACCEPT + break; + case 0x1F : //VK_MODECHANGE + break; + case 0x20 : //VK_SPACE + out_key = SAKI_Space; + + break; + case 0x29 : //VK_SELECT + break; + case 0x2A : //VK_PRINT + out_key = SAKI_PrintScreen; + break; + case 0x2B : //VK_EXECUTE + break; + case 0x2C : //VK_SNAPSHOT + break; + case 0x2F : //VK_HELP + break; + case 0x30 : //0 key + out_key = SAKI_0; + + break; + case 0x31 : //1 key + out_key = SAKI_1; + + break; + case 0x32 : //2 key + out_key = SAKI_2; + + break; + case 0x33 : //3 key + out_key = SAKI_3; + + break; + case 0x34 : //4 key + out_key = SAKI_4; + + break; + case 0x35 : //5 key + out_key = SAKI_5; + + break; + case 0x36 : //6 key + out_key = SAKI_6; + + break; + case 0x37 : //7 key + out_key = SAKI_7; + + break; + case 0x38 : //8 key + out_key = SAKI_8; + + break; + case 0x39 : //9 key + out_key = SAKI_9; + + break; + case 0x41 : //A key + out_key = SAKI_A; + + break; + case 0x42 : //B key + out_key = SAKI_B; + + break; + case 0x43 : //C key + out_key = SAKI_C; + + break; + case 0x44 : //D key + out_key = SAKI_D; + + break; + case 0x45 : //E key + out_key = SAKI_E; + + break; + case 0x46 : //F key + out_key = SAKI_F; + + break; + case 0x47 : //G key + out_key = SAKI_G; + + break; + case 0x48 : //H key + out_key = SAKI_H; + + break; + case 0x49 : //I key + out_key = SAKI_I; + + break; + case 0x4A : //J key + out_key = SAKI_J; + + break; + case 0x4B : //K key + out_key = SAKI_K; + + break; + case 0x4C : //L key + out_key = SAKI_L; + + break; + case 0x4D : //M key + out_key = SAKI_M; + + break; + case 0x4E : //N key + out_key = SAKI_N; + + break; + case 0x4F : //O key + out_key = SAKI_O; + + break; + case 0x50 : //P key + out_key = SAKI_P; + + break; + case 0x51 : //Q key + out_key = SAKI_Q; + + break; + case 0x52 : //R key + out_key = SAKI_R; + + break; + case 0x53 : //S key + out_key = SAKI_S; + + break; + case 0x54 : //T key + out_key = SAKI_T; + + break; + case 0x55 : //U key + out_key = SAKI_U; + + break; + case 0x56 : //V key + out_key = SAKI_V; + + break; + case 0x57 : //W key + out_key = SAKI_W; + + break; + case 0x58 : //X key + out_key = SAKI_X; + + break; + case 0x59 : //Y key + out_key = SAKI_Y; + + break; + case 0x5A : //Z key + out_key = SAKI_Z; + + break; + case 0x5B : //VK_LWIN + break; + case 0x5C : //VK_RWIN + break; + case 0x5D : //VK_APPS + break; + case 0x5F : //VK_SLEEP + break; + case 0x60 : //VK_NUMPAD0 + out_key = SAKI_Numpad0; + + break; + case 0x61 : //VK_NUMPAD1 + out_key = SAKI_Numpad1; + + break; + case 0x62 : //VK_NUMPAD2 + out_key = SAKI_Numpad2; + + break; + case 0x63 : //VK_NUMPAD3 + out_key = SAKI_Numpad3; + + break; + case 0x64 : //VK_NUMPAD4 + out_key = SAKI_Numpad4; + + break; + case 0x65 : //VK_NUMPAD5 + out_key = SAKI_Numpad5; + + break; + case 0x66 : //VK_NUMPAD6 + out_key = SAKI_Numpad6; + + break; + case 0x67 : //VK_NUMPAD7 + out_key = SAKI_Numpad7; + + break; + case 0x68 : //VK_NUMPAD8 + out_key = SAKI_Numpad8; + + break; + case 0x69 : //VK_NUMPAD9 + out_key = SAKI_Numpad9; + + break; + case 0x6A : //VK_MULTIPLY + out_key = SAKI_NumpadMultiply; + + break; + case 0x6B : //VK_ADD + out_key = SAKI_NumpadPlus; + + break; + case 0x6C : //VK_SEPARATOR + break; + case 0x6D : //VK_SUBTRACT + out_key = SAKI_NumpadSubtract; + + break; + case 0x6E : //VK_DECIMAL + out_key = SAKI_NumpadDecimal; + + break; + case 0x6F : //VK_DIVIDE + out_key = SAKI_NumpadDivide; + + break; + case 0x70 : //VK_F1 + out_key = SAKI_F1; + break; + case 0x71 : //VK_F2 + out_key = SAKI_F2; + break; + case 0x72 : //VK_F3 + out_key = SAKI_F3; + break; + case 0x73 : //VK_F4 + out_key = SAKI_F4; + break; + case 0x74 : //VK_F5 + out_key = SAKI_F5; + break; + case 0x75 : //VK_F6 + out_key = SAKI_F6; + break; + case 0x76 : //VK_F7 + out_key = SAKI_F7; + break; + case 0x77 : //VK_F8 + out_key = SAKI_F8; + break; + case 0x78 : //VK_F9 + out_key = SAKI_F9; + break; + case 0x79 : //VK_F10 + out_key = SAKI_F10; + break; + case 0x7A : //VK_F11 + out_key = SAKI_F11; + break; + case 0x7B : //VK_F12 + out_key = SAKI_F12; + break; + case 0x7C : //VK_F13 + out_key = SAKI_F13; + break; + case 0x7D : //VK_F14 + out_key = SAKI_F14; + break; + case 0x7E : //VK_F15 + out_key = SAKI_F15; + break; + case 0x7F : //VK_F16 + out_key = SAKI_F16; + break; + case 0x80 : //VK_F17 + out_key = SAKI_F17; + break; + case 0x81 : //VK_F18 + out_key = SAKI_F18; + break; + case 0x82 : //VK_F19 + out_key = SAKI_F19; + break; + case 0x83 : //VK_F20 + out_key = SAKI_F20; + break; + case 0x84 : //VK_F21 + out_key = SAKI_F21; + break; + case 0x85 : //VK_F22 + out_key = SAKI_F22; + break; + case 0x86 : //VK_F23 + out_key = SAKI_F23; + break; + case 0x87 : //VK_F24 + out_key = SAKI_F24; + break; + case 0x90 : //VK_NUMLOCK + out_key = SAKI_Numlock; + break; + case 0x91 : //VK_SCROLL + out_key = SAKI_ScrlLock; + break; + case 0xA0 : //VK_LSHIFT + out_key = SAKI_LeftShift; + break; + case 0xA1 : //VK_RSHIFT + out_key = SAKI_RightShift; + break; + case 0xA2 : //VK_LCONTROL + out_key = SAKI_LeftCtrl; + break; + case 0xA3 : //VK_RCONTROL + out_key = SAKI_RightCtrl; + break; + case 0xA4 : //VK_LMENU + out_key = SAKI_LeftAlt; + break; + case 0xA5 : //VK_RMENU + out_key = SAKI_RightCtrl; + break; + case 0xAD : //VK_VOLUME_MUTE + out_key = SAKI_VolumeMute; + break; + case 0xAE : //VK_VOLUME_DOWN + out_key = SAKI_VolumeDown; + break; + case 0xAF : //VK_VOLUME_UP + out_key = SAKI_VolumeUp; + break; + case 0xB0 : //VK_MEDIA_NEXT_TRACK + out_key = SAKI_MediaNext; + break; + case 0xB1 : //VK_MEDIA_PREV_TRACK + out_key = SAKI_MediaPrev; + break; + case 0xB2 : //VK_MEDIA_STOP + out_key = SAKI_MediaStop; + break; + case 0xB3 : //VK_MEDIA_PLAY_PAUSE + out_key = SAKI_MediaPlayPause; + break; + + case 0xBB://VK_OEM_PLUS + break; + case 0xBC://VK_OEM_COMMA + break; + case 0xBD://VK_OEM_MINUS + break; + case 0xBE://VK_OEM_PERIOD + break; + case 0xBA://VK_OEM_1 + break; + case 0xBF://VK_OEM_2 + break; + case 0xC0://VK_OEM_3 + break; + case 0xDB://VK_OEM_4 + break; + case 0xDC://VK_OEM_5 + break; + case 0xDD://VK_OEM_6 + break; + case 0xDE://VK_OEM_7 + break; + case 0xDF://VK_OEM_8 + break; + } +} + + + + + diff --git a/Code/Misc/Input/Source/Win32/Win32Mouse.cpp b/Code/Misc/Input/Source/Win32/Win32Mouse.cpp index 50d55a91..a05db67c 100644 --- a/Code/Misc/Input/Source/Win32/Win32Mouse.cpp +++ b/Code/Misc/Input/Source/Win32/Win32Mouse.cpp @@ -1,17 +1,70 @@ ///////////////////////////////////////////////////////////////////// // Created by [Dennis Andersen] [2013] ///////////////////////////////////////////////////////////////////// -#include "..\..\Include\Win32\Win32Input.h" +#include "..\..\Include\Win32\Win32Mouse.h" using namespace Input; using namespace Input::Enum; using namespace Input::Struct; using namespace Input::Typedefs; +void MapButton(RAWMOUSE& rawMouse, bool &isUp, Enum::SAMI& btn, int& delta, Struct::SAIPoint2D& vel, unsigned int& mcode) +{ + if(rawMouse.lLastX != 0 || rawMouse.lLastY != 0) + { + vel.x = rawMouse.lLastX; + vel.y = rawMouse.lLastY; + } + if( rawMouse.usButtonFlags > 0 ) + { +//-------------------------------------------------------------------------------------- + //Mouse button pressed + if(rawMouse.usButtonFlags == RI_MOUSE_LEFT_BUTTON_DOWN) + { + btn = SAMI_MouseLeftBtn; + isUp = false; + } + else if(rawMouse.usButtonFlags == RI_MOUSE_MIDDLE_BUTTON_DOWN) + { + btn = SAMI_MouseMiddleBtn; + isUp = false; + } + else if(rawMouse.usButtonFlags == RI_MOUSE_RIGHT_BUTTON_DOWN) + { + btn = SAMI_MouseRightBtn; + isUp = false; + } +//-------------------------------------------------------------------------------------- + //Mouse button Released + else if(rawMouse.usButtonFlags == RI_MOUSE_LEFT_BUTTON_UP) + { + btn = SAMI_MouseLeftBtn; + isUp = true; + } + else if(rawMouse.usButtonFlags == RI_MOUSE_MIDDLE_BUTTON_UP) + { + btn = SAMI_MouseMiddleBtn; + isUp = true; + } + else if(rawMouse.usButtonFlags == RI_MOUSE_RIGHT_BUTTON_UP) + { + btn = SAMI_MouseRightBtn; + isUp = true; + } +//-------------------------------------------------------------------------------------- + else if (rawMouse.usButtonFlags == RI_MOUSE_WHEEL) + { + delta = ((int)rawMouse.usButtonData); + + if(delta > 120) delta = -1; + else delta = 1; + } + } +} + Win32Mouse::Win32Mouse() { - memset(&this->device, 0, sizeof(RAWINPUTDEVICE)); memset(&this->buttons[0], 0, sizeof(Buttons) * MAXBUTTONS); } Win32Mouse::~Win32Mouse() @@ -31,69 +84,26 @@ bool Win32Mouse::IsBtnDown(Enum::SAMI btn) return this->buttons[btn].isDown; } -int Win32Mouse::GetWheelDelta() -{ - return this->wheelDelta; -} -Struct::SAIPointInt2D Win32Mouse::GetPixelPosition(Struct::SAIPointInt2D targetMem) -{ - targetMem = this->pixelPos; - return targetMem; -} -Struct::SAIPointFloat2D Win32Mouse::GetNormalizedPosition(Struct::SAIPointFloat2D targetMem) -{ - POINT mousePos; - GetCursorPos( &mousePos ); - - RECT windowVertex; - GetWindowRect( this->device.hwndTarget, &windowVertex ); - - this->normalPos.x = (float)(mousePos.x - windowVertex.left); - this->normalPos.x /= (float)(windowVertex.right - windowVertex.left); - - this->normalPos.y = (float)(mousePos.y - windowVertex.top); - this->normalPos.y /= (float)(windowVertex.bottom - windowVertex.top); - return targetMem; -} - -void Win32Mouse::ProccessMouseData (bool isUp, Enum::SAMI btn, int delta, Struct::SAIPointInt2D velocity, unsigned int makeCode) +void Win32Mouse::ProccessMouseData (RAWMOUSE mouse) { + bool isUp = true; + Enum::SAMI btn = Enum::SAMI_Unknown; + int delta = 0; + Struct::SAIPoint2D velocity; + unsigned int makeCode = 0; + MapButton(mouse, isUp, btn, delta, velocity, makeCode); + if(velocity.Length() != 0) { - this->pixelPos.x += velocity.x; - this->pixelPos.y += velocity.y; - - for (unsigned int i = 0; i < this->mouseSubscribers.size(); i++) - { - if(this->mouseSubscribers[i]) - this->mouseSubscribers[i]->OnMouseMove(this->pixelPos, this); - } - MouseCallbackList *w = this->callbackList; - while (w) - { - if(w->function) - if (w->type == MouseCallbackList::CallbackDataType_OnMove) - w->function.mouseMoveCallback(this->pixelPos, this); - w = w->next; - } + this->pixelPos.x += this->deltaPos.x = velocity.x; + this->pixelPos.y += this->deltaPos.y = velocity.y; + InternalOnMove(this->pixelPos); } if(delta != 0) { - for (unsigned int i = 0; i < this->mouseSubscribers.size(); i++) - { - if(this->mouseSubscribers[i]) - this->mouseSubscribers[i]->OnMouseScroll(delta, this); - } - MouseCallbackList *w = this->callbackList; - while (w) - { - if(w->function) - if (w->type == MouseCallbackList::CallbackDataType_OnMove) - w->function.mouseScrollCallback(delta, this); - w = w->next; - } + InternalOnScroll(delta); } @@ -105,80 +115,19 @@ void Win32Mouse::ProccessMouseData (bool isUp, Enum::SAMI btn, int delta, Struct //The btn is released. if(isUp) { - for (unsigned int i = 0; i < this->mouseSubscribers.size(); i++) - { - if(this->mouseSubscribers[i]) - this->mouseSubscribers[i]->OnMouseRelease(btn, this); - } - MouseCallbackList *w = this->callbackList; - while (w) - { - if(w->function) - if (w->type == MouseCallbackList::CallbackDataType_OnRelease) - w->function.mouseReleaseCallback(btn, this); - w = w->next; - } + InternalOnBtnRelease(btn); } //The btn is pressed. else { + //The btn is down since last frame if(this->buttons[btn].isDown) { - for (unsigned int i = 0; i < this->mouseSubscribers.size(); i++) - { - if(this->mouseSubscribers[i]) - this->mouseSubscribers[i]->OnMouseDown(btn, this); - } - MouseCallbackList *w = this->callbackList; - while (w) - { - if(w->function) - if (w->type == MouseCallbackList::CallbackDataType_OnDown) - w->function.mouseDownCallback(btn, this); - w = w->next; - } + InternalOnBtnDown(btn); } else { - for (unsigned int i = 0; i < this->mouseSubscribers.size(); i++) - { - if(this->mouseSubscribers[i]) - this->mouseSubscribers[i]->OnMousePress(btn, this); - } - MouseCallbackList *w = this->callbackList; - while (w) - { - if(w->function) - if (w->type == MouseCallbackList::CallbackDataType_OnPress) - w->function.mousePressCallback(btn, this); - w = w->next; - } + InternalOnBtnPress(btn); } } - - -} - -bool Win32Mouse::Create(HWND target) -{ - this->device.usUsagePage = 0x01; - this->device.hwndTarget = target; - this->device.usUsage = Input::RawInput_Usage_mouse; - this->device.dwFlags = RIDEV_NOLEGACY | RIDEV_CAPTUREMOUSE; - - if(RegisterRawInputDevices(&this->device, 1, sizeof(RAWINPUTDEVICE)) == TRUE) - { - return true; - } - - memset(&this->device, 0, sizeof(RAWINPUTDEVICE)); - - return false; -} - - - - - - - +} \ No newline at end of file From 9a470fc175ec25f9f1f130157e350a29f3fac114 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Fri, 21 Feb 2014 12:09:38 +0100 Subject: [PATCH 11/32] post merge fixes --- Code/Game/GameClient/DanBiasGame_Impl.cpp | 38 +++++-------------- Code/Game/GameClient/GameClient.vcxproj.user | 2 +- .../GameClient/GameClientState/GameState.cpp | 17 +++------ .../GameClientState/LanMenuState.cpp | 5 +-- .../GameClient/GameClientState/MainState.cpp | 1 + .../GameClientState/SharedStateContent.h | 3 +- 6 files changed, 19 insertions(+), 47 deletions(-) diff --git a/Code/Game/GameClient/DanBiasGame_Impl.cpp b/Code/Game/GameClient/DanBiasGame_Impl.cpp index c89e5db9..3a3149d7 100644 --- a/Code/Game/GameClient/DanBiasGame_Impl.cpp +++ b/Code/Game/GameClient/DanBiasGame_Impl.cpp @@ -20,7 +20,6 @@ #include "EventHandler/EventHandler.h" #include "GameClientState/SharedStateContent.h" -#include "Win32/Win32ApplicationKeyboard.h" #include "Utilities.h" using namespace ::Oyster; @@ -46,27 +45,23 @@ namespace DanBias NetworkClient networkClient; SharedStateContent sharedStateContent; - ::Input::Win32ApplicationKeyboard *keyboardDevice_application; bool serverOwner; float capFrame; 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->sharedStateContent.network = nullptr; + this->sharedStateContent.mouseDevice = nullptr; + this->sharedStateContent.keyboardDevice = nullptr; + this->serverOwner = false; + this->capFrame = 0; } ~DanBiasGamePrivateData() { SafeDeleteInstance( this->sharedStateContent.mouseDevice ); - SafeDeleteInstance( this->sharedStateContent.keyboardDevice_raw ); - SafeDeleteInstance( this->sharedStateContent.keyboardDevice_application ); + SafeDeleteInstance( this->sharedStateContent.keyboardDevice ); } } data; } @@ -177,16 +172,14 @@ namespace DanBias MessageBox( 0, L"Could not initialize the mouseDevice.", L"Error", MB_OK ); return E_FAIL; } - data.sharedStateContent.mouseDevice->Disable(); - data.sharedStateContent.keyboardDevice_raw = dynamic_cast( ::Input::InputManager::Instance()->CreateDevice(Input::Enum::SAIType_Keyboard, handle) ); - if( !data.sharedStateContent.keyboardDevice_raw ) + data.sharedStateContent.keyboardDevice= dynamic_cast( ::Input::InputManager::Instance()->CreateDevice(Input::Enum::SAIType_Keyboard, handle) ); + if( !data.sharedStateContent.keyboardDevice ) { MessageBox( 0, L"Could not initialize the raw keyboard device.", L"Error", MB_OK ); return E_FAIL; } - data.keyboardDevice_application->Disable(); return S_OK; } @@ -275,25 +268,12 @@ namespace DanBias LRESULT CALLBACK WindowCallBack(HWND handle, UINT message, WPARAM wParam, LPARAM lParam ) { - //PAINTSTRUCT ps; - //HDC hdc; - switch ( message ) { - //case WM_PAINT: - // hdc = BeginPaint( handle, &ps ); - // EndPaint( handle, &ps ); - //break; - case WM_DESTROY: PostQuitMessage( 0 ); break; - default: - if( DanBias::data.keyboardDevice_application->IsActive() ) - { - DanBias::data.keyboardDevice_application->CaptureText( message, wParam ); - } - break; + default: break; } return DefWindowProc( handle, message, wParam, lParam ); diff --git a/Code/Game/GameClient/GameClient.vcxproj.user b/Code/Game/GameClient/GameClient.vcxproj.user index 2e28d6f7..4b847ee6 100644 --- a/Code/Game/GameClient/GameClient.vcxproj.user +++ b/Code/Game/GameClient/GameClient.vcxproj.user @@ -1,7 +1,7 @@  - true + false $(OutDir) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 1e142d6f..27ad8ba9 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -27,8 +27,7 @@ struct GameState::MyData GameClientState::ClientState nextState; NetworkClient *nwClient; ::Input::Mouse *mouseInput; - ::Input::Keyboard *keyboardInput_raw; - ::Input::ApplicationKeyboard *keyboardInput_app; + ::Input::Keyboard *keyboardInput; ::std::map> *staticObjects; ::std::map> *dynamicObjects; @@ -67,15 +66,11 @@ bool GameState::Init( SharedStateContent &shared ) this->privData->nextState = GameClientState::ClientState_Same; this->privData->nwClient = shared.network; this->privData->mouseInput = shared.mouseDevice; - this->privData->keyboardInput_raw = shared.keyboardDevice_raw; - this->privData->keyboardInput_app = shared.keyboardDevice_application; + this->privData->keyboardInput = shared.keyboardDevice; this->privData->staticObjects = &shared.staticObjects; this->privData->dynamicObjects = &shared.dynamicObjects; 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; this->privData->camera.SetPerspectiveProjection( Utility::Value::Radian(90.0f), aspectRatio, 0.1f, 1000.0f ); @@ -101,7 +96,7 @@ bool GameState::Init( SharedStateContent &shared ) } // create UI states - this->gameUI = new GamingUI(this->privData->mouseInput, this->privData->keyboardInput_raw, this->privData->nwClient, &this->privData->camera); + this->gameUI = new GamingUI(this->privData->mouseInput, this->privData->keyboardInput, this->privData->nwClient, &this->privData->camera); this->respawnUI = new RespawnUI(this->privData->nwClient, 20); this->currGameUI = gameUI; ((GamingUI*)gameUI)->Init(); @@ -268,8 +263,6 @@ 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 ) { @@ -323,7 +316,7 @@ void GameState::ReadKeyInput() #ifdef _DEBUG // DEGUG KEYS // Reload shaders - if( this->privData->keyboardInput_raw->IsKeyDown(::Input::Enum::SAKI_R) ) + if( this->privData->keyboardInput->IsKeyDown(::Input::Enum::SAKI_R) ) { if( !this->key_Reload_Shaders ) { @@ -337,7 +330,7 @@ void GameState::ReadKeyInput() this->key_Reload_Shaders = false; // toggle wire frame render - if( this->privData->keyboardInput_raw->IsKeyDown(::Input::Enum::SAKI_T) ) + if( this->privData->keyboardInput->IsKeyDown(::Input::Enum::SAKI_T) ) { if( !this->key_Wireframe_Toggle ) { diff --git a/Code/Game/GameClient/GameClientState/LanMenuState.cpp b/Code/Game/GameClient/GameClientState/LanMenuState.cpp index dd49dd23..6f72014d 100644 --- a/Code/Game/GameClient/GameClientState/LanMenuState.cpp +++ b/Code/Game/GameClient/GameClientState/LanMenuState.cpp @@ -29,7 +29,7 @@ struct LanMenuState::MyData GameClientState::ClientState nextState; NetworkClient *nwClient; ::Input::Mouse *mouseInput; - ::Input::ApplicationKeyboard *keyboardInput; + ::Input::Keyboard *keyboardInput; Graphics::API::Texture background; EventButtonCollection guiElements; @@ -55,8 +55,7 @@ bool LanMenuState::Init( SharedStateContent &shared ) this->privData->nextState = GameClientState::ClientState_Same; this->privData->nwClient = shared.network; this->privData->mouseInput = shared.mouseDevice; - this->privData->keyboardInput = shared.keyboardDevice_application; - this->privData->keyboardInput->Activate(); + this->privData->keyboardInput = shared.keyboardDevice; this->privData->background = Graphics::API::CreateTexture( L"color_white.png" ); diff --git a/Code/Game/GameClient/GameClientState/MainState.cpp b/Code/Game/GameClient/GameClientState/MainState.cpp index e4c1fe0e..68f8d973 100644 --- a/Code/Game/GameClient/GameClientState/MainState.cpp +++ b/Code/Game/GameClient/GameClientState/MainState.cpp @@ -48,6 +48,7 @@ bool MainState::Init( SharedStateContent &shared ) this->privData->nextState = GameClientState::ClientState_Same; this->privData->nwClient = shared.network; this->privData->mouseInput = shared.mouseDevice; + //this->privData->mouseInput-> this->privData->background = Graphics::API::CreateTexture( L"color_white.png" ); diff --git a/Code/Game/GameClient/GameClientState/SharedStateContent.h b/Code/Game/GameClient/GameClientState/SharedStateContent.h index 293213d6..cb722cec 100644 --- a/Code/Game/GameClient/GameClientState/SharedStateContent.h +++ b/Code/Game/GameClient/GameClientState/SharedStateContent.h @@ -28,8 +28,7 @@ namespace DanBias { namespace Client ::Oyster::Network::NetworkClient *network; ::Input::Mouse *mouseDevice; - ::Input::Keyboard *keyboardDevice_raw; - ::Input::ApplicationKeyboard *keyboardDevice_application; + ::Input::Keyboard *keyboardDevice; }; } } From 40276391af8482d24b534a77c43c4c134a6cd7f9 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Fri, 21 Feb 2014 12:18:46 +0100 Subject: [PATCH 12/32] post merge fixes --- Code/Game/GameClient/GameClientState/GameState.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 71a984c9..bb0bdc90 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -207,8 +207,7 @@ bool GameState::Render() } } -#ifdef _DEBUG - //RB DEBUG render wire frame +#ifdef _DEBUG //RB DEBUG render wire frame if(this->renderWhireframe) { Oyster::Graphics::API::StartRenderWireFrame(); @@ -248,8 +247,7 @@ bool GameState::Render() } } } - //!RB DEBUG -#endif +#endif //!RB DEBUG Oyster::Graphics::API::StartGuiRender(); // render gui elemnts @@ -372,7 +370,7 @@ void GameState::ReadKeyInput() #endif // !DEGUG KEYS // toggle wire frame render - if( this->privData->input->IsKeyPressed(DIK_TAB) ) + if( this->privData->keyboardInput->IsKeyDown(::Input::Enum::SAKI_Tab) ) { if( !this->key_showStats ) { From dee6c5f8d1aaa8516fe28487356f3cbecdf8fc30 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Fri, 21 Feb 2014 12:31:31 +0100 Subject: [PATCH 13/32] MainState renders now a mouseCursor --- Code/Game/GameClient/GameClientState/MainState.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/MainState.cpp b/Code/Game/GameClient/GameClientState/MainState.cpp index 68f8d973..91248ab4 100644 --- a/Code/Game/GameClient/GameClientState/MainState.cpp +++ b/Code/Game/GameClient/GameClientState/MainState.cpp @@ -25,7 +25,8 @@ struct MainState::MyData GameClientState::ClientState nextState; NetworkClient *nwClient; ::Input::Mouse *mouseInput; - Graphics::API::Texture background; + Float3 mousePos; + Graphics::API::Texture background, mouseCursor; EventButtonCollection guiElements; }; @@ -49,8 +50,10 @@ bool MainState::Init( SharedStateContent &shared ) this->privData->nwClient = shared.network; this->privData->mouseInput = shared.mouseDevice; //this->privData->mouseInput-> + this->privData->mousePos = Float3( 0.0f ); this->privData->background = Graphics::API::CreateTexture( L"color_white.png" ); + this->privData->mouseCursor = Graphics::API::CreateTexture( L"cursor_md.png" ); // create buttons ButtonRectangle *button; @@ -81,8 +84,8 @@ GameClientState::ClientState MainState::Update( float deltaTime ) ::Input::Struct::SAIPoint2D pos; this->privData->mouseInput->GetPixelPosition( pos ); - mouseState.x = pos.x; - mouseState.y = pos.y; + this->privData->mousePos.x = mouseState.x = pos.x; + this->privData->mousePos.y = mouseState.y = pos.y; mouseState.mouseButtonPressed = this->privData->mouseInput->IsBtnDown( ::Input::Enum::SAMI_MouseLeftBtn ); } EventHandler::Instance().Update( mouseState ); @@ -95,6 +98,7 @@ bool MainState::Render() Graphics::API::NewFrame(); Graphics::API::StartGuiRender(); + Graphics::API::RenderGuiElement( this->privData->mouseCursor, this->privData->mousePos, Float2(0.1f), Float4(1.0f) ); Graphics::API::RenderGuiElement( this->privData->background, Float3(0.5f, 0.5f, 0.9f), Float2(1.0f), Float4(63.0f/255.0f,73.0f/255.0f,127.0f/255.0f,0.6f) ); this->privData->guiElements.RenderTexture(); @@ -110,6 +114,7 @@ bool MainState::Release() if( this->privData ) { Graphics::API::DeleteTexture( this->privData->background ); + Graphics::API::DeleteTexture( this->privData->mouseCursor ); EventHandler::Instance().ReleaseCollection( &this->privData->guiElements ); this->privData = NULL; From 44aab68bfbcfb62268eea3bc87bc5ff5f1e26f6e Mon Sep 17 00:00:00 2001 From: Dennis Andersen Date: Fri, 21 Feb 2014 21:04:30 +0100 Subject: [PATCH 14/32] Input - More support for mouse --- Code/Game/GameClient/DanBiasGame_Impl.cpp | 7 +- Code/Game/GameClient/GameClient.vcxproj.user | 2 +- .../GameClient/GameClientState/GamingUI.cpp | 2 +- .../GameClientState/LanMenuState.cpp | 2 +- .../GameClientState/LobbyAdminState.cpp | 2 +- .../GameClient/GameClientState/LobbyState.cpp | 2 +- .../GameClient/GameClientState/MainState.cpp | 4 +- Code/Misc/Input/Include/Common.h | 20 ++- Code/Misc/Input/Include/InputObject.h | 2 + Code/Misc/Input/Include/Keyboard.h | 3 + Code/Misc/Input/Include/Mouse.h | 29 ++-- Code/Misc/Input/Include/Win32/Win32Input.h | 1 - Code/Misc/Input/Include/Win32/Win32Keyboard.h | 7 +- Code/Misc/Input/Include/Win32/Win32Mouse.h | 19 ++- Code/Misc/Input/Source/Mouse.cpp | 19 +-- Code/Misc/Input/Source/Win32/Win32Input.cpp | 60 +++----- .../Misc/Input/Source/Win32/Win32Keyboard.cpp | 54 +++++++- Code/Misc/Input/Source/Win32/Win32Mouse.cpp | 128 ++++++++++++++++-- 18 files changed, 261 insertions(+), 102 deletions(-) diff --git a/Code/Game/GameClient/DanBiasGame_Impl.cpp b/Code/Game/GameClient/DanBiasGame_Impl.cpp index 3a3149d7..f5ff4232 100644 --- a/Code/Game/GameClient/DanBiasGame_Impl.cpp +++ b/Code/Game/GameClient/DanBiasGame_Impl.cpp @@ -60,8 +60,8 @@ namespace DanBias ~DanBiasGamePrivateData() { - SafeDeleteInstance( this->sharedStateContent.mouseDevice ); - SafeDeleteInstance( this->sharedStateContent.keyboardDevice ); + //SafeDeleteInstance( this->sharedStateContent.mouseDevice ); + //SafeDeleteInstance( this->sharedStateContent.keyboardDevice ); } } data; } @@ -273,6 +273,9 @@ LRESULT CALLBACK WindowCallBack(HWND handle, UINT message, WPARAM wParam, LPARAM case WM_DESTROY: PostQuitMessage( 0 ); break; + case WM_INPUT: + message = 0; + break; default: break; } diff --git a/Code/Game/GameClient/GameClient.vcxproj.user b/Code/Game/GameClient/GameClient.vcxproj.user index 4b847ee6..2e28d6f7 100644 --- a/Code/Game/GameClient/GameClient.vcxproj.user +++ b/Code/Game/GameClient/GameClient.vcxproj.user @@ -1,7 +1,7 @@  - false + true $(OutDir) diff --git a/Code/Game/GameClient/GameClientState/GamingUI.cpp b/Code/Game/GameClient/GameClientState/GamingUI.cpp index 222f81c0..56b8f98f 100644 --- a/Code/Game/GameClient/GameClientState/GamingUI.cpp +++ b/Code/Game/GameClient/GameClientState/GamingUI.cpp @@ -161,7 +161,7 @@ void GamingUI::ReadKeyInput() //send delta mouse movement { static const float mouseSensitivity = Radian( 1.0f ); - ::Input::Struct::SAIPoint2D deltaPos; + ::Input::Struct::SAIPointFloat2D deltaPos; this->mouseInput->GetDeltaPosition( deltaPos ); this->camera->PitchDown( deltaPos.y * mouseSensitivity );; diff --git a/Code/Game/GameClient/GameClientState/LanMenuState.cpp b/Code/Game/GameClient/GameClientState/LanMenuState.cpp index 6f72014d..8cca6cf4 100644 --- a/Code/Game/GameClient/GameClientState/LanMenuState.cpp +++ b/Code/Game/GameClient/GameClientState/LanMenuState.cpp @@ -92,7 +92,7 @@ GameClientState::ClientState LanMenuState::Update( float deltaTime ) { MouseInput mouseState; { - ::Input::Struct::SAIPoint2D pos; + ::Input::Struct::SAIPointInt2D pos; this->privData->mouseInput->GetPixelPosition( pos ); mouseState.x = pos.x; diff --git a/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp b/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp index bac7e4cb..312f1c41 100644 --- a/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp +++ b/Code/Game/GameClient/GameClientState/LobbyAdminState.cpp @@ -63,7 +63,7 @@ GameClientState::ClientState LobbyAdminState::Update( float deltaTime ) { MouseInput mouseState; { - ::Input::Struct::SAIPoint2D pos; + ::Input::Struct::SAIPointInt2D pos; this->privData->mouseInput->GetPixelPosition( pos ); mouseState.x = pos.x; diff --git a/Code/Game/GameClient/GameClientState/LobbyState.cpp b/Code/Game/GameClient/GameClientState/LobbyState.cpp index 3db9b341..c47febbe 100644 --- a/Code/Game/GameClient/GameClientState/LobbyState.cpp +++ b/Code/Game/GameClient/GameClientState/LobbyState.cpp @@ -63,7 +63,7 @@ GameClientState::ClientState LobbyState::Update( float deltaTime ) { MouseInput mouseState; { - ::Input::Struct::SAIPoint2D pos; + ::Input::Struct::SAIPointInt2D pos; this->privData->mouseInput->GetPixelPosition( pos ); mouseState.x = pos.x; diff --git a/Code/Game/GameClient/GameClientState/MainState.cpp b/Code/Game/GameClient/GameClientState/MainState.cpp index 91248ab4..a057ab74 100644 --- a/Code/Game/GameClient/GameClientState/MainState.cpp +++ b/Code/Game/GameClient/GameClientState/MainState.cpp @@ -81,8 +81,8 @@ GameClientState::ClientState MainState::Update( float deltaTime ) { MouseInput mouseState; { - ::Input::Struct::SAIPoint2D pos; - this->privData->mouseInput->GetPixelPosition( pos ); + ::Input::Struct::SAIPointFloat2D pos; + this->privData->mouseInput->GetNormalizedPosition( pos ); this->privData->mousePos.x = mouseState.x = pos.x; this->privData->mousePos.y = mouseState.y = pos.y; diff --git a/Code/Misc/Input/Include/Common.h b/Code/Misc/Input/Include/Common.h index eed90eb7..694001a3 100644 --- a/Code/Misc/Input/Include/Common.h +++ b/Code/Misc/Input/Include/Common.h @@ -26,6 +26,11 @@ namespace Input SAIType_futureExample2, SAIType_futureExample3, }; + enum InputOptionType + { + InputOptionType_RawInput, + InputOptionType_PlatformDefault, + }; enum ButtonState { ButtonState_Press, // When button is pressed (once) @@ -37,15 +42,24 @@ namespace Input /*********************************************************************/ namespace Struct { - struct SAIPoint2D + struct SAIPointInt2D { int x; int y; - SAIPoint2D() :x(0), y(0) { } - SAIPoint2D(int _x, int _y) :x(_x), y(_y) { } + SAIPointInt2D() :x(0), y(0) { } + SAIPointInt2D(int _x, int _y) :x(_x), y(_y) { } int Length() { return (abs(x) + abs(y)); } }; + struct SAIPointFloat2D + { + float x; + float y; + SAIPointFloat2D() :x(0.0f), y(0.0f) { } + SAIPointFloat2D(float _x, float _y) :x(_x), y(_y) { } + float Length() { return (fabs(x) + fabs(y)); } + }; + struct InputData; } /*********************************************************************/ diff --git a/Code/Misc/Input/Include/InputObject.h b/Code/Misc/Input/Include/InputObject.h index 3536730b..641ea2ed 100644 --- a/Code/Misc/Input/Include/InputObject.h +++ b/Code/Misc/Input/Include/InputObject.h @@ -16,6 +16,8 @@ namespace Input virtual void Activate () = 0; virtual void Deactivate () = 0; virtual bool IsActive() = 0; + virtual bool IsInputOptionSuported(Enum::InputOptionType options) const = 0; + virtual void SetInputOptionType(Enum::InputOptionType options) = 0; protected: InputObject(Enum::SAIType type) { this->type = type; } diff --git a/Code/Misc/Input/Include/Keyboard.h b/Code/Misc/Input/Include/Keyboard.h index c2568e3b..fc3afafb 100644 --- a/Code/Misc/Input/Include/Keyboard.h +++ b/Code/Misc/Input/Include/Keyboard.h @@ -156,6 +156,8 @@ namespace Input virtual bool IsKeyUp (Enum::SAKI key) = 0; virtual bool IsKeyDown (Enum::SAKI key) = 0; virtual wchar_t* GetAsText(Enum::SAKI key) = 0; + virtual void SetInputOptionType(Enum::InputOptionType options) override = 0; + virtual bool IsInputOptionSuported(Enum::InputOptionType options) const override = 0; public: /* global subscribe callback functions */ void AddOnKeyPressCallback (Typedefs::OnKeyPressCallback func); @@ -195,6 +197,7 @@ namespace Input ::std::wstring* textTarget; ::std::wstring::size_type writePos; bool active; + Enum::InputOptionType inputMode; }; } diff --git a/Code/Misc/Input/Include/Mouse.h b/Code/Misc/Input/Include/Mouse.h index 56f7884f..daa809c6 100644 --- a/Code/Misc/Input/Include/Mouse.h +++ b/Code/Misc/Input/Include/Mouse.h @@ -47,7 +47,7 @@ namespace Input typedef void(*OnMousePressCallback)(Enum::SAMI btn, Mouse* sender); typedef void(*OnMouseDownCallback)(Enum::SAMI btn, Mouse* sender); typedef void(*OnMouseReleaseCallback)(Enum::SAMI btn, Mouse* sender); - typedef void(*OnMouseMoveCallback)(Struct::SAIPoint2D cord, Mouse* sender); + typedef void(*OnMouseMoveCallback)(Struct::SAIPointInt2D cord, Mouse* sender); typedef void(*OnMouseScrollCallback)(int delta, Mouse* sender); } //----------------------------------------------------------------------------------------------------------------------------- @@ -62,21 +62,22 @@ namespace Input virtual void OnMousePress ( Enum::SAMI key, Mouse* sender ) { } virtual void OnMouseDown ( Enum::SAMI key, Mouse* sender ) { } virtual void OnMouseRelease ( Enum::SAMI key, Mouse* sender ) { } - virtual void OnMouseMove ( Struct::SAIPoint2D coordinate, Mouse* sender ) { } + virtual void OnMouseMove ( Struct::SAIPointInt2D coordinate, Mouse* sender ) { } virtual void OnMouseScroll ( int delta, Mouse* sender ) { } }; public: /* Manual check functions */ - virtual ~Mouse(); + virtual bool IsBtnUp(Enum::SAMI key) const = 0; + virtual bool IsBtnDown(Enum::SAMI key) const = 0; + virtual int GetWheelDelta() const = 0; + virtual Struct::SAIPointInt2D& GetPixelPosition(Struct::SAIPointInt2D& targetMem = Struct::SAIPointInt2D()) const = 0; + virtual Struct::SAIPointFloat2D& GetNormalizedPosition(Struct::SAIPointFloat2D& targetMem = Struct::SAIPointFloat2D()) const = 0; + virtual Struct::SAIPointFloat2D& GetDeltaPosition(Struct::SAIPointFloat2D& targetMem = Struct::SAIPointFloat2D()) const = 0; + virtual void SetInputOptionType(Enum::InputOptionType options) override = 0; + virtual bool IsInputOptionSuported(Enum::InputOptionType options) const override = 0; - virtual bool IsBtnUp(Enum::SAMI key) = 0; - virtual bool IsBtnDown(Enum::SAMI key) = 0; public: /* global subscribe callback functions */ - int GetWheelDelta() const; - Struct::SAIPoint2D & GetPixelPosition( Struct::SAIPoint2D &targetMem = Struct::SAIPoint2D() ) const; - Struct::SAIPoint2D & GetDeltaPosition( Struct::SAIPoint2D &targetMem = Struct::SAIPoint2D() ) const; - void AddOnMousePressCallback( Typedefs::OnMousePressCallback func); void AddOnMouseDownCallback( Typedefs::OnMouseDownCallback func ); void AddOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func ); @@ -106,21 +107,25 @@ namespace Input protected: Mouse(); + virtual ~Mouse(); protected: void InternalOnBtnPress(Enum::SAMI key); void InternalOnBtnDown(Enum::SAMI key); void InternalOnBtnRelease(Enum::SAMI key); - void InternalOnMove(Struct::SAIPoint2D cord); + void InternalOnMove(Struct::SAIPointInt2D cord); void InternalOnScroll(int delta); protected: std::vector mouseSubscribers; MouseCallbackList* callbackList; - Struct::SAIPoint2D pixelPos, deltaPos; + Struct::SAIPointInt2D pixelPos; + Struct::SAIPointFloat2D normalPos; + Struct::SAIPointFloat2D deltaPos; bool isCurorLocked; int wheelDelta; - bool active; + bool active; + Enum::InputOptionType inputMode; }; } diff --git a/Code/Misc/Input/Include/Win32/Win32Input.h b/Code/Misc/Input/Include/Win32/Win32Input.h index e8306400..1db7353e 100644 --- a/Code/Misc/Input/Include/Win32/Win32Input.h +++ b/Code/Misc/Input/Include/Win32/Win32Input.h @@ -57,7 +57,6 @@ namespace Input std::vector mouse; bool enabled; - bool exclusive; HWND targetHwin; private: diff --git a/Code/Misc/Input/Include/Win32/Win32Keyboard.h b/Code/Misc/Input/Include/Win32/Win32Keyboard.h index e2e0442c..5cdd4b1d 100644 --- a/Code/Misc/Input/Include/Win32/Win32Keyboard.h +++ b/Code/Misc/Input/Include/Win32/Win32Keyboard.h @@ -13,14 +13,17 @@ namespace Input class Win32Keyboard :public Keyboard { public: - Win32Keyboard(); + Win32Keyboard(HWND target); ~Win32Keyboard(); bool IsKeyUp (Enum::SAKI key) override; bool IsKeyDown (Enum::SAKI key) override; wchar_t* GetAsText(Enum::SAKI key) override; + void SetInputOptionType(Enum::InputOptionType options) override; + bool IsInputOptionSuported(Enum::InputOptionType options) const override; void ProccessKeyboardData (RAWKEYBOARD keyboard); + bool Create( ); private: void MapKey(RAWKEYBOARD& rawKB, Enum::SAKI& out_key, bool& isE0); @@ -31,7 +34,7 @@ namespace Input bool isDown; unsigned int makecode; }; - + RAWINPUTDEVICE device; static const int MAXKEYS = 256; Keys keys[MAXKEYS]; }; diff --git a/Code/Misc/Input/Include/Win32/Win32Mouse.h b/Code/Misc/Input/Include/Win32/Win32Mouse.h index 71a37b2d..9da211d2 100644 --- a/Code/Misc/Input/Include/Win32/Win32Mouse.h +++ b/Code/Misc/Input/Include/Win32/Win32Mouse.h @@ -12,13 +12,20 @@ namespace Input class Win32Mouse :public Mouse { public: - Win32Mouse(); + Win32Mouse(HWND target); ~Win32Mouse(); - bool IsBtnUp(Enum::SAMI key) override; - bool IsBtnDown(Enum::SAMI key) override; + bool IsBtnUp(Enum::SAMI key) const override; + bool IsBtnDown(Enum::SAMI key) const override; + int GetWheelDelta() const override; + Struct::SAIPointInt2D& GetPixelPosition(Struct::SAIPointInt2D &targetMem = Struct::SAIPointInt2D()) const override; + Struct::SAIPointFloat2D& GetNormalizedPosition(Struct::SAIPointFloat2D &targetMem = Struct::SAIPointFloat2D()) const override; + Struct::SAIPointFloat2D& GetDeltaPosition(Struct::SAIPointFloat2D& targetMem = Struct::SAIPointFloat2D()) const override; + void SetInputOptionType(Enum::InputOptionType options) override; + bool IsInputOptionSuported(Enum::InputOptionType options) const override; void ProccessMouseData (RAWMOUSE mouse); + bool Create( ); private: struct Buttons @@ -26,8 +33,10 @@ namespace Input unsigned int makeCode; bool isDown; }; - static const int MAXBUTTONS = 25; - Buttons buttons[25]; + static const int MAXBUTTONS =Enum::SAMI_Unknown; + Buttons buttons[MAXBUTTONS]; + RAWINPUTDEVICE device; + Struct::SAIPointInt2D windowSize; }; } diff --git a/Code/Misc/Input/Source/Mouse.cpp b/Code/Misc/Input/Source/Mouse.cpp index 103e1342..69a92477 100644 --- a/Code/Misc/Input/Source/Mouse.cpp +++ b/Code/Misc/Input/Source/Mouse.cpp @@ -165,7 +165,7 @@ void Mouse::InternalOnBtnRelease(Enum::SAMI btn) w = w->next; } } -void Mouse::InternalOnMove(Struct::SAIPoint2D cord) +void Mouse::InternalOnMove(Struct::SAIPointInt2D cord) { for (unsigned int i = 0; i < this->mouseSubscribers.size(); i++) { @@ -200,23 +200,6 @@ void Mouse::InternalOnScroll(int delta) -int Mouse::GetWheelDelta() const -{ - return this->wheelDelta; -} -SAIPoint2D & Mouse::GetPixelPosition( Struct::SAIPoint2D &targetMem ) const -{ - targetMem.x = this->pixelPos.x; - targetMem.y = this->pixelPos.y; - return targetMem; -} -SAIPoint2D & Mouse::GetDeltaPosition( Struct::SAIPoint2D &targetMem ) const -{ - targetMem.x = this->deltaPos.x; - targetMem.y = this->deltaPos.y; - return targetMem; -} - void Mouse::AddOnMousePressCallback( Typedefs::OnMousePressCallback func) { MouseCallbackList::CallbackData d; diff --git a/Code/Misc/Input/Source/Win32/Win32Input.cpp b/Code/Misc/Input/Source/Win32/Win32Input.cpp index d3ff2a0a..94bd42e1 100644 --- a/Code/Misc/Input/Source/Win32/Win32Input.cpp +++ b/Code/Misc/Input/Source/Win32/Win32Input.cpp @@ -16,7 +16,6 @@ using namespace Input::Enum; using namespace Input::Struct; using namespace Input::Typedefs; - Win32Input *Win32Input::instance = 0; LRESULT Win32Input::RawInputParser(HWND h, LPARAM l) @@ -88,14 +87,6 @@ LRESULT CALLBACK Win32Input::RawWindowCallback(HWND h, UINT m, WPARAM w, LPARAM case WM_INPUT: return Win32Input::instance->RawInputParser(h, l); break; - - case WM_KEYDOWN: - val = 0; - break; - - case WM_CHAR: - val = 0; - break; case WM_ACTIVATE: Win32Input::instance->WindowActivate((w == TRUE)); @@ -115,7 +106,7 @@ void Win32Input::WindowActivate(bool activate) } else { - ShowCursor(0); + ShowCursor(1); } } @@ -151,55 +142,46 @@ InputObject* Win32Input::CreateDevice(const SAIType inputType, Typedefs::WindowH { if(!this->instance->targetHwin) { - this->targetHwin = CreateWindowExW( 0, L"RawInputCallbackFunc" , NULL, NULL, NULL, NULL, NULL, - NULL, (HWND)targetApplication, NULL, (HINSTANCE)GetModuleHandle(0), NULL ); + RECT rc; + GetWindowRect((HWND)targetApplication, &rc); + + AdjustWindowRect(&rc, GetWindowStyle((HWND)targetApplication), FALSE); + + this->targetHwin = CreateWindowExW( 0, L"RawInputCallbackFunc" , NULL, NULL, rc.left, rc.top, rc.right, rc.bottom, + (HWND)targetApplication, NULL, (HINSTANCE)GetModuleHandle(0), NULL ); } + InputObject* val = 0; - RAWINPUTDEVICE rid; - rid.usUsagePage = 0x01; - rid.hwndTarget = this->instance->targetHwin; switch (inputType) { case SAIType_Keyboard: { - rid.usUsage = RawInput_Usage_keyboard; - rid.dwFlags = RIDEV_NOLEGACY; - if(RegisterRawInputDevices(&rid, 1, sizeof(RAWINPUTDEVICE)) == TRUE) - { - Win32Keyboard* obj = new Win32Keyboard(); - this->keyboard.push_back(obj); - val = obj; - } - else + Win32Keyboard* obj = new Win32Keyboard(this->targetHwin); + if(!obj->Create()) { + delete obj; return 0; } + + this->keyboard.push_back(obj); + val = obj; } break; case SAIType_Mouse: { - rid.usUsage = RawInput_Usage_mouse; - rid.dwFlags = RIDEV_NOLEGACY | RIDEV_CAPTUREMOUSE; - if(RegisterRawInputDevices(&rid, 1, sizeof(RAWINPUTDEVICE)) == TRUE) - { - int i = 0; - val = (InputObject*)1; - Win32Mouse* obj = new Win32Mouse(); - this->mouse.push_back(obj); - val = obj; - } - else + Win32Mouse* obj = new Win32Mouse(this->targetHwin); + if(!obj->Create()) { + delete obj; return 0; } + + this->mouse.push_back(obj); + val = obj; } break; - - //case SAIType_ApplicationKeyboard: - // //val = new Win32ApplicationKeyboard(); - // break; } return val; diff --git a/Code/Misc/Input/Source/Win32/Win32Keyboard.cpp b/Code/Misc/Input/Source/Win32/Win32Keyboard.cpp index e587f5c8..cde1dace 100644 --- a/Code/Misc/Input/Source/Win32/Win32Keyboard.cpp +++ b/Code/Misc/Input/Source/Win32/Win32Keyboard.cpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////// // Created by [Dennis Andersen] [2013] ///////////////////////////////////////////////////////////////////// -#include "..\..\Include\Win32\Win32Keyboard.h" +#include "..\..\Include\Win32\Win32Input.h" #include #pragma warning ( disable : 4172 ) @@ -10,8 +10,12 @@ using namespace Input::Enum; using namespace std; -Win32Keyboard::Win32Keyboard() +Win32Keyboard::Win32Keyboard(HWND target) { + this->device.usUsagePage = 0x01; + this->device.hwndTarget = target; + this->device.usUsage = RawInput_Usage_keyboard; + this->device.dwFlags = RIDEV_NOLEGACY; memset(&this->keys[0], 0, sizeof(Win32Keyboard::Keys) * MAXKEYS); } Win32Keyboard::~Win32Keyboard() @@ -37,6 +41,43 @@ wchar_t* Win32Keyboard::GetAsText(Enum::SAKI key) GetKeyNameTextW((LONG)temp, buff, 16); return buff; } +void Win32Keyboard::SetInputOptionType(Enum::InputOptionType options) +{ + if(! IsInputOptionSuported(options) ) return; + if(this->inputMode == options) return; + + this->inputMode = options; + switch (options) + { + case Input::Enum::InputOptionType_RawInput: + { + if(!Create()) + printf("Warning! Could not create the specific device"); + } + break; + case Input::Enum::InputOptionType_PlatformDefault: + { + RAWINPUTDEVICE d; + d.usUsagePage = 0x01; + d.hwndTarget = 0; + d.usUsage = RawInput_Usage_keyboard; + d.dwFlags = RIDEV_REMOVE; + + RegisterRawInputDevices(&d, 1, sizeof(RAWINPUTDEVICE)); + } + break; + } +} +bool Win32Keyboard::IsInputOptionSuported(Enum::InputOptionType options) const +{ + switch (options) + { + case Input::Enum::InputOptionType_RawInput: return true; + case Input::Enum::InputOptionType_PlatformDefault: return true; + } + return false; +} + void Win32Keyboard::ProccessKeyboardData (RAWKEYBOARD keyboard) { if(!this->active) @@ -639,6 +680,15 @@ void Win32Keyboard::MapKey(RAWKEYBOARD& rawKB, SAKI& out_key, bool& isE0) break; } } +bool Win32Keyboard::Create() +{ + if(RegisterRawInputDevices(&this->device, 1, sizeof(RAWINPUTDEVICE)) == TRUE) + { + return true; + } + + return false; +} diff --git a/Code/Misc/Input/Source/Win32/Win32Mouse.cpp b/Code/Misc/Input/Source/Win32/Win32Mouse.cpp index a05db67c..9b875319 100644 --- a/Code/Misc/Input/Source/Win32/Win32Mouse.cpp +++ b/Code/Misc/Input/Source/Win32/Win32Mouse.cpp @@ -1,14 +1,14 @@ ///////////////////////////////////////////////////////////////////// // Created by [Dennis Andersen] [2013] ///////////////////////////////////////////////////////////////////// -#include "..\..\Include\Win32\Win32Mouse.h" +#include "..\..\Include\Win32\Win32Input.h" using namespace Input; using namespace Input::Enum; using namespace Input::Struct; using namespace Input::Typedefs; -void MapButton(RAWMOUSE& rawMouse, bool &isUp, Enum::SAMI& btn, int& delta, Struct::SAIPoint2D& vel, unsigned int& mcode) +void MapButton(RAWMOUSE& rawMouse, bool &isUp, Enum::SAMI& btn, int& delta, Struct::SAIPointInt2D& vel, unsigned int& mcode) { if(rawMouse.lLastX != 0 || rawMouse.lLastY != 0) { @@ -63,41 +63,119 @@ void MapButton(RAWMOUSE& rawMouse, bool &isUp, Enum::SAMI& btn, int& delta, Stru } -Win32Mouse::Win32Mouse() +Win32Mouse::Win32Mouse(HWND target) { + this->device.usUsagePage = 0x01; + this->device.hwndTarget = target; + this->device.usUsage = RawInput_Usage_mouse; + this->device.dwFlags = RIDEV_NOLEGACY | RIDEV_CAPTUREMOUSE; memset(&this->buttons[0], 0, sizeof(Buttons) * MAXBUTTONS); } Win32Mouse::~Win32Mouse() -{ -} +{ } -bool Win32Mouse::IsBtnUp(Enum::SAMI btn) +bool Win32Mouse::IsBtnUp(Enum::SAMI btn) const { if(btn == SAMI_Unknown) return false; return !this->buttons[btn].isDown; } -bool Win32Mouse::IsBtnDown(Enum::SAMI btn) +bool Win32Mouse::IsBtnDown(Enum::SAMI btn) const { if(btn == SAMI_Unknown) return false; return this->buttons[btn].isDown; } +int Win32Mouse::GetWheelDelta() const +{ + return this->wheelDelta; +} +SAIPointInt2D& Win32Mouse::GetPixelPosition( Struct::SAIPointInt2D &targetMem ) const +{ + memcpy(&targetMem, &this->pixelPos, sizeof(SAIPointFloat2D)); + + return targetMem; +} +SAIPointFloat2D& Win32Mouse::GetNormalizedPosition(Struct::SAIPointFloat2D& targetMem) const +{ + memcpy(&targetMem, &this->normalPos, sizeof(SAIPointFloat2D)); + + return targetMem; +} +SAIPointFloat2D& Win32Mouse::GetDeltaPosition(Struct::SAIPointFloat2D& targetMem) const +{ + memcpy(&targetMem, &this->deltaPos, sizeof(SAIPointFloat2D)); + + return targetMem; +} + +void Win32Mouse::SetInputOptionType(Enum::InputOptionType options) +{ + if(! IsInputOptionSuported(options) ) return; + + this->inputMode = options; + switch (options) + { + case Input::Enum::InputOptionType_RawInput: + { + if(!Create()) + printf("Warning! Could not create the specific device"); + } + break; + case Input::Enum::InputOptionType_PlatformDefault: + { + RAWINPUTDEVICE d; + d.usUsagePage = 0x01; + d.hwndTarget = 0; + d.usUsage = RawInput_Usage_mouse; + d.dwFlags = RIDEV_REMOVE; + + RegisterRawInputDevices(&d, 1, sizeof(RAWINPUTDEVICE)); + } + break; + } +} +bool Win32Mouse::IsInputOptionSuported(Enum::InputOptionType options) const +{ + switch (options) + { + case Input::Enum::InputOptionType_RawInput: return true; + case Input::Enum::InputOptionType_PlatformDefault: return true; + } + return false; +} void Win32Mouse::ProccessMouseData (RAWMOUSE mouse) { bool isUp = true; Enum::SAMI btn = Enum::SAMI_Unknown; int delta = 0; - Struct::SAIPoint2D velocity; + Struct::SAIPointInt2D velocity; unsigned int makeCode = 0; MapButton(mouse, isUp, btn, delta, velocity, makeCode); if(velocity.Length() != 0) { - this->pixelPos.x += this->deltaPos.x = velocity.x; - this->pixelPos.y += this->deltaPos.y = velocity.y; + this->pixelPos.x += velocity.x; + this->pixelPos.y += velocity.y; + + //Contain + if(this->pixelPos.x < 0) { this->pixelPos.x = 0; } + else if(this->pixelPos.x > this->windowSize.x) { this->pixelPos.x = this->windowSize.x; } + if(this->pixelPos.y < 0) { this->pixelPos.y = 0; } + else if(this->pixelPos.y > this->windowSize.y) { this->pixelPos.y = this->windowSize.y; } + + + RECT windowVertex; + GetWindowRect( this->device.hwndTarget, &windowVertex ); + + this->normalPos.x = (float)(pixelPos.x - windowVertex.left); + this->normalPos.x /= (float)(windowVertex.right - windowVertex.left); + + this->normalPos.y = (float)(pixelPos.y - windowVertex.top); + this->normalPos.y /= (float)(windowVertex.bottom - windowVertex.top); + InternalOnMove(this->pixelPos); } @@ -130,4 +208,32 @@ void Win32Mouse::ProccessMouseData (RAWMOUSE mouse) InternalOnBtnPress(btn); } } -} \ No newline at end of file +} +bool Win32Mouse::Create() +{ + if(!this->device.hwndTarget) + { + RECT desktop; + const HWND hDesktop = GetDesktopWindow(); + GetWindowRect(hDesktop, &desktop); + windowSize.x = desktop.right; + windowSize.y = desktop.bottom; + this->device.dwFlags = 0; + } + else + { + RECT re; + GetWindowRect(this->device.hwndTarget, &re); + windowSize.x = re.right; + windowSize.y = re.bottom; + } + + if(RegisterRawInputDevices(&this->device, 1, sizeof(RAWINPUTDEVICE)) == TRUE) + { + return true; + } + + return false; +} + + From 2d788137b2e4cdeabeeb6378411a5f2cac391b2f Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Mon, 24 Feb 2014 13:15:01 +0100 Subject: [PATCH 15/32] Dans Raw device lab demo To be reverted --- Code/DanBias.sln | 37 +++ .../RawDeviceLab/RawDeviceLab.vcxproj | 72 ++++++ Code/LabProjects/RawDeviceLab/main.cpp | 243 ++++++++++++++++++ 3 files changed, 352 insertions(+) create mode 100644 Code/LabProjects/RawDeviceLab/RawDeviceLab.vcxproj create mode 100644 Code/LabProjects/RawDeviceLab/main.cpp diff --git a/Code/DanBias.sln b/Code/DanBias.sln index 033e050e..6835e750 100644 --- a/Code/DanBias.sln +++ b/Code/DanBias.sln @@ -49,6 +49,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LevelLoader", "Game\LevelLo EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GameServerDebugEnvironment", "Game\LanServer\GameServerDebugEnvironment\GameServerDebugEnvironment.vcxproj", "{67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Lab", "Lab", "{46A660B9-6BE9-411C-B366-235FD8F8A9BD}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RawDeviceLab", "LabProjects\RawDeviceLab\RawDeviceLab.vcxproj", "{32DD438B-8C9C-49EF-9EA5-EB48951D869A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -751,6 +755,38 @@ Global {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.RelWithDebInfo|x64.ActiveCfg = Release|Win32 {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.RelWithDebInfo|x86.ActiveCfg = Release|Win32 {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.RelWithDebInfo|x86.Build.0 = Release|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Debug|Win32.ActiveCfg = Debug|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Debug|Win32.Build.0 = Debug|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Debug|x64.ActiveCfg = Debug|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Debug|x86.ActiveCfg = Debug|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Debug|x86.Build.0 = Debug|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.MinSizeRel|Any CPU.ActiveCfg = Release|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.MinSizeRel|Mixed Platforms.ActiveCfg = Release|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.MinSizeRel|Mixed Platforms.Build.0 = Release|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.MinSizeRel|Win32.ActiveCfg = Release|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.MinSizeRel|Win32.Build.0 = Release|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.MinSizeRel|x64.ActiveCfg = Release|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.MinSizeRel|x86.ActiveCfg = Release|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.MinSizeRel|x86.Build.0 = Release|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Release|Any CPU.ActiveCfg = Release|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Release|Mixed Platforms.Build.0 = Release|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Release|Win32.ActiveCfg = Release|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Release|Win32.Build.0 = Release|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Release|x64.ActiveCfg = Release|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Release|x86.ActiveCfg = Release|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Release|x86.Build.0 = Release|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.RelWithDebInfo|Mixed Platforms.ActiveCfg = Release|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.RelWithDebInfo|Mixed Platforms.Build.0 = Release|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.RelWithDebInfo|Win32.ActiveCfg = Release|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.RelWithDebInfo|Win32.Build.0 = Release|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.RelWithDebInfo|x64.ActiveCfg = Release|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.RelWithDebInfo|x86.ActiveCfg = Release|Win32 + {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.RelWithDebInfo|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -774,5 +810,6 @@ Global {604A12A7-07BF-4482-BDF3-7101C811F121} = {C83A6FAD-E71F-4B1E-9D63-E93E61DDC012} {C8CBA520-5D7D-4D61-A8DA-6E05FD132BCB} = {C83A6FAD-E71F-4B1E-9D63-E93E61DDC012} {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE} = {C83A6FAD-E71F-4B1E-9D63-E93E61DDC012} + {32DD438B-8C9C-49EF-9EA5-EB48951D869A} = {46A660B9-6BE9-411C-B366-235FD8F8A9BD} EndGlobalSection EndGlobal diff --git a/Code/LabProjects/RawDeviceLab/RawDeviceLab.vcxproj b/Code/LabProjects/RawDeviceLab/RawDeviceLab.vcxproj new file mode 100644 index 00000000..27eb0513 --- /dev/null +++ b/Code/LabProjects/RawDeviceLab/RawDeviceLab.vcxproj @@ -0,0 +1,72 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {32DD438B-8C9C-49EF-9EA5-EB48951D869A} + Test + + + + Application + true + v110 + MultiByte + + + Application + false + v110 + true + MultiByte + + + + + + + + + + + + + + + Level3 + Disabled + true + + + true + + + + + Level3 + MaxSpeed + true + true + true + + + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/Code/LabProjects/RawDeviceLab/main.cpp b/Code/LabProjects/RawDeviceLab/main.cpp new file mode 100644 index 00000000..b636fbe7 --- /dev/null +++ b/Code/LabProjects/RawDeviceLab/main.cpp @@ -0,0 +1,243 @@ +#include + +const unsigned short raw_input_usage_keyboard = 6; +const unsigned short raw_input_usage_mouse = 2; +HWND winHandle; +bool isPointAndClickMode; +float normalizedMousePosX, normalizedMousePosY; + +LRESULT CALLBACK RawWindowCallback(HWND h, UINT m, WPARAM w, LPARAM l); +LRESULT RawInputParser(HWND h, LPARAM l); +void Update( ); + +//int main() +int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdShow) +{ + WNDCLASSEXW wc; + wc.cbSize = sizeof(WNDCLASSEXW); + wc.hIconSm = NULL; + wc.style = NULL; + wc.lpfnWndProc = RawWindowCallback; + wc.cbClsExtra = NULL; + wc.cbWndExtra = NULL; + wc.hInstance = hinst; + wc.hIcon = NULL; + wc.hCursor = NULL; + wc.hbrBackground = NULL; + wc.lpszMenuName = NULL; + wc.lpszClassName = L"RawInputTest"; + + if( !RegisterClassExW(&wc) ) + { + const char *breakpoint = ""; + } + + winHandle = CreateWindowExW( 0, L"RawInputTest", L"RawInputTest", WS_OVERLAPPEDWINDOW | WS_CAPTION, 0, 0, 600, 400, NULL, NULL, hinst, NULL ); + ShowWindow( winHandle, cmdShow ); + + if( !winHandle ) + { + const char *breakpoint = ""; + } + + isPointAndClickMode = true; + normalizedMousePosX = + normalizedMousePosY = 0.5f; + + MSG msg = {0}; + while( true ) + { + if( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) ) + { + if (msg.message == WM_QUIT) break; + DispatchMessage(&msg); + } + else + { + Update(); + } + } + return 0; +} + +LRESULT CALLBACK RawWindowCallback(HWND h, UINT m, WPARAM w, LPARAM l) +{ + LRESULT val = 0; + switch (m) + { + case WM_INPUT: + { + RawInputParser( h, l ); + } + break; + case WM_KEYUP: + { + if( w == 16 ) + { + const char *breakpoint = ""; + + RAWINPUTDEVICE rid; + rid.usUsagePage = 0x01; + rid.hwndTarget = winHandle; + rid.usUsage = raw_input_usage_keyboard; + rid.dwFlags = RIDEV_NOLEGACY; + if( RegisterRawInputDevices(&rid, 1, sizeof(RAWINPUTDEVICE)) == FALSE ) + { + const char *breakpoint = ""; + } + } + } + break; + case WM_RBUTTONUP: + { + const char *breakpoint = ""; + + RAWINPUTDEVICE rid; + rid.usUsagePage = 0x01; + rid.hwndTarget = winHandle; + rid.usUsage = raw_input_usage_mouse; + rid.dwFlags = RIDEV_NOLEGACY | RIDEV_CAPTUREMOUSE; + if( RegisterRawInputDevices(&rid, 1, sizeof(RAWINPUTDEVICE)) == TRUE ) + { + ShowCursor( false ); + isPointAndClickMode = false; + } + else + { + const char *breakpoint = ""; + } + } + break; + case WM_ACTIVATE: + { + const char *breakpoint = ""; + } + break; + break; + case WM_CREATE: + { + const char *breakpoint = ""; + } + break; + case WM_DESTROY: + PostQuitMessage( 0 ); + break; + default: break; + } + + return DefWindowProc(h, m, w, l); +} + +LRESULT RawInputParser(HWND h, LPARAM l) +{ + //Get The size of the raw data buffer + UINT bufferSize; + GetRawInputData((HRAWINPUT)l, RID_INPUT, NULL, &bufferSize, sizeof(RAWINPUTHEADER)); + if (bufferSize < 1) + { return 0; } + + //Create and read the raw input data + LPBYTE rawBuffer = new BYTE[bufferSize]; + UINT readBytes = GetRawInputData((HRAWINPUT)l, RID_INPUT, rawBuffer, &bufferSize, sizeof(RAWINPUTHEADER)); + if ( readBytes != bufferSize ) + { + delete [] rawBuffer; + return 0; + } + + HRESULT result = 0; + RAWINPUT* raw = (RAWINPUT*)rawBuffer; + + if( raw->header.dwType == RIM_TYPEKEYBOARD ) + { + if( (raw->data.keyboard.Flags & RI_KEY_BREAK) && raw->data.keyboard.VKey == 16 ) + { + const char *breakpoint = ""; + + RAWINPUTDEVICE rid; + rid.usUsagePage = 0x01; + rid.hwndTarget = NULL; + rid.usUsage = raw_input_usage_keyboard; + rid.dwFlags = RIDEV_REMOVE; + if( RegisterRawInputDevices(&rid, 1, sizeof(RAWINPUTDEVICE)) == FALSE ) + { + const char *breakpoint = ""; + } + } + } + else if( raw->header.dwType == RIM_TYPEMOUSE ) + { + if( raw->data.mouse.usButtonFlags & RI_MOUSE_MIDDLE_BUTTON_UP ) + { + const char *breakpoint = ""; + + RAWINPUTDEVICE rid; + rid.usUsagePage = 0x01; + rid.hwndTarget = NULL; + rid.usUsage = raw_input_usage_mouse; + rid.dwFlags = RIDEV_REMOVE; + if( RegisterRawInputDevices(&rid, 1, sizeof(RAWINPUTDEVICE)) == TRUE ) + { + RECT winRect; + GetWindowRect( winHandle, &winRect ); + SetCursorPos( (winRect.left + winRect.right) >> 1, (winRect.top + winRect.bottom) >> 1 ); + isPointAndClickMode = true; + } + else + { + const char *breakpoint = ""; + } + } + } + else result = DefRawInputProc(&raw, 1, sizeof(RAWINPUTHEADER)); + + delete [] rawBuffer; + return result; +} + +void Update( ) +{ + if( isPointAndClickMode ) + { + { // Calculating and storing the normalizedMousePos values + POINT clientReach, clientCenter, mousePos; + + RECT winRect, clientRect; + GetClientRect( winHandle, &clientRect ); + GetWindowRect( winHandle, &winRect ); + + LONG borderThickness = (winRect.right - winRect.left - clientRect.right) >> 1; + + clientReach.x = clientRect.right >> 1; + clientReach.y = clientRect.bottom >> 1; + + clientCenter.x = (winRect.left + winRect.right) >> 1; + clientCenter.y = winRect.bottom - clientReach.y - borderThickness; + + GetCursorPos( &mousePos ); + + normalizedMousePosX = ((float)(mousePos.x - clientCenter.x + clientReach.x)) / (float)clientRect.right; + normalizedMousePosY = ((float)(mousePos.y - clientCenter.y + clientReach.y)) / (float)clientRect.bottom; + } + + // Check if normalizedMousePos intersects client surface [(0,0), (1,1)] + bool mouseIsNowWithinBounds = true; + if ( normalizedMousePosX < 0.0f ) mouseIsNowWithinBounds = false; + else if( normalizedMousePosX > 1.0f ) mouseIsNowWithinBounds = false; + else if( normalizedMousePosY < 0.0f ) mouseIsNowWithinBounds = false; + else if( normalizedMousePosY > 1.0f ) mouseIsNowWithinBounds = false; + + // Detect onEnter or onExit case + static bool mouseWereWithinBounds = false; + if( mouseIsNowWithinBounds & !mouseWereWithinBounds ) + { // onEnter + ShowCursor( false ); + mouseWereWithinBounds = mouseIsNowWithinBounds; + } + else if( !mouseIsNowWithinBounds & mouseWereWithinBounds ) + { // onExit + ShowCursor( true ); + mouseWereWithinBounds = mouseIsNowWithinBounds; + } + } +} \ No newline at end of file From cc17f80fd72c78c0fc9074e6d922d07397862857 Mon Sep 17 00:00:00 2001 From: dean11 Date: Mon, 24 Feb 2014 16:01:06 +0100 Subject: [PATCH 16/32] Input - Added toggle for input --- Code/Misc/Input/Include/Common.h | 20 ++- Code/Misc/Input/Include/Input.h | 1 - Code/Misc/Input/Include/InputManager.h | 6 +- Code/Misc/Input/Include/Keyboard.h | 33 +++-- Code/Misc/Input/Include/Mouse.h | 55 ++++---- Code/Misc/Input/Include/Win32/Win32Input.h | 2 - Code/Misc/Input/Include/Win32/Win32Keyboard.h | 11 +- Code/Misc/Input/Include/Win32/Win32Mouse.h | 22 +++- Code/Misc/Input/Source/Keyboard.cpp | 18 +-- Code/Misc/Input/Source/Mouse.cpp | 71 +++++----- Code/Misc/Input/Source/Win32/Win32Input.cpp | 78 +++++------ .../Misc/Input/Source/Win32/Win32Keyboard.cpp | 79 +++++++++++- Code/Misc/Input/Source/Win32/Win32Mouse.cpp | 121 ++++++++++++++++-- Code/Misc/WindowManager/WindowShell.cpp | 23 ++-- Code/Misc/WindowManager/WindowShell.h | 2 +- 15 files changed, 370 insertions(+), 172 deletions(-) diff --git a/Code/Misc/Input/Include/Common.h b/Code/Misc/Input/Include/Common.h index eed90eb7..694001a3 100644 --- a/Code/Misc/Input/Include/Common.h +++ b/Code/Misc/Input/Include/Common.h @@ -26,6 +26,11 @@ namespace Input SAIType_futureExample2, SAIType_futureExample3, }; + enum InputOptionType + { + InputOptionType_RawInput, + InputOptionType_PlatformDefault, + }; enum ButtonState { ButtonState_Press, // When button is pressed (once) @@ -37,15 +42,24 @@ namespace Input /*********************************************************************/ namespace Struct { - struct SAIPoint2D + struct SAIPointInt2D { int x; int y; - SAIPoint2D() :x(0), y(0) { } - SAIPoint2D(int _x, int _y) :x(_x), y(_y) { } + SAIPointInt2D() :x(0), y(0) { } + SAIPointInt2D(int _x, int _y) :x(_x), y(_y) { } int Length() { return (abs(x) + abs(y)); } }; + struct SAIPointFloat2D + { + float x; + float y; + SAIPointFloat2D() :x(0.0f), y(0.0f) { } + SAIPointFloat2D(float _x, float _y) :x(_x), y(_y) { } + float Length() { return (fabs(x) + fabs(y)); } + }; + struct InputData; } /*********************************************************************/ diff --git a/Code/Misc/Input/Include/Input.h b/Code/Misc/Input/Include/Input.h index bd3c7a33..3de235ca 100644 --- a/Code/Misc/Input/Include/Input.h +++ b/Code/Misc/Input/Include/Input.h @@ -7,7 +7,6 @@ #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/InputManager.h b/Code/Misc/Input/Include/InputManager.h index 237fb179..1feff9cf 100644 --- a/Code/Misc/Input/Include/InputManager.h +++ b/Code/Misc/Input/Include/InputManager.h @@ -37,9 +37,9 @@ namespace Input * @see InputDescription * @return Returns a handle to a device that can be rethrown to a specific device. */ - virtual InputObject* CreateDevice ( const Enum::SAIType inputType, Typedefs::WindowHandle targetApplication = 0 ) = 0; - virtual Keyboard* CreateKeyboardDevice ( Typedefs::WindowHandle targetApplication = 0 ) { return (Keyboard*)CreateDevice(Enum::SAIType_Keyboard, targetApplication); } - virtual Mouse* CreateMouseDevice ( Typedefs::WindowHandle targetApplication = 0 ) { return (Mouse*)CreateDevice(Enum::SAIType_Mouse, targetApplication); } + virtual InputObject* CreateDevice ( const Enum::SAIType inputType, Typedefs::WindowHandle targetApplication ) = 0; + virtual Keyboard* CreateKeyboardDevice ( Typedefs::WindowHandle targetApplication ) { return (Keyboard*)CreateDevice(Enum::SAIType_Keyboard, targetApplication); } + virtual Mouse* CreateMouseDevice ( Typedefs::WindowHandle targetApplication ) { return (Mouse*)CreateDevice(Enum::SAIType_Mouse, targetApplication); } /** Enables or Disables the Input proccessing. * @param The toggler. diff --git a/Code/Misc/Input/Include/Keyboard.h b/Code/Misc/Input/Include/Keyboard.h index c2568e3b..4db0bce6 100644 --- a/Code/Misc/Input/Include/Keyboard.h +++ b/Code/Misc/Input/Include/Keyboard.h @@ -49,6 +49,10 @@ namespace Input SAKI_7 , SAKI_8 , SAKI_9 , + SAKI_Add , + SAKI_Comma , + SAKI_Minus , + SAKI_Period , SAKI_A , SAKI_B , SAKI_C , @@ -133,9 +137,9 @@ namespace Input //----------------------------------------------------------------------------------------------------------------------------- namespace Typedefs { - typedef void(*OnKeyPressCallback)(Enum::SAKI key, const wchar_t[16], Keyboard* sender); - typedef void(*OnKeyDownCallback)(Enum::SAKI key, const wchar_t[16], Keyboard* sender); - typedef void(*OnKeyReleaseCallback)(Enum::SAKI key, const wchar_t[16], Keyboard* sender); + typedef void(*OnKeyPressCallback)(Enum::SAKI key, Keyboard* sender); + typedef void(*OnKeyDownCallback)(Enum::SAKI key, Keyboard* sender); + typedef void(*OnKeyReleaseCallback)(Enum::SAKI key, Keyboard* sender); } //----------------------------------------------------------------------------------------------------------------------------- @@ -145,9 +149,9 @@ namespace Input class KeyboardEvent { public: - virtual void OnKeyPress(Enum::SAKI key, const wchar_t[40], Keyboard* sender) { } - virtual void OnKeyDown(Enum::SAKI key, const wchar_t[40], Keyboard* sender) { } - virtual void OnKeyRelease(Enum::SAKI key, const wchar_t[40], Keyboard* sender) { } + virtual void OnKeyPress(Enum::SAKI key, Keyboard* sender) { } + virtual void OnKeyDown(Enum::SAKI key, Keyboard* sender) { } + virtual void OnKeyRelease(Enum::SAKI key, Keyboard* sender) { } }; public: /* Manual check functions */ @@ -157,6 +161,11 @@ namespace Input virtual bool IsKeyDown (Enum::SAKI key) = 0; virtual wchar_t* GetAsText(Enum::SAKI key) = 0; + public: /* From InputObject */ + virtual void Activate () override = 0; + virtual void Deactivate () override = 0; + virtual bool IsActive() override = 0; + public: /* global subscribe callback functions */ void AddOnKeyPressCallback (Typedefs::OnKeyPressCallback func); void AddOnKeyDownCallback (Typedefs::OnKeyDownCallback func); @@ -166,11 +175,6 @@ namespace Input void RemoveOnKeyDownCallback (Typedefs::OnKeyDownCallback func); void RemoveOnKeyReleaseCallback (Typedefs::OnKeyReleaseCallback func); - public: /* From InputObject */ - virtual void Activate () override { this->active = true; } - virtual void Deactivate () override { this->active = false; } - virtual bool IsActive() override { return this->active; } - public: void operator+= (KeyboardEvent* object); void operator-= (KeyboardEvent* object); @@ -185,9 +189,9 @@ namespace Input Keyboard(); protected: /* Internal event proc */ - void InternalOnKeyPress(Enum::SAKI key, wchar_t text[16]); - void InternalOnKeyDown(Enum::SAKI key, wchar_t text[16]); - void InternalOnKeyRelease(Enum::SAKI key, wchar_t text[16]); + void InternalOnKeyPress(Enum::SAKI key); + void InternalOnKeyDown(Enum::SAKI key); + void InternalOnKeyRelease(Enum::SAKI key); protected: std::vector keyEventSubscrivers; @@ -195,6 +199,7 @@ namespace Input ::std::wstring* textTarget; ::std::wstring::size_type writePos; bool active; + Enum::InputOptionType inputMode; }; } diff --git a/Code/Misc/Input/Include/Mouse.h b/Code/Misc/Input/Include/Mouse.h index 56f7884f..f83a71a5 100644 --- a/Code/Misc/Input/Include/Mouse.h +++ b/Code/Misc/Input/Include/Mouse.h @@ -47,7 +47,8 @@ namespace Input typedef void(*OnMousePressCallback)(Enum::SAMI btn, Mouse* sender); typedef void(*OnMouseDownCallback)(Enum::SAMI btn, Mouse* sender); typedef void(*OnMouseReleaseCallback)(Enum::SAMI btn, Mouse* sender); - typedef void(*OnMouseMoveCallback)(Struct::SAIPoint2D cord, Mouse* sender); + typedef void(*OnMouseMovePixelPosCallback)(Struct::SAIPointInt2D cord, Mouse* sender); + typedef void(*OnMouseMoveVelocityCallback)(Struct::SAIPointInt2D cord, Mouse* sender); typedef void(*OnMouseScrollCallback)(int delta, Mouse* sender); } //----------------------------------------------------------------------------------------------------------------------------- @@ -59,41 +60,42 @@ namespace Input class MouseEvent { public: - virtual void OnMousePress ( Enum::SAMI key, Mouse* sender ) { } - virtual void OnMouseDown ( Enum::SAMI key, Mouse* sender ) { } - virtual void OnMouseRelease ( Enum::SAMI key, Mouse* sender ) { } - virtual void OnMouseMove ( Struct::SAIPoint2D coordinate, Mouse* sender ) { } - virtual void OnMouseScroll ( int delta, Mouse* sender ) { } + virtual void OnMousePress ( Enum::SAMI key, Mouse* sender ) { } + virtual void OnMouseDown ( Enum::SAMI key, Mouse* sender ) { } + virtual void OnMouseRelease ( Enum::SAMI key, Mouse* sender ) { } + virtual void OnMouseMovePixelPos ( Struct::SAIPointInt2D coordinate, Mouse* sender ) { } + virtual void OnMouseMoveVelocity ( Struct::SAIPointInt2D coordinate, Mouse* sender ) { } + virtual void OnMouseScroll ( int delta, Mouse* sender ) { } }; public: /* Manual check functions */ - virtual ~Mouse(); + virtual bool IsBtnUp(Enum::SAMI key) const = 0; + virtual bool IsBtnDown(Enum::SAMI key) const = 0; + virtual int GetWheelDelta() const = 0; + virtual Struct::SAIPointInt2D& GetPixelPosition(Struct::SAIPointInt2D& targetMem = Struct::SAIPointInt2D()) const = 0; + virtual Struct::SAIPointFloat2D& GetNormalizedPosition(Struct::SAIPointFloat2D& targetMem = Struct::SAIPointFloat2D()) = 0; + virtual Struct::SAIPointFloat2D& GetDeltaPosition(Struct::SAIPointFloat2D& targetMem = Struct::SAIPointFloat2D()) const = 0; + + public: /* From InputObject */ + virtual void Activate () override = 0; + virtual void Deactivate () override = 0; + virtual bool IsActive() override = 0; - virtual bool IsBtnUp(Enum::SAMI key) = 0; - virtual bool IsBtnDown(Enum::SAMI key) = 0; - public: /* global subscribe callback functions */ - int GetWheelDelta() const; - Struct::SAIPoint2D & GetPixelPosition( Struct::SAIPoint2D &targetMem = Struct::SAIPoint2D() ) const; - Struct::SAIPoint2D & GetDeltaPosition( Struct::SAIPoint2D &targetMem = Struct::SAIPoint2D() ) const; - void AddOnMousePressCallback( Typedefs::OnMousePressCallback func); void AddOnMouseDownCallback( Typedefs::OnMouseDownCallback func ); void AddOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func ); - void AddOnMouseMoveCallback( Typedefs::OnMouseMoveCallback func ); + void AddOnMouseMovePixelPosCallback( Typedefs::OnMouseMovePixelPosCallback func ); + void AddOnMouseMoveVelocityCallback( Typedefs::OnMouseMoveVelocityCallback func ); void AddOnMouseScrollCallback( Typedefs::OnMouseScrollCallback func ); void RemoveOnMousePressCallback( Typedefs::OnMousePressCallback func); void RemoveOnMouseDownCallback( Typedefs::OnMouseDownCallback func ); void RemoveOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func ); - void RemoveOnMouseMoveCallback( Typedefs::OnMouseMoveCallback func ); + void RemoveOnMouseMovePixelPosCallback( Typedefs::OnMouseMovePixelPosCallback func ); + void RemoveOnMouseMoveVelocityCallback( Typedefs::OnMouseMoveVelocityCallback func ); void RemoveOnMouseScrollCallback( Typedefs::OnMouseScrollCallback func ); - public: /* From InputObject */ - virtual void Activate () override { this->active = true; } - virtual void Deactivate () override { this->active = false; } - virtual bool IsActive() override { return this->active; } - public: void operator+= (MouseEvent* object); void operator-= (MouseEvent* object); @@ -106,21 +108,26 @@ namespace Input protected: Mouse(); + virtual ~Mouse(); protected: void InternalOnBtnPress(Enum::SAMI key); void InternalOnBtnDown(Enum::SAMI key); void InternalOnBtnRelease(Enum::SAMI key); - void InternalOnMove(Struct::SAIPoint2D cord); + void InternalOnMove(Struct::SAIPointInt2D pixelPos, Struct::SAIPointInt2D velocity); void InternalOnScroll(int delta); protected: std::vector mouseSubscribers; MouseCallbackList* callbackList; - Struct::SAIPoint2D pixelPos, deltaPos; + Struct::SAIPointInt2D pixelPos; + Struct::SAIPointInt2D velocity; + Struct::SAIPointFloat2D normalPos; + Struct::SAIPointFloat2D deltaPos; + bool isCurorLocked; int wheelDelta; - bool active; + Enum::InputOptionType inputMode; }; } diff --git a/Code/Misc/Input/Include/Win32/Win32Input.h b/Code/Misc/Input/Include/Win32/Win32Input.h index e8306400..fb3fe4ec 100644 --- a/Code/Misc/Input/Include/Win32/Win32Input.h +++ b/Code/Misc/Input/Include/Win32/Win32Input.h @@ -8,7 +8,6 @@ #include "..\InputManager.h" #include "Win32Keyboard.h" #include "Win32Mouse.h" -#include "Win32ApplicationKeyboard.h" #include #define NOMINMAX #include @@ -57,7 +56,6 @@ namespace Input std::vector mouse; bool enabled; - bool exclusive; HWND targetHwin; private: diff --git a/Code/Misc/Input/Include/Win32/Win32Keyboard.h b/Code/Misc/Input/Include/Win32/Win32Keyboard.h index e2e0442c..8e9b2e7d 100644 --- a/Code/Misc/Input/Include/Win32/Win32Keyboard.h +++ b/Code/Misc/Input/Include/Win32/Win32Keyboard.h @@ -13,14 +13,20 @@ namespace Input class Win32Keyboard :public Keyboard { public: - Win32Keyboard(); + Win32Keyboard(HWND target); ~Win32Keyboard(); bool IsKeyUp (Enum::SAKI key) override; bool IsKeyDown (Enum::SAKI key) override; wchar_t* GetAsText(Enum::SAKI key) override; + public: /* From InputObject */ + void Activate () override; + void Deactivate () override; + inline bool IsActive() override { return this->isActive; } + void ProccessKeyboardData (RAWKEYBOARD keyboard); + bool Create( ); private: void MapKey(RAWKEYBOARD& rawKB, Enum::SAKI& out_key, bool& isE0); @@ -31,9 +37,10 @@ namespace Input bool isDown; unsigned int makecode; }; - + RAWINPUTDEVICE device; static const int MAXKEYS = 256; Keys keys[MAXKEYS]; + bool isActive; }; } diff --git a/Code/Misc/Input/Include/Win32/Win32Mouse.h b/Code/Misc/Input/Include/Win32/Win32Mouse.h index 71a37b2d..e36d83b6 100644 --- a/Code/Misc/Input/Include/Win32/Win32Mouse.h +++ b/Code/Misc/Input/Include/Win32/Win32Mouse.h @@ -12,13 +12,22 @@ namespace Input class Win32Mouse :public Mouse { public: - Win32Mouse(); + Win32Mouse(HWND target); ~Win32Mouse(); - bool IsBtnUp(Enum::SAMI key) override; - bool IsBtnDown(Enum::SAMI key) override; + bool IsBtnUp(Enum::SAMI key) const override; + bool IsBtnDown(Enum::SAMI key) const override; + int GetWheelDelta() const override; + Struct::SAIPointInt2D& GetPixelPosition(Struct::SAIPointInt2D &targetMem = Struct::SAIPointInt2D()) const override; + Struct::SAIPointFloat2D& GetNormalizedPosition(Struct::SAIPointFloat2D &targetMem = Struct::SAIPointFloat2D()) override; + Struct::SAIPointFloat2D& GetDeltaPosition(Struct::SAIPointFloat2D& targetMem = Struct::SAIPointFloat2D()) const override; + + void Activate () override; + void Deactivate () override; + inline bool IsActive() override { return this->isActive; } void ProccessMouseData (RAWMOUSE mouse); + bool Create( ); private: struct Buttons @@ -26,8 +35,11 @@ namespace Input unsigned int makeCode; bool isDown; }; - static const int MAXBUTTONS = 25; - Buttons buttons[25]; + static const int MAXBUTTONS =Enum::SAMI_Unknown; + Buttons buttons[MAXBUTTONS]; + RAWINPUTDEVICE device; + Struct::SAIPointInt2D windowSize; + bool isActive; }; } diff --git a/Code/Misc/Input/Source/Keyboard.cpp b/Code/Misc/Input/Source/Keyboard.cpp index 8f99e8fe..a35f75a5 100644 --- a/Code/Misc/Input/Source/Keyboard.cpp +++ b/Code/Misc/Input/Source/Keyboard.cpp @@ -112,13 +112,13 @@ Keyboard::~Keyboard() } -void Keyboard::InternalOnKeyPress(Enum::SAKI key, wchar_t text[16]) +void Keyboard::InternalOnKeyPress(Enum::SAKI key) { for (unsigned int i = 0; i < this->keyEventSubscrivers.size(); i++) { if(this->keyEventSubscrivers[i]) { - this->keyEventSubscrivers[i]->OnKeyPress(key, GetAsText(key), this); + this->keyEventSubscrivers[i]->OnKeyPress(key, this); } } KeyboardCallbackList *w = this->callbackList; @@ -126,17 +126,17 @@ void Keyboard::InternalOnKeyPress(Enum::SAKI key, wchar_t text[16]) { if(w->function) if (w->type == KeyboardCallbackList::CallbackDataType_OnPress) - w->function.keyPressCallback(key, GetAsText(key), this); + w->function.keyPressCallback(key, this); w = w->next; } } -void Keyboard::InternalOnKeyDown(Enum::SAKI key, wchar_t text[16]) +void Keyboard::InternalOnKeyDown(Enum::SAKI key) { for (unsigned int i = 0; i < this->keyEventSubscrivers.size(); i++) { if(this->keyEventSubscrivers[i]) { - this->keyEventSubscrivers[i]->OnKeyDown(key, GetAsText(key), this); + this->keyEventSubscrivers[i]->OnKeyDown(key, this); } } KeyboardCallbackList *w = this->callbackList; @@ -144,17 +144,17 @@ void Keyboard::InternalOnKeyDown(Enum::SAKI key, wchar_t text[16]) { if(w->function) if (w->type == KeyboardCallbackList::CallbackDataType_OnDown) - w->function.keyDownCallback(key, GetAsText(key), this); + w->function.keyDownCallback(key, this); w = w->next; } } -void Keyboard::InternalOnKeyRelease(Enum::SAKI key, wchar_t text[16]) +void Keyboard::InternalOnKeyRelease(Enum::SAKI key) { for (unsigned int i = 0; i < this->keyEventSubscrivers.size(); i++) { if(this->keyEventSubscrivers[i]) { - this->keyEventSubscrivers[i]->OnKeyRelease(key, GetAsText(key), this); + this->keyEventSubscrivers[i]->OnKeyRelease(key, this); } } KeyboardCallbackList *w = this->callbackList; @@ -162,7 +162,7 @@ void Keyboard::InternalOnKeyRelease(Enum::SAKI key, wchar_t text[16]) { if(w->function) if (w->type == KeyboardCallbackList::CallbackDataType_OnRelease) - w->function.keyReleaseCallback(key, GetAsText(key), this); + w->function.keyReleaseCallback(key, this); w = w->next; } } diff --git a/Code/Misc/Input/Source/Mouse.cpp b/Code/Misc/Input/Source/Mouse.cpp index 103e1342..b3cebbc4 100644 --- a/Code/Misc/Input/Source/Mouse.cpp +++ b/Code/Misc/Input/Source/Mouse.cpp @@ -16,7 +16,8 @@ struct Mouse::MouseCallbackList CallbackDataType_OnPress, CallbackDataType_OnDown, CallbackDataType_OnRelease, - CallbackDataType_OnMove, + CallbackDataType_OnMovePixelPos, + CallbackDataType_OnMoveVelocity, CallbackDataType_OnScroll, } type; union CallbackData @@ -24,7 +25,8 @@ struct Mouse::MouseCallbackList Typedefs::OnMousePressCallback mousePressCallback; Typedefs::OnMouseDownCallback mouseDownCallback; Typedefs::OnMouseReleaseCallback mouseReleaseCallback; - Typedefs::OnMouseMoveCallback mouseMoveCallback; + Typedefs::OnMouseMovePixelPosCallback mouseMovePixelPosCallback; + Typedefs::OnMouseMoveVelocityCallback mouseMoveVelocityCallback; Typedefs::OnMouseScrollCallback mouseScrollCallback; void* dummy; @@ -165,19 +167,24 @@ void Mouse::InternalOnBtnRelease(Enum::SAMI btn) w = w->next; } } -void Mouse::InternalOnMove(Struct::SAIPoint2D cord) +void Mouse::InternalOnMove(Struct::SAIPointInt2D pixelPos, Struct::SAIPointInt2D velocity) { for (unsigned int i = 0; i < this->mouseSubscribers.size(); i++) { if(this->mouseSubscribers[i]) - this->mouseSubscribers[i]->OnMouseMove(this->pixelPos, this); + { + this->mouseSubscribers[i]->OnMouseMovePixelPos(pixelPos, this); + this->mouseSubscribers[i]->OnMouseMoveVelocity(velocity, this); + } } MouseCallbackList *w = this->callbackList; while (w) { if(w->function) - if (w->type == MouseCallbackList::CallbackDataType_OnMove) - w->function.mouseMoveCallback(this->pixelPos, this); + if (w->type == MouseCallbackList::CallbackDataType_OnMovePixelPos) + w->function.mouseMovePixelPosCallback(pixelPos, this); + else if (w->type == MouseCallbackList::CallbackDataType_OnMoveVelocity) + w->function.mouseMoveVelocityCallback(velocity, this); w = w->next; } } @@ -192,7 +199,7 @@ void Mouse::InternalOnScroll(int delta) while (w) { if(w->function) - if (w->type == MouseCallbackList::CallbackDataType_OnMove) + if (w->type == MouseCallbackList::CallbackDataType_OnScroll) w->function.mouseScrollCallback(delta, this); w = w->next; } @@ -200,36 +207,19 @@ void Mouse::InternalOnScroll(int delta) -int Mouse::GetWheelDelta() const -{ - return this->wheelDelta; -} -SAIPoint2D & Mouse::GetPixelPosition( Struct::SAIPoint2D &targetMem ) const -{ - targetMem.x = this->pixelPos.x; - targetMem.y = this->pixelPos.y; - return targetMem; -} -SAIPoint2D & Mouse::GetDeltaPosition( Struct::SAIPoint2D &targetMem ) const -{ - targetMem.x = this->deltaPos.x; - targetMem.y = this->deltaPos.y; - return targetMem; -} - void Mouse::AddOnMousePressCallback( Typedefs::OnMousePressCallback func) { MouseCallbackList::CallbackData d; d.mousePressCallback = func; - if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnRelease); - else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnRelease); + if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnPress); + else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnPress); } void Mouse::AddOnMouseDownCallback( Typedefs::OnMouseDownCallback func ) { MouseCallbackList::CallbackData d; d.mouseDownCallback = func; - if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnRelease); - else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnRelease); + if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnDown); + else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnDown); } void Mouse::AddOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func ) { @@ -238,19 +228,26 @@ void Mouse::AddOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func ) if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnRelease); else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnRelease); } -void Mouse::AddOnMouseMoveCallback( Typedefs::OnMouseMoveCallback func ) +void Mouse::AddOnMouseMovePixelPosCallback( Typedefs::OnMouseMovePixelPosCallback func ) { MouseCallbackList::CallbackData d; - d.mouseMoveCallback = func; - if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnRelease); - else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnRelease); + d.mouseMovePixelPosCallback = func; + if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnMovePixelPos); + else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnMovePixelPos); +} +void Mouse::AddOnMouseMoveVelocityCallback( Typedefs::OnMouseMoveVelocityCallback func ) +{ + MouseCallbackList::CallbackData d; + d.mouseMoveVelocityCallback = func; + if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnMoveVelocity); + else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnMoveVelocity); } void Mouse::AddOnMouseScrollCallback( Typedefs::OnMouseScrollCallback func ) { MouseCallbackList::CallbackData d; d.mouseScrollCallback = func; - if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnRelease); - else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnRelease); + if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnScroll); + else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnScroll); } void Mouse::RemoveOnMousePressCallback( Typedefs::OnMousePressCallback func) @@ -265,7 +262,11 @@ void Mouse::RemoveOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func { RemoveFromList(this->callbackList, func); } -void Mouse::RemoveOnMouseMoveCallback( Typedefs::OnMouseMoveCallback func ) +void Mouse::RemoveOnMouseMovePixelPosCallback( Typedefs::OnMouseMovePixelPosCallback func ) +{ + RemoveFromList(this->callbackList, func); +} +void Mouse::RemoveOnMouseMoveVelocityCallback( Typedefs::OnMouseMoveVelocityCallback func ) { RemoveFromList(this->callbackList, func); } diff --git a/Code/Misc/Input/Source/Win32/Win32Input.cpp b/Code/Misc/Input/Source/Win32/Win32Input.cpp index d3ff2a0a..72d519d2 100644 --- a/Code/Misc/Input/Source/Win32/Win32Input.cpp +++ b/Code/Misc/Input/Source/Win32/Win32Input.cpp @@ -16,7 +16,6 @@ using namespace Input::Enum; using namespace Input::Struct; using namespace Input::Typedefs; - Win32Input *Win32Input::instance = 0; LRESULT Win32Input::RawInputParser(HWND h, LPARAM l) @@ -88,14 +87,6 @@ LRESULT CALLBACK Win32Input::RawWindowCallback(HWND h, UINT m, WPARAM w, LPARAM case WM_INPUT: return Win32Input::instance->RawInputParser(h, l); break; - - case WM_KEYDOWN: - val = 0; - break; - - case WM_CHAR: - val = 0; - break; case WM_ACTIVATE: Win32Input::instance->WindowActivate((w == TRUE)); @@ -115,7 +106,7 @@ void Win32Input::WindowActivate(bool activate) } else { - ShowCursor(0); + ShowCursor(1); } } @@ -151,55 +142,49 @@ InputObject* Win32Input::CreateDevice(const SAIType inputType, Typedefs::WindowH { if(!this->instance->targetHwin) { - this->targetHwin = CreateWindowExW( 0, L"RawInputCallbackFunc" , NULL, NULL, NULL, NULL, NULL, - NULL, (HWND)targetApplication, NULL, (HINSTANCE)GetModuleHandle(0), NULL ); + RECT rc; + GetClientRect((HWND)targetApplication, &rc); + + AdjustWindowRect(&rc, GetWindowStyle((HWND)targetApplication), FALSE); + + rc.right = rc.right - rc.left; + rc.bottom = rc.bottom - rc.top; + + this->targetHwin = CreateWindowExW( 0, L"RawInputCallbackFunc" , NULL, NULL, rc.left, rc.top, rc.right, rc.bottom, + (HWND)targetApplication, NULL, (HINSTANCE)GetModuleHandle(0), NULL ); } + InputObject* val = 0; - RAWINPUTDEVICE rid; - rid.usUsagePage = 0x01; - rid.hwndTarget = this->instance->targetHwin; switch (inputType) { case SAIType_Keyboard: { - rid.usUsage = RawInput_Usage_keyboard; - rid.dwFlags = RIDEV_NOLEGACY; - if(RegisterRawInputDevices(&rid, 1, sizeof(RAWINPUTDEVICE)) == TRUE) - { - Win32Keyboard* obj = new Win32Keyboard(); - this->keyboard.push_back(obj); - val = obj; - } - else + Win32Keyboard* obj = new Win32Keyboard(this->targetHwin); + if(!obj->Create()) { + delete obj; return 0; } + + this->keyboard.push_back(obj); + val = obj; } break; case SAIType_Mouse: { - rid.usUsage = RawInput_Usage_mouse; - rid.dwFlags = RIDEV_NOLEGACY | RIDEV_CAPTUREMOUSE; - if(RegisterRawInputDevices(&rid, 1, sizeof(RAWINPUTDEVICE)) == TRUE) - { - int i = 0; - val = (InputObject*)1; - Win32Mouse* obj = new Win32Mouse(); - this->mouse.push_back(obj); - val = obj; - } - else + Win32Mouse* obj = new Win32Mouse(this->targetHwin); + if(!obj->Create()) { + delete obj; return 0; } + + this->mouse.push_back(obj); + val = obj; } break; - - //case SAIType_ApplicationKeyboard: - // //val = new Win32ApplicationKeyboard(); - // break; } return val; @@ -208,6 +193,21 @@ InputObject* Win32Input::CreateDevice(const SAIType inputType, Typedefs::WindowH void Win32Input::ToggleInputSystem(bool enable) { this->enabled = enable; + + if(this->enabled) + { + for (unsigned int i = 0; i < this->mouse.size(); i++) + { this->mouse[i]->Deactivate(); } + for (unsigned int i = 0; i < this->keyboard.size(); i++) + { this->keyboard[i]->Deactivate(); } + } + else + { + for (unsigned int i = 0; i < this->mouse.size(); i++) + { this->mouse[i]->Activate(); } + for (unsigned int i = 0; i < this->keyboard.size(); i++) + { this->keyboard[i]->Activate(); } + } } void Win32Input::Destroy () { diff --git a/Code/Misc/Input/Source/Win32/Win32Keyboard.cpp b/Code/Misc/Input/Source/Win32/Win32Keyboard.cpp index e587f5c8..475a9e85 100644 --- a/Code/Misc/Input/Source/Win32/Win32Keyboard.cpp +++ b/Code/Misc/Input/Source/Win32/Win32Keyboard.cpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////// // Created by [Dennis Andersen] [2013] ///////////////////////////////////////////////////////////////////// -#include "..\..\Include\Win32\Win32Keyboard.h" +#include "..\..\Include\Win32\Win32Input.h" #include #pragma warning ( disable : 4172 ) @@ -10,8 +10,13 @@ using namespace Input::Enum; using namespace std; -Win32Keyboard::Win32Keyboard() +Win32Keyboard::Win32Keyboard(HWND target) { + this->isActive = false; + this->device.usUsagePage = 0x01; + this->device.hwndTarget = target; + this->device.usUsage = RawInput_Usage_keyboard; + this->device.dwFlags = RIDEV_NOLEGACY; memset(&this->keys[0], 0, sizeof(Win32Keyboard::Keys) * MAXKEYS); } Win32Keyboard::~Win32Keyboard() @@ -37,6 +42,28 @@ wchar_t* Win32Keyboard::GetAsText(Enum::SAKI key) GetKeyNameTextW((LONG)temp, buff, 16); return buff; } + +void Win32Keyboard::Activate () +{ + if(this->isActive) return; + + this->Create(); +} +void Win32Keyboard::Deactivate () +{ + if(!this->isActive) return; + + RAWINPUTDEVICE d; + d.dwFlags = RIDEV_REMOVE; + d.hwndTarget = 0; + d.usUsage = RawInput_Usage_keyboard; + d.usUsagePage = 0x01; + if(RegisterRawInputDevices(&d, 1, sizeof(RAWINPUTDEVICE))) + { + this->isActive = true; + } +} + void Win32Keyboard::ProccessKeyboardData (RAWKEYBOARD keyboard) { if(!this->active) @@ -55,7 +82,7 @@ void Win32Keyboard::ProccessKeyboardData (RAWKEYBOARD keyboard) //The key is released. if(isUp)/*(k.Flags == RI_KEY_BREAK || k.Flags == (RI_KEY_BREAK | RI_KEY_E0) || k.Flags == (RI_KEY_BREAK | RI_KEY_E1))*/ { - InternalOnKeyRelease(key, L""); + InternalOnKeyRelease(key); this->keys[key].isDown = false; this->keys[key].isE0 = isE0; this->keys[key].makecode = keyboard.MakeCode; @@ -65,11 +92,11 @@ void Win32Keyboard::ProccessKeyboardData (RAWKEYBOARD keyboard) { if(this->keys[key].isDown) { - this->InternalOnKeyDown(key, L""); + this->InternalOnKeyDown(key); } else { - this->InternalOnKeyPress(key, L""); + this->InternalOnKeyPress(key); this->keys[key].isDown = true; this->keys[key].isE0 = isE0; this->keys[key].makecode = keyboard.MakeCode; @@ -108,8 +135,32 @@ void Win32Keyboard::ProccessKeyboardData (RAWKEYBOARD keyboard) { wchar_t test = towlower((wchar_t)virtualKey); if( this->keys[SAKI_LeftShift].isDown || this->keys[SAKI_RightShift].isDown ) + { + if(key == SAKI_0) test = L'='; + else if(key == SAKI_1) test = L'!'; + else if(key == SAKI_2) test = L'"'; + else if(key == SAKI_3) test = L'#'; + else if(key == SAKI_4) test = L'¤'; + else if(key == SAKI_5) test = L'%'; + else if(key == SAKI_6) test = L'&'; + else if(key == SAKI_7) test = L'/'; + else if(key == SAKI_8) test = L'('; + else if(key == SAKI_9) test = L')'; + else if(key == SAKI_Add) test = L'?'; test = towupper(test); - + } + else if( this->keys[SAKI_LeftAlt].isDown || this->keys[SAKI_RightAlt].isDown ) + { + if(key == SAKI_2) test = L'@'; + else if(key == SAKI_3) test = L'£'; + else if(key == SAKI_4) test = L'$'; + else if(key == SAKI_5) test = L'€'; + else if(key == SAKI_7) test = L'{'; + else if(key == SAKI_8) test = L'['; + else if(key == SAKI_9) test = L']'; + else if(key == SAKI_0) test = L'}'; + else if(key == SAKI_Add) test = L'\\'; + } this->textTarget->insert( this->writePos, 1, test); ++this->writePos; } @@ -247,7 +298,7 @@ void Win32Keyboard::MapKey(RAWKEYBOARD& rawKB, SAKI& out_key, bool& isE0) out_key = SAKI_LeftShift; out_key = SAKI_RightShift; break; - case 0x13 : //VK_PAUSE + case 0x13 : //VK_PAUSE out_key = SAKI_Pause; break; case 0x14 : //VK_CAPITAL @@ -614,12 +665,16 @@ void Win32Keyboard::MapKey(RAWKEYBOARD& rawKB, SAKI& out_key, bool& isE0) break; case 0xBB://VK_OEM_PLUS + out_key = SAKI_Add; break; case 0xBC://VK_OEM_COMMA + out_key = SAKI_Comma; break; case 0xBD://VK_OEM_MINUS + out_key = SAKI_Minus; break; case 0xBE://VK_OEM_PERIOD + out_key = SAKI_Period; break; case 0xBA://VK_OEM_1 break; @@ -639,6 +694,16 @@ void Win32Keyboard::MapKey(RAWKEYBOARD& rawKB, SAKI& out_key, bool& isE0) break; } } +bool Win32Keyboard::Create() +{ + if(RegisterRawInputDevices(&this->device, 1, sizeof(RAWINPUTDEVICE)) == TRUE) + { + this->isActive = true; + return true; + } + + return false; +} diff --git a/Code/Misc/Input/Source/Win32/Win32Mouse.cpp b/Code/Misc/Input/Source/Win32/Win32Mouse.cpp index a05db67c..801772b6 100644 --- a/Code/Misc/Input/Source/Win32/Win32Mouse.cpp +++ b/Code/Misc/Input/Source/Win32/Win32Mouse.cpp @@ -1,14 +1,14 @@ ///////////////////////////////////////////////////////////////////// // Created by [Dennis Andersen] [2013] ///////////////////////////////////////////////////////////////////// -#include "..\..\Include\Win32\Win32Mouse.h" +#include "..\..\Include\Win32\Win32Input.h" using namespace Input; using namespace Input::Enum; using namespace Input::Struct; using namespace Input::Typedefs; -void MapButton(RAWMOUSE& rawMouse, bool &isUp, Enum::SAMI& btn, int& delta, Struct::SAIPoint2D& vel, unsigned int& mcode) +void MapButton(RAWMOUSE& rawMouse, bool &isUp, Enum::SAMI& btn, int& delta, Struct::SAIPointInt2D& vel, unsigned int& mcode) { if(rawMouse.lLastX != 0 || rawMouse.lLastY != 0) { @@ -62,43 +62,109 @@ void MapButton(RAWMOUSE& rawMouse, bool &isUp, Enum::SAMI& btn, int& delta, Stru } } - -Win32Mouse::Win32Mouse() +void ContainPoint(Struct::SAIPointInt2D& pixelPos, Struct::SAIPointInt2D& windowSize) { + if(pixelPos.x < 0) { pixelPos.x = 0; } + else if(pixelPos.x > windowSize.x) { pixelPos.x = windowSize.x; } + if(pixelPos.y < 0) { pixelPos.y = 0; } + else if(pixelPos.y > windowSize.y) { pixelPos.y = windowSize.y; } +} + +Win32Mouse::Win32Mouse(HWND target) +{ + this->isActive = false; + this->device.usUsagePage = 0x01; + this->device.hwndTarget = target; + this->device.usUsage = RawInput_Usage_mouse; + this->device.dwFlags = RIDEV_NOLEGACY | RIDEV_CAPTUREMOUSE; memset(&this->buttons[0], 0, sizeof(Buttons) * MAXBUTTONS); } Win32Mouse::~Win32Mouse() -{ -} +{ } -bool Win32Mouse::IsBtnUp(Enum::SAMI btn) +bool Win32Mouse::IsBtnUp(Enum::SAMI btn) const { if(btn == SAMI_Unknown) return false; return !this->buttons[btn].isDown; } -bool Win32Mouse::IsBtnDown(Enum::SAMI btn) +bool Win32Mouse::IsBtnDown(Enum::SAMI btn) const { if(btn == SAMI_Unknown) return false; return this->buttons[btn].isDown; } +int Win32Mouse::GetWheelDelta() const +{ + return this->wheelDelta; +} +SAIPointInt2D& Win32Mouse::GetPixelPosition( Struct::SAIPointInt2D &targetMem ) const +{ + memcpy(&targetMem, &this->pixelPos, sizeof(SAIPointFloat2D)); + + return targetMem; +} +SAIPointFloat2D& Win32Mouse::GetNormalizedPosition(Struct::SAIPointFloat2D& targetMem) +{ + RECT windowVertex; + GetWindowRect( this->device.hwndTarget, &windowVertex ); + + this->normalPos.x = (float)(pixelPos.x - windowVertex.left); + this->normalPos.x /= (float)(windowVertex.right - windowVertex.left); + + this->normalPos.y = (float)(pixelPos.y - windowVertex.top); + this->normalPos.y /= (float)(windowVertex.bottom - windowVertex.top); + + memcpy(&targetMem, &this->normalPos, sizeof(SAIPointFloat2D)); + + return targetMem; +} +SAIPointFloat2D& Win32Mouse::GetDeltaPosition(Struct::SAIPointFloat2D& targetMem) const +{ + memcpy(&targetMem, &this->deltaPos, sizeof(SAIPointFloat2D)); + + return targetMem; +} + +void Win32Mouse::Activate () +{ + if(this->isActive) return; + + this->Create(); +} +void Win32Mouse::Deactivate () +{ + if(!this->isActive) return; + + RAWINPUTDEVICE d; + d.dwFlags = RIDEV_REMOVE; + d.hwndTarget = 0; + d.usUsage = RawInput_Usage_mouse; + d.usUsagePage = 0x01; + if(RegisterRawInputDevices(&d, 1, sizeof(RAWINPUTDEVICE))) + { + this->isActive = false; + } +} void Win32Mouse::ProccessMouseData (RAWMOUSE mouse) { bool isUp = true; Enum::SAMI btn = Enum::SAMI_Unknown; int delta = 0; - Struct::SAIPoint2D velocity; + Struct::SAIPointInt2D velocity; unsigned int makeCode = 0; MapButton(mouse, isUp, btn, delta, velocity, makeCode); if(velocity.Length() != 0) { - this->pixelPos.x += this->deltaPos.x = velocity.x; - this->pixelPos.y += this->deltaPos.y = velocity.y; - InternalOnMove(this->pixelPos); + this->pixelPos.x += velocity.x; + this->pixelPos.y += velocity.y; + + ContainPoint(this->pixelPos, this->windowSize); + + InternalOnMove(this->pixelPos, velocity); } if(delta != 0) @@ -130,4 +196,33 @@ void Win32Mouse::ProccessMouseData (RAWMOUSE mouse) InternalOnBtnPress(btn); } } -} \ No newline at end of file +} +bool Win32Mouse::Create() +{ + if(!this->device.hwndTarget) + { + RECT desktop; + const HWND hDesktop = GetDesktopWindow(); + GetClientRect(hDesktop, &desktop); + windowSize.x = desktop.right; + windowSize.y = desktop.bottom; + this->device.dwFlags = 0; + } + else + { + RECT re; + GetClientRect(this->device.hwndTarget, &re); + windowSize.x = re.right - re.left; + windowSize.y = re.bottom - re.top; + } + + if(RegisterRawInputDevices(&this->device, 1, sizeof(RAWINPUTDEVICE)) == TRUE) + { + this->isActive = true; + return true; + } + + return false; +} + + diff --git a/Code/Misc/WindowManager/WindowShell.cpp b/Code/Misc/WindowManager/WindowShell.cpp index 308e610f..97e3bbe0 100644 --- a/Code/Misc/WindowManager/WindowShell.cpp +++ b/Code/Misc/WindowManager/WindowShell.cpp @@ -77,7 +77,6 @@ bool WindowShell::CreateWin(WINDOW_INIT_DESC &desc) if(!desc.hInstance) desc.hInstance = GetModuleHandle(0); if(desc.windowSize.x <= 0) desc.windowSize.x = 50; if(desc.windowSize.y <= 0) desc.windowSize.y = 50; - __windowShellData.parent = desc.parent; __windowShellData.hIns = desc.hInstance; @@ -111,20 +110,14 @@ bool WindowShell::CreateWin(WINDOW_INIT_DESC &desc) RECT rectW; - int width; - int height; DWORD style = desc.windowStyle; bool windowed = false; - width = desc.windowSize.x + GetSystemMetrics(SM_CXFIXEDFRAME)*2; - height = desc.windowSize.y + GetSystemMetrics(SM_CYFIXEDFRAME)*2 + GetSystemMetrics(SM_CYCAPTION); + rectW.left = 0; + rectW.top = 0; + rectW.right = desc.windowSize.x; + rectW.bottom = desc.windowSize.y; - rectW.left=(GetSystemMetrics(SM_CXSCREEN)-width)/2; - rectW.top=(GetSystemMetrics(SM_CYSCREEN)-height)/2; - rectW.right=rectW.left+width; - rectW.bottom=rectW.top+height; - - if(__windowShellData.parent) { rectW.left = 0; @@ -135,6 +128,8 @@ bool WindowShell::CreateWin(WINDOW_INIT_DESC &desc) windowed = true; } + AdjustWindowRect(& rectW, style, FALSE); + if(windowed) { __windowShellData.hWnd = CreateWindowExW( @@ -161,8 +156,8 @@ bool WindowShell::CreateWin(WINDOW_INIT_DESC &desc) style, desc.windowPosition.x, desc.windowPosition.y, - desc.windowSize.x, - desc.windowSize.y, + rectW.right - rectW.left, + rectW.bottom - rectW.top, 0, 0, __windowShellData.hIns, @@ -173,7 +168,6 @@ bool WindowShell::CreateWin(WINDOW_INIT_DESC &desc) if( !__windowShellData.hWnd ) { printf("Failed to create window handle : Code ( %ul )", GetLastError()); - //MessageBox(0, L"Failed to create window", L"Error!", 0); return false; } @@ -258,3 +252,4 @@ bool WindowShell::Frame() return true; } + diff --git a/Code/Misc/WindowManager/WindowShell.h b/Code/Misc/WindowManager/WindowShell.h index 04bb9931..458debd7 100644 --- a/Code/Misc/WindowManager/WindowShell.h +++ b/Code/Misc/WindowManager/WindowShell.h @@ -40,7 +40,7 @@ public: POINT _windowSize = cPOINT(800, 600), POINT _windowPosition = cPOINT(0,0), UINT _windowClassStyle = (CS_HREDRAW | CS_VREDRAW | CS_OWNDC), - UINT _windowStyle = (WS_POPUPWINDOW|WS_SYSMENU|WS_CAPTION), + UINT _windowStyle = (WS_POPUPWINDOW|WS_CAPTION), HICON _icon = LoadIcon(0, IDI_APPLICATION), HCURSOR _cursor = LoadCursor(NULL, IDC_ARROW), HBRUSH _background = (HBRUSH)GetStockObject(BLACK_BRUSH) From 1f90de4cb444e39e2f48ec492efb44dd7780820f Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Mon, 24 Feb 2014 19:45:13 +0100 Subject: [PATCH 17/32] some implemetations --- Code/DanBias.sln | 50 +++---------------- .../GameClient/GameClientState/GameState.cpp | 6 +-- .../GameClient/GameClientState/GamingUI.cpp | 4 ++ .../GameClientState/LanMenuState.cpp | 13 +++-- .../GameClient/GameClientState/LobbyState.cpp | 13 +++-- .../GameClient/GameClientState/MainState.cpp | 2 +- 6 files changed, 32 insertions(+), 56 deletions(-) diff --git a/Code/DanBias.sln b/Code/DanBias.sln index 6835e750..c825e6ee 100644 --- a/Code/DanBias.sln +++ b/Code/DanBias.sln @@ -49,10 +49,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LevelLoader", "Game\LevelLo EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GameServerDebugEnvironment", "Game\LanServer\GameServerDebugEnvironment\GameServerDebugEnvironment.vcxproj", "{67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Lab", "Lab", "{46A660B9-6BE9-411C-B366-235FD8F8A9BD}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RawDeviceLab", "LabProjects\RawDeviceLab\RawDeviceLab.vcxproj", "{32DD438B-8C9C-49EF-9EA5-EB48951D869A}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -701,7 +697,8 @@ Global {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|Mixed Platforms.Build.0 = Release|Win32 {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|Win32.ActiveCfg = Release|Win32 {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|Win32.Build.0 = Release|Win32 - {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|x64.ActiveCfg = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|x64.ActiveCfg = Release|x64 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|x64.Build.0 = Release|x64 {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|x86.ActiveCfg = Release|Win32 {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|x86.Build.0 = Release|Win32 {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Release|Any CPU.ActiveCfg = Release|Win32 @@ -718,7 +715,8 @@ Global {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|Mixed Platforms.Build.0 = Release|Win32 {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|Win32.ActiveCfg = Release|Win32 {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|Win32.Build.0 = Release|Win32 - {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|x64.ActiveCfg = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|x64.ActiveCfg = Release|x64 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|x64.Build.0 = Release|x64 {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|x86.ActiveCfg = Release|Win32 {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|x86.Build.0 = Release|Win32 {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.Debug|Any CPU.ActiveCfg = Debug|Win32 @@ -735,7 +733,8 @@ Global {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.MinSizeRel|Mixed Platforms.Build.0 = Release|Win32 {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.MinSizeRel|Win32.ActiveCfg = Release|Win32 {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.MinSizeRel|Win32.Build.0 = Release|Win32 - {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.MinSizeRel|x64.ActiveCfg = Release|Win32 + {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.MinSizeRel|x64.ActiveCfg = Release|x64 + {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.MinSizeRel|x64.Build.0 = Release|x64 {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.MinSizeRel|x86.ActiveCfg = Release|Win32 {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.MinSizeRel|x86.Build.0 = Release|Win32 {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.Release|Any CPU.ActiveCfg = Release|Win32 @@ -752,41 +751,10 @@ Global {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.RelWithDebInfo|Mixed Platforms.Build.0 = Release|Win32 {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.RelWithDebInfo|Win32.ActiveCfg = Release|Win32 {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.RelWithDebInfo|Win32.Build.0 = Release|Win32 - {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.RelWithDebInfo|x64.ActiveCfg = Release|Win32 + {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.RelWithDebInfo|x64.ActiveCfg = Release|x64 + {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.RelWithDebInfo|x64.Build.0 = Release|x64 {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.RelWithDebInfo|x86.ActiveCfg = Release|Win32 {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE}.RelWithDebInfo|x86.Build.0 = Release|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Debug|Any CPU.ActiveCfg = Debug|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Debug|Mixed Platforms.Build.0 = Debug|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Debug|Win32.ActiveCfg = Debug|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Debug|Win32.Build.0 = Debug|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Debug|x64.ActiveCfg = Debug|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Debug|x86.ActiveCfg = Debug|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Debug|x86.Build.0 = Debug|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.MinSizeRel|Any CPU.ActiveCfg = Release|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.MinSizeRel|Mixed Platforms.ActiveCfg = Release|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.MinSizeRel|Mixed Platforms.Build.0 = Release|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.MinSizeRel|Win32.ActiveCfg = Release|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.MinSizeRel|Win32.Build.0 = Release|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.MinSizeRel|x64.ActiveCfg = Release|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.MinSizeRel|x86.ActiveCfg = Release|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.MinSizeRel|x86.Build.0 = Release|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Release|Any CPU.ActiveCfg = Release|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Release|Mixed Platforms.ActiveCfg = Release|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Release|Mixed Platforms.Build.0 = Release|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Release|Win32.ActiveCfg = Release|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Release|Win32.Build.0 = Release|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Release|x64.ActiveCfg = Release|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Release|x86.ActiveCfg = Release|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.Release|x86.Build.0 = Release|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.RelWithDebInfo|Mixed Platforms.ActiveCfg = Release|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.RelWithDebInfo|Mixed Platforms.Build.0 = Release|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.RelWithDebInfo|Win32.ActiveCfg = Release|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.RelWithDebInfo|Win32.Build.0 = Release|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.RelWithDebInfo|x64.ActiveCfg = Release|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.RelWithDebInfo|x86.ActiveCfg = Release|Win32 - {32DD438B-8C9C-49EF-9EA5-EB48951D869A}.RelWithDebInfo|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -800,7 +768,6 @@ Global {C83A6FAD-E71F-4B1E-9D63-E93E61DDC012} = {20720CA7-795C-45AD-A302-9383A6DD503A} {8690FDDF-C5B7-4C42-A337-BD5243F29B85} = {20720CA7-795C-45AD-A302-9383A6DD503A} {2A1BC987-AF42-4500-802D-89CD32FC1309} = {20720CA7-795C-45AD-A302-9383A6DD503A} - {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63} = {20720CA7-795C-45AD-A302-9383A6DD503A} {C4C76A8D-44C5-4452-9F61-39C7E01CBDB4} = {F156EEBC-0195-4020-8700-4433208DE12B} {3EA5F14D-2A71-4588-A69D-87C4571C580F} = {F156EEBC-0195-4020-8700-4433208DE12B} {7E3990D2-3D94-465C-B58D-64A74B3ECF9B} = {1322B12B-5E37-448A-AAAF-F637460DCB23} @@ -810,6 +777,5 @@ Global {604A12A7-07BF-4482-BDF3-7101C811F121} = {C83A6FAD-E71F-4B1E-9D63-E93E61DDC012} {C8CBA520-5D7D-4D61-A8DA-6E05FD132BCB} = {C83A6FAD-E71F-4B1E-9D63-E93E61DDC012} {67D0FB00-FF1F-4DE4-84BD-664AE93D25EE} = {C83A6FAD-E71F-4B1E-9D63-E93E61DDC012} - {32DD438B-8C9C-49EF-9EA5-EB48951D869A} = {46A660B9-6BE9-411C-B366-235FD8F8A9BD} EndGlobalSection EndGlobal diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index bb0bdc90..abfa07f0 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -81,9 +81,6 @@ bool GameState::Init( SharedStateContent &shared ) gfxOp.GlobalTint = Math::Float3(1,1,1); Graphics::API::SetOptions(gfxOp); - //tell server ready - this->privData->nwClient->Send( Protocol_General_Status(Protocol_General_Status::States_ready) ); - // DEGUG KEYS this->key_Reload_Shaders = false; this->key_Wireframe_Toggle = false; @@ -105,6 +102,9 @@ bool GameState::Init( SharedStateContent &shared ) ((RespawnUI*)respawnUI)->Init(); ((StatsUI*)statsUI)->Init(); + //tell server ready + this->privData->nwClient->Send( Protocol_General_Status(Protocol_General_Status::States_ready) ); + return true; } diff --git a/Code/Game/GameClient/GameClientState/GamingUI.cpp b/Code/Game/GameClient/GameClientState/GamingUI.cpp index 56b8f98f..68e62f10 100644 --- a/Code/Game/GameClient/GameClientState/GamingUI.cpp +++ b/Code/Game/GameClient/GameClientState/GamingUI.cpp @@ -38,6 +38,10 @@ bool GamingUI::Init() this->plane = new Plane_UI(L"box_tex.png", Float3(0.5f, 0.0f, 0.5f), Float2(0.3f, 0.1f)); this->text = new Text_UI(L"hej", Float3(0.5f,0.0f,0.1f), Float2(0.1f,0.1f)); + // setting input mode to all raw + this->keyboardInput->Activate(); + this->mouseInput->Activate(); + return true; } GameStateUI::UIState GamingUI::Update( float deltaTime ) diff --git a/Code/Game/GameClient/GameClientState/LanMenuState.cpp b/Code/Game/GameClient/GameClientState/LanMenuState.cpp index 8cca6cf4..d8361503 100644 --- a/Code/Game/GameClient/GameClientState/LanMenuState.cpp +++ b/Code/Game/GameClient/GameClientState/LanMenuState.cpp @@ -30,7 +30,8 @@ struct LanMenuState::MyData NetworkClient *nwClient; ::Input::Mouse *mouseInput; ::Input::Keyboard *keyboardInput; - Graphics::API::Texture background; + Float3 mousePos; + Graphics::API::Texture background, mouseCursor; EventButtonCollection guiElements; TextField *connectIP; @@ -58,6 +59,7 @@ bool LanMenuState::Init( SharedStateContent &shared ) this->privData->keyboardInput = shared.keyboardDevice; this->privData->background = Graphics::API::CreateTexture( L"color_white.png" ); + this->privData->mouseCursor = Graphics::API::CreateTexture( L"cursor_md.png" ); // create guiElements this->privData->connectIP = new TextField( L"color_white.png", Float4(1.0f), Float4(0.0f), this, Float3(0.5f, 0.3f, 0.5f), Float2(0.8f, 0.09f), ResizeAspectRatio_None ); @@ -92,11 +94,11 @@ GameClientState::ClientState LanMenuState::Update( float deltaTime ) { MouseInput mouseState; { - ::Input::Struct::SAIPointInt2D pos; - this->privData->mouseInput->GetPixelPosition( pos ); + ::Input::Struct::SAIPointFloat2D pos; + this->privData->mouseInput->GetNormalizedPosition( pos ); - mouseState.x = pos.x; - mouseState.y = pos.y; + this->privData->mousePos.x = mouseState.x = pos.x; + this->privData->mousePos.y = mouseState.y = pos.y; mouseState.mouseButtonPressed = this->privData->mouseInput->IsBtnDown( ::Input::Enum::SAMI_MouseLeftBtn ); } EventHandler::Instance().Update( mouseState ); @@ -110,6 +112,7 @@ bool LanMenuState::Render( ) Graphics::API::StartGuiRender(); + Graphics::API::RenderGuiElement( this->privData->mouseCursor, this->privData->mousePos, Float2(0.01f), Float4(1.0f) ); Graphics::API::RenderGuiElement( this->privData->background, Float3(0.5f, 0.5f, 1.0f), Float2(1.0f) ); this->privData->guiElements.RenderTexture(); diff --git a/Code/Game/GameClient/GameClientState/LobbyState.cpp b/Code/Game/GameClient/GameClientState/LobbyState.cpp index c47febbe..62303865 100644 --- a/Code/Game/GameClient/GameClientState/LobbyState.cpp +++ b/Code/Game/GameClient/GameClientState/LobbyState.cpp @@ -23,7 +23,8 @@ struct LobbyState::MyData GameClientState::ClientState nextState; NetworkClient *nwClient; ::Input::Mouse *mouseInput; - Graphics::API::Texture background; + Float3 mousePos; + Graphics::API::Texture background, mouseCursor;; EventButtonCollection guiElements; } privData; @@ -46,6 +47,7 @@ bool LobbyState::Init( SharedStateContent &shared ) this->privData->mouseInput = shared.mouseDevice; this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" ); + this->privData->mouseCursor = Graphics::API::CreateTexture( L"cursor_md.png" ); // create buttons ButtonRectangle *button; @@ -63,11 +65,11 @@ GameClientState::ClientState LobbyState::Update( float deltaTime ) { MouseInput mouseState; { - ::Input::Struct::SAIPointInt2D pos; - this->privData->mouseInput->GetPixelPosition( pos ); + ::Input::Struct::SAIPointFloat2D pos; + this->privData->mouseInput->GetNormalizedPosition( pos ); - mouseState.x = pos.x; - mouseState.y = pos.y; + this->privData->mousePos.x = mouseState.x = pos.x; + this->privData->mousePos.y = mouseState.y = pos.y; mouseState.mouseButtonPressed = this->privData->mouseInput->IsBtnDown( ::Input::Enum::SAMI_MouseLeftBtn ); } EventHandler::Instance().Update( mouseState ); @@ -79,6 +81,7 @@ bool LobbyState::Render( ) Graphics::API::NewFrame(); Graphics::API::StartGuiRender(); + Graphics::API::RenderGuiElement( this->privData->mouseCursor, this->privData->mousePos, Float2(0.01f), Float4(1.0f) ); Graphics::API::RenderGuiElement( this->privData->background, Float3(0.5f, 0.5f, 1.0f), Float2(1.0f) ); this->privData->guiElements.RenderTexture(); diff --git a/Code/Game/GameClient/GameClientState/MainState.cpp b/Code/Game/GameClient/GameClientState/MainState.cpp index a057ab74..25607be6 100644 --- a/Code/Game/GameClient/GameClientState/MainState.cpp +++ b/Code/Game/GameClient/GameClientState/MainState.cpp @@ -98,7 +98,7 @@ bool MainState::Render() Graphics::API::NewFrame(); Graphics::API::StartGuiRender(); - Graphics::API::RenderGuiElement( this->privData->mouseCursor, this->privData->mousePos, Float2(0.1f), Float4(1.0f) ); + Graphics::API::RenderGuiElement( this->privData->mouseCursor, this->privData->mousePos, Float2(0.01f), Float4(1.0f) ); Graphics::API::RenderGuiElement( this->privData->background, Float3(0.5f, 0.5f, 0.9f), Float2(1.0f), Float4(63.0f/255.0f,73.0f/255.0f,127.0f/255.0f,0.6f) ); this->privData->guiElements.RenderTexture(); From df2572a95e7468e7574be2a96ebfe9d630d8079e Mon Sep 17 00:00:00 2001 From: Dennis Andersen Date: Tue, 25 Feb 2014 01:05:37 +0100 Subject: [PATCH 18/32] Input - Added method for releasing default input object --- Code/Misc/Input/Include/InputManager.h | 5 +++++ Code/Misc/Input/Source/InputManager.cpp | 6 ++++++ Code/Misc/Input/Source/Keyboard.cpp | 4 ++++ Code/Misc/Input/Source/Win32/Win32Input.cpp | 6 ++---- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Code/Misc/Input/Include/InputManager.h b/Code/Misc/Input/Include/InputManager.h index 1feff9cf..b34d81e9 100644 --- a/Code/Misc/Input/Include/InputManager.h +++ b/Code/Misc/Input/Include/InputManager.h @@ -25,6 +25,11 @@ namespace Input */ static InputManager* CreateInputManager (); + /** + * @return Destroy default input manager. + */ + static void DestroyInputManager (); + /** * @return Destroys a input manager. */ diff --git a/Code/Misc/Input/Source/InputManager.cpp b/Code/Misc/Input/Source/InputManager.cpp index 48bb828f..b226d1da 100644 --- a/Code/Misc/Input/Source/InputManager.cpp +++ b/Code/Misc/Input/Source/InputManager.cpp @@ -57,6 +57,11 @@ InputManager* InputManager::CreateInputManager() { return CreateManager(); } +void InputManager::DestroyInputManager() +{ + delete defaultInstance; + defaultInstance = 0; +} void InputManager::DestroyInputManager(InputManager* inputSystem) { if(!inputSystem) return; @@ -77,3 +82,4 @@ InputManager::~InputManager() + diff --git a/Code/Misc/Input/Source/Keyboard.cpp b/Code/Misc/Input/Source/Keyboard.cpp index a35f75a5..fc75f4d8 100644 --- a/Code/Misc/Input/Source/Keyboard.cpp +++ b/Code/Misc/Input/Source/Keyboard.cpp @@ -226,6 +226,10 @@ void Keyboard::BindTextTarget( ::std::wstring *field ) { this->writePos = field->size(); } + else + { + this->writePos = 0; + } } void Keyboard::ReleaseTextTarget( ) { diff --git a/Code/Misc/Input/Source/Win32/Win32Input.cpp b/Code/Misc/Input/Source/Win32/Win32Input.cpp index 30ebf7ab..e1b0e040 100644 --- a/Code/Misc/Input/Source/Win32/Win32Input.cpp +++ b/Code/Misc/Input/Source/Win32/Win32Input.cpp @@ -150,7 +150,7 @@ Win32Input::Win32Input() { /*wrong*/ } } Win32Input::~Win32Input() -{} +{ Destroy(); } InputObject* Win32Input::CreateDevice(const SAIType inputType, Typedefs::WindowHandle targetApplication) { if(!this->instance->targetHwin) @@ -225,9 +225,7 @@ void Win32Input::ToggleInputSystem(bool enable) void Win32Input::Destroy () { ShowCursor(true); - RECT r; - GetWindowRect(GetDesktopWindow(), &r); - ClipCursor(&r); + ClipCursor(0); for (unsigned int i = 0; i < this->keyboard.size(); i++) { From 18d0a6460b341e0a322d64d9ea5124a3bfd780a8 Mon Sep 17 00:00:00 2001 From: Dennis Andersen Date: Tue, 25 Feb 2014 01:05:37 +0100 Subject: [PATCH 19/32] Input - Added method for releasing default input object --- Code/Misc/Input/Include/InputManager.h | 5 +++++ Code/Misc/Input/Source/InputManager.cpp | 6 ++++++ Code/Misc/Input/Source/Keyboard.cpp | 4 ++++ Code/Misc/Input/Source/Win32/Win32Input.cpp | 6 ++---- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Code/Misc/Input/Include/InputManager.h b/Code/Misc/Input/Include/InputManager.h index 1feff9cf..b34d81e9 100644 --- a/Code/Misc/Input/Include/InputManager.h +++ b/Code/Misc/Input/Include/InputManager.h @@ -25,6 +25,11 @@ namespace Input */ static InputManager* CreateInputManager (); + /** + * @return Destroy default input manager. + */ + static void DestroyInputManager (); + /** * @return Destroys a input manager. */ diff --git a/Code/Misc/Input/Source/InputManager.cpp b/Code/Misc/Input/Source/InputManager.cpp index 48bb828f..b226d1da 100644 --- a/Code/Misc/Input/Source/InputManager.cpp +++ b/Code/Misc/Input/Source/InputManager.cpp @@ -57,6 +57,11 @@ InputManager* InputManager::CreateInputManager() { return CreateManager(); } +void InputManager::DestroyInputManager() +{ + delete defaultInstance; + defaultInstance = 0; +} void InputManager::DestroyInputManager(InputManager* inputSystem) { if(!inputSystem) return; @@ -77,3 +82,4 @@ InputManager::~InputManager() + diff --git a/Code/Misc/Input/Source/Keyboard.cpp b/Code/Misc/Input/Source/Keyboard.cpp index a35f75a5..fc75f4d8 100644 --- a/Code/Misc/Input/Source/Keyboard.cpp +++ b/Code/Misc/Input/Source/Keyboard.cpp @@ -226,6 +226,10 @@ void Keyboard::BindTextTarget( ::std::wstring *field ) { this->writePos = field->size(); } + else + { + this->writePos = 0; + } } void Keyboard::ReleaseTextTarget( ) { diff --git a/Code/Misc/Input/Source/Win32/Win32Input.cpp b/Code/Misc/Input/Source/Win32/Win32Input.cpp index 30ebf7ab..e1b0e040 100644 --- a/Code/Misc/Input/Source/Win32/Win32Input.cpp +++ b/Code/Misc/Input/Source/Win32/Win32Input.cpp @@ -150,7 +150,7 @@ Win32Input::Win32Input() { /*wrong*/ } } Win32Input::~Win32Input() -{} +{ Destroy(); } InputObject* Win32Input::CreateDevice(const SAIType inputType, Typedefs::WindowHandle targetApplication) { if(!this->instance->targetHwin) @@ -225,9 +225,7 @@ void Win32Input::ToggleInputSystem(bool enable) void Win32Input::Destroy () { ShowCursor(true); - RECT r; - GetWindowRect(GetDesktopWindow(), &r); - ClipCursor(&r); + ClipCursor(0); for (unsigned int i = 0; i < this->keyboard.size(); i++) { From 13167064cb3789d53bbafd3a1b681f75d334c758 Mon Sep 17 00:00:00 2001 From: dean11 Date: Tue, 25 Feb 2014 13:49:20 +0100 Subject: [PATCH 20/32] Input - Added mouse features, custom tags and all-in-one callback --- Code/Misc/Input/Include/ApplicationKeyboard.h | 36 ------ Code/Misc/Input/Include/Common.h | 7 +- Code/Misc/Input/Include/InputManager.h | 5 - Code/Misc/Input/Include/Keyboard.h | 1 - Code/Misc/Input/Include/Mouse.h | 45 +++++-- .../Include/Win32/Win32ApplicationKeyboard.h | 23 ---- .../Misc/Input/Source/ApplicationKeyboard.cpp | 44 ------- Code/Misc/Input/Source/InputManager.cpp | 6 - Code/Misc/Input/Source/Keyboard.cpp | 4 - Code/Misc/Input/Source/Mouse.cpp | 115 ++++++++++++------ .../Source/Win32/Win32ApplicationKeyboard.cpp | 51 -------- Code/Misc/Input/Source/Win32/Win32Input.cpp | 6 +- Code/Misc/Input/Source/Win32/Win32Mouse.cpp | 47 +++++++ 13 files changed, 165 insertions(+), 225 deletions(-) delete mode 100644 Code/Misc/Input/Include/ApplicationKeyboard.h delete mode 100644 Code/Misc/Input/Include/Win32/Win32ApplicationKeyboard.h delete mode 100644 Code/Misc/Input/Source/ApplicationKeyboard.cpp delete mode 100644 Code/Misc/Input/Source/Win32/Win32ApplicationKeyboard.cpp diff --git a/Code/Misc/Input/Include/ApplicationKeyboard.h b/Code/Misc/Input/Include/ApplicationKeyboard.h deleted file mode 100644 index b03e5abb..00000000 --- a/Code/Misc/Input/Include/ApplicationKeyboard.h +++ /dev/null @@ -1,36 +0,0 @@ -///////////////////////////////////////////////////////////////////// -// Created by [Dan Andersson] [2014] -///////////////////////////////////////////////////////////////////// -#ifndef INPUT_APPLICATION_KEBOARD_H -#define INPUT_APPLICATION_KEBOARD_H - -#include "InputObject.h" -#include - -namespace Input -{ - class ApplicationKeyboard : public InputObject - { - public: - virtual ~ApplicationKeyboard(); - - bool IsActive() const; - - void Activate(); - void Deactivate(); - - void BindTextTarget( ::std::wstring *field ); - void ReleaseTextTarget(); - - protected: - ::std::wstring *textTarget; - ::std::wstring::size_type writePos; - - ApplicationKeyboard(); - - private: - bool active; - }; -} - -#endif // !INPUT_KEBOARD_H diff --git a/Code/Misc/Input/Include/Common.h b/Code/Misc/Input/Include/Common.h index 694001a3..f3dd2512 100644 --- a/Code/Misc/Input/Include/Common.h +++ b/Code/Misc/Input/Include/Common.h @@ -21,22 +21,17 @@ namespace Input { SAIType_Keyboard, SAIType_Mouse, - //SAIType_ApplicationKeyboard, SAIType_futureExample1, SAIType_futureExample2, SAIType_futureExample3, }; - enum InputOptionType - { - InputOptionType_RawInput, - InputOptionType_PlatformDefault, - }; enum ButtonState { ButtonState_Press, // When button is pressed (once) ButtonState_Down, // When the button is held down ButtonState_Release, // When button is released (once) ButtonState_Up, // Default state, will not be proccesed as a callback! + ButtonState_Unknown, }; } /*********************************************************************/ diff --git a/Code/Misc/Input/Include/InputManager.h b/Code/Misc/Input/Include/InputManager.h index b34d81e9..1feff9cf 100644 --- a/Code/Misc/Input/Include/InputManager.h +++ b/Code/Misc/Input/Include/InputManager.h @@ -25,11 +25,6 @@ namespace Input */ static InputManager* CreateInputManager (); - /** - * @return Destroy default input manager. - */ - static void DestroyInputManager (); - /** * @return Destroys a input manager. */ diff --git a/Code/Misc/Input/Include/Keyboard.h b/Code/Misc/Input/Include/Keyboard.h index 4db0bce6..b6708604 100644 --- a/Code/Misc/Input/Include/Keyboard.h +++ b/Code/Misc/Input/Include/Keyboard.h @@ -199,7 +199,6 @@ namespace Input ::std::wstring* textTarget; ::std::wstring::size_type writePos; bool active; - Enum::InputOptionType inputMode; }; } diff --git a/Code/Misc/Input/Include/Mouse.h b/Code/Misc/Input/Include/Mouse.h index f83a71a5..863cdd4e 100644 --- a/Code/Misc/Input/Include/Mouse.h +++ b/Code/Misc/Input/Include/Mouse.h @@ -38,12 +38,30 @@ namespace Input SAMI_MouseBtnX18, SAMI_MouseBtnX19, SAMI_MouseBtnX20, + SAMI_MouseMove, + SAMI_MouseScroll, SAMI_Unknown, }; } //----------------------------------------------------------------------------------------------------------------------------- + namespace Struct + { + struct MouseEventData + { + Enum::SAMI type; + Enum::ButtonState buttonState; + Struct::SAIPointInt2D pixelPos; + Struct::SAIPointFloat2D normalizedPos; + Struct::SAIPointInt2D velocity; + Mouse* sender; + int scrollDelta; + void* tag; + }; + } + //----------------------------------------------------------------------------------------------------------------------------- namespace Typedefs { + typedef void(*OnMouseCallback)( const Struct::MouseEventData& eventData ); typedef void(*OnMousePressCallback)(Enum::SAMI btn, Mouse* sender); typedef void(*OnMouseDownCallback)(Enum::SAMI btn, Mouse* sender); typedef void(*OnMouseReleaseCallback)(Enum::SAMI btn, Mouse* sender); @@ -60,6 +78,7 @@ namespace Input class MouseEvent { public: + virtual void OnMouse ( const Struct::MouseEventData& eventData ) { } virtual void OnMousePress ( Enum::SAMI key, Mouse* sender ) { } virtual void OnMouseDown ( Enum::SAMI key, Mouse* sender ) { } virtual void OnMouseRelease ( Enum::SAMI key, Mouse* sender ) { } @@ -82,13 +101,21 @@ namespace Input virtual bool IsActive() override = 0; public: /* global subscribe callback functions */ - void AddOnMousePressCallback( Typedefs::OnMousePressCallback func); - void AddOnMouseDownCallback( Typedefs::OnMouseDownCallback func ); - void AddOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func ); - void AddOnMouseMovePixelPosCallback( Typedefs::OnMouseMovePixelPosCallback func ); - void AddOnMouseMoveVelocityCallback( Typedefs::OnMouseMoveVelocityCallback func ); - void AddOnMouseScrollCallback( Typedefs::OnMouseScrollCallback func ); + void AddMouseEvent(MouseEvent* object); + void RemoveMouseEvent(MouseEvent* object); + void operator+= (MouseEvent* object); + void operator-= (MouseEvent* object); + public: /* global subscribe callback functions */ + void AddOnMouseCallback( Typedefs::OnMouseCallback func, void* tag); + void AddOnMousePressCallback( Typedefs::OnMousePressCallback func, void* tag); + void AddOnMouseDownCallback( Typedefs::OnMouseDownCallback func, void* tag ); + void AddOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func, void* tag ); + void AddOnMouseMovePixelPosCallback( Typedefs::OnMouseMovePixelPosCallback func, void* tag ); + void AddOnMouseMoveVelocityCallback( Typedefs::OnMouseMoveVelocityCallback func, void* tag ); + void AddOnMouseScrollCallback( Typedefs::OnMouseScrollCallback func, void* tag ); + + void RemoveOnMouseCallback( Typedefs::OnMouseCallback func); void RemoveOnMousePressCallback( Typedefs::OnMousePressCallback func); void RemoveOnMouseDownCallback( Typedefs::OnMouseDownCallback func ); void RemoveOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func ); @@ -96,10 +123,6 @@ namespace Input void RemoveOnMouseMoveVelocityCallback( Typedefs::OnMouseMoveVelocityCallback func ); void RemoveOnMouseScrollCallback( Typedefs::OnMouseScrollCallback func ); - public: - void operator+= (MouseEvent* object); - void operator-= (MouseEvent* object); - void SetPixelPos(int x, int y); void ToggleCursor(bool toggler); @@ -111,6 +134,7 @@ namespace Input virtual ~Mouse(); protected: + void InternalOnEvent(Struct::MouseEventData & data); void InternalOnBtnPress(Enum::SAMI key); void InternalOnBtnDown(Enum::SAMI key); void InternalOnBtnRelease(Enum::SAMI key); @@ -127,7 +151,6 @@ namespace Input bool isCurorLocked; int wheelDelta; - Enum::InputOptionType inputMode; }; } diff --git a/Code/Misc/Input/Include/Win32/Win32ApplicationKeyboard.h b/Code/Misc/Input/Include/Win32/Win32ApplicationKeyboard.h deleted file mode 100644 index 98bcc0e9..00000000 --- a/Code/Misc/Input/Include/Win32/Win32ApplicationKeyboard.h +++ /dev/null @@ -1,23 +0,0 @@ -///////////////////////////////////////////////////////////////////// -// Created by [Dan Andersson] [2014] -///////////////////////////////////////////////////////////////////// -#ifndef INPUT_WIN32_APPLICATION_KEBOARD_H -#define INPUT_WIN32_APPLICATION_KEBOARD_H - -#define NOMINMAX -#include -#include "..\ApplicationKeyboard.h" - -namespace Input -{ - class Win32ApplicationKeyboard : public ApplicationKeyboard - { - public: - Win32ApplicationKeyboard(); - ~Win32ApplicationKeyboard(); - - void CaptureText( UINT msg, WPARAM param ); - }; -} - -#endif // !INPUT_WIN32_APPLICATION_KEBOARD_H diff --git a/Code/Misc/Input/Source/ApplicationKeyboard.cpp b/Code/Misc/Input/Source/ApplicationKeyboard.cpp deleted file mode 100644 index 66ddb042..00000000 --- a/Code/Misc/Input/Source/ApplicationKeyboard.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "../Include/ApplicationKeyboard.h" - -using namespace ::Input; - -ApplicationKeyboard::ApplicationKeyboard() : - InputObject( Enum::SAIType_ApplicationKeyboard ) -{ - this->textTarget = nullptr; - this->writePos = 0; - this->isEnabled = true; -} - -ApplicationKeyboard::~ApplicationKeyboard() -{ /* DO nothing */ } - -bool ApplicationKeyboard::IsActive() const -{ - return this->isEnabled; -} - -void ApplicationKeyboard::Activate() -{ - this->isEnabled = true; -} - -void ApplicationKeyboard::Deactivate() -{ - this->isEnabled = false; -} - -void ApplicationKeyboard::BindTextTarget( ::std::wstring *field ) -{ - this->textTarget = field; - - if( field ) - { - this->writePos = field->size(); - } -} - -void ApplicationKeyboard::ReleaseTextTarget( ) -{ - this->BindTextTarget( nullptr ); -} \ No newline at end of file diff --git a/Code/Misc/Input/Source/InputManager.cpp b/Code/Misc/Input/Source/InputManager.cpp index b226d1da..48bb828f 100644 --- a/Code/Misc/Input/Source/InputManager.cpp +++ b/Code/Misc/Input/Source/InputManager.cpp @@ -57,11 +57,6 @@ InputManager* InputManager::CreateInputManager() { return CreateManager(); } -void InputManager::DestroyInputManager() -{ - delete defaultInstance; - defaultInstance = 0; -} void InputManager::DestroyInputManager(InputManager* inputSystem) { if(!inputSystem) return; @@ -82,4 +77,3 @@ InputManager::~InputManager() - diff --git a/Code/Misc/Input/Source/Keyboard.cpp b/Code/Misc/Input/Source/Keyboard.cpp index fc75f4d8..a35f75a5 100644 --- a/Code/Misc/Input/Source/Keyboard.cpp +++ b/Code/Misc/Input/Source/Keyboard.cpp @@ -226,10 +226,6 @@ void Keyboard::BindTextTarget( ::std::wstring *field ) { this->writePos = field->size(); } - else - { - this->writePos = 0; - } } void Keyboard::ReleaseTextTarget( ) { diff --git a/Code/Misc/Input/Source/Mouse.cpp b/Code/Misc/Input/Source/Mouse.cpp index b3cebbc4..2d309ddf 100644 --- a/Code/Misc/Input/Source/Mouse.cpp +++ b/Code/Misc/Input/Source/Mouse.cpp @@ -13,6 +13,7 @@ struct Mouse::MouseCallbackList { enum CallbackDataType { + CallbackDataType_OnEvent, CallbackDataType_OnPress, CallbackDataType_OnDown, CallbackDataType_OnRelease, @@ -22,6 +23,7 @@ struct Mouse::MouseCallbackList } type; union CallbackData { + Typedefs::OnMouseCallback mouseCallback; Typedefs::OnMousePressCallback mousePressCallback; Typedefs::OnMouseDownCallback mouseDownCallback; Typedefs::OnMouseReleaseCallback mouseReleaseCallback; @@ -37,7 +39,8 @@ struct Mouse::MouseCallbackList operator bool(){ return this->dummy != 0; } } function; MouseCallbackList *next; - MouseCallbackList(CallbackData func, CallbackDataType t) :function(func), next(0), type(t) { } + void* tag; + MouseCallbackList(CallbackData func, CallbackDataType t, void* ct) :function(func), next(0), type(t), tag(ct) { } }; void ClearList(Mouse::MouseCallbackList* first) @@ -52,7 +55,7 @@ void ClearList(Mouse::MouseCallbackList* first) delete removee; } } -void AddToList(Mouse::MouseCallbackList* first, Mouse::MouseCallbackList::CallbackData data, Mouse::MouseCallbackList::CallbackDataType type) +void AddToList(Mouse::MouseCallbackList* first, Mouse::MouseCallbackList::CallbackData data, Mouse::MouseCallbackList::CallbackDataType type, void* tag) { Mouse::MouseCallbackList *w = first; Mouse::MouseCallbackList *prev = first; @@ -62,7 +65,7 @@ void AddToList(Mouse::MouseCallbackList* first, Mouse::MouseCallbackList::Callba Mouse::MouseCallbackList::CallbackData f; f = data; - prev->next = new Mouse::MouseCallbackList(f, type); + prev->next = new Mouse::MouseCallbackList(f, type, tag); } void RemoveFromList(Mouse::MouseCallbackList* first, Mouse::MouseCallbackList::CallbackData data) { @@ -119,6 +122,25 @@ Mouse::~Mouse() } +void Mouse::InternalOnEvent(MouseEventData & data) +{ + for (unsigned int i = 0; i < this->mouseSubscribers.size(); i++) + { + if(this->mouseSubscribers[i]) + this->mouseSubscribers[i]->OnMouse(data); + } + MouseCallbackList *w = this->callbackList; + while (w) + { + if(w->function) + if (w->type == MouseCallbackList::CallbackDataType_OnEvent) + { + data.tag = w->tag; + w->function.mouseCallback(data); + } + w = w->next; + } +} void Mouse::InternalOnBtnPress(Enum::SAMI btn) { for (unsigned int i = 0; i < this->mouseSubscribers.size(); i++) @@ -205,49 +227,85 @@ void Mouse::InternalOnScroll(int delta) } } +void Mouse::AddMouseEvent(MouseEvent* object) +{ + if(ExistsInList(this->mouseSubscribers, object)) return; + this->mouseSubscribers.push_back(object); +} +void Mouse::RemoveMouseEvent(MouseEvent* object) +{ + int i = -1; + if((i = ExistsInList(this->mouseSubscribers, object))) + { + std::swap(this->mouseSubscribers[i], this->mouseSubscribers[this->mouseSubscribers.size() - 1]); + this->mouseSubscribers.resize(this->mouseSubscribers.size() - 1); + } +} +void Mouse::operator+= (MouseEvent* object) +{ + if(ExistsInList(this->mouseSubscribers, object)) return; -void Mouse::AddOnMousePressCallback( Typedefs::OnMousePressCallback func) + this->mouseSubscribers.push_back(object); +} +void Mouse::operator-= (MouseEvent* object) +{ + int i = -1; + if((i = ExistsInList(this->mouseSubscribers, object))) + { + std::swap(this->mouseSubscribers[i], this->mouseSubscribers[this->mouseSubscribers.size() - 1]); + this->mouseSubscribers.resize(this->mouseSubscribers.size() - 1); + } +} + +void Mouse::AddOnMouseCallback( Typedefs::OnMouseCallback func, void* tag) +{ + MouseCallbackList::CallbackData d; + d.mouseCallback = func; + if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnEvent, tag); + else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnEvent, tag); +} +void Mouse::AddOnMousePressCallback( Typedefs::OnMousePressCallback func, void* tag) { MouseCallbackList::CallbackData d; d.mousePressCallback = func; - if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnPress); - else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnPress); + if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnPress, tag); + else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnPress, tag); } -void Mouse::AddOnMouseDownCallback( Typedefs::OnMouseDownCallback func ) +void Mouse::AddOnMouseDownCallback( Typedefs::OnMouseDownCallback func, void* tag ) { MouseCallbackList::CallbackData d; d.mouseDownCallback = func; - if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnDown); - else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnDown); + if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnDown, tag); + else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnDown, tag); } -void Mouse::AddOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func ) +void Mouse::AddOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func, void* tag ) { MouseCallbackList::CallbackData d; d.mouseReleaseCallback = func; - if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnRelease); - else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnRelease); + if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnRelease, tag); + else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnRelease, tag); } -void Mouse::AddOnMouseMovePixelPosCallback( Typedefs::OnMouseMovePixelPosCallback func ) +void Mouse::AddOnMouseMovePixelPosCallback( Typedefs::OnMouseMovePixelPosCallback func, void* tag ) { MouseCallbackList::CallbackData d; d.mouseMovePixelPosCallback = func; - if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnMovePixelPos); - else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnMovePixelPos); + if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnMovePixelPos, tag); + else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnMovePixelPos, tag); } -void Mouse::AddOnMouseMoveVelocityCallback( Typedefs::OnMouseMoveVelocityCallback func ) +void Mouse::AddOnMouseMoveVelocityCallback( Typedefs::OnMouseMoveVelocityCallback func, void* tag ) { MouseCallbackList::CallbackData d; d.mouseMoveVelocityCallback = func; - if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnMoveVelocity); - else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnMoveVelocity); + if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnMoveVelocity, tag); + else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnMoveVelocity, tag); } -void Mouse::AddOnMouseScrollCallback( Typedefs::OnMouseScrollCallback func ) +void Mouse::AddOnMouseScrollCallback( Typedefs::OnMouseScrollCallback func, void* tag ) { MouseCallbackList::CallbackData d; d.mouseScrollCallback = func; - if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnScroll); - else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnScroll); + if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnScroll, tag); + else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnScroll, tag); } void Mouse::RemoveOnMousePressCallback( Typedefs::OnMousePressCallback func) @@ -285,21 +343,6 @@ void Mouse::ToggleCursor(bool toggler) this->isCurorLocked = toggler; } -void Mouse::operator+= (MouseEvent* object) -{ - if(ExistsInList(this->mouseSubscribers, object)) return; - - this->mouseSubscribers.push_back(object); -} -void Mouse::operator-= (MouseEvent* object) -{ - int i = -1; - if((i = ExistsInList(this->mouseSubscribers, object))) - { - std::swap(this->mouseSubscribers[i], this->mouseSubscribers[this->mouseSubscribers.size() - 1]); - this->mouseSubscribers.resize(this->mouseSubscribers.size() - 1); - } -} diff --git a/Code/Misc/Input/Source/Win32/Win32ApplicationKeyboard.cpp b/Code/Misc/Input/Source/Win32/Win32ApplicationKeyboard.cpp deleted file mode 100644 index 3b58a032..00000000 --- a/Code/Misc/Input/Source/Win32/Win32ApplicationKeyboard.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "../../Include/Win32/Win32ApplicationKeyboard.h" -#include "Utilities.h" - -using namespace ::Input; -using namespace ::Utility::Value; -using ::std::wstring; - -Win32ApplicationKeyboard::Win32ApplicationKeyboard() : ApplicationKeyboard() { /* DO nothing */ } - -Win32ApplicationKeyboard::~Win32ApplicationKeyboard() { /* DO nothing */ } - -void Win32ApplicationKeyboard::CaptureText( UINT msg, WPARAM param ) -{ - if( !this->textTarget | !this->isEnabled ) - return; - - switch( msg ) - { - case WM_CHAR: - this->textTarget->insert( this->writePos, 1, (wchar_t)param ); - ++this->writePos; - break; - case WM_KEYDOWN: - { - switch( param ) - { - case VK_BACK: - if( this->writePos > 0 ) - { - --this->writePos; - this->textTarget->erase( this->writePos, 1 ); - } - break; - case VK_DELETE: - if( this->writePos < this->textTarget->size() ) - { - this->textTarget->erase( this->writePos, 1 ); - } - break; - case VK_LEFT: - this->writePos = Max( this->writePos - 1, (wstring::size_type)0 ); - break; - case VK_RIGHT: - this->writePos = Min( this->writePos + 1, this->textTarget->size() ); - break; - default: break; - } - } - default: break; - } -} diff --git a/Code/Misc/Input/Source/Win32/Win32Input.cpp b/Code/Misc/Input/Source/Win32/Win32Input.cpp index e1b0e040..30ebf7ab 100644 --- a/Code/Misc/Input/Source/Win32/Win32Input.cpp +++ b/Code/Misc/Input/Source/Win32/Win32Input.cpp @@ -150,7 +150,7 @@ Win32Input::Win32Input() { /*wrong*/ } } Win32Input::~Win32Input() -{ Destroy(); } +{} InputObject* Win32Input::CreateDevice(const SAIType inputType, Typedefs::WindowHandle targetApplication) { if(!this->instance->targetHwin) @@ -225,7 +225,9 @@ void Win32Input::ToggleInputSystem(bool enable) void Win32Input::Destroy () { ShowCursor(true); - ClipCursor(0); + RECT r; + GetWindowRect(GetDesktopWindow(), &r); + ClipCursor(&r); for (unsigned int i = 0; i < this->keyboard.size(); i++) { diff --git a/Code/Misc/Input/Source/Win32/Win32Mouse.cpp b/Code/Misc/Input/Source/Win32/Win32Mouse.cpp index c7bc9bf2..6defebcc 100644 --- a/Code/Misc/Input/Source/Win32/Win32Mouse.cpp +++ b/Code/Misc/Input/Source/Win32/Win32Mouse.cpp @@ -152,6 +152,10 @@ void Win32Mouse::Deactivate () void Win32Mouse::ProccessMouseData (RAWMOUSE mouse) { + static MouseEventData mouseEventData; + memset(&mouseEventData, 0, sizeof(MouseEventData)); + + bool isUp = true; Enum::SAMI btn = Enum::SAMI_Unknown; int delta = 0; @@ -167,11 +171,30 @@ void Win32Mouse::ProccessMouseData (RAWMOUSE mouse) ContainPoint(this->pixelPos, this->windowSize); InternalOnMove(this->pixelPos, velocity); + + GetNormalizedPosition( mouseEventData.normalizedPos ); + mouseEventData.pixelPos = this->pixelPos; + mouseEventData.velocity = velocity; + mouseEventData.buttonState = Enum::ButtonState_Unknown; + mouseEventData.scrollDelta = 0; + mouseEventData.sender = this; + mouseEventData.type = SAMI::SAMI_MouseMove; + + InternalOnEvent(mouseEventData); } if(delta != 0) { InternalOnScroll(delta); + + GetNormalizedPosition( mouseEventData.normalizedPos ); + mouseEventData.pixelPos = this->pixelPos; + mouseEventData.buttonState = Enum::ButtonState_Unknown; + mouseEventData.scrollDelta = delta; + mouseEventData.sender = this; + mouseEventData.type = SAMI::SAMI_MouseScroll; + + InternalOnEvent(mouseEventData); } @@ -184,6 +207,14 @@ void Win32Mouse::ProccessMouseData (RAWMOUSE mouse) if(isUp) { InternalOnBtnRelease(btn); + + GetNormalizedPosition( mouseEventData.normalizedPos ); + mouseEventData.pixelPos = this->pixelPos; + mouseEventData.buttonState = Enum::ButtonState_Release; + mouseEventData.type = btn; + mouseEventData.sender = this; + + InternalOnEvent(mouseEventData); } //The btn is pressed. else @@ -192,10 +223,26 @@ void Win32Mouse::ProccessMouseData (RAWMOUSE mouse) if(this->buttons[btn].isDown) { InternalOnBtnDown(btn); + + GetNormalizedPosition( mouseEventData.normalizedPos ); + mouseEventData.pixelPos = this->pixelPos; + mouseEventData.buttonState = Enum::ButtonState_Down; + mouseEventData.type = btn; + mouseEventData.sender = this; + + InternalOnEvent(mouseEventData); } else { InternalOnBtnPress(btn); + + GetNormalizedPosition( mouseEventData.normalizedPos ); + mouseEventData.pixelPos = this->pixelPos; + mouseEventData.buttonState = Enum::ButtonState_Press; + mouseEventData.type = btn; + mouseEventData.sender = this; + + InternalOnEvent(mouseEventData); } } } From 6dc60a2082a4e57347789d3c26db0978194e4dc4 Mon Sep 17 00:00:00 2001 From: dean11 Date: Tue, 25 Feb 2014 14:20:11 +0100 Subject: [PATCH 21/32] Input - Added more functionality, custom tag and all-in-one key callback --- Code/Misc/Input/Include/InputManager.h | 5 + Code/Misc/Input/Include/Keyboard.h | 49 +++++-- Code/Misc/Input/Source/InputManager.cpp | 8 ++ Code/Misc/Input/Source/Keyboard.cpp | 128 +++++++++++++----- .../Misc/Input/Source/Win32/Win32Keyboard.cpp | 23 +++- 5 files changed, 159 insertions(+), 54 deletions(-) diff --git a/Code/Misc/Input/Include/InputManager.h b/Code/Misc/Input/Include/InputManager.h index 1feff9cf..964a47bc 100644 --- a/Code/Misc/Input/Include/InputManager.h +++ b/Code/Misc/Input/Include/InputManager.h @@ -25,6 +25,11 @@ namespace Input */ static InputManager* CreateInputManager (); + /** + * @return Destroys the default input manager. + */ + static void DestroyInputManager (); + /** * @return Destroys a input manager. */ diff --git a/Code/Misc/Input/Include/Keyboard.h b/Code/Misc/Input/Include/Keyboard.h index b6708604..f29bcde1 100644 --- a/Code/Misc/Input/Include/Keyboard.h +++ b/Code/Misc/Input/Include/Keyboard.h @@ -135,11 +135,23 @@ namespace Input }; } //----------------------------------------------------------------------------------------------------------------------------- + namespace Struct + { + struct KeyboardEventData + { + Enum::SAKI key; + Enum::ButtonState state; + Keyboard* sender; + void* tag; + }; + } + //----------------------------------------------------------------------------------------------------------------------------- namespace Typedefs { - typedef void(*OnKeyPressCallback)(Enum::SAKI key, Keyboard* sender); - typedef void(*OnKeyDownCallback)(Enum::SAKI key, Keyboard* sender); - typedef void(*OnKeyReleaseCallback)(Enum::SAKI key, Keyboard* sender); + typedef void(*OnKeyEventCallback) (const Struct::KeyboardEventData& eventData); + typedef void(*OnKeyPressCallback) (Enum::SAKI key, Keyboard* sender, void* tag); + typedef void(*OnKeyDownCallback) (Enum::SAKI key, Keyboard* sender, void* tag); + typedef void(*OnKeyReleaseCallback) (Enum::SAKI key, Keyboard* sender, void* tag); } //----------------------------------------------------------------------------------------------------------------------------- @@ -149,9 +161,10 @@ namespace Input class KeyboardEvent { public: - virtual void OnKeyPress(Enum::SAKI key, Keyboard* sender) { } - virtual void OnKeyDown(Enum::SAKI key, Keyboard* sender) { } - virtual void OnKeyRelease(Enum::SAKI key, Keyboard* sender) { } + virtual void OnKeyEvent (const Struct::KeyboardEventData& eventData) { } + virtual void OnKeyPress (Enum::SAKI key, Keyboard* sender) { } + virtual void OnKeyDown (Enum::SAKI key, Keyboard* sender) { } + virtual void OnKeyRelease (Enum::SAKI key, Keyboard* sender) { } }; public: /* Manual check functions */ @@ -166,18 +179,25 @@ namespace Input virtual void Deactivate () override = 0; virtual bool IsActive() override = 0; - public: /* global subscribe callback functions */ - void AddOnKeyPressCallback (Typedefs::OnKeyPressCallback func); - void AddOnKeyDownCallback (Typedefs::OnKeyDownCallback func); - void AddOnKeyReleaseCallback (Typedefs::OnKeyReleaseCallback func); + public: /* object subscribe functions */ + void AddKeyboardEvent (KeyboardEvent* object); + void RemoveKeyboardEvent (KeyboardEvent* object); + void operator+= (KeyboardEvent* object); + void operator-= (KeyboardEvent* object); - void RemoveOnKeyPressCallback (Typedefs::OnKeyPressCallback func); - void RemoveOnKeyDownCallback (Typedefs::OnKeyDownCallback func); + public: /* global subscribe callback functions */ + void AddOnKeyEventCallback (Typedefs::OnKeyEventCallback func, void* tag); + void AddOnKeyPressCallback (Typedefs::OnKeyPressCallback func, void* tag); + void AddOnKeyDownCallback (Typedefs::OnKeyDownCallback func, void* tag); + void AddOnKeyReleaseCallback (Typedefs::OnKeyReleaseCallback func, void* tag); + + void RemoveOnKeyEventCallback (Typedefs::OnKeyEventCallback func); + void RemoveOnKeyPressCallback (Typedefs::OnKeyPressCallback func); + void RemoveOnKeyDownCallback (Typedefs::OnKeyDownCallback func); void RemoveOnKeyReleaseCallback (Typedefs::OnKeyReleaseCallback func); public: - void operator+= (KeyboardEvent* object); - void operator-= (KeyboardEvent* object); + void BindTextTarget( ::std::wstring *field ); void ReleaseTextTarget(); @@ -189,6 +209,7 @@ namespace Input Keyboard(); protected: /* Internal event proc */ + void InternalOnEvent(Struct::KeyboardEventData& data); void InternalOnKeyPress(Enum::SAKI key); void InternalOnKeyDown(Enum::SAKI key); void InternalOnKeyRelease(Enum::SAKI key); diff --git a/Code/Misc/Input/Source/InputManager.cpp b/Code/Misc/Input/Source/InputManager.cpp index 48bb828f..8e13dd6e 100644 --- a/Code/Misc/Input/Source/InputManager.cpp +++ b/Code/Misc/Input/Source/InputManager.cpp @@ -57,6 +57,14 @@ InputManager* InputManager::CreateInputManager() { return CreateManager(); } +void InputManager::DestroyInputManager() +{ + if(!defaultInstance) return; + + defaultInstance->Destroy(); + delete defaultInstance; + defaultInstance = 0; +} void InputManager::DestroyInputManager(InputManager* inputSystem) { if(!inputSystem) return; diff --git a/Code/Misc/Input/Source/Keyboard.cpp b/Code/Misc/Input/Source/Keyboard.cpp index a35f75a5..b94d5dce 100644 --- a/Code/Misc/Input/Source/Keyboard.cpp +++ b/Code/Misc/Input/Source/Keyboard.cpp @@ -12,12 +12,14 @@ struct Keyboard::KeyboardCallbackList { enum CallbackDataType { + CallbackDataType_OnEvent, CallbackDataType_OnPress, CallbackDataType_OnDown, CallbackDataType_OnRelease } type; union CallbackData { + Typedefs::OnKeyEventCallback keyEventCallback; Typedefs::OnKeyPressCallback keyPressCallback; Typedefs::OnKeyDownCallback keyDownCallback; Typedefs::OnKeyReleaseCallback keyReleaseCallback; @@ -29,7 +31,8 @@ struct Keyboard::KeyboardCallbackList operator bool(){ return this->keyDownCallback != 0; } } function; KeyboardCallbackList *next; - KeyboardCallbackList(CallbackData func, CallbackDataType t) :function(func), next(0), type(t) { } + void* tag; + KeyboardCallbackList(CallbackData func, CallbackDataType t, void* ct) :function(func), next(0), type(t), tag(ct) { } }; void ClearList(Keyboard::KeyboardCallbackList* first) @@ -44,7 +47,7 @@ void ClearList(Keyboard::KeyboardCallbackList* first) delete removee; } } -void AddToList(Keyboard::KeyboardCallbackList* first, Keyboard::KeyboardCallbackList::CallbackData data, Keyboard::KeyboardCallbackList::CallbackDataType type) +void AddToList(Keyboard::KeyboardCallbackList* first, Keyboard::KeyboardCallbackList::CallbackData data, Keyboard::KeyboardCallbackList::CallbackDataType type, void* tag) { Keyboard::KeyboardCallbackList *w = first; Keyboard::KeyboardCallbackList *prev = first; @@ -54,7 +57,7 @@ void AddToList(Keyboard::KeyboardCallbackList* first, Keyboard::KeyboardCallback Keyboard::KeyboardCallbackList::CallbackData f; f = data; - prev->next = new Keyboard::KeyboardCallbackList(f, type); + prev->next = new Keyboard::KeyboardCallbackList(f, type, tag); } void RemoveFromList(Keyboard::KeyboardCallbackList* first, Keyboard::KeyboardCallbackList::CallbackData data) { @@ -112,6 +115,27 @@ Keyboard::~Keyboard() } +void Keyboard::InternalOnEvent(Struct::KeyboardEventData& data) +{ + for (unsigned int i = 0; i < this->keyEventSubscrivers.size(); i++) + { + if(this->keyEventSubscrivers[i]) + { + this->keyEventSubscrivers[i]->OnKeyEvent(data); + } + } + KeyboardCallbackList *w = this->callbackList; + while (w) + { + if(w->function) + if (w->type == KeyboardCallbackList::CallbackDataType_OnEvent) + { + data.tag = w->tag; + w->function.keyEventCallback(data); + } + w = w->next; + } +} void Keyboard::InternalOnKeyPress(Enum::SAKI key) { for (unsigned int i = 0; i < this->keyEventSubscrivers.size(); i++) @@ -126,7 +150,9 @@ void Keyboard::InternalOnKeyPress(Enum::SAKI key) { if(w->function) if (w->type == KeyboardCallbackList::CallbackDataType_OnPress) - w->function.keyPressCallback(key, this); + { + w->function.keyPressCallback(key, this, w->tag); + } w = w->next; } } @@ -144,7 +170,7 @@ void Keyboard::InternalOnKeyDown(Enum::SAKI key) { if(w->function) if (w->type == KeyboardCallbackList::CallbackDataType_OnDown) - w->function.keyDownCallback(key, this); + w->function.keyDownCallback(key, this, w->tag); w = w->next; } } @@ -162,46 +188,26 @@ void Keyboard::InternalOnKeyRelease(Enum::SAKI key) { if(w->function) if (w->type == KeyboardCallbackList::CallbackDataType_OnRelease) - w->function.keyReleaseCallback(key, this); + w->function.keyReleaseCallback(key, this, w->tag); w = w->next; } } -void Keyboard::AddOnKeyPressCallback (OnKeyPressCallback func) +void Keyboard::AddKeyboardEvent(KeyboardEvent* object) { - KeyboardCallbackList::CallbackData d; - d.keyPressCallback = func; - if(!this->callbackList) this->callbackList = new KeyboardCallbackList(d, KeyboardCallbackList::CallbackDataType_OnPress); - else AddToList(this->callbackList, d, KeyboardCallbackList::CallbackDataType_OnPress); -} -void Keyboard::AddOnKeyDownCallback (OnKeyDownCallback func) -{ - KeyboardCallbackList::CallbackData d; - d.keyDownCallback = func; - if(!this->callbackList) this->callbackList = new KeyboardCallbackList(d, KeyboardCallbackList::CallbackDataType_OnDown); - else AddToList(this->callbackList, d, KeyboardCallbackList::CallbackDataType_OnDown); -} -void Keyboard::AddOnKeyReleaseCallback (OnKeyReleaseCallback func) -{ - KeyboardCallbackList::CallbackData d; - d.keyReleaseCallback = func; - if(!this->callbackList) this->callbackList = new KeyboardCallbackList(d, KeyboardCallbackList::CallbackDataType_OnRelease); - else AddToList(this->callbackList, d, KeyboardCallbackList::CallbackDataType_OnRelease); -} + if(ExistsInList(this->keyEventSubscrivers, object)) return; -void Keyboard::RemoveOnKeyPressCallback (OnKeyPressCallback func) -{ - RemoveFromList(this->callbackList, func); + this->keyEventSubscrivers.push_back(object); } -void Keyboard::RemoveOnKeyDownCallback (OnKeyDownCallback func) +void Keyboard::RemoveKeyboardEvent(KeyboardEvent* object) { - RemoveFromList(this->callbackList, func); + int i = -1; + if((i = ExistsInList(this->keyEventSubscrivers, object))) + { + std::swap(this->keyEventSubscrivers[i], this->keyEventSubscrivers[this->keyEventSubscrivers.size() - 1]); + this->keyEventSubscrivers.resize(this->keyEventSubscrivers.size() - 1); + } } -void Keyboard::RemoveOnKeyReleaseCallback (OnKeyReleaseCallback func) -{ - RemoveFromList(this->callbackList, func); -} - void Keyboard::operator+= (KeyboardEvent* object) { if(ExistsInList(this->keyEventSubscrivers, object)) return; @@ -218,6 +224,56 @@ void Keyboard::operator-= (KeyboardEvent* object) } } +void Keyboard::AddOnKeyEventCallback (OnKeyEventCallback func, void* tag) +{ + KeyboardCallbackList::CallbackData d; + d.keyEventCallback = func; + if(!this->callbackList) this->callbackList = new KeyboardCallbackList(d, KeyboardCallbackList::CallbackDataType_OnEvent, tag); + else AddToList(this->callbackList, d, KeyboardCallbackList::CallbackDataType_OnEvent, tag); +} +void Keyboard::AddOnKeyPressCallback (OnKeyPressCallback func, void* tag) +{ + KeyboardCallbackList::CallbackData d; + d.keyPressCallback = func; + if(!this->callbackList) this->callbackList = new KeyboardCallbackList(d, KeyboardCallbackList::CallbackDataType_OnPress, tag); + else AddToList(this->callbackList, d, KeyboardCallbackList::CallbackDataType_OnPress, tag); +} +void Keyboard::AddOnKeyDownCallback (OnKeyDownCallback func, void* tag) +{ + KeyboardCallbackList::CallbackData d; + d.keyDownCallback = func; + if(!this->callbackList) this->callbackList = new KeyboardCallbackList(d, KeyboardCallbackList::CallbackDataType_OnDown, tag); + else AddToList(this->callbackList, d, KeyboardCallbackList::CallbackDataType_OnDown, tag); +} +void Keyboard::AddOnKeyReleaseCallback (OnKeyReleaseCallback func, void* tag) +{ + KeyboardCallbackList::CallbackData d; + d.keyReleaseCallback = func; + if(!this->callbackList) this->callbackList = new KeyboardCallbackList(d, KeyboardCallbackList::CallbackDataType_OnRelease, tag); + else AddToList(this->callbackList, d, KeyboardCallbackList::CallbackDataType_OnRelease, tag); +} + +void Keyboard::RemoveOnKeyEventCallback (OnKeyEventCallback func) +{ + Keyboard::KeyboardCallbackList::CallbackData temp; + temp.keyEventCallback = func; + RemoveFromList(this->callbackList, temp); +} +void Keyboard::RemoveOnKeyPressCallback (OnKeyPressCallback func) +{ + RemoveFromList(this->callbackList, func); +} +void Keyboard::RemoveOnKeyDownCallback (OnKeyDownCallback func) +{ + RemoveFromList(this->callbackList, func); +} +void Keyboard::RemoveOnKeyReleaseCallback (OnKeyReleaseCallback func) +{ + RemoveFromList(this->callbackList, func); +} + + + void Keyboard::BindTextTarget( ::std::wstring *field ) { this->textTarget = field; diff --git a/Code/Misc/Input/Source/Win32/Win32Keyboard.cpp b/Code/Misc/Input/Source/Win32/Win32Keyboard.cpp index 475a9e85..84e3eb28 100644 --- a/Code/Misc/Input/Source/Win32/Win32Keyboard.cpp +++ b/Code/Misc/Input/Source/Win32/Win32Keyboard.cpp @@ -66,10 +66,10 @@ void Win32Keyboard::Deactivate () void Win32Keyboard::ProccessKeyboardData (RAWKEYBOARD keyboard) { - if(!this->active) - { - return; - } + if(!this->active) return; + + static Struct::KeyboardEventData keyboardEventData; + memset(&keyboardEventData, 0, sizeof(Struct::KeyboardEventData)); bool isUp = (( keyboard.Flags & RI_KEY_BREAK) != 0); SAKI key = SAKI_Unknown; @@ -86,6 +86,11 @@ void Win32Keyboard::ProccessKeyboardData (RAWKEYBOARD keyboard) this->keys[key].isDown = false; this->keys[key].isE0 = isE0; this->keys[key].makecode = keyboard.MakeCode; + + keyboardEventData.key = key; + keyboardEventData.sender = this; + keyboardEventData.state = Enum::ButtonState_Release; + InternalOnEvent(keyboardEventData); } //The key is pressed. else /*if (k.Flags == RI_KEY_MAKE || k.Flags == (RI_KEY_MAKE | RI_KEY_E0) || k.Flags == (RI_KEY_MAKE | RI_KEY_E1))*/ @@ -93,6 +98,11 @@ void Win32Keyboard::ProccessKeyboardData (RAWKEYBOARD keyboard) if(this->keys[key].isDown) { this->InternalOnKeyDown(key); + + keyboardEventData.key = key; + keyboardEventData.sender = this; + keyboardEventData.state = Enum::ButtonState_Down; + InternalOnEvent(keyboardEventData); } else { @@ -100,6 +110,11 @@ void Win32Keyboard::ProccessKeyboardData (RAWKEYBOARD keyboard) this->keys[key].isDown = true; this->keys[key].isE0 = isE0; this->keys[key].makecode = keyboard.MakeCode; + + keyboardEventData.key = key; + keyboardEventData.sender = this; + keyboardEventData.state = Enum::ButtonState_Press; + InternalOnEvent(keyboardEventData); } } } From 0fd038be8c75228b80e97fab4e95d2d7205ea88c Mon Sep 17 00:00:00 2001 From: dean11 Date: Tue, 25 Feb 2014 15:52:15 +0100 Subject: [PATCH 22/32] NewInpuit - Pre-merge with gameclient --- Code/Game/GameClient/DanBiasGame_Impl.cpp | 6 ++--- .../GameClient/GameClientState/GameStateUI.h | 13 ----------- .../GameClientState/LanMenuState.cpp | 10 ++++---- .../GameClient/GameClientState/MainState.cpp | 8 +++++-- .../Misc/Input/Source/Win32/Win32Keyboard.cpp | 23 ++++++++++++++----- 5 files changed, 32 insertions(+), 28 deletions(-) diff --git a/Code/Game/GameClient/DanBiasGame_Impl.cpp b/Code/Game/GameClient/DanBiasGame_Impl.cpp index 12b645c0..e5df1557 100644 --- a/Code/Game/GameClient/DanBiasGame_Impl.cpp +++ b/Code/Game/GameClient/DanBiasGame_Impl.cpp @@ -78,8 +78,8 @@ namespace DanBias //if(! data.window->CreateWin(WindowShell::WINDOW_INIT_DESC(L"Window", cPOINT(1600, 900), cPOINT()))) WindowShell::WINDOW_INIT_DESC winDesc; - winDesc.windowSize.x = 1280; - winDesc.windowSize.y = 720; + winDesc.windowSize.x = 1920; + winDesc.windowSize.y = 1080; winDesc.windowProcCallback = WindowCallBack; if(! data.window->CreateWin(winDesc) ) @@ -152,7 +152,7 @@ namespace DanBias Oyster::Graphics::API::Option p; p.modelPath = L"..\\Content\\Models\\"; p.texturePath = L"..\\Content\\Textures\\"; - p.Resolution = Oyster::Math::Float2( 1280.0f, 720.0f ); + p.Resolution = Oyster::Math::Float2( 1920.0f, 1080.0f ); //! @todo fix proper amb value p.AmbientValue = 1.3f; diff --git a/Code/Game/GameClient/GameClientState/GameStateUI.h b/Code/Game/GameClient/GameClientState/GameStateUI.h index 152a7f04..52ade7be 100644 --- a/Code/Game/GameClient/GameClientState/GameStateUI.h +++ b/Code/Game/GameClient/GameClientState/GameStateUI.h @@ -42,17 +42,4 @@ namespace DanBias { namespace Client }; } } -namespace Utility { namespace DynamicMemory -{ // template specializationto allowuse of dynamicmemory tools - template<> - inline void SafeDeleteInstance( ::DanBias::Client::GameStateUI *dynamicInstance ) - { - if( dynamicInstance ) - { - dynamicInstance->Release(); - delete dynamicInstance; - } - } -} } - #endif \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/LanMenuState.cpp b/Code/Game/GameClient/GameClientState/LanMenuState.cpp index 14944830..4d7304c8 100644 --- a/Code/Game/GameClient/GameClientState/LanMenuState.cpp +++ b/Code/Game/GameClient/GameClientState/LanMenuState.cpp @@ -59,7 +59,7 @@ bool LanMenuState::Init( SharedStateContent &shared ) this->privData->keyboardInput = shared.keyboardDevice; this->privData->background = Graphics::API::CreateTexture( L"color_white.png" ); - this->privData->mouseCursor = Graphics::API::CreateTexture( L"cursor_md.png" ); + this->privData->mouseCursor = Graphics::API::CreateTexture( L"cursor.png" ); // create guiElements this->privData->connectIP = new TextField( L"noedge-btn-ipfield.png", Float4(1.0f), Float4(1.0f), this, Float3(0.5f, 0.2f, 0.9f), Float2(0.5f, 0.05f), ResizeAspectRatio_Height ); @@ -112,7 +112,7 @@ bool LanMenuState::Render( ) Graphics::API::StartGuiRender(); - Graphics::API::RenderGuiElement( this->privData->mouseCursor, this->privData->mousePos, Float2(0.01f), Float4(1.0f) ); + Graphics::API::RenderGuiElement( this->privData->mouseCursor, this->privData->mousePos, Float2(0.15f, 0.24), Float4(1.0f) ); Graphics::API::RenderGuiElement( this->privData->background, Float3(0.5f, 0.5f, 1.0f), Float2(1.0f) ); this->privData->guiElements.RenderTexture(); @@ -133,7 +133,7 @@ void LanMenuState::ChangeState( ClientState next ) { switch( next ) { - case GameClientState::ClientState_Lobby: + case GameClientState::ClientState_NetLoad: // attempt to connect to lobby if( !this->privData->nwClient->Connect(this->privData->connectPort, (*this->privData->connectIP)[0]) ) return; @@ -141,6 +141,8 @@ void LanMenuState::ChangeState( ClientState next ) default: break; } + this->privData->keyboardInput->ReleaseTextTarget(); + this->privData->nextState = next; } @@ -149,7 +151,7 @@ void OnButtonInteract_Connect( Oyster::Event::ButtonEvent& e ) switch( e.state ) { case ButtonState_Released: - e.owner->ChangeState( GameClientState::ClientState_Lobby ); + e.owner->ChangeState( GameClientState::ClientState_NetLoad ); break; default: break; } diff --git a/Code/Game/GameClient/GameClientState/MainState.cpp b/Code/Game/GameClient/GameClientState/MainState.cpp index 761a2015..8cdc2dc5 100644 --- a/Code/Game/GameClient/GameClientState/MainState.cpp +++ b/Code/Game/GameClient/GameClientState/MainState.cpp @@ -55,7 +55,7 @@ bool MainState::Init( SharedStateContent &shared ) this->privData->mousePos = Float3( 0.0f ); this->privData->background = Graphics::API::CreateTexture( L"color_white.png" ); - this->privData->mouseCursor = Graphics::API::CreateTexture( L"cursor_md.png" ); + this->privData->mouseCursor = Graphics::API::CreateTexture( L"cursor.png" ); // create buttons ButtonRectangle *button; @@ -103,7 +103,11 @@ bool MainState::Render() Graphics::API::NewFrame(); Graphics::API::StartGuiRender(); - Graphics::API::RenderGuiElement( this->privData->mouseCursor, this->privData->mousePos, Float2(0.01f), Float4(1.0f) ); + if(this->privData->mouseInput->IsBtnDown(Input::Enum::SAMI_MouseLeftBtn)) + Graphics::API::RenderGuiElement( this->privData->mouseCursor, this->privData->mousePos, Float2(0.15f), Float4(1.0f) ); + else + Graphics::API::RenderGuiElement( this->privData->mouseCursor, this->privData->mousePos, Float2(0.15f, 0.24), Float4(1.0f) ); + Graphics::API::RenderGuiElement( this->privData->background, Float3(0.5f, 0.5f, 0.9f), Float2(1.0f), Float4(0.0f, 0.0f, 0.0f, 1.0f) ); this->privData->guiElements.RenderTexture(); diff --git a/Code/Misc/Input/Source/Win32/Win32Keyboard.cpp b/Code/Misc/Input/Source/Win32/Win32Keyboard.cpp index 84e3eb28..7abe863f 100644 --- a/Code/Misc/Input/Source/Win32/Win32Keyboard.cpp +++ b/Code/Misc/Input/Source/Win32/Win32Keyboard.cpp @@ -17,6 +17,7 @@ Win32Keyboard::Win32Keyboard(HWND target) this->device.hwndTarget = target; this->device.usUsage = RawInput_Usage_keyboard; this->device.dwFlags = RIDEV_NOLEGACY; + this->writePos = 0; memset(&this->keys[0], 0, sizeof(Win32Keyboard::Keys) * MAXKEYS); } Win32Keyboard::~Win32Keyboard() @@ -140,12 +141,20 @@ void Win32Keyboard::ProccessKeyboardData (RAWKEYBOARD keyboard) } else if (this->keys[SAKI_Left].isDown) { - this->writePos = std::max( this->writePos - 1, (wstring::size_type)0 ); + this->writePos = std::max( ((int)this->writePos) - 1, (int)(wstring::size_type)0 ); } else if (this->keys[SAKI_Right].isDown) { this->writePos = std::min( this->writePos + 1, this->textTarget->size() ); } + else if (this->keys[SAKI_Enter].isDown || this->keys[SAKI_NumpadEnter].isDown) + { + this->textTarget->insert( this->writePos, 1, '\n'); + } + else if ( this->keys[SAKI_Tab].isDown ) + { + this->textTarget->insert( this->writePos, 1, '\t'); + } else if (virtualKey && !isUp) { wchar_t test = towlower((wchar_t)virtualKey); @@ -176,9 +185,11 @@ void Win32Keyboard::ProccessKeyboardData (RAWKEYBOARD keyboard) else if(key == SAKI_0) test = L'}'; else if(key == SAKI_Add) test = L'\\'; } + this->textTarget->insert( this->writePos, 1, test); ++this->writePos; } + } } @@ -251,7 +262,7 @@ void Win32Keyboard::MapKey(RAWKEYBOARD& rawKB, SAKI& out_key, bool& isE0) case VK_DELETE: if (!isE0) out_key = SAKI_NumpadDecimal; - + else out_key = SAKI_Delete; break; case VK_HOME: @@ -271,24 +282,24 @@ void Win32Keyboard::MapKey(RAWKEYBOARD& rawKB, SAKI& out_key, bool& isE0) case VK_NEXT: if (!isE0) out_key = SAKI_Numpad3; - + break; // the standard arrow keys will always have their e0 bit set, but the // corresponding keys on the NUMPAD will not. case VK_LEFT: if (!isE0) out_key = SAKI_Numpad4; - + else out_key = SAKI_Left; break; case VK_RIGHT: if (!isE0) out_key = SAKI_Numpad6; - + else out_key = SAKI_Right; break; case VK_UP: if (!isE0) out_key = SAKI_Numpad8; - + else out_key = SAKI_Up; break; case VK_DOWN: From 13d6a062fc58cc9c801bfd94fa133bed4f11ce08 Mon Sep 17 00:00:00 2001 From: Linda Andersson Date: Wed, 26 Feb 2014 10:05:07 +0100 Subject: [PATCH 23/32] Added collision and weapon events and send them to client --- .../GameClient/GameClientState/GameState.cpp | 31 +++++++++++++ Code/Game/GameLogic/AttatchmentMassDriver.cpp | 10 ++++- Code/Game/GameLogic/CollisionManager.cpp | 3 +- Code/Game/GameLogic/Game.cpp | 4 ++ Code/Game/GameLogic/Game.h | 2 + Code/Game/GameLogic/GameAPI.h | 3 +- Code/Game/GameLogic/Level.cpp | 42 ++++++++++++------ Code/Game/GameProtocols/ObjectProtocols.h | 44 ++++++++++++++++++- .../GameProtocols/ProtocolIdentificationID.h | 1 + Code/Game/GameServer/GameSession.h | 1 + .../Implementation/GameSession_Gameplay.cpp | 5 +++ .../Implementation/GameSession_General.cpp | 1 + Code/Game/LevelLoader/ObjectDefines.h | 20 ++++++--- 13 files changed, 143 insertions(+), 24 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 7e8a0ee7..c5dd45c5 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -750,6 +750,15 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState case GameLogic::PlayerAction::PlayerAction_Idle: player->playAnimation(L"idle", true); break; + + case GameLogic::WeaponAction::WeaponAction_PrimaryShoot: + break; + case GameLogic::WeaponAction::WeaponAction_SecondaryShoot: + break; + case GameLogic::WeaponAction::WeaponAction_Reload: + break; + + default: break; } @@ -757,6 +766,28 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState } } return GameClientState::event_processed; + case protocol_Gameplay_ObjectCollision: + { + Protocol_ObjectCollision decoded(data); + C_Object *object; + object = (this->privData->players)[decoded.objectID]; + if( !object) + { + // if it is not a player + object = (*this->privData->dynamicObjects)[decoded.objectID]; + } + if( object ) + { + switch (decoded.collisionID) + { + case GameLogic::CollisionEvent::CollisionEvent_BasicCollision: + break; + default: + break; + } + } + } + return GameClientState::event_processed; default: break; } } diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index 62f3599e..13ef8fef 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -1,7 +1,7 @@ #include "AttatchmentMassDriver.h" #include "PhysicsAPI.h" #include "GameLogicStates.h" - +#include "Game.h" using namespace GameLogic; @@ -48,6 +48,8 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, { currentEnergy -= 90.0f; ForcePush(usage,dt); + // add CD + ((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_PrimaryShoot); } break; @@ -55,7 +57,9 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, if(currentEnergy >= 1.0f) { currentEnergy -= 1.0f; - ForcePull(usage,dt); + ForcePull(usage,dt); + // add CD + ((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_SecondaryShoot); } break; @@ -64,6 +68,8 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, { currentEnergy -= 90.0f; ForceZip(usage,dt); + // add CD + ((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_UtilityActivate); } break; } diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 3e931f8e..72057e2b 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -69,7 +69,8 @@ using namespace GameLogic; //player->playerState = PLAYER_STATE::PLAYER_STATE_WALKING; break; } - + // send collision event message + ((Game*)&Game::Instance())->onCollisionEventFnc(player, CollisionEvent::CollisionEvent_BasicCollision); //return Physics::ICustomBody::SubscriptMessage_none; } diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index 5879bd86..87216b3b 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -188,6 +188,10 @@ void Game::SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) { this->onPickupEventFnc = functionPointer; } +void Game::SetCollisionSubscription(GameEvent::CollisionEventFunction functionPointer) +{ + this->onCollisionEventFnc = functionPointer; +} bool Game::Initiate() { API::Instance().Init(); diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index abef28f4..28ad9772 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -87,6 +87,7 @@ namespace GameLogic void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) override; void SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) override; void SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) override; + void SetCollisionSubscription(GameEvent::CollisionEventFunction functionPointer) override; bool Initiate() override; float GetFrameTime() const; @@ -108,6 +109,7 @@ namespace GameLogic GameEvent::ObjectDeadFunction onDeadFnc; GameEvent::AnimationEventFunction onActionEventFnc; GameEvent::PickupEventFunction onPickupEventFnc; + GameEvent::CollisionEventFunction onCollisionEventFnc; }; } diff --git a/Code/Game/GameLogic/GameAPI.h b/Code/Game/GameLogic/GameAPI.h index 653fc26b..80b255bd 100644 --- a/Code/Game/GameLogic/GameAPI.h +++ b/Code/Game/GameLogic/GameAPI.h @@ -33,6 +33,7 @@ namespace GameLogic typedef void(*ObjectDeadFunction)(IObjectData* victim, IObjectData* killer, float seconds); // Callback method that sends killer and death timer typedef void(*PickupEventFunction)(IObjectData* player, int pickupEffectID ); // Callback method that sends killer and death timer typedef void(*AnimationEventFunction)(IObjectData* player, int actionID ); // Callback method that sends killer and death timer + typedef void(*CollisionEventFunction)(IObjectData*object, int collisionID); //etc... }; @@ -188,7 +189,7 @@ namespace GameLogic virtual void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) = 0; virtual void SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) = 0; virtual void SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) = 0; - + virtual void SetCollisionSubscription(GameEvent::CollisionEventFunction functionPointer) = 0; }; } diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 0f0ab632..40a2b55a 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -16,6 +16,7 @@ using namespace Oyster::Math; Level::Level(void) { + srand (time(NULL)); objID = 100; } Level::~Level(void) @@ -405,6 +406,15 @@ void Level::AddPlayerToTeam(Player *player, int teamID) } void Level::AddPlayerToGame(Player *player) { + for(int i = 0; i < (int)this->playerObjects.Size(); i++) + { + if (!this->playerObjects[i]) + { + this->playerObjects[i] = player; + return; + } + } + // if no free space, allocate a new spot this->playerObjects.Push(player); } void Level::RemovePlayerFromGame(Player *player) @@ -413,7 +423,7 @@ void Level::RemovePlayerFromGame(Player *player) { if ((Player*)this->playerObjects[i] == player) { - //this->playerObjects[i]. + this->playerObjects[i] = nullptr; } } } @@ -426,7 +436,8 @@ void Level::RespawnPlayer(Player *player) { //this->teamManager.RespawnPlayerRandom(player); - Float3 spawnPoint = spawnPoints[0]; + int i = rand() % spawnPoints.Size(); + Float3 spawnPoint = spawnPoints[i]; player->Respawn(spawnPoint); } void Level::Update(float deltaTime) @@ -434,19 +445,22 @@ void Level::Update(float deltaTime) // update lvl-things for(int i = 0; i < (int)this->playerObjects.Size(); i++) { - if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DEAD) + if(this->playerObjects[i]) { - // true when timer reaches 0 - if(this->playerObjects[i]->deathTimerTick(deltaTime)) - RespawnPlayer(this->playerObjects[i]); - } - else if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DIED) - { - this->playerObjects[i]->setDeathTimer(DEATH_TIMER); - // HACK to avoid crasch. affected by tag is NULL - Player* killer = this->playerObjects[i]->getAffectingPlayer(); - ((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i], DEATH_TIMER); // add killer ID - //((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i]->getAffectingPlayer(), DEATH_TIMER); // add killer ID + if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DEAD) + { + // true when timer reaches 0 + if(this->playerObjects[i]->deathTimerTick(deltaTime)) + RespawnPlayer(this->playerObjects[i]); + } + else if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DIED) + { + this->playerObjects[i]->setDeathTimer(DEATH_TIMER); + // HACK to avoid crasch. affected by tag is NULL + Player* killer = this->playerObjects[i]->getAffectingPlayer(); + ((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i], DEATH_TIMER); // add killer ID + //((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i]->getAffectingPlayer(), DEATH_TIMER); // add killer ID + } } } diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index 48fa71f7..9b469bbc 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -969,7 +969,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; } -//#define protocol_Gameplay_ObjectAction 369 + //#define protocol_Gameplay_ObjectAction 369 struct Protocol_ObjectAction :public Oyster::Network::CustomProtocolObject { short objectID; @@ -1010,4 +1010,46 @@ namespace GameLogic private: Oyster::Network::CustomNetProtocol protocol; }; + //#define protocol_Gameplay_ObjectCollision 370 + struct Protocol_ObjectCollision :public Oyster::Network::CustomProtocolObject + { + short objectID; + int collisionID; + // TODO: maybe position, impact, and velocity + + Protocol_ObjectCollision() + { + this->protocol[0].value = protocol_Gameplay_ObjectCollision; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + this->protocol[1].type = Oyster::Network::NetAttributeType_Short; + this->protocol[2].type = Oyster::Network::NetAttributeType_Int; + + this->objectID = -1; + this->collisionID = -1; + } + Protocol_ObjectCollision(Oyster::Network::CustomNetProtocol& p) + { + this->objectID = p[1].value.netShort; + this->collisionID = p[2].value.netInt; + } + Protocol_ObjectCollision( int id, int collisionID) + { + this->protocol[0].value = protocol_Gameplay_ObjectCollision; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + this->protocol[1].type = Oyster::Network::NetAttributeType_Short; + this->protocol[2].type = Oyster::Network::NetAttributeType_Int; + + this->objectID = id; + this->collisionID = collisionID; + } + Oyster::Network::CustomNetProtocol GetProtocol() override + { + this->protocol[1].value = objectID; + this->protocol[2].value = collisionID; + return protocol; + } + + private: + Oyster::Network::CustomNetProtocol protocol; + }; #endif // !GAMELOGIC_PLAYER_PROTOCOLS_H \ No newline at end of file diff --git a/Code/Game/GameProtocols/ProtocolIdentificationID.h b/Code/Game/GameProtocols/ProtocolIdentificationID.h index 95e10ba1..f4f2b136 100644 --- a/Code/Game/GameProtocols/ProtocolIdentificationID.h +++ b/Code/Game/GameProtocols/ProtocolIdentificationID.h @@ -72,6 +72,7 @@ #define protocol_Gameplay_ObjectDie 367 #define protocol_Gameplay_ObjectDisconnectPlayer 368 #define protocol_Gameplay_ObjectAction 369 +#define protocol_Gameplay_ObjectCollision 370 #define protocol_GameplayMAX 399 diff --git a/Code/Game/GameServer/GameSession.h b/Code/Game/GameServer/GameSession.h index 79b50395..d449ff2d 100644 --- a/Code/Game/GameServer/GameSession.h +++ b/Code/Game/GameServer/GameSession.h @@ -105,6 +105,7 @@ namespace DanBias static void ObjectDead ( GameLogic::IObjectData* victim, GameLogic::IObjectData* killer, float seconds ); static void PickupEvent ( GameLogic::IObjectData* movedObject, int pickupEffectID ); static void ActionEvent ( GameLogic::IObjectData* movedObject , int actionID ); + static void CollisionEvent ( GameLogic::IObjectData* Object , int collisionID ); //Private member variables private: Utility::DynamicMemory::DynamicArray gClients; diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index fd000a0c..218721be 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -176,6 +176,11 @@ using namespace DanBias; // send action protocol GameSession::gameSession->Send(Protocol_ObjectAction(movedObject->GetID(), actionID).GetProtocol()); } + void GameSession::CollisionEvent( GameLogic::IObjectData* movedObject , int collisionID ) + { + // send action protocol + GameSession::gameSession->Send(Protocol_ObjectCollision(movedObject->GetID(), collisionID).GetProtocol()); + } //*****************************************************// //****************** Protocol methods *****************// //******************************************************************************************************************// diff --git a/Code/Game/GameServer/Implementation/GameSession_General.cpp b/Code/Game/GameServer/Implementation/GameSession_General.cpp index ca869fb7..d19fcecf 100644 --- a/Code/Game/GameServer/Implementation/GameSession_General.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_General.cpp @@ -114,6 +114,7 @@ bool GameSession::Create(GameDescription& desc, bool forceStart) this->gameInstance.SetDeadSubscription(GameSession::ObjectDead); this->gameInstance.SetActionSubscription(GameSession::ActionEvent); this->gameInstance.SetPickupSubscription(GameSession::PickupEvent); + this->gameInstance.SetCollisionSubscription(GameSession::CollisionEvent); this->gameInstance.SetFPS(60); this->description.clients.Clear(); diff --git a/Code/Game/LevelLoader/ObjectDefines.h b/Code/Game/LevelLoader/ObjectDefines.h index 3eae71a5..e77174f7 100644 --- a/Code/Game/LevelLoader/ObjectDefines.h +++ b/Code/Game/LevelLoader/ObjectDefines.h @@ -95,16 +95,26 @@ namespace GameLogic enum PlayerAction { - PlayerAction_Jump, - PlayerAction_Walk, - PlayerAction_Idle, + PlayerAction_Jump = 0, + PlayerAction_Walk = 1, + PlayerAction_Idle = 2, }; + // continue ID counting from playerAction enum WeaponAction { - WeaponAtcion_PrimaryShoot, - WeaponAction_SecondaryShoot + WeaponAction_PrimaryShoot = 3, + WeaponAction_SecondaryShoot = 4, + WeaponAction_UtilityActivate = 5, + WeaponAction_Reload = 6, + WeaponAction_EnergyDepleted = 7, + }; + // TODO: add more collision Events + enum CollisionEvent + { + CollisionEvent_BasicCollision, + }; enum PickupType { PickupType_Health, From 8798fc90068c19ed4fe5b76a98f567b87f912edf Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Wed, 26 Feb 2014 10:22:08 +0100 Subject: [PATCH 24/32] Fixed static id not matching on client/server. --- Code/Game/GameLogic/Level.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 0f0ab632..e22c11b6 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -238,7 +238,11 @@ bool Level::InitiateLevel(std::wstring levelPath) { LevelMetaData* LevelObjData = ((LevelMetaData*)obj); std::string levelName = LevelObjData->levelName; + // LevelObjData->worldSize; + + //LevelMetaData is not an object. + --this->objID; } break; case ObjectType::ObjectType_Static: From 9ec3fc6fa40ead95f7f0cacb30eecdab87ce72cf Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Wed, 26 Feb 2014 10:22:43 +0100 Subject: [PATCH 25/32] Does not render non visible models anymore. --- Code/Game/GameClient/GameClientState/C_Object.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Code/Game/GameClient/GameClientState/C_Object.cpp b/Code/Game/GameClient/GameClientState/C_Object.cpp index b168b92c..8e84da8e 100644 --- a/Code/Game/GameClient/GameClientState/C_Object.cpp +++ b/Code/Game/GameClient/GameClientState/C_Object.cpp @@ -91,7 +91,10 @@ void C_Object::Render() { if( this->model ) { - Oyster::Graphics::API::RenderModel(model); + if(this->model->Visible) + { + Oyster::Graphics::API::RenderModel(model); + } } } void C_Object::Release() From 925f05b3b05d49be201c153f88bc77c4594c129a Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Wed, 26 Feb 2014 10:23:38 +0100 Subject: [PATCH 26/32] Health pickups is now working! --- .../GameClient/GameClientState/GameState.cpp | 18 ++++++++++++--- Code/Game/GameLogic/CollisionManager.cpp | 20 ++++++++++++----- Code/Game/GameLogic/PickupSystem/Pickup.cpp | 1 + .../GameLogic/PickupSystem/PickupHealth.cpp | 4 ++++ Code/Game/GameLogic/Player.cpp | 22 ++++++++++++------- .../Implementation/GameSession_Gameplay.cpp | 2 +- Code/Game/LevelLoader/LevelParser.cpp | 8 +++++++ 7 files changed, 57 insertions(+), 18 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 7e8a0ee7..28c65b12 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -142,8 +142,8 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa this->privData->camera.SetPosition( p->getPos() ); Float3 offset = Float3( 0.0f ); // DEBUG position of camera so we can see the player model - offset.y = p->getScale().y * 5.0f; - offset.z = p->getScale().z * -5.0f; + //offset.y = p->getScale().y * 5.0f; + //offset.z = p->getScale().z * -5.0f; // !DEBUG this->privData->camera.SetHeadOffset( offset ); this->privData->camera.UpdateOrientation(); @@ -187,7 +187,7 @@ bool GameState::Render() { if(playerObject->second) { - //if( this->privData->myId != playerObject->second->GetId() ) + if( this->privData->myId != playerObject->second->GetId() ) { playerObject->second->Render(); } @@ -596,6 +596,12 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState { // if it is not a player object = (*this->privData->dynamicObjects)[decoded.objectID]; + + if(!object) + { + //If it is a static object + object = (*this->privData->staticObjects)[decoded.objectID]; + } } if( object ) @@ -613,6 +619,12 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState { // if it is not a player object = (*this->privData->dynamicObjects)[decoded.objectID]; + + if(!object) + { + //If it is a static object + object = (*this->privData->staticObjects)[decoded.objectID]; + } } if( object ) diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 3e931f8e..187d592c 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -44,7 +44,6 @@ using namespace GameLogic; realObjB = realObjA; } - switch (realObjB->GetObjectType()) { case ObjectSpecialType::ObjectSpecialType_Generic: @@ -368,14 +367,19 @@ using namespace GameLogic; Object* a = (Object*)objA->GetCustomTag(); Object* b = (Object*)objB->GetCustomTag(); - if(!a) + if(!a) return; - if(!b) + if(!b) return; if(b->GetObjectType() == ObjectSpecialType_Player) { - ((Pickup*)a)->OnCollision((Player*)(b)); + //Only update if it is active. And if the player is alive + if(((Pickup*)a)->IsActive() && ((Player*)b)->GetState() != PLAYER_STATE_DEAD && ((Player*)b)->GetState() != PLAYER_STATE_DIED) + { + ((Pickup*)a)->OnCollision((Player*)(b)); + } + return; } else if(a->GetObjectType() != ObjectSpecialType_Player) { @@ -383,6 +387,10 @@ using namespace GameLogic; //Do nothing. return; } - - ((Pickup*)b)->OnCollision((Player*)a); + + //Only update if it is active. And if the player is alive + if(((Pickup*)b)->IsActive() && ((Player*)a)->GetState() != PLAYER_STATE_DEAD && ((Player*)a)->GetState() != PLAYER_STATE_DIED) + { + ((Pickup*)b)->OnCollision((Player*)a); + } } \ No newline at end of file diff --git a/Code/Game/GameLogic/PickupSystem/Pickup.cpp b/Code/Game/GameLogic/PickupSystem/Pickup.cpp index 73a319f8..a7bcaf14 100644 --- a/Code/Game/GameLogic/PickupSystem/Pickup.cpp +++ b/Code/Game/GameLogic/PickupSystem/Pickup.cpp @@ -9,6 +9,7 @@ Pickup::Pickup(Oyster::Physics::ICustomBody *rigidBody, EventOnCollision collisi this->active = true; this->spawnTime = spawnTime; timer.reset(); + this->GetRigidBody()->MoveToLimbo(); } Pickup::~Pickup() diff --git a/Code/Game/GameLogic/PickupSystem/PickupHealth.cpp b/Code/Game/GameLogic/PickupSystem/PickupHealth.cpp index 56cbef1e..5473c44c 100644 --- a/Code/Game/GameLogic/PickupSystem/PickupHealth.cpp +++ b/Code/Game/GameLogic/PickupSystem/PickupHealth.cpp @@ -1,4 +1,5 @@ #include "PickupHealth.h" +#include "../Game.h" using namespace GameLogic; @@ -14,5 +15,8 @@ PickupHealth::~PickupHealth() void PickupHealth::OnCollision(Player *player) { timer.reset(); + ((Game*)&Game::Instance())->onDisableFnc(this); + + this->active = false; player->DamageLife(-hpValue); } \ No newline at end of file diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index ddacf25b..9a440b2d 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -345,16 +345,22 @@ PLAYER_STATE Player::GetState() const void Player::DamageLife(int damage) { - this->playerStats.hp -= damage; - // send hp to client - this->gameInstance->onDamageTakenFnc( this, this->playerStats.hp); - - if(this->playerStats.hp <= 0) + if(damage != 0) { - this->playerStats.hp = 0; - this->playerState = PLAYER_STATE_DIED; - } + this->playerStats.hp -= damage; + if(this->playerStats.hp > 100) + this->playerStats.hp = 100; + + // send hp to client + this->gameInstance->onDamageTakenFnc( this, this->playerStats.hp); + + if(this->playerStats.hp <= 0) + { + this->playerStats.hp = 0; + this->playerState = PLAYER_STATE_DIED; + } + } } void Player::AddAffectedObject(DynamicObject &AffectedObject) diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index fd000a0c..7887e858 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -152,7 +152,7 @@ using namespace DanBias; } void GameSession::ObjectEnabled( GameLogic::IObjectData* movedObject ) { - GameSession::gameSession->Send(Protocol_ObjectDisable(movedObject->GetID()).GetProtocol()); + GameSession::gameSession->Send(Protocol_ObjectEnable(movedObject->GetID()).GetProtocol()); } void GameSession::ObjectDamaged( GameLogic::IObjectData* movedObject, float hp ) { diff --git a/Code/Game/LevelLoader/LevelParser.cpp b/Code/Game/LevelLoader/LevelParser.cpp index 680b0358..f94513b0 100644 --- a/Code/Game/LevelLoader/LevelParser.cpp +++ b/Code/Game/LevelLoader/LevelParser.cpp @@ -167,6 +167,14 @@ std::vector> LevelParser::Parse(std::string filen ParseObject(&buffer[counter], &header->healthValue, 4); counter += 4; + + // DEBUG + header->position[1] = 150; + header->spawnTime = 5; + header->boundingVolume.box.mass = 0; + header->typeID = ObjectType_Static; + header->healthValue = 50; + // !DEBUG objects.push_back(header); break; From 16ca665311e35090a95144c945b8db5eb7dc4bd0 Mon Sep 17 00:00:00 2001 From: Linda Andersson Date: Wed, 26 Feb 2014 11:09:24 +0100 Subject: [PATCH 27/32] Fixed deleting problems when shuting down --- Code/Game/GameLogic/Level.cpp | 116 +++--------------- Code/Game/GameLogic/Level.h | 11 +- Code/Game/GameLogic/Player.cpp | 6 +- .../GameServer/Implementation/GameClient.cpp | 3 - 4 files changed, 27 insertions(+), 109 deletions(-) diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index d785a082..233e73da 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -17,12 +17,10 @@ using namespace Oyster::Math; Level::Level(void) { srand (time(NULL)); - objID = 100; + objIDCounter = 100; } Level::~Level(void) { - delete this->levelObj; - this->levelObj = NULL; } Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) { @@ -32,7 +30,7 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) { case ObjectSpecialType_None: { - gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; @@ -50,22 +48,22 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) float worldSize = ((WorldAttributes*)obj)->worldSize; float atmosphereSize = ((WorldAttributes*)obj)->atmoSphereSize; - gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_Building: { - gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_Stone: { - gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_StandardBox: { - gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_RedExplosiveBox: @@ -73,7 +71,7 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) Oyster::Math::Float dmg = 120; Oyster::Math::Float force = 500; Oyster::Math::Float radie = 3; - gameObj = new ExplosiveCrate(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID++, dmg, force, radie); + gameObj = new ExplosiveCrate(rigidBody, (ObjectSpecialType)obj->specialTypeID, objIDCounter++, dmg, force, radie); } break; //case ObjectSpecialType_BlueExplosiveBox: @@ -82,24 +80,24 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) // break; case ObjectSpecialType_SpikeBox: { - gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_Spike: { - gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_CrystalFormation: { int dmg = 50; //gameObj = new Crystal(rigidBody); - gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_CrystalShard: { - gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_JumpPad: @@ -107,39 +105,28 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) float power = 500; //((JumpPadAttributes*)obj)->power; Oyster::Math::Float3 dir = ((JumpPadAttributes*)obj)->direction; Oyster::Math::Float3 pushForce = dir * power; - gameObj = new JumpPad(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID , pushForce); + gameObj = new JumpPad(rigidBody, (ObjectSpecialType)obj->specialTypeID, objIDCounter , pushForce); } break; case ObjectSpecialType_Portal: { Oyster::Math::Float3 destination = ((PortalAttributes*)obj)->destination; - gameObj = new Portal(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID, destination); - } - break; - //case ObjectSpecialType_SpawnPoint: - //{ - // save - - //} - break; - case ObjectSpecialType_Player: - { - // should not be read from the lvl format + gameObj = new Portal(rigidBody, (ObjectSpecialType)obj->specialTypeID, objIDCounter, destination); } break; case ObjectSpecialType_Generic: { - gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_PickupHealth: { - gameObj = new PickupHealth(rigidBody, obj->specialTypeID, objID, ((PickupHealthAttributes*)obj)->spawnTime, ((PickupHealthAttributes*)obj)->healthValue); + gameObj = new PickupHealth(rigidBody, obj->specialTypeID, objIDCounter, ((PickupHealthAttributes*)obj)->spawnTime, ((PickupHealthAttributes*)obj)->healthValue); } break; default: { - gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; } @@ -231,7 +218,7 @@ bool Level::InitiateLevel(std::wstring levelPath) for (int i = 0; i < objCount; i++) { - ++this->objID; + ++this->objIDCounter; ObjectTypeHeader* obj = objects.at(i); switch (obj->typeID) { @@ -243,7 +230,7 @@ bool Level::InitiateLevel(std::wstring levelPath) // LevelObjData->worldSize; //LevelMetaData is not an object. - --this->objID; + --this->objIDCounter; } break; case ObjectType::ObjectType_Static: @@ -338,71 +325,6 @@ bool Level::InitiateLevel(std::wstring levelPath) return true; } -bool Level::InitiateLevel(float radius) -{ - API::Instance().SetGravityPoint(Oyster::Math3D::Float3(0,0,0)); - API::Instance().SetGravity(200); - int idCount = 100; - // add level sphere - ICustomBody* rigidBody = API::Instance().AddCollisionSphere(599.2f, Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f); - - levelObj = new StaticObject(rigidBody, LevelCollisionAfter, ObjectSpecialType_World, idCount++); - - //this->levelObj->objectID = idCount++; - rigidBody->SetCustomTag(levelObj); - - - ICustomBody* rigidBody_TestBox; - - int nrOfBoxex = 5; - int offset = 0; - for(int i =0; i< nrOfBoxex; i ++) - { - rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(0.0f, 605.0f + i*5.0f, 10.0f), 5.0f, 0.5f, 0.8f, 0.6f); - - this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox, Object::DefaultOnCollision, ObjectSpecialType_StandardBox, idCount++)); - } - /*offset += nrOfBoxex; - for(int i =0; i< nrOfBoxex; i ++) - { - rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0,5, -605 -( i*5)), 5); - - this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultOnCollision, OBJECT_TYPE::OBJECT_TYPE_BOX)); - rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i+offset]); - - } - offset += nrOfBoxex; - for(int i =0; i< nrOfBoxex; i ++) - { - rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(200, 620 + ( i*7), 0), 5); - - this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultOnCollision, OBJECT_TYPE::OBJECT_TYPE_BOX)); - rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i+offset]); - } - offset += nrOfBoxex; - for(int i =0; i< nrOfBoxex; i ++) - { - rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(5, 605 + i*5, 0), 5); - - this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultOnCollision, OBJECT_TYPE::OBJECT_TYPE_BOX)); - rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i]); - - }*/ - - // add crystal - ICustomBody* rigidBody_Crystal = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(10.0f, 605.0f, 0.0f), 5.0f, 0.5f, 0.8f, 0.6f); - this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal, Object::DefaultOnCollision, ObjectSpecialType_StandardBox, idCount++)); - - // add house - ICustomBody* rigidBody_House =API::Instance().AddCollisionBox(Oyster::Math::Float3(20.0f, 20.0f, 20.0f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(-50.0f, 590.0f, 0.0f), 0.0f, 0.5f, 0.8f, 0.6f); - this->staticObjects.Push(new StaticObject(rigidBody_House, Object::DefaultOnCollision, ObjectSpecialType_Generic, idCount++)); - - // add jumppad - - ICustomBody* rigidBody_Jumppad = API::Instance().AddCollisionBox(Oyster::Math::Float3(1.0f, 1.0f, 1.0f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(4.0f, 600.3f, 0.0f), 5.0f, 0.5f, 0.8f, 0.6f); - this->staticObjects.Push(new JumpPad(rigidBody_Jumppad, ObjectSpecialType_JumpPad,idCount++ ,Oyster::Math::Float3(0,2000,0))); - return true; -} void Level::AddPlayerToTeam(Player *player, int teamID) { @@ -490,7 +412,7 @@ void Level::PhysicsOnMoveLevel(const ICustomBody *object) Object* temp = (Object*)object->GetCustomTag(); ((Game*)&Game::Instance())->onMoveFnc(temp); } -Utility::DynamicMemory::DynamicArray> Level::GetPlayers() +Utility::DynamicMemory::DynamicArray Level::GetPlayers() { return this->playerObjects; } diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index 7d6c25c9..876fd034 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -35,7 +35,6 @@ namespace GameLogic * @param levelPath: Path to a file that contains all information on the level ********************************************************/ bool InitiateLevel(std::wstring levelPath); - bool InitiateLevel(float radius); Oyster::Physics::ICustomBody* InitRigidBodyCube( const ObjectHeader* obj); Oyster::Physics::ICustomBody* InitRigidBodySphere( const ObjectHeader* obj); @@ -77,19 +76,19 @@ namespace GameLogic static void PlayerDied( Player* player ); static void PhysicsOnMoveLevel(const Oyster::Physics::ICustomBody *object); - Utility::DynamicMemory::DynamicArray> GetPlayers(); + Utility::DynamicMemory::DynamicArray GetPlayers(); Utility::DynamicMemory::DynamicArray> GetStaticObjects(); Utility::DynamicMemory::DynamicArray> GetDynamicObject(); private: - Utility::DynamicMemory::DynamicArray> playerObjects; + Utility::DynamicMemory::DynamicArray playerObjects; TeamManager teamManager; Utility::DynamicMemory::DynamicArray> staticObjects; Utility::DynamicMemory::DynamicArray> dynamicObjects; GameModeType gameMode; - Utility::DynamicMemory::SmartPointer rigidBodyLevel; - StaticObject *levelObj; - int objID; + //Utility::DynamicMemory::SmartPointer rigidBodyLevel; +// //StaticObject *levelObj; + int objIDCounter; Utility::DynamicMemory::DynamicArray spawnPoints; PickupSystem pickupSystem; diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 040e70be..550488bd 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -37,10 +37,10 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustom Player::~Player(void) { - if(weapon) + if(this->weapon) { - delete weapon; - weapon = NULL; + delete this->weapon; + this->weapon = NULL; } } void Player::initPlayerData() diff --git a/Code/Game/GameServer/Implementation/GameClient.cpp b/Code/Game/GameServer/Implementation/GameClient.cpp index 90b412ef..74795ce6 100644 --- a/Code/Game/GameServer/Implementation/GameClient.cpp +++ b/Code/Game/GameServer/Implementation/GameClient.cpp @@ -25,9 +25,6 @@ GameClient::GameClient(Utility::DynamicMemory::SmartPointerplayer) - this->player->Inactivate(); - this->isReady = false; this->character = L"char_orca.dan"; this->alias = L"Unknown"; From 934bc80b6212244e419f35547178dbd50c0c9953 Mon Sep 17 00:00:00 2001 From: Linda Andersson Date: Wed, 26 Feb 2014 11:53:33 +0100 Subject: [PATCH 28/32] InGame keys: Go to mainMenu with M. Exit client with ESC. Fix drop in drop out correctly. --- .../GameClient/GameClientState/GameState.cpp | 19 ++++++++++++++----- .../GameClient/GameClientState/GamingUI.cpp | 6 ++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 556ddf03..c65aa7b4 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -153,19 +153,28 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa GameClientState::ClientState GameState::Update( float deltaTime ) { - GameStateUI::UIState UIstate = this->currGameUI->Update( deltaTime ); + GameStateUI::UIState UIstate = this->gameUI->Update( deltaTime ); switch (UIstate) { + case DanBias::Client::GameStateUI::UIState_shut_down: + { + this->privData->nextState = ClientState_Quit; + // disconnect + } + + break; case DanBias::Client::GameStateUI::UIState_same: break; case DanBias::Client::GameStateUI::UIState_gaming: break; case DanBias::Client::GameStateUI::UIState_main_menu: - //this->privData->nextState = - break; - case DanBias::Client::GameStateUI::UIState_shut_down: - this->privData->nextState = ClientState_Quit; + { + this->privData->nextState = ClientState_Main; + // disconnect + } + break; + default: break; } diff --git a/Code/Game/GameClient/GameClientState/GamingUI.cpp b/Code/Game/GameClient/GameClientState/GamingUI.cpp index 1486fdda..d12dfdb3 100644 --- a/Code/Game/GameClient/GameClientState/GamingUI.cpp +++ b/Code/Game/GameClient/GameClientState/GamingUI.cpp @@ -17,6 +17,7 @@ GamingUI::GamingUI() : this->camera = nullptr; this->plane = nullptr; this->text = nullptr; + this->nextState = GameStateUI::UIState_same; } GamingUI::GamingUI( InputClass *input, NetworkClient *connection, Camera_FPSV2 *camera ) : @@ -25,6 +26,7 @@ GamingUI::GamingUI( InputClass *input, NetworkClient *connection, Camera_FPSV2 * this->input = input; this->netClient = connection; this->camera = camera; + this->nextState = GameStateUI::UIState_same; } GamingUI::~GamingUI() { /* Do nothing */ } @@ -169,6 +171,10 @@ void GamingUI::ReadKeyInput() { this->nextState = GameStateUI::UIState_shut_down; } + if( this->input->IsKeyPressed(DIK_M) ) + { + this->nextState = GameStateUI::UIState_main_menu; + } // !DEGUG KEYS // TODO: implement sub-menu } From 15df481dd30afe5dabc2ef9d5fa1c5851b25c8b8 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Wed, 26 Feb 2014 12:00:30 +0100 Subject: [PATCH 29/32] GL - merge stuff --- Code/Game/GameLogic/CollisionManager.cpp | 4 +- Code/Game/GameLogic/DynamicObject.cpp | 5 -- Code/Game/GameLogic/Level.cpp | 58 +++++++++++++++++++----- Code/Game/GameLogic/Player.cpp | 35 +++----------- Code/Game/GameLogic/Player.h | 7 +-- 5 files changed, 58 insertions(+), 51 deletions(-) diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 32f5bdc5..c355fd04 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -255,16 +255,18 @@ using namespace GameLogic; { //realobjA is the affectedObject, transfer this to realobjB realObjB->SetAffectedBy(*realObjA->getAffectingPlayer()); + return; } if(realObjB->getAffectingPlayer() != NULL && realObjA->getAffectingPlayer() == NULL) { //realobjB is the affectedObject, transfer this to realobjA realObjA->SetAffectedBy(*realObjB->getAffectingPlayer()); + return; } - if(realObjA->getAffectingPlayer() != NULL && realObjB->getAffectingPlayer() != NULL) + if(realObjA->getAffectingPlayer() != NULL && realObjB->getAffectingPlayer() != NULL && ( realObjA->getAffectingPlayer()->GetID() != realObjB->getAffectingPlayer()->GetID())) { //Both objects have a player affecting them, now use the special case if(realObjA->GetRigidBody()->GetState().previousVelocity.GetMagnitude() > realObjB->GetRigidBody()->GetState().previousVelocity.GetMagnitude() ) diff --git a/Code/Game/GameLogic/DynamicObject.cpp b/Code/Game/GameLogic/DynamicObject.cpp index 844deaf2..d785b4d4 100644 --- a/Code/Game/GameLogic/DynamicObject.cpp +++ b/Code/Game/GameLogic/DynamicObject.cpp @@ -90,11 +90,6 @@ void DynamicObject::Activate() void DynamicObject::SetAffectedBy(Player &player) { this->affectedBy = &player; - if(this->type != ObjectSpecialType::ObjectSpecialType_Player) //should not add itself to its own list if its a player - { - player.AddAffectedObject(*this); - } - } Player* DynamicObject::getAffectingPlayer() diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 233e73da..56c0e21c 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -369,23 +369,59 @@ void Level::RespawnPlayer(Player *player) void Level::Update(float deltaTime) { // update lvl-things + + for(int i = 0; i < (int)this->playerObjects.Size(); i++) { - if(this->playerObjects[i]) + if(this->playerObjects[i]->getAffectingPlayer() != NULL) { - if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DEAD) + + } + + if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DEAD) + { + // true when timer reaches 0 + if(this->playerObjects[i]->deathTimerTick(deltaTime)) + RespawnPlayer(this->playerObjects[i]); + } + else if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DIED) + { + this->playerObjects[i]->setDeathTimer(DEATH_TIMER); + // HACK to avoid crasch. affected by tag is NULL + //((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i], DEATH_TIMER); // add killer ID + Player* killer = this->playerObjects[i]->getAffectingPlayer(); + if(!killer) //if there is no killer then you commited suicide { - // true when timer reaches 0 - if(this->playerObjects[i]->deathTimerTick(deltaTime)) - RespawnPlayer(this->playerObjects[i]); + killer = this->playerObjects[i]; } - else if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DIED) + ((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], killer, DEATH_TIMER); // add killer ID + } + } + + for(int i = 0; i < dynamicObjects.Size(); i++) + { + if(dynamicObjects[i]->getAffectingPlayer() != NULL) + { + Oyster::Math::Float vel = dynamicObjects[i]->GetRigidBody()->GetLinearVelocity().GetMagnitude(); + + if(vel <= 0.1f) // is bearly moving { - this->playerObjects[i]->setDeathTimer(DEATH_TIMER); - // HACK to avoid crasch. affected by tag is NULL - Player* killer = this->playerObjects[i]->getAffectingPlayer(); - ((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i], DEATH_TIMER); // add killer ID - //((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i]->getAffectingPlayer(), DEATH_TIMER); // add killer ID + //set the tag AffectedBy to NULL + dynamicObjects[i]->RemoveAffectedBy(); + } + } + } + + for(int i = 0; i < playerObjects.Size(); i++) + { + if(playerObjects[i]->getAffectingPlayer() != NULL) + { + Oyster::Math::Float vel = playerObjects[i]->GetRigidBody()->GetLinearVelocity().GetMagnitude(); + + if(vel <= 0.1f) // is bearly moving + { + //set the tag AffectedBy to NULL + playerObjects[i]->RemoveAffectedBy(); } } } diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 550488bd..e8787a1b 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -8,11 +8,11 @@ using namespace GameLogic; using namespace Oyster::Physics; const float MOVE_FORCE = 30; const float KEY_TIMER = 0.03f; +const float AFFECTED_TIMER = 1.0f; Player::Player() :DynamicObject() { Player::initPlayerData(); - AffectedObjects.Reserve(15); this->weapon = NULL; this->teamID = -1; } @@ -22,7 +22,6 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision) { this->weapon = new Weapon(2,this); Player::initPlayerData(); - AffectedObjects.Reserve(15); this->teamID = teamID; } @@ -31,7 +30,6 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustom { this->weapon = new Weapon(2,this); Player::initPlayerData(); - AffectedObjects.Reserve(15); this->teamID = teamID; } @@ -57,7 +55,7 @@ void Player::initPlayerData() this->key_strafeRight = 0; this->key_strafeLeft = 0; this->key_jump = 0; - this->invincibleCooldown = 0; + this->RecentlyAffected = 0; this->deathTimer = 0; this->rotationUp = 0; @@ -67,7 +65,10 @@ void Player::BeginFrame() { if( this->playerState != PLAYER_STATE_DEAD && this->playerState != PLAYER_STATE_DIED) { - weapon->Update(0.002f); + weapon->Update(0.002f); + + + Oyster::Math::Float maxSpeed = 30; @@ -214,16 +215,6 @@ void Player::BeginFrame() void Player::EndFrame() { - //check if there are any objects that can be removed from the AffectedObjects list - for(int i = 0; i < this->AffectedObjects.Size(); i++) - { - if(this->AffectedObjects[i] && (this->AffectedObjects[i]->GetRigidBody()->GetState().previousVelocity).GetMagnitude() <= 0.1f) - { - this->AffectedObjects[i]->RemoveAffectedBy(); - this->AffectedObjects.Remove(i); - } - - } } void Player::Move(const PLAYER_MOVEMENT &movement) @@ -360,20 +351,6 @@ void Player::DamageLife(int damage) } } -void Player::AddAffectedObject(DynamicObject &AffectedObject) -{ - //check if object already exists in the list, if so then do not add - for(int i = 0; i < AffectedObjects.Size(); i++) - { - if(AffectedObjects[i]->GetID() == AffectedObject.GetID()) - { - //object already exists, exit function - return; - } - } - //else you add the object to the stack - AffectedObjects.Push(&AffectedObject); -} bool Player::deathTimerTick(float dt) { this->deathTimer -= dt; diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index c64ba066..edb4cc79 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -67,8 +67,6 @@ namespace GameLogic void SetLookDir(const Oyster::Math3D::Float3& lookDir); void TurnLeft(Oyster::Math3D::Float deltaRadians); - - void AddAffectedObject(DynamicObject &AffectedObject); /******************************************************** * Collision function for player, this is to be sent to physics through the subscribe function with the rigidbody @@ -90,6 +88,7 @@ namespace GameLogic Oyster::Math::Float4x4 GetOrientation() const; int GetTeamID() const; PLAYER_STATE GetState() const; + Oyster::Math::Float GetRecentlyAffected(); void DamageLife(int damage); void setDeathTimer(float deathTimer); @@ -104,8 +103,6 @@ namespace GameLogic void initPlayerData(); private: - - Utility::DynamicMemory::DynamicArray AffectedObjects; int teamID; Weapon *weapon; PLAYER_STATE playerState; @@ -122,7 +119,7 @@ namespace GameLogic float deathTimer; bool hasTakenDamage; - float invincibleCooldown; + Oyster::Math::Float RecentlyAffected; PlayerStats playerStats; PlayerScore playerScore; From 4cd91fadad7767b6fabd6b913646fbb4fe4fec0e Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Wed, 26 Feb 2014 13:59:06 +0100 Subject: [PATCH 30/32] Found bug. Explosive box was increasing the ID. --- Code/Game/GameLogic/Level.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 56c0e21c..3fa39829 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -71,7 +71,7 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) Oyster::Math::Float dmg = 120; Oyster::Math::Float force = 500; Oyster::Math::Float radie = 3; - gameObj = new ExplosiveCrate(rigidBody, (ObjectSpecialType)obj->specialTypeID, objIDCounter++, dmg, force, radie); + gameObj = new ExplosiveCrate(rigidBody, (ObjectSpecialType)obj->specialTypeID, objIDCounter, dmg, force, radie); } break; //case ObjectSpecialType_BlueExplosiveBox: @@ -228,9 +228,6 @@ bool Level::InitiateLevel(std::wstring levelPath) std::string levelName = LevelObjData->levelName; // LevelObjData->worldSize; - - //LevelMetaData is not an object. - --this->objIDCounter; } break; case ObjectType::ObjectType_Static: From a896d146c7ec12d2435b0c8ca2f6a284698784e3 Mon Sep 17 00:00:00 2001 From: dean11 Date: Wed, 26 Feb 2014 14:33:08 +0100 Subject: [PATCH 31/32] Merged with physics and added filepath --- Code/Game/GameLogic/Level.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 446866b4..5a6bfa09 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -237,7 +237,9 @@ ICustomBody* Level::InitRigidBodyMesh( const ObjectHeader* obj) //rigidBodyRadius = (obj->scale[0] * obj->scale[1] * obj->scale[2]) * obj->boundingVolume.sphere.radius; //create the rigid body - rigidBody = API::Instance().AddTriangleMesh(obj->boundingVolume.cgMesh.filename, rigidWorldRotation , rigidWorldPos , rigidBodyMass, obj->boundingVolume.cgMesh.restitutionCoeff , obj->boundingVolume.cgMesh.frictionCoeffStatic , obj->boundingVolume.cgMesh.frictionCoeffDynamic); + std::wstring fname = L"..\\Content\\Worlds\\cgf\\"; + fname.append(obj->boundingVolume.cgMesh.filename); + rigidBody = API::Instance().AddTriangleMesh( fname , rigidWorldRotation , rigidWorldPos , rigidBodyMass, obj->boundingVolume.cgMesh.restitutionCoeff , obj->boundingVolume.cgMesh.frictionCoeffStatic , obj->boundingVolume.cgMesh.frictionCoeffDynamic); return rigidBody; } bool Level::InitiateLevel(std::wstring levelPath) From 3bfedf920aef03db278fd22b75dfd98351a412ca Mon Sep 17 00:00:00 2001 From: dean11 Date: Wed, 26 Feb 2014 16:10:04 +0100 Subject: [PATCH 32/32] GameServer - minor --- Code/Game/GameClient/DanBiasGame_Impl.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Code/Game/GameClient/DanBiasGame_Impl.cpp b/Code/Game/GameClient/DanBiasGame_Impl.cpp index 7c809af6..85ea810a 100644 --- a/Code/Game/GameClient/DanBiasGame_Impl.cpp +++ b/Code/Game/GameClient/DanBiasGame_Impl.cpp @@ -78,8 +78,8 @@ namespace DanBias //if(! data.window->CreateWin(WindowShell::WINDOW_INIT_DESC(L"Window", cPOINT(1600, 900), cPOINT()))) WindowShell::WINDOW_INIT_DESC winDesc; - winDesc.windowSize.x = 1920; - winDesc.windowSize.y = 1080; + winDesc.windowSize.x = 1280; + winDesc.windowSize.y = 720; winDesc.windowProcCallback = WindowCallBack; if(! data.window->CreateWin(winDesc) ) @@ -153,7 +153,7 @@ namespace DanBias Oyster::Graphics::API::Option p; p.modelPath = L"..\\Content\\Models\\"; p.texturePath = L"..\\Content\\Textures\\"; - p.Resolution = Oyster::Math::Float2( 1920.0f, 1080.0f ); + p.Resolution = Oyster::Math::Float2( 1280.0f, 720.0f ); //! @todo fix proper amb value p.AmbientValue = 1.3f;