From fbb53e3a6dd481d0f8a337728ba79c979e6a221e Mon Sep 17 00:00:00 2001 From: Turanszki Janos Date: Sat, 23 Nov 2019 04:33:03 +0000 Subject: [PATCH] input refactor --- Documentation/ScriptingAPI-Documentation.md | 62 +- Documentation/WickedEngine-Documentation.md | 2 +- Editor/Editor.cpp | 78 +- Editor/Translator.cpp | 8 +- Editor/main.cpp | 4 +- README.md | 6 +- WickedEngine/MainComponent.cpp | 4 +- WickedEngine/WickedEngine.h | 5 +- WickedEngine/WickedEngine_SHARED.vcxitems | 8 +- .../WickedEngine_SHARED.vcxitems.filters | 24 +- WickedEngine/wiDirectInput.cpp | 743 +++++++++--------- WickedEngine/wiDirectInput.h | 80 +- WickedEngine/wiGUI.cpp | 4 +- WickedEngine/wiInitializer.cpp | 2 +- .../{wiInputManager.cpp => wiInput.cpp} | 148 +++- WickedEngine/wiInput.h | 110 +++ WickedEngine/wiInputManager.h | 78 -- WickedEngine/wiInputManager_BindLua.cpp | 278 ------- WickedEngine/wiInput_BindLua.cpp | 260 ++++++ ...putManager_BindLua.h => wiInput_BindLua.h} | 16 +- WickedEngine/wiLua.cpp | 4 +- WickedEngine/wiRawInput.h | 54 +- WickedEngine/wiVersion.cpp | 2 +- WickedEngine/wiWidget.cpp | 34 +- WickedEngine/wiXInput.cpp | 93 ++- WickedEngine/wiXInput.h | 48 +- scripts/camera_animation_clamped.lua | 2 +- scripts/camera_animation_repeat.lua | 2 +- scripts/character_controller_tps.lua | 16 +- scripts/fighting_game.lua | 22 +- 30 files changed, 1153 insertions(+), 1044 deletions(-) rename WickedEngine/{wiInputManager.cpp => wiInput.cpp} (80%) create mode 100644 WickedEngine/wiInput.h delete mode 100644 WickedEngine/wiInputManager.h delete mode 100644 WickedEngine/wiInputManager_BindLua.cpp create mode 100644 WickedEngine/wiInput_BindLua.cpp rename WickedEngine/{wiInputManager_BindLua.h => wiInput_BindLua.h} (65%) diff --git a/Documentation/ScriptingAPI-Documentation.md b/Documentation/ScriptingAPI-Documentation.md index 03d29fd09..e537c5c90 100644 --- a/Documentation/ScriptingAPI-Documentation.md +++ b/Documentation/ScriptingAPI-Documentation.md @@ -698,10 +698,10 @@ Handles the network communication features. ### Input Handling These provide functions to check the state of the input devices. -#### InputManager +#### Input Query input devices -- [outer]input : InputManager -- [void-constructor]InputManager() +- [outer]input : Input +- [void-constructor]Input() - Down(int code, opt int type = INPUT_TYPE_KEYBOARD, opt int playerindex = 0) : bool result -- Check whether a button is currently being held down - Press(int code, opt int type = INPUT_TYPE_KEYBOARD, opt int playerindex = 0) : bool result -- Check whether a button has just been pushed that wasn't before - Hold(int code, opt int duration = 30, opt boolean continuous = false, opt int type = INPUT_TYPE_KEYBOARD, opt int playerindex = 0) : bool result -- Check whether a button was being held down for a specific duration (nunmber of frames). If continuous == true, than it will also return true after the duration was reached @@ -722,38 +722,38 @@ Describes a touch contact point - [outer]TOUCHSTATE_RELEASED : int - [outer]TOUCHSTATE_MOVED : int -#### Input types -- [outer]INPUT_TYPE_KEYBOARD : int -- keyboard or mouse -- [outer]INPUT_TYPE_GAMEPAD : int -- xinput or directinput gamepad - #### Keyboard Key codes -- [outer]VK_UP : int -- [outer]VK_DOWN : int -- [outer]VK_LEFT : int -- [outer]VK_RIGHT : int -- [outer]VK_SPACE : int -- [outer]VK_RETURN : int -- [outer]VK_RSHIFT : int -- [outer]VK_LSHIFT : int -- [outer]VK_F1 : int -- [outer]VK_F2 : int -- [outer]VK_F3 : int -- [outer]VK_F4 : int -- [outer]VK_F5 : int -- [outer]VK_F6 : int -- [outer]VK_F7 : int -- [outer]VK_F8 : int -- [outer]VK_F9 : int -- [outer]VK_F10 : int -- [outer]VK_F11 : int -- [outer]VK_F12 : int -- [outer]VK_ESCAPE : int +- [outer]KEYBOARD_BUTTON_UP : int +- [outer]KEYBOARD_BUTTON_DOWN : int +- [outer]KEYBOARD_BUTTON_LEFT : int +- [outer]KEYBOARD_BUTTON_RIGHT : int +- [outer]KEYBOARD_BUTTON_SPACE : int +- [outer]KEYBOARD_BUTTON_RSHIFT : int +- [outer]KEYBOARD_BUTTON_LSHIFT : int +- [outer]KEYBOARD_BUTTON_F1 : int +- [outer]KEYBOARD_BUTTON_F2 : int +- [outer]KEYBOARD_BUTTON_F3 : int +- [outer]KEYBOARD_BUTTON_F4 : int +- [outer]KEYBOARD_BUTTON_F5 : int +- [outer]KEYBOARD_BUTTON_F6 : int +- [outer]KEYBOARD_BUTTON_F7 : int +- [outer]KEYBOARD_BUTTON_F8 : int +- [outer]KEYBOARD_BUTTON_F9 : int +- [outer]KEYBOARD_BUTTON_F10 : int +- [outer]KEYBOARD_BUTTON_F11 : int +- [outer]KEYBOARD_BUTTON_F12 : int +- [outer]KEYBOARD_BUTTON_ENTER : int +- [outer]KEYBOARD_BUTTON_ESCAPE : int +- [outer]KEYBOARD_BUTTON_HOME : int +- [outer]KEYBOARD_BUTTON_RCONTROL : int +- [outer]KEYBOARD_BUTTON_LCONTROL : int +- [outer]KEYBOARD_BUTTON_DELETE : int - You can also generate a key code by calling string.byte(char uppercaseLetter) where the parameter represents the desired key of the keyboard #### Mouse Key Codes -- [outer]VK_LBUTTON : int -- [outer]VK_MBUTTON : int -- [outer]VK_RBUTTON : int +- [outer]MOUSE_BUTTON_LEFT : int +- [outer]MOUSE_BUTTON_RIGHT : int +- [outer]MOUSE_BUTTON_MIDDLE : int #### Gamepad Key Codes - [outer]GAMEPAD_BUTTON_UP : int diff --git a/Documentation/WickedEngine-Documentation.md b/Documentation/WickedEngine-Documentation.md index e4c32289c..b68f15f07 100644 --- a/Documentation/WickedEngine-Documentation.md +++ b/Documentation/WickedEngine-Documentation.md @@ -127,7 +127,7 @@ A collection of engine-level helper classes ## Input The input interface can be found here -- wiInputManager +- wiInput - This manages all inputs - There are several functions, such as down(), press(), etc. to check button states. diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index 7434dfede..2cfbafbc5 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -752,7 +752,7 @@ void EditorComponent::Update(float dt) selectionOutlineTimer += dt; // Exit cinema mode: - if (wiInputManager::down(VK_ESCAPE)) + if (wiInput::down(wiInput::KEYBOARD_BUTTON_ESCAPE)) { if (renderPath != nullptr) { @@ -773,49 +773,49 @@ void EditorComponent::Update(float dt) static bool camControlStart = true; if (camControlStart) { - originalMouse = wiInputManager::getpointer(); + originalMouse = wiInput::getpointer(); } - XMFLOAT4 currentMouse = wiInputManager::getpointer(); + XMFLOAT4 currentMouse = wiInput::getpointer(); float xDif = 0, yDif = 0; - if (wiInputManager::down(VK_MBUTTON)) + if (wiInput::down(wiInput::MOUSE_BUTTON_MIDDLE)) { camControlStart = false; xDif = currentMouse.x - originalMouse.x; yDif = currentMouse.y - originalMouse.y; xDif = 0.1f*xDif*(1.0f / 60.0f); yDif = 0.1f*yDif*(1.0f / 60.0f); - wiInputManager::setpointer(originalMouse); - wiInputManager::hidepointer(true); + wiInput::setpointer(originalMouse); + wiInput::hidepointer(true); } else { camControlStart = true; - wiInputManager::hidepointer(false); + wiInput::hidepointer(false); } const float buttonrotSpeed = 2.0f / 60.0f; - if (wiInputManager::down(VK_LEFT)) + if (wiInput::down(wiInput::KEYBOARD_BUTTON_LEFT)) { xDif -= buttonrotSpeed; } - if (wiInputManager::down(VK_RIGHT)) + if (wiInput::down(wiInput::KEYBOARD_BUTTON_RIGHT)) { xDif += buttonrotSpeed; } - if (wiInputManager::down(VK_UP)) + if (wiInput::down(wiInput::KEYBOARD_BUTTON_UP)) { yDif -= buttonrotSpeed; } - if (wiInputManager::down(VK_DOWN)) + if (wiInput::down(wiInput::KEYBOARD_BUTTON_DOWN)) { yDif += buttonrotSpeed; } - const XMFLOAT4 leftStick = wiInputManager::getanalog(GAMEPAD_ANALOG_THUMBSTICK_L, 0); - const XMFLOAT4 rightStick = wiInputManager::getanalog(GAMEPAD_ANALOG_THUMBSTICK_R, 0); - const XMFLOAT4 rightTrigger = wiInputManager::getanalog(GAMEPAD_ANALOG_TRIGGER_R, 0); + const XMFLOAT4 leftStick = wiInput::getanalog(wiInput::GAMEPAD_ANALOG_THUMBSTICK_L, 0); + const XMFLOAT4 rightStick = wiInput::getanalog(wiInput::GAMEPAD_ANALOG_THUMBSTICK_R, 0); + const XMFLOAT4 rightTrigger = wiInput::getanalog(wiInput::GAMEPAD_ANALOG_TRIGGER_R, 0); const float jostickrotspeed = 0.05f; xDif += rightStick.x * jostickrotspeed; @@ -830,19 +830,19 @@ void EditorComponent::Update(float dt) // FPS Camera const float clampedDT = min(dt, 0.1f); // if dt > 100 millisec, don't allow the camera to jump too far... - const float speed = ((wiInputManager::down(VK_SHIFT) ? 10.0f : 1.0f) + rightTrigger.x * 10.0f) * cameraWnd->movespeedSlider->GetValue() * clampedDT; + const float speed = ((wiInput::down(wiInput::KEYBOARD_BUTTON_LSHIFT) ? 10.0f : 1.0f) + rightTrigger.x * 10.0f) * cameraWnd->movespeedSlider->GetValue() * clampedDT; static XMVECTOR move = XMVectorSet(0, 0, 0, 0); XMVECTOR moveNew = XMVectorSet(leftStick.x, 0, leftStick.y, 0); - if (!wiInputManager::down(VK_CONTROL)) + if (!wiInput::down(wiInput::KEYBOARD_BUTTON_LCONTROL)) { // Only move camera if control not pressed - if (wiInputManager::down('A') || wiInputManager::down(GAMEPAD_BUTTON_LEFT, INPUT_TYPE_GAMEPAD)) { moveNew += XMVectorSet(-1, 0, 0, 0); } - if (wiInputManager::down('D') || wiInputManager::down(GAMEPAD_BUTTON_RIGHT, INPUT_TYPE_GAMEPAD)) { moveNew += XMVectorSet(1, 0, 0, 0); } - if (wiInputManager::down('W') || wiInputManager::down(GAMEPAD_BUTTON_UP, INPUT_TYPE_GAMEPAD)) { moveNew += XMVectorSet(0, 0, 1, 0); } - if (wiInputManager::down('S') || wiInputManager::down(GAMEPAD_BUTTON_DOWN, INPUT_TYPE_GAMEPAD)) { moveNew += XMVectorSet(0, 0, -1, 0); } - if (wiInputManager::down('E') || wiInputManager::down(GAMEPAD_BUTTON_2, INPUT_TYPE_GAMEPAD)) { moveNew += XMVectorSet(0, 1, 0, 0); } - if (wiInputManager::down('Q') || wiInputManager::down(GAMEPAD_BUTTON_1, INPUT_TYPE_GAMEPAD)) { moveNew += XMVectorSet(0, -1, 0, 0); } + if (wiInput::down((wiInput::BUTTON)'A') || wiInput::down(wiInput::GAMEPAD_BUTTON_LEFT)) { moveNew += XMVectorSet(-1, 0, 0, 0); } + if (wiInput::down((wiInput::BUTTON)'D') || wiInput::down(wiInput::GAMEPAD_BUTTON_RIGHT)) { moveNew += XMVectorSet(1, 0, 0, 0); } + if (wiInput::down((wiInput::BUTTON)'W') || wiInput::down(wiInput::GAMEPAD_BUTTON_UP)) { moveNew += XMVectorSet(0, 0, 1, 0); } + if (wiInput::down((wiInput::BUTTON)'S') || wiInput::down(wiInput::GAMEPAD_BUTTON_DOWN)) { moveNew += XMVectorSet(0, 0, -1, 0); } + if (wiInput::down((wiInput::BUTTON)'E') || wiInput::down(wiInput::GAMEPAD_BUTTON_2)) { moveNew += XMVectorSet(0, 1, 0, 0); } + if (wiInput::down((wiInput::BUTTON)'Q') || wiInput::down(wiInput::GAMEPAD_BUTTON_1)) { moveNew += XMVectorSet(0, -1, 0, 0); } moveNew += XMVector3Normalize(moveNew); } moveNew *= speed; @@ -872,14 +872,14 @@ void EditorComponent::Update(float dt) { // Orbital Camera - if (wiInputManager::down(VK_LSHIFT)) + if (wiInput::down(wiInput::KEYBOARD_BUTTON_LSHIFT)) { XMVECTOR V = XMVectorAdd(camera.GetRight() * xDif, camera.GetUp() * yDif) * 10; XMFLOAT3 vec; XMStoreFloat3(&vec, V); cameraWnd->camera_target.Translate(vec); } - else if (wiInputManager::down(VK_LCONTROL) || currentMouse.z != 0.0f) + else if (wiInput::down(wiInput::KEYBOARD_BUTTON_LCONTROL) || currentMouse.z != 0.0f) { cameraWnd->camera_transform.Translate(XMFLOAT3(0, 0, yDif * 4 + currentMouse.z)); cameraWnd->camera_transform.translation_local.z = std::min(0.0f, cameraWnd->camera_transform.translation_local.z); @@ -1076,7 +1076,7 @@ void EditorComponent::Update(float dt) { if (object->GetRenderTypes() & RENDERTYPE_WATER) { - if (wiInputManager::down(VK_LBUTTON)) + if (wiInput::down(wiInput::MOUSE_BUTTON_LEFT)) { // if water, then put a water ripple onto it: wiRenderer::PutWaterRipple(wiHelper::GetOriginalWorkingDirectory() + "images/ripple.png", hovered.position); @@ -1084,10 +1084,10 @@ void EditorComponent::Update(float dt) } else { - if (wiInputManager::press(VK_LBUTTON)) + if (wiInput::press(wiInput::MOUSE_BUTTON_LEFT)) { SoftBodyPhysicsComponent* softBody = scene.softbodies.GetComponent(object->meshID); - if (softBody != nullptr && wiInputManager::down('P')) + if (softBody != nullptr && wiInput::down((wiInput::BUTTON)'P')) { MeshComponent* mesh = scene.meshes.GetComponent(object->meshID); @@ -1122,7 +1122,7 @@ void EditorComponent::Update(float dt) } // Visualize soft body pinning: - if (wiInputManager::down('P')) + if (wiInput::down((wiInput::BUTTON)'P')) { for (size_t i = 0; i < scene.softbodies.GetCount(); ++i) { @@ -1155,7 +1155,7 @@ void EditorComponent::Update(float dt) // Select... static bool selectAll = false; - if (wiInputManager::press(VK_RBUTTON) || selectAll) + if (wiInput::press(wiInput::MOUSE_BUTTON_RIGHT) || selectAll) { wiArchive* archive = AdvanceHistory(); @@ -1193,7 +1193,7 @@ void EditorComponent::Update(float dt) { // Add the hovered item to the selection: - if (!selected.empty() && wiInputManager::down(VK_LSHIFT)) + if (!selected.empty() && wiInput::down(wiInput::KEYBOARD_BUTTON_LSHIFT)) { // Union selection: list saved = selected; @@ -1327,7 +1327,7 @@ void EditorComponent::Update(float dt) } // Delete - if (wiInputManager::press(VK_DELETE)) + if (wiInput::press(wiInput::KEYBOARD_BUTTON_DELETE)) { wiArchive* archive = AdvanceHistory(); @@ -1352,15 +1352,15 @@ void EditorComponent::Update(float dt) } // Control operations... - if (wiInputManager::down(VK_CONTROL)) + if (wiInput::down(wiInput::KEYBOARD_BUTTON_LCONTROL)) { // Select All - if (wiInputManager::press('A')) + if (wiInput::press((wiInput::BUTTON)'A')) { selectAll = true; } // Copy - if (wiInputManager::press('C')) + if (wiInput::press((wiInput::BUTTON)'C')) { auto prevSel = selected; EndTranslate(); @@ -1377,7 +1377,7 @@ void EditorComponent::Update(float dt) BeginTranslate(); } // Paste - if (wiInputManager::press('V')) + if (wiInput::press((wiInput::BUTTON)'V')) { auto prevSel = selected; EndTranslate(); @@ -1395,7 +1395,7 @@ void EditorComponent::Update(float dt) BeginTranslate(); } // Duplicate Instances - if (wiInputManager::press('D')) + if (wiInput::press((wiInput::BUTTON)'D')) { auto prevSel = selected; EndTranslate(); @@ -1408,7 +1408,7 @@ void EditorComponent::Update(float dt) BeginTranslate(); } // Put Instances - if (clipboard != nullptr && hovered.subsetIndex >= 0 && wiInputManager::down(VK_LSHIFT) && wiInputManager::press(VK_LBUTTON)) + if (clipboard != nullptr && hovered.subsetIndex >= 0 && wiInput::down(wiInput::KEYBOARD_BUTTON_LSHIFT) && wiInput::press(wiInput::MOUSE_BUTTON_LEFT)) { XMMATRIX M = XMLoadFloat4x4(&hovered.orientation); @@ -1427,12 +1427,12 @@ void EditorComponent::Update(float dt) } } // Undo - if (wiInputManager::press('Z')) + if (wiInput::press((wiInput::BUTTON)'Z')) { ConsumeHistoryOperation(true); } // Redo - if (wiInputManager::press('Y')) + if (wiInput::press((wiInput::BUTTON)'Y')) { ConsumeHistoryOperation(false); } diff --git a/Editor/Translator.cpp b/Editor/Translator.cpp index 6c00d5b5b..5e1a2c014 100644 --- a/Editor/Translator.cpp +++ b/Editor/Translator.cpp @@ -1,7 +1,7 @@ #include "stdafx.h" #include "Translator.h" #include "wiRenderer.h" -#include "wiInputManager.h" +#include "wiInput.h" #include "wiMath.h" #include "ShaderInterop_Renderer.h" @@ -203,7 +203,7 @@ void Translator::Update() dragStarted = false; dragEnded = false; - XMFLOAT4 pointer = wiInputManager::getpointer(); + XMFLOAT4 pointer = wiInput::getpointer(); const CameraComponent& cam = wiRenderer::GetCamera(); XMVECTOR pos = transform.GetPositionV(); @@ -285,7 +285,7 @@ void Translator::Update() } } - if (dragging || (state != TRANSLATOR_IDLE && wiInputManager::down(VK_LBUTTON))) + if (dragging || (state != TRANSLATOR_IDLE && wiInput::down(wiInput::MOUSE_BUTTON_LEFT))) { XMVECTOR plane, planeNormal; if (state == TRANSLATOR_X) @@ -403,7 +403,7 @@ void Translator::Update() dragging = true; } - if (!wiInputManager::down(VK_LBUTTON)) + if (!wiInput::down(wiInput::MOUSE_BUTTON_LEFT)) { if (dragging) { diff --git a/Editor/main.cpp b/Editor/main.cpp index e6756db58..cb84a7a95 100644 --- a/Editor/main.cpp +++ b/Editor/main.cpp @@ -214,9 +214,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) break; case WM_MOUSEWHEEL: { - XMFLOAT4 pointer = wiInputManager::getpointer(); + XMFLOAT4 pointer = wiInput::getpointer(); float delta = GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA; - wiInputManager::setpointer(XMFLOAT4(pointer.x, pointer.y, delta, 0)); + wiInput::setpointer(XMFLOAT4(pointer.x, pointer.y, delta, 0)); } break; case WM_KEYDOWN: diff --git a/README.md b/README.md index 6931790d1..272c2303f 100644 --- a/README.md +++ b/README.md @@ -124,8 +124,8 @@ wiAudio::Play(&mySoundInstance); // Play the sound instance wiAudio::SetVolume(0.6, &mySoundInstance); // Set the volume of this soundinstance wiAudio::SetVolume(0.2); // Set the master volume -if (wiInputManager::press(VK_SPACE)) { wiAudio::Stop(&mySoundInstance); } // You can check if a button is pressed or not (this only triggers once) -if (wiInputManager::down(VK_SPACE)) { wiAudio::Play(&mySoundInstance); } // You can check if a button is pushed down or not (this triggers repeatedly) +if (wiInput::press(wiInput::KEYBOARD_BUTTON_SPACE)) { wiAudio::Stop(&mySoundInstance); } // You can check if a button is pressed or not (this only triggers once) +if (wiInput::down(wiInput::KEYBOARD_BUTTON_SPACE)) { wiAudio::Play(&mySoundInstance); } // You can check if a button is pushed down or not (this triggers repeatedly) ``` Some scripting examples (LUA): @@ -169,7 +169,7 @@ audio.SetVolume(0.6, soundinstance) -- sets the volume of this soundinstance audio.SetVolume(0.2) -- sets the master volume -- Check for input: -if(input.press(VK_LEFT)) then +if(input.press(KEYBOARD_BUTTON_LEFT)) then audio.Play(soundinstance); -- this will play the sound if you press the left arrow on the keyboard end ``` diff --git a/WickedEngine/MainComponent.cpp b/WickedEngine/MainComponent.cpp index 7bb1e24ab..f09ac0a40 100644 --- a/WickedEngine/MainComponent.cpp +++ b/WickedEngine/MainComponent.cpp @@ -3,7 +3,7 @@ #include "wiRenderer.h" #include "wiHelper.h" #include "wiTimer.h" -#include "wiInputManager.h" +#include "wiInput.h" #include "wiBackLog.h" #include "MainComponent_BindLua.h" #include "wiVersion.h" @@ -169,7 +169,7 @@ void MainComponent::Run() // Variable-timed update: Update(dt); - wiInputManager::Update(); + wiInput::Update(); Render(); } diff --git a/WickedEngine/WickedEngine.h b/WickedEngine/WickedEngine.h index 5e2bb43dc..4196638c7 100644 --- a/WickedEngine/WickedEngine.h +++ b/WickedEngine/WickedEngine.h @@ -31,15 +31,12 @@ #include "wiEmittedParticle.h" #include "wiHairParticle.h" #include "wiRenderer.h" -#include "wiDirectInput.h" -#include "wiXInput.h" -#include "wiRawInput.h" #include "wiMath.h" #include "wiAudio.h" #include "wiResourceManager.h" #include "wiTimer.h" #include "wiHelper.h" -#include "wiInputManager.h" +#include "wiInput.h" #include "wiTextureHelper.h" #include "wiRandom.h" #include "wiColor.h" diff --git a/WickedEngine/WickedEngine_SHARED.vcxitems b/WickedEngine/WickedEngine_SHARED.vcxitems index 666e3aced..e0a6359ee 100644 --- a/WickedEngine/WickedEngine_SHARED.vcxitems +++ b/WickedEngine/WickedEngine_SHARED.vcxitems @@ -272,6 +272,8 @@ + + @@ -336,8 +338,6 @@ - - @@ -665,8 +665,8 @@ - - + + diff --git a/WickedEngine/WickedEngine_SHARED.vcxitems.filters b/WickedEngine/WickedEngine_SHARED.vcxitems.filters index 33b60a406..e9c731abc 100644 --- a/WickedEngine/WickedEngine_SHARED.vcxitems.filters +++ b/WickedEngine/WickedEngine_SHARED.vcxitems.filters @@ -189,9 +189,6 @@ ENGINE\Scripting\LuaBindings - - ENGINE\Scripting\LuaBindings - ENGINE\Scripting\LuaBindings @@ -912,9 +909,6 @@ ENGINE\Input - - ENGINE\Input - ENGINE\Input @@ -1134,6 +1128,12 @@ UTILITY + + ENGINE\Input + + + ENGINE\Scripting\LuaBindings + @@ -1268,9 +1268,6 @@ ENGINE\Scripting\LuaBindings - - ENGINE\Scripting\LuaBindings - ENGINE\Scripting\LuaBindings @@ -1757,9 +1754,6 @@ ENGINE\Input - - ENGINE\Input - ENGINE\Input @@ -1904,6 +1898,12 @@ UTILITY + + ENGINE\Input + + + ENGINE\Scripting\LuaBindings + diff --git a/WickedEngine/wiDirectInput.cpp b/WickedEngine/wiDirectInput.cpp index 013cce112..1b0546d8d 100644 --- a/WickedEngine/wiDirectInput.cpp +++ b/WickedEngine/wiDirectInput.cpp @@ -1,414 +1,421 @@ #include "wiDirectInput.h" #include "CommonInclude.h" -short wiDirectInput::connectedJoys = 0; +namespace wiInput +{ + + short wiDirectInput::connectedJoys = 0; #ifndef WINSTORE_SUPPORT +#pragma comment(lib,"dinput8.lib") + #include #include #include -//#include + //#include -//----------------------------------------------------------------------------- -// Enum each PNP device using WMI and check each device ID to see if it contains -// "IG_" (ex. "VID_045E&PID_028E&IG_00"). If it does, then it's an XInput device -// Unfortunately this information can not be found by just using DirectInput -//----------------------------------------------------------------------------- -BOOL IsXInputDevice(const GUID* pGuidProductFromDirectInput) -{ - IWbemLocator* pIWbemLocator = NULL; - IEnumWbemClassObject* pEnumDevices = NULL; - IWbemClassObject* pDevices[20] = { 0 }; - IWbemServices* pIWbemServices = NULL; - BSTR bstrNamespace = NULL; - BSTR bstrDeviceID = NULL; - BSTR bstrClassName = NULL; - DWORD uReturned = 0; - bool bIsXinputDevice = false; - uint32_t iDevice = 0; - VARIANT var; - HRESULT hr; - - // CoInit if needed - hr = CoInitialize(NULL); - bool bCleanupCOM = SUCCEEDED(hr); - - // Create WMI - hr = CoCreateInstance(__uuidof(WbemLocator), - NULL, - CLSCTX_INPROC_SERVER, - __uuidof(IWbemLocator), - (LPVOID*)&pIWbemLocator); - if (FAILED(hr) || pIWbemLocator == NULL) - goto LCleanup; - - bstrNamespace = SysAllocString(L"\\\\.\\root\\cimv2"); if (bstrNamespace == NULL) goto LCleanup; - bstrClassName = SysAllocString(L"Win32_PNPEntity"); if (bstrClassName == NULL) goto LCleanup; - bstrDeviceID = SysAllocString(L"DeviceID"); if (bstrDeviceID == NULL) goto LCleanup; - - // Connect to WMI - hr = pIWbemLocator->ConnectServer(bstrNamespace, NULL, NULL, 0L, - 0L, NULL, NULL, &pIWbemServices); - if (FAILED(hr) || pIWbemServices == NULL) - goto LCleanup; - - // Switch security level to IMPERSONATE. - CoSetProxyBlanket(pIWbemServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL, - RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE); - - hr = pIWbemServices->CreateInstanceEnum(bstrClassName, 0, NULL, &pEnumDevices); - if (FAILED(hr) || pEnumDevices == NULL) - goto LCleanup; - - // Loop over all devices - for (;;) + //----------------------------------------------------------------------------- + // Enum each PNP device using WMI and check each device ID to see if it contains + // "IG_" (ex. "VID_045E&PID_028E&IG_00"). If it does, then it's an XInput device + // Unfortunately this information can not be found by just using DirectInput + //----------------------------------------------------------------------------- + BOOL IsXInputDevice(const GUID* pGuidProductFromDirectInput) { - // Get 20 at a time - hr = pEnumDevices->Next(10000, 20, pDevices, &uReturned); - if (FAILED(hr)) + IWbemLocator* pIWbemLocator = NULL; + IEnumWbemClassObject* pEnumDevices = NULL; + IWbemClassObject* pDevices[20] = { 0 }; + IWbemServices* pIWbemServices = NULL; + BSTR bstrNamespace = NULL; + BSTR bstrDeviceID = NULL; + BSTR bstrClassName = NULL; + DWORD uReturned = 0; + bool bIsXinputDevice = false; + uint32_t iDevice = 0; + VARIANT var; + HRESULT hr; + + // CoInit if needed + hr = CoInitialize(NULL); + bool bCleanupCOM = SUCCEEDED(hr); + + // Create WMI + hr = CoCreateInstance(__uuidof(WbemLocator), + NULL, + CLSCTX_INPROC_SERVER, + __uuidof(IWbemLocator), + (LPVOID*)&pIWbemLocator); + if (FAILED(hr) || pIWbemLocator == NULL) goto LCleanup; - if (uReturned == 0) - break; - for (iDevice = 0; iDeviceConnectServer(bstrNamespace, NULL, NULL, 0L, + 0L, NULL, NULL, &pIWbemServices); + if (FAILED(hr) || pIWbemServices == NULL) + goto LCleanup; + + // Switch security level to IMPERSONATE. + CoSetProxyBlanket(pIWbemServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL, + RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE); + + hr = pIWbemServices->CreateInstanceEnum(bstrClassName, 0, NULL, &pEnumDevices); + if (FAILED(hr) || pEnumDevices == NULL) + goto LCleanup; + + // Loop over all devices + for (;;) { - // For each device, get its device ID - hr = pDevices[iDevice]->Get(bstrDeviceID, 0L, &var, NULL, NULL); - if (SUCCEEDED(hr) && var.vt == VT_BSTR && var.bstrVal != NULL) - { - // Check if the device ID contains "IG_". If it does, then it's an XInput device - // This information can not be found from DirectInput - if (wcsstr(var.bstrVal, L"IG_")) - { - // If it does, then get the VID/PID from var.bstrVal - DWORD dwPid = 0, dwVid = 0; - WCHAR* strVid = wcsstr(var.bstrVal, L"VID_"); - if (strVid && swscanf_s(strVid, L"VID_%4X", &dwVid) != 1) - dwVid = 0; - WCHAR* strPid = wcsstr(var.bstrVal, L"PID_"); - if (strPid && swscanf_s(strPid, L"PID_%4X", &dwPid) != 1) - dwPid = 0; + // Get 20 at a time + hr = pEnumDevices->Next(10000, 20, pDevices, &uReturned); + if (FAILED(hr)) + goto LCleanup; + if (uReturned == 0) + break; - // Compare the VID/PID to the DInput device - DWORD dwVidPid = MAKELONG(dwVid, dwPid); - if (dwVidPid == pGuidProductFromDirectInput->Data1) + for (iDevice = 0; iDevice < uReturned; iDevice++) + { + // For each device, get its device ID + hr = pDevices[iDevice]->Get(bstrDeviceID, 0L, &var, NULL, NULL); + if (SUCCEEDED(hr) && var.vt == VT_BSTR && var.bstrVal != NULL) + { + // Check if the device ID contains "IG_". If it does, then it's an XInput device + // This information can not be found from DirectInput + if (wcsstr(var.bstrVal, L"IG_")) { - bIsXinputDevice = true; - goto LCleanup; + // If it does, then get the VID/PID from var.bstrVal + DWORD dwPid = 0, dwVid = 0; + WCHAR* strVid = wcsstr(var.bstrVal, L"VID_"); + if (strVid && swscanf_s(strVid, L"VID_%4X", &dwVid) != 1) + dwVid = 0; + WCHAR* strPid = wcsstr(var.bstrVal, L"PID_"); + if (strPid && swscanf_s(strPid, L"PID_%4X", &dwPid) != 1) + dwPid = 0; + + // Compare the VID/PID to the DInput device + DWORD dwVidPid = MAKELONG(dwVid, dwPid); + if (dwVidPid == pGuidProductFromDirectInput->Data1) + { + bIsXinputDevice = true; + goto LCleanup; + } } } + SAFE_RELEASE(pDevices[iDevice]); } + } + + LCleanup: + if (bstrNamespace) + SysFreeString(bstrNamespace); + if (bstrDeviceID) + SysFreeString(bstrDeviceID); + if (bstrClassName) + SysFreeString(bstrClassName); + for (iDevice = 0; iDevice < 20; iDevice++) SAFE_RELEASE(pDevices[iDevice]); + SAFE_RELEASE(pEnumDevices); + SAFE_RELEASE(pIWbemLocator); + SAFE_RELEASE(pIWbemServices); + + if (bCleanupCOM) + CoUninitialize(); + + return bIsXinputDevice; + } + + wiDirectInput::wiDirectInput(HINSTANCE hinstance, HWND hwnd) + { + for (int i = 0; i < 256; ++i) { + m_keyboardState[i] = 0; } + Initialize(hinstance, hwnd); + } + wiDirectInput::~wiDirectInput() + { + Shutdown(); } -LCleanup: - if (bstrNamespace) - SysFreeString(bstrNamespace); - if (bstrDeviceID) - SysFreeString(bstrDeviceID); - if (bstrClassName) - SysFreeString(bstrClassName); - for (iDevice = 0; iDevice<20; iDevice++) - SAFE_RELEASE(pDevices[iDevice]); - SAFE_RELEASE(pEnumDevices); - SAFE_RELEASE(pIWbemLocator); - SAFE_RELEASE(pIWbemServices); + IDirectInputDevice8* m_keyboard = 0; + IDirectInputDevice8* joystick[2] = { 0,0 }; + IDirectInput8* m_directInput = 0; - if (bCleanupCOM) - CoUninitialize(); + BOOL CALLBACK enumCallback(const DIDEVICEINSTANCE* instance, VOID* context) + { + HRESULT hr; - return bIsXinputDevice; -} + //SLOW!!! + if (IsXInputDevice(&instance->guidProduct)) + return DIENUM_CONTINUE; -wiDirectInput::wiDirectInput(HINSTANCE hinstance, HWND hwnd) -{ - for(int i=0;i<256;++i){ - m_keyboardState[i]=0; - } - Initialize(hinstance, hwnd); -} -wiDirectInput::~wiDirectInput() -{ - Shutdown(); -} + // Obtain an interface to the enumerated joystick. + hr = m_directInput->CreateDevice(instance->guidInstance, &joystick[wiDirectInput::connectedJoys], NULL); -IDirectInputDevice8* m_keyboard = 0; -IDirectInputDevice8* joystick[2] = {0,0}; -IDirectInput8* m_directInput = 0; + // If it failed, then we can't use this joystick. (Maybe the user unplugged + // it while we were in the middle of enumerating it.) + if (FAILED(hr)) { + return DIENUM_CONTINUE; + } -BOOL CALLBACK enumCallback(const DIDEVICEINSTANCE* instance, VOID* context) -{ - HRESULT hr; - - //SLOW!!! - if (IsXInputDevice(&instance->guidProduct)) - return DIENUM_CONTINUE; - - // Obtain an interface to the enumerated joystick. - hr = m_directInput->CreateDevice(instance->guidInstance, &joystick[wiDirectInput::connectedJoys], NULL); - - // If it failed, then we can't use this joystick. (Maybe the user unplugged - // it while we were in the middle of enumerating it.) - if (FAILED(hr)) { - return DIENUM_CONTINUE; - } - - // Stop enumeration. Note: we're just taking the first joystick we get. You - // could store all the enumerated joysticks and let the user pick. - wiDirectInput::connectedJoys++; - if (wiDirectInput::connectedJoys<2) - return DIENUM_CONTINUE; - else - return DIENUM_STOP; -} -BOOL CALLBACK enumAxesCallback(const DIDEVICEOBJECTINSTANCE* instance, VOID* context) -{ - HWND hDlg = (HWND)context; - - DIPROPRANGE propRange; - propRange.diph.dwSize = sizeof(DIPROPRANGE); - propRange.diph.dwHeaderSize = sizeof(DIPROPHEADER); - propRange.diph.dwHow = DIPH_BYID; - propRange.diph.dwObj = instance->dwType; - propRange.lMin = -1000; - propRange.lMax = +1000; - - // Set the range for the axis - for (short i = 0; iSetProperty(DIPROP_RANGE, &propRange.diph))) { + // Stop enumeration. Note: we're just taking the first joystick we get. You + // could store all the enumerated joysticks and let the user pick. + wiDirectInput::connectedJoys++; + if (wiDirectInput::connectedJoys < 2) + return DIENUM_CONTINUE; + else return DIENUM_STOP; - } - - return DIENUM_CONTINUE; -} - - -HRESULT wiDirectInput::Initialize(HINSTANCE hinstance, HWND hwnd) -{ - HRESULT result; - - - // Initialize the main direct input interface. - result = DirectInput8Create(hinstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&m_directInput, NULL); - if(FAILED(result)) + } + BOOL CALLBACK enumAxesCallback(const DIDEVICEOBJECTINSTANCE* instance, VOID* context) { - return E_FAIL; - } + HWND hDlg = (HWND)context; - //// Initialize the direct input interface for the keyboard. - //result = m_directInput->CreateDevice(GUID_SysKeyboard, &m_keyboard, NULL); - //if(FAILED(result)) - //{ - // return E_FAIL; - //} + DIPROPRANGE propRange; + propRange.diph.dwSize = sizeof(DIPROPRANGE); + propRange.diph.dwHeaderSize = sizeof(DIPROPHEADER); + propRange.diph.dwHow = DIPH_BYID; + propRange.diph.dwObj = instance->dwType; + propRange.lMin = -1000; + propRange.lMax = +1000; - //// Set the data format. In this case since it is a keyboard we can use the predefined data format. - //result = m_keyboard->SetDataFormat(&c_dfDIKeyboard); - //if(FAILED(result)) - //{ - // return E_FAIL; - //} - - //// Set the cooperative level of the keyboard to not share with other programs. - //result = m_keyboard->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE); - //if(FAILED(result)) - //{ - // return E_FAIL; - //} - - //// Now acquire the keyboard. - //result = m_keyboard->Acquire(); - //if(FAILED(result)) - //{ - // return E_FAIL; - //} - //m_keyboard->GetDeviceState(sizeof(m_keyboardState), (LPVOID)&m_keyboardState); - - InitJoy(hwnd); - - return S_OK; -} -HRESULT wiDirectInput::InitJoy(HWND hwnd){ - HRESULT result; - // Look for the first simple joystick we can find. - if (FAILED(result = m_directInput->EnumDevices(DI8DEVCLASS_GAMECTRL, ::enumCallback, NULL, DIEDFL_ATTACHEDONLY))) { - return result; - } - for(short i=0;iSetDataFormat(&c_dfDIJoystick2))) { - return result; - } - - // Set the cooperative level to let DInput know how this device should - // interact with the system and with other DInput applications. - if (FAILED(result = joystick[i]->SetCooperativeLevel(hwnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND))) { - return result; - } - - // Determine how many axis the joystick has (so we don't error out setting - // properties for unavailable axis) - capabilities.dwSize = sizeof(DIDEVCAPS); - if (FAILED(result = joystick[i]->GetCapabilities(&capabilities))) { - return result; - } - - // Enumerate the axes of the joyctick and set the range of each axis. Note: - // we could just use the defaults, but we're just trying to show an example - // of enumerating device objects (axes, buttons, etc.). - if (FAILED(result = joystick[i]->EnumObjects(::enumAxesCallback, NULL, DIDFT_AXIS))) - return result; - } - - - - return S_OK; -} - -void wiDirectInput::Shutdown() -{ - // Release the keyboard. - if(m_keyboard) - { - m_keyboard->Unacquire(); - m_keyboard->Release(); - m_keyboard = 0; - } - // Release Joypad - if(joystick){ - for(short i=0;iUnacquire(); - joystick[i]->Release(); - joystick[i] = 0; + // Set the range for the axis + for (short i = 0; i < wiDirectInput::connectedJoys; i++) + if (FAILED(joystick[i]->SetProperty(DIPROP_RANGE, &propRange.diph))) { + return DIENUM_STOP; } - } - // Release the main interface to direct input. - if(m_directInput) - { - m_directInput->Release(); - m_directInput = 0; + + return DIENUM_CONTINUE; } - return; -} - -bool wiDirectInput::Frame() -{ - //if(m_keyboard==nullptr) - // return false; - //// Read the keyboard device. - //HRESULT result = m_keyboard->GetDeviceState(sizeof(m_keyboardState), (LPVOID)&m_keyboardState); - //if(FAILED(result)) - //{ - // // If the keyboard lost focus or was not acquired then try to get control back. - // if((result == DIERR_INPUTLOST) || (result == DIERR_NOTACQUIRED)) - // { - // m_keyboard->Acquire(); - // } - // else - // { - // return false; - // } - //} - for(short i=0;iCreateDevice(GUID_SysKeyboard, &m_keyboard, NULL); + //if(FAILED(result)) + //{ + // return E_FAIL; + //} + + //// Set the data format. In this case since it is a keyboard we can use the predefined data format. + //result = m_keyboard->SetDataFormat(&c_dfDIKeyboard); + //if(FAILED(result)) + //{ + // return E_FAIL; + //} + + //// Set the cooperative level of the keyboard to not share with other programs. + //result = m_keyboard->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE); + //if(FAILED(result)) + //{ + // return E_FAIL; + //} + + //// Now acquire the keyboard. + //result = m_keyboard->Acquire(); + //if(FAILED(result)) + //{ + // return E_FAIL; + //} + //m_keyboard->GetDeviceState(sizeof(m_keyboardState), (LPVOID)&m_keyboardState); + + InitJoy(hwnd); + + return S_OK; + } + HRESULT wiDirectInput::InitJoy(HWND hwnd) { + HRESULT result; + // Look for the first simple joystick we can find. + if (FAILED(result = m_directInput->EnumDevices(DI8DEVCLASS_GAMECTRL, enumCallback, NULL, DIEDFL_ATTACHEDONLY))) { + return result; + } + for (short i = 0; i < connectedJoys; i++) { + + DIDEVCAPS capabilities; + + // Set the data format to "simple joystick" - a predefined data format + // + // A data format specifies which controls on a device we are interested in, + // and how they should be reported. This tells DInput that we will be + // passing a DIJOYSTATE2 structure to IDirectInputDevice::GetDeviceState(). + if (FAILED(result = joystick[i]->SetDataFormat(&c_dfDIJoystick2))) { + return result; + } + + // Set the cooperative level to let DInput know how this device should + // interact with the system and with other DInput applications. + if (FAILED(result = joystick[i]->SetCooperativeLevel(hwnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND))) { + return result; + } + + // Determine how many axis the joystick has (so we don't error out setting + // properties for unavailable axis) + capabilities.dwSize = sizeof(DIDEVCAPS); + if (FAILED(result = joystick[i]->GetCapabilities(&capabilities))) { + return result; + } + + // Enumerate the axes of the joyctick and set the range of each axis. Note: + // we could just use the defaults, but we're just trying to show an example + // of enumerating device objects (axes, buttons, etc.). + if (FAILED(result = joystick[i]->EnumObjects(enumAxesCallback, NULL, DIDFT_AXIS))) + return result; + } + + + + return S_OK; + } + + void wiDirectInput::Shutdown() + { + // Release the keyboard. + if (m_keyboard) + { + m_keyboard->Unacquire(); + m_keyboard->Release(); + m_keyboard = 0; + } + // Release Joypad + if (joystick) { + for (short i = 0; i < connectedJoys; i++) + if (joystick[i]) { + joystick[i]->Unacquire(); + joystick[i]->Release(); + joystick[i] = 0; + } + } + // Release the main interface to direct input. + if (m_directInput) + { + m_directInput->Release(); + m_directInput = 0; + } + + + return; + } + + bool wiDirectInput::Frame() + { + //if(m_keyboard==nullptr) + // return false; + //// Read the keyboard device. + //HRESULT result = m_keyboard->GetDeviceState(sizeof(m_keyboardState), (LPVOID)&m_keyboardState); + //if(FAILED(result)) + //{ + // // If the keyboard lost focus or was not acquired then try to get control back. + // if((result == DIERR_INPUTLOST) || (result == DIERR_NOTACQUIRED)) + // { + // m_keyboard->Acquire(); + // } + // else + // { + // return false; + // } + //} + for (short i = 0; i < connectedJoys; i++) + poll(joystick[i], &joyState[i]); + return true; } - return false; -} -int wiDirectInput::GetPressedKeys() -{ - int ret=0; - for(int i=0;i<256;i++) - if(m_keyboardState[i] & 0x80) + bool wiDirectInput::IsKeyDown(INT code) + { + if (m_keyboardState[code] & 0x80) { - ret+=i; - } - - return ret; -} - - - -HRESULT wiDirectInput::poll(IDirectInputDevice8* joy, DIJOYSTATE2 *js) -{ - HRESULT hr; - - if (joystick == NULL) { - return S_OK; - } - - - // Poll the device to read the current state - hr = joy->Poll(); - if (FAILED(hr)) { - // DInput is telling us that the input stream has been - // interrupted. We aren't tracking any state between polls, so - // we don't have any special reset that needs to be done. We - // just re-acquire and try again. - hr = joy->Acquire(); - while (hr == DIERR_INPUTLOST) { - hr = joy->Acquire(); - } - - // If we encounter a fatal error, return failure. - if ((hr == DIERR_INVALIDPARAM) || (hr == DIERR_NOTINITIALIZED)) { - return E_FAIL; - } - - // If another application has control of this device, return successfully. - // We'll just have to wait our turn to use the joystick. - if (hr == DIERR_OTHERAPPHASPRIO) { - return S_OK; - } - } - - // Get the input's device state - if (FAILED(hr = joy->GetDeviceState(sizeof(DIJOYSTATE2), js))) { - return hr; // The device should have been acquired during the Poll() - } - - return S_OK; -} - -bool wiDirectInput::isButtonDown(short pIndex, unsigned int buttoncode) -{ - if(connectedJoys && buttoncode < 128) - if(joyState[pIndex].rgbButtons[buttoncode-1]!=0) return true; - return false; -} -DWORD wiDirectInput::getDirections(short pIndex) -{ - DWORD buttons=0; - if(connectedJoys) - for(short i=0;i<4;i++){ - //if((LOWORD(joyState[pIndex].rgdwPOV[i]) != 0xFFFF)) - if(buttons+=joyState[pIndex].rgdwPOV[i] != DIRECTINPUT_POV_IDLE) - buttons+=joyState[pIndex].rgdwPOV[i]; } - return buttons; -} + + return false; + } + int wiDirectInput::GetPressedKeys() + { + int ret = 0; + for (int i = 0; i < 256; i++) + if (m_keyboardState[i] & 0x80) + { + ret += i; + } + + return ret; + } + + + + HRESULT wiDirectInput::poll(IDirectInputDevice8* joy, DIJOYSTATE2* js) + { + HRESULT hr; + + if (joystick == NULL) { + return S_OK; + } + + + // Poll the device to read the current state + hr = joy->Poll(); + if (FAILED(hr)) { + // DInput is telling us that the input stream has been + // interrupted. We aren't tracking any state between polls, so + // we don't have any special reset that needs to be done. We + // just re-acquire and try again. + hr = joy->Acquire(); + while (hr == DIERR_INPUTLOST) { + hr = joy->Acquire(); + } + + // If we encounter a fatal error, return failure. + if ((hr == DIERR_INVALIDPARAM) || (hr == DIERR_NOTINITIALIZED)) { + return E_FAIL; + } + + // If another application has control of this device, return successfully. + // We'll just have to wait our turn to use the joystick. + if (hr == DIERR_OTHERAPPHASPRIO) { + return S_OK; + } + } + + // Get the input's device state + if (FAILED(hr = joy->GetDeviceState(sizeof(DIJOYSTATE2), js))) { + return hr; // The device should have been acquired during the Poll() + } + + return S_OK; + } + + bool wiDirectInput::isButtonDown(short pIndex, unsigned int buttoncode) + { + if (connectedJoys && buttoncode < 128) + if (joyState[pIndex].rgbButtons[buttoncode - 1] != 0) + return true; + return false; + } + DWORD wiDirectInput::getDirections(short pIndex) + { + DWORD buttons = 0; + if (connectedJoys) + for (short i = 0; i < 4; i++) { + //if((LOWORD(joyState[pIndex].rgdwPOV[i]) != 0xFFFF)) + if (buttons += joyState[pIndex].rgdwPOV[i] != DIRECTINPUT_POV_IDLE) + buttons += joyState[pIndex].rgdwPOV[i]; + } + return buttons; + } #endif + +} diff --git a/WickedEngine/wiDirectInput.h b/WickedEngine/wiDirectInput.h index 493b94753..c9e4ddb7d 100644 --- a/WickedEngine/wiDirectInput.h +++ b/WickedEngine/wiDirectInput.h @@ -1,7 +1,11 @@ #pragma once +#include "CommonInclude.h" // TODO REFACTOR +namespace wiInput +{ + #define DIRECTINPUT_POV_IDLE 4294967292 #define DIRECTINPUT_POV_UP 1 #define DIRECTINPUT_POV_UPRIGHT 4501 @@ -15,57 +19,57 @@ #ifndef WINSTORE_SUPPORT #define DIRECTINPUT_VERSION 0x0800 #include -#pragma comment(lib,"dinput8.lib") #else #include #endif -class wiDirectInput -{ -public: - static short connectedJoys; + class wiDirectInput + { + public: + static short connectedJoys; #ifndef WINSTORE_SUPPORT - friend BOOL CALLBACK enumCallback(const DIDEVICEINSTANCE* instance, VOID* context); - friend BOOL CALLBACK enumAxesCallback(const DIDEVICEOBJECTINSTANCE* instance, VOID* context); -public: - wiDirectInput(HINSTANCE, HWND); - ~wiDirectInput(); + friend BOOL CALLBACK enumCallback(const DIDEVICEINSTANCE* instance, VOID* context); + friend BOOL CALLBACK enumAxesCallback(const DIDEVICEOBJECTINSTANCE* instance, VOID* context); + public: + wiDirectInput(HINSTANCE, HWND); + ~wiDirectInput(); - void Shutdown(); - bool Frame(); + void Shutdown(); + bool Frame(); - //KEYBOARD - bool IsKeyDown(INT); - int GetPressedKeys(); + //KEYBOARD + bool IsKeyDown(INT); + int GetPressedKeys(); - //JOYSTICK - bool isButtonDown(short pIndex, unsigned int buttoncode); - DWORD getDirections(short pIndex); - - DIJOYSTATE2 joyState[2]; + //JOYSTICK + bool isButtonDown(short pIndex, unsigned int buttoncode); + DWORD getDirections(short pIndex); - - static HRESULT InitJoy(HWND hwnd); + DIJOYSTATE2 joyState[2]; -private: - HRESULT Initialize(HINSTANCE, HWND); - - HRESULT poll(IDirectInputDevice8*joy,DIJOYSTATE2 *js); - unsigned char m_keyboardState[256]; + + static HRESULT InitJoy(HWND hwnd); + + private: + HRESULT Initialize(HINSTANCE, HWND); + + HRESULT poll(IDirectInputDevice8* joy, DIJOYSTATE2* js); + unsigned char m_keyboardState[256]; #else -public: - wiDirectInput(...){} - void Shutdown(){} - bool Frame(){ return false; } - bool IsKeyDown(INT){ return false; } - int GetPressedKeys(){ return 0; } - bool isButtonDown(short pIndex, unsigned int buttoncode){ return false; } - DWORD getDirections(short pIndex){ return 0; } - static HRESULT InitJoy(HWND hwnd){ return E_FAIL; } - int GetNumControllers() { return 0; } + public: + wiDirectInput(...) {} + void Shutdown() {} + bool Frame() { return false; } + bool IsKeyDown(INT) { return false; } + int GetPressedKeys() { return 0; } + bool isButtonDown(short pIndex, unsigned int buttoncode) { return false; } + DWORD getDirections(short pIndex) { return 0; } + static HRESULT InitJoy(HWND hwnd) { return E_FAIL; } + int GetNumControllers() { return 0; } #endif -}; + }; +} diff --git a/WickedEngine/wiGUI.cpp b/WickedEngine/wiGUI.cpp index b5d1b5784..7070af730 100644 --- a/WickedEngine/wiGUI.cpp +++ b/WickedEngine/wiGUI.cpp @@ -2,7 +2,7 @@ #include "wiWidget.h" #include "wiHashString.h" #include "wiRenderer.h" -#include "wiInputManager.h" +#include "wiInput.h" using namespace std; using namespace wiGraphics; @@ -36,7 +36,7 @@ void wiGUI::Update(float dt) UpdateTransform(); } - XMFLOAT4 _p = wiInputManager::getpointer(); + XMFLOAT4 _p = wiInput::getpointer(); pointerpos.x = _p.x; pointerpos.y = _p.y; diff --git a/WickedEngine/wiInitializer.cpp b/WickedEngine/wiInitializer.cpp index 72173aab1..583b20385 100644 --- a/WickedEngine/wiInitializer.cpp +++ b/WickedEngine/wiInitializer.cpp @@ -26,7 +26,7 @@ namespace wiInitializer wiJobSystem::Execute(ctx, [] { wiFont::Initialize(); }); wiJobSystem::Execute(ctx, [] { wiImage::Initialize(); }); - wiJobSystem::Execute(ctx, [] { wiInputManager::Initialize(); }); + wiJobSystem::Execute(ctx, [] { wiInput::Initialize(); }); wiJobSystem::Execute(ctx, [] { wiRenderer::Initialize(); wiWidget::LoadShaders(); }); wiJobSystem::Execute(ctx, [] { wiAudio::Initialize(); }); wiJobSystem::Execute(ctx, [] { wiNetwork::Initialize(); }); diff --git a/WickedEngine/wiInputManager.cpp b/WickedEngine/wiInput.cpp similarity index 80% rename from WickedEngine/wiInputManager.cpp rename to WickedEngine/wiInput.cpp index c23699dac..1df8272e1 100644 --- a/WickedEngine/wiInputManager.cpp +++ b/WickedEngine/wiInput.cpp @@ -1,4 +1,4 @@ -#include "wiInputManager.h" +#include "wiInput.h" #include "wiXInput.h" #include "wiDirectInput.h" #include "wiRawInput.h" @@ -13,7 +13,7 @@ using namespace std; -namespace wiInputManager +namespace wiInput { #ifndef WINSTORE_SUPPORT @@ -29,21 +29,15 @@ namespace wiInputManager struct Input { - INPUT_TYPE type; - uint32_t button; - short playerIndex; + BUTTON button = BUTTON_NONE; + short playerIndex = 0; - Input() { - type = INPUT_TYPE_KEYBOARD; - button = 0; - playerIndex = 0; - } bool operator<(const Input other) { - return (button != other.button || type != other.type || playerIndex != other.playerIndex); + return (button != other.button || playerIndex != other.playerIndex); } struct LessComparer { bool operator()(Input const& a, Input const& b) const { - return (a.button < b.button || a.type < b.type || a.playerIndex < b.playerIndex); + return (a.button < b.button || a.playerIndex < b.playerIndex); } }; }; @@ -84,7 +78,7 @@ namespace wiInputManager controllers.push_back({ Controller::DIRECTINPUT, i }); } - wiBackLog::post("wiInputManager Initialized"); + wiBackLog::post("wiInput Initialized"); initialized.store(true); } @@ -101,13 +95,12 @@ namespace wiInputManager for (auto iter = inputs.begin(); iter != inputs.end();) { - INPUT_TYPE type = iter->first.type; - uint32_t button = iter->first.button; + BUTTON button = iter->first.button; short playerIndex = iter->first.playerIndex; bool todelete = false; - if (down(button, type, playerIndex)) + if (down(button, playerIndex)) { iter->second++; } @@ -132,7 +125,7 @@ namespace wiInputManager } - bool down(uint32_t button, INPUT_TYPE inputType, short playerindex) + bool down(BUTTON button, short playerindex) { if (!initialized.load()) { @@ -143,18 +136,10 @@ namespace wiInputManager return false; } - switch (inputType) + if(button > GAMEPAD_RANGE_START) { - case INPUT_TYPE_KEYBOARD: - if (playerindex == 0) // can't differentiate between keyboards now.. - { - return KEY_DOWN(static_cast(button)) | KEY_TOGGLE(static_cast(button)); - } - break; - case INPUT_TYPE_GAMEPAD: if (playerindex < (int)controllers.size()) { - const Controller& controller = controllers[playerindex]; if (xinput != nullptr && controller.deviceType == Controller::XINPUT) @@ -209,19 +194,111 @@ namespace wiInputManager } } - break; - default:break; } + else if (playerindex == 0) // keyboard or mouse + { + int keycode = (int)button; + + switch (button) + { + case wiInput::MOUSE_BUTTON_LEFT: + keycode = VK_LBUTTON; + break; + case wiInput::MOUSE_BUTTON_RIGHT: + keycode = VK_RBUTTON; + break; + case wiInput::MOUSE_BUTTON_MIDDLE: + keycode = VK_MBUTTON; + break; + case wiInput::KEYBOARD_BUTTON_UP: + keycode = VK_UP; + break; + case wiInput::KEYBOARD_BUTTON_DOWN: + keycode = VK_DOWN; + break; + case wiInput::KEYBOARD_BUTTON_LEFT: + keycode = VK_LEFT; + break; + case wiInput::KEYBOARD_BUTTON_RIGHT: + keycode = VK_RIGHT; + break; + case wiInput::KEYBOARD_BUTTON_SPACE: + keycode = VK_SPACE; + break; + case wiInput::KEYBOARD_BUTTON_RSHIFT: + keycode = VK_RSHIFT; + break; + case wiInput::KEYBOARD_BUTTON_LSHIFT: + keycode = VK_LSHIFT; + break; + case wiInput::KEYBOARD_BUTTON_F1: + keycode = VK_F1; + break; + case wiInput::KEYBOARD_BUTTON_F2: + keycode = VK_F2; + break; + case wiInput::KEYBOARD_BUTTON_F3: + keycode = VK_F3; + break; + case wiInput::KEYBOARD_BUTTON_F4: + keycode = VK_F4; + break; + case wiInput::KEYBOARD_BUTTON_F5: + keycode = VK_F5; + break; + case wiInput::KEYBOARD_BUTTON_F6: + keycode = VK_F6; + break; + case wiInput::KEYBOARD_BUTTON_F7: + keycode = VK_F7; + break; + case wiInput::KEYBOARD_BUTTON_F8: + keycode = VK_F8; + break; + case wiInput::KEYBOARD_BUTTON_F9: + keycode = VK_F9; + break; + case wiInput::KEYBOARD_BUTTON_F10: + keycode = VK_F10; + break; + case wiInput::KEYBOARD_BUTTON_F11: + keycode = VK_F11; + break; + case wiInput::KEYBOARD_BUTTON_F12: + keycode = VK_F12; + break; + case wiInput::KEYBOARD_BUTTON_ENTER: + keycode = VK_RETURN; + break; + case wiInput::KEYBOARD_BUTTON_ESCAPE: + keycode = VK_ESCAPE; + break; + case wiInput::KEYBOARD_BUTTON_HOME: + keycode = VK_HOME; + break; + case wiInput::KEYBOARD_BUTTON_LCONTROL: + keycode = VK_LCONTROL; + break; + case wiInput::KEYBOARD_BUTTON_RCONTROL: + keycode = VK_RCONTROL; + break; + case wiInput::KEYBOARD_BUTTON_DELETE: + keycode = VK_DELETE; + break; + } + + return KEY_DOWN(keycode) | KEY_TOGGLE(keycode); + } + return false; } - bool press(uint32_t button, INPUT_TYPE inputType, short playerindex) + bool press(BUTTON button, short playerindex) { - if (!down(button, inputType, playerindex)) + if (!down(button, playerindex)) return false; - Input input = Input(); + Input input; input.button = button; - input.type = inputType; input.playerIndex = playerindex; auto iter = inputs.find(input); if (iter == inputs.end()) @@ -235,14 +312,13 @@ namespace wiInputManager } return false; } - bool hold(uint32_t button, uint32_t frames, bool continuous, INPUT_TYPE inputType, short playerIndex) + bool hold(BUTTON button, uint32_t frames, bool continuous, short playerIndex) { - if (!down(button, inputType, playerIndex)) + if (!down(button, playerIndex)) return false; - Input input = Input(); + Input input; input.button = button; - input.type = inputType; input.playerIndex = playerIndex; auto iter = inputs.find(input); if (iter == inputs.end()) diff --git a/WickedEngine/wiInput.h b/WickedEngine/wiInput.h new file mode 100644 index 000000000..a80842e6f --- /dev/null +++ b/WickedEngine/wiInput.h @@ -0,0 +1,110 @@ +#pragma once +#include "CommonInclude.h" + +#include + +namespace wiInput +{ + // Do not alter order as it is bound to lua manually! + enum BUTTON + { + BUTTON_NONE = 0, + + MOUSE_BUTTON_LEFT, + MOUSE_BUTTON_RIGHT, + MOUSE_BUTTON_MIDDLE, + + KEYBOARD_BUTTON_UP, + KEYBOARD_BUTTON_DOWN, + KEYBOARD_BUTTON_LEFT, + KEYBOARD_BUTTON_RIGHT, + KEYBOARD_BUTTON_SPACE, + KEYBOARD_BUTTON_RSHIFT, + KEYBOARD_BUTTON_LSHIFT, + KEYBOARD_BUTTON_F1, + KEYBOARD_BUTTON_F2, + KEYBOARD_BUTTON_F3, + KEYBOARD_BUTTON_F4, + KEYBOARD_BUTTON_F5, + KEYBOARD_BUTTON_F6, + KEYBOARD_BUTTON_F7, + KEYBOARD_BUTTON_F8, + KEYBOARD_BUTTON_F9, + KEYBOARD_BUTTON_F10, + KEYBOARD_BUTTON_F11, + KEYBOARD_BUTTON_F12, + KEYBOARD_BUTTON_ENTER, + KEYBOARD_BUTTON_ESCAPE, + KEYBOARD_BUTTON_HOME, + KEYBOARD_BUTTON_RCONTROL, + KEYBOARD_BUTTON_LCONTROL, + KEYBOARD_BUTTON_DELETE, + + CHARACTER_RANGE_START = 65, // letter A + + GAMEPAD_RANGE_START = 256, // do not use! + + GAMEPAD_BUTTON_UP, + GAMEPAD_BUTTON_LEFT, + GAMEPAD_BUTTON_DOWN, + GAMEPAD_BUTTON_RIGHT, + GAMEPAD_BUTTON_1, + GAMEPAD_BUTTON_2, + GAMEPAD_BUTTON_3, + GAMEPAD_BUTTON_4, + GAMEPAD_BUTTON_5, + GAMEPAD_BUTTON_6, + GAMEPAD_BUTTON_7, + GAMEPAD_BUTTON_8, + GAMEPAD_BUTTON_9, + GAMEPAD_BUTTON_10, + GAMEPAD_BUTTON_11, + GAMEPAD_BUTTON_12, + GAMEPAD_BUTTON_13, + GAMEPAD_BUTTON_14, + }; + enum GAMEPAD_ANALOG + { + GAMEPAD_ANALOG_THUMBSTICK_L, + GAMEPAD_ANALOG_THUMBSTICK_R, + GAMEPAD_ANALOG_TRIGGER_L, + GAMEPAD_ANALOG_TRIGGER_R, + }; + + // call once at app start + void Initialize(); + + // call once per frame + void Update(); + + // check if a button is down + bool down(BUTTON button, short playerindex = 0); + // check if a button is pressed once + bool press(BUTTON button, short playerindex = 0); + // check if a button is held down + bool hold(BUTTON button, uint32_t frames = 30, bool continuous = false, short playerIndex = 0); + // get pointer position (eg. mouse pointer) (.xy) + scroll delta (.z) + 1 unused (.w) + XMFLOAT4 getpointer(); + // set pointer position (eg. mouse pointer) + scroll delta (.z) + void setpointer(const XMFLOAT4& props); + // hide pointer + void hidepointer(bool value); + // read analog input from controllers, like thumbsticks or triggers + XMFLOAT4 getanalog(GAMEPAD_ANALOG analog, short playerIndex = 0); + + struct Touch + { + enum TOUCHSTATE + { + TOUCHSTATE_PRESSED, + TOUCHSTATE_RELEASED, + TOUCHSTATE_MOVED, + TOUCHSTATE_COUNT, + } state; + // current position of touch + XMFLOAT2 pos; + }; + const std::vector& getTouches(); + +}; + diff --git a/WickedEngine/wiInputManager.h b/WickedEngine/wiInputManager.h deleted file mode 100644 index 751757690..000000000 --- a/WickedEngine/wiInputManager.h +++ /dev/null @@ -1,78 +0,0 @@ -#pragma once -#include "CommonInclude.h" - -#include - -enum INPUT_TYPE -{ - INPUT_TYPE_KEYBOARD, - INPUT_TYPE_GAMEPAD, -}; -enum GAMEPAD_BUTTON -{ - GAMEPAD_BUTTON_UP, - GAMEPAD_BUTTON_LEFT, - GAMEPAD_BUTTON_DOWN, - GAMEPAD_BUTTON_RIGHT, - GAMEPAD_BUTTON_1, - GAMEPAD_BUTTON_2, - GAMEPAD_BUTTON_3, - GAMEPAD_BUTTON_4, - GAMEPAD_BUTTON_5, - GAMEPAD_BUTTON_6, - GAMEPAD_BUTTON_7, - GAMEPAD_BUTTON_8, - GAMEPAD_BUTTON_9, - GAMEPAD_BUTTON_10, - GAMEPAD_BUTTON_11, - GAMEPAD_BUTTON_12, - GAMEPAD_BUTTON_13, - GAMEPAD_BUTTON_14, -}; -enum GAMEPAD_ANALOG -{ - GAMEPAD_ANALOG_THUMBSTICK_L, - GAMEPAD_ANALOG_THUMBSTICK_R, - GAMEPAD_ANALOG_TRIGGER_L, - GAMEPAD_ANALOG_TRIGGER_R, -}; - -namespace wiInputManager -{ - // call once at app start - void Initialize(); - - // call once per frame - void Update(); - - // check if a button is down - bool down(uint32_t button, INPUT_TYPE inputType = INPUT_TYPE::INPUT_TYPE_KEYBOARD, short playerindex = 0); - // check if a button is pressed once - bool press(uint32_t button, INPUT_TYPE inputType = INPUT_TYPE::INPUT_TYPE_KEYBOARD, short playerindex = 0); - // check if a button is held down - bool hold(uint32_t button, uint32_t frames = 30, bool continuous = false, INPUT_TYPE inputType = INPUT_TYPE::INPUT_TYPE_KEYBOARD, short playerIndex = 0); - // get pointer position (eg. mouse pointer) (.xy) + scroll delta (.z) + 1 unused (.w) - XMFLOAT4 getpointer(); - // set pointer position (eg. mouse pointer) + scroll delta (.z) - void setpointer(const XMFLOAT4& props); - // hide pointer - void hidepointer(bool value); - // read analog input from controllers, like thumbsticks or triggers - XMFLOAT4 getanalog(GAMEPAD_ANALOG analog, short playerIndex = 0); - - struct Touch - { - enum TouchState - { - TOUCHSTATE_PRESSED, - TOUCHSTATE_RELEASED, - TOUCHSTATE_MOVED, - TOUCHSTATE_COUNT, - } state; - // current position of touch - XMFLOAT2 pos; - }; - const std::vector& getTouches(); - -}; - diff --git a/WickedEngine/wiInputManager_BindLua.cpp b/WickedEngine/wiInputManager_BindLua.cpp deleted file mode 100644 index 961f76b94..000000000 --- a/WickedEngine/wiInputManager_BindLua.cpp +++ /dev/null @@ -1,278 +0,0 @@ -#include "wiInputManager_BindLua.h" -#include "Vector_BindLua.h" - -const char wiInputManager_BindLua::className[] = "InputManager"; - -Luna::FunctionType wiInputManager_BindLua::methods[] = { - lunamethod(wiInputManager_BindLua, Down), - lunamethod(wiInputManager_BindLua, Press), - lunamethod(wiInputManager_BindLua, Hold), - lunamethod(wiInputManager_BindLua, GetPointer), - lunamethod(wiInputManager_BindLua, SetPointer), - lunamethod(wiInputManager_BindLua, HidePointer), - lunamethod(wiInputManager_BindLua, GetAnalog), - lunamethod(wiInputManager_BindLua, GetTouches), - { NULL, NULL } -}; -Luna::PropertyType wiInputManager_BindLua::properties[] = { - { NULL, NULL } -}; - -int wiInputManager_BindLua::Down(lua_State* L) -{ - int argc = wiLua::SGetArgCount(L); - if (argc > 0) - { - uint32_t code = (uint32_t)wiLua::SGetInt(L, 1); - INPUT_TYPE type = INPUT_TYPE_KEYBOARD; - if (argc > 1) - { - type = (INPUT_TYPE)wiLua::SGetInt(L, 2); - } - short playerindex = 0; - if (argc > 2) - { - playerindex = (short)wiLua::SGetInt(L, 3); - } - wiLua::SSetBool(L, wiInputManager::down(code, type, playerindex)); - return 1; - } - else - wiLua::SError(L, "Down(int code, opt int type = INPUT_TYPE_KEYBOARD) not enough arguments!"); - return 0; -} -int wiInputManager_BindLua::Press(lua_State* L) -{ - int argc = wiLua::SGetArgCount(L); - if (argc > 0) - { - uint32_t code = (uint32_t)wiLua::SGetInt(L, 1); - INPUT_TYPE type = INPUT_TYPE_KEYBOARD; - if (argc > 1) - { - type = (INPUT_TYPE)wiLua::SGetInt(L, 2); - } - short playerindex = 0; - if (argc > 2) - { - playerindex = (short)wiLua::SGetInt(L, 3); - } - wiLua::SSetBool(L, wiInputManager::press(code, type, playerindex)); - return 1; - } - else - wiLua::SError(L, "Press(int code, opt int type = INPUT_TYPE_KEYBOARD) not enough arguments!"); - return 0; -} -int wiInputManager_BindLua::Hold(lua_State* L) -{ - int argc = wiLua::SGetArgCount(L); - if (argc > 0) - { - uint32_t code = (uint32_t)wiLua::SGetInt(L, 1); - uint32_t duration = 30; - if (argc > 1) - { - duration = wiLua::SGetInt(L, 2); - } - bool continuous = false; - if (argc > 2) - { - continuous = wiLua::SGetBool(L, 3); - } - INPUT_TYPE type = INPUT_TYPE_KEYBOARD; - if (argc > 3) - { - type = (INPUT_TYPE)wiLua::SGetInt(L, 4); - } - short playerindex = 0; - if (argc > 4) - { - playerindex = (short)wiLua::SGetInt(L, 5); - } - wiLua::SSetBool(L, wiInputManager::hold(code, duration, continuous, type, playerindex)); - return 1; - } - else - wiLua::SError(L, "Hold(int code, opt int duration = 30, opt boolean continuous = false, opt int type = KEYBOARD) not enough arguments!"); - return 0; -} -int wiInputManager_BindLua::GetPointer(lua_State* L) -{ - Luna::push(L, new Vector_BindLua(XMLoadFloat4(&wiInputManager::getpointer()))); - return 1; -} -int wiInputManager_BindLua::SetPointer(lua_State* L) -{ - int argc = wiLua::SGetArgCount(L); - if (argc > 0) - { - Vector_BindLua* vec = Luna::lightcheck(L, 1); - if (vec != nullptr) - { - XMFLOAT4 props; - XMStoreFloat4(&props, vec->vector); - wiInputManager::setpointer(props); - } - else - wiLua::SError(L, "SetPointer(Vector props) argument is not a Vector!"); - } - else - wiLua::SError(L, "SetPointer(Vector props) not enough arguments!"); - return 0; -} -int wiInputManager_BindLua::HidePointer(lua_State* L) -{ - int argc = wiLua::SGetArgCount(L); - if (argc > 0) - { - wiInputManager::hidepointer(wiLua::SGetBool(L, 1)); - } - else - wiLua::SError(L, "HidePointer(bool value) not enough arguments!"); - return 0; -} -int wiInputManager_BindLua::GetAnalog(lua_State* L) -{ - XMFLOAT4 result = XMFLOAT4(0, 0, 0, 0); - - int argc = wiLua::SGetArgCount(L); - if (argc > 0) - { - GAMEPAD_ANALOG type = (GAMEPAD_ANALOG)wiLua::SGetInt(L, 1); - short playerindex = 0; - if (argc > 1) - { - playerindex = (short)wiLua::SGetInt(L, 2); - } - result = wiInputManager::getanalog(type, playerindex); - } - else - wiLua::SError(L, "GetAnalog(int type, opt int playerindex = 0) not enough arguments!"); - - Luna::push(L, new Vector_BindLua(XMLoadFloat4(&result))); - return 1; -} -int wiInputManager_BindLua::GetTouches(lua_State* L) -{ - auto& touches = wiInputManager::getTouches(); - for (auto& touch : touches) - { - Luna::push(L, new Touch_BindLua(touch)); - } - return (int)touches.size(); -} - -void wiInputManager_BindLua::Bind() -{ - static bool initialized = false; - if (!initialized) - { - initialized = true; - Luna::Register(wiLua::GetGlobal()->GetLuaState()); - wiLua::GetGlobal()->RunText("input = InputManager()"); - - //Input types - wiLua::GetGlobal()->RunText("INPUT_TYPE_KEYBOARD = 0"); - wiLua::GetGlobal()->RunText("INPUT_TYPE_GAMEPAD = 1"); - - //Keyboard - wiLua::GetGlobal()->RunText("VK_UP = 0x26"); - wiLua::GetGlobal()->RunText("VK_DOWN = 0x28"); - wiLua::GetGlobal()->RunText("VK_LEFT = 0x25"); - wiLua::GetGlobal()->RunText("VK_RIGHT = 0x27"); - wiLua::GetGlobal()->RunText("VK_SPACE = 0x20"); - wiLua::GetGlobal()->RunText("VK_RETURN = 0x0D"); - wiLua::GetGlobal()->RunText("VK_RSHIFT = 0xA1"); - wiLua::GetGlobal()->RunText("VK_LSHIFT = 0xA0"); - wiLua::GetGlobal()->RunText("VK_F1 = 0x70"); - wiLua::GetGlobal()->RunText("VK_F2 = 0x71"); - wiLua::GetGlobal()->RunText("VK_F3 = 0x72"); - wiLua::GetGlobal()->RunText("VK_F4 = 0x73"); - wiLua::GetGlobal()->RunText("VK_F5 = 0x74"); - wiLua::GetGlobal()->RunText("VK_F6 = 0x75"); - wiLua::GetGlobal()->RunText("VK_F7 = 0x76"); - wiLua::GetGlobal()->RunText("VK_F8 = 0x77"); - wiLua::GetGlobal()->RunText("VK_F9 = 0x78"); - wiLua::GetGlobal()->RunText("VK_F10 = 0x79"); - wiLua::GetGlobal()->RunText("VK_F11 = 0x7A"); - wiLua::GetGlobal()->RunText("VK_F12 = 0x7B"); - wiLua::GetGlobal()->RunText("VK_ESCAPE = 0x1B"); - - //Mouse - wiLua::GetGlobal()->RunText("VK_LBUTTON = 0x01"); - wiLua::GetGlobal()->RunText("VK_MBUTTON = 0x04"); - wiLua::GetGlobal()->RunText("VK_RBUTTON = 0x02"); - - //Gamepad - wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_UP = 0"); - wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_LEFT = 1"); - wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_DOWN = 2"); - wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_RIGHT = 3"); - wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_1 = 4"); - wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_2 = 5"); - wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_3 = 6"); - wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_4 = 7"); - wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_5 = 8"); - wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_6 = 9"); - wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_7 = 10"); - wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_8 = 11"); - wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_9 = 12"); - wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_10 = 13"); - wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_11 = 14"); - wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_12 = 15"); - wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_13 = 16"); - wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_14 = 17"); - - //Analog - wiLua::GetGlobal()->RunText("GAMEPAD_ANALOG_THUMBSTICK_L = 0"); - wiLua::GetGlobal()->RunText("GAMEPAD_ANALOG_THUMBSTICK_R = 1"); - wiLua::GetGlobal()->RunText("GAMEPAD_ANALOG_TRIGGER_L = 2"); - wiLua::GetGlobal()->RunText("GAMEPAD_ANALOG_TRIGGER_R = 3"); - - //Touch - wiLua::GetGlobal()->RunText("TOUCHSTATE_PRESSED = 0"); - wiLua::GetGlobal()->RunText("TOUCHSTATE_RELEASED = 1"); - wiLua::GetGlobal()->RunText("TOUCHSTATE_MOVED = 2"); - } - - Touch_BindLua::Bind(); -} - - - - - - - -const char Touch_BindLua::className[] = "Touch"; - -Luna::FunctionType Touch_BindLua::methods[] = { - lunamethod(Touch_BindLua, GetState), - lunamethod(Touch_BindLua, GetPos), - { NULL, NULL } -}; -Luna::PropertyType Touch_BindLua::properties[] = { - { NULL, NULL } -}; - -int Touch_BindLua::GetState(lua_State* L) -{ - wiLua::SSetInt(L, (int)touch.state); - return 1; -} -int Touch_BindLua::GetPos(lua_State* L) -{ - Luna::push(L, new Vector_BindLua(XMLoadFloat2(&touch.pos))); - return 1; -} - -void Touch_BindLua::Bind() -{ - static bool initialized = false; - if (!initialized) - { - initialized = true; - Luna::Register(wiLua::GetGlobal()->GetLuaState()); - } -} diff --git a/WickedEngine/wiInput_BindLua.cpp b/WickedEngine/wiInput_BindLua.cpp new file mode 100644 index 000000000..5a60105ef --- /dev/null +++ b/WickedEngine/wiInput_BindLua.cpp @@ -0,0 +1,260 @@ +#include "wiInput_BindLua.h" +#include "Vector_BindLua.h" + +const char wiInput_BindLua::className[] = "Input"; + +Luna::FunctionType wiInput_BindLua::methods[] = { + lunamethod(wiInput_BindLua, Down), + lunamethod(wiInput_BindLua, Press), + lunamethod(wiInput_BindLua, Hold), + lunamethod(wiInput_BindLua, GetPointer), + lunamethod(wiInput_BindLua, SetPointer), + lunamethod(wiInput_BindLua, HidePointer), + lunamethod(wiInput_BindLua, GetAnalog), + lunamethod(wiInput_BindLua, GetTouches), + { NULL, NULL } +}; +Luna::PropertyType wiInput_BindLua::properties[] = { + { NULL, NULL } +}; + +int wiInput_BindLua::Down(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + wiInput::BUTTON button = (wiInput::BUTTON)wiLua::SGetInt(L, 1); + short playerindex = 0; + if (argc > 1) + { + playerindex = (short)wiLua::SGetInt(L, 2); + } + wiLua::SSetBool(L, wiInput::down(button, playerindex)); + return 1; + } + else + wiLua::SError(L, "Down(int code, opt int playerindex = 0) not enough arguments!"); + return 0; +} +int wiInput_BindLua::Press(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + wiInput::BUTTON code = (wiInput::BUTTON)wiLua::SGetInt(L, 1); + short playerindex = 0; + if (argc > 1) + { + playerindex = (short)wiLua::SGetInt(L, 2); + } + wiLua::SSetBool(L, wiInput::press(code, playerindex)); + return 1; + } + else + wiLua::SError(L, "Press(int code, opt int playerindex = 0) not enough arguments!"); + return 0; +} +int wiInput_BindLua::Hold(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + wiInput::BUTTON button = (wiInput::BUTTON)wiLua::SGetInt(L, 1); + uint32_t duration = 30; + if (argc > 1) + { + duration = wiLua::SGetInt(L, 2); + } + bool continuous = false; + if (argc > 2) + { + continuous = wiLua::SGetBool(L, 3); + } + short playerindex = 0; + if (argc > 3) + { + playerindex = (short)wiLua::SGetInt(L, 4); + } + wiLua::SSetBool(L, wiInput::hold(button, duration, continuous, playerindex)); + return 1; + } + else + wiLua::SError(L, "Hold(int code, opt int duration = 30, opt boolean continuous = false, opt int playerindex = 0) not enough arguments!"); + return 0; +} +int wiInput_BindLua::GetPointer(lua_State* L) +{ + Luna::push(L, new Vector_BindLua(XMLoadFloat4(&wiInput::getpointer()))); + return 1; +} +int wiInput_BindLua::SetPointer(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + Vector_BindLua* vec = Luna::lightcheck(L, 1); + if (vec != nullptr) + { + XMFLOAT4 props; + XMStoreFloat4(&props, vec->vector); + wiInput::setpointer(props); + } + else + wiLua::SError(L, "SetPointer(Vector props) argument is not a Vector!"); + } + else + wiLua::SError(L, "SetPointer(Vector props) not enough arguments!"); + return 0; +} +int wiInput_BindLua::HidePointer(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + wiInput::hidepointer(wiLua::SGetBool(L, 1)); + } + else + wiLua::SError(L, "HidePointer(bool value) not enough arguments!"); + return 0; +} +int wiInput_BindLua::GetAnalog(lua_State* L) +{ + XMFLOAT4 result = XMFLOAT4(0, 0, 0, 0); + + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + wiInput::GAMEPAD_ANALOG type = (wiInput::GAMEPAD_ANALOG)wiLua::SGetInt(L, 1); + short playerindex = 0; + if (argc > 1) + { + playerindex = (short)wiLua::SGetInt(L, 2); + } + result = wiInput::getanalog(type, playerindex); + } + else + wiLua::SError(L, "GetAnalog(int type, opt int playerindex = 0) not enough arguments!"); + + Luna::push(L, new Vector_BindLua(XMLoadFloat4(&result))); + return 1; +} +int wiInput_BindLua::GetTouches(lua_State* L) +{ + auto& touches = wiInput::getTouches(); + for (auto& touch : touches) + { + Luna::push(L, new Touch_BindLua(touch)); + } + return (int)touches.size(); +} + +void wiInput_BindLua::Bind() +{ + static bool initialized = false; + if (!initialized) + { + initialized = true; + Luna::Register(wiLua::GetGlobal()->GetLuaState()); + wiLua::GetGlobal()->RunText("input = Input()"); + + wiLua::GetGlobal()->RunText("MOUSE_BUTTON_LEFT = 1"); + wiLua::GetGlobal()->RunText("MOUSE_BUTTON_RIGHT = 2"); + wiLua::GetGlobal()->RunText("MOUSE_BUTTON_MIDDLE = 3"); + + wiLua::GetGlobal()->RunText("KEYBOARD_BUTTON_UP = 4"); + wiLua::GetGlobal()->RunText("KEYBOARD_BUTTON_DOWN = 5"); + wiLua::GetGlobal()->RunText("KEYBOARD_BUTTON_LEFT = 6"); + wiLua::GetGlobal()->RunText("KEYBOARD_BUTTON_RIGHT = 7"); + wiLua::GetGlobal()->RunText("KEYBOARD_BUTTON_SPACE = 8"); + wiLua::GetGlobal()->RunText("KEYBOARD_BUTTON_RSHIFT = 9"); + wiLua::GetGlobal()->RunText("KEYBOARD_BUTTON_LSHIFT = 10"); + wiLua::GetGlobal()->RunText("KEYBOARD_BUTTON_F1 = 11"); + wiLua::GetGlobal()->RunText("KEYBOARD_BUTTON_F2 = 12"); + wiLua::GetGlobal()->RunText("KEYBOARD_BUTTON_F3 = 13"); + wiLua::GetGlobal()->RunText("KEYBOARD_BUTTON_F4 = 14"); + wiLua::GetGlobal()->RunText("KEYBOARD_BUTTON_F5 = 15"); + wiLua::GetGlobal()->RunText("KEYBOARD_BUTTON_F6 = 16"); + wiLua::GetGlobal()->RunText("KEYBOARD_BUTTON_F7 = 17"); + wiLua::GetGlobal()->RunText("KEYBOARD_BUTTON_F8 = 18"); + wiLua::GetGlobal()->RunText("KEYBOARD_BUTTON_F9 = 19"); + wiLua::GetGlobal()->RunText("KEYBOARD_BUTTON_F10 = 20"); + wiLua::GetGlobal()->RunText("KEYBOARD_BUTTON_F11 = 21"); + wiLua::GetGlobal()->RunText("KEYBOARD_BUTTON_F12 = 22"); + wiLua::GetGlobal()->RunText("KEYBOARD_BUTTON_ENTER = 23"); + wiLua::GetGlobal()->RunText("KEYBOARD_BUTTON_ESCAPE = 24"); + wiLua::GetGlobal()->RunText("KEYBOARD_BUTTON_HOME = 25"); + wiLua::GetGlobal()->RunText("KEYBOARD_BUTTON_RCONTROL = 26"); + wiLua::GetGlobal()->RunText("KEYBOARD_BUTTON_LCONTROL = 27"); + wiLua::GetGlobal()->RunText("KEYBOARD_BUTTON_DELETE = 28"); + + wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_UP = 257"); + wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_LEFT = 258"); + wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_DOWN = 259"); + wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_RIGHT = 260"); + wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_1 = 261"); + wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_2 = 262"); + wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_3 = 263"); + wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_4 = 264"); + wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_5 = 265"); + wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_6 = 266"); + wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_7 = 267"); + wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_8 = 268"); + wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_9 = 269"); + wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_10 = 270"); + wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_11 = 271"); + wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_12 = 272"); + wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_13 = 273"); + wiLua::GetGlobal()->RunText("GAMEPAD_BUTTON_14 = 274"); + + //Analog + wiLua::GetGlobal()->RunText("GAMEPAD_ANALOG_THUMBSTICK_L = 0"); + wiLua::GetGlobal()->RunText("GAMEPAD_ANALOG_THUMBSTICK_R = 1"); + wiLua::GetGlobal()->RunText("GAMEPAD_ANALOG_TRIGGER_L = 2"); + wiLua::GetGlobal()->RunText("GAMEPAD_ANALOG_TRIGGER_R = 3"); + + //Touch + wiLua::GetGlobal()->RunText("TOUCHSTATE_PRESSED = 0"); + wiLua::GetGlobal()->RunText("TOUCHSTATE_RELEASED = 1"); + wiLua::GetGlobal()->RunText("TOUCHSTATE_MOVED = 2"); + } + + Touch_BindLua::Bind(); +} + + + + + + + +const char Touch_BindLua::className[] = "Touch"; + +Luna::FunctionType Touch_BindLua::methods[] = { + lunamethod(Touch_BindLua, GetState), + lunamethod(Touch_BindLua, GetPos), + { NULL, NULL } +}; +Luna::PropertyType Touch_BindLua::properties[] = { + { NULL, NULL } +}; + +int Touch_BindLua::GetState(lua_State* L) +{ + wiLua::SSetInt(L, (int)touch.state); + return 1; +} +int Touch_BindLua::GetPos(lua_State* L) +{ + Luna::push(L, new Vector_BindLua(XMLoadFloat2(&touch.pos))); + return 1; +} + +void Touch_BindLua::Bind() +{ + static bool initialized = false; + if (!initialized) + { + initialized = true; + Luna::Register(wiLua::GetGlobal()->GetLuaState()); + } +} diff --git a/WickedEngine/wiInputManager_BindLua.h b/WickedEngine/wiInput_BindLua.h similarity index 65% rename from WickedEngine/wiInputManager_BindLua.h rename to WickedEngine/wiInput_BindLua.h index 1fb04c903..b07284e9b 100644 --- a/WickedEngine/wiInputManager_BindLua.h +++ b/WickedEngine/wiInput_BindLua.h @@ -1,17 +1,17 @@ #pragma once #include "wiLua.h" #include "wiLuna.h" -#include "wiInputManager.h" +#include "wiInput.h" -class wiInputManager_BindLua +class wiInput_BindLua { public: static const char className[]; - static Luna::FunctionType methods[]; - static Luna::PropertyType properties[]; + static Luna::FunctionType methods[]; + static Luna::PropertyType properties[]; - wiInputManager_BindLua(lua_State* L){} - ~wiInputManager_BindLua(){} + wiInput_BindLua(lua_State* L){} + ~wiInput_BindLua(){} int Down(lua_State* L); int Press(lua_State* L); @@ -28,13 +28,13 @@ public: class Touch_BindLua { public: - wiInputManager::Touch touch; + wiInput::Touch touch; static const char className[]; static Luna::FunctionType methods[]; static Luna::PropertyType properties[]; Touch_BindLua(lua_State* L) {} - Touch_BindLua(const wiInputManager::Touch& touch) :touch(touch) {} + Touch_BindLua(const wiInput::Touch& touch) :touch(touch) {} ~Touch_BindLua() {} int GetState(lua_State* L); diff --git a/WickedEngine/wiLua.cpp b/WickedEngine/wiLua.cpp index 5a7570dbb..a2c22988b 100644 --- a/WickedEngine/wiLua.cpp +++ b/WickedEngine/wiLua.cpp @@ -20,7 +20,7 @@ #include "wiSceneSystem_BindLua.h" #include "Vector_BindLua.h" #include "Matrix_BindLua.h" -#include "wiInputManager_BindLua.h" +#include "wiInput_BindLua.h" #include "wiFont_BindLua.h" #include "wiBackLog_BindLua.h" #include "wiNetwork_BindLua.h" @@ -72,7 +72,7 @@ wiLua* wiLua::GetGlobal() wiSceneSystem_BindLua::Bind(); Vector_BindLua::Bind(); Matrix_BindLua::Bind(); - wiInputManager_BindLua::Bind(); + wiInput_BindLua::Bind(); wiFont_BindLua::Bind(); wiBackLog_BindLua::Bind(); wiNetwork_BindLua::Bind(); diff --git a/WickedEngine/wiRawInput.h b/WickedEngine/wiRawInput.h index c09925c7a..6d14344de 100644 --- a/WickedEngine/wiRawInput.h +++ b/WickedEngine/wiRawInput.h @@ -1,29 +1,33 @@ #pragma once #include "CommonInclude.h" -//class wiRawInput -//{ -//public: -//#ifndef WINSTORE_SUPPORT -// wiRawInput(HWND hWnd = NULL); -// ~wiRawInput(); -// -// //for generic joypad support -// bool RegisterJoys(HWND hWnd); -// //disables legacy mouse and keyboard support -// bool RegisterKeyboardMouse(HWND hWnd); -// //use this in WndProc in case of WM_INPUT event -// void RetrieveData(LPARAM lParam); -// //read buffered data -// void RetrieveBufferedData(); -// -// RAWINPUT raw; -// -//#else -// //Raw input is not available! -// wiRawInput(){} -// //Raw input is not available! -// void RetrieveBufferedData(){} -//#endif //WINSTORE_SUPPORT -//}; +namespace wiInput +{ + //class wiRawInput + //{ + //public: + //#ifndef WINSTORE_SUPPORT + // wiRawInput(HWND hWnd = NULL); + // ~wiRawInput(); + // + // //for generic joypad support + // bool RegisterJoys(HWND hWnd); + // //disables legacy mouse and keyboard support + // bool RegisterKeyboardMouse(HWND hWnd); + // //use this in WndProc in case of WM_INPUT event + // void RetrieveData(LPARAM lParam); + // //read buffered data + // void RetrieveBufferedData(); + // + // RAWINPUT raw; + // + //#else + // //Raw input is not available! + // wiRawInput(){} + // //Raw input is not available! + // void RetrieveBufferedData(){} + //#endif //WINSTORE_SUPPORT + //}; + +} diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 313391c5f..6f32afaf4 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -7,7 +7,7 @@ namespace wiVersion // main engine core const int major = 0; // minor features, major updates - const int minor = 34; + const int minor = 35; // minor bug fixes, alterations, refactors, updates const int revision = 0; diff --git a/WickedEngine/wiWidget.cpp b/WickedEngine/wiWidget.cpp index 1bfec530c..85615d9f2 100644 --- a/WickedEngine/wiWidget.cpp +++ b/WickedEngine/wiWidget.cpp @@ -5,7 +5,7 @@ #include "wiFont.h" #include "wiMath.h" #include "wiHelper.h" -#include "wiInputManager.h" +#include "wiInput.h" #include "wiRenderer.h" #include "ShaderInterop_Renderer.h" @@ -314,7 +314,7 @@ void wiButton::Update(wiGUI* gui, float dt) } } - if (wiInputManager::press(VK_LBUTTON)) + if (wiInput::press(wiInput::MOUSE_BUTTON_LEFT)) { if (state == FOCUS) { @@ -323,7 +323,7 @@ void wiButton::Update(wiGUI* gui, float dt) } } - if (wiInputManager::down(VK_LBUTTON)) + if (wiInput::down(wiInput::MOUSE_BUTTON_LEFT)) { if (state == DEACTIVATING) { @@ -519,7 +519,7 @@ void wiTextInputField::Update(wiGUI* gui, float dt) } } - if (wiInputManager::press(VK_LBUTTON)) + if (wiInput::press(wiInput::MOUSE_BUTTON_LEFT)) { if (state == FOCUS) { @@ -528,7 +528,7 @@ void wiTextInputField::Update(wiGUI* gui, float dt) } } - if (wiInputManager::down(VK_LBUTTON)) + if (wiInput::down(wiInput::MOUSE_BUTTON_LEFT)) { if (state == DEACTIVATING) { @@ -546,7 +546,7 @@ void wiTextInputField::Update(wiGUI* gui, float dt) if (state == ACTIVE) { - if (wiInputManager::press(VK_RETURN)) + if (wiInput::press(wiInput::KEYBOARD_BUTTON_ENTER)) { // accept input... @@ -561,8 +561,8 @@ void wiTextInputField::Update(wiGUI* gui, float dt) gui->DeactivateWidget(this); } - else if ((wiInputManager::press(VK_LBUTTON) && !intersectsPointer) || - wiInputManager::press(VK_ESCAPE)) + else if ((wiInput::press(wiInput::MOUSE_BUTTON_LEFT) && !intersectsPointer) || + wiInput::press(wiInput::KEYBOARD_BUTTON_ESCAPE)) { // cancel input value_new.clear(); @@ -697,7 +697,7 @@ void wiSlider::Update(wiGUI* gui, float dt) } if (state == ACTIVE) { - if (wiInputManager::down(VK_LBUTTON)) + if (wiInput::down(wiInput::MOUSE_BUTTON_LEFT)) { if (state == ACTIVE) { @@ -730,7 +730,7 @@ void wiSlider::Update(wiGUI* gui, float dt) } } - if (wiInputManager::press(VK_LBUTTON)) + if (wiInput::press(wiInput::MOUSE_BUTTON_LEFT)) { if (state == FOCUS) { @@ -863,7 +863,7 @@ void wiCheckBox::Update(wiGUI* gui, float dt) } } - if (wiInputManager::press(VK_LBUTTON)) + if (wiInput::press(wiInput::MOUSE_BUTTON_LEFT)) { if (state == FOCUS) { @@ -872,7 +872,7 @@ void wiCheckBox::Update(wiGUI* gui, float dt) } } - if (wiInputManager::down(VK_LBUTTON)) + if (wiInput::down(wiInput::MOUSE_BUTTON_LEFT)) { if (state == DEACTIVATING) { @@ -1011,14 +1011,14 @@ void wiComboBox::Update(wiGUI* gui, float dt) } } - if (wiInputManager::press(VK_LBUTTON)) + if (wiInput::press(wiInput::MOUSE_BUTTON_LEFT)) { // activate clicked = true; } bool click_down = false; - if (wiInputManager::down(VK_LBUTTON)) + if (wiInput::down(wiInput::MOUSE_BUTTON_LEFT)) { click_down = true; if (state == DEACTIVATING) @@ -1076,7 +1076,7 @@ void wiComboBox::Update(wiGUI* gui, float dt) } else if (combostate == COMBOSTATE_HOVER) { - int scroll = (int)wiInputManager::getpointer().z; + int scroll = (int)wiInput::getpointer().z; firstItemVisible -= scroll; firstItemVisible = std::max(0, std::min((int)items.size() - maxVisibleItemCount, firstItemVisible)); if (scroll) @@ -1723,7 +1723,7 @@ void wiColorPicker::Update(wiGUI* gui, float dt) bool dragged = false; - if (wiInputManager::press(VK_LBUTTON)) + if (wiInput::press(wiInput::MOUSE_BUTTON_LEFT)) { if (state == FOCUS) { @@ -1732,7 +1732,7 @@ void wiColorPicker::Update(wiGUI* gui, float dt) } } - if (wiInputManager::down(VK_LBUTTON)) + if (wiInput::down(wiInput::MOUSE_BUTTON_LEFT)) { if (state == ACTIVE) { diff --git a/WickedEngine/wiXInput.cpp b/WickedEngine/wiXInput.cpp index 6e013a3d5..f0d4e8b76 100644 --- a/WickedEngine/wiXInput.cpp +++ b/WickedEngine/wiXInput.cpp @@ -2,54 +2,61 @@ #include "wiXInput.h" -wiXInput::wiXInput() +#pragma comment(lib,"xinput.lib") + +namespace wiInput { - g_bDeadZoneOn = true; - for(int i=0;i0) then - if(input.Down(VK_LSHIFT) or input.Down(GAMEPAD_BUTTON_6, INPUT_TYPE_GAMEPAD)) then + if(input.Down(KEYBOARD_BUTTON_LSHIFT) or input.Down(GAMEPAD_BUTTON_6)) then self:MoveDirection(lookDir,self.moveSpeed*2) else self:MoveDirection(lookDir,self.moveSpeed) @@ -122,7 +122,7 @@ Character = { end - if( input.Press(string.byte('J')) or input.Press(VK_SPACE) or input.Press(GAMEPAD_BUTTON_2, INPUT_TYPE_GAMEPAD) ) then + if( input.Press(string.byte('J')) or input.Press(KEYBOARD_BUTTON_SPACE) or input.Press(GAMEPAD_BUTTON_2) ) then self:Jump(2000) end @@ -133,7 +133,7 @@ Character = { diff = vector.Multiply(diff, getDeltaTime() * 4) -- read from mouse: - if(input.Down(VK_RBUTTON)) then + if(input.Down(MOUSE_BUTTON_RIGHT)) then local mousePosNew = input.GetPointer() local mouseDif = vector.Subtract(mousePosNew,self.savedPointerPos) mouseDif = mouseDif:Multiply(getDeltaTime() * 0.3) @@ -379,7 +379,7 @@ runProcess(function() - if(input.Press(VK_ESCAPE)) then + if(input.Press(KEYBOARD_BUTTON_ESCAPE)) then -- restore previous component -- so if you loaded this script from the editor, you can go back to the editor with ESC backlog_post("EXIT") diff --git a/scripts/fighting_game.lua b/scripts/fighting_game.lua index 69476c570..8ce8abf6b 100644 --- a/scripts/fighting_game.lua +++ b/scripts/fighting_game.lua @@ -1428,15 +1428,15 @@ local function Character(face, skin_color, shirt_color, hair_color, shoe_color) Input = function(self, playerindex) -- read input: - local left = input.Down(string.byte('A'), INPUT_TYPE_KEYBOARD, playerindex) or input.Down(GAMEPAD_BUTTON_LEFT, INPUT_TYPE_GAMEPAD, playerindex) - local right = input.Down(string.byte('D'), INPUT_TYPE_KEYBOARD, playerindex) or input.Down(GAMEPAD_BUTTON_RIGHT, INPUT_TYPE_GAMEPAD, playerindex) - local up = input.Down(string.byte('W'), INPUT_TYPE_KEYBOARD, playerindex) or input.Down(GAMEPAD_BUTTON_UP, INPUT_TYPE_GAMEPAD, playerindex) - local down = input.Down(string.byte('S'), INPUT_TYPE_KEYBOARD, playerindex) or input.Down(GAMEPAD_BUTTON_DOWN, INPUT_TYPE_GAMEPAD, playerindex) - local A = input.Down(VK_RIGHT, INPUT_TYPE_KEYBOARD, playerindex) or input.Down(GAMEPAD_BUTTON_3, INPUT_TYPE_GAMEPAD, playerindex) - local B = input.Down(VK_UP, INPUT_TYPE_KEYBOARD, playerindex) or input.Down(GAMEPAD_BUTTON_4, INPUT_TYPE_GAMEPAD, playerindex) - local C = input.Down(VK_LEFT, INPUT_TYPE_KEYBOARD, playerindex) or input.Down(GAMEPAD_BUTTON_1, INPUT_TYPE_GAMEPAD, playerindex) - local D = input.Down(VK_DOWN, INPUT_TYPE_KEYBOARD, playerindex) or input.Down(GAMEPAD_BUTTON_2, INPUT_TYPE_GAMEPAD, playerindex) - local T = input.Down(string.byte('T'), INPUT_TYPE_KEYBOARD, playerindex) or input.Down(GAMEPAD_BUTTON_5, INPUT_TYPE_GAMEPAD, playerindex) + local left = input.Down(string.byte('A'), playerindex) or input.Down(GAMEPAD_BUTTON_LEFT, playerindex) + local right = input.Down(string.byte('D'), playerindex) or input.Down(GAMEPAD_BUTTON_RIGHT, playerindex) + local up = input.Down(string.byte('W'), playerindex) or input.Down(GAMEPAD_BUTTON_UP, playerindex) + local down = input.Down(string.byte('S'), playerindex) or input.Down(GAMEPAD_BUTTON_DOWN, playerindex) + local A = input.Down(KEYBOARD_BUTTON_RIGHT, playerindex) or input.Down(GAMEPAD_BUTTON_3, playerindex) + local B = input.Down(KEYBOARD_BUTTON_UP, playerindex) or input.Down(GAMEPAD_BUTTON_4, playerindex) + local C = input.Down(KEYBOARD_BUTTON_LEFT, playerindex) or input.Down(GAMEPAD_BUTTON_1, playerindex) + local D = input.Down(KEYBOARD_BUTTON_DOWN, playerindex) or input.Down(GAMEPAD_BUTTON_2, playerindex) + local T = input.Down(string.byte('T'), playerindex) or input.Down(GAMEPAD_BUTTON_5, playerindex) -- swap left and right if facing the opposite side: if(self.face < 0) then @@ -1946,7 +1946,7 @@ runProcess(function() player2.ai_state = "Attack" elseif(input.Press(string.byte('H'))) then debug_draw = not debug_draw - elseif(input.Press(GAMEPAD_BUTTON_10, INPUT_TYPE_GAMEPAD, 1)) then + elseif(input.Press(GAMEPAD_BUTTON_10, 1)) then if(player2_control == "CPU") then player2_control = "Controller2" else @@ -1984,7 +1984,7 @@ runProcess(function() update() - if(input.Press(VK_ESCAPE)) then + if(input.Press(KEYBOARD_BUTTON_ESCAPE)) then -- restore previous component -- so if you loaded this script from the editor, you can go back to the editor with ESC backlog_post("EXIT")