From: Lukas Krickl Date: Mon, 2 Mar 2026 10:16:13 +0000 (+0100) Subject: command: Added command put X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=d539520285d073479f5b3c12345fd8d56cf6d92f;p=lrts%2F.git command: Added command put The command queue is a ring buffer and will try to schedule. --- diff --git a/src/i_input.c b/src/i_input.c index a8c16ce..441b3e6 100644 --- a/src/i_input.c +++ b/src/i_input.c @@ -57,6 +57,30 @@ lrts_bool i_input_double_press(enum i_input_actions action) { } void i_input_poll(void) { + u32 i; + struct i_input_map_ent *e; p_poll_events(); i_input_update(); + + /* translate inputs + * to command queue + */ + for (i = 0; i < I_INPUT_ACTION_LEN; i++) { + e = &i_input_map.inputs[i]; + LRTS_UNUSED(e); + switch (i) { + case I_INPUT_ACTION_CAMERA_UP: + case I_INPUT_ACTION_CAMERA_DOWN: + case I_INPUT_ACTION_CAMERA_LEFT: + case I_INPUT_ACTION_CAMERA_RIGHT: + case I_INPUT_ACTION_CURSOR_CLICK: + case I_INPUT_ACTION_CURSOR_ACTION: + case I_INPUT_ACTION_CURSOR_DRAG: + break; + default: + u_log(U_LOG_CRIT, "Critical: unhandeled input action %d\n", i); + p_exit(P_EXIT_FAIL); + break; + } + } } diff --git a/src/p_pc/u_assert.c b/src/p_pc/u_assert.c index f5711e7..445f254 100644 --- a/src/p_pc/u_assert.c +++ b/src/p_pc/u_assert.c @@ -1 +1,6 @@ #include + + +void p_exit(i8 exit_code) { + exit(exit_code); +} diff --git a/src/p_platform.h b/src/p_platform.h index 4495d9d..9657186 100644 --- a/src/p_platform.h +++ b/src/p_platform.h @@ -7,6 +7,9 @@ * This module contains init code for platforms */ +#define P_EXIT_OK 0 +#define P_EXIT_FAIL -1 + /* * Init call for IO routines. * This should set up stdin, stdout and stderr @@ -59,6 +62,7 @@ u64 p_ticks_per_second(void); */ void p_delay(u64 time); +void p_exit(i8 exit_code); /** diff --git a/src/t_command.c b/src/t_command.c index 832bff3..519890f 100644 --- a/src/t_command.c +++ b/src/t_command.c @@ -1,7 +1,24 @@ #include "t_command.h" +struct t_command_queue t_command_queue; + +void t_command_queue_process(void) { +} lrts_bool t_command_exec(struct t_command *c) { LRTS_UNUSED(c); return LRTS_TRUE; } + +void t_command_push(struct t_command c) { + if (t_command_queue.write_idx >= T_COMMANDS_MAX) { + t_command_queue.write_idx = 0; + } + + if (t_command_queue.buffer[t_command_queue.write_idx].type != T_COMMAND_NONE) { + u_log(U_LOG_CRIT, "Command queue overflow!\n"); + p_exit(P_EXIT_FAIL); + } + + t_command_queue.buffer[t_command_queue.write_idx++] = c; +} diff --git a/src/t_command.h b/src/t_command.h index 9dadc5e..ec53a4a 100644 --- a/src/t_command.h +++ b/src/t_command.h @@ -8,7 +8,7 @@ * each unit has a command queue. */ -#define T_COMMANDS_MAX 8 +#define T_COMMANDS_MAX 0x4FF enum t_command_type { T_COMMAND_NONE = 0, @@ -35,13 +35,24 @@ struct t_command { /** * This is a comamnd buffer * It wraps around and keeps track of the current command + * This is a ring buffer. If the current write is already allocated (not type NONE + * the program will exit!) */ struct t_command_queue { - u8 current; + u16 write_idx; + u16 read_idx; struct t_command buffer[T_COMMANDS_MAX]; }; +extern struct t_command_queue t_command_queue; + +/* runs the command queue */ +void t_command_queue_process(void); + /* executes a command. Returns true if command was executed. */ lrts_bool t_command_exec(struct t_command *c); +/* pushes a new command to the command queue */ +void t_command_push(struct t_command c); + #endif