Input test.

This commit is contained in:
2025-06-08 17:36:13 -05:00
parent 5cc38e14d6
commit 2309fea9f3
17 changed files with 301 additions and 19 deletions

22
src/display/color.h Normal file
View File

@@ -0,0 +1,22 @@
/**
* 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

@@ -5,20 +5,64 @@
* 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++) {
char_t c = ' '; // Replace with actual rendering logic
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);
}
}

View File

@@ -8,9 +8,6 @@
#pragma once
#include "dusk.h"
extern int32_t renderColumnCount;
extern int32_t renderRowCount;
/**
* Init the render system.
*/

View File

@@ -5,12 +5,24 @@
* 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));
@@ -33,6 +45,11 @@ 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);
}

View File

@@ -7,6 +7,7 @@
#pragma once
#include "dusk.h"
#include "display/color.h"
typedef struct {
int32_t width;
@@ -15,6 +16,8 @@ typedef struct {
extern term_t TERM;
extern const char_t* TERM_COLORS[COLOR_COUNT];
/**
* Initialize the terminal system.
*/
@@ -30,6 +33,8 @@ void termUpdate();
*/
void termClear();
void termPushColor(const color_t color);
/**
* Push a character to the terminal output buffer.
*