From 8491b7f0842476e62de8e6dc6fca7e8cc9219261 Mon Sep 17 00:00:00 2001 From: Vladislav Belov Date: Sun, 28 Jun 2026 17:34:03 +0200 Subject: [PATCH] Removes Unattach from emitter We don't really need that proxy. As the main idea is to move the ownership from a model to the particle manager. --- source/graphics/ParticleEmitter.cpp | 8 +------- source/graphics/ParticleEmitter.h | 9 --------- source/graphics/ParticleManager.cpp | 1 + source/graphics/ParticleManager.h | 6 +++++- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/source/graphics/ParticleEmitter.cpp b/source/graphics/ParticleEmitter.cpp index 527cbdb711..c3ef498551 100644 --- a/source/graphics/ParticleEmitter.cpp +++ b/source/graphics/ParticleEmitter.cpp @@ -381,12 +381,6 @@ void CParticleEmitter::RenderArray( g_Renderer.GetStats().m_Particles += m_NumberOfVisibleParticles; } -void CParticleEmitter::Unattach(const CParticleEmitterPtr& self) -{ - m_Active = false; - m_Type->m_Manager.AddUnattachedEmitter(self); -} - void CParticleEmitter::AddParticle(const SParticle& particle) { if (m_NextParticleIdx >= m_Particles.size()) @@ -410,7 +404,7 @@ CModelParticleEmitter::CModelParticleEmitter(const CParticleEmitterTypePtr& type CModelParticleEmitter::~CModelParticleEmitter() { - m_Emitter->Unattach(m_Emitter); + m_Type->m_Manager.AddUnattachedEmitter(std::move(m_Emitter)); } void CModelParticleEmitter::SetEntityVariable(const std::string& name, float value) diff --git a/source/graphics/ParticleEmitter.h b/source/graphics/ParticleEmitter.h index ec07e1dd8f..0704087ebb 100644 --- a/source/graphics/ParticleEmitter.h +++ b/source/graphics/ParticleEmitter.h @@ -150,15 +150,6 @@ public: void RenderArray( Renderer::Backend::IDeviceCommandContext* deviceCommandContext); - /** - * Stop this emitter emitting new particles, and pass responsibility for rendering - * to the CParticleManager. This should be called before dropping the last std::shared_ptr - * to this object so that it will carry on rendering (until all particles have dissipated) - * even when it's no longer attached to a model. - * @param self the std::shared_ptr you're about to drop - */ - void Unattach(const CParticleEmitterPtr& self); - void SetEntityVariable(const std::string& name, float value); CParticleEmitterTypePtr m_Type; diff --git a/source/graphics/ParticleManager.cpp b/source/graphics/ParticleManager.cpp index 8c9ae13789..57e8e00125 100644 --- a/source/graphics/ParticleManager.cpp +++ b/source/graphics/ParticleManager.cpp @@ -61,6 +61,7 @@ CParticleEmitterTypePtr CParticleManager::LoadEmitterType(const VfsPath& path) void CParticleManager::AddUnattachedEmitter(const CParticleEmitterPtr& emitter) { + emitter->m_Active = false; m_UnattachedEmitters.push_back(emitter); } diff --git a/source/graphics/ParticleManager.h b/source/graphics/ParticleManager.h index dd8a8f5c19..5f1cc7d7f9 100644 --- a/source/graphics/ParticleManager.h +++ b/source/graphics/ParticleManager.h @@ -43,7 +43,11 @@ public: /** * Tell the manager to handle rendering of an emitter that is no longer - * attached to a unit. + * attached to a unit. After the call the emitter becomes inactive. + * + * This should be called before dropping the emitter so that the manager + * will carry on rendering (until all particles have dissipated) + * even when it's no longer attached to a model. */ void AddUnattachedEmitter(const CParticleEmitterPtr& emitter);