Skip to content

Commit

Permalink
Main: ParticleSystem - do not track Affectors and Emitters in Factories
Browse files Browse the repository at this point in the history
this is redundant with ParticleSystem and slows down clearing
due to O(N) lookup and erase
  • Loading branch information
paroj committed Sep 1, 2023
1 parent 35e1193 commit ad0a11d
Show file tree
Hide file tree
Showing 20 changed files with 28 additions and 99 deletions.
2 changes: 1 addition & 1 deletion OgreMain/include/OgreParticleAffectorFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace Ogre {
class _OgreExport ParticleAffectorFactory : public FXAlloc
{
protected:
std::vector<ParticleAffector*> mAffectors;
OGRE_DEPRECATED std::vector<ParticleAffector*> mAffectors;
public:
ParticleAffectorFactory() {}
virtual ~ParticleAffectorFactory();
Expand Down
2 changes: 1 addition & 1 deletion OgreMain/include/OgreParticleEmitterFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace Ogre {
class _OgreExport ParticleEmitterFactory : public FXAlloc
{
protected:
std::vector<ParticleEmitter*> mEmitters;
OGRE_DEPRECATED std::vector<ParticleEmitter*> mEmitters;
public:
ParticleEmitterFactory() {}
virtual ~ParticleEmitterFactory();
Expand Down
6 changes: 5 additions & 1 deletion OgreMain/src/OgreParticleEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,22 +686,26 @@ namespace Ogre
//-----------------------------------------------------------------------
ParticleEmitterFactory::~ParticleEmitterFactory()
{
OGRE_IGNORE_DEPRECATED_BEGIN
// Destroy all emitters
for (auto& e : mEmitters)
{
OGRE_DELETE e;
}

mEmitters.clear();
OGRE_IGNORE_DEPRECATED_END
}
//-----------------------------------------------------------------------
void ParticleEmitterFactory::destroyEmitter(ParticleEmitter* e)
{
delete e;
OGRE_IGNORE_DEPRECATED_BEGIN
auto i = std::find(std::begin(mEmitters), std::end(mEmitters), e);
if (i != std::end(mEmitters)) {
mEmitters.erase(i);
OGRE_DELETE e;
}
OGRE_IGNORE_DEPRECATED_END
}

//-----------------------------------------------------------------------
Expand Down
6 changes: 5 additions & 1 deletion OgreMain/src/OgreParticleSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1552,27 +1552,31 @@ namespace Ogre {
//-----------------------------------------------------------------------
ParticleAffectorFactory::~ParticleAffectorFactory()
{
OGRE_IGNORE_DEPRECATED_BEGIN
// Destroy all affectors
for (auto *a : mAffectors)
{
OGRE_DELETE a;
}

mAffectors.clear();
OGRE_IGNORE_DEPRECATED_END
}
//-----------------------------------------------------------------------
void ParticleAffectorFactory::destroyAffector(ParticleAffector* e)
{
delete e;
OGRE_IGNORE_DEPRECATED_BEGIN
std::vector<ParticleAffector*>::iterator i;
for (i = mAffectors.begin(); i != mAffectors.end(); ++i)
{
if ((*i) == e)
{
mAffectors.erase(i);
OGRE_DELETE e;
break;
}
}
OGRE_IGNORE_DEPRECATED_END
}

}
7 changes: 1 addition & 6 deletions PlugIns/ParticleFX/include/OgreTextureAnimatorAffector.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,7 @@ namespace Ogre {
{
String getName() const override { return "TextureAnimator"; }

ParticleAffector* createAffector(ParticleSystem* psys) override
{
ParticleAffector* p = OGRE_NEW TextureAnimatorAffector(psys);
mAffectors.push_back(p);
return p;
}
ParticleAffector* createAffector(ParticleSystem* psys) override { return new TextureAnimatorAffector(psys); }
};

/** @} */
Expand Down
8 changes: 1 addition & 7 deletions PlugIns/ParticleFX/src/OgreBoxEmitterFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,7 @@ namespace Ogre {
public:
String getName() const override { return "Box"; }

ParticleEmitter* createEmitter(ParticleSystem* psys) override
{
ParticleEmitter* emit = OGRE_NEW BoxEmitter(psys);
mEmitters.push_back(emit);
return emit;
}

ParticleEmitter* createEmitter(ParticleSystem* psys) override { return new BoxEmitter(psys); }
};

}
Expand Down
7 changes: 1 addition & 6 deletions PlugIns/ParticleFX/src/OgreColourFaderAffectorFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ namespace Ogre {
{
String getName() const override { return "ColourFader"; }

ParticleAffector* createAffector(ParticleSystem* psys) override
{
ParticleAffector* p = OGRE_NEW ColourFaderAffector(psys);
mAffectors.push_back(p);
return p;
}
ParticleAffector* createAffector(ParticleSystem* psys) override { return new ColourFaderAffector(psys); }
};


Expand Down
7 changes: 1 addition & 6 deletions PlugIns/ParticleFX/src/OgreColourFaderAffectorFactory2.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ namespace Ogre {
{
String getName() const override { return "ColourFader2"; }

ParticleAffector* createAffector(ParticleSystem* psys) override
{
ParticleAffector* p = OGRE_NEW ColourFaderAffector2(psys);
mAffectors.push_back(p);
return p;
}
ParticleAffector* createAffector(ParticleSystem* psys) override { return new ColourFaderAffector2(psys); }
};


Expand Down
7 changes: 1 addition & 6 deletions PlugIns/ParticleFX/src/OgreColourImageAffectorFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ namespace Ogre {
{
String getName() const override { return "ColourImage"; }

ParticleAffector* createAffector(ParticleSystem* psys) override
{
ParticleAffector* p = OGRE_NEW ColourImageAffector(psys);
mAffectors.push_back(p);
return p;
}
ParticleAffector* createAffector(ParticleSystem* psys) override { return new ColourImageAffector(psys); }
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ namespace Ogre {
{
String getName() const override { return "ColourInterpolator"; }

ParticleAffector* createAffector(ParticleSystem* psys) override
{
ParticleAffector* p = new ColourInterpolatorAffector(psys);
mAffectors.push_back(p);
return p;
}
ParticleAffector* createAffector(ParticleSystem* psys) override { return new ColourInterpolatorAffector(psys); }
};


Expand Down
8 changes: 1 addition & 7 deletions PlugIns/ParticleFX/src/OgreCylinderEmitterFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,7 @@ namespace Ogre {
public:
String getName() const override { return "Cylinder"; }

ParticleEmitter* createEmitter(ParticleSystem* psys) override
{
ParticleEmitter* emit = OGRE_NEW CylinderEmitter(psys);
mEmitters.push_back(emit);
return emit;
}

ParticleEmitter* createEmitter(ParticleSystem* psys) override { return new CylinderEmitter(psys); }
};

}
Expand Down
7 changes: 1 addition & 6 deletions PlugIns/ParticleFX/src/OgreDeflectorPlaneAffectorFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ namespace Ogre {
{
String getName() const override { return "DeflectorPlane"; }

ParticleAffector* createAffector(ParticleSystem* psys) override
{
ParticleAffector* p = OGRE_NEW DeflectorPlaneAffector(psys);
mAffectors.push_back(p);
return p;
}
ParticleAffector* createAffector(ParticleSystem* psys) override { return new DeflectorPlaneAffector(psys); }
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ namespace Ogre {

ParticleAffector* createAffector(ParticleSystem* psys) override
{
ParticleAffector* p = OGRE_NEW DirectionRandomiserAffector(psys);
mAffectors.push_back(p);
return p;
return new DirectionRandomiserAffector(psys);
}
};

Expand Down
4 changes: 1 addition & 3 deletions PlugIns/ParticleFX/src/OgreEllipsoidEmitterFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ namespace Ogre {

ParticleEmitter* createEmitter(ParticleSystem* psys) override
{
ParticleEmitter* emit = OGRE_NEW EllipsoidEmitter(psys);
mEmitters.push_back(emit);
return emit;
return new EllipsoidEmitter(psys);
}

};
Expand Down
8 changes: 1 addition & 7 deletions PlugIns/ParticleFX/src/OgreHollowEllipsoidEmitterFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,7 @@ namespace Ogre {
public:
String getName() const override { return "HollowEllipsoid"; }

ParticleEmitter* createEmitter(ParticleSystem* psys) override
{
ParticleEmitter* emit = OGRE_NEW HollowEllipsoidEmitter(psys);
mEmitters.push_back(emit);
return emit;
}

ParticleEmitter* createEmitter(ParticleSystem* psys) override { return new HollowEllipsoidEmitter(psys); }
};

}
Expand Down
7 changes: 1 addition & 6 deletions PlugIns/ParticleFX/src/OgreLinearForceAffectorFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ namespace Ogre {
{
String getName() const override { return "LinearForce"; }

ParticleAffector* createAffector(ParticleSystem* psys) override
{
ParticleAffector* p = OGRE_NEW LinearForceAffector(psys);
mAffectors.push_back(p);
return p;
}
ParticleAffector* createAffector(ParticleSystem* psys) override { return new LinearForceAffector(psys); }
};


Expand Down
8 changes: 1 addition & 7 deletions PlugIns/ParticleFX/src/OgrePointEmitterFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,7 @@ namespace Ogre {
public:
String getName() const override { return "Point"; }

ParticleEmitter* createEmitter(ParticleSystem* psys) override
{
ParticleEmitter* emit = OGRE_NEW PointEmitter(psys);
mEmitters.push_back(emit);
return emit;
}

ParticleEmitter* createEmitter(ParticleSystem* psys) override { return new PointEmitter(psys); }
};

}
Expand Down
8 changes: 1 addition & 7 deletions PlugIns/ParticleFX/src/OgreRingEmitterFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,7 @@ namespace Ogre {
public:
String getName() const override { return "Ring"; }

ParticleEmitter* createEmitter(ParticleSystem* psys) override
{
ParticleEmitter* emit = OGRE_NEW RingEmitter(psys);
mEmitters.push_back(emit);
return emit;
}

ParticleEmitter* createEmitter(ParticleSystem* psys) override { return new RingEmitter(psys); }
};

}
Expand Down
7 changes: 1 addition & 6 deletions PlugIns/ParticleFX/src/OgreRotationAffectorFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ namespace Ogre {
{
String getName() const override { return "Rotator"; }

ParticleAffector* createAffector(ParticleSystem* psys) override
{
ParticleAffector* p = OGRE_NEW RotationAffector(psys);
mAffectors.push_back(p);
return p;
}
ParticleAffector* createAffector(ParticleSystem* psys) override { return new RotationAffector(psys); }
};


Expand Down
7 changes: 1 addition & 6 deletions PlugIns/ParticleFX/src/OgreScaleAffectorFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ namespace Ogre {
{
String getName() const override { return "Scaler"; }

ParticleAffector* createAffector(ParticleSystem* psys) override
{
ParticleAffector* p = OGRE_NEW ScaleAffector(psys);
mAffectors.push_back(p);
return p;
}
ParticleAffector* createAffector(ParticleSystem* psys) override { return new ScaleAffector(psys); }
};


Expand Down

0 comments on commit ad0a11d

Please sign in to comment.