map: wip added map struct
authorLukas Krickl <lukas@krickl.dev>
Thu, 26 Feb 2026 07:52:35 +0000 (08:52 +0100)
committerLukas Krickl <lukas@krickl.dev>
Thu, 26 Feb 2026 07:52:35 +0000 (08:52 +0100)
added more keyboard keys

src/i_input.h
src/lrts.c
src/r_assets.h
src/r_render.c
src/t_camera.c
src/t_camera.h
src/t_map.c
src/t_map.h

index c2a53be95c0a1d916de9596b607d3e2f75ff274e..9c166acfcbac0fe74a093f7a56ce04cfa4fff0f4 100644 (file)
@@ -26,7 +26,18 @@ struct i_cursor {
        enum i_button_state buttons[I_CURSOR_BUTTONS];
 };
 
+enum i_arrow_keys {
+       I_ARROW_UP = 0,
+       I_ARROW_DOWN,
+       I_ARROW_LEFT,
+       I_ARROW_RIGHT,
+       I_ARROW_LEN
+};
+
+#define I_FKEYS_LEN 12
+
 struct i_keyboard {
+       enum i_button_state esc;
        enum i_button_state shift;
        enum i_button_state ctrl;
        enum i_button_state alt;
@@ -35,6 +46,22 @@ struct i_keyboard {
        enum i_button_state space;
        enum i_button_state backspace;
 
+       enum i_button_state arrow[I_ARROW_LEN];
+
+       enum i_button_state del;
+       enum i_button_state home;
+       enum i_button_state end;
+       enum i_button_state pgup;
+       enum i_button_state pgdown;
+       enum i_button_state insert;
+
+       enum i_button_state tab;
+
+       enum i_button_state print;
+       enum i_button_state pause;
+
+       enum i_button_state fkey[I_FKEYS_LEN];
+
        /* ascii table for all other keys */
        enum i_button_state keys[I_KEYBOARD_KEYS];
 };
index f43239f30c58a87bb745d7750987ebe4c81c8b96..d5de30f5b10553cb60a299d73cce0965dead2966 100644 (file)
@@ -4,6 +4,8 @@
 #include "r_render.h"
 #include "r_assets.h"
 #include "i_input.h"
+#include "t_camera.h"
+#include "t_map.h"
 
 struct lrts_config lrts_global_cfg;
 
@@ -63,9 +65,16 @@ struct u_vec2 lrts_get_screen_res(void) {
 }
 
 void lrts_init(void) {
+       struct u_vec2 res = lrts_get_render_res();
+
        /* init the fallback tile mask */
        r_asset_init_fallback_tile();
        i_input_init();
+
+
+
+       t_main_camera = t_camera_init(res.x, res.y);
+       t_map = t_map_init();
 }
 
 int lrts_main(int argc, char **argv) {
index 4b1a11a312ca93fe117fb3f5224c410aa40bb0a7..a93bec2e897c6ffd8a29ef9a87f9dd6766662bce 100644 (file)
@@ -1,8 +1,8 @@
 #ifndef R_ASSETS_H__
 #define R_ASSETS_H__
 
-#define R_TILE_W 64
-#define R_TILE_H 32
+#define R_TILE_W 96
+#define R_TILE_H 48
 
 /**
  * This module contains asset descriptions
index 0e07d0c0ce962b173467196a572df88aaab5721e..48dfa6ab530747859c3e567201ebd2c0d176da4a 100644 (file)
@@ -26,19 +26,10 @@ void r_draw_pixel(struct r_framebuffer *fb, i32 x, i32 y, r_color color) {
 }
 
 void r_render_frame() {
-       int i, j;
-       struct t_tile t;
-
        p_draw_begin();
        
-       /* draw test tile */
-       t.type = T_TILE_TYPE_GRASS;
 
-       for (i = 0; i < 16; i++) {
-               for (j = 0; j < 16; j++) {
-                       r_draw_tile(&t, i, j);
-               }
-       }
+       t_map_draw(&t_map);
 
        p_draw_end();
        p_draw_present();
index 848931f69ef3b8fb18abd4ea79d9946ffb45080e..e8e0b1c2a68ee646cb91228d5e568f563e479a05 100644 (file)
@@ -1,5 +1,7 @@
 #include "t_camera.h"
 
+struct t_camera t_main_camera;
+
 struct t_camera t_camera_init(i32 viewport_x, i32 viewport_y) {
        struct t_camera c;
        c.x = 0;
@@ -16,3 +18,4 @@ void t_camera_scroll(struct t_camera *c, i32 by_x, i32 by_y) {
        U_CLAMP(c->x, 0, c->viewport_x);
        U_CLAMP(c->y, 0, c->viewport_y);
 }
+
index 5b7571273cea13977671bf27c98b8ceea1f47634..73af3c79f46ef991fdcd28a68f1e28b658e3f97a 100644 (file)
@@ -11,6 +11,8 @@ struct t_camera {
        i32 viewport_y;
 };
 
+extern struct t_camera t_main_camera;
+
 struct t_camera t_camera_init(i32 viewport_x, i32 viewport_y);
 
 void t_camera_scroll(struct t_camera *c, i32 by_x, i32 by_y);
index 8bdca942b349484fce0b9ced8cf43dbf5301389b..26e53c536a04aa492602c4d41d029606a78b2549 100644 (file)
@@ -1 +1,33 @@
 #include "t_map.h"
+#include "u_mem.h"
+
+struct t_map t_map;
+
+struct t_map t_map_init(void) {
+       u32 i, j;
+
+       struct t_map m;
+       u_memset(&m, 0, sizeof(m));
+
+       m.width = T_MAP_MAX_W;
+       m.height = T_MAP_MAX_H;
+
+       for (i = 0; i < m.width; i++) {
+               for (j = 0; j < m.height; j++) {
+                       m.tiles[j * m.width + i].type = T_TILE_TYPE_GRASS;
+               }
+       }
+
+       return m;
+}
+
+void t_map_draw(struct t_map *m) {
+       u32 i, j;
+       
+       /* TODO: only draw visible tiles */
+       for (i = 0; i < m->width; i++) {
+               for (j = 0; j < m->height; j++) {
+                       r_draw_tile(&m->tiles[j * m->width + i], i, j);
+               }
+       }
+}
index e38c695fbaf8a7ad6b4fb341cb9367bf3fe212b8..3fee0ac65dc3dcf3311a4f1a0608963875fd4fec 100644 (file)
@@ -14,4 +14,14 @@ struct t_map {
        struct t_tile tiles[T_MAP_MAX_W * T_MAP_MAX_H];
 };
 
+extern struct t_map t_map;
+
+/**
+ * Inits a default map of max size
+ * and grass tiles
+ */
+struct t_map t_map_init(void);
+
+void t_map_draw(struct t_map *m);
+
 #endif