From 995bbe1acd5eb9e5f8188026a0429c22a6575e1c Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Fri, 22 Aug 2025 22:42:38 -0500 Subject: [PATCH] Fixed time. --- CMakeLists.txt | 4 ++-- src/display/display.c | 9 ++++++--- src/display/mesh/meshrenderer.c | 7 +------ src/display/mesh/quad.c | 20 ++++++++++++++++++++ src/display/mesh/quad.h | 8 ++++++++ src/scene/test/scenetest.c | 12 ++---------- src/time/CMakeLists.txt | 15 ++++++++++++++- src/time/time.c | 30 ++++++++++++++---------------- src/time/time.h | 26 +------------------------- 9 files changed, 68 insertions(+), 63 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b9596f5..ec3a5d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,8 +10,8 @@ set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) if(NOT DEFINED DUSK_TARGET_SYSTEM) - # set(DUSK_TARGET_SYSTEM "linux") - set(DUSK_TARGET_SYSTEM "psp") + set(DUSK_TARGET_SYSTEM "linux") + # set(DUSK_TARGET_SYSTEM "psp") endif() # Prep cache diff --git a/src/display/display.c b/src/display/display.c index 79fb176..fe34194 100644 --- a/src/display/display.c +++ b/src/display/display.c @@ -10,6 +10,8 @@ #include "display/renderer.h" #include "ecs/ecssystem.h" +#include "display/mesh/quad.h" + display_t DISPLAY; errorret_t displayInit(void) { @@ -55,7 +57,8 @@ errorret_t displayInit(void) { glEnableClientState(GL_VERTEX_ARRAY); #endif - // For now, we just return an OK error. + quadInit(); + errorOk(); } @@ -73,9 +76,9 @@ errorret_t displayUpdate(void) { } } - // Set viewport size. + // TODO: move to framebuffer component int32_t windowWidth, windowHeight; - // SDL_GetWindowSize(DISPLAY.window, &windowWidth, &windowHeight); + SDL_GetWindowSize(DISPLAY.window, &windowWidth, &windowHeight); glViewport(0, 0, windowWidth, windowHeight); #endif diff --git a/src/display/mesh/meshrenderer.c b/src/display/mesh/meshrenderer.c index 912374c..6b672cd 100644 --- a/src/display/mesh/meshrenderer.c +++ b/src/display/mesh/meshrenderer.c @@ -6,7 +6,7 @@ */ #include "meshrenderer.h" -#include "scene/node.h" +#include "time/time.h" meshrenderer_t MESH_RENDERER_DATA[ECS_ENTITY_COUNT_MAX] = { 0 }; ecscomponent_t MESH_RENDERER_COMPONENT = ecsComponentInit( @@ -20,12 +20,7 @@ ecscomponent_t MESH_RENDERER_COMPONENT = ecsComponentInit( void meshRendererDraw(const ecsid_t id) { if(!meshRendererHas(id)) return; - meshrenderer_t *renderer = &MESH_RENDERER_DATA[id]; if(!renderer->mesh) return; - - node_t *node = nodeGet(id); - nodeMatrixUpdate(id); - meshDraw(renderer->mesh, 0, -1); } \ No newline at end of file diff --git a/src/display/mesh/quad.c b/src/display/mesh/quad.c index acf02f8..6fef521 100644 --- a/src/display/mesh/quad.c +++ b/src/display/mesh/quad.c @@ -8,6 +8,26 @@ #include "quad.h" #include "assert/assert.h" +mesh_t QUAD_MESH_SIMPLE; +meshvertex_t QUAD_MESH_SIMPLE_VERTICES[QUAD_VERTEX_COUNT] = { + { { 0xFF, 0xFF, 0xFF, 0xFF }, { 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } }, + { { 0xFF, 0xFF, 0xFF, 0xFF }, { 1.0f, 0.0f }, { 1.0f, 0.0f, 0.0f } }, + { { 0xFF, 0xFF, 0xFF, 0xFF }, { 1.0f, 1.0f }, { 1.0f, 1.0f, 0.0f } }, + + { { 0xFF, 0xFF, 0xFF, 0xFF }, { 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } }, + { { 0xFF, 0xFF, 0xFF, 0xFF }, { 1.0f, 1.0f }, { 1.0f, 1.0f, 0.0f } }, + { { 0xFF, 0xFF, 0xFF, 0xFF }, { 0.0f, 1.0f }, { 0.0f, 1.0f, 0.0f } } +}; + +void quadInit() { + meshInit( + &QUAD_MESH_SIMPLE, + QUAD_PRIMITIVE_TYPE, + QUAD_VERTEX_COUNT, + QUAD_MESH_SIMPLE_VERTICES + ); +} + void quadBuffer( meshvertex_t *vertices, const float_t minX, diff --git a/src/display/mesh/quad.h b/src/display/mesh/quad.h index 2bacfb5..860588a 100644 --- a/src/display/mesh/quad.h +++ b/src/display/mesh/quad.h @@ -11,6 +11,14 @@ #define QUAD_VERTEX_COUNT 6 #define QUAD_PRIMITIVE_TYPE MESH_PRIMITIVE_TRIANGLES +extern mesh_t QUAD_MESH_SIMPLE; +extern meshvertex_t QUAD_MESH_SIMPLE_VERTICES[QUAD_VERTEX_COUNT]; + +/** + * Initializes the quad mesh. + */ +void quadInit(); + /** * Buffers a quad into the provided vertex array. * diff --git a/src/scene/test/scenetest.c b/src/scene/test/scenetest.c index 938e1d0..2f6c47a 100644 --- a/src/scene/test/scenetest.c +++ b/src/scene/test/scenetest.c @@ -10,17 +10,9 @@ #include "display/camera.h" #include "display/display.h" #include "display/mesh/meshrenderer.h" - -mesh_t mesh; -meshvertex_t triangle[3] = { - {{255, 0, 0, 255}, {0.0f, 0.0f}, {1.0f, 0.0f}}, // Vertex 1 - {{0, 255, 0, 255}, {1.0f, 0.0f}, {-1.0f, 0.0f}}, // Vertex 2 - {{0, 0, 255, 255}, {0.5f, 1.0f}, {0, 2.0f}} // Vertex 3 -}; +#include "display/mesh/quad.h" void sceneTestAdd(void) { - meshInit(&mesh, MESH_PRIMITIVE_TRIANGLES, 3, triangle); - // Initialize the entity with a camera component ecsid_t camera = ecsEntityAdd(); node_t *node = nodeAdd(camera); @@ -39,5 +31,5 @@ void sceneTestAdd(void) { ecsid_t cube = ecsEntityAdd(); node = nodeAdd(cube); meshrenderer_t *renderer = meshRendererAdd(cube); - renderer->mesh = &mesh; + renderer->mesh = &QUAD_MESH_SIMPLE; } \ No newline at end of file diff --git a/src/time/CMakeLists.txt b/src/time/CMakeLists.txt index d8fd698..4db9ca4 100644 --- a/src/time/CMakeLists.txt +++ b/src/time/CMakeLists.txt @@ -7,4 +7,17 @@ target_sources(${DUSK_TARGET_NAME} PRIVATE time.c -) \ No newline at end of file +) + +# Compiler defs +if(DUSK_TARGET_SYSTEM STREQUAL "linux") + target_compile_definitions(${DUSK_TARGET_NAME} + PRIVATE + DUSK_TIME_SDL2=1 + ) +elseif(DUSK_TARGET_SYSTEM STREQUAL "psp") + target_compile_definitions(${DUSK_TARGET_NAME} + PRIVATE + DUSK_TIME_FIXED=1 + ) +endif() \ No newline at end of file diff --git a/src/time/time.c b/src/time/time.c index 66416c2..05e455b 100644 --- a/src/time/time.c +++ b/src/time/time.c @@ -9,33 +9,31 @@ #include "util/memory.h" #include "assert/assert.h" +#if DUSK_TIME_SDL2 + #include +#endif + dusktime_t TIME; void timeInit(void) { memoryZero(&TIME, sizeof(TIME)); // Set these to something non-zero. - TIME.lastTick = DUSK_TIME_STEP; - TIME.delta = TIME.realDelta = DUSK_TIME_STEP; - TIME.realTime = TIME.time = DUSK_TIME_STEP * 2; + TIME.time = DUSK_TIME_STEP; + TIME.delta = DUSK_TIME_STEP; } void timeUpdate(void) { - TIME.realDelta = timeDeltaGet(); - - #if DUSK_TIME_DYNAMIC - TIME.delta = TIME.realDelta; + float_t delta; + #if DUSK_TIME_SDL2 + delta = (float_t)SDL_GetTicks() / 1000.0f - TIME.time; + #elif DUSK_TIME_FIXED + delta = DUSK_TIME_PLATFORM_STEP; #else - TIME.delta = DUSK_TIME_PLATFORM_STEP; + #error "No time platform defined" #endif - + + TIME.delta = delta; assertTrue(TIME.delta >= 0.0f, "Time delta is negative"); - assertTrue(TIME.realDelta >= 0.0f, "Real time delta is negative"); - TIME.time += TIME.delta; - TIME.realTime += TIME.realDelta; -} - -float_t timeDeltaGet(void) { - return 0.1f; } \ No newline at end of file diff --git a/src/time/time.h b/src/time/time.h index 7c878c8..36a0784 100644 --- a/src/time/time.h +++ b/src/time/time.h @@ -10,26 +10,13 @@ typedef struct { float_t delta; - float_t lastTick; float_t time; - float_t realDelta; - float_t realTime; } dusktime_t; extern dusktime_t TIME; #define DUSK_TIME_STEP (1.0f / 60.0f) // Default to 60FPS -#ifndef DUSK_TIME_DYNAMIC - #define DUSK_TIME_DYNAMIC 1 -#endif - -#if DUSK_TIME_DYNAMIC == 0 - #ifndef DUSK_TIME_PLATFORM_STEP - #define DUSK_TIME_PLATFORM_STEP DUSK_TIME_STEP - #endif -#endif - /** * Initializes the time system. */ @@ -38,15 +25,4 @@ void timeInit(void); /** * Updates the time system */ -void timeUpdate(void); - -#if DUSK_TIME_DYNAMIC == 1 - /** - * Gets the time delta since the last frame, in seconds. Tied to the - * platform. - * - * This will only get called once per gameUpdate. - */ - float_t timeDeltaGet(void); -#endif - +void timeUpdate(void); \ No newline at end of file