***Making a Particle System Loader

Im making a particle system engine where it loads and reads files like "smoke_effect.ps" and then makes a 'ParticleSystem' class that is stored in an array called templates.

In the .ps text file, there are properties that the user can put in like gravity:0.2 and then the ParticleSystem class would have the gravity function added to its array of function pointers so when the system updates, it can loop through its array of function pointers and call them to take effect.

However, the function needs some way of knowing how much gravity for that class so the class should have the variable int gravity; in its header. The thing is that if the .ps file didn't have "gravity:0.2" (That is if I wanted non-moving particles), the variable "gravity" would still be taking up memory in the class with no use! So my question is this: How can I store variables in a class depending on what it has to use?

I thought of having an array of integers in the class and then that array would fill up as it adds function variables from the .ps file, but I don't know if that would work.
Last edited on
enum Variables{gravity, lifetime...};
std::map<Variables, int> values;

Note that this is much much slower than just reading a variable. And they're all ints. Considering the amount of RAM most systems have these days I'd consider storing unused data.
I dont think reading would be a performance hit right? I mean, the bottleneck is probably going to be the GPU.
Last edited on
int valueInt;
map<Variables, int> valuesMap;
valueInt = 10;                  //This is much faster
valuesMap[gravity] = 10; //Than this 

That's what I mean. It is a relatively small hit, unless you access the map many times a second. It just comes from the fact that the map has to do a number of comparisons (log n), dereference pointers, and then return a reference to the value at gravity. Accessing a value stored in a map is very different from changing a normal variable.
And you're right, I know nothing about your program, and if you are GPU bottlenecked, then this won't really matter.
Topic archived. No new replies allowed.