Skip to content

Commit 040c039

Browse files
committed
-
1 parent a07f0e4 commit 040c039

7 files changed

Lines changed: 42 additions & 2 deletions

src/Carnage3D.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ copy "$(SDKDIR)\glfw\lib-vc2015\glfw3.dll" "$(TargetDir)"</Command>
158158
<ClInclude Include="AiCharacterController.h" />
159159
<ClInclude Include="aux_math.h" />
160160
<ClInclude Include="Convert.h" />
161+
<ClInclude Include="InputActionsMapping.h" />
161162
<ClInclude Include="macro.h" />
162163
<ClInclude Include="MemoryManager.h" />
163164
<ClInclude Include="mem_allocators.h" />
@@ -242,6 +243,7 @@ copy "$(SDKDIR)\glfw\lib-vc2015\glfw3.dll" "$(TargetDir)"</Command>
242243
<ClCompile Include="GameObjectsManager.cpp" />
243244
<ClCompile Include="GpuBufferTexture.cpp" />
244245
<ClCompile Include="CharacterController.cpp" />
246+
<ClCompile Include="InputActionsMapping.cpp" />
245247
<ClCompile Include="MemoryManager.cpp" />
246248
<ClCompile Include="mem_allocators.cpp" />
247249
<ClCompile Include="path_utils.cpp" />

src/Carnage3D.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@
304304
<ClInclude Include="TrimeshBuffer.h">
305305
<Filter>Game\Rendering</Filter>
306306
</ClInclude>
307+
<ClInclude Include="InputActionsMapping.h">
308+
<Filter>Game</Filter>
309+
</ClInclude>
307310
</ItemGroup>
308311
<ItemGroup>
309312
<ClCompile Include="stdafx.cpp">
@@ -473,6 +476,9 @@
473476
<ClCompile Include="TrimeshBuffer.cpp">
474477
<Filter>Game\Rendering</Filter>
475478
</ClCompile>
479+
<ClCompile Include="InputActionsMapping.cpp">
480+
<Filter>Game</Filter>
481+
</ClCompile>
476482
</ItemGroup>
477483
<ItemGroup>
478484
<None Include="..\gamedata\config\sys_config.json.default">

src/GraphicsDevice.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111

1212
GraphicsDevice gGraphicsDevice;
1313

14+
#if (GLFW_VERSION_MAJOR == 3) && (GLFW_VERSION_MINOR < 3)
15+
#else
16+
#define GLFW_SUPPORTS_GAMEPADS
17+
#endif
18+
1419
//////////////////////////////////////////////////////////////////////////
1520

1621
// glfw to native input mapping
@@ -86,6 +91,7 @@ static eMButton GlfwMouseButtonToNative(int mbutton)
8691

8792
static eGamepadButton GlfwGamepadButtonToNative(int gpbutton)
8893
{
94+
#ifdef GLFW_SUPPORTS_GAMEPADS
8995
switch(gpbutton)
9096
{
9197
case GLFW_GAMEPAD_BUTTON_A: return eGamepadButton_A;
@@ -104,6 +110,7 @@ static eGamepadButton GlfwGamepadButtonToNative(int gpbutton)
104110
case GLFW_GAMEPAD_BUTTON_DPAD_DOWN: return eGamepadButton_DPAD_Down;
105111
case GLFW_GAMEPAD_BUTTON_DPAD_LEFT: return eGamepadButton_DPAD_Left;
106112
};
113+
#endif
107114
return eGamepadButton_null;
108115
}
109116

@@ -233,14 +240,15 @@ bool GraphicsDevice::Initialize(int screensizex, int screensizey, bool fullscree
233240
};
234241
gSystem.HandleEvent(ev);
235242
});
243+
#ifdef GLFW_SUPPORTS_GAMEPADS
236244
::glfwSetJoystickCallback([](int gamepad, int gamepadStatus)
237245
{
238246
if (gamepad < MAX_GAMEPADS)
239247
{
240248
gInputs.SetGamepadPresent(gamepad, (gamepadStatus == GLFW_CONNECTED));
241249
}
242250
});
243-
251+
#endif
244252
// setup opengl extensions
245253
if (!InitializeOGLExtensions())
246254
{
@@ -298,12 +306,13 @@ bool GraphicsDevice::Initialize(int screensizex, int screensizey, bool fullscree
298306
EnableVSync(vsync);
299307

300308
// init gamepads
309+
#ifdef GLFW_SUPPORTS_GAMEPADS
301310
for (int icurr = 0; icurr < MAX_GAMEPADS; ++icurr)
302311
{
303312
bool isGamepad = ::glfwJoystickIsGamepad(icurr) == GLFW_TRUE;
304313
gInputs.SetGamepadPresent(icurr, isGamepad);
305314
}
306-
315+
#endif
307316
return true;
308317
}
309318

@@ -783,6 +792,7 @@ void GraphicsDevice::Present()
783792

784793
void GraphicsDevice::ProcessGamepadsInputs()
785794
{
795+
#ifdef GLFW_SUPPORTS_GAMEPADS
786796
GLFWgamepadstate gamepadstate;
787797

788798
for (int icurr = 0; icurr < MAX_GAMEPADS; ++icurr)
@@ -823,6 +833,7 @@ void GraphicsDevice::ProcessGamepadsInputs()
823833
gSystem.HandleEvent(inputEvent);
824834
}
825835
}
836+
#endif
826837
}
827838

828839
void GraphicsDevice::SetViewportRect(const Rect2D& sourceRectangle)

src/InputActionsMapping.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include "stdafx.h"
2+
#include "InputActionsMapping.h"

src/InputActionsMapping.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
3+
#include "GameDefs.h"
4+
5+
class InputActionsMapping
6+
{
7+
public:
8+
9+
public:
10+
eInputControllerType mControllerType = eInputControllerType_None;
11+
// keyboard mapping
12+
ePedestrianAction mKeycodesToActions[eKeycode_COUNT];
13+
eKeycode mActionsToKeycodes[ePedestrianAction_COUNT];
14+
// gamepad mapping
15+
ePedestrianAction mGamepadButtonsToActions[eGamepadButton_COUNT];
16+
eGamepadButton mActionsToGamepadButtons[ePedestrianAction_COUNT];
17+
};

src/Inputs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ decl_enum_strings(eGamepadButton);
116116
// input controller
117117
enum eInputControllerType
118118
{
119+
eInputControllerType_None,
119120
eInputControllerType_Keyboard,
120121
eInputControllerType_Gamepad1,
121122
eInputControllerType_Gamepad2,

src/enums_impl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ impl_enum_strings(eGamepadButton)
8989

9090
impl_enum_strings(eInputControllerType)
9191
{
92+
{eInputControllerType_None, "None"},
9293
{eInputControllerType_Keyboard, "Keyboard"},
9394
{eInputControllerType_Gamepad1, "Gamepad1"},
9495
{eInputControllerType_Gamepad2, "Gamepad2"},

0 commit comments

Comments
 (0)