-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added input management for mouse and keyboard, basic camera controls,…
… update texture function for components, and a cleanup function.
- Loading branch information
Showing
10 changed files
with
213 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
**/build | ||
**/.vscode | ||
**/.exe | ||
**/.exe | ||
**/cmake-build-debug | ||
**/log.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,114 @@ | ||
#include "Input.h" | ||
#include "debugmalloc.h" | ||
|
||
void input_handle_event(SDL_Event &e) { | ||
|
||
} | ||
ButtonState buttons[SDL_NUM_SCANCODES]; | ||
ButtonState mouseButtons[5]; | ||
uint8_t mouseClicks[5]; | ||
|
||
int mouseDeltaX = 0, mouseDeltaY = 0; | ||
int mouseX = 0, mouseY = 0; | ||
int mouseWheelX = 0, mouseWheelY = 0; | ||
|
||
void input_reset_events() { | ||
for (int i = 0; i < SDL_NUM_SCANCODES; i++) { | ||
buttons[i].isPressed = false; | ||
buttons[i].isReleased = false; | ||
} | ||
|
||
for (int i = 0; i < 5; i++) { | ||
mouseButtons[i].isReleased = false; | ||
mouseButtons[i].isPressed = false; | ||
mouseClicks[i] = 0; | ||
} | ||
mouseDeltaX = 0; | ||
mouseDeltaY = 0; | ||
mouseWheelX = 0; | ||
mouseWheelY = 0; | ||
} | ||
|
||
void input_handle_event(SDL_Event *e) { | ||
if (e->type == SDL_KEYDOWN) { | ||
if (!buttons[e->key.keysym.scancode].isHeld) { | ||
buttons[e->key.keysym.scancode].isHeld = true; | ||
buttons[e->key.keysym.scancode].isPressed = true; | ||
} | ||
} else if (e->type == SDL_KEYUP) { | ||
if (buttons[e->key.keysym.scancode].isHeld) { | ||
buttons[e->key.keysym.scancode].isHeld = false; | ||
buttons[e->key.keysym.scancode].isReleased = true; | ||
} | ||
} | ||
switch (e->type) { | ||
case SDL_KEYDOWN: | ||
if (!buttons[e->key.keysym.scancode].isHeld) { | ||
buttons[e->key.keysym.scancode].isHeld = true; | ||
buttons[e->key.keysym.scancode].isPressed = true; | ||
} | ||
break; | ||
case SDL_KEYUP: | ||
if (buttons[e->key.keysym.scancode].isHeld) { | ||
buttons[e->key.keysym.scancode].isHeld = false; | ||
buttons[e->key.keysym.scancode].isReleased = true; | ||
} | ||
break; | ||
case SDL_MOUSEBUTTONDOWN: | ||
if (!mouseButtons[e->button.button].isHeld) { | ||
mouseButtons[e->button.button].isHeld = true; | ||
mouseButtons[e->button.button].isPressed = true; | ||
mouseClicks[e->button.button] = e->button.clicks; | ||
} | ||
break; | ||
case SDL_MOUSEBUTTONUP: | ||
if (mouseButtons[e->button.button].isHeld) { | ||
mouseButtons[e->button.button].isHeld = false; | ||
mouseButtons[e->button.button].isReleased = true; | ||
} | ||
break; | ||
case SDL_MOUSEMOTION: | ||
mouseDeltaX = e->motion.xrel; | ||
mouseDeltaY = e->motion.yrel; | ||
mouseX = e->motion.x; | ||
mouseY = e->motion.y; | ||
break; | ||
case SDL_MOUSEWHEEL: | ||
mouseWheelX = e->wheel.x; | ||
mouseWheelY = e->wheel.y; | ||
if (e->wheel.direction == SDL_MOUSEWHEEL_FLIPPED) { | ||
mouseWheelX *= -1; | ||
mouseWheelY *= -1; | ||
} | ||
break; | ||
} | ||
} | ||
|
||
ButtonState input_get_key(SDL_Scancode code) { | ||
return buttons[code]; | ||
} | ||
|
||
ButtonState input_get_mouse_button(int id) { | ||
return mouseButtons[id]; | ||
} | ||
|
||
int input_get_mouse_x() { | ||
return mouseX; | ||
} | ||
|
||
int input_get_mouse_y() { | ||
return mouseY; | ||
} | ||
|
||
int input_get_mouse_delta_x() { | ||
return mouseDeltaX; | ||
} | ||
|
||
int input_get_mouse_delta_y() { | ||
return mouseDeltaY; | ||
} | ||
|
||
int input_get_mouse_wheel_x() { | ||
return mouseWheelX; | ||
} | ||
|
||
int input_get_mouse_wheel_y() { | ||
return mouseWheelY; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters