Removed DUSK_ prefix

This commit is contained in:
2025-08-23 10:13:49 -05:00
parent 1bf6fe6eaf
commit 1dfde00317
28 changed files with 148 additions and 101 deletions

View File

@@ -289,7 +289,7 @@ void consoleUpdate() {
exec->cmd->function(exec); exec->cmd->function(exec);
} }
// #if DUSK_KEYBOARD_SUPPORT == 1 // #if KEYBOARD_SUPPORT == 1
// uint8_t key; // uint8_t key;
// while((key = inputKeyboardPop()) != 0) { // while((key = inputKeyboardPop()) != 0) {
// printf("Key pressed: %c\n", key); // printf("Key pressed: %c\n", key);

View File

@@ -41,7 +41,7 @@ typedef struct {
bool_t visible; bool_t visible;
// May move these later // May move these later
// #if DUSK_KEYBOARD_SUPPORT == 1 // #if KEYBOARD_SUPPORT == 1
// char_t inputBuffer[CONSOLE_LINE_MAX]; // char_t inputBuffer[CONSOLE_LINE_MAX];
// int32_t inputIndex; // int32_t inputIndex;
// #endif // #endif

View File

@@ -37,14 +37,14 @@ void gameUpdate(void) {
// Game logic is tied to 60FPS for now, saves me a lot of hassle with float // Game logic is tied to 60FPS for now, saves me a lot of hassle with float
// issues // issues
float_t timeSinceLastTick = TIME.time - TIME.lastTick; float_t timeSinceLastTick = TIME.time - TIME.lastTick;
while(timeSinceLastTick >= DUSK_TIME_STEP) { while(timeSinceLastTick >= TIME_STEP) {
sceneUpdate(); sceneUpdate();
uiTextboxUpdate(); uiTextboxUpdate();
eventUpdate(); eventUpdate();
inputUpdate(); inputUpdate();
timeSinceLastTick -= DUSK_TIME_STEP; timeSinceLastTick -= TIME_STEP;
TIME.lastTick = TIME.time; TIME.lastTick = TIME.time;
} }

View File

@@ -15,18 +15,18 @@ void timeInit(void) {
memoryZero(&TIME, sizeof(TIME)); memoryZero(&TIME, sizeof(TIME));
// Set these to something non-zero. // Set these to something non-zero.
TIME.lastTick = DUSK_TIME_STEP; TIME.lastTick = TIME_STEP;
TIME.delta = TIME.realDelta = DUSK_TIME_STEP; TIME.delta = TIME.realDelta = TIME_STEP;
TIME.realTime = TIME.time = DUSK_TIME_STEP * 2; TIME.realTime = TIME.time = TIME_STEP * 2;
} }
void timeUpdate(void) { void timeUpdate(void) {
TIME.realDelta = timeDeltaGet(); TIME.realDelta = timeDeltaGet();
#if DUSK_TIME_DYNAMIC #if TIME_DYNAMIC
TIME.delta = TIME.realDelta; TIME.delta = TIME.realDelta;
#else #else
TIME.delta = DUSK_TIME_PLATFORM_STEP; TIME.delta = TIME_PLATFORM_STEP;
#endif #endif
assertTrue(TIME.delta >= 0.0f, "Time delta is negative"); assertTrue(TIME.delta >= 0.0f, "Time delta is negative");

View File

@@ -18,15 +18,15 @@ typedef struct {
extern dusktime_t TIME; extern dusktime_t TIME;
#define DUSK_TIME_STEP (1.0f / 60.0f) // Default to 60FPS #define TIME_STEP (1.0f / 60.0f) // Default to 60FPS
#ifndef DUSK_TIME_DYNAMIC #ifndef TIME_DYNAMIC
#define DUSK_TIME_DYNAMIC 1 #define TIME_DYNAMIC 1
#endif #endif
#if DUSK_TIME_DYNAMIC == 0 #if TIME_DYNAMIC == 0
#ifndef DUSK_TIME_PLATFORM_STEP #ifndef TIME_PLATFORM_STEP
#define DUSK_TIME_PLATFORM_STEP DUSK_TIME_STEP #define TIME_PLATFORM_STEP TIME_STEP
#endif #endif
#endif #endif
@@ -40,7 +40,7 @@ void timeInit(void);
*/ */
void timeUpdate(void); void timeUpdate(void);
#if DUSK_TIME_DYNAMIC == 1 #if TIME_DYNAMIC == 1
/** /**
* Gets the time delta since the last frame, in seconds. Tied to the * Gets the time delta since the last frame, in seconds. Tied to the
* platform. * platform.

View File

@@ -27,7 +27,7 @@ void consoleInit() {
consolePrint(" = Dawn Console = "); consolePrint(" = Dawn Console = ");
#if DUSK_CONSOLE_POSIX #if CONSOLE_POSIX
threadInit(&CONSOLE.thread, consoleInputThread); threadInit(&CONSOLE.thread, consoleInputThread);
threadMutexInit(&CONSOLE.execMutex); threadMutexInit(&CONSOLE.execMutex);
threadStartRequest(&CONSOLE.thread); threadStartRequest(&CONSOLE.thread);
@@ -75,7 +75,7 @@ void consolePrint(const char_t *message, ...) {
} }
void consoleExec(const char_t *line) { void consoleExec(const char_t *line) {
#if DUSK_CONSOLE_POSIX #if CONSOLE_POSIX
threadMutexLock(&CONSOLE.execMutex); threadMutexLock(&CONSOLE.execMutex);
#endif #endif
@@ -279,13 +279,13 @@ void consoleExec(const char_t *line) {
} }
} }
#if DUSK_CONSOLE_POSIX #if CONSOLE_POSIX
threadMutexUnlock(&CONSOLE.execMutex); threadMutexUnlock(&CONSOLE.execMutex);
#endif #endif
} }
void consoleUpdate() { void consoleUpdate() {
#if DUSK_CONSOLE_POSIX #if CONSOLE_POSIX
threadMutexLock(&CONSOLE.execMutex); threadMutexLock(&CONSOLE.execMutex);
#endif #endif
@@ -298,13 +298,13 @@ void consoleUpdate() {
// Clear the exec buffer // Clear the exec buffer
CONSOLE.execBufferCount = 0; CONSOLE.execBufferCount = 0;
#if DUSK_CONSOLE_POSIX #if CONSOLE_POSIX
threadMutexUnlock(&CONSOLE.execMutex); threadMutexUnlock(&CONSOLE.execMutex);
#endif #endif
} }
void consoleDispose(void) { void consoleDispose(void) {
#if DUSK_CONSOLE_POSIX #if CONSOLE_POSIX
threadStop(&CONSOLE.thread); threadStop(&CONSOLE.thread);
threadMutexDispose(&CONSOLE.execMutex); threadMutexDispose(&CONSOLE.execMutex);
#endif #endif
@@ -312,7 +312,7 @@ void consoleDispose(void) {
consolePrint(" = Console shutting down = "); consolePrint(" = Console shutting down = ");
} }
#if DUSK_CONSOLE_POSIX #if CONSOLE_POSIX
void consoleInputThread(thread_t *thread) { void consoleInputThread(thread_t *thread) {
assertNotNull(thread, "Thread cannot be NULL."); assertNotNull(thread, "Thread cannot be NULL.");
@@ -325,7 +325,7 @@ void consoleDispose(void) {
}; };
while(!threadShouldStop(thread) && ENGINE.running) { while(!threadShouldStop(thread) && ENGINE.running) {
int32_t rc = poll(&pfd, 1, DUSK_CONSOLE_POSIX_POLL_RATE); int32_t rc = poll(&pfd, 1, CONSOLE_POSIX_POLL_RATE);
if(rc == 0) continue; if(rc == 0) continue;
if(rc < 0) { if(rc < 0) {

View File

@@ -9,12 +9,12 @@
#include "consolevar.h" #include "consolevar.h"
#include "consolecmd.h" #include "consolecmd.h"
#if DUSK_CONSOLE_POSIX #if CONSOLE_POSIX
#include "thread/thread.h" #include "thread/thread.h"
#include <poll.h> #include <poll.h>
#include <unistd.h> #include <unistd.h>
#define DUSK_CONSOLE_POSIX_POLL_RATE 75 #define CONSOLE_POSIX_POLL_RATE 75
#endif #endif
typedef enum { typedef enum {
@@ -48,7 +48,7 @@ typedef struct {
bool_t visible; bool_t visible;
#if DUSK_CONSOLE_POSIX #if CONSOLE_POSIX
char_t inputBuffer[CONSOLE_LINE_MAX]; char_t inputBuffer[CONSOLE_LINE_MAX];
thread_t thread; thread_t thread;
threadmutex_t execMutex; threadmutex_t execMutex;
@@ -114,7 +114,7 @@ void consoleUpdate();
*/ */
void consoleDispose(void); void consoleDispose(void);
#if DUSK_CONSOLE_POSIX #if CONSOLE_POSIX
/** /**
* Input thread handler for posix input. * Input thread handler for posix input.
* *

View File

@@ -19,17 +19,18 @@ add_subdirectory(texture)
if(DUSK_TARGET_SYSTEM STREQUAL "linux") if(DUSK_TARGET_SYSTEM STREQUAL "linux")
target_compile_definitions(${DUSK_TARGET_NAME} target_compile_definitions(${DUSK_TARGET_NAME}
PRIVATE PRIVATE
DUSK_DISPLAY_SDL2=1 DISPLAY_SDL2=1
DISPLAY_WINDOW_WIDTH_DEFAULT=960 DISPLAY_WINDOW_WIDTH_DEFAULT=960
DISPLAY_WINDOW_HEIGHT_DEFAULT=720 DISPLAY_WINDOW_HEIGHT_DEFAULT=720
) )
elseif(DUSK_TARGET_SYSTEM STREQUAL "psp") elseif(DUSK_TARGET_SYSTEM STREQUAL "psp")
target_compile_definitions(${DUSK_TARGET_NAME} target_compile_definitions(${DUSK_TARGET_NAME}
PRIVATE PRIVATE
DUSK_DISPLAY_SDL2=1 DISPLAY_SDL2=1
DISPLAY_WINDOW_WIDTH_DEFAULT=480 DISPLAY_WINDOW_WIDTH_DEFAULT=480
DISPLAY_WINDOW_HEIGHT_DEFAULT=272 DISPLAY_WINDOW_HEIGHT_DEFAULT=272
DISPLAY_WIDTH=480 DISPLAY_WIDTH=480
DISPLAY_HEIGHT=272 DISPLAY_HEIGHT=272
DISPLAY_SIZE_DYNAMIC=0
) )
endif() endif()

View File

@@ -30,7 +30,6 @@ void cameraEntityAdded(const ecsid_t id) {
cam->perspective.fov = glm_rad(90.0f); cam->perspective.fov = glm_rad(90.0f);
cam->nearClip = 0.1f; cam->nearClip = 0.1f;
cam->farClip = 1000.0f; cam->farClip = 1000.0f;
cam->clearColor = COLOR_CORNFLOWER_BLUE;
} }
void cameraPush(const ecsid_t id) { void cameraPush(const ecsid_t id) {
@@ -67,7 +66,7 @@ void cameraPush(const ecsid_t id) {
); );
} }
#if DUSK_DISPLAY_SDL2 #if DISPLAY_SDL2
mat4 pv; mat4 pv;
glm_mat4_mul(projection, view, pv); glm_mat4_mul(projection, view, pv);
@@ -76,21 +75,13 @@ void cameraPush(const ecsid_t id) {
glLoadIdentity(); glLoadIdentity();
glLoadMatrixf((const GLfloat*)pv); glLoadMatrixf((const GLfloat*)pv);
glClearColor(
cam->clearColor.r / 255.0f,
cam->clearColor.g / 255.0f,
cam->clearColor.b / 255.0f,
cam->clearColor.a / 255.0f
);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
#endif #endif
} }
void cameraPop(void) { void cameraPop(void) {
#if DUSK_DISPLAY_SDL2 #if DISPLAY_SDL2
glPopMatrix(); glPopMatrix();
#endif #endif
} }

View File

@@ -32,7 +32,6 @@ typedef struct {
float_t nearClip; float_t nearClip;
float_t farClip; float_t farClip;
color_t clearColor;
} camera_t; } camera_t;
extern camera_t CAMERA_DATA[ECS_ENTITY_COUNT_MAX]; extern camera_t CAMERA_DATA[ECS_ENTITY_COUNT_MAX];

View File

@@ -16,7 +16,7 @@
display_t DISPLAY; display_t DISPLAY;
errorret_t displayInit(void) { errorret_t displayInit(void) {
#if DUSK_DISPLAY_SDL2 #if DISPLAY_SDL2
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) != 0) { if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) != 0) {
errorThrow("SDL Failed to Initialize: %s", SDL_GetError()); errorThrow("SDL Failed to Initialize: %s", SDL_GetError());
} }
@@ -65,7 +65,7 @@ errorret_t displayInit(void) {
} }
errorret_t displayUpdate(void) { errorret_t displayUpdate(void) {
#if DUSK_DISPLAY_SDL2 #if DISPLAY_SDL2
SDL_Event event; SDL_Event event;
while(SDL_PollEvent(&event)) { while(SDL_PollEvent(&event)) {
switch(event.type) { switch(event.type) {
@@ -86,7 +86,7 @@ errorret_t displayUpdate(void) {
rendererRender(CAMERA_MAIN); rendererRender(CAMERA_MAIN);
#if DUSK_DISPLAY_SDL2 #if DISPLAY_SDL2
SDL_GL_SwapWindow(DISPLAY.window); SDL_GL_SwapWindow(DISPLAY.window);
#endif #endif
@@ -95,7 +95,7 @@ errorret_t displayUpdate(void) {
} }
errorret_t displayDispose(void) { errorret_t displayDispose(void) {
#if DUSK_DISPLAY_SDL2 #if DISPLAY_SDL2
if(DISPLAY.glContext) { if(DISPLAY.glContext) {
SDL_GL_DeleteContext(DISPLAY.glContext); SDL_GL_DeleteContext(DISPLAY.glContext);
DISPLAY.glContext = NULL; DISPLAY.glContext = NULL;

View File

@@ -8,11 +8,15 @@
#pragma once #pragma once
#include "error/error.h" #include "error/error.h"
#if DUSK_DISPLAY_SDL2 #if DISPLAY_SDL2
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#define GL_GLEXT_PROTOTYPES #define GL_GLEXT_PROTOTYPES
#include <GL/gl.h> #include <GL/gl.h>
#include <GL/glext.h> #include <GL/glext.h>
#ifndef DISPLAY_SIZE_DYNAMIC
#define DISPLAY_SIZE_DYNAMIC 1
#endif
#else #else
#error "Need to specify display backend." #error "Need to specify display backend."
#endif #endif
@@ -31,8 +35,10 @@
#define DISPLAY_WINDOW_HEIGHT_DEFAULT DISPLAY_HEIGHT #define DISPLAY_WINDOW_HEIGHT_DEFAULT DISPLAY_HEIGHT
#endif #endif
typedef struct { typedef struct {
#if DUSK_DISPLAY_SDL2 #if DISPLAY_SDL2
SDL_Window *window; SDL_Window *window;
SDL_GLContext glContext; SDL_GLContext glContext;
#endif #endif

View File

@@ -20,11 +20,15 @@ void frameBufferInitBackbuffer() {
} }
int32_t frameBufferGetWidth(const framebuffer_t *framebuffer) { int32_t frameBufferGetWidth(const framebuffer_t *framebuffer) {
#if DUSK_DISPLAY_SDL2 #if DISPLAY_SDL2
if(framebuffer == &FRAMEBUFFER_BACKBUFFER) { if(framebuffer == &FRAMEBUFFER_BACKBUFFER) {
int32_t windowWidth, windowHeight; #if DISPLAY_SIZE_DYNAMIC == 0
SDL_GetWindowSize(DISPLAY.window, &windowWidth, &windowHeight); return DISPLAY_WIDTH;
return windowWidth; #else
int32_t windowWidth, windowHeight;
SDL_GetWindowSize(DISPLAY.window, &windowWidth, &windowHeight);
return windowWidth;
#endif
} }
assertUnreachable("Framebuffer width not implemented"); assertUnreachable("Framebuffer width not implemented");
@@ -33,11 +37,15 @@ int32_t frameBufferGetWidth(const framebuffer_t *framebuffer) {
} }
int32_t frameBufferGetHeight(const framebuffer_t *framebuffer) { int32_t frameBufferGetHeight(const framebuffer_t *framebuffer) {
#if DUSK_DISPLAY_SDL2 #if DISPLAY_SDL2
if(framebuffer == &FRAMEBUFFER_BACKBUFFER) { if(framebuffer == &FRAMEBUFFER_BACKBUFFER) {
int32_t windowWidth, windowHeight; #if DISPLAY_SIZE_DYNAMIC == 0
SDL_GetWindowSize(DISPLAY.window, &windowWidth, &windowHeight); return DISPLAY_HEIGHT;
return windowHeight; #else
int32_t windowWidth, windowHeight;
SDL_GetWindowSize(DISPLAY.window, &windowWidth, &windowHeight);
return windowHeight;
#endif
} }
assertUnreachable("Framebuffer height not implemented"); assertUnreachable("Framebuffer height not implemented");
@@ -47,7 +55,7 @@ int32_t frameBufferGetHeight(const framebuffer_t *framebuffer) {
void frameBufferBind(const framebuffer_t *framebuffer) { void frameBufferBind(const framebuffer_t *framebuffer) {
if(framebuffer == NULL) { if(framebuffer == NULL) {
#if DUSK_DISPLAY_SDL2 #if DISPLAY_SDL2
frameBufferBind(&FRAMEBUFFER_BACKBUFFER); frameBufferBind(&FRAMEBUFFER_BACKBUFFER);
#endif #endif
@@ -56,14 +64,19 @@ void frameBufferBind(const framebuffer_t *framebuffer) {
} }
// Bind the framebuffer for rendering // Bind the framebuffer for rendering
#if DUSK_DISPLAY_SDL2 #if DISPLAY_SDL2
if(framebuffer == &FRAMEBUFFER_BACKBUFFER) { if(framebuffer == &FRAMEBUFFER_BACKBUFFER) {
#if PSP
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); #else
int32_t windowWidth, windowHeight; glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
SDL_GetWindowSize(DISPLAY.window, &windowWidth, &windowHeight); #endif
} else { } else {
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer->id); #if PSP
assertUnreachable("Framebuffers not supported on PSP");
#else
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer->id);
#endif
} }
glViewport( glViewport(
0, 0, 0, 0,
@@ -74,6 +87,28 @@ void frameBufferBind(const framebuffer_t *framebuffer) {
FRAMEBUFFER_BOUND = framebuffer; FRAMEBUFFER_BOUND = framebuffer;
} }
void frameBufferClear(uint8_t flags, color_t color) {
#if DISPLAY_SDL2
GLbitfield glFlags = 0;
if(flags & FRAMEBUFFER_CLEAR_COLOR) {
glFlags |= GL_COLOR_BUFFER_BIT;
glClearColor(
color.r / 255.0f,
color.g / 255.0f,
color.b / 255.0f,
color.a / 255.0f
);
}
if(flags & FRAMEBUFFER_CLEAR_DEPTH) {
glFlags |= GL_DEPTH_BUFFER_BIT;
}
glClear(glFlags);
#endif
}
/** /**
* Disposes of the framebuffer using EXT methods. * Disposes of the framebuffer using EXT methods.
* *
@@ -82,7 +117,7 @@ void frameBufferBind(const framebuffer_t *framebuffer) {
void frameBufferDispose(framebuffer_t *framebuffer) { void frameBufferDispose(framebuffer_t *framebuffer) {
assertNotNull(framebuffer, "Framebuffer cannot be NULL"); assertNotNull(framebuffer, "Framebuffer cannot be NULL");
#if DUSK_DISPLAY_SDL2 #if DISPLAY_SDL2
if(framebuffer == &FRAMEBUFFER_BACKBUFFER) { if(framebuffer == &FRAMEBUFFER_BACKBUFFER) {
assertUnreachable("Cannot dispose of backbuffer"); assertUnreachable("Cannot dispose of backbuffer");
} }

View File

@@ -9,8 +9,11 @@
#include "display/display.h" #include "display/display.h"
#include "display/texture/texture.h" #include "display/texture/texture.h"
#define FRAMEBUFFER_CLEAR_COLOR (1 << 0)
#define FRAMEBUFFER_CLEAR_DEPTH (1 << 1)
typedef struct { typedef struct {
#if DUSK_DISPLAY_SDL2 #if DISPLAY_SDL2
// OpenGL Framebuffer Object ID // OpenGL Framebuffer Object ID
GLuint id; GLuint id;
#endif #endif
@@ -45,6 +48,14 @@ int32_t frameBufferGetHeight(const framebuffer_t *framebuffer);
*/ */
void frameBufferBind(const framebuffer_t *framebuffer); void frameBufferBind(const framebuffer_t *framebuffer);
/**
* Clears the currently bound framebuffer.
*
* @param flags The clear flags.
* @param color The color to clear the color buffer to (if clearing color).
*/
void frameBufferClear(uint8_t flags, color_t color);
/** /**
* Disposes of the framebuffer using EXT methods. * Disposes of the framebuffer using EXT methods.
* *

View File

@@ -43,7 +43,7 @@ void meshDraw(
"Vertex offset + count must not exceed vertex count" "Vertex offset + count must not exceed vertex count"
); );
#if DUSK_DISPLAY_SDL2 #if DISPLAY_SDL2
// PSP style pointer legacy OpenGL // PSP style pointer legacy OpenGL
const GLsizei stride = sizeof(meshvertex_t); const GLsizei stride = sizeof(meshvertex_t);

View File

@@ -7,7 +7,7 @@
#include "display/display.h" #include "display/display.h"
typedef enum { typedef enum {
#if DUSK_DISPLAY_SDL2 #if DISPLAY_SDL2
MESH_PRIMITIVE_TRIANGLES = GL_TRIANGLES, MESH_PRIMITIVE_TRIANGLES = GL_TRIANGLES,
MESH_PRIMITIVE_LINES = GL_LINES, MESH_PRIMITIVE_LINES = GL_LINES,
MESH_PRIMITIVE_POINTS = GL_POINTS, MESH_PRIMITIVE_POINTS = GL_POINTS,
@@ -19,7 +19,7 @@ typedef enum {
#define MESH_VERTEX_POS_SIZE 3 #define MESH_VERTEX_POS_SIZE 3
typedef struct { typedef struct {
#if DUSK_DISPLAY_SDL2 #if DISPLAY_SDL2
GLubyte color[MESH_VERTEX_COLOR_SIZE]; GLubyte color[MESH_VERTEX_COLOR_SIZE];
GLfloat uv[MESH_VERTEX_UV_SIZE]; GLfloat uv[MESH_VERTEX_UV_SIZE];
GLfloat pos[MESH_VERTEX_POS_SIZE]; GLfloat pos[MESH_VERTEX_POS_SIZE];

View File

@@ -20,6 +20,10 @@ void rendererRender(const ecsid_t camera) {
meshCount = meshRendererGetAll(meshes); meshCount = meshRendererGetAll(meshes);
frameBufferBind(NULL); frameBufferBind(NULL);
frameBufferClear(
FRAMEBUFFER_CLEAR_COLOR | FRAMEBUFFER_CLEAR_DEPTH,
COLOR_CORNFLOWER_BLUE
);
cameraPush(camera); cameraPush(camera);
for(uint32_t i = 0; i < meshCount; i++) { for(uint32_t i = 0; i < meshCount; i++) {
id = meshes[i]; id = meshes[i];

View File

@@ -37,7 +37,7 @@ void textureInit(
); );
#endif #endif
#if DUSK_DISPLAY_SDL2 #if DISPLAY_SDL2
glGenTextures(1, &texture->id); glGenTextures(1, &texture->id);
glBindTexture(GL_TEXTURE_2D, texture->id); glBindTexture(GL_TEXTURE_2D, texture->id);
glTexImage2D( glTexImage2D(
@@ -58,7 +58,7 @@ void textureBind(const texture_t *texture) {
if(TEXTURE_BOUND == texture) return; if(TEXTURE_BOUND == texture) return;
if(texture == NULL) { if(texture == NULL) {
#if DUSK_DISPLAY_SDL2 #if DISPLAY_SDL2
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
#endif #endif
TEXTURE_BOUND = NULL; TEXTURE_BOUND = NULL;
@@ -74,7 +74,7 @@ void textureBind(const texture_t *texture) {
"Texture width and height must be greater than 0" "Texture width and height must be greater than 0"
); );
#if DUSK_DISPLAY_SDL2 #if DISPLAY_SDL2
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture->id); glBindTexture(GL_TEXTURE_2D, texture->id);
#endif #endif
@@ -85,7 +85,7 @@ void textureDispose(texture_t *texture) {
assertNotNull(texture, "Texture cannot be NULL"); assertNotNull(texture, "Texture cannot be NULL");
assertTrue(texture->id != 0, "Texture ID must not be 0"); assertTrue(texture->id != 0, "Texture ID must not be 0");
#if DUSK_DISPLAY_SDL2 #if DISPLAY_SDL2
glDeleteTextures(1, &texture->id); glDeleteTextures(1, &texture->id);
#endif #endif
} }

View File

@@ -10,14 +10,14 @@
#include "display/color.h" #include "display/color.h"
typedef enum { typedef enum {
#if DUSK_DISPLAY_SDL2 #if DISPLAY_SDL2
TEXTURE_FORMAT_RGBA = GL_RGBA, TEXTURE_FORMAT_RGBA = GL_RGBA,
TEXTURE_FORMAT_ALPHA = GL_ALPHA, TEXTURE_FORMAT_ALPHA = GL_ALPHA,
#endif #endif
} textureformat_t; } textureformat_t;
typedef struct { typedef struct {
#if DUSK_DISPLAY_SDL2 #if DISPLAY_SDL2
GLuint id; GLuint id;
#endif #endif

View File

@@ -116,14 +116,14 @@ void nodeMatrixPush(const ecsid_t id) {
assertTrue(nodeHas(id), "Not a node component"); assertTrue(nodeHas(id), "Not a node component");
node_t *node = nodeGet(id); node_t *node = nodeGet(id);
#if DUSK_DISPLAY_SDL2 #if DISPLAY_SDL2
glPushMatrix(); glPushMatrix();
glMultMatrixf((const GLfloat*)node->transform); glMultMatrixf((const GLfloat*)node->transform);
#endif #endif
} }
void nodeMatrixPop(void) { void nodeMatrixPop(void) {
#if DUSK_DISPLAY_SDL2 #if DISPLAY_SDL2
glPopMatrix(); glPopMatrix();
#endif #endif
} }

View File

@@ -14,11 +14,11 @@ target_sources(${DUSK_TARGET_NAME}
if(DUSK_TARGET_SYSTEM STREQUAL "linux") if(DUSK_TARGET_SYSTEM STREQUAL "linux")
target_compile_definitions(${DUSK_TARGET_NAME} target_compile_definitions(${DUSK_TARGET_NAME}
PRIVATE PRIVATE
DUSK_THREAD_PTHREAD=1 THREAD_PTHREAD=1
) )
elseif(DUSK_TARGET_SYSTEM STREQUAL "psp") elseif(DUSK_TARGET_SYSTEM STREQUAL "psp")
target_compile_definitions(${DUSK_TARGET_NAME} target_compile_definitions(${DUSK_TARGET_NAME}
PRIVATE PRIVATE
DUSK_THREAD_PTHREAD=1 THREAD_PTHREAD=1
) )
endif() endif()

View File

@@ -18,7 +18,7 @@ void threadInit(thread_t *thread, const threadcallback_t callback) {
thread->state = THREAD_STATE_STOPPED; thread->state = THREAD_STATE_STOPPED;
thread->callback = callback; thread->callback = callback;
#if DUSK_THREAD_PTHREAD #if THREAD_PTHREAD
thread->threadId = 0; thread->threadId = 0;
#endif #endif
} }
@@ -30,7 +30,7 @@ void threadStartRequest(thread_t *thread) {
thread->state = THREAD_STATE_STARTING; thread->state = THREAD_STATE_STARTING;
threadMutexUnlock(&thread->stateMutex); threadMutexUnlock(&thread->stateMutex);
#if DUSK_THREAD_PTHREAD #if THREAD_PTHREAD
assertTrue(thread->threadId == 0, "Thread id not 0."); assertTrue(thread->threadId == 0, "Thread id not 0.");
pthread_create( pthread_create(
@@ -93,7 +93,7 @@ bool_t threadShouldStop(thread_t *thread) {
return state; return state;
} }
#if DUSK_THREAD_PTHREAD #if THREAD_PTHREAD
void * threadHandler(thread_t *thread) { void * threadHandler(thread_t *thread) {
assertNotNull(thread, "Thread cannot be NULL."); assertNotNull(thread, "Thread cannot be NULL.");

View File

@@ -8,7 +8,7 @@
#pragma once #pragma once
#include "thread/threadmutex.h" #include "thread/threadmutex.h"
#if DUSK_THREAD_PTHREAD #if THREAD_PTHREAD
#include <pthread.h> #include <pthread.h>
#else #else
#error "At least one threading implementation must be defined." #error "At least one threading implementation must be defined."
@@ -40,7 +40,7 @@ typedef struct thread_s {
threadcallback_t callback; threadcallback_t callback;
void *data; void *data;
#if DUSK_THREAD_PTHREAD #if THREAD_PTHREAD
pthread_t threadId; pthread_t threadId;
#endif #endif
} thread_t; } thread_t;
@@ -93,7 +93,7 @@ void threadStop(thread_t *thread);
*/ */
bool_t threadShouldStop(thread_t *thread); bool_t threadShouldStop(thread_t *thread);
#if DUSK_THREAD_PTHREAD #if THREAD_PTHREAD
/** /**
* Handles the thread's lifecycle for pthreads. * Handles the thread's lifecycle for pthreads.
* @param thread Pointer to the thread structure to handle. * @param thread Pointer to the thread structure to handle.

View File

@@ -8,43 +8,43 @@
#include "threadmutex.h" #include "threadmutex.h"
void threadMutexInit(threadmutex_t *lock) { void threadMutexInit(threadmutex_t *lock) {
#if DUSK_THREAD_PTHREAD #if THREAD_PTHREAD
pthread_mutex_init(&lock->mutex, NULL); pthread_mutex_init(&lock->mutex, NULL);
#endif #endif
} }
void threadMutexLock(threadmutex_t *lock) { void threadMutexLock(threadmutex_t *lock) {
#if DUSK_THREAD_PTHREAD #if THREAD_PTHREAD
pthread_mutex_lock(&lock->mutex); pthread_mutex_lock(&lock->mutex);
#endif #endif
} }
bool_t threadMutexTryLock(threadmutex_t *lock) { bool_t threadMutexTryLock(threadmutex_t *lock) {
#if DUSK_THREAD_PTHREAD #if THREAD_PTHREAD
return pthread_mutex_trylock(&lock->mutex) == 0; return pthread_mutex_trylock(&lock->mutex) == 0;
#endif #endif
} }
void threadMutexUnlock(threadmutex_t *lock) { void threadMutexUnlock(threadmutex_t *lock) {
#if DUSK_THREAD_PTHREAD #if THREAD_PTHREAD
pthread_mutex_unlock(&lock->mutex); pthread_mutex_unlock(&lock->mutex);
#endif #endif
} }
void threadMutexWaitLock(threadmutex_t *lock) { void threadMutexWaitLock(threadmutex_t *lock) {
#if DUSK_THREAD_PTHREAD #if THREAD_PTHREAD
pthread_cond_wait(&lock->cond, &lock->mutex); pthread_cond_wait(&lock->cond, &lock->mutex);
#endif #endif
} }
void threadMutexSignal(threadmutex_t *lock) { void threadMutexSignal(threadmutex_t *lock) {
#if DUSK_THREAD_PTHREAD #if THREAD_PTHREAD
pthread_cond_signal(&lock->cond); pthread_cond_signal(&lock->cond);
#endif #endif
} }
void threadMutexDispose(threadmutex_t *lock) { void threadMutexDispose(threadmutex_t *lock) {
#if DUSK_THREAD_PTHREAD #if THREAD_PTHREAD
pthread_mutex_destroy(&lock->mutex); pthread_mutex_destroy(&lock->mutex);
#endif #endif
} }

View File

@@ -8,14 +8,14 @@
#pragma once #pragma once
#include "dusk.h" #include "dusk.h"
#if DUSK_THREAD_PTHREAD #if THREAD_PTHREAD
#include <pthread.h> #include <pthread.h>
#else #else
#error "At least one threading implementation must be defined." #error "At least one threading implementation must be defined."
#endif #endif
typedef struct threadlock_t { typedef struct threadlock_t {
#if DUSK_THREAD_PTHREAD #if THREAD_PTHREAD
pthread_mutex_t mutex; pthread_mutex_t mutex;
pthread_cond_t cond; pthread_cond_t cond;
#endif #endif

View File

@@ -13,11 +13,11 @@ target_sources(${DUSK_TARGET_NAME}
if(DUSK_TARGET_SYSTEM STREQUAL "linux") if(DUSK_TARGET_SYSTEM STREQUAL "linux")
target_compile_definitions(${DUSK_TARGET_NAME} target_compile_definitions(${DUSK_TARGET_NAME}
PRIVATE PRIVATE
DUSK_TIME_SDL2=1 TIME_SDL2=1
) )
elseif(DUSK_TARGET_SYSTEM STREQUAL "psp") elseif(DUSK_TARGET_SYSTEM STREQUAL "psp")
target_compile_definitions(${DUSK_TARGET_NAME} target_compile_definitions(${DUSK_TARGET_NAME}
PRIVATE PRIVATE
DUSK_TIME_FIXED=1 TIME_FIXED=1
) )
endif() endif()

View File

@@ -9,7 +9,7 @@
#include "util/memory.h" #include "util/memory.h"
#include "assert/assert.h" #include "assert/assert.h"
#if DUSK_TIME_SDL2 #if TIME_SDL2
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#endif #endif
@@ -19,16 +19,16 @@ void timeInit(void) {
memoryZero(&TIME, sizeof(TIME)); memoryZero(&TIME, sizeof(TIME));
// Set these to something non-zero. // Set these to something non-zero.
TIME.time = DUSK_TIME_STEP; TIME.time = TIME_STEP;
TIME.delta = DUSK_TIME_STEP; TIME.delta = TIME_STEP;
} }
void timeUpdate(void) { void timeUpdate(void) {
float_t delta; float_t delta;
#if DUSK_TIME_SDL2 #if TIME_SDL2
delta = (float_t)SDL_GetTicks() / 1000.0f - TIME.time; delta = (float_t)SDL_GetTicks() / 1000.0f - TIME.time;
#elif DUSK_TIME_FIXED #elif TIME_FIXED
delta = DUSK_TIME_PLATFORM_STEP; delta = TIME_PLATFORM_STEP;
#else #else
#error "No time platform defined" #error "No time platform defined"
#endif #endif

View File

@@ -15,7 +15,7 @@ typedef struct {
extern dusktime_t TIME; extern dusktime_t TIME;
#define DUSK_TIME_STEP (1.0f / 60.0f) // Default to 60FPS #define TIME_STEP (1.0f / 60.0f) // Default to 60FPS
/** /**
* Initializes the time system. * Initializes the time system.