Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions platforms/input/xinput/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ project(nbcraft-input-xinput)
# Build
add_library(nbcraft-input STATIC
GameControllerHandler_xinput.cpp
XInput.cpp
)

target_link_libraries(nbcraft-input
Expand Down
23 changes: 13 additions & 10 deletions platforms/input/xinput/GameControllerHandler_xinput.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
#ifdef _XBOX
#include <xtl.h>
#else
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif

#include "XInput.hpp"
#include "GameControllerHandler_xinput.hpp"
#include "client/player/input/Keyboard.hpp"
#include "client/player/input/GameControllerManager.hpp"
Expand All @@ -16,6 +10,12 @@
GameControllerHandler_xinput::GameControllerHandler_xinput()
: GameControllerHandler()
{
XInput::init();

if (!XInput::GetState)
for (DWORD i = 0; i < XUSER_MAX_COUNT; ++i)
m_connectionStates[i] = GameController::STATE_DISCONNECTED;

_initButtonMap();

// need to have the connection states ready for AppPlatform->hasGamepad()
Expand Down Expand Up @@ -84,10 +84,13 @@ void GameControllerHandler_xinput::_processMotion(GameController::ID controllerI

void GameControllerHandler_xinput::refresh()
{
if (!XInput::GetState)
return;

// Ingest our input "queue"
for (DWORD i = 0; i < XUSER_MAX_COUNT; i++)
for (DWORD i = 0; i < XUSER_MAX_COUNT; ++i)
{
DWORD result = XInputGetState(i, &m_inputStates.m_inputState[i]);
DWORD result = XInput::GetState(i, &m_inputStates.m_inputState[i]);
m_connectionStates[i] = result == ERROR_SUCCESS ? GameController::STATE_CONNECTED : GameController::STATE_DISCONNECTED;
}

Expand Down Expand Up @@ -140,4 +143,4 @@ void GameControllerHandler_xinput::normalizeAxes(Vec2& io, float deadzone) const
{
io = Vec2::ZERO;
}*/
}
}
2 changes: 1 addition & 1 deletion platforms/input/xinput/GameControllerHandler_xinput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ class GameControllerHandler_xinput : public GameControllerHandler

protected:
InputState_xinput m_inputStates;
};
};
3 changes: 3 additions & 0 deletions platforms/input/xinput/XInput.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "XInput.hpp"

DWORD (WINAPI *XInput::GetState)(DWORD, XINPUT_STATE *) = nullptr;
36 changes: 36 additions & 0 deletions platforms/input/xinput/XInput.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once

#ifdef _XBOX
#include <xtl.h>
#else
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <xinput.h>
#endif

#include "common/Logger.hpp"

class XInput
{
public:

static DWORD (WINAPI *GetState)(DWORD, XINPUT_STATE *);

static void init(void)
{
#ifdef _XBOX
GetState = ::XInputGetState;
#else
HMODULE module = LoadLibrary("XINPUT1_4.DLL");
if (!module) module = LoadLibrary("XINPUT1_3.DLL");
if (!module) module = LoadLibrary("XINPUT1_2.DLL");
if (!module) module = LoadLibrary("XINPUT1_1.DLL");
if (!module) module = LoadLibrary("XINPUT9_1_0.DLL");
if (module)
GetState = (DWORD (WINAPI *)(DWORD, XINPUT_STATE *))GetProcAddress(module, "XInputGetState");
if (!GetState)
LOG_W("Could not find xinput driver, xinput controllers will be disabled.");
#endif
}

};
8 changes: 7 additions & 1 deletion projects/visual-studio/Input.XInput/Input.XInput.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@
<ItemGroup>
<ClInclude Include="$(MC_ROOT)\platforms\input\xinput\GameControllerHandler_xinput.hpp" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="$(MC_ROOT)\platforms\input\xinput\XInput.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MC_ROOT)\platforms\input\xinput\XInput.hpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@
<ClCompile Include="$(MC_ROOT)\platforms\input\xinput\GameControllerHandler_xinput.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\platforms\input\xinput\XInput.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MC_ROOT)\platforms\input\xinput\GameControllerHandler_xinput.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\platforms\input\xinput\XInput.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
</Project>
Loading