laptop changes

This commit is contained in:
2026-09-23 04:20:43 +00:00
parent 39253771f1
commit a98eac3dc7
7 changed files with 138 additions and 6 deletions
+7
View File
@@ -0,0 +1,7 @@
#include "entity.hpp"
namespace sophia {
Entity::Entity(entt::entity handle, Scene* scene) : handle(handle), scene(scene) {}
} // namespace sophia
+66
View File
@@ -0,0 +1,66 @@
#pragma once
#include <sophia/scene.hpp>
#include <entt/entt.hpp>
#include <sophia/util/assert.hpp>
#include <sophia/types.hpp>
namespace sophia {
class Entity {
public:
Entity(const Entity&) = default;
Entity& operator=(const Entity&) = default;
Entity() = default;
Entity(entt::entity handle, Scene* scene);
template<typename T, typename... Args>
T& addComponent(Args&&... args) {
SOPHIA_ASSERT(!hasComponent<T>(), "Entity already has component!");
T& component = scene->registry.emplace<T>(handle, std::forward<Args>(args)...);
// scene->OnComponentAdded<T>(*this, component);
return component;
}
template<typename T>
T& getComponent()
{
SOPHIA_ASSERT(hasComponent<T>(), "Entity does not have component!");
return scene->registry.get<T>(handle);
}
template<typename T>
bool hasComponent()
{
return scene->registry.all_of<T>(handle);
}
template<typename T>
void removeComponent()
{
SOPHIA_ASSERT(hasComponent<T>(), "Entity does not have component!");
scene->registry.remove<T>(handle);
}
operator bool() const { return handle != entt::null; }
operator entt::entity() const { return handle; }
operator u32() const { return (u32)handle; }
// UUID GetUUID() { return GetComponent<IDComponent>().ID; }
// const std::string& GetName() { return GetComponent<TagComponent>().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
+50 -1
View File
@@ -1,12 +1,61 @@
#include "rendering/scene_renderer.hpp"
#include <sophia/util/assert.hpp>
#include <sophia/components.hpp>
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<CameraComponent>(), "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
+5 -2
View File
@@ -3,10 +3,14 @@
#include <sophia/handles.hpp>
#include <sophia/scene.hpp>
#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;
+1
View File
@@ -12,6 +12,7 @@ DebugUI::DebugUI(PanelRegistry& registry, ConsoleCommandRegistry& commands)
this->panelRegistryHandle = registry.emplace<PanelRegistryPanel>(registry);
this->frameStatsHandle = registry.emplace<FrameStatsPanel>();
this->consoleHandle = registry.emplace<ConsolePanel>(commands);
hide();
// #endif // !NDEBUG
}