summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-rw-r--r--Readme.md4
-rw-r--r--include/rodeo.h8
-rw-r--r--include/rodeo/input.h6
-rw-r--r--include/rodeo/input_t.h29
-rw-r--r--src/input/rodeo_input.c76
-rw-r--r--src/rodeo_input.c23
7 files changed, 111 insertions, 36 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fdfa91d..e8865d6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,7 +9,6 @@ add_library(${PROJECT_NAME}
"src/rodeo.c"
"src/rodeo_math.c"
"src/log/rodeo_log.c"
- "src/rodeo_input.c"
"src/input/rodeo_input.c"
)
diff --git a/Readme.md b/Readme.md
index 554888c..5d1566f 100644
--- a/Readme.md
+++ b/Readme.md
@@ -25,12 +25,12 @@ The goal of this style of design approach is to avoid over-thinking of future de
- [x] Callback event-based input system.
- [x] Bind inputs(such as character keys) to function pointers. Once the key is pressed the function is called.
-- [ ] Abstract into "commands" which allows naming, adding functions, adding multiple inputs, and assigning to "scenes" that can be enabled or disabled.
+- [x] Abstract into "commands" which allows adding functions, adding multiple inputs, and assigning to "scenes" that can be enabled or disabled.
- [ ] Implementing further input abstractions by 4 categories:
- [x] Binary (such as keys on a keyboard, or buttons on a controller)
- [ ] Bounded Range (such as the x and y joysticks on a controller)
- [ ] Unbounded Range (such as the x and y mouse delta)
- - [ ] Positional (such as the position of a mouse)
+ - [x] Positional (such as the position of a mouse)
### Logging
diff --git a/include/rodeo.h b/include/rodeo.h
index 2d43ce0..ba47491 100644
--- a/include/rodeo.h
+++ b/include/rodeo.h
@@ -149,11 +149,3 @@ rodeo_frame_limit_set(uint32_t limit);
uint32_t
rodeo_frame_limit_get(void);
-
-/// --- Input ---
-
-int32_t
-rodeo_input_mouse_x_get(void);
-
-int32_t
-rodeo_input_mouse_y_get(void);
diff --git a/include/rodeo/input.h b/include/rodeo/input.h
index 5c7cb1c..41a7849 100644
--- a/include/rodeo/input.h
+++ b/include/rodeo/input.h
@@ -45,6 +45,12 @@ rodeo_input_command_register_binary_mouseButton(
rodeo_input_binary_mouseButton_t mouse_button
);
+bool
+rodeo_input_command_register_positional_mouse(
+ rodeo_input_command_t *input_command,
+ rodeo_input_positional_mouse_t mouse_position
+);
+
// alternative proposed "general" registration methods
//rodeo_input_command_register_binary(cmd, rodeo_input_binary_Scancode, rodeo_input_binary_scancode_Q );
//rodeo_input_command_register_any(cmd, rodeo_input_type_Binary, rodeo_input_binary_Scancode, rodeo_input_binary_scancode_Q );
diff --git a/include/rodeo/input_t.h b/include/rodeo/input_t.h
index 39385da..6013eed 100644
--- a/include/rodeo/input_t.h
+++ b/include/rodeo/input_t.h
@@ -5,6 +5,7 @@
// -- system --
#include <stdbool.h>
+#include <stdint.h>
// - SDL code start -
@@ -765,8 +766,17 @@ rodeo_input_binary_mouseButton_t;
typedef
enum
{
+ rodeo_input_positional_mouse_X = 1,
+ rodeo_input_positional_mouse_Y = 2
+}
+rodeo_input_positional_mouse_t;
+
+typedef
+enum
+{
rodeo_input_type_Invalid = (1 << 0),
- rodeo_input_type_Binary = (1 << 1)
+ rodeo_input_type_Binary = (1 << 1),
+ rodeo_input_type_Positional = (1 << 2),
}
rodeo_input_type_t ;
@@ -788,12 +798,15 @@ enum
}
rodeo_input_binary_state_t;
+typedef int64_t rodeo_input_positional_state_t;
+
typedef
struct
{
union
{
rodeo_input_binary_state_t binary_state;
+ rodeo_input_positional_state_t positional_state;
}
data;
rodeo_input_type_t input_type;
@@ -818,12 +831,17 @@ void
#define i_tag input_binary_mouseButtons
#include <stc/cset.h>
+#define i_val rodeo_input_positional_mouse_t
+#define i_tag input_positional_mouse
+#include <stc/cset.h>
+
typedef
struct
{
uint32_t valid_types; // rodeo_input_type_t
- //rodeo_input_callback_function *callback;
+
cset_input_callback_functions callbacks;
+
// binary
struct
{
@@ -831,6 +849,13 @@ struct
cset_input_binary_mouseButtons mouse_buttons;
}
binary;
+
+ // unbounded range
+ struct
+ {
+ cset_input_positional_mouse mouse_position;
+ }
+ unbounded_range;
}
rodeo_input_command_t;
diff --git a/src/input/rodeo_input.c b/src/input/rodeo_input.c
index 02144dc..a6edfbb 100644
--- a/src/input/rodeo_input.c
+++ b/src/input/rodeo_input.c
@@ -99,6 +99,58 @@ rodeo_input_events_poll(void)
}
}
break;
+ case SDL_MOUSEMOTION:
+ {
+ 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_positional_mouse_value *x_value = cset_input_positional_mouse_get(
+ &command->unbounded_range.mouse_position,
+ rodeo_input_positional_mouse_X
+ );
+ const cset_input_positional_mouse_value *y_value = cset_input_positional_mouse_get(
+ &command->unbounded_range.mouse_position,
+ rodeo_input_positional_mouse_Y
+ );
+
+ if(x_value != NULL)
+ {
+ rodeo_input_any_state_t input_state = {
+ .data.positional_state = event.motion.x,
+ .input_type = rodeo_input_type_Positional
+ };
+ c_foreach(
+ k,
+ cset_input_callback_functions,
+ command->callbacks
+ )
+ {
+ (**k.ref)(input_state);
+ }
+ }
+
+ if(y_value != NULL)
+ {
+ rodeo_input_any_state_t input_state = {
+ .data.positional_state = event.motion.y,
+ .input_type = rodeo_input_type_Positional
+ };
+ c_foreach(
+ k,
+ cset_input_callback_functions,
+ command->callbacks
+ )
+ {
+ (**k.ref)(input_state);
+ }
+ }
+ }
+ }
+ }
+ break;
}
}
return false;
@@ -233,6 +285,30 @@ rodeo_input_command_register_binary_mouseButton(
}
}
+bool
+rodeo_input_command_register_positional_mouse(
+ rodeo_input_command_t *input_command,
+ rodeo_input_positional_mouse_t mouse_axis
+)
+{
+ if((rodeo_input_type_Positional & 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_positional_mouse_insert(
+ &input_command->unbounded_range.mouse_position,
+ mouse_axis
+ );
+ return true;
+ }
+}
+
void
rodeo_input_scene_register_command(
rodeo_input_scene_t *scene,
diff --git a/src/rodeo_input.c b/src/rodeo_input.c
deleted file mode 100644
index 3a40b77..0000000
--- a/src/rodeo_input.c
+++ /dev/null
@@ -1,23 +0,0 @@
-
-// public internal
-#include "rodeo_types.h"
-#include "rodeo.h"
-
-// external
-#include "SDL/SDL.h"
-
-int32_t
-rodeo_input_mouse_x_get(void)
-{
- int32_t x, y;
- SDL_GetMouseState(&x, &y);
- return x;
-}
-
-int32_t
-rodeo_input_mouse_y_get(void)
-{
- int32_t x, y;
- SDL_GetMouseState(&x, &y);
- return y;
-}