diff --git a/SHADE_Engine/src/Events/SHEventDefines.h b/SHADE_Engine/src/Events/SHEventDefines.h index e03dfd82..cdef68b9 100644 --- a/SHADE_Engine/src/Events/SHEventDefines.h +++ b/SHADE_Engine/src/Events/SHEventDefines.h @@ -30,5 +30,5 @@ constexpr SHEventIdentifier SH_BUTTON_RELEASE_EVENT { 21 }; constexpr SHEventIdentifier SH_BUTTON_HOVER_ENTER_EVENT { 22 }; constexpr SHEventIdentifier SH_BUTTON_HOVER_EXIT_EVENT { 23 }; constexpr SHEventIdentifier SH_ASSET_COMPILE_EVENT { 24 }; -constexpr SHEventIdentifier SH_LIGHT_DELETE_EVENT { 25 }; +constexpr SHEventIdentifier SH_GRAPHICS_LIGHT_DELETE_EVENT { 25 }; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 22f0423d..d41e93d1 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -542,7 +542,7 @@ namespace SHADE std::make_shared>(this, &SHGraphicsSystem::ReceiveLightDeleteEvent) }; ReceiverPtr lightDeleteReceivePtr = std::dynamic_pointer_cast(lightDeleteEvent); - SHEventManager::SubscribeTo(SH_ASSET_COMPILE_EVENT, lightDeleteReceivePtr); + SHEventManager::SubscribeTo(SH_GRAPHICS_LIGHT_DELETE_EVENT, lightDeleteReceivePtr); std::shared_ptr> compileAssetReceiever @@ -951,19 +951,19 @@ namespace SHADE auto const& EVENT_DATA = reinterpret_cast*>(eventPtr.get())->data; auto* lightComp = SHComponentManager::GetComponent(EVENT_DATA->lightEntity); - if (lightComp && lightComp->GetShadowMapIndex()) + if (lightComp && lightComp->GetShadowMapIndex() != SHLightData::INVALID_SHADOW_MAP_INDEX) { std::string depthResourceName = "ShadowMap_Depth " + std::to_string(EVENT_DATA->lightEntity); std::string shadowMapResourceName = "ShadowMap " + std::to_string(EVENT_DATA->lightEntity); std::string shadowMapBlurredResourceName = "ShadowMap Blurred" + std::to_string(EVENT_DATA->lightEntity); // Remove render graph node - renderGraph->RemoveNode(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data() + shadowMapResourceName); + //renderGraph->RemoveNode(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data() + shadowMapResourceName); // Remove render graph resource - renderGraph->RemoveResource(depthResourceName); - renderGraph->RemoveResource(shadowMapResourceName); - renderGraph->RemoveResource(shadowMapBlurredResourceName); + //renderGraph->RemoveResource(depthResourceName); + //renderGraph->RemoveResource(shadowMapResourceName); + //renderGraph->RemoveResource(shadowMapBlurredResourceName); // Register light component shadow map index into light system as recyclable lightingSubSystem->RemoveShadowMap (EVENT_DATA->lightEntity); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp index 5e95c6ad..f8578647 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp @@ -21,6 +21,14 @@ namespace SHADE void SHLightComponent::OnDestroy(void) { + if (lightData.shadowMapIndex != SHLightData::INVALID_SHADOW_MAP_INDEX) + { + // Create new event and broadcast it + SHDeleteLightEvent newEvent; + newEvent.lightEntity = GetEID(); + + SHEventManager::BroadcastEvent(newEvent, SH_GRAPHICS_LIGHT_DELETE_EVENT); + } }