Gorgon Game Engine
Controller Class Reference

This class allows finer control for the animations, allowing loop, stopping at the end, events, speed and direction control. More...

Inheritance diagram for Controller:
[legend]

Public Member Functions

 Controller (double progress=0.0)
 Default constructor. More...
 
virtual ~Controller ()
 
- Public Member Functions inherited from ControllerBase
 ControllerBase ()
 Default constructor. More...
 
 ControllerBase (Governor &governor)
 
virtual ~ControllerBase ()
 Destructor. More...
 
virtual void Add (Base &animation)
 This function attaches the given animation to this controller. More...
 
void AutoDestruct ()
 Set a flag that will automatically destroy this controller whenever it has no animations left to control. More...
 
virtual void Delete (Base &animation)
 Deletes the given animation. More...
 
virtual unsigned GetProgress () const =0
 Returns the current progress of the timer. More...
 
void Keep ()
 Resets the flag that will automatically destroy this controller whenever it has no animations left to control. More...
 
virtual void Remove (Base &animation)
 Removes the given animation. More...
 
virtual void SetGovernor (Governor &governor)
 Changes the governor of this controller. More...
 

Protected Attributes

bool isfinished
 Whether the controller is finished. More...
 
bool islooping
 Looping state. More...
 
bool ispaused
 Paused state. More...
 
unsigned length
 Length of the animations controlled by this controller. More...
 
double progress
 Floating point progress to avoid precision loss due to speed. More...
 
float speed
 Current speed. More...
 
- Protected Attributes inherited from ControllerBase
Containers::Collection< Baseanimations
 List of animations this controller holds. More...
 
bool collectable
 Whether this controller should be collected by the garbage collector when its task is finished. More...
 
Governorgovernor
 

Progress modification functions

virtual void Progress (unsigned timepassed) override final
 Progresses this controller by the given time. More...
 
virtual void SetProgress (unsigned progress)
 Sets the current progress of the controller. More...
 
void SetProgress (double progress)
 Sets the current progress of the controller. More...
 
virtual void Reset () override
 Resets the controller to start from the beginning. More...
 

Progress control functions

virtual void Play ()
 Starts this controller to run once. More...
 
virtual void Loop ()
 Starts this controller in looping mode. More...
 
virtual void Pause ()
 Pauses the controller, until a Resume or Reset is issued. More...
 
virtual void Resume ()
 Resumes the controller. This method will not have any effect if the animation is finished. More...
 
virtual void SetSpeed (float speed)
 Changes the speed of the controller. More...
 
virtual void Reverse ()
 Reverses the animation direction by negating the speed. More...
 
virtual void SetLength (unsigned length)
 Informs controller about the length of the animations its controlling. More...
 

Information functions

virtual float GetSpeed ()
 Returns the current speed of the controller. More...
 
bool IsPaused () const
 Returns whether the controller is paused. More...
 
bool IsFinished () const
 Whether the controller is finished either by reaching to the end while the speed is positive or reaching to 0 while the speed is negative. More...
 
bool IsPlaying () const
 Returns whether the controller is playing its animations right now. More...
 
bool IsLooping () const
 Checks whether the controller is in loop mode. More...
 
virtual bool IsControlled () const override final
 This method allows clients to determine if the progress is controlled. More...
 

Events

Event< ControllerFinishedEvent
 Will be fired when the controller reaches the finished state. More...
 

Detailed Description

This class allows finer control for the animations, allowing loop, stopping at the end, events, speed and direction control.

Use SetLength to control the length of the animation. Otherwise, if the first controlled animation exists, its length is used. Best used with a single animation or animations that have the same duration.

Constructor & Destructor Documentation

◆ Controller()

Controller ( double  progress = 0.0)

Default constructor.

References Controller::progress, and Controller::SetProgress().

◆ ~Controller()

virtual ~Controller ( )
virtual

Member Function Documentation

◆ GetSpeed()

virtual float GetSpeed ( )
virtual

Returns the current speed of the controller.

References Controller::speed.

◆ IsControlled()

virtual bool IsControlled ( ) const
finaloverridevirtual

This method allows clients to determine if the progress is controlled.

If the progress is not controlled, there is no way to force the animation to stop. Therefore, animations with looping capabilities should wrap around to start over. However, if the timer is a controller then the best strategy will be to stop at the end, and return the leftover time. This way, controller can decide what to do next.

Implements ControllerBase.

◆ IsFinished()

bool IsFinished ( ) const

Whether the controller is finished either by reaching to the end while the speed is positive or reaching to 0 while the speed is negative.

References Controller::isfinished.

◆ IsLooping()

bool IsLooping ( ) const

Checks whether the controller is in loop mode.

It also checks the length if the speed is negative and makes sure that the controller can actually loop

References Controller::islooping, Controller::length, and Controller::speed.

◆ IsPaused()

bool IsPaused ( ) const

Returns whether the controller is paused.

Does not check if the speed is 0 or not, setting speed to 0 will effectively pause the animation without changing paused status.

References Controller::ispaused.

◆ IsPlaying()

bool IsPlaying ( ) const

Returns whether the controller is playing its animations right now.

This method does not take speed being 0 into account.

References Controller::isfinished, and Controller::ispaused.

◆ Loop()

virtual void Loop ( )
virtual

Starts this controller in looping mode.

Looping will not work when the length is 0 and the speed is set to a negative value (animation is running in reverse). If the animation is paused, this function works like Resume except that this function sets controller to looping mode

References Controller::islooping, and Controller::Play().

◆ Pause()

void Pause ( )
virtual

Pauses the controller, until a Resume or Reset is issued.

References Controller::ispaused.

◆ Play()

void Play ( )
virtual

Starts this controller to run once.

If the controller is marked as finished, this method will set the progress to 0 or length depending on the direction of the controller. If length is 0 and the speed is negative this method will not start playing finished controller. If the animation is paused, this function works like Resume except that this function sets controller to run once mode.

References ControllerBase::animations, Controller::isfinished, Controller::islooping, Controller::ispaused, Controller::length, Controller::progress, and Controller::speed.

◆ Progress()

void Progress ( unsigned  timepassed)
finaloverridevirtual

◆ Reset()

void Reset ( )
overridevirtual

Resets the controller to start from the beginning.

Also resets finished and paused status and modifies the speed to be 1.

Implements ControllerBase.

References Controller::isfinished, Controller::ispaused, Controller::progress, and Controller::speed.

◆ Resume()

virtual void Resume ( )
virtual

Resumes the controller. This method will not have any effect if the animation is finished.

References Controller::ispaused.

◆ Reverse()

virtual void Reverse ( )
virtual

Reverses the animation direction by negating the speed.

References Controller::speed.

◆ SetLength()

virtual void SetLength ( unsigned  length)
virtual

Informs controller about the length of the animations its controlling.

This allows Controller to seek to the end of the animation

References Controller::length.

◆ SetProgress() [1/2]

void SetProgress ( double  progress)

Sets the current progress of the controller.

If the progress is a negative value, it will be subtracted from the animation length. If the animation length is 0, then the controller will immediately stop and sets the progress to 0.

References Controller::progress.

◆ SetProgress() [2/2]

virtual void SetProgress ( unsigned  progress)
virtual

Sets the current progress of the controller.

References Controller::progress.

◆ SetSpeed()

virtual void SetSpeed ( float  speed)
virtual

Changes the speed of the controller.

Speed can be negative to run animations backwards. Setting speed 0 effectively pauses the controller, however, when the speed is 0 controller will not report that its paused.

References Controller::speed.

Member Data Documentation

◆ FinishedEvent

Event<Controller> FinishedEvent

Will be fired when the controller reaches the finished state.

controller is finished either by reaching to the end while the speed is positive or reaching to 0 while the speed is negative

◆ isfinished

bool isfinished
protected

Whether the controller is finished.

◆ islooping

bool islooping
protected

Looping state.

◆ ispaused

bool ispaused
protected

Paused state.

◆ length

unsigned length
protected

Length of the animations controlled by this controller.

◆ progress

double progress
protected

Floating point progress to avoid precision loss due to speed.

◆ speed

float speed
protected

Current speed.


The documentation for this class was generated from the following files: