Point lights

This commit is contained in:
Confideo-IOM
2026-08-28 16:36:25 +01:00
parent 30538ae7ab
commit e3d37e3f8a
60 changed files with 458 additions and 184 deletions
+16 -5
View File
@@ -15,7 +15,7 @@ class IHydraComponentArray
};
template<typename T>
class HydraComponentArray : public IHydraComponentArray
class HydraComponentArray : public IHydraComponentArray, HydraObject
{
private:
std::array<T, MAX_ACTORS> m_components;
@@ -28,11 +28,12 @@ class HydraComponentArray : public IHydraComponentArray
void RemoveComponent(HydraID entity_id)
{
std::lock_guard<std::mutex> lock(m_mutex);
if(m_entity_to_component.find(entity_id) == m_entity_to_component.end())
{
return;
}
DebugLog("COMPONENT DELETED:" + std::to_string(entity_id) + "\n");
HydraID component_index = m_entity_to_component[entity_id];
HydraID last_component_index = m_component_count -1;
HydraID last_entity_id = m_component_to_entity[last_component_index];
@@ -41,15 +42,21 @@ class HydraComponentArray : public IHydraComponentArray
{
m_components[component_index] = m_components[last_component_index];
m_entity_to_component[last_entity_id] = component_index;
m_component_to_entity.erase(last_component_index);
m_component_to_entity[component_index] = last_entity_id;
m_components[last_component_index] = {};
DebugLog("COMPONENT MOVED:" + std::to_string(last_entity_id) + "\n");
}
else
{
m_components[component_index] = {};
m_components[last_component_index] = {};
m_entity_to_component.erase(entity_id);
m_component_to_entity.erase(last_component_index);
}
m_entity_to_component.erase(entity_id);
m_component_to_entity.erase(component_index);
m_component_count--;
}
@@ -85,6 +92,10 @@ class HydraComponentArray : public IHydraComponentArray
{
RemoveComponent(entity_id);
}
T const * const GetComponents()
{
return &m_components[0];
}
};
#endif /* HYDRACOMPONENTARRAY */
+11 -3
View File
@@ -19,12 +19,14 @@ class HydraComponentManager :public HydraObject
std::shared_ptr<HydraComponentArray<T>> _GetComponentArray()
{
std::string type_name = std::string(typeid(T).name());
if(m_component_types.find(type_name) == m_component_types.end())
{
std::cout << "Error";
}
assert(m_component_types.find(type_name) != m_component_types.end() && "Component type does not exist");
return std::static_pointer_cast<HydraComponentArray<T>>(m_component_arrays[type_name]);
}
public:
template<typename T>
ComponentTypeID RegisterComponentType()
{
@@ -58,7 +60,13 @@ class HydraComponentManager :public HydraObject
{
return _GetComponentArray<T>()->GetComponent(entity_id);
}
template<typename T>
T const * const GetComponents()
{
return _GetComponentArray<T>()->GetComponents();
}
template<typename T>
bool HasComponent(HydraID entity_id)
{
+10 -1
View File
@@ -59,7 +59,7 @@ public:
{
// Remove the component from the entity
m_component_manager->RemoveComponent<T>(entity_id);
std::string(typeid(T).name());
// Get the current signature, remove the component from it and update
auto signature = m_entity_manager->GetSignature(entity_id);
signature.set(m_component_manager->GetComponentTypeID<T>(), false);
@@ -79,6 +79,11 @@ public:
{
return m_component_manager->GetComponent<T>(entity_id);
}
template <typename T>
T &GetComponents()
{
return m_component_manager->GetComponents<T>();
}
template <typename T>
std::shared_ptr<T> RegisterSystem()
@@ -100,6 +105,10 @@ public:
{
m_system_manager->InitialiseComponents();
}
void DeleteComponents()
{
m_system_manager->DeleteComponents();
}
};
#endif /* HYDRAECS */
+15 -7
View File
@@ -6,11 +6,12 @@ void HydraSystem::Update(float delta_t_seconds)
UpdateSystem(delta_t_seconds);
}
void HydraSystem::Shutdown()
{
for(HydraID entity_id : Entities)
{
DestroyComponents(entity_id);
DestroyComponent(entity_id);
}
FreeSystemResources();
}
@@ -23,13 +24,20 @@ void HydraSystem::InitialiseComponents()
}
EntitiesToCreate.clear();
}
void HydraSystem::DestroyComponents(HydraID actor_id)
void HydraSystem::DeleteComponents()
{
auto it = std::find(Entities.begin(), Entities.end(), actor_id);
if(it == Entities.end())
for(auto it = EntitiesToDelete.begin(); it != EntitiesToDelete.end(); ++it)
{
return;
HydraID actor_id = *it;
DestroyComponent(actor_id);
}
EntitiesToDelete.clear();
}
void HydraSystem::DeleteComponent(HydraID actor_id)
{
if(std::find(Entities.begin(), Entities.end(), actor_id)!= Entities.end())
{
DestroyComponent(actor_id);
}
DestroyComponent(actor_id);
}
+6 -4
View File
@@ -10,17 +10,19 @@ class HydraSystem : public HydraObject
public:
std::set<HydraID> Entities;
std::set<HydraID> EntitiesToCreate;
std::set<HydraID> EntitiesToDelete;
void Update(float delta_t_seconds);
void InitialiseComponents();
void InitialiseComponents();
void DeleteComponents();
void DeleteComponent(HydraID actor_id);
virtual void InitialiseComponent(HydraID actor_id) {};
void DestroyComponents(HydraID actor_id);
virtual void Shutdown();
virtual void Initialise(){};
protected:
virtual void UpdateSystem(float delta_t_seconds) = 0;
virtual void UpdateSystem(float delta_t_seconds) = 0;
virtual void DestroyComponent(HydraID actor_id) {};
virtual void FreeSystemResources(){};
};
+12 -2
View File
@@ -75,7 +75,8 @@ public:
// Entity signature does not match system signature - erase from set
else
{
system->DestroyComponents(entity_id);
//system->DestroyComponents(entity_id);
//system->DeleteComponent(entity_id);
system->Entities.erase(entity_id);
system->EntitiesToCreate.erase(entity_id);
}
@@ -87,11 +88,20 @@ public:
for (auto const& pair : m_systems)
{
auto const& system = pair.second;
system->DestroyComponents(entity_id);
system->DeleteComponent(entity_id);
//system->EntitiesToDelete.insert(entity_id);
system->Entities.erase(entity_id);
system->EntitiesToCreate.erase(entity_id);
}
}
void DeleteComponents()
{
for (auto const& pair : m_systems)
{
auto const& system = pair.second;
system->DeleteComponents();
}
}
void InitialiseComponents()
{
for (auto const& pair : m_systems)
@@ -0,0 +1,9 @@
#ifndef HYDRASHADOWCASTERCOMPONENT
#define HYDRASHADOWCASTERCOMPONENT
#include "../../engine/HydraEngine.h"
struct HydraShadowCasterComponent
{
};
#endif /* HYDRASHADOWCASTERCOMPONENT */
@@ -16,58 +16,22 @@
void HydraMaterialSystem::Initialise()
{
HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
HydraID create_gpu_buffer_task_id = task_scheduler->CreateTask<HydraCreateGPUBufferTask>(HydraThreadAffinity::Render);
HydraCreateGPUBufferTask *task = static_cast<HydraCreateGPUBufferTask *>(task_scheduler->GetTask(create_gpu_buffer_task_id));
task->Intialise("MaterialBuffer", 1, MAX_MATERIALS * sizeof(HydraMaterialBuffer), &m_material_buffer_id, HYDRA_BUFFER_TYPE::HYDRA_SSBO_BUFFER);
task_scheduler->WaitForTask(create_gpu_buffer_task_id);
create_gpu_buffer_task_id = task_scheduler->CreateTask<HydraCreateGPUBufferTask>(HydraThreadAffinity::Render);
task = static_cast<HydraCreateGPUBufferTask *>(task_scheduler->GetTask(create_gpu_buffer_task_id));
task->Intialise("TextureBuffer", 1, MAX_TEXTURES * sizeof(uint64_t), &m_texture_buffer_id, HYDRA_BUFFER_TYPE::HYDRA_SSBO_BUFFER);
task_scheduler->WaitForTask(create_gpu_buffer_task_id);
}
void HydraMaterialSystem::InitialiseComponent(HydraID entity_id)
{
}
void HydraMaterialSystem::FreeSystemResources()
{
HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
HydraID delete_gpu_buffer_task_id = task_scheduler->CreateTask<HydraDeleteGPUBufferTask>(HydraThreadAffinity::Render);
HydraDeleteGPUBufferTask *task = static_cast<HydraDeleteGPUBufferTask *>(task_scheduler->GetTask(delete_gpu_buffer_task_id));
task->Intialise(m_material_buffer_id);
task_scheduler->WaitForTask(delete_gpu_buffer_task_id);
delete_gpu_buffer_task_id = task_scheduler->CreateTask<HydraDeleteGPUBufferTask>(HydraThreadAffinity::Render);
task = static_cast<HydraDeleteGPUBufferTask *>(task_scheduler->GetTask(delete_gpu_buffer_task_id));
task->Intialise(m_texture_buffer_id);
task_scheduler->WaitForTask(delete_gpu_buffer_task_id);
}
void HydraMaterialSystem::UpdateSystem(float delta_t_seconds)
{
_WriteToGPU();
GetEngine()->MaterialBufferManager()->UpdateBuffer();
}
void HydraMaterialSystem::_WriteToGPU()
void HydraMaterialSystem::DestroyComponent(HydraID entity_id)
{
void* buffer = GetEngine()->MaterialBufferManager()->GetMaterialBuffer();
HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
HydraID update_buffer_task_id = task_scheduler->CreateTask<HydraUpdateWholeGPUBufferTask>(HydraThreadAffinity::Render);
HydraUpdateWholeGPUBufferTask *task = static_cast<HydraUpdateWholeGPUBufferTask *>(task_scheduler->GetTask(update_buffer_task_id));
task->Intialise(m_material_buffer_id, buffer);
task_scheduler->WaitForTask(update_buffer_task_id);
buffer = GetEngine()->TextureBufferManager()->GetTextureBuffer();
update_buffer_task_id = task_scheduler->CreateTask<HydraUpdateWholeGPUBufferTask>(HydraThreadAffinity::Render);
task = static_cast<HydraUpdateWholeGPUBufferTask *>(task_scheduler->GetTask(update_buffer_task_id));
task->Intialise(m_texture_buffer_id, buffer);
task_scheduler->WaitForTask(update_buffer_task_id);
HydraMaterialComponent mat_comp = GetEngine()->ECS()->GetComponent<HydraMaterialComponent>(entity_id);
GetEngine()->MaterialBufferManager()->DeleteMaterial(mat_comp.material_id);
}
@@ -14,9 +14,11 @@ class HydraMaterialSystem : public HydraSystem
public:
void Initialise() override;
void InitialiseComponent(HydraID entity_id) override;
protected:
void FreeSystemResources() override;
virtual void UpdateSystem(float delta_t_seconds);
void DestroyComponent(HydraID entity_id) override;
private:
void _WriteToGPU();
HydraID m_material_buffer_id = INVALID_HYDRA_ID;
@@ -8,6 +8,7 @@
#include "../../task/physics/HydraGetPhysicsUpdatesTask.hpp"
#include "../../task/physics/HydraStepPhysicsTask.h"
#include "../../task/physics/HydraSetPhysicsLinearVelocity.hpp"
#include "../../task/physics/HydraDeletePhysicsObjectTask.h"
#include "../../ecs/HydraECS.h"
#include "../../ecs/components/HydraPhysicsComponent.h"
#include "../../ecs/components/HydraPositionComponent.h"
@@ -86,12 +87,27 @@ void HydraPhysicsSystem::InitialiseComponent(HydraID entity_id)
set_task->Initialise(body_id, pos_comp.position, glm::quat(pos_comp.orientation));
task_scheduler->WaitForTask(task_id);
phys_comp.initialised = true;
DebugLog("PHYSICS CREATED:" + std::to_string(entity_id) + "\n");
}
void HydraPhysicsSystem::DestroyComponent(HydraID entity_id)
{
HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
HydraPhysicsComponent& phys_comp = GetEngine()->ECS()->GetComponent<HydraPhysicsComponent>(entity_id);
if(phys_comp.initialised)
{
HydraID task_id = task_scheduler->CreateTask<HydraDeletePhysicsObjectTask>(HydraThreadAffinity::Physics);
HydraDeletePhysicsObjectTask *task = static_cast<HydraDeletePhysicsObjectTask *>(task_scheduler->GetTask(task_id));
task->Initialise(phys_comp.body_id);
task_scheduler->WaitForTask(task_id);
}
else
{
std::cout << "here";
}
DebugLog("PHYSICS DELETED:" + std::to_string(entity_id) + "\n");
}
void HydraPhysicsSystem::UpdateSystem(float delta_t_seconds)
@@ -101,6 +117,7 @@ void HydraPhysicsSystem::UpdateSystem(float delta_t_seconds)
{
HydraID entity_id = m_bodies_to_set_transform.front();
m_bodies_to_set_transform.pop();
HydraPhysicsComponent& phys_comp = GetEngine()->ECS()->GetComponent<HydraPhysicsComponent>(entity_id);
HydraPositionComponent& pos_comp = GetEngine()->ECS()->GetComponent<HydraPositionComponent>(entity_id);
@@ -68,7 +68,6 @@ void HydraPointShadowSourceSystem::_UpdateShadowMap(HydraID entity_id)
float view_size = 4.0f;
float view_near = 0.1f;
float view_far = 100.0f;
glm::vec3 camera_pos = GetEngine()->Camera()->GetPosition();
@@ -0,0 +1,16 @@
#ifndef HYDRASHADOWCASTERSYSTEM
#define HYDRASHADOWCASTERSYSTEM
#include "../../engine/HydraObject.h"
#include "../HydraSystem.h"
#include <GLMIncludes.h>
#include <queue>
class HydraShadowCasterSystem : public HydraSystem
{
public:
protected:
void UpdateSystem(float delta_t_seconds) override {}
};
#endif /* HYDRASHADOWCASTERSYSTEM */