From dd910a31aae9344cb777cf9a97f3e2cc792e75f9 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Wed, 4 Feb 2026 17:44:53 -0600 Subject: [PATCH] Actually compiled --- .ci/dolphin/build.sh | 3 +- CMakeLists.txt | 31 ++------ src/display/CMakeLists.txt | 1 - src/display/display.c | 9 ++- src/display/displaydefs.h | 20 ++--- src/display/framebuffer.c | 10 +-- src/display/framebuffer.h | 3 + src/display/mesh/mesh.h | 12 +-- src/display/texture.c | 14 +--- src/display/texture.h | 6 ++ src/input/CMakeLists.txt | 3 +- src/input/inputbutton.c | 25 +++++- src/input/inputbutton.h | 13 +++ src2/CMakeLists.txt | 27 ------- src2/main.c | 159 ------------------------------------- src2/null.c | 10 --- src2/sdl_assets_loader.c | 74 ----------------- src2/sdl_assets_loader.h | 20 ----- src2/sdl_starter.c | 55 ------------- src2/sdl_starter.h | 15 ---- 20 files changed, 80 insertions(+), 430 deletions(-) delete mode 100644 src2/CMakeLists.txt delete mode 100644 src2/main.c delete mode 100644 src2/null.c delete mode 100644 src2/sdl_assets_loader.c delete mode 100644 src2/sdl_assets_loader.h delete mode 100644 src2/sdl_starter.c delete mode 100644 src2/sdl_starter.h diff --git a/.ci/dolphin/build.sh b/.ci/dolphin/build.sh index b169069..3f6498a 100755 --- a/.ci/dolphin/build.sh +++ b/.ci/dolphin/build.sh @@ -1,10 +1,11 @@ #!/bin/bash docker build -t myapp:latest -f .ci/dolphin/Dockerfile . docker run -it -v ./:/workdir myapp:latest /bin/bash -c ' \ + export PATH="$DEVKITPPC/bin:$PATH" && \ cd /workdir && \ rm -rf build2 && \ mkdir -p build2 && \ - cmake -S. -Bbuild2 -DDUSK_TARGET_SYSTEM=gamecube -DCMAKE_TOOLCHAIN_FILE="$DEVKITPRO/cmake/GameCube.cmake" + cmake -S. -Bbuild2 -DDUSK_TARGET_SYSTEM=gamecube -DCMAKE_TOOLCHAIN_FILE="$DEVKITPRO/cmake/GameCube.cmake" && \ cd build2 && \ make VERBOSE=1 \ ' diff --git a/CMakeLists.txt b/CMakeLists.txt index 2a84a8e..5fd6c77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,8 @@ # https://opensource.org/licenses/MIT # Setup -cmake_minimum_required(VERSION 3.13) +cmake_minimum_required(VERSION 3.18) + set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) @@ -17,7 +18,7 @@ set(DUSK_CACHE_TARGET "dusk-target") # Build variables set(DUSK_ROOT_DIR "${CMAKE_SOURCE_DIR}") set(DUSK_BUILD_DIR "${CMAKE_BINARY_DIR}") -set(DUSK_SOURCES_DIR "${DUSK_ROOT_DIR}/src2") +set(DUSK_SOURCES_DIR "${DUSK_ROOT_DIR}/src") set(DUSK_TEST_DIR "${DUSK_ROOT_DIR}/test") set(DUSK_TEMP_DIR "${DUSK_BUILD_DIR}/temp") set(DUSK_TOOLS_DIR "${DUSK_ROOT_DIR}/tools") @@ -118,27 +119,11 @@ elseif(DUSK_TARGET_SYSTEM STREQUAL "psp") elseif(DUSK_TARGET_SYSTEM STREQUAL "gamecube" OR DUSK_TARGET_SYSTEM STREQUAL "wii") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions") + configure_file(opengl.pc.in opengl.pc @ONLY) + find_package(PkgConfig REQUIRED) - pkg_check_modules(SDL2 IMPORTED_TARGET sdl2) - pkg_check_modules(SDL2_ttf IMPORTED_TARGET SDL2_ttf) - pkg_check_modules(SDL2_image IMPORTED_TARGET SDL2_image) - pkg_check_modules(SDL2_mixer IMPORTED_TARGET SDL2_mixer) - pkg_check_modules(OPENGL IMPORTED_TARGET opengl) pkg_check_modules(zip IMPORTED_TARGET libzip) - pkg_check_modules(GLU IMPORTED_TARGET glu) - pkg_check_modules(freetype2 IMPORTED_TARGET freetype2) - - - target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC - PkgConfig::SDL2 - PkgConfig::SDL2_ttf - PkgConfig::SDL2_image - PkgConfig::SDL2_mixer - PkgConfig::zip - PkgConfig::GLU - PkgConfig::freetype2 - ) target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC DOLPHIN @@ -169,14 +154,12 @@ elseif(DUSK_TARGET_SYSTEM STREQUAL "gamecube" OR DUSK_TARGET_SYSTEM STREQUAL "wi target_compile_definitions(liblua PRIVATE LUA_USE_C89) add_library(lua::lua ALIAS liblua) set(Lua_FOUND TRUE CACHE BOOL "Lua found" FORCE) - + target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PRIVATE cglm liblua - - stdc++ - ogc m + PkgConfig::zip ) endif() diff --git a/src/display/CMakeLists.txt b/src/display/CMakeLists.txt index 2284adc..71d8fc9 100644 --- a/src/display/CMakeLists.txt +++ b/src/display/CMakeLists.txt @@ -41,7 +41,6 @@ elseif(DUSK_TARGET_SYSTEM STREQUAL "psp") elseif(DUSK_TARGET_SYSTEM STREQUAL "gamecube" OR DUSK_TARGET_SYSTEM STREQUAL "wii") target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC - DISPLAY_SDL2=1 DISPLAY_WINDOW_WIDTH_DEFAULT=640 DISPLAY_WINDOW_HEIGHT_DEFAULT=480 DISPLAY_WIDTH=640 diff --git a/src/display/display.c b/src/display/display.c index 84e78f5..900ebe7 100644 --- a/src/display/display.c +++ b/src/display/display.c @@ -133,12 +133,13 @@ errorret_t displayUpdate(void) { #if DISPLAY_SDL2 SDL_GL_SwapWindow(DISPLAY.window); + + GLenum err; + while((err = glGetError()) != GL_NO_ERROR) { + debugPrint("GL Error: %d\n", err); + } #endif - GLenum err; - while((err = glGetError()) != GL_NO_ERROR) { - debugPrint("GL Error: %d\n", err); - } // For now, we just return an OK error. errorOk(); diff --git a/src/display/displaydefs.h b/src/display/displaydefs.h index 5090210..4b28e41 100644 --- a/src/display/displaydefs.h +++ b/src/display/displaydefs.h @@ -8,25 +8,17 @@ #pragma once #if DISPLAY_SDL2 - #if DOLPHIN - #include "dusk.h" - #include - #include - #include - - #define GL_COLOR_INDEX8_EXT GX_RGBA8 + #include - #else - #include - - #define GL_GLEXT_PROTOTYPES - #include - #include - #endif + #define GL_GLEXT_PROTOTYPES + #include + #include #ifndef DISPLAY_SIZE_DYNAMIC #define DISPLAY_SIZE_DYNAMIC 1 #endif +#elif DOLPHIN + // Dolphin. #else #error "Need to specify display backend." #endif diff --git a/src/display/framebuffer.c b/src/display/framebuffer.c index 54a57c0..7b7e340 100644 --- a/src/display/framebuffer.c +++ b/src/display/framebuffer.c @@ -102,16 +102,12 @@ void frameBufferBind(const framebuffer_t *framebuffer) { if(framebuffer == &FRAMEBUFFER_BACKBUFFER) { #if PSP - #elif DOLPHIN - #else glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); #endif } else { #if PSP assertUnreachable("Framebuffers not supported on PSP"); - #elif DOLPHIN - assertUnreachable("Framebuffers not supported on DOLPHIN"); #else glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer->id); #endif @@ -144,11 +140,7 @@ void frameBufferClear(uint8_t flags, color_t color) { glFlags |= GL_DEPTH_BUFFER_BIT; } - #if DOLPHIN - assertUnreachable("Framebuffers not supported on DOLPHIN"); - #else - glClear(glFlags); - #endif + glClear(glFlags); #endif } diff --git a/src/display/framebuffer.h b/src/display/framebuffer.h index b33b19c..aa63488 100644 --- a/src/display/framebuffer.h +++ b/src/display/framebuffer.h @@ -16,6 +16,9 @@ typedef struct { // OpenGL Framebuffer Object ID GLuint id; texture_t texture; + #elif DOLPHIN + // --- IGNORE --- + uint8_t id; #else #error "Framebuffers not implemented on this platform." #endif diff --git a/src/display/mesh/mesh.h b/src/display/mesh/mesh.h index 56f5ff4..730a96d 100644 --- a/src/display/mesh/mesh.h +++ b/src/display/mesh/mesh.h @@ -12,6 +12,10 @@ typedef enum { MESH_PRIMITIVE_TRIANGLES = GL_TRIANGLES, MESH_PRIMITIVE_LINES = GL_LINES, MESH_PRIMITIVE_POINTS = GL_POINTS, + #elif DOLPHIN + MESH_PRIMITIVE_TRIANGLES = GX_TRIANGLES, + MESH_PRIMITIVE_LINES = GX_LINES, + MESH_PRIMITIVE_POINTS = GX_POINTS, #endif } meshprimitivetype_t; @@ -19,11 +23,9 @@ typedef enum { #define MESH_VERTEX_POS_SIZE 3 typedef struct { - #if DISPLAY_SDL2 - color4b_t color; - GLfloat uv[MESH_VERTEX_UV_SIZE]; - GLfloat pos[MESH_VERTEX_POS_SIZE]; - #endif + color4b_t color; + float uv[MESH_VERTEX_UV_SIZE]; + float pos[MESH_VERTEX_POS_SIZE]; } meshvertex_t; typedef struct { diff --git a/src/display/texture.c b/src/display/texture.c index 6449303..63f24d7 100644 --- a/src/display/texture.c +++ b/src/display/texture.c @@ -77,8 +77,6 @@ void textureInit( #if PSP havePalTex = true; - #elif DOLPHIN - havePalTex = false; #else GLint mask = 0; glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask); @@ -127,14 +125,10 @@ void textureInit( GL_UNSIGNED_BYTE, (void*)data.palette.data ); - #if DOLPHIN - assertUnreachable("Paletted textures not supported on DOLPHIN"); - #else - glColorTableEXT( - GL_TEXTURE_2D, GL_RGBA, pal->colorCount, GL_RGBA, - GL_UNSIGNED_BYTE, (const void*)pal->colors - ); - #endif + glColorTableEXT( + GL_TEXTURE_2D, GL_RGBA, pal->colorCount, GL_RGBA, + GL_UNSIGNED_BYTE, (const void*)pal->colors + ); } break; diff --git a/src/display/texture.h b/src/display/texture.h index be6ac48..6c2d760 100644 --- a/src/display/texture.h +++ b/src/display/texture.h @@ -14,12 +14,18 @@ typedef enum { TEXTURE_FORMAT_RGBA = GL_RGBA, TEXTURE_FORMAT_ALPHA = GL_ALPHA, TEXTURE_FORMAT_PALETTE = GL_COLOR_INDEX8_EXT, + #elif DOLPHIN + TEXTURE_FORMAT_RGBA = GX_TF_RGBA8, + TEXTURE_FORMAT_ALPHA = GX_TF_A8, + TEXTURE_FORMAT_PALETTE = GX_TF_CI8, #endif } textureformat_t; typedef struct { #if DISPLAY_SDL2 GLuint id; + #elif DOLPHIN + uint8_t id; #endif int32_t width; diff --git a/src/input/CMakeLists.txt b/src/input/CMakeLists.txt index 1db94a8..d030e22 100644 --- a/src/input/CMakeLists.txt +++ b/src/input/CMakeLists.txt @@ -19,16 +19,17 @@ if(DUSK_TARGET_SYSTEM STREQUAL "linux") INPUT_MOUSE=1 INPUT_GAMEPAD=1 ) + elseif(DUSK_TARGET_SYSTEM STREQUAL "psp") target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC INPUT_SDL2=1 INPUT_GAMEPAD=1 ) + elseif(DUSK_TARGET_SYSTEM STREQUAL "gamecube" OR DUSK_TARGET_SYSTEM STREQUAL "wii") target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC - INPUT_SDL2=1 INPUT_GAMEPAD=1 ) endif() diff --git a/src/input/inputbutton.c b/src/input/inputbutton.c index 087bcd9..d252bef 100644 --- a/src/input/inputbutton.c +++ b/src/input/inputbutton.c @@ -31,7 +31,6 @@ inputbuttondata_t INPUT_BUTTON_DATA[] = { { .name = "lstick_negative_x", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTX, .positive = false } } }, { .name = "lstick_positive_y", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTY, .positive = true } } }, { .name = "lstick_negative_y", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = SDL_CONTROLLER_AXIS_LEFTY, .positive = false } } }, - #else #endif #endif @@ -172,6 +171,30 @@ inputbuttondata_t INPUT_BUTTON_DATA[] = { { .name = "kp_enter", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_ENTER } }, { .name = "kp_equals", { .type = INPUT_BUTTON_TYPE_KEYBOARD, .scancode = SDL_SCANCODE_KP_EQUALS } }, #endif + + #elif DOLPHIN + #if INPUT_GAMEPAD == 1 + { .name = "a", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_A } }, + { .name = "b", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_B } }, + { .name = "x", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_X } }, + { .name = "y", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_Y } }, + { .name = "start", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_START } }, + { .name = "dpad_up", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_UP } }, + { .name = "dpad_down", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_DOWN } }, + { .name = "dpad_left", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_LEFT } }, + { .name = "dpad_right", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_BUTTON_RIGHT } }, + { .name = "l", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_TRIGGER_L } }, + { .name = "r", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_TRIGGER_R } }, + { .name = "z", { .type = INPUT_BUTTON_TYPE_GAMEPAD, .gpButton = PAD_TRIGGER_Z } }, + { .name = "lstick_positive_x", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_LEFT_X, .positive = true } } }, + { .name = "lstick_negative_x", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_LEFT_X, .positive = false } } }, + { .name = "lstick_positive_y", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_LEFT_Y, .positive = true } } }, + { .name = "lstick_negative_y", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_LEFT_Y, .positive = false } } }, + { .name = "cstick_positive_x", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_C_X, .positive = true } } }, + { .name = "cstick_negative_x", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_C_X, .positive = false } } }, + { .name = "cstick_positive_y", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_C_Y, .positive = true } } }, + { .name = "cstick_negative_y", { .type = INPUT_BUTTON_TYPE_GAMEPAD_AXIS, .gpAxis = { .axis = INPUT_GAMEPAD_AXIS_C_Y, .positive = false } } }, + #endif #endif { .name = NULL } diff --git a/src/input/inputbutton.h b/src/input/inputbutton.h index ae3daa6..9e484e0 100644 --- a/src/input/inputbutton.h +++ b/src/input/inputbutton.h @@ -10,6 +10,8 @@ #if INPUT_SDL2 == 1 #include +#elif DOLPHIN + #else #error "No input backend defined" #endif @@ -26,6 +28,16 @@ #if INPUT_SDL2 == 1 typedef SDL_GameControllerButton inputgamepadbutton_t; typedef SDL_GameControllerAxis inputgamepadaxis_t; + #elif DOLPHIN == 1 + typedef u16 inputgamepadbutton_t; + typedef enum { + INPUT_GAMEPAD_AXIS_LEFT_X, + INPUT_GAMEPAD_AXIS_LEFT_Y, + INPUT_GAMEPAD_AXIS_C_X, + INPUT_GAMEPAD_AXIS_C_Y, + INPUT_GAMEPAD_AXIS_TRIGGER_LEFT, + INPUT_GAMEPAD_AXIS_TRIGGER_RIGHT + } inputgamepadaxis_t; #endif #endif @@ -35,6 +47,7 @@ typedef enum { #if INPUT_KEYBOARD == 1 INPUT_BUTTON_TYPE_KEYBOARD, #endif + #if INPUT_GAMEPAD == 1 INPUT_BUTTON_TYPE_GAMEPAD, INPUT_BUTTON_TYPE_GAMEPAD_AXIS, diff --git a/src2/CMakeLists.txt b/src2/CMakeLists.txt deleted file mode 100644 index 6bb5452..0000000 --- a/src2/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright (c) 2025 Dominic Masters -# -# This software is released under the MIT License. -# https://opensource.org/licenses/MIT - -# Libs - -# Includes -target_include_directories(${DUSK_LIBRARY_TARGET_NAME} - PUBLIC - ${CMAKE_CURRENT_LIST_DIR} -) - -# Sources - -# Main Binary Source -target_sources(${DUSK_BINARY_TARGET_NAME} - PRIVATE - main.c - sdl_starter.c - sdl_assets_loader.c -) - -# Defs - - -# Subdirs diff --git a/src2/main.c b/src2/main.c deleted file mode 100644 index 894229e..0000000 --- a/src2/main.c +++ /dev/null @@ -1,159 +0,0 @@ -#include -#include "sdl_starter.h" -#include "sdl_assets_loader.h" - -SDL_Window *window = NULL; -SDL_Renderer *renderer = NULL; - -const int PLAYER_SPEED = 600; - -SDL_Rect player = {SCREEN_WIDTH / 2 - 64, SCREEN_HEIGHT / 2 - 64, 64, 64}; - -SDL_Rect ball = {SCREEN_WIDTH / 2 + 50, SCREEN_HEIGHT / 2, 32, 32}; - -int ballVelocityX = 400; -int ballVelocityY = 400; - -int colorIndex; - -SDL_Color colors[] = { - {128, 128, 128, 0}, // gray - {255, 255, 255, 0}, // white - {255, 0, 0, 0}, // red - {0, 255, 0, 0}, // green - {0, 0, 255, 0}, // blue - {255, 255, 0, 0}, // brown - {0, 255, 255, 0}, // cyan - {255, 0, 255, 0}, // purple -}; - -void quitGame() -{ - SDL_DestroyRenderer(renderer); - SDL_DestroyWindow(window); - SDL_Quit(); -} - -void handleEvents() -{ - SDL_Event event; - - while (SDL_PollEvent(&event)) - { - if (event.type == SDL_QUIT) - { - quitGame(); - exit(0); - } - } -} - -int rand_range(int min, int max) -{ - return min + rand() / (RAND_MAX / (max - min + 1) + 1); -} - -void update(float deltaTime) -{ - // PAD_ButtonsDown tells us which buttons were pressed in this loop - // this is a "one shot" state which will not fire again until the button has been released - const u32 padDown = PAD_ButtonsDown(0); - - // PAD_ButtonsHeld tells us which buttons are keep pressing in this loop - const u32 padHeld = PAD_ButtonsHeld(0); - - // We return to the launcher application via exit - if (padDown & PAD_BUTTON_START) - exit(0); - - if (padHeld & PAD_BUTTON_LEFT && player.x > 0) - { - player.x -= PLAYER_SPEED * deltaTime; - } - - else if (padHeld & PAD_BUTTON_RIGHT && player.x < SCREEN_WIDTH - player.w) - { - player.x += PLAYER_SPEED * deltaTime; - } - - else if (padHeld & PAD_BUTTON_UP && player.y > 0) - { - player.y -= PLAYER_SPEED * deltaTime; - } - - else if (padHeld & PAD_BUTTON_DOWN && player.y < SCREEN_HEIGHT - player.h) - { - player.y += PLAYER_SPEED * deltaTime; - } - - if (ball.x < 0 || ball.x > SCREEN_WIDTH - ball.w) - { - ballVelocityX *= -1; - - colorIndex = rand_range(0, 5); - } - - else if (ball.y < 0 || ball.y > SCREEN_HEIGHT - ball.h) - { - ballVelocityY *= -1; - - colorIndex = rand_range(0, 5); - } - - else if (SDL_HasIntersection(&player, &ball)) - { - ballVelocityX *= -1; - ballVelocityY *= -1; - - colorIndex = rand_range(0, 5); - } - - ball.x += ballVelocityX * deltaTime; - ball.y += ballVelocityY * deltaTime; -} - -void render() -{ - SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); - SDL_RenderClear(renderer); - - SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); - - SDL_RenderFillRect(renderer, &player); - - SDL_SetRenderDrawColor(renderer, colors[colorIndex].r, colors[colorIndex].g, colors[colorIndex].b, 255); - - SDL_RenderFillRect(renderer, &ball); - - SDL_RenderPresent(renderer); -} - -int main(int argc, char **argv) -{ - window = SDL_CreateWindow("My Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN); - renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); - - if (startSDL(window, renderer) > 0) - { - return 1; - } - - Uint32 previousFrameTime = SDL_GetTicks(); - Uint32 currentFrameTime = previousFrameTime; - float deltaTime = 0.0f; - - PAD_Init(); - - while (true) - { - PAD_ScanPads(); - - currentFrameTime = SDL_GetTicks(); - deltaTime = (currentFrameTime - previousFrameTime) / 1000.0f; - previousFrameTime = currentFrameTime; - - handleEvents(); - update(deltaTime); - render(); - } -} \ No newline at end of file diff --git a/src2/null.c b/src2/null.c deleted file mode 100644 index a7d5fbe..0000000 --- a/src2/null.c +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Copyright (c) 2026 Dominic Masters - * - * This software is released under the MIT License. - * https://opensource.org/licenses/MIT - */ - -void dusk_null_method(void) { - return; -} \ No newline at end of file diff --git a/src2/sdl_assets_loader.c b/src2/sdl_assets_loader.c deleted file mode 100644 index 7abc5de..0000000 --- a/src2/sdl_assets_loader.c +++ /dev/null @@ -1,74 +0,0 @@ -#include "sdl_assets_loader.h" - -Sprite loadSprite(SDL_Renderer *renderer, const char *filePath, int positionX, int positionY) -{ - SDL_Rect textureBounds = {positionX, positionY, 0, 0}; - - SDL_Texture *texture = IMG_LoadTexture(renderer, filePath); - - if (texture != NULL) - { - SDL_QueryTexture(texture, NULL, NULL, &textureBounds.w, &textureBounds.h); - } - - Sprite sprite = {texture, textureBounds}; - - return sprite; -} - - -Mix_Chunk *loadSound(const char *filePath) -{ - Mix_Chunk *sound = NULL; - - sound = Mix_LoadWAV(filePath); - if (sound == NULL) - { - printf("Failed to load scratch sound effect! SDL_mixer Error: %s\n", Mix_GetError()); - } - - return sound; -} - - -Mix_Music *loadMusic(const char *filePath) -{ - Mix_Music *music = NULL; - - music = Mix_LoadMUS(filePath); - if (music == NULL) - { - printf("Failed to load music! SDL_mixer Error: %s\n", Mix_GetError()); - } - - return music; -} - - -void updateTextureText(SDL_Texture **texture, const char *text, TTF_Font **fontSquare, SDL_Renderer *renderer) -{ - SDL_Color fontColor = {255, 255, 255}; - - if (*fontSquare == NULL) - { - printf("TTF_OpenFont fontSquare: %s\n", TTF_GetError()); - } - - SDL_Surface *surface = TTF_RenderUTF8_Blended(*fontSquare, text, fontColor); - if (surface == NULL) - { - printf("TTF_OpenFont: %s\n", TTF_GetError()); - SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Unable to create text surface! SDL Error: %s\n", SDL_GetError()); - exit(3); - } - - SDL_DestroyTexture(*texture); - *texture = SDL_CreateTextureFromSurface(renderer, surface); - if (*texture == NULL) - { - printf("TTF_OpenFont: %s\n", TTF_GetError()); - SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Unable to create texture from surface! SDL Error: %s\n", SDL_GetError()); - } - - SDL_FreeSurface(surface); -} \ No newline at end of file diff --git a/src2/sdl_assets_loader.h b/src2/sdl_assets_loader.h deleted file mode 100644 index 7bdbeea..0000000 --- a/src2/sdl_assets_loader.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -typedef struct -{ - SDL_Texture *texture; - SDL_Rect textureBounds; -} Sprite; - -Sprite loadSprite(SDL_Renderer *renderer, const char *filePath, int positionX, int positionY); - -Mix_Chunk *loadSound(const char *filePath); - -Mix_Music *loadMusic(const char *filePath); - -void updateTextureText(SDL_Texture **texture, const char *text, TTF_Font **fontSquare, SDL_Renderer *renderer); \ No newline at end of file diff --git a/src2/sdl_starter.c b/src2/sdl_starter.c deleted file mode 100644 index 78c7c14..0000000 --- a/src2/sdl_starter.c +++ /dev/null @@ -1,55 +0,0 @@ - -#include "sdl_starter.h" -#include -#include -#include -#include - -int startSDL(SDL_Window *window, SDL_Renderer *renderer) { - - - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0) - { - printf("SDL crashed. Error: %s\n", SDL_GetError()); - return 1; - } - - - if (window == NULL) - { - fprintf(stderr, "Failed to create window: %s\n", SDL_GetError()); - SDL_Quit(); - return 1; - } - - - if (renderer == NULL) - { - fprintf(stderr, "Failed to create renderer: %s\n", SDL_GetError()); - SDL_DestroyWindow(window); - SDL_Quit(); - return 1; - } - - - if (!IMG_Init(IMG_INIT_PNG)) - { - printf("SDL_image crashed. Error: %s\n", SDL_GetError()); - return 1; - } - - - if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0) - { - printf("SDL_mixer could not initialize! SDL_mixer Error: %s\n", Mix_GetError()); - return 1; - } - - - if (TTF_Init() == -1) - { - return 1; - } - - return 0; -} \ No newline at end of file diff --git a/src2/sdl_starter.h b/src2/sdl_starter.h deleted file mode 100644 index ff3a63b..0000000 --- a/src2/sdl_starter.h +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Copyright (c) 2026 Dominic Masters - * - * This software is released under the MIT License. - * https://opensource.org/licenses/MIT - */ - - -#pragma once -#include - -#define SCREEN_WIDTH 640 -#define SCREEN_HEIGHT 480 - -int startSDL(SDL_Window *window, SDL_Renderer *renderer);