Jump to content
  • Advertisement
Sign in to follow this  
MajinMusashi

Particle system design

This topic is 4677 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! I've researched a lot about particle systems, and I made a little demo using what I've learned. However, none of those resources covered in details how to integrate a particle system into a real game. Here is the simplified class hierarchy of my particle system: Manager -> Emitters -> Particles - Manager is a singleton (so there is only one instance at a time in a game) that has a vector of emitter vectors (std::vector<std::vector<Emitter>>) and allow access (creation, destruction etc.) to these emitters by the game programmer; - Emitter represents each special effect like smoke, fire etc. (each one with its own behavior) and has a vector of particles; - Particles are the "atomic structures" of my system (simple textured quads); The questions, taking by example game a crazy Tetris close, where there are special effects like sparks, smoke and explosions: 1) Is it reasonable to maintain something like a vector of emitter vectors inside Manager, so I could have multiple instances of the same special effect (emitter)? 2) Dynamic creation of emitters seems a very CPU intensive task, but on the other hand static creation would limit the number of emitter instances and could spend much memory. What is the best strategy to achive a decent performance and memory consumption? Thanks again!

Share this post


Link to post
Share on other sites
Advertisement
This looks like a programming question. Try that board. I sure can't help you.

Good luck with it, though. With the pervasiveness of particle systems in simple games, I'm sure there's a simple and elegant solution to your problem.

Share this post


Link to post
Share on other sites
There are several approaches to the question you ask.

In regards to a vector of emitter vectors, you can avoid this by defining a vector of some base emitter class from which all emitters inherit. Then in the manager you can maintain a vector of pointers to this base class. When a new emittor is needed, you can dynamically allocate an instance of that type of emittor and store it in your vector. Always store pointers in your STL containers, they follow value semantics and can do copying behind the scenes.

Dynamic creation is a good approach, since it enables you to consume resources as they are needed.

Good luck and good question.....

Share this post


Link to post
Share on other sites
Quote:
Original post by Iron Chef Carnage
This looks like a programming question. Try that board. I sure can't help you.

Yes, I agree. I was fooled by the word "design" (as in "design patterns"). Thanks, but I don't know how to move my post, and duplicate it isn't a good thing.

Share this post


Link to post
Share on other sites
Quote:
Original post by ChickenMcOwnage
Dynamic memory allocation is very slow, so for something like a particle engine you'll almost always want to use vectors/arrays.

Chicken, arrays and vectors could be used independent of dynamic or static allocation. I'm not sure I understood what you meant to say.

Share this post


Link to post
Share on other sites
Quote:
Original post by AzCoder
In regards to a vector of emitter vectors, you can avoid this by defining a vector of some base emitter class from which all emitters inherit. Then in the manager you can maintain a vector of pointers to this base class.

When a new emittor is needed, you can dynamically allocate an instance of that type of emittor and store it in your vector. Always store pointers in your STL containers, they follow value semantics and can do copying behind the scenes.
Dynamic creation is a good approach, since it enables you to consume resources as they are needed.[/quote]
Agreed. Thanks, AzCoder!

Share this post


Link to post
Share on other sites
Quote:
Original post by MajinMusashi
1) Is it reasonable to maintain something like a vector of emitter vectors inside Manager, so I could have multiple instances of the same special effect (emitter)?

I don't see a need for a vector of emitter vectors. A simple vector of emitters (actually a vector of pointers to emitters, so you can have different kinds) should be fine.

Quote:
Original post by MajinMusashi
2) Dynamic creation of emitters seems a very CPU intensive task, but on the other hand static creation would limit the number of emitter instances and could spend much memory. What is the best strategy to achive a decent performance and memory consumption?
Unless you are creating and destroying many emitters every frame, I doubt it would it be a "CPU intensive task". If it does turn out to be slow, then possible solutions are to preallocate a pool of emitters or use the Flyweight pattern.


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!