From 7b5bb990b0e075e23d82c96bcc324a9fa626608a Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Fri, 24 Feb 2023 00:06:12 -0800 Subject: [PATCH] Improved compile time significantly --- src/dawn/game/_DawnGame.hpp | 4 ++-- src/dawn/scene/Scene.hpp | 1 + src/dawn/scene/SceneItemComponentList.hpp | 15 ++++++++++++- src/dawn/scene/debug/SceneDebugLine.cpp | 8 +++++++ src/dawn/scene/debug/SceneDebugLine.hpp | 6 +++++ .../components/TicTacToeGame.cpp | 10 ++++++++- .../components/TicTacToeGame.hpp | 1 + src/dawntools/tools/CMakeLists.txt | 10 ++++----- .../SceneItemComponentRegister.cpp | 22 ++++++++++++------- 9 files changed, 60 insertions(+), 17 deletions(-) diff --git a/src/dawn/game/_DawnGame.hpp b/src/dawn/game/_DawnGame.hpp index 6a853280..314f46ac 100644 --- a/src/dawn/game/_DawnGame.hpp +++ b/src/dawn/game/_DawnGame.hpp @@ -14,7 +14,7 @@ #include "locale/LocaleManager.hpp" #include "save/SaveManager.hpp" #include "audio/AudioManager.hpp" -#include "scene/SceneItemComponentListItems.hpp" +#include "scene/SceneItemComponentList.hpp" #define DAWN_GAME_INIT_RESULT_SUCCESS 0 #define DAWN_GAME_UPDATE_RESULT_SUCCESS 0 @@ -25,7 +25,7 @@ namespace Dawn { class IDawnGame { protected: - SceneItemComponentListItems componentListItems; + SceneItemComponentList componentList; public: Scene *scene = nullptr; diff --git a/src/dawn/scene/Scene.hpp b/src/dawn/scene/Scene.hpp index 0e286fc4..c38459fc 100644 --- a/src/dawn/scene/Scene.hpp +++ b/src/dawn/scene/Scene.hpp @@ -135,6 +135,7 @@ namespace Dawn { #if DAWN_DEBUG_BUILD std::vector debugLines; void debugLine(struct SceneDebugLine line); + void debugRay(struct SceneDebugRay ray); void debugCube(struct SceneDebugCube cube); void debugOrigin(); void debugGrid(); diff --git a/src/dawn/scene/SceneItemComponentList.hpp b/src/dawn/scene/SceneItemComponentList.hpp index 5024a0e4..20365131 100644 --- a/src/dawn/scene/SceneItemComponentList.hpp +++ b/src/dawn/scene/SceneItemComponentList.hpp @@ -8,7 +8,7 @@ namespace Dawn { struct SceneItemComponentRegister { - int32_t i; + uint8_t i; }; class SceneItemComponentList { @@ -16,10 +16,23 @@ namespace Dawn { std::vector components; protected: + /** + * Request the list to append a scene item component of type T + * to the registry. + * + * @tparam T Parameter type of the SceneItemComponent + */ template void append() { struct SceneItemComponentRegister r; this->components.push_back(r); } + + public: + /** + * Initialies the scene item component list. This constructor is generated + * at build time from the scene item component registry tool. + */ + SceneItemComponentList(); }; } \ No newline at end of file diff --git a/src/dawn/scene/debug/SceneDebugLine.cpp b/src/dawn/scene/debug/SceneDebugLine.cpp index ba32e711..ec27e4e1 100644 --- a/src/dawn/scene/debug/SceneDebugLine.cpp +++ b/src/dawn/scene/debug/SceneDebugLine.cpp @@ -57,6 +57,14 @@ void Scene::debugLine(struct SceneDebugLine line) { this->debugLines.push_back(line); } +void Scene::debugRay(struct SceneDebugRay ray) { + this->debugLine((struct SceneDebugLine){ + .v0 = ray.start, + .v1 = ray.start + ray.direction, + .color = ray.color + }); +} + void Scene::debugCube(struct SceneDebugCube cube) { auto min = cube.min; auto max = cube.max; diff --git a/src/dawn/scene/debug/SceneDebugLine.hpp b/src/dawn/scene/debug/SceneDebugLine.hpp index af42b57f..f384862d 100644 --- a/src/dawn/scene/debug/SceneDebugLine.hpp +++ b/src/dawn/scene/debug/SceneDebugLine.hpp @@ -23,6 +23,12 @@ namespace Dawn { glm::mat4 transform = glm::mat4(1.0f); }; + struct SceneDebugRay { + glm::vec3 start; + glm::vec3 direction; + struct Color color = COLOR_RED; + }; + struct SceneDebugLine { glm::vec3 v0 = glm::vec3(0, 0, 0); glm::vec3 v1 = glm::vec3(1, 1, 1); diff --git a/src/dawntictactoe/components/TicTacToeGame.cpp b/src/dawntictactoe/components/TicTacToeGame.cpp index bb27893c..b36da585 100644 --- a/src/dawntictactoe/components/TicTacToeGame.cpp +++ b/src/dawntictactoe/components/TicTacToeGame.cpp @@ -22,5 +22,13 @@ void TicTacToeGame::onSceneUpdate() { mouse *= 2.0f; mouse -= glm::vec2(1, 1); - + Camera *camera = getScene()->findComponent(); + if(camera == nullptr) return; + + struct Ray3D ray; + glm::vec3 pos = glm::vec3(mouse.x * camera->orthoRight, mouse.y * camera->orthoBottom, 0.0f); + ray.direction = glm::vec3(0, 0, -15); + ray.origin = pos; + + getScene()->debugRay((struct SceneDebugRay){ .start = ray.origin, .direction = ray.direction }); } \ No newline at end of file diff --git a/src/dawntictactoe/components/TicTacToeGame.hpp b/src/dawntictactoe/components/TicTacToeGame.hpp index 9d3daf5a..e1fc50fd 100644 --- a/src/dawntictactoe/components/TicTacToeGame.hpp +++ b/src/dawntictactoe/components/TicTacToeGame.hpp @@ -6,6 +6,7 @@ #pragma once #include "scene/SceneItemComponent.hpp" #include "TicTacToeTile.hpp" +#include "physics/3d/Ray3D.hpp" namespace Dawn { class TicTacToeGame : public SceneItemComponent { diff --git a/src/dawntools/tools/CMakeLists.txt b/src/dawntools/tools/CMakeLists.txt index 47cf286e..5a70c87b 100644 --- a/src/dawntools/tools/CMakeLists.txt +++ b/src/dawntools/tools/CMakeLists.txt @@ -117,15 +117,15 @@ function(tool_scenecomponent clazz hfile) ) if(NOT TARGET sceneitemcomponentgen_cmd) add_custom_target(sceneitemcomponentgen_cmd - COMMAND sceneitemcomponentgen --input="${DAWN_TEMP_DIR}/SceneItemComponents.txt" --output="${DAWN_GENERATED_DIR}/scene/SceneItemComponentListItems.hpp" + COMMAND sceneitemcomponentgen --input="${DAWN_TEMP_DIR}/SceneItemComponents.txt" --output="${DAWN_GENERATED_DIR}/scene/SceneItemComponentListItems.cpp" COMMENT "Generating scene item component ${hfile}::${clazz}" DEPENDS sceneitemcomponentgen ) + target_sources(${DAWN_TARGET_NAME} + PRIVATE + ${DAWN_GENERATED_DIR}/scene/SceneItemComponentListItems.cpp + ) endif() - target_include_directories(${DAWN_TARGET_NAME} - PUBLIC - ${DAWN_GENERATED_DIR} - ) add_dependencies(sceneitemcomponentgen ${clazz}_scenecomponent) add_dependencies(${DAWN_TARGET_NAME} sceneitemcomponentgen_cmd) endfunction() diff --git a/src/dawntools/tools/sceneitemcomponentregister/SceneItemComponentRegister.cpp b/src/dawntools/tools/sceneitemcomponentregister/SceneItemComponentRegister.cpp index 48b49e37..13421a8e 100644 --- a/src/dawntools/tools/sceneitemcomponentregister/SceneItemComponentRegister.cpp +++ b/src/dawntools/tools/sceneitemcomponentregister/SceneItemComponentRegister.cpp @@ -14,21 +14,27 @@ void SceneItemComponentRootGen::generate( std::vector *info, std::string tabs = "" ) { - struct ClassGenInfo clazz; - clazz.clazz = "SceneItemComponentListItems"; - clazz.extend = "SceneItemComponentList"; - clazz.includes.push_back("#include \"scene/SceneItemComponentList.hpp\""); - + line(out, "#include \"scene/SceneItemComponentList.hpp\"", tabs); + line(out, "", tabs); auto it = info->begin(); while(it != info->end()) { auto c = *it; - clazz.includes.push_back("#include \"" + c.header + "\""); - line(&clazz.constructorCode, "this->append<" + c.clazz + ">();", ""); + line(out, "#include \"" + c.header + "\"", tabs); ++it; } + line(out, "", tabs); + line(out, "using namespace Dawn;", tabs); + line(out, "", tabs); - classGen(out, clazz); + line(out, "SceneItemComponentList::SceneItemComponentList() {", tabs); + it = info->begin(); + while(it != info->end()) { + auto c = *it; + line(out, "this->append<" + c.clazz + ">();", tabs + " "); + ++it; + } + line(out, "}", tabs); } std::vector SceneItemComponentRegister::getRequiredFlags() {