I am writing a particle system. (for the game and particle editor) There are modifiers from 0 to n in this system. They modify the particles in the particle system in each frame.
For example, you might have a predefined modifier called "GravityModifier" that only makes each next particle in each frame: "particle.Velocity.Y + = 9.81" or something like that.
Now I want the user to be able to write additional modifiers at run time (in the editor). I would like to be able to use C # for this. And since particle systems are written to JSON files, custom modifier scripts must be written as source code (possibly base64 encoded) to the file.
-
My question is: Suppose a game wants to load such a particle system file. How to compile custom modifiers into executable code?
Another important thing to consider when answering this question: Please note that this will be a particle system for the game. Compiled code will be called more than 3,000 times for each frame. (mainly at 60 frames per second) Therefore, it is very important that the compiled code takes much longer than other game functions. It would be nice if the modifier scripts were compiled into form delegates: delegate void ModifyParticle (ref Particle p);
Is it possible? If so, how?
source share