nomlib
Loading...
Searching...
No Matches
nom::IActionObject Class Referenceabstract

Pure virtual base class interface for actions. More...

#include <IActionObject.hpp>

Inheritance diagram for nom::IActionObject:
[legend]

Public Types

enum  FrameState { COMPLETED , PLAYING }
 The update status of the action. More...
typedef IActionObject self_type
typedef std::function< real32(real32, real32, real32, real32)> timing_curve_func
 A function pointer to a timing mode.

Public Member Functions

const std::string & name () const
 Get the unique identifier of the action.
real32 duration () const
 Get the duration of the action.
real32 speed () const
 Get the speed modifier of the action.
const IActionObject::timing_curve_functiming_curve () const
 Get the timing mode function used by the action.
void set_name (const std::string &action_id)
 Set the unique identifier of the action.
virtual void set_speed (real32 speed)
 Set the speed factor of the action.
virtual void set_timing_curve (const IActionObject::timing_curve_func &mode)
 Set the timing mode of the action.
virtual std::unique_ptr< IActionObject > clone () const =0
 Create a deep copy instance of the action.
virtual IActionObject::FrameState next_frame (real32 delta_time)=0
 Play the action forward in time by one time step.
virtual IActionObject::FrameState prev_frame (real32 delta_time)=0
 Play the action backwards in time by one time step.
virtual void pause (real32 delta_time)=0
 Freeze the action's internal state.
virtual void resume (real32 delta_time)=0
 Resume the internal state of the action.
virtual void rewind (real32 delta_time)=0
 Reset the internal state of the action back to its initial starting values.
virtual void release ()=0
 Free externally referenced resources held by the action.

Protected Member Functions

IActionObject::FrameState status () const
 Get the current state of the action.
void set_duration (real32 seconds)
 Set the duration of the action.
void set_status (FrameState state)
 Set the state of the action.

Protected Attributes

real32 elapsed_frames_ = 0.0f
 Internal frames counter.
Timer timer_
 Internal time clock (milliseconds resolution).

Private Attributes

FrameState status_ = FrameState::PLAYING
std::string name_
real32 duration_ = 0.0f
real32 speed_ = 1.0f
timing_curve_func timing_curve_ = nullptr

(Note that these are not member symbols.)

typedef std::vector< std::shared_ptr< IActionObject > > action_list
 A collection of actions.
template<typename ObjectType, typename... ObjectArgs>
std::shared_ptr< ObjectType > create_action (ObjectArgs &&... args)
 Constructor function for creating an action.
template<typename ObjectType>
std::shared_ptr< ObjectType > create_action (const action_list &actions)
 Constructor function for creating an action that uses a collection of actions.

Detailed Description

Pure virtual base class interface for actions.

TODO: This documentation section is a STUB!

Creating Custom Actions

A simple, bare-bones example:

{
NOM_LOG_TRACE_PRIO( NOM_LOG_CATEGORY_TRACE_ACTION,
nom::NOM_LOG_PRIORITY_VERBOSE );
this->set_duration(seconds);
this->elapsed_frames_ = 0.0f;
}
WaitForDurationAction::~WaitForDurationAction()
{
NOM_LOG_TRACE_PRIO( NOM_LOG_CATEGORY_TRACE_ACTION,
nom::NOM_LOG_PRIORITY_VERBOSE );
}
std::unique_ptr<IActionObject> WaitForDurationAction::clone() const
{
return( nom::make_unique<self_type>( self_type(*this) ) );
}
{
delta_time = ( Timer::to_seconds( this->timer_.ticks() ) );
if( this->timer_.started() == false ) {
this->timer_.start();
NOM_LOG_DEBUG( NOM_LOG_CATEGORY_ACTION, DEBUG_CLASS_NAME,
"BEGIN at", delta_time );
}
// Clamp delta values that go beyond maximal duration
if( delta_time > (this->duration() / this->speed() ) ) {
delta_time = this->duration() / this->speed();
}
// Apply speed scalar onto current frame time
real32 frame_time = delta_time * this->speed();
if( delta_time < (this->duration() / this->speed() ) ) {
++this->elapsed_frames_;
NOM_LOG_DEBUG( NOM_LOG_CATEGORY_ACTION, DEBUG_CLASS_NAME,
"delta_time:", delta_time,
"frame_time:", frame_time,
"[elapsed frames]:", this->elapsed_frames_ );
} else {
}
return this->status();
}
{
// NOTE: This action is not reversible
return this->next_frame(delta_time);
}
void WaitForDurationAction::pause(real32 delta_time)
{
this->timer_.pause();
}
void WaitForDurationAction::resume(real32 delta_time)
{
this->timer_.unpause();
}
void WaitForDurationAction::rewind(real32 delta_time)
{
this->elapsed_frames_ = 0.0f;
this->timer_.stop();
}
{
// Nothing to free!
}

References (Conceptual)

See also
SpriteKit: SKAction Class Reference
SpriteKit: Creating Actions That Run Other Actions

Definition at line 41 of file IActionObject.hpp.

Member Typedef Documentation

◆ self_type

typedef IActionObject nom::IActionObject::self_type

Definition at line 44 of file IActionObject.hpp.

◆ timing_curve_func

typedef std::function<real32(real32, real32, real32, real32)> nom::IActionObject::timing_curve_func

A function pointer to a timing mode.

See also
nom::Linear, nom::Quad, nom::Cubic, nom::Quart, nom::Quint, nom::Back, nom::Bounce, nom::Circ, nom::Elastic, nom::Expo, nom::Sine

Definition at line 51 of file IActionObject.hpp.

Member Enumeration Documentation

◆ FrameState

The update status of the action.

Enumerator
COMPLETED 

The action has finished its update loop.

PLAYING 

The action is still updating; duration remains.

Definition at line 54 of file IActionObject.hpp.

Member Function Documentation

◆ clone()

virtual std::unique_ptr< IActionObject > nom::IActionObject::clone ( ) const
pure virtual

Create a deep copy instance of the action.

Remarks
A cloned instance is created using the action's attributes at the time of construction. External resources of the action – i.e.: nom::Sprite – are not modified, and you may need to reset the state appropriately if the action has been ran previously.

Implemented in nom::AnimateTexturesAction, nom::CallbackAction, nom::FadeAlphaByAction, nom::FadeAudioGainBy, nom::FadeInAction, nom::FadeOutAction, nom::GroupAction, nom::MoveByAction, nom::PlayAudioSource, nom::RemoveAction, nom::RepeatForAction, nom::RepeatForeverAction, nom::ReversedAction, nom::ScaleByAction, nom::SequenceAction, nom::SpriteBatchAction, and nom::WaitForDurationAction.

◆ duration()

real32 nom::IActionObject::duration ( ) const

Get the duration of the action.

Returns
The duration in fractional seconds.

◆ next_frame()

virtual IActionObject::FrameState nom::IActionObject::next_frame ( real32 delta_time)
pure virtual

Play the action forward in time by one time step.

Parameters
delta_timeReserved for application-defined implementations.
Note
This method should not normally need to be called externally! Exceptions might include: a) implementing a new action; b) advanced debugging
See also
nom::DispatchQueue

Implemented in nom::AnimateTexturesAction, nom::CallbackAction, nom::FadeAlphaByAction, nom::FadeAudioGainBy, nom::FadeInAction, nom::FadeOutAction, nom::GroupAction, nom::MoveByAction, nom::PlayAudioSource, nom::RemoveAction, nom::RepeatForAction, nom::RepeatForeverAction, nom::ReversedAction, nom::ScaleByAction, nom::SequenceAction, nom::SpriteBatchAction, and nom::WaitForDurationAction.

◆ pause()

virtual void nom::IActionObject::pause ( real32 delta_time)
pure virtual

Freeze the action's internal state.

Parameters
delta_timeReserved for application-defined implementations.
Note
This method should not normally need to be called externally! Exceptions might include: a) implementing a new action; b) advanced debugging
See also
nom::DispatchQueue

Implemented in nom::AnimateTexturesAction, nom::CallbackAction, nom::FadeAlphaByAction, nom::FadeAudioGainBy, nom::FadeInAction, nom::FadeOutAction, nom::GroupAction, nom::MoveByAction, nom::PlayAudioSource, nom::RemoveAction, nom::RepeatForAction, nom::RepeatForeverAction, nom::ReversedAction, nom::ScaleByAction, nom::SequenceAction, nom::SpriteBatchAction, and nom::WaitForDurationAction.

◆ prev_frame()

virtual IActionObject::FrameState nom::IActionObject::prev_frame ( real32 delta_time)
pure virtual

Play the action backwards in time by one time step.

Parameters
delta_timeReserved for application-defined implementations.
Note
This method should not normally need to be called externally! Exceptions might include: a) implementing a new action; b) advanced debugging
Remarks
Not all actions are reversible – see the action's documentation for its implementation details.
See also
nom::ReversedAction

Implemented in nom::AnimateTexturesAction, nom::CallbackAction, nom::FadeAlphaByAction, nom::FadeAudioGainBy, nom::FadeInAction, nom::FadeOutAction, nom::GroupAction, nom::MoveByAction, nom::PlayAudioSource, nom::RemoveAction, nom::RepeatForAction, nom::RepeatForeverAction, nom::ReversedAction, nom::ScaleByAction, nom::SequenceAction, nom::SpriteBatchAction, and nom::WaitForDurationAction.

◆ release()

virtual void nom::IActionObject::release ( )
pure virtual

Free externally referenced resources held by the action.

Note
This method should not normally need to be called externally! Exceptions might include: a) implementing a new action; b) advanced debugging
See also
nom::RemoveAction

Implemented in nom::AnimateTexturesAction, nom::CallbackAction, nom::FadeAlphaByAction, nom::FadeAudioGainBy, nom::FadeInAction, nom::FadeOutAction, nom::GroupAction, nom::MoveByAction, nom::PlayAudioSource, nom::RemoveAction, nom::RepeatForAction, nom::RepeatForeverAction, nom::ReversedAction, nom::ScaleByAction, nom::SequenceAction, nom::SpriteBatchAction, and nom::WaitForDurationAction.

◆ resume()

virtual void nom::IActionObject::resume ( real32 delta_time)
pure virtual

Resume the internal state of the action.

Parameters
delta_timeReserved for application-defined implementations.
Note
This method should not normally need to be called externally! Exceptions might include: a) implementing a new action; b) advanced debugging
See also
nom::DispatchQueue

Implemented in nom::AnimateTexturesAction, nom::CallbackAction, nom::FadeAlphaByAction, nom::FadeAudioGainBy, nom::FadeInAction, nom::FadeOutAction, nom::GroupAction, nom::MoveByAction, nom::PlayAudioSource, nom::RemoveAction, nom::RepeatForAction, nom::RepeatForeverAction, nom::ReversedAction, nom::ScaleByAction, nom::SequenceAction, nom::SpriteBatchAction, and nom::WaitForDurationAction.

◆ rewind()

virtual void nom::IActionObject::rewind ( real32 delta_time)
pure virtual

Reset the internal state of the action back to its initial starting values.

Parameters
delta_timeReserved for application-defined implementations.
Note
This method should not normally need to be called externally! Exceptions might include: a) implementing a new action; b) advanced debugging
See also
nom::RepeatForAction, nom::RepeatForeverAction

Implemented in nom::AnimateTexturesAction, nom::CallbackAction, nom::FadeAlphaByAction, nom::FadeAudioGainBy, nom::FadeInAction, nom::FadeOutAction, nom::GroupAction, nom::MoveByAction, nom::PlayAudioSource, nom::RemoveAction, nom::RepeatForAction, nom::RepeatForeverAction, nom::ReversedAction, nom::ScaleByAction, nom::SequenceAction, nom::SpriteBatchAction, and nom::WaitForDurationAction.

◆ set_duration()

void nom::IActionObject::set_duration ( real32 seconds)
protected

Set the duration of the action.

Parameters
secondsThe duration in seconds.

◆ set_speed()

virtual void nom::IActionObject::set_speed ( real32 speed)
virtual

Set the speed factor of the action.

Reimplemented in nom::GroupAction, nom::RepeatForAction, nom::RepeatForeverAction, nom::ReversedAction, and nom::SequenceAction.

◆ set_status()

void nom::IActionObject::set_status ( FrameState state)
protected

Set the state of the action.

Parameters
stateOne of the IActionObject::FrameState enumeration values.

◆ set_timing_curve()

virtual void nom::IActionObject::set_timing_curve ( const IActionObject::timing_curve_func & mode)
virtual

◆ speed()

real32 nom::IActionObject::speed ( ) const

Get the speed modifier of the action.

Returns
The speed factor of the action.
Remarks
A value of zero (0.0f) stops the action from progressing forward in time.

◆ status()

IActionObject::FrameState nom::IActionObject::status ( ) const
protected

Get the current state of the action.

See also
nom::IActionObject::FrameState

◆ timing_curve()

const IActionObject::timing_curve_func & nom::IActionObject::timing_curve ( ) const

Get the timing mode function used by the action.

Returns
The function pointer to the timing curve function.
See also
nom::IActionObject::timing_curve_func

◆ action_list

typedef std::vector<std::shared_ptr<IActionObject> > action_list
related

A collection of actions.

Definition at line 216 of file IActionObject.hpp.

◆ create_action() [1/2]

template<typename ObjectType>
std::shared_ptr< ObjectType > create_action ( const action_list & actions)
related

Constructor function for creating an action that uses a collection of actions.

Parameters
actionsThe collection of actions to pass to the constructed object.
Remarks
The collection can be constructed in-place with a std::initializer_list object.
Note
If you are building with Visual Studio 2013 on the Windows platform, you will want to ensure that you have Update 2 or better applied before using this function call with a std::initializer_list object. See also: stackoverflow.com: std::shared_ptr in an std::initializer_list appears to be getting destroyed prematurely
See also
nom::GroupAction, nom::SequenceAction

Definition at line 252 of file IActionObject.hpp.

◆ create_action() [2/2]

template<typename ObjectType, typename... ObjectArgs>
std::shared_ptr< ObjectType > create_action ( ObjectArgs &&... args)
related

Constructor function for creating an action.

Parameters
argsThe arguments to pass to the constructed object.

Definition at line 224 of file IActionObject.hpp.

Member Data Documentation

◆ duration_

real32 nom::IActionObject::duration_ = 0.0f
private

Definition at line 208 of file IActionObject.hpp.

◆ elapsed_frames_

real32 nom::IActionObject::elapsed_frames_ = 0.0f
protected

Internal frames counter.

Remarks
This is intended purely for debugging convenience.

Definition at line 195 of file IActionObject.hpp.

◆ name_

std::string nom::IActionObject::name_
private

Definition at line 207 of file IActionObject.hpp.

◆ speed_

real32 nom::IActionObject::speed_ = 1.0f
private

Definition at line 209 of file IActionObject.hpp.

◆ status_

FrameState nom::IActionObject::status_ = FrameState::PLAYING
private

Definition at line 206 of file IActionObject.hpp.

◆ timer_

Timer nom::IActionObject::timer_
protected

Internal time clock (milliseconds resolution).

Remarks
Each action is responsible for keeping track of its clock – this provides a stable, fixed duration that yields to reliable results across any frame rate – at the cost of potentially skipping frames when performance suffers.

Definition at line 203 of file IActionObject.hpp.

◆ timing_curve_

timing_curve_func nom::IActionObject::timing_curve_ = nullptr
private

Definition at line 210 of file IActionObject.hpp.


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