command: Added command put
authorLukas Krickl <lukas@krickl.dev>
Mon, 2 Mar 2026 10:16:13 +0000 (11:16 +0100)
committerLukas Krickl <lukas@krickl.dev>
Mon, 2 Mar 2026 10:16:13 +0000 (11:16 +0100)
The command queue is a ring buffer and will try to schedule.

src/i_input.c
src/p_pc/u_assert.c
src/p_platform.h
src/t_command.c
src/t_command.h

index a8c16cec520af434088bb4e18b209938ded1b28b..441b3e62c83ecc920437c1443f1df5185df4e0f2 100644 (file)
@@ -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;
+               }
+       }
 }
index f5711e7692e70b793bf78fc8d25b5fbf8f3a098b..445f254336b0551d060bb6b92088a8a422b64f8a 100644 (file)
@@ -1 +1,6 @@
 #include <assert.h>
+
+
+void p_exit(i8 exit_code) {
+       exit(exit_code);
+}
index 4495d9d15a3109a685c100e6a7b2448ac1446f57..96571869c2048a7310ea4b446fa8ecfae99b9cae 100644 (file)
@@ -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);
 
 
 /**
index 832bff304a39727067f7a4e98bc1abf6a774f60d..519890fe79f899c5f23e05c415946ad8125d2c1d 100644 (file)
@@ -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;
+}
index 9dadc5eb4a88cae42748d563b38b9c162fb2afec..ec53a4ad407295d3f6e232d718b266048d8cc6e7 100644 (file)
@@ -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