summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2023-04-25 19:35:10 -0400
committerrealtradam <[email protected]>2023-04-25 19:35:10 -0400
commite5ad114afa00ed98908c3b3bacadf30c742cabd6 (patch)
tree18aebb82716bc38436a9287e65970d6f37e88c97
parent86a8351bf8318dc69ba89ac11d6f0b8baf70f7c1 (diff)
downloadRodeoKit-e5ad114afa00ed98908c3b3bacadf30c742cabd6.tar.gz
RodeoKit-e5ad114afa00ed98908c3b3bacadf30c742cabd6.zip
added controller buttons to input system
-rw-r--r--include/rodeo/input.h6
-rw-r--r--include/rodeo/input_t.h34
-rw-r--r--src/input/rodeo_input.c99
3 files changed, 115 insertions, 24 deletions
diff --git a/include/rodeo/input.h b/include/rodeo/input.h
index 9f94119..690d2d1 100644
--- a/include/rodeo/input.h
+++ b/include/rodeo/input.h
@@ -40,6 +40,12 @@ rodeo_input_command_register_binary_scancode(
);
bool
+rodeo_input_command_register_binary_controllerButton(
+ rodeo_input_command_t *input_command,
+ rodeo_input_binary_controllerButton_t button
+);
+
+bool
rodeo_input_command_register_binary_mouseButton(
rodeo_input_command_t *input_command,
rodeo_input_binary_mouseButton_t mouse_button
diff --git a/include/rodeo/input_t.h b/include/rodeo/input_t.h
index cb3163e..0d57942 100644
--- a/include/rodeo/input_t.h
+++ b/include/rodeo/input_t.h
@@ -720,6 +720,8 @@ typedef enum
}
rodeo_input_binary_keycode_t;
+
+
/**
* \brief Enumeration of valid key mods (possibly OR'd together).
*/
@@ -761,6 +763,33 @@ enum
}
rodeo_input_binary_mouseButton_t;
+typedef enum
+{
+ rodeo_input_binary_controllerButton_INVALID = -1,
+ rodeo_input_binary_controllerButton_A,
+ rodeo_input_binary_controllerButton_B,
+ rodeo_input_binary_controllerButton_X,
+ rodeo_input_binary_controllerButton_Y,
+ rodeo_input_binary_controllerButton_BACK,
+ rodeo_input_binary_controllerButton_GUIDE,
+ rodeo_input_binary_controllerButton_START,
+ rodeo_input_binary_controllerButton_LEFTSTICK,
+ rodeo_input_binary_controllerButton_RIGHTSTICK,
+ rodeo_input_binary_controllerButton_LEFTSHOULDER,
+ rodeo_input_binary_controllerButton_RIGHTSHOULDER,
+ rodeo_input_binary_controllerButton_DPAD_UP,
+ rodeo_input_binary_controllerButton_DPAD_DOWN,
+ rodeo_input_binary_controllerButton_DPAD_LEFT,
+ rodeo_input_binary_controllerButton_DPAD_RIGHT,
+ rodeo_input_binary_controllerButton_MISC1, /* Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button, Amazon Luna microphone button */
+ rodeo_input_binary_controllerButton_PADDLE1, /* Xbox Elite paddle P1 (upper left, facing the back) */
+ rodeo_input_binary_controllerButton_PADDLE2, /* Xbox Elite paddle P3 (upper right, facing the back) */
+ rodeo_input_binary_controllerButton_PADDLE3, /* Xbox Elite paddle P2 (lower left, facing the back) */
+ rodeo_input_binary_controllerButton_PADDLE4, /* Xbox Elite paddle P4 (lower right, facing the back) */
+ rodeo_input_binary_controllerButton_TOUCHPAD, /* PS4/PS5 touchpad button */
+ rodeo_input_binary_controllerButton_MAX
+} rodeo_input_binary_controllerButton_t;
+
// - SDL code end -
typedef
@@ -903,6 +932,10 @@ void*
#define i_tag input_unboundedRange_mouse
#include <stc/cset.h>
+#define i_val rodeo_input_binary_controllerButton_t
+#define i_tag input_binary_controllerButton
+#include <stc/cset.h>
+
typedef
struct
{
@@ -914,6 +947,7 @@ struct
{
cset_input_binary_scancodes scancodes;
cset_input_binary_mouseButtons mouse_buttons;
+ cset_input_binary_controllerButton controller_buttons;
}
binary;
diff --git a/src/input/rodeo_input.c b/src/input/rodeo_input.c
index ac7f5e2..3d46546 100644
--- a/src/input/rodeo_input.c
+++ b/src/input/rodeo_input.c
@@ -192,22 +192,41 @@ rodeo_input_events_poll(void)
}
}
break;
- case SDL_CONTROLLERDEVICEADDED:
- {
- irodeo_input_controller_register(event.cdevice.which);
- }
- break;
- case SDL_CONTROLLERDEVICEREMOVED:
- {
- irodeo_input_controller_unregister(event.cdevice.which);
- }
- break;
- case SDL_CONTROLLERDEVICEREMAPPED:
+ case SDL_CONTROLLERBUTTONDOWN:
+ case SDL_CONTROLLERBUTTONUP:
{
- rodeo_log(
- rodeo_logLevel_warning,
- "SDL Controller device was remapped"
- );
+ c_foreach(i, cset_input_scene, istate.active_scenes)
+ {
+ rodeo_input_scene_t *scene = *i.ref;
+ c_foreach(j, cset_input_commands, scene->commands)
+ {
+ rodeo_input_command_t *command = *j.ref;
+ const cset_input_binary_controllerButton_value *value = cset_input_binary_controllerButton_get(
+ &command->binary.controller_buttons,
+ (rodeo_input_binary_controllerButton_t)event.cbutton.button
+ );
+
+ if(value == NULL)
+ {
+ continue;
+ }
+ else
+ {
+ rodeo_input_any_state_t input_state = {
+ .data.binary_state = event.cbutton.state,
+ .type = rodeo_input_type_Binary
+ };
+ c_foreach(
+ k,
+ cset_input_callback_functions,
+ command->callbacks
+ )
+ {
+ (**k.ref)(&input_state, NULL);
+ }
+ }
+ }
+ }
}
break;
case SDL_CONTROLLERAXISMOTION:
@@ -239,15 +258,23 @@ rodeo_input_events_poll(void)
}
}
break;
- case SDL_CONTROLLERBUTTONDOWN:
- case SDL_CONTROLLERBUTTONUP:
- case SDL_JOYBUTTONDOWN:
- case SDL_JOYBUTTONUP:
- case SDL_JOYAXISMOTION:
- //rodeo_log(
- // rodeo_logLevel_info,
- // "controller event"
- //);
+ case SDL_CONTROLLERDEVICEADDED:
+ {
+ irodeo_input_controller_register(event.cdevice.which);
+ }
+ break;
+ case SDL_CONTROLLERDEVICEREMOVED:
+ {
+ irodeo_input_controller_unregister(event.cdevice.which);
+ }
+ break;
+ case SDL_CONTROLLERDEVICEREMAPPED:
+ {
+ rodeo_log(
+ rodeo_logLevel_warning,
+ "SDL Controller device was remapped"
+ );
+ }
break;
}
}
@@ -360,6 +387,30 @@ rodeo_input_command_register_binary_scancode(
}
bool
+rodeo_input_command_register_binary_controllerButton(
+ rodeo_input_command_t *input_command,
+ rodeo_input_binary_controllerButton_t button
+)
+{
+ if((rodeo_input_type_Binary & input_command->valid_types) == 0)
+ {
+ rodeo_log(
+ rodeo_logLevel_error,
+ "Attempting to register input type which is invalid for this input command, failed to do so"
+ );
+ return false;
+ }
+ else
+ {
+ cset_input_binary_controllerButton_insert(
+ &input_command->binary.controller_buttons,
+ button
+ );
+ return true;
+ }
+}
+
+bool
rodeo_input_command_register_binary_mouseButton(
rodeo_input_command_t *input_command,
rodeo_input_binary_mouseButton_t mouse_button