From 7feba5191fcd542c589743c5ffa02130a3458669 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Thu, 26 Feb 2026 08:52:35 +0100 Subject: [PATCH] map: wip added map struct added more keyboard keys --- src/i_input.h | 27 +++++++++++++++++++++++++++ src/lrts.c | 9 +++++++++ src/r_assets.h | 4 ++-- src/r_render.c | 11 +---------- src/t_camera.c | 3 +++ src/t_camera.h | 2 ++ src/t_map.c | 32 ++++++++++++++++++++++++++++++++ src/t_map.h | 10 ++++++++++ 8 files changed, 86 insertions(+), 12 deletions(-) diff --git a/src/i_input.h b/src/i_input.h index c2a53be..9c166ac 100644 --- a/src/i_input.h +++ b/src/i_input.h @@ -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]; }; diff --git a/src/lrts.c b/src/lrts.c index f43239f..d5de30f 100644 --- a/src/lrts.c +++ b/src/lrts.c @@ -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) { diff --git a/src/r_assets.h b/src/r_assets.h index 4b1a11a..a93bec2 100644 --- a/src/r_assets.h +++ b/src/r_assets.h @@ -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 diff --git a/src/r_render.c b/src/r_render.c index 0e07d0c..48dfa6a 100644 --- a/src/r_render.c +++ b/src/r_render.c @@ -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(); diff --git a/src/t_camera.c b/src/t_camera.c index 848931f..e8e0b1c 100644 --- a/src/t_camera.c +++ b/src/t_camera.c @@ -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); } + diff --git a/src/t_camera.h b/src/t_camera.h index 5b75712..73af3c7 100644 --- a/src/t_camera.h +++ b/src/t_camera.h @@ -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); diff --git a/src/t_map.c b/src/t_map.c index 8bdca94..26e53c5 100644 --- a/src/t_map.c +++ b/src/t_map.c @@ -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); + } + } +} diff --git a/src/t_map.h b/src/t_map.h index e38c695..3fee0ac 100644 --- a/src/t_map.h +++ b/src/t_map.h @@ -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 -- 2.30.2