For a long time I wanted to add the ability to dynamically add particle effects on objects when certain things happen (for example when a beam stops firing). This was largely inspired by the
drawing by OneOneThree of the Imperieuse.
Originally I only wanted to add support for particle effects but then I noticed that sound effects would also be necessary. Soon I realized that the system would be a lot more flexible if it allowed freely specifying a sequence of actions that would be executed in sequence. The end result is a system where the following is a valid program:
$Subsystem: turret02, 3, 5.0
$Default PBanks: ( "SGreen" )
$On Beam Warmdown:
+Wait: 5
+Set Position: (-8 0 0) ; Relative position to beam turret subobject
+Set Direction: (-1 -1 1) ; Direction for the particle effect
+Start Particle Effect: Beam Warmdown Effect
+Set Position: (8 0 0) ; Actions can be used multiple times with different parameters
+Set Direction: (1 -1 1)
+Start Particle Effect: Beam Warmdown Effect
When used it looks something like this:
https://gfycat.com/VastAcrobaticDinosaurAt the moment there is only
$On Beam Warmdown: on subsystems which is triggered once a beam of that turret powers down. The way you specify the program is by simply listing what actions should be taken. The same action type can appear multiple times so you can start multiple particle effects in the same program (see above). Here are the available actions:
- +Wait: This instructs the program to delay the remaining actions by the specified amount of (in-game) seconds.
- +Set Position: This sets the "position" value all subsequent actions will use. For example, particle effects will be created at this position, relative to the host object. If the position (or direction) is changed by a later action it will not affect actions that have already been executed.
- +Set Direction: Similar to +Set Position, this sets the direction for the particle effects (or any other effects which use a direction). The specified vector will be normalized so you don't need to do that manually.
- +Start Particle Effect: The reason why this even exists. This starts the specified particle effect at the current position with the current direction.
I would like to gather some feedback on the system before I proceed with adding new features.
Test builds:
http://swc.fs2downloads.com/builds/test/actionSystem/Source code:
https://github.com/scp-fs2open/fs2open.github.com/tree/test/actionSystemThank you for reading this and let me know what you think!
Developer documentation:The basic idea behind the system is pretty simple and very similar to how a normal computer program is run. The actions stored in a program are examined sequentially and executed by calling a virtual function on the action object. Every instance of a program invocation is completely isolated and maintains an internal state of which instruction is currently being executed and what the values of the local variables are. The local variables are stored in a struct which is used by actions for keeping track of what should happen within a single program instance.
New actions can be added pretty easily by adding a new
Action subclass and then adding a parsing handler to
Program.cpp. New actions can also add new local variables to the locals struct. Take a look at the existing actions in case you are curious.