Author Topic: Request for Comments: Programmable action system  (Read 5285 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
  • ヾ(´︶`♡)ノ
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
  • Moderator
  • 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
  • Moderator
  • 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
  • Moderator
  • 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
  • Moderator
  • 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

 

Offline Darius

  • 211
Re: Request for Comments: Programmable action system


Bumping this topic because this is 100% right up my street.

Has this had any additional options since release? I don't use beams in my current mod but I'd love to tie this to laser or missile turret fire, or stuff like warping in/out, damage, etc.

 
Re: Request for Comments: Programmable action system
It was never implented (well, afaik). The code linked in the first post hasnt been merged and there's no mention in the "Subsystem" entry on the wiki so I guess it remained unfinished.

Ironically I had a similar idea around the time this was posted although I missed this thread: each subsystem would create a particle effect upon destruction instead of the normal fireball.tbl-based one, also each turret would explode differently. Lasers would create a brief flash, Beams have a big flash followed by leaking plasma, flak and missile turrets would spill shrapnels and so forth. On top of that effect I *think* it'd be possible to specify further effects on delay so after the initial explosion/flash happend you'd have plumes of smoke come out of the destroyed subsystem/turret with the size decreasing over time.
« Last Edit: February 25, 2023, 11:25:10 am by Nightmare »

 

Offline m!m

  • 211
Re: Request for Comments: Programmable action system
The relevant code was merged and is in the actions folder: https://github.com/scp-fs2open/fs2open.github.com/tree/master/code/actions
I guess I never got around to updating the wiki though...