diff --git a/engine/src/entity.cpp b/engine/src/entity.cpp index e891f90..eed9281 100644 --- a/engine/src/entity.cpp +++ b/engine/src/entity.cpp @@ -2,6 +2,7 @@ namespace sophia { -Entity::Entity(entt::entity handle, Scene* scene) : handle(handle), scene(scene) {} +Entity::Entity(entt::entity handle, Scene* scene) + : handle(handle), scene(scene) {} -} // namespace sophia +} // namespace sophia diff --git a/engine/src/entity.hpp b/engine/src/entity.hpp index 67a4a7a..0c3950d 100644 --- a/engine/src/entity.hpp +++ b/engine/src/entity.hpp @@ -1,44 +1,42 @@ #pragma once -#include #include -#include +#include #include +#include namespace sophia { class Entity { -public: + public: Entity(const Entity&) = default; Entity& operator=(const Entity&) = default; Entity() = default; - Entity(entt::entity handle, Scene* scene); + Entity(entt::entity handle, Scene* scene); - template + template T& addComponent(Args&&... args) { SOPHIA_ASSERT(!hasComponent(), "Entity already has component!"); - T& component = scene->registry.emplace(handle, std::forward(args)...); + T& component = + scene->registry.emplace(handle, std::forward(args)...); // scene->OnComponentAdded(*this, component); return component; } - template - T& getComponent() - { + template + T& getComponent() { SOPHIA_ASSERT(hasComponent(), "Entity does not have component!"); return scene->registry.get(handle); } - template - bool hasComponent() - { + template + bool hasComponent() { return scene->registry.all_of(handle); } - template - void removeComponent() - { + template + void removeComponent() { SOPHIA_ASSERT(hasComponent(), "Entity does not have component!"); scene->registry.remove(handle); } @@ -54,13 +52,11 @@ public: return handle == other.handle && scene == other.scene; } - bool operator!=(const Entity& other) const { - return !(*this == other); - } + bool operator!=(const Entity& other) const { return !(*this == other); } -private: - entt::entity handle { entt::null}; + private: + entt::entity handle{entt::null}; Scene* scene = nullptr; }; -} // namespace sophia +} // namespace sophia diff --git a/engine/src/rendering/scene_renderer.cpp b/engine/src/rendering/scene_renderer.cpp index 3262802..3b32ab3 100644 --- a/engine/src/rendering/scene_renderer.cpp +++ b/engine/src/rendering/scene_renderer.cpp @@ -1,61 +1,63 @@ #include "rendering/scene_renderer.hpp" -#include #include +#include namespace sophia { namespace { - struct PushConstantData { - glm::mat4 transform{1.f}; - glm::vec4 color{1.f}; - }; -} +struct PushConstantData { + glm::mat4 transform{1.f}; + glm::vec4 color{1.f}; +}; +} // namespace SceneRenderer::SceneRenderer(ResourceRegistry& resources) : resources{resources} {} SceneRenderer::~SceneRenderer() {} -void SceneRenderer::render(const Scene& scene, Entity camera, RenderTargetHandle target) { - SOPHIA_ASSERT(camera.hasComponent(), "camera does not have camera component!"); +void SceneRenderer::render(const Scene& scene, Entity camera, + RenderTargetHandle target) { + SOPHIA_ASSERT(camera.hasComponent(), + "camera does not have camera component!"); - auto& R = scene.registry; + auto& registry = 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 + // 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 + // We now have + /* + M = mesh + T = transform - Work Batch - |- M0 - | |- T0 - | \- T2 - | - |- M1 - | |- T1 - | \- T5 - | - \- M2 - |- T3 - \- T4 + Work Batch + |- M0 + | |- T0 + | \- T2 + | + |- M1 + | |- T1 + | \- T5 + | + \- M2 + |- T3 + \- T4 - */ + */ - /* - for batch in Work Batch: - batch.mesh.bind() + /* + for batch in Work Batch: + batch.mesh.bind() - for transform in batch.transforms: - commandBuffer.pushConstants(transform) - batch.mesh.draw(commandBuffer) + for transform in batch.transforms: + commandBuffer.pushConstants(transform) + batch.mesh.draw(commandBuffer) - NOTE: Use instanced rendering? - */ + NOTE: Use instanced rendering? + */ } } // namespace sophia diff --git a/engine/src/rendering/scene_renderer.hpp b/engine/src/rendering/scene_renderer.hpp index 1ef0bce..0eaf29c 100644 --- a/engine/src/rendering/scene_renderer.hpp +++ b/engine/src/rendering/scene_renderer.hpp @@ -8,9 +8,9 @@ namespace sophia { - /** - * !TEMP to be decoupled once scene batching and rendering impl - */ +/** + * !TEMP to be decoupled once scene batching and rendering impl + */ class SceneRenderer { public: SceneRenderer(const SceneRenderer&) = delete;