diff --git a/CMakeLists.txt b/CMakeLists.txt index e85dc6d..9f1c9c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ set(SRC_FILES "src/input_manager.cpp" "src/scene_manager.cpp" - "src/texture_manager.cpp" + "src/texture.cpp" "src/gfx_device_vulkan.cpp" @@ -36,15 +36,15 @@ set(INCLUDE_FILES "include/input_manager.hpp" "include/scene_manager.hpp" + "include/resource_manager.hpp" - "include/texture_manager.hpp" "include/texture.hpp" - "include/gfx.hpp" "include/gfx_device.hpp" "include/scene.hpp" + "include/ecs_system.hpp" "include/util/files.hpp" ) diff --git a/include/components/mesh_renderer.hpp b/include/components/mesh_renderer.hpp new file mode 100644 index 0000000..cd92947 --- /dev/null +++ b/include/components/mesh_renderer.hpp @@ -0,0 +1,9 @@ +#pragma once + +namespace engine::components { + + struct MeshRenderer { + int placeholder; + }; + +} diff --git a/include/ecs_system.hpp b/include/ecs_system.hpp new file mode 100644 index 0000000..d75d85e --- /dev/null +++ b/include/ecs_system.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include +#include + +namespace engine::ecs { + + template + class System { + + public: + std::map m_components{}; + + virtual void onUpdate(float ts) = 0; + + }; + +} diff --git a/include/resource_manager.hpp b/include/resource_manager.hpp index f33cf81..4c4f340 100644 --- a/include/resource_manager.hpp +++ b/include/resource_manager.hpp @@ -12,7 +12,7 @@ namespace engine { public: ResourceManager() {} - virtual ~ResourceManager() {} + ~ResourceManager() {} ResourceManager(const ResourceManager&) = delete; ResourceManager& operator=(const ResourceManager&) = delete; @@ -45,4 +45,4 @@ namespace engine { }; -} \ No newline at end of file +} diff --git a/include/scene.hpp b/include/scene.hpp index 9739e9b..acbc1c7 100644 --- a/include/scene.hpp +++ b/include/scene.hpp @@ -1,9 +1,25 @@ #pragma once +#include "ecs_system.hpp" +#include "components/mesh_renderer.hpp" + +#include "log.hpp" + #include namespace engine { + class RendererSystem : public ecs::System { + + public: + void onUpdate(float ts) override + { + for (const auto& [id, data] : m_components) { + DEBUG("rendering entity {}\tts={}", id, ts); + } + } + }; + class Scene { public: @@ -12,10 +28,14 @@ namespace engine { Scene& operator=(const Scene&) = delete; ~Scene(); + void update(float ts); + uint32_t createEntity() { return m_nextEntityID++; } + + std::unique_ptr m_renderSystem; private: uint32_t m_nextEntityID = 1000; diff --git a/include/scene_manager.hpp b/include/scene_manager.hpp index 6c42345..31d2386 100644 --- a/include/scene_manager.hpp +++ b/include/scene_manager.hpp @@ -1,12 +1,13 @@ #pragma once +#include "resource_manager.hpp" + #include #include namespace engine { class Scene; // "scene.hpp" - class TextureManager; // "texture_manager.hpp" class SceneManager { @@ -16,16 +17,16 @@ namespace engine { SceneManager(const SceneManager&) = delete; SceneManager& operator=(const SceneManager&) = delete; - void createScene(std::unique_ptr&& scene); + Scene* createScene(std::unique_ptr&& scene); - void updateActiveScene(); + void updateActiveScene(float ts); private: std::vector> m_scenes; int m_activeSceneIndex = -1; - const std::unique_ptr m_textureManager; +// const std::unique_ptr> m_textureManager; }; -} \ No newline at end of file +} diff --git a/include/texture_manager.hpp b/include/texture_manager.hpp deleted file mode 100644 index 6be7769..0000000 --- a/include/texture_manager.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "resource_manager.hpp" - -namespace engine { - - class Texture { - - }; - - class TextureManager : public ResourceManager { - - public: - TextureManager(); - ~TextureManager() override; - TextureManager(const TextureManager&) = delete; - TextureManager& operator=(const TextureManager&) = delete; - - private: - - }; - -} \ No newline at end of file diff --git a/run.sh b/run.sh index ceec117..f1b72b7 100755 --- a/run.sh +++ b/run.sh @@ -1,3 +1,3 @@ #!/bin/sh -cd "Release/test" +cd "Debug/test" ./enginetest diff --git a/src/application.cpp b/src/application.cpp index 5e22305..ef6c73c 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -20,9 +20,6 @@ namespace engine { m_gfx = std::make_unique(appName, appVersion, m_window->getHandle()); m_inputManager = std::make_unique(window()); m_sceneManager = std::make_unique(); - - auto myScene = std::make_unique(); - m_sceneManager->createScene(std::move(myScene)); } Application::~Application() {} @@ -40,7 +37,7 @@ namespace engine { while (m_window->isRunning()) { /* logic */ - m_sceneManager->updateActiveScene(); + m_sceneManager->updateActiveScene(m_window->dt()); /* draw */ m_gfx->renderFrame(); diff --git a/src/scene.cpp b/src/scene.cpp index ddaa42f..56c4ece 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -1,12 +1,19 @@ #include "scene.hpp" +#include "components/mesh_renderer.hpp" + namespace engine { Scene::Scene() { - + m_renderSystem = std::make_unique(); } Scene::~Scene() {} + void Scene::update(float ts) + { + m_renderSystem->onUpdate(ts); + } + } diff --git a/src/scene_manager.cpp b/src/scene_manager.cpp index 64d2122..09371cd 100644 --- a/src/scene_manager.cpp +++ b/src/scene_manager.cpp @@ -1,28 +1,30 @@ #include "scene_manager.hpp" #include "scene.hpp" -#include "texture_manager.hpp" #include "log.hpp" +#include + namespace engine { SceneManager::SceneManager() - : m_textureManager(std::make_unique()) { - auto tex = std::make_unique(); - m_textureManager->add("myTexture", std::move(tex)); } SceneManager::~SceneManager() {} - void SceneManager::createScene(std::unique_ptr&& scene) + Scene* SceneManager::createScene(std::unique_ptr&& scene) { m_scenes.emplace_back(std::move(scene)); + m_activeSceneIndex = m_scenes.size() - 1; + return m_scenes.back().get(); } - void SceneManager::updateActiveScene() + void SceneManager::updateActiveScene(float ts) { if (m_activeSceneIndex >= 0) { + assert(m_activeSceneIndex < m_scenes.size()); + m_scenes[m_activeSceneIndex]->update(ts); } } diff --git a/src/texture_manager.cpp b/src/texture_manager.cpp deleted file mode 100644 index fe7e42b..0000000 --- a/src/texture_manager.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "texture_manager.hpp" - -namespace engine { - - TextureManager::TextureManager() - { - - } - - TextureManager::~TextureManager() - { - - } - -} \ No newline at end of file diff --git a/test/src/game.cpp b/test/src/game.cpp index 35cefa7..1f44220 100644 --- a/test/src/game.cpp +++ b/test/src/game.cpp @@ -2,6 +2,9 @@ #include "application.hpp" #include "window.hpp" +#include "scene_manager.hpp" +#include "scene.hpp" +#include "components/mesh_renderer.hpp" void playGame() { @@ -10,5 +13,13 @@ void playGame() // configure window app.window()->setRelativeMouseMode(false); + auto myScene = std::make_unique(); + + auto entity1 = myScene->createEntity(); + + myScene->m_renderSystem->m_components.emplace(entity1, engine::components::MeshRenderer()); + + app.sceneManager()->createScene(std::move(myScene)); + app.gameLoop(); }