Cleanup
This commit is contained in:
@@ -28,7 +28,10 @@ class HydraComponentArray : public IHydraComponentArray
|
||||
void RemoveComponent(HydraID entity_id)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
assert(m_entity_to_component.find(entity_id) == m_entity_to_component.end() && "Trying to remove a component that doesnt exist");
|
||||
if(m_entity_to_component.find(entity_id) == m_entity_to_component.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
HydraID component_index = m_entity_to_component[entity_id];
|
||||
HydraID last_component_index = m_component_count -1;
|
||||
@@ -80,15 +83,8 @@ class HydraComponentArray : public IHydraComponentArray
|
||||
|
||||
void EntityDeleted(HydraID entity_id)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
if(m_entity_to_component.find(entity_id) != m_entity_to_component.end())
|
||||
{
|
||||
RemoveComponent(entity_id);
|
||||
}
|
||||
RemoveComponent(entity_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif /* HYDRACOMPONENTARRAY */
|
||||
|
||||
@@ -24,9 +24,8 @@ public:
|
||||
void DestroyEntity(HydraID entity_id)
|
||||
{
|
||||
m_system_manager->EntityDeleted(entity_id);
|
||||
m_entity_manager->DeleteEntity(entity_id);
|
||||
m_component_manager->EntityDeleted(entity_id);
|
||||
|
||||
m_entity_manager->DeleteEntity(entity_id);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
||||
@@ -36,13 +36,17 @@ void HydraDirectionalShadowSourceSystem::InitialiseComponent(HydraID entity_id)
|
||||
|
||||
HydraDirectionalShadowSourceComponent& shadow_comp = ecs->GetComponent<HydraDirectionalShadowSourceComponent>(entity_id);
|
||||
|
||||
//light_comp.shadow_map_id = shadow_id;
|
||||
light_comp.shadow_caster = 1;
|
||||
//shadow_comp.shadow_id = shadow_id;
|
||||
shadow_comp.entity_id = entity_id;
|
||||
|
||||
HydraID shadow_id = GetEngine()->ShadowBufferManager()->AddDirectionalShadow(shadow_comp);
|
||||
assert(shadow_id != INVALID_HYDRA_ID && "Add directional Shadow - out of shadows!");
|
||||
|
||||
light_comp.shadow_map_id = shadow_id;
|
||||
light_comp.shadow_caster = 1;
|
||||
shadow_comp.shadow_id = shadow_id;
|
||||
_InitialiseShadowMap(entity_id);
|
||||
|
||||
|
||||
//_InitialiseShadowMap(entity_id);
|
||||
}
|
||||
|
||||
void HydraDirectionalShadowSourceSystem::DestroyComponent(HydraID entity_id)
|
||||
@@ -50,8 +54,7 @@ void HydraDirectionalShadowSourceSystem::DestroyComponent(HydraID entity_id)
|
||||
HydraEngine *engine = GetEngine();
|
||||
HydraECS *ecs = engine->ECS();
|
||||
HydraDirectionalShadowSourceComponent& shadow_comp = ecs->GetComponent<HydraDirectionalShadowSourceComponent>(entity_id);
|
||||
GetEngine()->ShadowBufferManager()->DeleteDirectionalShadow(shadow_comp.shadow_id);
|
||||
|
||||
GetEngine()->ShadowBufferManager()->DeleteDirectionalShadow(shadow_comp.shadow_id);
|
||||
}
|
||||
|
||||
void HydraDirectionalShadowSourceSystem::UpdateSystem(float delta_t_seconds)
|
||||
@@ -110,24 +113,3 @@ void HydraDirectionalShadowSourceSystem::_UpdateShadowMap(HydraID entity_id)
|
||||
}
|
||||
|
||||
|
||||
void HydraDirectionalShadowSourceSystem::_InitialiseShadowMap(HydraID entity_id)
|
||||
{
|
||||
HydraEngine *engine = GetEngine();
|
||||
HydraECS *ecs = engine->ECS();
|
||||
HydraTextureBufferManager *tex_man = engine->TextureBufferManager();
|
||||
HydraDirectionalShadowSourceComponent &shad_comp = ecs->GetComponent<HydraDirectionalShadowSourceComponent>(entity_id);
|
||||
HydraLightComponent &light_comp = ecs->GetComponent<HydraLightComponent>(entity_id);
|
||||
|
||||
shad_comp.entity_id = entity_id;
|
||||
|
||||
HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
|
||||
|
||||
uint32_t depth_texture_id = 0;
|
||||
HydraID create_framebuffer_task_id = task_scheduler->CreateTask<HydraCreateCascadeShadowFrameBuffer>(HydraThreadAffinity::Render);
|
||||
HydraCreateCascadeShadowFrameBuffer *fb_task = static_cast<HydraCreateCascadeShadowFrameBuffer *>(task_scheduler->GetTask(create_framebuffer_task_id));
|
||||
fb_task->Initialise(&depth_texture_id, &shad_comp.frame_buffer_id);
|
||||
|
||||
task_scheduler->WaitForTask(create_framebuffer_task_id);
|
||||
shad_comp.shadow_texture_id = depth_texture_id;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,7 @@ class HydraDirectionalShadowSourceSystem : public HydraSystem
|
||||
void UpdateSystem(float delta_t_seconds) override;
|
||||
private:
|
||||
void _UpdateShadowMap(HydraID entity_id);
|
||||
|
||||
void _InitialiseShadowMap(HydraID entity_id);
|
||||
|
||||
HydraID m_shadow_actor_id = INVALID_HYDRA_ID;
|
||||
std::mutex m_mutex;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "../components/HydraLightComponent.h"
|
||||
#include "../components/HydraPositionComponent.h"
|
||||
#include "../../buffer/HydraLightBufferManager.h"
|
||||
#include "../../buffer/HydraLightBuffer.h"
|
||||
|
||||
|
||||
#include "../../scheduler/HydraTaskScheduler.h"
|
||||
#include "../../task/buffer/HydraCreateGPUBufferTask.hpp"
|
||||
@@ -15,51 +15,27 @@
|
||||
|
||||
void HydraLightSystem::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("LightBuffer", 1, MAX_LIGHTS * sizeof(HydraLightComponent), &m_light_buffer_id, HYDRA_BUFFER_TYPE::HYDRA_SSBO_BUFFER);
|
||||
task_scheduler->WaitForTask(create_gpu_buffer_task_id);
|
||||
|
||||
}
|
||||
|
||||
uint32_t HydraLightSystem::GetLightCount()
|
||||
{
|
||||
return m_lights.size();
|
||||
}
|
||||
|
||||
void HydraLightSystem::InitialiseComponent(HydraID entity_id)
|
||||
{
|
||||
HydraLightBufferManager *light_man = GetEngine()->LightBufferManager();
|
||||
uint32_t light_count = light_man->GetLightCount();
|
||||
HydraECS *ecs = GetEngine()->ECS();
|
||||
|
||||
HydraPositionComponent &pos_comp = ecs->GetComponent<HydraPositionComponent>(entity_id);
|
||||
HydraLightComponent &light_comp = ecs->GetComponent<HydraLightComponent>(entity_id);
|
||||
|
||||
m_lights.push_back(light_comp);
|
||||
light_man->AddLight(light_comp);
|
||||
}
|
||||
|
||||
void HydraLightSystem::FreeSystemResources()
|
||||
void HydraLightSystem::DestroyComponent(HydraID actor_id)
|
||||
{
|
||||
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_light_buffer_id);
|
||||
task_scheduler->WaitForTask(delete_gpu_buffer_task_id);
|
||||
HydraLightBufferManager *light_man = GetEngine()->LightBufferManager();
|
||||
light_man->RemoveLight(actor_id);
|
||||
}
|
||||
|
||||
void HydraLightSystem::UpdateSystem(float delta_t_seconds)
|
||||
{
|
||||
_WriteToGPU();
|
||||
HydraLightBufferManager *light_man = GetEngine()->LightBufferManager();
|
||||
light_man->UpdateBuffer();
|
||||
}
|
||||
|
||||
void HydraLightSystem::_WriteToGPU()
|
||||
{
|
||||
void *buffer = static_cast<void *>(m_lights.data());
|
||||
HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
|
||||
|
||||
HydraID update_buffer_task_id = task_scheduler->CreateTask<HydraUpdatePartialGPUBufferTask>(HydraThreadAffinity::Render);
|
||||
HydraUpdatePartialGPUBufferTask *task = static_cast<HydraUpdatePartialGPUBufferTask *>(task_scheduler->GetTask(update_buffer_task_id));
|
||||
task->Intialise(m_light_buffer_id, 0, sizeof(HydraLightComponent) * m_lights.size(), buffer);
|
||||
task_scheduler->WaitForTask(update_buffer_task_id);
|
||||
}
|
||||
@@ -14,15 +14,15 @@ class HydraLightSystem : public HydraSystem
|
||||
{
|
||||
public:
|
||||
void Initialise() override;
|
||||
uint32_t GetLightCount();
|
||||
//uint32_t GetLightCount();
|
||||
protected:
|
||||
void InitialiseComponent(HydraID entity_id) override;
|
||||
void FreeSystemResources() override;
|
||||
void DestroyComponent(HydraID actor_id) override;
|
||||
virtual void UpdateSystem(float delta_t_seconds);
|
||||
private:
|
||||
void _WriteToGPU();
|
||||
|
||||
HydraID m_light_buffer_id = INVALID_HYDRA_ID;
|
||||
std::vector<HydraLightComponent> m_lights;
|
||||
|
||||
|
||||
};
|
||||
#endif /* HYDRALIGHTSYSTEM */
|
||||
|
||||
@@ -37,8 +37,9 @@ void HydraPointShadowSourceSystem::InitialiseComponent(HydraID entity_id)
|
||||
|
||||
light_comp.shadow_map_id = shadow_id;
|
||||
light_comp.shadow_caster = 1;
|
||||
shadow_comp.shadow_id = shadow_id;
|
||||
_InitialiseShadowMap(entity_id);
|
||||
shadow_comp.entity_id = entity_id;
|
||||
//shadow_comp.shadow_id = shadow_id;
|
||||
//_InitialiseShadowMap(entity_id);
|
||||
}
|
||||
|
||||
void HydraPointShadowSourceSystem::UpdateSystem(float delta_t_seconds)
|
||||
@@ -51,7 +52,7 @@ void HydraPointShadowSourceSystem::UpdateSystem(float delta_t_seconds)
|
||||
|
||||
void HydraPointShadowSourceSystem::DestroyComponent(HydraID entity_id)
|
||||
{
|
||||
HydraEngine *engine = GetEngine();
|
||||
HydraEngine *engine = GetEngine();
|
||||
HydraECS *ecs = engine->ECS();
|
||||
HydraPointShadowSourceComponent& shadow_comp = ecs->GetComponent<HydraPointShadowSourceComponent>(entity_id);
|
||||
GetEngine()->ShadowBufferManager()->DeletePointShadow(shadow_comp.shadow_id);
|
||||
@@ -85,7 +86,7 @@ void HydraPointShadowSourceSystem::_UpdateShadowMap(HydraID entity_id)
|
||||
//GL_TEXTURE_CUBE_MAP_NEGATIVE_X - right
|
||||
shad_comp.light_space_view[1] = glm::lookAt(light_pos, light_pos + glm::vec3(-1.0, 0.0, 0.0), glm::vec3(0.0, 1.0, 0.0));
|
||||
//GL_TEXTURE_CUBE_MAP_POSITIVE_Y - Up
|
||||
shad_comp.light_space_view[2] = glm::lookAt(light_pos, light_pos + glm::vec3(0.0, 1.0, 0.0), glm::vec3(0.0, 0.0, 1.0));
|
||||
shad_comp.light_space_view[2] = glm::lookAt(light_pos, light_pos + glm::vec3(0.0, 1.0, 0.0), glm::vec3(0.0, 0.0, -1.0));
|
||||
//GL_TEXTURE_CUBE_MAP_NEGATIVE_Y - down
|
||||
shad_comp.light_space_view[3] = glm::lookAt(light_pos, light_pos + glm::vec3(0.0, -1.0, 0.0), glm::vec3(0.0, 0.0, 1.0));
|
||||
//GL_TEXTURE_CUBE_MAP_POSITIVE_Z - back
|
||||
@@ -101,22 +102,22 @@ void HydraPointShadowSourceSystem::_UpdateShadowMap(HydraID entity_id)
|
||||
|
||||
void HydraPointShadowSourceSystem::_InitialiseShadowMap(HydraID entity_id)
|
||||
{
|
||||
HydraEngine *engine = GetEngine();
|
||||
HydraECS *ecs = engine->ECS();
|
||||
HydraTextureBufferManager *tex_man = engine->TextureBufferManager();
|
||||
HydraPointShadowSourceComponent &shad_comp = ecs->GetComponent<HydraPointShadowSourceComponent>(entity_id);
|
||||
HydraLightComponent &light_comp = ecs->GetComponent<HydraLightComponent>(entity_id);
|
||||
// HydraEngine *engine = GetEngine();
|
||||
// HydraECS *ecs = engine->ECS();
|
||||
// HydraTextureBufferManager *tex_man = engine->TextureBufferManager();
|
||||
// HydraPointShadowSourceComponent &shad_comp = ecs->GetComponent<HydraPointShadowSourceComponent>(entity_id);
|
||||
// HydraLightComponent &light_comp = ecs->GetComponent<HydraLightComponent>(entity_id);
|
||||
|
||||
shad_comp.entity_id = entity_id;
|
||||
// shad_comp.entity_id = entity_id;
|
||||
|
||||
HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
|
||||
// HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
|
||||
|
||||
uint32_t depth_texture_id = 0;
|
||||
HydraID create_framebuffer_task_id = task_scheduler->CreateTask<HydraCreateCubemapShadowFrameBuffer>(HydraThreadAffinity::Render);
|
||||
HydraCreateCubemapShadowFrameBuffer *fb_task = static_cast<HydraCreateCubemapShadowFrameBuffer *>(task_scheduler->GetTask(create_framebuffer_task_id));
|
||||
fb_task->Initialise(&shad_comp.shadow_texture_id, &depth_texture_id, &shad_comp.frame_buffer_id);
|
||||
// uint32_t depth_texture_id = 0;
|
||||
// HydraID create_framebuffer_task_id = task_scheduler->CreateTask<HydraCreateCubemapShadowFrameBuffer>(HydraThreadAffinity::Render);
|
||||
// HydraCreateCubemapShadowFrameBuffer *fb_task = static_cast<HydraCreateCubemapShadowFrameBuffer *>(task_scheduler->GetTask(create_framebuffer_task_id));
|
||||
// fb_task->Initialise(&shad_comp.shadow_texture_id, &depth_texture_id, &shad_comp.frame_buffer_id);
|
||||
|
||||
task_scheduler->WaitForTask(create_framebuffer_task_id);
|
||||
shad_comp.shadow_texture_id = depth_texture_id;
|
||||
// task_scheduler->WaitForTask(create_framebuffer_task_id);
|
||||
// shad_comp.shadow_texture_id = depth_texture_id;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ void HydraSpotShadowSourceSystem::InitialiseComponent(HydraID entity_id)
|
||||
|
||||
light_comp.shadow_map_id = shadow_id;
|
||||
light_comp.shadow_caster = 1;
|
||||
shadow_comp.shadow_id = shadow_id;
|
||||
shadow_comp.entity_id = entity_id;
|
||||
_InitialiseShadowMap(entity_id);
|
||||
|
||||
}
|
||||
@@ -103,22 +103,22 @@ void HydraSpotShadowSourceSystem::_UpdateShadowMap(HydraID entity_id)
|
||||
|
||||
void HydraSpotShadowSourceSystem::_InitialiseShadowMap(HydraID entity_id)
|
||||
{
|
||||
HydraEngine *engine = GetEngine();
|
||||
HydraECS *ecs = engine->ECS();
|
||||
HydraTextureBufferManager *tex_man = engine->TextureBufferManager();
|
||||
HydraSpotShadowSourceComponent &shad_comp = ecs->GetComponent<HydraSpotShadowSourceComponent>(entity_id);
|
||||
HydraLightComponent &light_comp = ecs->GetComponent<HydraLightComponent>(entity_id);
|
||||
// HydraEngine *engine = GetEngine();
|
||||
// HydraECS *ecs = engine->ECS();
|
||||
// HydraTextureBufferManager *tex_man = engine->TextureBufferManager();
|
||||
// HydraSpotShadowSourceComponent &shad_comp = ecs->GetComponent<HydraSpotShadowSourceComponent>(entity_id);
|
||||
// HydraLightComponent &light_comp = ecs->GetComponent<HydraLightComponent>(entity_id);
|
||||
|
||||
shad_comp.entity_id = entity_id;
|
||||
// shad_comp.entity_id = entity_id;
|
||||
|
||||
HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
|
||||
// HydraTaskScheduler *task_scheduler = GetEngine()->TaskScheduler();
|
||||
|
||||
uint32_t depth_texture_id = 0;
|
||||
HydraID create_framebuffer_task_id = task_scheduler->CreateTask<HydraCreateShadowFrameBuffer>(HydraThreadAffinity::Render);
|
||||
HydraCreateShadowFrameBuffer *fb_task = static_cast<HydraCreateShadowFrameBuffer *>(task_scheduler->GetTask(create_framebuffer_task_id));
|
||||
fb_task->Initialise(&shad_comp.shadow_texture_id, &depth_texture_id, &shad_comp.frame_buffer_id);
|
||||
// uint32_t depth_texture_id = 0;
|
||||
// HydraID create_framebuffer_task_id = task_scheduler->CreateTask<HydraCreateShadowFrameBuffer>(HydraThreadAffinity::Render);
|
||||
// HydraCreateShadowFrameBuffer *fb_task = static_cast<HydraCreateShadowFrameBuffer *>(task_scheduler->GetTask(create_framebuffer_task_id));
|
||||
// fb_task->Initialise(&shad_comp.shadow_texture_id, &depth_texture_id, &shad_comp.frame_buffer_id);
|
||||
|
||||
task_scheduler->WaitForTask(create_framebuffer_task_id);
|
||||
shad_comp.shadow_texture_id = depth_texture_id;
|
||||
// task_scheduler->WaitForTask(create_framebuffer_task_id);
|
||||
// shad_comp.shadow_texture_id = depth_texture_id;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user