diff options
| author | 0scar <qgt268@alumni.ku.dk> | 2024-02-06 09:48:05 +0000 |
|---|---|---|
| committer | 0scar <qgt268@alumni.ku.dk> | 2024-02-06 09:48:05 +0000 |
| commit | 3705b14a4b2ac0d6baa418f08991424cfad89891 (patch) | |
| tree | e66853908357fb02deee6718a3bc0aedd3736c7a | |
| parent | d52bd1c709456164b167cc7389b641b690c97ee5 (diff) | |
Works on my machine
Albeit when compiled twice :)
37 files changed, 113 insertions, 85 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index ca9021a..39f8e76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,17 +91,21 @@ FetchContent_Declare(cglm ) FetchContent_MakeAvailable(cglm) -## Compilation information -add_subdirectory(src) +## Glad +set(GLAD_HEADER ${CMAKE_BINARY_DIR}/include/glad/gl.h) +## Compilation information add_compile_options(${RELEASE_OPTS}) add_link_options(${RELEASE_OPTS}) +#set_property(SOURCE src/core/include/engine/engine.h APPEND PROPERTY OBJECT_DEPENDS ${GLAD_HEADER}) + add_library(${PROJECT_NAME} - ${CMAKE_BINARY_DIR}/include/glad/gl.h - #${ENGINE_SOURCES} + src/main.c + ${GLAD_HEADER} ) + set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE C) target_include_directories(${PROJECT_NAME} PUBLIC @@ -109,6 +113,10 @@ target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_BINARY_DIR}/include ${ENGINE_INCLUDE}) + +# Add the modules +add_subdirectory(src) + target_link_libraries(${PROJECT_NAME} glfw OpenGL::GL @@ -119,7 +127,7 @@ target_link_libraries(${PROJECT_NAME} daw_resources daw_ui daw_utils - NOT:$<PLATFORM_ID:Windows>>:m> + $<$<NOT:$<PLATFORM_ID:Windows>>:m> $<$<BOOL:${DAW_BUILD_HOTRELOAD}>:dl> $<$<AND:$<NOT:$<C_COMPILER_ID:MSVC>>,$<BOOL:${DAW_BUILD_UBSAN}>>:ubsan> ) @@ -166,18 +174,6 @@ if (NOT NOT_SUBPROJECT) endif() include(DawAddState) -add_custom_command( - OUTPUT ${CMAKE_BINARY_DIR}/include/glad/gl.h - COMMAND - glad - --api gl:core=3.3 - --out-path ${CMAKE_BINARY_DIR} - --reproducible - c - --header-only - --mx -) - message("Configured ${PROJECT_NAME} ${PROJECT_VERSION}") message("version: ${ENGINE_VERSION_MAJOR}.${ENGINE_VERSION_MINOR}.${ENGINE_VERSION_PATCH}-${ENGINE_VERSION_TWEAK} (${ENGINE_BUILD_TYPE} build)") message("enable debug: ${DAW_BUILD_DEBUG}") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5f0b8b5..b474ff7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,3 +1,13 @@ +set(DAW_INCLUDE_DIRS + ${CMAKE_CURRENT_LIST_DIR}/core/include + ${CMAKE_CURRENT_LIST_DIR}/ctrl/include + ${CMAKE_CURRENT_LIST_DIR}/rendering/include + ${CMAKE_CURRENT_LIST_DIR}/resources/include + ${CMAKE_CURRENT_LIST_DIR}/ui/include + ${CMAKE_CURRENT_LIST_DIR}/utils/include + ${CMAKE_BINARY_DIR}/include + ) + add_subdirectory(core) add_subdirectory(ctrl) add_subdirectory(rendering) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index c6adabf..a9e2b6d 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -9,4 +9,7 @@ add_library(daw_core src/state.c ) -target_include_directories(daw_core PRIVATE include) +set_property(SOURCE src/loop.c APPEND PROPERTY OBJECT_DEPENDS ${GLAD_HEADER}) + +target_include_directories(daw_core PRIVATE ${DAW_INCLUDE_DIRS}) +target_link_libraries(daw_core PRIVATE cglm) diff --git a/src/core/include/engine/core/logging.h b/src/core/include/engine/core/logging.h index d1c5890..52bb446 100644 --- a/src/core/include/engine/core/logging.h +++ b/src/core/include/engine/core/logging.h @@ -7,7 +7,7 @@ #include <stdlib.h> #include <string.h> -#include "types.h" +#include <engine/core/types.h> #if defined __linux__ || defined __APPLE__ #define TERM_COLOR_RESET "\033[0m" diff --git a/src/core/include/engine/core/memory.h b/src/core/include/engine/core/memory.h index 04c24d5..dbdd065 100644 --- a/src/core/include/engine/core/memory.h +++ b/src/core/include/engine/core/memory.h @@ -1,8 +1,7 @@ #ifndef MEMORY_H #define MEMORY_H -#include "types.h" -// #include <stdlib.h> +#include <engine/core/types.h> typedef struct memory { void* data; diff --git a/src/core/include/engine/core/state.h b/src/core/include/engine/core/state.h index 13593ed..af94560 100644 --- a/src/core/include/engine/core/state.h +++ b/src/core/include/engine/core/state.h @@ -1,7 +1,7 @@ #ifndef STATE_H #define STATE_H -#include <engine/memory.h> +#include <engine/core/memory.h> typedef enum StateType { STATE_null, diff --git a/src/core/include/engine/engine.h b/src/core/include/engine/engine.h index e8a5ace..ba4e227 100644 --- a/src/core/include/engine/engine.h +++ b/src/core/include/engine/engine.h @@ -3,14 +3,17 @@ #include <stdbool.h> -#include <engine/input.h> -#include <engine/logging.h> -#include <engine/memory.h> +// TODO: Cleanup the includes, ideally this header file should only include all +// "public-facing" headers. + +#include <engine/core/types.h> +#include <engine/core/logging.h> +#include <engine/core/memory.h> +#include <engine/core/state.h> +#include <engine/ctrl/input.h> #include <engine/resources.h> -#include <engine/stack.h> -#include <engine/state.h> -#include <engine/types.h> -#include <engine/vector.h> +#include <engine/utils/stack.h> +#include <engine/utils/vector.h> typedef struct { u32 texture_id; @@ -83,7 +86,7 @@ void engine_input_ctx_push(i_ctx* ctx); void engine_input_ctx_pop(void); void engine_input_ctx_reset(void); -#include "rendering.h" +#include <engine/rendering/rendering.h> #ifdef ENGINE_INTERNALS diff --git a/src/core/src/dltools.c b/src/core/src/dltools.c index 1e43b79..d27c4ff 100644 --- a/src/core/src/dltools.c +++ b/src/core/src/dltools.c @@ -1,4 +1,5 @@ #include <stdlib.h> +#include <stdbool.h> #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) /* include winapi */ @@ -6,8 +7,8 @@ #include <dlfcn.h> #endif -#include <engine/dltools.h> -#include <engine/logging.h> +#include <engine/core/dltools.h> +#include <engine/core/logging.h> bool dynamic_library_close(void* shared_library) { #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) diff --git a/src/core/src/logging.c b/src/core/src/logging.c index 7870258..94782ac 100644 --- a/src/core/src/logging.c +++ b/src/core/src/logging.c @@ -1,5 +1,5 @@ -#include <engine/logging.h> -#include <engine/types.h> +#include <engine/core/logging.h> +#include <engine/core/types.h> #include <stdlib.h> char* itoa(i32 x) { diff --git a/src/core/src/loop.c b/src/core/src/loop.c index 79e0c0c..837d193 100644 --- a/src/core/src/loop.c +++ b/src/core/src/loop.c @@ -25,14 +25,12 @@ #endif #define ENGINE_INTERNALS -#include <engine/btree.h> #include <engine/engine.h> -#include <engine/hashmap.h> -#include <engine/list.h> +#include <engine/utils/btree.h> +#include <engine/utils/hashmap.h> +#include <engine/utils/list.h> -#include <engine/state.h> -// #include <states/titlescreen.h> -// #include <states/gameover.h> +#include <engine/core/state.h> #define DEFAULT_NUM_PROCS 8 diff --git a/src/core/src/memory.c b/src/core/src/memory.c index f19803e..7a51a0d 100644 --- a/src/core/src/memory.c +++ b/src/core/src/memory.c @@ -2,9 +2,8 @@ #include <stdlib.h> #include <string.h> -#include <engine/logging.h> - -#include <engine/memory.h> +#include <engine/core/logging.h> +#include <engine/core/memory.h> memory* memory_new(usize max_size) { memory* m = malloc(sizeof(memory)); diff --git a/src/core/src/state.c b/src/core/src/state.c index 55f2a12..a2af5e1 100644 --- a/src/core/src/state.c +++ b/src/core/src/state.c @@ -1,9 +1,9 @@ #include <string.h> -#include <engine/dltools.h> -#include <engine/input.h> -#include <engine/logging.h> -#include <engine/state.h> +#include <engine/core/dltools.h> +#include <engine/core/logging.h> +#include <engine/core/state.h> +#include <engine/ctrl/input.h> typedef StateType state_update_t(void*); diff --git a/src/ctrl/CMakeLists.txt b/src/ctrl/CMakeLists.txt index 7a449d6..3f76069 100644 --- a/src/ctrl/CMakeLists.txt +++ b/src/ctrl/CMakeLists.txt @@ -6,4 +6,4 @@ add_library(daw_ctrl src/mouse.c ) -target_include_directories(daw_ctrl PRIVATE include) +target_include_directories(daw_ctrl PRIVATE ${DAW_INCLUDE_DIRS}) diff --git a/src/ctrl/include/engine/ctrl/input.h b/src/ctrl/include/engine/ctrl/input.h index 49b3a96..26a5f5b 100644 --- a/src/ctrl/include/engine/ctrl/input.h +++ b/src/ctrl/include/engine/ctrl/input.h @@ -1,7 +1,7 @@ #ifndef INPUT_H #define INPUT_H -#include <engine/types.h> +#include <engine/core/types.h> typedef void input_callback_t(void*); typedef i32 scancode_t; diff --git a/src/ctrl/src/input.c b/src/ctrl/src/input.c index 34b1718..2fd025e 100644 --- a/src/ctrl/src/input.c +++ b/src/ctrl/src/input.c @@ -1,6 +1,6 @@ -#include <engine/dltools.h> -#include <engine/input.h> -#include <engine/logging.h> +#include <engine/core/dltools.h> +#include <engine/core/logging.h> +#include <engine/ctrl/input.h> #include <string.h> /* Lazy binds, used internally. They are similar to BindAction and friends. diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..adef7b9 --- /dev/null +++ b/src/main.c @@ -0,0 +1 @@ +/* Intentionally left blank for now */ diff --git a/src/rendering/CMakeLists.txt b/src/rendering/CMakeLists.txt index e04d858..f19cce0 100644 --- a/src/rendering/CMakeLists.txt +++ b/src/rendering/CMakeLists.txt @@ -3,9 +3,25 @@ add_library(daw_rendering src/rendering.c src/text.c src/window.c + ${GLAD_HEADER} ) -target_include_directories(daw_rendering PRIVATE include) +add_custom_command( + OUTPUT ${GLAD_HEADER} + COMMAND + glad + --api gl:core=4.6 + --out-path ${CMAKE_BINARY_DIR} + --reproducible + c + --header-only + --mx + ) + +set_property(SOURCE src/window.c APPEND PROPERTY OBJECT_DEPENDS ${GLAD_HEADER}) +set_property(SOURCE src/rendering.c APPEND PROPERTY OBJECT_DEPENDS ${GLAD_HEADER}) + +target_include_directories(daw_rendering PRIVATE ${DAW_INCLUDE_DIRS}) target_link_libraries(daw_rendering PRIVATE OpenGL::GL cglm diff --git a/src/rendering/include/engine/rendering/rendering.h b/src/rendering/include/engine/rendering/rendering.h index ff24412..6ae6535 100644 --- a/src/rendering/include/engine/rendering/rendering.h +++ b/src/rendering/include/engine/rendering/rendering.h @@ -1,8 +1,8 @@ #ifndef RENDERING_H #define RENDERING_H -#include "types.h" -#include "vector.h" +#include <engine/core/types.h> +#include <engine/utils/vector.h> #define GLFW_INCLUDE_NONE #include <GLFW/glfw3.h> @@ -26,8 +26,8 @@ typedef struct { } Sprite; -#include "engine.h" -#include "ui.h" +#include <engine/engine.h> +#include <engine/ui.h> /* Rendering functions */ void render_begin(Window* w); @@ -52,7 +52,7 @@ void engine_draw_sprite_ex(Sprite* s, v2_i32* pos, f32 scale, Sprite sprite_new(u64 tid, u8 coord); #ifdef ENGINE_INTERNALS -#include "engine.h" +#include <engine/engine.h> //#include <glad/gl.h> //#define GLFW_INCLUDE_NONE diff --git a/src/rendering/src/rendering.c b/src/rendering/src/rendering.c index dff3432..808897c 100644 --- a/src/rendering/src/rendering.c +++ b/src/rendering/src/rendering.c @@ -9,7 +9,7 @@ #define ENGINE_INTERNALS #include <engine/engine.h> -#include <engine/rendering.h> +#include <engine/rendering/rendering.h> /* Extern globals */ extern Platform* GLOBAL_PLATFORM; diff --git a/src/resources/CMakeLists.txt b/src/resources/CMakeLists.txt index 02ab1ca..6a99990 100644 --- a/src/resources/CMakeLists.txt +++ b/src/resources/CMakeLists.txt @@ -4,4 +4,4 @@ add_library(daw_resources src/textures.c ) -target_include_directories(daw_resources PRIVATE include) +target_include_directories(daw_resources PRIVATE ${DAW_INCLUDE_DIRS}) diff --git a/src/resources/include/engine/resources/resources.h b/src/resources/include/engine/resources.h index 1689544..9de24ce 100644 --- a/src/resources/include/engine/resources/resources.h +++ b/src/resources/include/engine/resources.h @@ -1,7 +1,7 @@ #ifndef RESOURCES_H #define RESOURCES_H -#include <engine/types.h> +#include <engine/core/types.h> /* We need some "global resources", available to all states. * These are resources such as common fonts, GUI frames, button background diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 23dcae6..fa91929 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -3,4 +3,4 @@ add_library(daw_ui src/rendering.c ) -target_include_directories(daw_ui PRIVATE include) +target_include_directories(daw_ui PRIVATE ${DAW_INCLUDE_DIRS}) diff --git a/src/ui/include/engine/ui/ui.h b/src/ui/include/engine/ui.h index 4a3cd3e..eea81af 100644 --- a/src/ui/include/engine/ui/ui.h +++ b/src/ui/include/engine/ui.h @@ -1,9 +1,9 @@ #ifndef ENGINE_UI_H #define ENGINE_UI_H -#include "list.h" -#include "types.h" -#include "vector.h" +#include <engine/core/types.h> +#include <engine/utils/list.h> +#include <engine/utils/vector.h> #define DIRECTION_HORIZONTAL true #define DIRECTION_VERTICAL false diff --git a/src/ui/src/positioning.c b/src/ui/src/positioning.c index 3db73fe..6bb32fb 100644 --- a/src/ui/src/positioning.c +++ b/src/ui/src/positioning.c @@ -1,8 +1,8 @@ #include <stdint.h> #define ENGINE_INTERNALS -#include <engine/btree.h> #include <engine/engine.h> +#include <engine/utils/btree.h> #include <engine/utils.h> static Engine_color DEFAULT_FG = {0xFF, 0xFF, 0xFF, 0xFF}; diff --git a/src/ui/src/rendering.c b/src/ui/src/rendering.c index 1516736..093f373 100644 --- a/src/ui/src/rendering.c +++ b/src/ui/src/rendering.c @@ -5,7 +5,7 @@ #define ENGINE_INTERNALS #include <engine/engine.h> -#include <engine/rendering.h> +#include <engine/rendering/rendering.h> extern Platform* GLOBAL_PLATFORM; diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt index 7508d26..64f5586 100644 --- a/src/utils/CMakeLists.txt +++ b/src/utils/CMakeLists.txt @@ -7,4 +7,4 @@ add_library(daw_utils src/vector.c ) -target_include_directories(daw_utils PRIVATE include) +target_include_directories(daw_utils PRIVATE ${DAW_INCLUDE_DIRS}) diff --git a/src/utils/include/engine/utils/utils.h b/src/utils/include/engine/utils.h index e537f52..d10a03a 100644 --- a/src/utils/include/engine/utils/utils.h +++ b/src/utils/include/engine/utils.h @@ -1,8 +1,8 @@ #ifndef ENGINE_UTILS_H #define ENGINE_UTILS_H -#include "types.h" -#include "vector.h" +#include <engine/core/types.h> +#include <engine/utils/vector.h> #define MIN(a, b) ((a < b) ? (a) : (b)) #define MAX(a, b) ((a > b) ? (a) : (b)) diff --git a/src/utils/include/engine/utils/fov.h b/src/utils/include/engine/utils/fov.h index 15ef38b..b083d2b 100644 --- a/src/utils/include/engine/utils/fov.h +++ b/src/utils/include/engine/utils/fov.h @@ -1,8 +1,8 @@ #ifndef ENGINE_FOV_H #define ENGINE_FOV_H -#include "types.h" -#include "vector.h" +#include <engine/core/types.h> +#include <engine/utils/vector.h> #include <stdbool.h> /* `fov_shadowcast`: */ diff --git a/src/utils/include/engine/utils/hashmap.h b/src/utils/include/engine/utils/hashmap.h index bf1d87c..046c810 100644 --- a/src/utils/include/engine/utils/hashmap.h +++ b/src/utils/include/engine/utils/hashmap.h @@ -1,12 +1,12 @@ #ifndef ENGINE_HASHMAP_H #define ENGINE_HASHMAP_H -#include "types.h" - -#include "list.h" -#include "memory.h" #include <stdlib.h> +#include <engine/core/types.h> +#include <engine/core/memory.h> +#include <engine/utils/list.h> + i32 lolhash(const usize s, i32 v); /* Define a linked list before using this */ diff --git a/src/utils/include/engine/utils/stack.h b/src/utils/include/engine/utils/stack.h index 69975df..9fc53aa 100644 --- a/src/utils/include/engine/utils/stack.h +++ b/src/utils/include/engine/utils/stack.h @@ -25,7 +25,7 @@ #ifndef STACK_H #define STACK_H -#include "types.h" +#include <engine/core/types.h> typedef struct { isize head; /* current number of elements */ diff --git a/src/utils/include/engine/utils/vector.h b/src/utils/include/engine/utils/vector.h index 58bb0a2..11517dc 100644 --- a/src/utils/include/engine/utils/vector.h +++ b/src/utils/include/engine/utils/vector.h @@ -1,7 +1,7 @@ #ifndef VECTOR_H #define VECTOR_H -#include "types.h" +#include <engine/core/types.h> #include <stdbool.h> #include <stdio.h> diff --git a/src/utils/src/btree.c b/src/utils/src/btree.c index c125564..1e85e6c 100644 --- a/src/utils/src/btree.c +++ b/src/utils/src/btree.c @@ -1,4 +1,4 @@ -#include <engine/btree.h> +#include <engine/utils/btree.h> #include <stdbool.h> #include <stdio.h> diff --git a/src/utils/src/fov.c b/src/utils/src/fov.c index 3d5ae16..7bd27e2 100644 --- a/src/utils/src/fov.c +++ b/src/utils/src/fov.c @@ -1,4 +1,4 @@ -#include <engine/fov.h> +#include <engine/utils/fov.h> #include <engine/utils.h> #include <math.h> #include <stdint.h> diff --git a/src/utils/src/hashmap.c b/src/utils/src/hashmap.c index 1652bb6..61c5e43 100644 --- a/src/utils/src/hashmap.c +++ b/src/utils/src/hashmap.c @@ -1,3 +1,5 @@ -#include <engine/hashmap.h> +#include <engine/utils/hashmap.h> +/* Currently, this is a "works, but very poorly" placeholder implementation. + * Should be avoided in practice */ i32 lolhash(const usize s, i32 v) { return v % s; } diff --git a/src/utils/src/misc.c b/src/utils/src/misc.c index 0f3d218..290c417 100644 --- a/src/utils/src/misc.c +++ b/src/utils/src/misc.c @@ -3,7 +3,7 @@ #include <string.h> -#include <engine/logging.h> +#include <engine/core/logging.h> #include <engine/utils.h> /* These should all be in some external facing module "tools" */ diff --git a/src/utils/src/stack.c b/src/utils/src/stack.c index ff195ba..a5fc419 100644 --- a/src/utils/src/stack.c +++ b/src/utils/src/stack.c @@ -1,5 +1,5 @@ -#include <engine/logging.h> -#include <engine/stack.h> +#include <engine/core/logging.h> +#include <engine/utils/stack.h> #include <stdlib.h> Stack stack_new_ex(const usize element_size, const usize size) { diff --git a/src/utils/src/vector.c b/src/utils/src/vector.c index 3465df7..5fedb1f 100644 --- a/src/utils/src/vector.c +++ b/src/utils/src/vector.c @@ -1,5 +1,5 @@ #include <engine/utils.h> -#include <engine/vector.h> +#include <engine/utils/vector.h> bool v2_i32_eq(const v2_i32 a, const v2_i32 b) { return (a.x == b.x) && (a.y == b.y); |
