Fixed time.

This commit is contained in:
2025-08-22 22:42:38 -05:00
parent 1fb9485ee8
commit 995bbe1acd
9 changed files with 68 additions and 63 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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,

View File

@@ -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.
*

View File

@@ -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;
}

View File

@@ -7,4 +7,17 @@
target_sources(${DUSK_TARGET_NAME}
PRIVATE
time.c
)
)
# 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()

View File

@@ -9,33 +9,31 @@
#include "util/memory.h"
#include "assert/assert.h"
#if DUSK_TIME_SDL2
#include <SDL2/SDL.h>
#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;
}

View File

@@ -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);