From 8e49be5ac4bc36d5963fc44ef28d8acbee6b6edc Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Sat, 18 Apr 2026 15:29:40 -0500 Subject: [PATCH] Testing some wii rendering bugs --- src/dusk/display/display.c | 3 - src/dusk/display/text/text.c | 9 ++- src/dusk/display/text/text.h | 4 +- src/dusk/engine/engine.c | 2 +- src/dusk/entity/entitymanager.c | 5 +- src/dusk/scene/scene.c | 78 +++++++++++++++++++++ src/dusk/scene/scene.h | 4 ++ src/dusk/script/module/display/moduletext.c | 4 +- src/duskdolphin/display/displaydolphin.c | 2 +- 9 files changed, 95 insertions(+), 16 deletions(-) diff --git a/src/dusk/display/display.c b/src/dusk/display/display.c index 644f1d61..d03ac926 100644 --- a/src/dusk/display/display.c +++ b/src/dusk/display/display.c @@ -101,9 +101,6 @@ errorret_t displayUpdate(void) { errorChain(sceneRender()); - // Render UI - // uiRender(); - // Finish up screenUnbind(); screenRender(); diff --git a/src/dusk/display/text/text.c b/src/dusk/display/text/text.c index 196a3a23..98e23776 100644 --- a/src/dusk/display/text/text.c +++ b/src/dusk/display/text/text.c @@ -70,9 +70,7 @@ errorret_t textDraw( const float_t x, const float_t y, const char_t *text, - #if MESH_ENABLE_COLOR - const color_t color, - #endif + const color_t color, const tileset_t *tileset, texture_t *texture ) { @@ -83,6 +81,11 @@ errorret_t textDraw( errorChain(shaderSetTexture(&SHADER_UNLIT, SHADER_UNLIT_TEXTURE, texture)); + #if MESH_ENABLE_COLOR + #else + errorChain(shaderSetColor(&SHADER_UNLIT, SHADER_UNLIT_COLOR, color)); + #endif + // errorChain(spriteBatchPush( // // texture, // posX, posY, diff --git a/src/dusk/display/text/text.h b/src/dusk/display/text/text.h index d2a43208..5944e205 100644 --- a/src/dusk/display/text/text.h +++ b/src/dusk/display/text/text.h @@ -66,9 +66,7 @@ errorret_t textDraw( const float_t x, const float_t y, const char_t *text, - #if MESH_ENABLE_COLOR - const color_t color, - #endif + const color_t color, const tileset_t *tileset, texture_t *texture ); diff --git a/src/dusk/engine/engine.c b/src/dusk/engine/engine.c index baf8e64b..eef022c4 100644 --- a/src/dusk/engine/engine.c +++ b/src/dusk/engine/engine.c @@ -112,7 +112,7 @@ errorret_t engineInit(const int32_t argc, const char_t **argv) { physicsManagerInit(); errorChain(networkInit()); errorChain(gameInit()); - + // printf("Init done, going to queue online in 3 seconds...\n"); // onlineSwapTime = TIME.time + 3.0f; diff --git a/src/dusk/entity/entitymanager.c b/src/dusk/entity/entitymanager.c index c657ed61..1b691b58 100644 --- a/src/dusk/entity/entitymanager.c +++ b/src/dusk/entity/entitymanager.c @@ -8,6 +8,7 @@ #include "entitymanager.h" #include "assert/assert.h" #include "util/memory.h" +#include "scene/scene.h" entitymanager_t ENTITY_MANAGER; @@ -18,8 +19,8 @@ void entityManagerInit(void) { sizeof(entityid_t) * COMPONENT_TYPE_COUNT * ENTITY_COUNT_MAX ); - printf( - "Entity Manager size is currently: %zu bytes (%.2f KB)\n", + sceneLog( + "Entity Manager size: %zu bytes (%.2f KB)\n", sizeof(entitymanager_t), sizeof(entitymanager_t) / 1024.0f ); diff --git a/src/dusk/scene/scene.c b/src/dusk/scene/scene.c index 9a24fbc9..50ddc5c0 100644 --- a/src/dusk/scene/scene.c +++ b/src/dusk/scene/scene.c @@ -12,12 +12,59 @@ #include "entity/entitymanager.h" #include "display/shader/shaderunlit.h" #include "display/mesh/cube.h" +#include "display/spritebatch/spritebatch.h" +#include "display/text/text.h" +#include "display/screen/screen.h" scene_t SCENE; +char_t SCENE_LOG[SCENE_LOG_SIZE]; + +void sceneLog(const char *fmt, ...) { + char temp[512]; + + // 1. Format input like printf + va_list args; + va_start(args, fmt); + vsnprintf(temp, sizeof(temp), fmt, args); + va_end(args); + + printf("%s", temp); + + // 2. Split into lines + char *lines[64]; + int line_count = 0; + + char *ptr = temp; + while (*ptr && line_count < 64) { + lines[line_count++] = ptr; + + char *nl = strchr(ptr, '\n'); + if (!nl) break; + + *nl = '\0'; + ptr = nl + 1; + } + + // 3. Prepend lines in reverse order (so final order is correct) + for (int i = 0; i < line_count; i++) { + char new_log[SCENE_LOG_SIZE]; + + snprintf(new_log, sizeof(new_log), "%s\n%s", lines[i], SCENE_LOG); + + // Copy back safely + strncpy(SCENE_LOG, new_log, SCENE_LOG_SIZE - 1); + SCENE_LOG[SCENE_LOG_SIZE - 1] = '\0'; + } +} + errorret_t sceneInit(void) { memoryZero(&SCENE, sizeof(scene_t)); + memoryZero(SCENE_LOG, sizeof(SCENE_LOG)); + sceneLog("Init\n"); + + errorOk(); } @@ -52,6 +99,7 @@ errorret_t sceneRender(void) { mat4 view, proj, model; errorChain(shaderBind(&SHADER_UNLIT)); + // For each camera. for(entityid_t camIndex = 0; camIndex < camCount; camIndex++) { entityid_t camEnt = camEnts[camIndex]; componentid_t camComp = camComps[camIndex]; @@ -110,6 +158,36 @@ errorret_t sceneRender(void) { } } + // Here is where UI will go + glm_ortho( + 0.0f, SCREEN.width, + SCREEN.height, 0.0f, + 0.1f, 100.0f, + proj + ); + glm_lookat( + (vec3){ 0.0f, 0.0f, 1.0f }, + (vec3){ 0.0f, 0.0f, 0.0f }, + (vec3){ 0.0f, 1.0f, 0.0f }, + view + ); + glm_mat4_identity(model); + + errorChain(shaderBind(&SHADER_UNLIT)); + errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_PROJECTION, proj)); + errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_VIEW, view)); + errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_MODEL, model)); + // errorChain(shaderSetTexture(&SHADER_UNLIT, SHADER_UNLIT_0TEXTURE, &DEFAULT_FONT_TEXTURE)); + // errorChain(shaderSetColor(&SHADER_UNLIT, SHADER_UNLIT_COLOR, COLOR_WHITE)); + errorChain(textDraw( + 100, 100, + "Hello World", + COLOR_WHITE, + &DEFAULT_FONT_TILESET, + &DEFAULT_FONT_TEXTURE + )); + errorChain(spriteBatchFlush()); + errorOk(); } diff --git a/src/dusk/scene/scene.h b/src/dusk/scene/scene.h index 6e0a079d..bf949761 100644 --- a/src/dusk/scene/scene.h +++ b/src/dusk/scene/scene.h @@ -14,6 +14,10 @@ typedef struct { extern scene_t SCENE; +#define SCENE_LOG_SIZE 1024 +extern char_t SCENE_LOG[SCENE_LOG_SIZE]; +void sceneLog(const char *fmt, ...); + /** * Initialize the scene subsystem. * diff --git a/src/dusk/script/module/display/moduletext.c b/src/dusk/script/module/display/moduletext.c index e20cd739..de18aecc 100644 --- a/src/dusk/script/module/display/moduletext.c +++ b/src/dusk/script/module/display/moduletext.c @@ -52,9 +52,7 @@ int moduleTextDraw(lua_State *L) { x, y, text, - #if MESH_ENABLE_COLOR - color == NULL ? COLOR_WHITE : *color, - #endif + color == NULL ? COLOR_WHITE : *color, &DEFAULT_FONT_TILESET, &DEFAULT_FONT_TEXTURE ); diff --git a/src/duskdolphin/display/displaydolphin.c b/src/duskdolphin/display/displaydolphin.c index bbec3708..f4b4cdf6 100644 --- a/src/duskdolphin/display/displaydolphin.c +++ b/src/duskdolphin/display/displaydolphin.c @@ -76,7 +76,7 @@ errorret_t displayInitDolphin(void) { ); // Setup cull modes - GX_SetCullMode(GX_CULL_BACK); + GX_SetCullMode(GX_CULL_NONE); GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR); GX_SetZMode(GX_TRUE, GX_ALWAYS, GX_FALSE); GX_SetDispCopyGamma(GX_GM_1_0);