libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
Ship::Tickable Class Reference

Manages a collection of Actions and indexed EventActions. More...

#include <Tickable.h>

Inheritance diagram for Ship::Tickable:
[legend]
Collaboration diagram for Ship::Tickable:
[legend]

Public Member Functions

 Tickable (const bool isTicking=true)
 Constructs a Tickable.
 
 Tickable (const bool isTicking, const std::vector< std::shared_ptr< Action > > &actions)
 Constructs a Tickable with an initial set of Actions.
 
virtual ~Tickable ()
 
bool IsTicking () const
 Returns true if this Tickable is currently ticking.
 
bool Start (const bool force=false)
 Starts ticking, enabling EventID-targeted Tick() calls on Actions.
 
bool Stop (const bool force=false)
 Stops ticking; subsequent Tick() calls become no-ops.
 
bool Tick (EventID eventId)
 Ticks only indexed EventActions whose EventID matches the given ID.
 
bool Tick (const std::vector< EventID > &eventIds)
 Ticks only indexed EventActions whose EventID matches one of the given IDs.
 
template<typename T >
bool Tick (const std::vector< EventID > &eventIds)
 Ticks Actions matching both type T and one of the given EventIDs.
 
template<typename T >
bool Tick (EventID eventId)
 Ticks Actions matching both type T and the given EventID.
 
EventActionListGetActionList ()
 Returns a mutable reference to the internal EventActionList.
 
const EventActionListGetActionList () const
 Returns a const reference to the internal EventActionList.
 
double GetTime (const ClockType clockType) const
 Returns the wall-clock time for a profiling checkpoint.
 

Protected Member Functions

virtual bool CanStart ()
 Permission hook; override to prevent starting. Defaults to true.
 
virtual bool CanStop ()
 Permission hook; override to prevent stopping. Defaults to true.
 
virtual void Started (const bool forced)
 Notification hook called after the Tickable has been started.
 
virtual void Stopped (const bool forced)
 Notification hook called after the Tickable has been stopped.
 
std::mutex & GetMutex ()
 Returns a reference to the internal mutex for synchronization. Only available when COMPONENT_THREAD_SAFE is defined.
 

Detailed Description

Manages a collection of Actions and indexed EventActions.

A Tickable owns zero or more Actions. Actions are stored in an internal EventActionList, which provides both generic action storage and indexed EventID lookup for efficient event dispatch. Thread safety for the action list is handled internally via a mutex when thread safety is enabled.

Constructor & Destructor Documentation

◆ Tickable() [1/2]

Ship::Tickable::Tickable ( const bool  isTicking = true)

Constructs a Tickable.

Parameters
isTickingIf true, the Tickable starts in the ticking state.

◆ Tickable() [2/2]

Ship::Tickable::Tickable ( const bool  isTicking,
const std::vector< std::shared_ptr< Action > > &  actions 
)

Constructs a Tickable with an initial set of Actions.

Parameters
isTickingIf true, the Tickable starts in the ticking state.
actionsThe Actions to add upon construction.

◆ ~Tickable()

virtual Ship::Tickable::~Tickable ( )
virtual

Member Function Documentation

◆ CanStart()

virtual bool Ship::Tickable::CanStart ( )
protectedvirtual

Permission hook; override to prevent starting. Defaults to true.

◆ CanStop()

virtual bool Ship::Tickable::CanStop ( )
protectedvirtual

Permission hook; override to prevent stopping. Defaults to true.

◆ GetActionList() [1/2]

EventActionList & Ship::Tickable::GetActionList ( )

Returns a mutable reference to the internal EventActionList.

◆ GetActionList() [2/2]

const EventActionList & Ship::Tickable::GetActionList ( ) const

Returns a const reference to the internal EventActionList.

◆ GetMutex()

std::mutex & Ship::Tickable::GetMutex ( )
protected

Returns a reference to the internal mutex for synchronization. Only available when COMPONENT_THREAD_SAFE is defined.

◆ GetTime()

double Ship::Tickable::GetTime ( const ClockType  clockType) const

Returns the wall-clock time for a profiling checkpoint.

Parameters
clockTypeWhich checkpoint to query.
Returns
Elapsed time in seconds since the epoch for the requested checkpoint.

◆ IsTicking()

bool Ship::Tickable::IsTicking ( ) const

Returns true if this Tickable is currently ticking.

◆ Start()

bool Ship::Tickable::Start ( const bool  force = false)

Starts ticking, enabling EventID-targeted Tick() calls on Actions.

Parameters
forceIf true, bypass the CanStart() check.
Returns
True if successfully started.

◆ Started()

virtual void Ship::Tickable::Started ( const bool  forced)
protectedvirtual

Notification hook called after the Tickable has been started.

Parameters
forcedWhether the start bypassed permission checks.

◆ Stop()

bool Ship::Tickable::Stop ( const bool  force = false)

Stops ticking; subsequent Tick() calls become no-ops.

Parameters
forceIf true, bypass the CanStop() check.
Returns
True if successfully stopped.

◆ Stopped()

virtual void Ship::Tickable::Stopped ( const bool  forced)
protectedvirtual

Notification hook called after the Tickable has been stopped.

Parameters
forcedWhether the stop bypassed permission checks.

◆ Tick() [1/4]

bool Ship::Tickable::Tick ( const std::vector< EventID > &  eventIds)

Ticks only indexed EventActions whose EventID matches one of the given IDs.

Parameters
eventIdsThe EventIDs to include.
Returns
True if at least one matching Action ran.

◆ Tick() [2/4]

template<typename T >
bool Ship::Tickable::Tick ( const std::vector< EventID > &  eventIds)

Ticks Actions matching both type T and one of the given EventIDs.

Template Parameters
TThe Action subtype to filter by.
Parameters
eventIdsThe EventIDs to include.
Returns
True if at least one matching Action ran.

◆ Tick() [3/4]

bool Ship::Tickable::Tick ( EventID  eventId)

Ticks only indexed EventActions whose EventID matches the given ID.

Parameters
eventIdThe EventID to include.
Returns
True if at least one matching Action ran.

◆ Tick() [4/4]

template<typename T >
bool Ship::Tickable::Tick ( EventID  eventId)

Ticks Actions matching both type T and the given EventID.

Template Parameters
TThe Action subtype to filter by.
Parameters
eventIdThe EventID to include.
Returns
True if at least one matching Action ran.

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