-1

I had a question regarding the way I am designing my particle system.

Right now I have a class P, which stores all the information about a particle such as speed, position, direction, type, etc. I also have a main file I will be drawing these particles, updating and instantiating them in. I want to create a list of these particles using the c++ std list library, so initially I did

std::list<P> listOfParticles; 

in the main file. Here is the problem. By doing this I will essentially be forced to make my update and draw functions in the main file. I feel like this is bad practice, and that everything to do with the particle should be kept in one class, but I am unsure where to go from here in terms of best practice. Would it be a good idea to just create a list of particles in the class P where I am defining what a particle is? I feel like this isn't a smart idea though.. If anyone could guide me in the right direction I would really appreciate it.

user145570
  • 201
  • 1
  • 2
  • 7

2 Answers2

1

"By doing this I will essentially be forced to make my update and draw functions in the main file"

No one is stopping you from putting declarations/definitions of class members in same/different .h/.cpp files.

EDIT:-

That's what I said, better it would be if you make this List a member of some other class where you would put all functions to manipulate this list.

ravi
  • 10,994
  • 1
  • 18
  • 36
  • so like, maybe have another class which holds a set number of particles, and in there have the update, draw functions? – user145570 Dec 12 '14 at 05:05
0

Your list of particles most probably deserves its own class, let C, that will handle storage, initial spatial distribution, temporal updates... i.e. all global operations on the particle cloud. If you are sure that you will ever handle a single list, you can make it a static member.

The class that represents the individual particles (P) can be nested into (C) if there is no need to see it from outside. It will encapsulate particle data and possibly also model pairwise interaction with another particle and other single-particle operations.