Action is a time-based, self-contained interpolation framework. It has the capability of interpolating values over a duration with delays, ease types, and completion callbacks. Because it uses templates and pointers to the values it is interpolating, Action is flexible in what it can do: lower the volume of a sound clip, scale a transform, change the color of a particle, etc.
Because Action interpolates values within the codebase of the project, it needs to store references to these values as well as the interpolation values. Commonly referred to as To, From, and FromTo tweens, Action uses a simple templated struct to keep track of each value:
At its root, Action’s interpolator runs off of the concept of a Single – a single interpolation. This is split into two layers: a base layer that handles the majority of the logic and a top layer that contains a Value and handles the templated nature of the system:
And here’s an overview of the top level:
If you’re eagle-eyed, you’ll notice that SingleBase inherits from ActionBase – this is a class that holds basic info shared across all types of actions, like Groups and Sequences (more on those in a bit).
Singles are stored in a vector, and are updated individually:
Thus, the only setup needed from an external party is to #include 'Action.h' and to call Action::update() in its main update loop.
In addition to interpolating single values, Action supports interpolating groups of values in unison and in sequence. For Groups, if specified by the user, a group-wide delay is added to each of the Singles within a group, and then the group handles updating each single in unison. For Sequences, determining the delay for each of the Singles is a little more involved:
Depending on the looptype of the Sequence, the delay for the Singles has to be recalculated:
heads is a boolean that keeps track if the Sequence is in the ‘downwards’ or ‘upwards’ motion of the yo-yo. To get the correct delay, we take twice the length of the entire sequence, and add the current delay of the opposite Single: so if the entire sequence is 10 seconds long, and the current Single is second from the end, the delay is 20 seconds plus the delay of the second from the start.
Callbacks in Action are std::function<void()>, which means that they can be used with std::bind and lambda function notation:
This allows the callbacks to be extremely flexible for the user.