This commit is contained in:
2025-06-08 15:55:41 -05:00
parent 823aa454bd
commit 5cc38e14d6
8 changed files with 116 additions and 5 deletions

View File

@ -7,4 +7,5 @@
target_sources(${DUSK_TARGET_NAME} target_sources(${DUSK_TARGET_NAME}
PRIVATE PRIVATE
render.c render.c
term.c
) )

View File

@ -6,7 +6,22 @@
*/ */
#include "render.h" #include "render.h"
#include "term.h"
void renderInit() { 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();
} }

View File

@ -6,8 +6,17 @@
*/ */
#pragma once #pragma once
#include "dusk.h"
extern int32_t renderColumnCount;
extern int32_t renderRowCount;
/** /**
* Init the render system. * Init the render system.
*/ */
void renderInit(); void renderInit();
/**
* Update the render system.
*/
void renderUpdate();

42
src/display/term.c Normal file
View File

@ -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 <sys/ioctl.h>
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);
}

43
src/display/term.h Normal file
View File

@ -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();

View File

@ -13,8 +13,8 @@ int32_t main(const int32_t argc, const char **argv) {
renderInit(); renderInit();
while(1) { while(1) {
renderUpdate();
usleep(16 * 1000); // Sleep for 16 milliseconds (60 FPS) usleep(100 * 1000); // Sleep for 16 milliseconds (60 FPS)
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;

View File

@ -29,6 +29,7 @@ typedef enum {
typedef struct _entity_t { typedef struct _entity_t {
entitytype_t type; entitytype_t type;
uint8_t x, y; uint8_t x, y;
uint8_t subX, subY;
entitydir_t dir; entitydir_t dir;
// Per type data // Per type data

View File

@ -23,6 +23,6 @@ iteminfo_t ITEM_INFO[ITEM_TYPE_COUNT] = {
}; };
static inline bool_t itemTypeIsStackable(const itemtype_t type) { 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; return ITEM_INFO[type].stackable;
} }