Skip to content

Commit 6edada3

Browse files
committed
-
1 parent ffbf597 commit 6edada3

8 files changed

Lines changed: 295 additions & 137 deletions

src/CarnageGame.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,25 +104,25 @@ void CarnageGame::InputEvent(KeyInputEvent& inputEvent)
104104
if (inputEvent.mConsumed)
105105
return;
106106

107-
if (inputEvent.mKeycode == KEYCODE_TILDE && inputEvent.mPressed) // show debug console
107+
if (inputEvent.mKeycode == eKeycode_TILDE && inputEvent.mPressed) // show debug console
108108
{
109109
gDebugConsoleWindow.mWindowShown = !gDebugConsoleWindow.mWindowShown;
110110
return;
111111
}
112-
if (inputEvent.mKeycode == KEYCODE_F3 && inputEvent.mPressed)
112+
if (inputEvent.mKeycode == eKeycode_F3 && inputEvent.mPressed)
113113
{
114114
gRenderManager.ReloadRenderPrograms();
115115
return;
116116
}
117117

118118
mHumanController.InputEvent(inputEvent);
119119

120-
if (inputEvent.mKeycode == KEYCODE_ESCAPE && inputEvent.mPressed)
120+
if (inputEvent.mKeycode == eKeycode_ESCAPE && inputEvent.mPressed)
121121
{
122122
gSystem.QuitRequest();
123123
}
124124

125-
if (inputEvent.mKeycode == KEYCODE_C && inputEvent.mPressed)
125+
if (inputEvent.mKeycode == eKeycode_C && inputEvent.mPressed)
126126
{
127127
gGameCheatsWindow.mWindowShown = !gGameCheatsWindow.mWindowShown;
128128
}

src/FreeLookCameraController.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,22 @@ void FreeLookCameraController::InputEvent(KeyInputEvent& inputEvent)
7474
if (inputEvent.mConsumed)
7575
return;
7676

77-
if (inputEvent.mKeycode == KEYCODE_W)
77+
if (inputEvent.mKeycode == eKeycode_W)
7878
{
7979
mMoveForward = inputEvent.mPressed;
8080
}
8181

82-
if (inputEvent.mKeycode == KEYCODE_S)
82+
if (inputEvent.mKeycode == eKeycode_S)
8383
{
8484
mMoveBackward = inputEvent.mPressed;
8585
}
8686

87-
if (inputEvent.mKeycode == KEYCODE_D)
87+
if (inputEvent.mKeycode == eKeycode_D)
8888
{
8989
mMoveRight = inputEvent.mPressed;
9090
}
9191

92-
if (inputEvent.mKeycode == KEYCODE_A)
92+
if (inputEvent.mKeycode == eKeycode_A)
9393
{
9494
mMoveLeft = inputEvent.mPressed;
9595
}
@@ -100,7 +100,7 @@ void FreeLookCameraController::InputEvent(MouseButtonInputEvent& inputEvent)
100100
if (inputEvent.mConsumed)
101101
return;
102102

103-
if (inputEvent.mButton == MBUTTON_LEFT)
103+
if (inputEvent.mButton == eMButton_LEFT)
104104
{
105105
mMouseDragCamera = inputEvent.mPressed;
106106
if (mMouseDragCamera)

src/GameDefs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,8 @@ decl_enum_strings(eWeaponType);
699699
// pedestrian basic action
700700
enum ePedestrianAction
701701
{
702-
702+
ePedestrianAction_null, // not an action
703+
703704
ePedestrianAction_TurnLeft,
704705
ePedestrianAction_TurnRight,
705706
ePedestrianAction_Jump,

src/GraphicsDevice.cpp

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,81 @@
1111

1212
GraphicsDevice gGraphicsDevice;
1313

14+
//////////////////////////////////////////////////////////////////////////
15+
16+
// glfw to native input mapping
17+
static eKeycode GlfwKeycodeToNative(int keycode)
18+
{
19+
switch (keycode)
20+
{
21+
case GLFW_KEY_ESCAPE: return eKeycode_ESCAPE;
22+
case GLFW_KEY_SPACE: return eKeycode_SPACE;
23+
case GLFW_KEY_PAGE_UP: return eKeycode_PAGE_UP;
24+
case GLFW_KEY_PAGE_DOWN: return eKeycode_PAGE_DOWN;
25+
case GLFW_KEY_HOME: return eKeycode_HOME;
26+
case GLFW_KEY_END: return eKeycode_END;
27+
case GLFW_KEY_INSERT: return eKeycode_INSERT;
28+
case GLFW_KEY_DELETE: return eKeycode_DELETE;
29+
case GLFW_KEY_RIGHT_CONTROL: return eKeycode_RIGHT_CTRL;
30+
case GLFW_KEY_LEFT_CONTROL: return eKeycode_LEFT_CTRL;
31+
case GLFW_KEY_BACKSPACE: return eKeycode_BACKSPACE;
32+
case GLFW_KEY_ENTER: return eKeycode_ENTER;
33+
case GLFW_KEY_TAB: return eKeycode_TAB;
34+
case GLFW_KEY_GRAVE_ACCENT: return eKeycode_TILDE;
35+
case GLFW_KEY_F1: return eKeycode_F1;
36+
case GLFW_KEY_F2: return eKeycode_F2;
37+
case GLFW_KEY_F3: return eKeycode_F3;
38+
case GLFW_KEY_F4: return eKeycode_F4;
39+
case GLFW_KEY_F5: return eKeycode_F5;
40+
case GLFW_KEY_F6: return eKeycode_F6;
41+
case GLFW_KEY_F7: return eKeycode_F7;
42+
case GLFW_KEY_F8: return eKeycode_F8;
43+
case GLFW_KEY_F9: return eKeycode_F9;
44+
case GLFW_KEY_F10: return eKeycode_F10;
45+
case GLFW_KEY_F11: return eKeycode_F11;
46+
case GLFW_KEY_F12: return eKeycode_F12;
47+
case GLFW_KEY_A: return eKeycode_A;
48+
case GLFW_KEY_C: return eKeycode_C;
49+
case GLFW_KEY_F: return eKeycode_F;
50+
case GLFW_KEY_V: return eKeycode_V;
51+
case GLFW_KEY_X: return eKeycode_X;
52+
case GLFW_KEY_W: return eKeycode_W;
53+
case GLFW_KEY_D: return eKeycode_D;
54+
case GLFW_KEY_S: return eKeycode_S;
55+
case GLFW_KEY_Y: return eKeycode_Y;
56+
case GLFW_KEY_Z: return eKeycode_Z;
57+
case GLFW_KEY_R: return eKeycode_R;
58+
case GLFW_KEY_0: return eKeycode_0;
59+
case GLFW_KEY_1: return eKeycode_1;
60+
case GLFW_KEY_2: return eKeycode_2;
61+
case GLFW_KEY_3: return eKeycode_3;
62+
case GLFW_KEY_4: return eKeycode_4;
63+
case GLFW_KEY_5: return eKeycode_5;
64+
case GLFW_KEY_6: return eKeycode_6;
65+
case GLFW_KEY_7: return eKeycode_7;
66+
case GLFW_KEY_8: return eKeycode_8;
67+
case GLFW_KEY_9: return eKeycode_9;
68+
case GLFW_KEY_LEFT: return eKeycode_LEFT;
69+
case GLFW_KEY_RIGHT: return eKeycode_RIGHT;
70+
case GLFW_KEY_UP: return eKeycode_UP;
71+
case GLFW_KEY_DOWN: return eKeycode_DOWN;
72+
}
73+
return eKeycode_null;
74+
}
75+
76+
static eMButton GlfwMouseButtonToNative(int mbutton)
77+
{
78+
switch (mbutton)
79+
{
80+
case GLFW_MOUSE_BUTTON_LEFT: return eMButton_LEFT;
81+
case GLFW_MOUSE_BUTTON_RIGHT: return eMButton_RIGHT;
82+
case GLFW_MOUSE_BUTTON_MIDDLE: return eMButton_MIDDLE;
83+
}
84+
return eMButton_null;
85+
}
86+
87+
//////////////////////////////////////////////////////////////////////////
88+
1489
GraphicsDevice::GraphicsDevice()
1590
: mCurrentStates()
1691
, mViewportRect()
@@ -90,17 +165,25 @@ bool GraphicsDevice::Initialize(int screensizex, int screensizey, bool fullscree
90165
::glfwMakeContextCurrent(graphicsWindow);
91166
::glfwSetMouseButtonCallback(graphicsWindow, [](GLFWwindow*, int button, int action, int mods)
92167
{
93-
if (action != GLFW_REPEAT)
168+
if (action == GLFW_REPEAT)
169+
return;
170+
171+
eMButton mbuttonNative = GlfwMouseButtonToNative(button);
172+
if (mbuttonNative != eMButton_null)
94173
{
95-
MouseButtonInputEvent ev { button, mods, action == GLFW_PRESS };
174+
MouseButtonInputEvent ev { mbuttonNative, mods, action == GLFW_PRESS };
96175
gSystem.HandleEvent(ev);
97176
}
98177
});
99178
::glfwSetKeyCallback(graphicsWindow, [](GLFWwindow*, int keycode, int scancode, int action, int mods)
100179
{
101-
if (action != GLFW_REPEAT)
180+
if (action == GLFW_REPEAT)
181+
return;
182+
183+
eKeycode keycodeNative = GlfwKeycodeToNative(keycode);
184+
if (keycodeNative != eKeycode_null)
102185
{
103-
KeyInputEvent ev { keycode, scancode, mods, action == GLFW_PRESS };
186+
KeyInputEvent ev { keycodeNative, scancode, mods, action == GLFW_PRESS };
104187
gSystem.HandleEvent(ev);
105188
}
106189
});

src/HumanCharacterController.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ void HumanCharacterController::UpdateFrame(Pedestrian* pedestrian, Timespan delt
1414
void HumanCharacterController::InputEvent(KeyInputEvent& inputEvent)
1515
{
1616
debug_assert(mCharacter);
17-
if (inputEvent.mKeycode == KEYCODE_LEFT)
17+
if (inputEvent.mKeycode == eKeycode_LEFT)
1818
{
1919
if (mCharacter->IsCarPassenger())
2020
{
@@ -27,7 +27,7 @@ void HumanCharacterController::InputEvent(KeyInputEvent& inputEvent)
2727
inputEvent.SetConsumed();
2828
}
2929

30-
if (inputEvent.mKeycode == KEYCODE_RIGHT)
30+
if (inputEvent.mKeycode == eKeycode_RIGHT)
3131
{
3232
if (mCharacter->IsCarPassenger())
3333
{
@@ -40,7 +40,7 @@ void HumanCharacterController::InputEvent(KeyInputEvent& inputEvent)
4040
inputEvent.SetConsumed();
4141
}
4242

43-
if (inputEvent.mKeycode == KEYCODE_UP)
43+
if (inputEvent.mKeycode == eKeycode_UP)
4444
{
4545
if (mCharacter->IsCarPassenger())
4646
{
@@ -53,7 +53,7 @@ void HumanCharacterController::InputEvent(KeyInputEvent& inputEvent)
5353
inputEvent.SetConsumed();
5454
}
5555

56-
if (inputEvent.mKeycode == KEYCODE_DOWN)
56+
if (inputEvent.mKeycode == eKeycode_DOWN)
5757
{
5858
if (mCharacter->IsCarPassenger())
5959
{
@@ -66,7 +66,7 @@ void HumanCharacterController::InputEvent(KeyInputEvent& inputEvent)
6666
inputEvent.SetConsumed();
6767
}
6868

69-
if (inputEvent.mKeycode == KEYCODE_SPACE)
69+
if (inputEvent.mKeycode == eKeycode_SPACE)
7070
{
7171
if (mCharacter->IsCarPassenger())
7272
{
@@ -79,7 +79,7 @@ void HumanCharacterController::InputEvent(KeyInputEvent& inputEvent)
7979
inputEvent.SetConsumed();
8080
}
8181

82-
if (inputEvent.mKeycode == KEYCODE_TAB)
82+
if (inputEvent.mKeycode == eKeycode_TAB)
8383
{
8484
if (mCharacter->IsCarPassenger())
8585
{
@@ -96,31 +96,31 @@ void HumanCharacterController::InputEvent(KeyInputEvent& inputEvent)
9696
inputEvent.SetConsumed();
9797
}
9898

99-
if (inputEvent.mKeycode == KEYCODE_LEFT_CTRL)
99+
if (inputEvent.mKeycode == eKeycode_LEFT_CTRL)
100100
{
101101
mCharacter->mCtlActions[ePedestrianAction_Shoot] = inputEvent.mPressed;
102102
inputEvent.SetConsumed();
103103
}
104104

105-
if (inputEvent.mKeycode == KEYCODE_Z && inputEvent.mPressed)
105+
if (inputEvent.mKeycode == eKeycode_Z && inputEvent.mPressed)
106106
{
107107
SwitchPrevWeapon();
108108
inputEvent.SetConsumed();
109109
}
110110

111-
if (inputEvent.mKeycode == KEYCODE_X && inputEvent.mPressed)
111+
if (inputEvent.mKeycode == eKeycode_X && inputEvent.mPressed)
112112
{
113113
SwitchNextWeapon();
114114
inputEvent.SetConsumed();
115115
}
116116

117-
if (inputEvent.mKeycode == KEYCODE_ENTER && inputEvent.mPressed)
117+
if (inputEvent.mKeycode == eKeycode_ENTER && inputEvent.mPressed)
118118
{
119119
EnterOrExitCar(false);
120120
inputEvent.SetConsumed();
121121
}
122122

123-
if (inputEvent.mKeycode == KEYCODE_F && inputEvent.mPressed)
123+
if (inputEvent.mKeycode == eKeycode_F && inputEvent.mPressed)
124124
{
125125
EnterOrExitCar(true);
126126
inputEvent.SetConsumed();

src/ImGuiManager.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,27 @@ bool ImGuiManager::Initialize()
2323
io.BackendRendererName = "imgui_impl_opengl3";
2424
io.BackendFlags = ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasSetMousePos;
2525
io.ConfigFlags = ImGuiConfigFlags_NavEnableKeyboard | ImGuiConfigFlags_NavEnableSetMousePos;
26-
io.KeyMap[ImGuiKey_Tab] = KEYCODE_TAB;
27-
io.KeyMap[ImGuiKey_LeftArrow] = KEYCODE_LEFT;
28-
io.KeyMap[ImGuiKey_RightArrow] = KEYCODE_RIGHT;
29-
io.KeyMap[ImGuiKey_UpArrow] = KEYCODE_UP;
30-
io.KeyMap[ImGuiKey_DownArrow] = KEYCODE_DOWN;
31-
io.KeyMap[ImGuiKey_PageUp] = KEYCODE_PAGE_UP;
32-
io.KeyMap[ImGuiKey_PageDown] = KEYCODE_PAGE_DOWN;
33-
io.KeyMap[ImGuiKey_Home] = KEYCODE_HOME;
34-
io.KeyMap[ImGuiKey_End] = KEYCODE_END;
35-
io.KeyMap[ImGuiKey_Insert] = KEYCODE_INSERT;
36-
io.KeyMap[ImGuiKey_Delete] = KEYCODE_DELETE;
37-
io.KeyMap[ImGuiKey_Backspace] = KEYCODE_BACKSPACE;
38-
io.KeyMap[ImGuiKey_Space] = KEYCODE_SPACE;
39-
io.KeyMap[ImGuiKey_Enter] = KEYCODE_ENTER;
40-
io.KeyMap[ImGuiKey_Escape] = KEYCODE_ENTER;
41-
io.KeyMap[ImGuiKey_A] = KEYCODE_A;
42-
io.KeyMap[ImGuiKey_C] = KEYCODE_C;
43-
io.KeyMap[ImGuiKey_V] = KEYCODE_V;
44-
io.KeyMap[ImGuiKey_X] = KEYCODE_X;
45-
io.KeyMap[ImGuiKey_Y] = KEYCODE_Y;
46-
io.KeyMap[ImGuiKey_Z] = KEYCODE_Z;
26+
io.KeyMap[ImGuiKey_Tab] = eKeycode_TAB;
27+
io.KeyMap[ImGuiKey_LeftArrow] = eKeycode_LEFT;
28+
io.KeyMap[ImGuiKey_RightArrow] = eKeycode_RIGHT;
29+
io.KeyMap[ImGuiKey_UpArrow] = eKeycode_UP;
30+
io.KeyMap[ImGuiKey_DownArrow] = eKeycode_DOWN;
31+
io.KeyMap[ImGuiKey_PageUp] = eKeycode_PAGE_UP;
32+
io.KeyMap[ImGuiKey_PageDown] = eKeycode_PAGE_DOWN;
33+
io.KeyMap[ImGuiKey_Home] = eKeycode_HOME;
34+
io.KeyMap[ImGuiKey_End] = eKeycode_END;
35+
io.KeyMap[ImGuiKey_Insert] = eKeycode_INSERT;
36+
io.KeyMap[ImGuiKey_Delete] = eKeycode_DELETE;
37+
io.KeyMap[ImGuiKey_Backspace] = eKeycode_BACKSPACE;
38+
io.KeyMap[ImGuiKey_Space] = eKeycode_SPACE;
39+
io.KeyMap[ImGuiKey_Enter] = eKeycode_ENTER;
40+
io.KeyMap[ImGuiKey_Escape] = eKeycode_ENTER;
41+
io.KeyMap[ImGuiKey_A] = eKeycode_A;
42+
io.KeyMap[ImGuiKey_C] = eKeycode_C;
43+
io.KeyMap[ImGuiKey_V] = eKeycode_V;
44+
io.KeyMap[ImGuiKey_X] = eKeycode_X;
45+
io.KeyMap[ImGuiKey_Y] = eKeycode_Y;
46+
io.KeyMap[ImGuiKey_Z] = eKeycode_Z;
4747

4848
SetupStyle(io);
4949

0 commit comments

Comments
 (0)