diff --git a/src/display/CMakeLists.txt b/src/display/CMakeLists.txt index b354f11..944d412 100644 --- a/src/display/CMakeLists.txt +++ b/src/display/CMakeLists.txt @@ -7,4 +7,5 @@ target_sources(${DUSK_TARGET_NAME} PRIVATE render.c + term.c ) \ No newline at end of file diff --git a/src/display/render.c b/src/display/render.c index 0e9dbba..5a1f258 100644 --- a/src/display/render.c +++ b/src/display/render.c @@ -6,7 +6,22 @@ */ #include "render.h" +#include "term.h" void renderInit() { - + termInit(); +} + +void renderUpdate() { + termUpdate(); + termClear(); + + for(int32_t y = 0; y < TERM.height; y++) { + for(int32_t x = 0; x < TERM.width; x++) { + char_t c = ' '; // Replace with actual rendering logic + termPushChar(c); + } + } + + termFlush(); } \ No newline at end of file diff --git a/src/display/render.h b/src/display/render.h index 04f4f00..2eea46c 100644 --- a/src/display/render.h +++ b/src/display/render.h @@ -6,8 +6,17 @@ */ #pragma once +#include "dusk.h" + +extern int32_t renderColumnCount; +extern int32_t renderRowCount; /** * Init the render system. */ -void renderInit(); \ No newline at end of file +void renderInit(); + +/** + * Update the render system. + */ +void renderUpdate(); \ No newline at end of file diff --git a/src/display/term.c b/src/display/term.c new file mode 100644 index 0000000..d4a66d7 --- /dev/null +++ b/src/display/term.c @@ -0,0 +1,42 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "term.h" +#include "util/memory.h" +#include + +term_t TERM; + +void termInit() { + memoryZero(&TERM, sizeof(term_t)); + + struct winsize w; + if(ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) == 0) { + TERM.width = w.ws_col; + TERM.height = w.ws_row; + } +} + +void termUpdate() { + struct winsize w; + if(ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) == 0) { + TERM.width = w.ws_col; + TERM.height = w.ws_row; + } +} + +void termClear() { + printf("\033[2J\033[H"); +} + +void termPushChar(const char_t c) { + putchar(c); +} + +void termFlush() { + fflush(stdout); +} \ No newline at end of file diff --git a/src/display/term.h b/src/display/term.h new file mode 100644 index 0000000..093b535 --- /dev/null +++ b/src/display/term.h @@ -0,0 +1,43 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "dusk.h" + +typedef struct { + int32_t width; + int32_t height; +} term_t; + +extern term_t TERM; + +/** + * Initialize the terminal system. + */ +void termInit(); + +/** + * Update the terminal system, typically called each frame. + */ +void termUpdate(); + +/** + * Clear the terminal screen and reset cursor position. + */ +void termClear(); + +/** + * Push a character to the terminal output buffer. + * + * @param c The character to push. + */ +void termPushChar(const char_t c); + +/** + * Flush the terminal output buffer to the terminal. + */ +void termFlush(); \ No newline at end of file diff --git a/src/main.c b/src/main.c index 7c9a82b..f41a72d 100644 --- a/src/main.c +++ b/src/main.c @@ -13,8 +13,8 @@ int32_t main(const int32_t argc, const char **argv) { renderInit(); while(1) { - - usleep(16 * 1000); // Sleep for 16 milliseconds (60 FPS) + renderUpdate(); + usleep(100 * 1000); // Sleep for 16 milliseconds (60 FPS) } return EXIT_SUCCESS; diff --git a/src/rpg/entity/entity.h b/src/rpg/entity/entity.h index 62dd8e9..0f0286a 100644 --- a/src/rpg/entity/entity.h +++ b/src/rpg/entity/entity.h @@ -29,6 +29,7 @@ typedef enum { typedef struct _entity_t { entitytype_t type; uint8_t x, y; + uint8_t subX, subY; entitydir_t dir; // Per type data diff --git a/src/rpg/item/itemtype.c b/src/rpg/item/itemtype.c index 01df5f9..a6d6a5d 100644 --- a/src/rpg/item/itemtype.c +++ b/src/rpg/item/itemtype.c @@ -23,6 +23,6 @@ iteminfo_t ITEM_INFO[ITEM_TYPE_COUNT] = { }; static inline bool_t itemTypeIsStackable(const itemtype_t type) { - assert(type < ITEM_TYPE_COUNT, "Invalid item type"); + assertTrue(type < ITEM_TYPE_COUNT, "Invalid item type"); return ITEM_INFO[type].stackable; } \ No newline at end of file