Modding, Mission Design, and Coding > FS2 Open Coding - The Source Code Project (SCP)

Request for Comments: Programmable action system

(1/3) > >>

m!m:
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:

--- Code: ---$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

--- End code ---

When used it looks something like this: https://gfycat.com/VastAcrobaticDinosaur

At 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/actionSystem

Thank 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.

Spoon:
Neat.

I love all the work you're doing on expanding the particle system. Could you also extend this to work on primary and secondary weapon fire? Missile turrets having smoke backlash and primary turrets belching smoke would look so much better when done through the much more flexible particle system that you made. The muzzleflash system is rigid and limiting.

Goober5000:
Seconded, this does look pretty neat.

@m!m, thinking out loud here, could this action framework be ported to the model animation system?  That part of the code has been sorely in need of improvement for ages -- in fact, it really needs to simply be ripped out and replaced, and this would be the ideal thing to replace it with.  Think of all the ways you could use this for animations -- can anyone say in-game cutscenes with character models?

m!m:

--- Quote from: Spoon on July 26, 2018, 06:26:47 pm ---I love all the work you're doing on expanding the particle system. Could you also extend this to work on primary and secondary weapon fire? Missile turrets having smoke backlash and primary turrets belching smoke would look so much better when done through the much more flexible particle system that you made. The muzzleflash system is rigid and limiting.

--- End quote ---
If the basic idea and implementation appears to be working then adding support for other triggers is very easy. I only added the beam warmdown hook so I had something to test the system with but in general it can be extended to a lot of different things.


--- Quote from: Goober5000 on July 26, 2018, 07:33:07 pm ---@m!m, thinking out loud here, could this action framework be ported to the model animation system?  That part of the code has been sorely in need of improvement for ages -- in fact, it really needs to simply be ripped out and replaced, and this would be the ideal thing to replace it with.  Think of all the ways you could use this for animations -- can anyone say in-game cutscenes with character models?

--- End quote ---
I'm not sure what exactly you are suggesting here. It would certainly be possible to add an action for triggering an animation but this system is not suited for specifying model animations. That should be done using dedicated modeling software where FSO only reads and displays the final animations.

Goober5000:

--- Quote from: m!m on July 26, 2018, 09:03:25 pm ---
--- Quote from: Goober5000 on July 26, 2018, 07:33:07 pm ---@m!m, thinking out loud here, could this action framework be ported to the model animation system?  That part of the code has been sorely in need of improvement for ages -- in fact, it really needs to simply be ripped out and replaced, and this would be the ideal thing to replace it with.  Think of all the ways you could use this for animations -- can anyone say in-game cutscenes with character models?
--- End quote ---
I'm not sure what exactly you are suggesting here. It would certainly be possible to add an action for triggering an animation but this system is not suited for specifying model animations. That should be done using dedicated modeling software where FSO only reads and displays the final animations.
--- End quote ---

A full-fledged animation system such as used in modeling software is beyond the scope of this request.  No, what I meant was that this could be used to sequence rotations and thereby create animations.  Let's take docking clamps as an example.  The current animation system runs a particular hardcoded rotation at each point on the docking path.  Using your system as an alternative, you could add a configurable hook so that when the path point is reached, it would initiate a custom rotation, with a custom duration, to/from a custom angle, possibly with a custom delay.  And maybe even more than one rotation.  Your system would be much more flexible.

The existing animation system should be ripped out completely, and reimplemented.  Old animations should be implemented as special use cases of the new animations.

Navigation

[0] Message Index

[#] Next page

Go to full version