Formatting
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace sophia {
|
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
|
||||||
|
|||||||
+15
-19
@@ -1,44 +1,42 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <sophia/scene.hpp>
|
|
||||||
#include <entt/entt.hpp>
|
#include <entt/entt.hpp>
|
||||||
#include <sophia/util/assert.hpp>
|
#include <sophia/scene.hpp>
|
||||||
#include <sophia/types.hpp>
|
#include <sophia/types.hpp>
|
||||||
|
#include <sophia/util/assert.hpp>
|
||||||
|
|
||||||
namespace sophia {
|
namespace sophia {
|
||||||
|
|
||||||
class Entity {
|
class Entity {
|
||||||
public:
|
public:
|
||||||
Entity(const Entity&) = default;
|
Entity(const Entity&) = default;
|
||||||
Entity& operator=(const Entity&) = default;
|
Entity& operator=(const Entity&) = default;
|
||||||
|
|
||||||
Entity() = default;
|
Entity() = default;
|
||||||
Entity(entt::entity handle, Scene* scene);
|
Entity(entt::entity handle, Scene* scene);
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
template <typename T, typename... Args>
|
||||||
T& addComponent(Args&&... args) {
|
T& addComponent(Args&&... args) {
|
||||||
SOPHIA_ASSERT(!hasComponent<T>(), "Entity already has component!");
|
SOPHIA_ASSERT(!hasComponent<T>(), "Entity already has component!");
|
||||||
T& component = scene->registry.emplace<T>(handle, std::forward<Args>(args)...);
|
T& component =
|
||||||
|
scene->registry.emplace<T>(handle, std::forward<Args>(args)...);
|
||||||
// scene->OnComponentAdded<T>(*this, component);
|
// scene->OnComponentAdded<T>(*this, component);
|
||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template <typename T>
|
||||||
T& getComponent()
|
T& getComponent() {
|
||||||
{
|
|
||||||
SOPHIA_ASSERT(hasComponent<T>(), "Entity does not have component!");
|
SOPHIA_ASSERT(hasComponent<T>(), "Entity does not have component!");
|
||||||
return scene->registry.get<T>(handle);
|
return scene->registry.get<T>(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template <typename T>
|
||||||
bool hasComponent()
|
bool hasComponent() {
|
||||||
{
|
|
||||||
return scene->registry.all_of<T>(handle);
|
return scene->registry.all_of<T>(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template <typename T>
|
||||||
void removeComponent()
|
void removeComponent() {
|
||||||
{
|
|
||||||
SOPHIA_ASSERT(hasComponent<T>(), "Entity does not have component!");
|
SOPHIA_ASSERT(hasComponent<T>(), "Entity does not have component!");
|
||||||
scene->registry.remove<T>(handle);
|
scene->registry.remove<T>(handle);
|
||||||
}
|
}
|
||||||
@@ -54,12 +52,10 @@ public:
|
|||||||
return handle == other.handle && scene == other.scene;
|
return handle == other.handle && scene == other.scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!=(const Entity& other) const {
|
bool operator!=(const Entity& other) const { return !(*this == other); }
|
||||||
return !(*this == other);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
entt::entity handle { entt::null};
|
entt::entity handle{entt::null};
|
||||||
Scene* scene = nullptr;
|
Scene* scene = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,26 +1,28 @@
|
|||||||
#include "rendering/scene_renderer.hpp"
|
#include "rendering/scene_renderer.hpp"
|
||||||
|
|
||||||
#include <sophia/util/assert.hpp>
|
|
||||||
#include <sophia/components.hpp>
|
#include <sophia/components.hpp>
|
||||||
|
#include <sophia/util/assert.hpp>
|
||||||
|
|
||||||
namespace sophia {
|
namespace sophia {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
struct PushConstantData {
|
struct PushConstantData {
|
||||||
glm::mat4 transform{1.f};
|
glm::mat4 transform{1.f};
|
||||||
glm::vec4 color{1.f};
|
glm::vec4 color{1.f};
|
||||||
};
|
};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
SceneRenderer::SceneRenderer(ResourceRegistry& resources)
|
SceneRenderer::SceneRenderer(ResourceRegistry& resources)
|
||||||
: resources{resources} {}
|
: resources{resources} {}
|
||||||
|
|
||||||
SceneRenderer::~SceneRenderer() {}
|
SceneRenderer::~SceneRenderer() {}
|
||||||
|
|
||||||
void SceneRenderer::render(const Scene& scene, Entity camera, RenderTargetHandle target) {
|
void SceneRenderer::render(const Scene& scene, Entity camera,
|
||||||
SOPHIA_ASSERT(camera.hasComponent<CameraComponent>(), "camera does not have camera component!");
|
RenderTargetHandle target) {
|
||||||
|
SOPHIA_ASSERT(camera.hasComponent<CameraComponent>(),
|
||||||
|
"camera does not have camera component!");
|
||||||
|
|
||||||
auto& R = scene.registry;
|
auto& registry = scene.registry;
|
||||||
|
|
||||||
// Get all mesh
|
// Get all mesh
|
||||||
// For each mesh, get all entities(ES) that have a transform and that mesh
|
// For each mesh, get all entities(ES) that have a transform and that mesh
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
namespace sophia {
|
namespace sophia {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* !TEMP to be decoupled once scene batching and rendering impl
|
* !TEMP to be decoupled once scene batching and rendering impl
|
||||||
*/
|
*/
|
||||||
class SceneRenderer {
|
class SceneRenderer {
|
||||||
|
|||||||
Reference in New Issue
Block a user