From a98eac3dc713be938de40b77ab90bb1ae4398751 Mon Sep 17 00:00:00 2001 From: Caleb Burke Date: Wed, 23 Sep 2026 04:20:43 +0000 Subject: [PATCH] laptop changes --- engine/include/sophia/scene.hpp | 6 +++ engine/include/sophia/ui/debug_ui.hpp | 6 +-- engine/src/entity.cpp | 7 +++ engine/src/entity.hpp | 66 +++++++++++++++++++++++++ engine/src/rendering/scene_renderer.cpp | 51 ++++++++++++++++++- engine/src/rendering/scene_renderer.hpp | 7 ++- engine/src/ui/debug_ui.cpp | 1 + 7 files changed, 138 insertions(+), 6 deletions(-) create mode 100644 engine/src/entity.cpp create mode 100644 engine/src/entity.hpp diff --git a/engine/include/sophia/scene.hpp b/engine/include/sophia/scene.hpp index bbc1c70..d23850e 100644 --- a/engine/include/sophia/scene.hpp +++ b/engine/include/sophia/scene.hpp @@ -4,6 +4,9 @@ namespace sophia { +class Entity; +class SceneRenderer; // !TEMP remove this + class Scene { public: Scene(); @@ -14,6 +17,9 @@ class Scene { void setActiveCamera(entt::entity camera) { activeCamera = camera; } private: + friend class Entity; + friend class SceneRenderer; // !TEMP remove this + entt::registry registry; entt::entity activeCamera = entt::null; }; diff --git a/engine/include/sophia/ui/debug_ui.hpp b/engine/include/sophia/ui/debug_ui.hpp index 0037196..22d27a9 100644 --- a/engine/include/sophia/ui/debug_ui.hpp +++ b/engine/include/sophia/ui/debug_ui.hpp @@ -17,9 +17,9 @@ class DebugUI { void show(); void hide(); - void showPanelRegistry(bool show = true); - void showFrameStats(bool show = true); - void showConsole(bool show = true); + void showPanelRegistry(bool show = false); + void showFrameStats(bool show = false); + void showConsole(bool show = false); private: PanelRegistry& registry; diff --git a/engine/src/entity.cpp b/engine/src/entity.cpp new file mode 100644 index 0000000..e891f90 --- /dev/null +++ b/engine/src/entity.cpp @@ -0,0 +1,7 @@ +#include "entity.hpp" + +namespace sophia { + +Entity::Entity(entt::entity handle, Scene* scene) : handle(handle), scene(scene) {} + +} // namespace sophia diff --git a/engine/src/entity.hpp b/engine/src/entity.hpp new file mode 100644 index 0000000..67a4a7a --- /dev/null +++ b/engine/src/entity.hpp @@ -0,0 +1,66 @@ +#pragma once + +#include +#include +#include +#include + +namespace sophia { + +class Entity { +public: + Entity(const Entity&) = default; + Entity& operator=(const Entity&) = default; + + Entity() = default; + Entity(entt::entity handle, Scene* scene); + + template + T& addComponent(Args&&... args) { + SOPHIA_ASSERT(!hasComponent(), "Entity already has component!"); + T& component = scene->registry.emplace(handle, std::forward(args)...); + // scene->OnComponentAdded(*this, component); + return component; + } + + template + T& getComponent() + { + SOPHIA_ASSERT(hasComponent(), "Entity does not have component!"); + return scene->registry.get(handle); + } + + template + bool hasComponent() + { + return scene->registry.all_of(handle); + } + + template + void removeComponent() + { + SOPHIA_ASSERT(hasComponent(), "Entity does not have component!"); + scene->registry.remove(handle); + } + + operator bool() const { return handle != entt::null; } + operator entt::entity() const { return handle; } + operator u32() const { return (u32)handle; } + + // UUID GetUUID() { return GetComponent().ID; } + // const std::string& GetName() { return GetComponent().Tag; } + + bool operator==(const Entity& other) const { + return handle == other.handle && scene == other.scene; + } + + bool operator!=(const Entity& other) const { + return !(*this == other); + } + +private: + entt::entity handle { entt::null}; + Scene* scene = nullptr; +}; + +} // namespace sophia diff --git a/engine/src/rendering/scene_renderer.cpp b/engine/src/rendering/scene_renderer.cpp index 4abc935..3262802 100644 --- a/engine/src/rendering/scene_renderer.cpp +++ b/engine/src/rendering/scene_renderer.cpp @@ -1,12 +1,61 @@ #include "rendering/scene_renderer.hpp" +#include +#include + namespace sophia { +namespace { + struct PushConstantData { + glm::mat4 transform{1.f}; + glm::vec4 color{1.f}; + }; +} + SceneRenderer::SceneRenderer(ResourceRegistry& resources) : resources{resources} {} SceneRenderer::~SceneRenderer() {} -void SceneRenderer::render(const Scene& scene, RenderTargetHandle target) {} +void SceneRenderer::render(const Scene& scene, Entity camera, RenderTargetHandle target) { + SOPHIA_ASSERT(camera.hasComponent(), "camera does not have camera component!"); + + auto& R = scene.registry; + + // Get all mesh + // For each mesh, get all entities(ES) that have a transform and that mesh + // For e in ES: add e's transform component to a list + + // We now have + /* + M = mesh + T = transform + + Work Batch + |- M0 + | |- T0 + | \- T2 + | + |- M1 + | |- T1 + | \- T5 + | + \- M2 + |- T3 + \- T4 + + */ + + /* + for batch in Work Batch: + batch.mesh.bind() + + for transform in batch.transforms: + commandBuffer.pushConstants(transform) + batch.mesh.draw(commandBuffer) + + NOTE: Use instanced rendering? + */ +} } // namespace sophia diff --git a/engine/src/rendering/scene_renderer.hpp b/engine/src/rendering/scene_renderer.hpp index 39e4537..1ef0bce 100644 --- a/engine/src/rendering/scene_renderer.hpp +++ b/engine/src/rendering/scene_renderer.hpp @@ -3,10 +3,14 @@ #include #include +#include "entity.hpp" #include "resources/resource_registry.hpp" namespace sophia { + /** + * !TEMP to be decoupled once scene batching and rendering impl + */ class SceneRenderer { public: SceneRenderer(const SceneRenderer&) = delete; @@ -15,8 +19,7 @@ class SceneRenderer { SceneRenderer(ResourceRegistry& resources); ~SceneRenderer(); - // add camera as a arg (entity) - void render(const Scene& scene, RenderTargetHandle target); + void render(const Scene& scene, Entity camera, RenderTargetHandle target); private: ResourceRegistry& resources; diff --git a/engine/src/ui/debug_ui.cpp b/engine/src/ui/debug_ui.cpp index f52cf17..ffd5d17 100644 --- a/engine/src/ui/debug_ui.cpp +++ b/engine/src/ui/debug_ui.cpp @@ -12,6 +12,7 @@ DebugUI::DebugUI(PanelRegistry& registry, ConsoleCommandRegistry& commands) this->panelRegistryHandle = registry.emplace(registry); this->frameStatsHandle = registry.emplace(); this->consoleHandle = registry.emplace(commands); + hide(); // #endif // !NDEBUG }