diff --git a/src/dusk/CMakeLists.txt b/src/dusk/CMakeLists.txt index c72315b..b07c043 100644 --- a/src/dusk/CMakeLists.txt +++ b/src/dusk/CMakeLists.txt @@ -6,7 +6,6 @@ # Libs target_link_libraries(${DUSK_TARGET_NAME} PUBLIC - cglm ) # Includes @@ -24,5 +23,5 @@ target_sources(${DUSK_TARGET_NAME} # Subdirs add_subdirectory(assert) -add_subdirectory(entity) -add_subdirectory(display) \ No newline at end of file +add_subdirectory(render) +add_subdirectory(entity) \ No newline at end of file diff --git a/src/dusk/display/camera.c b/src/dusk/display/camera.c deleted file mode 100644 index d889843..0000000 --- a/src/dusk/display/camera.c +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Copyright (c) 2025 Dominic Masters - * - * This software is released under the MIT License. - * https://opensource.org/licenses/MIT - */ - -#include "camera.h" - -void cameraInit(camera_t *camera) { - glm_mat4_identity(camera->projection); - glm_mat4_identity(camera->view); -} - -void cameraLookAt( - camera_t *camera, - const vec3 eye, - const vec3 center, - const vec3 up -) { - glm_lookat(eye, center, up, camera->view); -} - -void cameraPerspective( - camera_t *camera, - float aspect, - float fovy, - float zNear, - float zFar -) { - glm_perspective(fovy, aspect, zNear, zFar, camera->projection); -} - -void cameraOrtho( - camera_t *camera, - float left, - float right, - float bottom, - float top, - float near, - float far -) { - glm_ortho(left, right, bottom, top, near, far, camera->projection); -} \ No newline at end of file diff --git a/src/dusk/display/camera.h b/src/dusk/display/camera.h deleted file mode 100644 index c0d98f5..0000000 --- a/src/dusk/display/camera.h +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Copyright (c) 2025 Dominic Masters - * - * This software is released under the MIT License. - * https://opensource.org/licenses/MIT - */ - -#pragma once -#include "dusk.h" - -typedef struct { - mat4 projection; - mat4 view; -} camera_t; - -/** - * Initializes the camera. - * - * @param camera The camera to initialize. - */ -void cameraInit(camera_t *camera); - -/** - * Changes a camera to look at a specific point. - * - * @param camera The camera to modify. - * @param eye The position of the camera. - * @param center The point to look at. - * @param up The up vector. - */ -void cameraLookAt( - camera_t *camera, - const vec3 eye, - const vec3 center, - const vec3 up -); - -/** - * Changes the camera's perspective. - * - * @param camera The camera to modify. - * @param fovy The field of view in the y direction. - * @param aspect The aspect ratio. - * @param zNear The near plane. - * @param zFar The far plane. - */ -void cameraPerspective( - camera_t *camera, - const float fovy, - const float aspect, - const float zNear, - const float zFar -); - -/** - * Changes the camera's orthographic perspective. - * - * @param camera The camera to modify. - * @param left The left plane. - * @param right The right plane. - * @param bottom The bottom plane. - * @param top The top plane. - * @param near The near plane. - * @param far The far plane. - */ -void cameraOrtho( - camera_t *camera, - const float left, - const float right, - const float bottom, - const float top, - const float near, - const float far -); \ No newline at end of file diff --git a/src/dusk/dusk.h b/src/dusk/dusk.h index 51d88a1..b4e1857 100644 --- a/src/dusk/dusk.h +++ b/src/dusk/dusk.h @@ -14,13 +14,6 @@ #include #include #include -#include -#include -#include -#include - -typedef float float_t; -typedef double double_t; typedef bool bool_t; typedef char char_t; diff --git a/src/dusk/game.c b/src/dusk/game.c index 7445d0d..b6cf387 100644 --- a/src/dusk/game.c +++ b/src/dusk/game.c @@ -7,19 +7,24 @@ #include "game.h" #include "input.h" +#include "render/scene.h" + +game_t GAME; void gameInit() { + memset(&GAME, 0, sizeof(game_t)); + inputInit(); + sceneInit(); } void gameUpdate() { + GAME.tick++; + inputUpdate(); - - if(inputWasPressed(INPUT_MENU)) { - // Quit - printf("Quit\n"); - } + sceneUpdate(); } void gameDispose() { + } \ No newline at end of file diff --git a/src/dusk/game.h b/src/dusk/game.h index 69bc4b8..94b8b50 100644 --- a/src/dusk/game.h +++ b/src/dusk/game.h @@ -10,6 +10,12 @@ #define GAME_TICK_RATE 60 +typedef struct { + uint32_t tick; +} game_t; + +extern game_t GAME; + /** * Initializes the game. */ diff --git a/src/dusk/entity/CMakeLists.txt b/src/dusk/overworld/CMakeLists.txt similarity index 92% rename from src/dusk/entity/CMakeLists.txt rename to src/dusk/overworld/CMakeLists.txt index f81260a..ee7265d 100644 --- a/src/dusk/entity/CMakeLists.txt +++ b/src/dusk/overworld/CMakeLists.txt @@ -7,6 +7,7 @@ target_sources(${DUSK_TARGET_NAME} PRIVATE entity.c + overworld.c ) # Subdirs \ No newline at end of file diff --git a/src/dusk/entity/entity.c b/src/dusk/overworld/entity.c similarity index 100% rename from src/dusk/entity/entity.c rename to src/dusk/overworld/entity.c diff --git a/src/dusk/entity/entity.h b/src/dusk/overworld/entity.h similarity index 100% rename from src/dusk/entity/entity.h rename to src/dusk/overworld/entity.h diff --git a/src/dusk/overworld/overworld.c b/src/dusk/overworld/overworld.c new file mode 100644 index 0000000..c33dd2c --- /dev/null +++ b/src/dusk/overworld/overworld.c @@ -0,0 +1,25 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "overworld.h" + +void overworldInit() { + +} + +void overworldSceneInit() { + +} + +void overworldSceneDeinit() { + +} + +void overworldUpdate() { + +} + diff --git a/src/dusk/overworld/overworld.h b/src/dusk/overworld/overworld.h new file mode 100644 index 0000000..cffe780 --- /dev/null +++ b/src/dusk/overworld/overworld.h @@ -0,0 +1,14 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "dusk.h" + +void overworldInit(); +void overworldSceneInit(); +void overworldSceneDeinit(); +void overworldUpdate(); \ No newline at end of file diff --git a/src/dusk/display/CMakeLists.txt b/src/dusk/render/CMakeLists.txt similarity index 93% rename from src/dusk/display/CMakeLists.txt rename to src/dusk/render/CMakeLists.txt index 206a87a..7b444ad 100644 --- a/src/dusk/display/CMakeLists.txt +++ b/src/dusk/render/CMakeLists.txt @@ -6,7 +6,7 @@ # Sources target_sources(${DUSK_TARGET_NAME} PRIVATE - camera.c + scene.c ) # Subdirs \ No newline at end of file diff --git a/src/dusk/render/scene.c b/src/dusk/render/scene.c new file mode 100644 index 0000000..967e1f5 --- /dev/null +++ b/src/dusk/render/scene.c @@ -0,0 +1,47 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "scene.h" +#include "assert/assert.h" +#include "overworld/overworld.h" + +scenetypecallback_t SCENE_CALLBACKS[] = { + { NULL, NULL, NULL, NULL },// SCENE_TYPE_INITIAL + { overworldInit, overworldSceneInit, overworldSceneDeinit, overworldUpdate }, +}; + +scene_t SCENE; + +void sceneInit() { + memset(&SCENE, 0, sizeof(scene_t)); + + for(uint8_t i = 0; i < SCENE_TYPE_COUNT; i++) { + if(SCENE_CALLBACKS[i].onInit) SCENE_CALLBACKS[i].onInit(); + } + + sceneSet(SCENE_TYPE_OVERWORLD);// Testing +} + +void sceneUpdate() { + assertTrue(SCENE.current < SCENE_TYPE_COUNT, "Invalid Scene Type"); + + if(SCENE.next != SCENE.current) { + SCENE.current = SCENE.next; + if(SCENE_CALLBACKS[SCENE.current].onActive) { + SCENE_CALLBACKS[SCENE.current].onActive(); + } + } + + if(SCENE_CALLBACKS[SCENE.current].onUpdate) { + SCENE_CALLBACKS[SCENE.current].onUpdate(); + } +} + +void sceneSet(const scenetype_t scene) { + assertTrue(SCENE.next < SCENE_TYPE_COUNT, "Invalid Scene Type"); + SCENE.next = scene; +} \ No newline at end of file diff --git a/src/dusk/render/scene.h b/src/dusk/render/scene.h new file mode 100644 index 0000000..dfd94fa --- /dev/null +++ b/src/dusk/render/scene.h @@ -0,0 +1,47 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "dusk.h" + +typedef enum { + SCENE_TYPE_INITIAL, + SCENE_TYPE_OVERWORLD, +} scenetype_t; + +#define SCENE_TYPE_COUNT 2 + +typedef struct { + scenetype_t current; + scenetype_t next; +} scene_t; + +typedef struct { + void (*onInit)(); + void (*onActive)(); + void (*onInactive)(); + void (*onUpdate)(); +} scenetypecallback_t; + +extern scene_t SCENE; + +/** + * Initializes the scene system. + */ +void sceneInit(); + +/** + * Updates the scene system. + */ +void sceneUpdate(); + +/** + * Sets the current scene. This will happen at the start of the next tick. + * + * @param scene The scene to set. + */ +void sceneSet(const scenetype_t scene); \ No newline at end of file diff --git a/src/duskgl/CMakeLists.txt b/src/duskgl/CMakeLists.txt index 32ec7e7..7f4c067 100644 --- a/src/duskgl/CMakeLists.txt +++ b/src/duskgl/CMakeLists.txt @@ -9,6 +9,7 @@ target_link_libraries(${DUSK_TARGET_NAME} archive_static m spng_static + cglm ) # Includes diff --git a/src/duskgl/duskgl.h b/src/duskgl/duskgl.h index 956d99f..742042c 100644 --- a/src/duskgl/duskgl.h +++ b/src/duskgl/duskgl.h @@ -10,6 +10,13 @@ #include "duskglimpl.h" #include +#include +#include +#include +#include + +typedef float float_t; +typedef double double_t; extern char_t EXECUTABLE_PATH[]; extern char_t EXECUTABLE_DIRECTORY[]; \ No newline at end of file