input refactor

This commit is contained in:
Turanszki Janos
2019-11-23 04:33:03 +00:00
parent df963528da
commit fbb53e3a6d
30 changed files with 1153 additions and 1044 deletions
+31 -31
View File
@@ -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
+1 -1
View File
@@ -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.
+39 -39
View File
@@ -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<wiSceneSystem::PickResult> 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);
}
+4 -4
View File
@@ -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)
{
+2 -2
View File
@@ -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:
+3 -3
View File
@@ -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
```
+2 -2
View File
@@ -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();
}
+1 -4
View File
@@ -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"
+4 -4
View File
@@ -272,6 +272,8 @@
<ClInclude Include="$(MSBuildThisFileDirectory)wiGraphicsDevice_DX12.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiGraphicsDevice_SharedInternals.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiGraphicsDevice_Vulkan.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiInput.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiInput_BindLua.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiIntersect.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiHashString.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)LoadingScreen.h" />
@@ -336,8 +338,6 @@
<ClInclude Include="$(MSBuildThisFileDirectory)wiImage.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiImageParams_BindLua.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiInitializer.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiInputManager.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiInputManager_BindLua.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiIntersect_BindLua.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiJobSystem.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)wiNetwork.h" />
@@ -665,8 +665,8 @@
<ClCompile Include="$(MSBuildThisFileDirectory)wiImage.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiImageParams_BindLua.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiInitializer.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiInputManager.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiInputManager_BindLua.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiInput.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiInput_BindLua.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiIntersect.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiIntersect_BindLua.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiJobSystem.cpp" />
@@ -189,9 +189,6 @@
<ClInclude Include="$(MSBuildThisFileDirectory)wiFont_BindLua.h">
<Filter>ENGINE\Scripting\LuaBindings</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)wiInputManager_BindLua.h">
<Filter>ENGINE\Scripting\LuaBindings</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)wiNetwork_BindLua.h">
<Filter>ENGINE\Scripting\LuaBindings</Filter>
</ClInclude>
@@ -912,9 +909,6 @@
<ClInclude Include="$(MSBuildThisFileDirectory)wiRawInput.h">
<Filter>ENGINE\Input</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)wiInputManager.h">
<Filter>ENGINE\Input</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)wiDirectInput.h">
<Filter>ENGINE\Input</Filter>
</ClInclude>
@@ -1134,6 +1128,12 @@
<ClInclude Include="$(MSBuildThisFileDirectory)Utility\D3D12MemAlloc.h">
<Filter>UTILITY</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)wiInput.h">
<Filter>ENGINE\Input</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)wiInput_BindLua.h">
<Filter>ENGINE\Scripting\LuaBindings</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="$(MSBuildThisFileDirectory)LUA\lapi.c">
@@ -1268,9 +1268,6 @@
<ClCompile Include="$(MSBuildThisFileDirectory)wiFont_BindLua.cpp">
<Filter>ENGINE\Scripting\LuaBindings</Filter>
</ClCompile>
<ClCompile Include="$(MSBuildThisFileDirectory)wiInputManager_BindLua.cpp">
<Filter>ENGINE\Scripting\LuaBindings</Filter>
</ClCompile>
<ClCompile Include="$(MSBuildThisFileDirectory)wiNetwork_BindLua.cpp">
<Filter>ENGINE\Scripting\LuaBindings</Filter>
</ClCompile>
@@ -1757,9 +1754,6 @@
<ClCompile Include="$(MSBuildThisFileDirectory)wiRawInput.cpp">
<Filter>ENGINE\Input</Filter>
</ClCompile>
<ClCompile Include="$(MSBuildThisFileDirectory)wiInputManager.cpp">
<Filter>ENGINE\Input</Filter>
</ClCompile>
<ClCompile Include="$(MSBuildThisFileDirectory)wiDirectInput.cpp">
<Filter>ENGINE\Input</Filter>
</ClCompile>
@@ -1904,6 +1898,12 @@
<ClCompile Include="$(MSBuildThisFileDirectory)Utility\D3D12MemAlloc.cpp">
<Filter>UTILITY</Filter>
</ClCompile>
<ClCompile Include="$(MSBuildThisFileDirectory)wiInput.cpp">
<Filter>ENGINE\Input</Filter>
</ClCompile>
<ClCompile Include="$(MSBuildThisFileDirectory)wiInput_BindLua.cpp">
<Filter>ENGINE\Scripting\LuaBindings</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Image Include="$(MSBuildThisFileDirectory)..\Documentation\orderofexecution.png">
File diff suppressed because it is too large Load Diff
+42 -38
View File
@@ -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 <dinput.h>
#pragma comment(lib,"dinput8.lib")
#else
#include <Windows.h>
#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
};
};
}
+2 -2
View File
@@ -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;
+1 -1
View File
@@ -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(); });
@@ -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<int>(button)) | KEY_TOGGLE(static_cast<int>(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())
+110
View File
@@ -0,0 +1,110 @@
#pragma once
#include "CommonInclude.h"
#include <vector>
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<Touch>& getTouches();
};
-78
View File
@@ -1,78 +0,0 @@
#pragma once
#include "CommonInclude.h"
#include <vector>
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<Touch>& getTouches();
};
-278
View File
@@ -1,278 +0,0 @@
#include "wiInputManager_BindLua.h"
#include "Vector_BindLua.h"
const char wiInputManager_BindLua::className[] = "InputManager";
Luna<wiInputManager_BindLua>::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<wiInputManager_BindLua>::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<Vector_BindLua>::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<Vector_BindLua>::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<Vector_BindLua>::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<Touch_BindLua>::push(L, new Touch_BindLua(touch));
}
return (int)touches.size();
}
void wiInputManager_BindLua::Bind()
{
static bool initialized = false;
if (!initialized)
{
initialized = true;
Luna<wiInputManager_BindLua>::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<Touch_BindLua>::FunctionType Touch_BindLua::methods[] = {
lunamethod(Touch_BindLua, GetState),
lunamethod(Touch_BindLua, GetPos),
{ NULL, NULL }
};
Luna<Touch_BindLua>::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<Vector_BindLua>::push(L, new Vector_BindLua(XMLoadFloat2(&touch.pos)));
return 1;
}
void Touch_BindLua::Bind()
{
static bool initialized = false;
if (!initialized)
{
initialized = true;
Luna<Touch_BindLua>::Register(wiLua::GetGlobal()->GetLuaState());
}
}
+260
View File
@@ -0,0 +1,260 @@
#include "wiInput_BindLua.h"
#include "Vector_BindLua.h"
const char wiInput_BindLua::className[] = "Input";
Luna<wiInput_BindLua>::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<wiInput_BindLua>::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<Vector_BindLua>::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<Vector_BindLua>::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<Vector_BindLua>::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<Touch_BindLua>::push(L, new Touch_BindLua(touch));
}
return (int)touches.size();
}
void wiInput_BindLua::Bind()
{
static bool initialized = false;
if (!initialized)
{
initialized = true;
Luna<wiInput_BindLua>::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<Touch_BindLua>::FunctionType Touch_BindLua::methods[] = {
lunamethod(Touch_BindLua, GetState),
lunamethod(Touch_BindLua, GetPos),
{ NULL, NULL }
};
Luna<Touch_BindLua>::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<Vector_BindLua>::push(L, new Vector_BindLua(XMLoadFloat2(&touch.pos)));
return 1;
}
void Touch_BindLua::Bind()
{
static bool initialized = false;
if (!initialized)
{
initialized = true;
Luna<Touch_BindLua>::Register(wiLua::GetGlobal()->GetLuaState());
}
}
@@ -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<wiInputManager_BindLua>::FunctionType methods[];
static Luna<wiInputManager_BindLua>::PropertyType properties[];
static Luna<wiInput_BindLua>::FunctionType methods[];
static Luna<wiInput_BindLua>::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<Touch_BindLua>::FunctionType methods[];
static Luna<Touch_BindLua>::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);
+2 -2
View File
@@ -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();
+29 -25
View File
@@ -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
//};
}
+1 -1
View File
@@ -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;
+17 -17
View File
@@ -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)
{
+50 -43
View File
@@ -2,54 +2,61 @@
#include "wiXInput.h"
wiXInput::wiXInput()
#pragma comment(lib,"xinput.lib")
namespace wiInput
{
g_bDeadZoneOn = true;
for(int i=0;i<MAX_CONTROLLERS;++i){
controllers[i] = CONTROLLER_STATE();
controllers[i].bConnected=false;
wiXInput::wiXInput()
{
g_bDeadZoneOn = true;
for (int i = 0; i < MAX_CONTROLLERS; ++i) {
controllers[i] = CONTROLLER_STATE();
controllers[i].bConnected = false;
}
}
wiXInput::~wiXInput()
{
CleanUp();
}
}
wiXInput::~wiXInput()
{
CleanUp();
}
HRESULT wiXInput::UpdateControllerState()
{
DWORD dwResult = 0;
for( DWORD i = 0; i < MAX_CONTROLLERS; i++ )
{
// Simply get the state of the controller from XInput.
dwResult = XInputGetState( i, &controllers[i].state );
HRESULT wiXInput::UpdateControllerState()
{
DWORD dwResult = 0;
for (DWORD i = 0; i < MAX_CONTROLLERS; i++)
{
// Simply get the state of the controller from XInput.
dwResult = XInputGetState(i, &controllers[i].state);
if( dwResult == ERROR_SUCCESS )
controllers[i].bConnected = true;
else
controllers[i].bConnected = false;
}
if (dwResult == ERROR_SUCCESS)
controllers[i].bConnected = true;
else
controllers[i].bConnected = false;
}
return S_OK;
}
return S_OK;
}
DWORD wiXInput::GetButtons(SHORT newPlayerIndex)
{
if(controllers[newPlayerIndex].bConnected)
return controllers[newPlayerIndex].state.Gamepad.wButtons;
return 0;
}
DWORD wiXInput::GetDirections(short newPlayerIndex){
if(controllers[newPlayerIndex].bConnected)
return controllers[newPlayerIndex].state.Gamepad.wButtons;
return 0;
}
bool wiXInput::isButtonDown(short newPlayerIndex, DWORD checkforButton){
if(controllers[newPlayerIndex].bConnected)
return (controllers[newPlayerIndex].state.Gamepad.wButtons & checkforButton) != 0;
return false;
}
DWORD wiXInput::GetButtons(SHORT newPlayerIndex)
{
if (controllers[newPlayerIndex].bConnected)
return controllers[newPlayerIndex].state.Gamepad.wButtons;
return 0;
}
DWORD wiXInput::GetDirections(short newPlayerIndex) {
if (controllers[newPlayerIndex].bConnected)
return controllers[newPlayerIndex].state.Gamepad.wButtons;
return 0;
}
bool wiXInput::isButtonDown(short newPlayerIndex, DWORD checkforButton) {
if (controllers[newPlayerIndex].bConnected)
return (controllers[newPlayerIndex].state.Gamepad.wButtons & checkforButton) != 0;
return false;
}
void wiXInput::CleanUp()
{
}
void wiXInput::CleanUp()
{
}
}
+24 -24
View File
@@ -4,34 +4,34 @@
// TODO REFACTOR
#pragma comment(lib,"xinput.lib")
namespace wiInput
{
#define MAX_CONTROLLERS 4 // XInput handles up to 4 controllers
#define INPUT_DEADZONE ( 0.24f * FLOAT(0x7FFF) ) // Default to 24% of the +/- 32767 range. This is a reasonable default value but can be altered if needed.
class wiXInput
{
private:
struct CONTROLLER_STATE
class wiXInput
{
XINPUT_STATE state;
bool bConnected;
private:
struct CONTROLLER_STATE
{
XINPUT_STATE state;
bool bConnected;
};
public:
wiXInput();
~wiXInput();
HRESULT UpdateControllerState();
DWORD GetButtons(SHORT);
DWORD GetDirections(short);
bool isButtonDown(short, DWORD);
void CleanUp();
CONTROLLER_STATE controllers[MAX_CONTROLLERS];
WCHAR g_szMessage[4][1024];
bool g_bDeadZoneOn;
};
public:
wiXInput();
~wiXInput();
HRESULT UpdateControllerState();
DWORD GetButtons(SHORT);
DWORD GetDirections(short);
bool isButtonDown(short,DWORD);
void CleanUp();
CONTROLLER_STATE controllers[MAX_CONTROLLERS];
WCHAR g_szMessage[4][1024];
bool g_bDeadZoneOn;
};
}
+1 -1
View File
@@ -39,7 +39,7 @@ end
runProcess(function()
while true do
if(input.Press(VK_F8)) then
if(input.Press(KEYBOARD_BUTTON_F8)) then
ToggleCameraAnimation()
end
if(play) then
+1 -1
View File
@@ -39,7 +39,7 @@ end
runProcess(function()
while true do
if(input.Press(VK_F8)) then
if(input.Press(KEYBOARD_BUTTON_F8)) then
ToggleCameraAnimation()
end
if(play) then
+8 -8
View File
@@ -95,17 +95,17 @@ Character = {
if(self.state==self.states.STAND) then
local lookDir = Vector()
if(input.Down(VK_LEFT) or input.Down(string.byte('A'))) then
if(input.Down(KEYBOARD_BUTTON_LEFT) or input.Down(string.byte('A'))) then
lookDir = lookDir:Add( Vector(-1) )
end
if(input.Down(VK_RIGHT) or input.Down(string.byte('D'))) then
if(input.Down(KEYBOARD_BUTTON_RIGHT) or input.Down(string.byte('D'))) then
lookDir = lookDir:Add( Vector(1) )
end
if(input.Down(VK_UP) or input.Down(string.byte('W'))) then
if(input.Down(KEYBOARD_BUTTON_UP) or input.Down(string.byte('W'))) then
lookDir = lookDir:Add( Vector(0,0,1) )
end
if(input.Down(VK_DOWN) or input.Down(string.byte('S'))) then
if(input.Down(KEYBOARD_BUTTON_DOWN) or input.Down(string.byte('S'))) then
lookDir = lookDir:Add( Vector(0,0,-1) )
end
@@ -113,7 +113,7 @@ Character = {
lookDir = vector.Add(lookDir, Vector(analog.GetX(), 0, analog.GetY()))
if(lookDir:Length()>0) 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")
+11 -11
View File
@@ -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")