Author Topic: Request for Comments: Programmable action system  (Read 903 times)

0 Members and 1 Guest are viewing this topic.

Offline m!m

  • 211
Request for Comments: Programmable action system
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: [Select]
$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/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.


 

Offline Spoon

  • 212
  • troll missions builder ヾ(´︶`♡)ノ
Re: Request for Comments: Programmable action system
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.
Urutorahappī!!

[02:42] <@Axem> spoon somethings wrong
[02:42] <@Axem> critically wrong
[02:42] <@Axem> im happy with these missions now
[02:44] <@Axem> well
[02:44] <@Axem> with 2 of them

 

Offline Goober5000

  • HLP Loremaster
  • Administrator
  • 214
    • Goober5000 Productions
Re: Request for Comments: Programmable action system
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?

 

Offline m!m

  • 211
Re: Request for Comments: Programmable action system
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.
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.

@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?
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.

 

Offline Goober5000

  • HLP Loremaster
  • Administrator
  • 214
    • Goober5000 Productions
Re: Request for Comments: Programmable action system
@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?
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.

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.

 

Offline m!m

  • 211
Re: Request for Comments: Programmable action system
Ok, that's pretty much what I already thought. Adding hooks for specific animation triggers is certainly possible and I'll take a look at this once the initial version is finished. However, the system you are describing would not be an improvement over the previous system since it would also only support rotation animations instead of also allowing translations. I have been thinking about replacing the animation system for some time now but I'll need to take a closer look at the existing code to understand what features the new system must support so that we don't break existing models.

 

Offline Goober5000

  • HLP Loremaster
  • Administrator
  • 214
    • Goober5000 Productions
Re: Request for Comments: Programmable action system
It would be an improvement because even the existing animation system is inconsistently specified.  Twisted Infinities has a model that uses docking clamps, and a couple of years ago Vasudan Admiral and I were banging our heads against the wall trying to get it to work in all situations.

And yes, support for translations (linear movement) would be very nice to have.  But I consider that a separate - and mostly independent - problem.

 

Offline m!m

  • 211
Re: Request for Comments: Programmable action system
Does the existing animation system support naming specific animations and then triggering them by specifying that name? Something like that would be within the scope of the action system (once the initial version is finished).

I don't want to add a system where the modder has to specify the actual animation in the table since those values are something that need to be generated by the modeling program.

Anyway, I'm currently working on adding support for local rotations and offsets to this system. I want to do this to support specifying complex actions on weapon impacts which requires a position relative to the impacted object and also a special orientation to make the effect relative to the hull of the object at the impact location.

  

Offline Goober5000

  • HLP Loremaster
  • Administrator
  • 214
    • Goober5000 Productions
Re: Request for Comments: Programmable action system
I think the existing animation system was just a first-draft framework hacked around model rotations.  It's kind of backwards to what you are asking: at each stage of the docking path, the code looks for "docking animation 1" and runs it if it exists, then "docking animation 2" and so forth.  In the model file, you give your subobject joint the "docking animation 1" property if you want it to run at that point.

Defining specific animations and then triggering them by name is a better way to do it.  I disagree with you though: I think allowing the modder to specify them in the table file would be the best way to do it.  This is for two reasons: 1) editing a table file is much easier than editing a POF file, and 2) the POF format doesn't really have support for full-fledged animations.

I would really like something like this:
Code: [Select]
$Name: Retract docking clamps
$Movement 1
+Subobject: clamp01
+Start angle: 0
+Stop angle: 45
+Duration: 2000
+Subobject: clamp02
+Start angle: 0
+Stop angle: -45
+Duration: 2000

Then:
Code: [Select]
$On Dock Path Point 4
+Retract docking clamps
+Delay: 4000