-
Notifications
You must be signed in to change notification settings - Fork 1
3. Foveated Animation Target script
In order to be able to interface with our agent's animation frequencies, as well as mange them while outside our Limit Threshold, we define the foveated_animation_target.cs
script to act as an interface for us to use.
It should be noted that, currently, this script has dependencies on the Animator component (to change animation update frequencies or stop them outright). If this component is missing, the script will fail and cause undefined behaviour.
When the script starts, it starts a LowFramerate()
co-routine which runs indefinitely. After it does, it checks if Focus Sphere script is set to use Halt Stop or Minimum Stop:
- If Halt Stop is used, start animations with an update frequency of 10 Hz (our default Minimum Stop update frequency) on a timer of 2 seconds. This will cause the agents to get out of their default position, then halt their animations.
- If Minimum Stop is used, start animations with an update frequency of 10 Hz (our default Minimum Stop update frequency).
The LowFramerate
co-routine checks at set intervals whether it's set to run at a fixed update frequency (that is, the agent is foveated). If it is, then we evaluate the agent's animations based on the time since the last time they were evaluated.
After that, we make note of the current time, then wait for a pre-determined amount of time plus/minus a small random amount of time to avoid performance spikes by spreading out the workload over time.
This script also defines a number of functions specifically meant for changing the agent's update animations.
The TimedStop
function is used by the other functions when we want our update frequency change to be temporary. It calculates a point in time in the future when the animation should be stopped, then calls the AnimationStopTimer
co-routine.
The AnimationStopTimer
co-routine regularly checks if the animation time limit has passed, and if it has it sets the agent's animation based on the scene's Stop Behaviour.
The StopAnimation
Function fully disables the Animator object, causing the agent to no longer have any animations.
This function takes an optional timer parameter to pass on to TimedStop
The function re-enables the animator component.
This function takes two optional parameters:
- A FPS/Hz parameter to determine the update frequency of the agent
- A timer parameter to pass on to
TimedStop
SetFixedFPS
takes the FPS/Hz parameter and sets the agent's animation update frequency to it.
It does so through the following:
- Set the Animator Playable Graph's Update Mode to Manual. This causes the Animator to stop updating the agent's animations, unless we explicitly call the Playable Graph's
Evaluate
function. - Set the
_lowFps
flag toTrue
, causing ourLowFramerate
co-routine to go into effect and periodically callEvaluate
to achieve our fixed update frequency rate.
If an FPS/Hz of 0 is passed to the function, it will instead use the agent's pre-determined foveated update frequency rate (defined in the lowFpsFrames
variable. However, while this behaviour has been used for testing purposes in the past, it is not currently used in any of the testing scenes.
This function takes an optional timer parameter to pass on to TimedStop
.
SetForegroundFPS
aims to undo the effects of SetFixedFPS
or StopAnimation
functions. It does so by.
- Setting the Playable Graph's update mode back to GameTime (that is, it goes back to evaluating the animations of the agent every frame).
- Restarting the Playable Graph by stopping it then immediately playing it again.