twn_input.c: remove input_mouse_captured(), add ctx.mouse_capture

This commit is contained in:
veclavtalica 2025-01-14 00:28:21 +03:00
parent 6d19d2d819
commit 4ed3764c1d
5 changed files with 5 additions and 18 deletions

View File

@ -216,7 +216,7 @@ static void ingame_tick(State *state) {
if (input_action_just_pressed("mouse_capture_toggle")) if (input_action_just_pressed("mouse_capture_toggle"))
scn->mouse_captured = !scn->mouse_captured; scn->mouse_captured = !scn->mouse_captured;
input_mouse_captured(scn->mouse_captured); ctx.mouse_capture = scn->mouse_captured;
generate_terrain(scn); generate_terrain(scn);
draw_terrain(scn); draw_terrain(scn);

View File

@ -38,6 +38,7 @@ typedef struct Context {
/* is set to true when state is invalidated and needs to be rebuilt */ /* is set to true when state is invalidated and needs to be rebuilt */
/* watch for it and handle properly! */ /* watch for it and handle properly! */
bool initialization_needed; bool initialization_needed;
bool mouse_capture;
} Context; } Context;
/* when included after twn_engine_context there's an 'ctx' defined already */ /* when included after twn_engine_context there's an 'ctx' defined already */

View File

@ -15,6 +15,5 @@ TWN_API bool input_action_pressed(const char *name);
TWN_API bool input_action_just_pressed(const char *name); TWN_API bool input_action_just_pressed(const char *name);
TWN_API bool input_action_just_released(const char *name); TWN_API bool input_action_just_released(const char *name);
TWN_API Vec2 input_action_position(const char *name); TWN_API Vec2 input_action_position(const char *name);
TWN_API void input_mouse_captured(bool enabled);
#endif #endif

View File

@ -52,15 +52,6 @@
"return": "Vec2" "return": "Vec2"
}, },
"input_mouse_captured": {
"module": "input",
"symbol": "set_mouse_captured",
"header": "twn_input.h",
"params": [
{ "name": "enabled", "type": "bool" }
]
},
"draw_sprite": { "draw_sprite": {
"module": "draw", "module": "draw",
"symbol": "sprite", "symbol": "sprite",
@ -268,7 +259,8 @@
{ "name": "mouse_movement", "type": "Vec2" }, { "name": "mouse_movement", "type": "Vec2" },
{ "name": "random_seed", "type": "float" }, { "name": "random_seed", "type": "float" },
{ "name": "debug", "type": "bool" }, { "name": "debug", "type": "bool" },
{ "name": "initialization_needed", "type": "bool" } { "name": "initialization_needed", "type": "bool" },
{ "name": "mouse_capture", "type": "bool" }
], ],
"c_type": "Context" "c_type": "Context"
}, },

View File

@ -218,7 +218,7 @@ void input_state_deinit(InputState *input) {
void input_state_update(InputState *input) { void input_state_update(InputState *input) {
/* TODO: don't spam it if it happens */ /* TODO: don't spam it if it happens */
if (SDL_SetRelativeMouseMode(input->mouse_captured) != 0) if (SDL_SetRelativeMouseMode(ctx.game_copy.mouse_capture) != 0)
log_warn("(%s) Mouse capture isn't supported.", __func__); log_warn("(%s) Mouse capture isn't supported.", __func__);
int x, y; int x, y;
@ -326,11 +326,6 @@ Vec2 input_action_position(char const *action_name) {
} }
void input_mouse_captured(bool enabled) {
ctx.input.mouse_captured = enabled;
}
void input_reset_state(InputState *input) { void input_reset_state(InputState *input) {
for (size_t i = 0; i < shlenu(input->action_hash); ++i) { for (size_t i = 0; i < shlenu(input->action_hash); ++i) {
Action *action = &input->action_hash[i].value; Action *action = &input->action_hash[i].value;