Render test

This commit is contained in:
2025-06-10 17:09:33 -05:00
parent a2fd58fda7
commit 1b6db0c643
47 changed files with 219 additions and 370 deletions

View File

@@ -1,11 +0,0 @@
# Copyright (c) 2025 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DUSK_TARGET_NAME}
PRIVATE
render.c
term.c
)

View File

@@ -1,22 +0,0 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dusk.h"
typedef enum {
COLOR_BLACK,
COLOR_RED,
COLOR_GREEN,
COLOR_YELLOW,
COLOR_BLUE,
COLOR_MAGENTA,
COLOR_CYAN,
COLOR_WHITE,
} color_t;
#define COLOR_COUNT (COLOR_WHITE + 1)

View File

@@ -1,71 +0,0 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "assert/assert.h"
#include "render.h"
#include "term.h"
#include "rpg/entity/entity.h"
void renderInit() {
termInit();
}
void renderUpdate() {
char_t c;
color_t color, colorCurrent;
entity_t *ent;
termUpdate();
termClear();
colorCurrent = COLOR_WHITE;
termPushColor(colorCurrent);
for(int32_t y = 0; y < TERM.height; y++) {
for(int32_t x = 0; x < TERM.width; x++) {
color = COLOR_WHITE;
c = ' ';
ent = entityGetAt(x, y);
if(ent) {
color = COLOR_RED;
switch(ent->dir) {
case ENTITY_DIR_UP:
c = '^';
color = COLOR_GREEN;
break;
case ENTITY_DIR_DOWN:
c = 'v';
color = COLOR_RED;
break;
case ENTITY_DIR_LEFT:
c = '<';
color = COLOR_YELLOW;
break;
case ENTITY_DIR_RIGHT:
c = '>';
color = COLOR_BLUE;
break;
default:
assertUnreachable("Invalid entity direction");
break;
}
}
if(c == ' ') {
termPushChar(' ');
continue;
}
if(color != colorCurrent) termPushColor((colorCurrent = color));
termPushChar(c);
}
}
termFlush();
}

View File

@@ -1,19 +0,0 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dusk.h"
/**
* Init the render system.
*/
void renderInit();
/**
* Update the render system.
*/
void renderUpdate();

View File

@@ -1,59 +0,0 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "assert/assert.h"
#include "term.h"
#include "util/memory.h"
#include <sys/ioctl.h>
term_t TERM;
const char_t* TERM_COLORS[COLOR_COUNT] = {
[COLOR_BLACK] = "\033[30m",
[COLOR_RED] = "\033[31m",
[COLOR_GREEN] = "\033[32m",
[COLOR_YELLOW] = "\033[33m",
[COLOR_BLUE] = "\033[34m",
[COLOR_MAGENTA] = "\033[35m",
[COLOR_CYAN] = "\033[36m",
[COLOR_WHITE] = "\033[37m"
};
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 termPushColor(const color_t color) {
assertTrue(color < COLOR_COUNT, "Invalid color index");
printf("%s", TERM_COLORS[color]);
}
void termPushChar(const char_t c) {
putchar(c);
}
void termFlush() {
fflush(stdout);
}

View File

@@ -1,48 +0,0 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dusk.h"
#include "display/color.h"
typedef struct {
int32_t width;
int32_t height;
} term_t;
extern term_t TERM;
extern const char_t* TERM_COLORS[COLOR_COUNT];
/**
* 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();
void termPushColor(const color_t color);
/**
* 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();