Term
This commit is contained in:
@ -7,4 +7,5 @@
|
||||
target_sources(${DUSK_TARGET_NAME}
|
||||
PRIVATE
|
||||
render.c
|
||||
term.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();
|
||||
}
|
@ -6,8 +6,17 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
|
||||
extern int32_t renderColumnCount;
|
||||
extern int32_t renderRowCount;
|
||||
|
||||
/**
|
||||
* Init the render system.
|
||||
*/
|
||||
void renderInit();
|
||||
void renderInit();
|
||||
|
||||
/**
|
||||
* Update the render system.
|
||||
*/
|
||||
void renderUpdate();
|
42
src/display/term.c
Normal file
42
src/display/term.c
Normal 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
43
src/display/term.h
Normal 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();
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
Reference in New Issue
Block a user