You.i Engine
CYITimer Class Reference

Detailed Description

A low-precision timer driven by the update loop.

The timer is configured with an interval in milliseconds. Each frame after the timer has been started, the elapsed time will be compared against the interval - and if it is larger than or equal to the interval, the TimedOut signal will be emitted.

Because the signal can only be emitted during CYIApp::Update, this timer cannot be more precise than the time between updates. The TimedOut signal can be delayed by an extra frame if the signal connection happens across threads.

The timer has two modes of operation - single shot and repeated. Single shot mode is the default.

See also
SetSingleShot

#include <utility/YiTimer.h>

Inheritance diagram for CYITimer:

Public Types

enum  State {
  State::Off = 0,
  State::Running,
  State::Suspended
}
 

Public Member Functions

 CYITimer ()
 
 CYITimer (int32_t timerID)
 
virtual ~CYITimer ()
 
 CYITimer (CYITimer &&other)
 
CYITimeroperator= (CYITimer &&other)
 
uint64_t GetInterval () const
 
State GetState () const
 
bool IsSingleShot () const
 
void SetInterval (uint64_t intervalMs)
 
void SetSingleShot (bool singleShot)
 
void Start (uint64_t intervalMs)
 
void Start ()
 
void Stop ()
 
void Suspend ()
 
void Resume ()
 
void SetTimerID (int32_t timerID)
 
int32_t GetTimerID () const
 
- Public Member Functions inherited from CYISignalHandler
 CYISignalHandler ()
 
 CYISignalHandler (const CYISignalHandler &rSignalHandler)
 
virtual ~CYISignalHandler ()
 
CYISignalHandleroperator= (const CYISignalHandler &rSignalHandler)
 
void MoveToThread (CYIThread *pThread)
 This function allows the user to override the default thread affinity to any CYIThread that may or may not be running. More...
 
CYIThreadHandle GetThreadAffinity () const
 
void SetThreadAffinity (const CYIThreadHandle &rThreadAffinity)
 
virtual bool IsConnected () const
 
virtual bool IsConnected (const CYISignalBase &rSignal) const
 
void Disconnect (CYISignalBase &rSignal)
 
void DisconnectFromAllSignals ()
 
- Public Member Functions inherited from CYIThread::Listener
 Listener ()
 
virtual ~Listener ()
 
virtual void OnThreadStarted (CYIThread *)
 
virtual void OnThreadTerminated (CYIThread *)
 
virtual void OnThreadFinished (CYIThread *)
 

Public Attributes

CYISignal< int32_t > TimedOut
 

Member Enumeration Documentation

◆ State

enum CYITimer::State
strong

Represents the state of the timer.

Enumerator
Off 

The timer has not been started, has been stopped, or timed out. It cannot be suspended or resumed in the Off state.

Running 

The timer has been started, and is not suspended.

Suspended 

The timer has been started, but is suspended.

Constructor & Destructor Documentation

◆ CYITimer() [1/3]

CYITimer::CYITimer ( )

Creates a new timer instance with ID defaulted to 0.

The initial state is CYITimer::State::Off.

◆ CYITimer() [2/3]

CYITimer::CYITimer ( int32_t  timerID)

Creates a new timer instance which can be identified by its ID, timerID.

The initial state is CYITimer::State::Off.

See also
SetTimerID

◆ ~CYITimer()

virtual CYITimer::~CYITimer ( )
virtual

◆ CYITimer() [3/3]

CYITimer::CYITimer ( CYITimer &&  other)

Moves the CYITimerPriv private timer

Member Function Documentation

◆ GetInterval()

uint64_t CYITimer::GetInterval ( ) const

Returns the currently configured timeout interval for this timer. The returned value is specified in milliseconds.

See also
SetInterval

◆ GetState()

State CYITimer::GetState ( ) const

Returns the state of the timer.

See also
CYITimer::State

◆ GetTimerID()

int32_t CYITimer::GetTimerID ( ) const
See also
SetTimerID

◆ IsSingleShot()

bool CYITimer::IsSingleShot ( ) const

Returns true if the timer is configured to be single shot. The default value is true.

See also
SetSingleShot.

◆ operator=()

CYITimer& CYITimer::operator= ( CYITimer &&  other)

Move assignment operator

◆ Resume()

void CYITimer::Resume ( )

Resumes a suspended timer.

Resuming a timer moves it from the CYITimer::State::Suspended state to the CYITimer::State::Running state. Resuming has no effect if the timer is not CYITimer::State::Suspended.

◆ SetInterval()

void CYITimer::SetInterval ( uint64_t  intervalMs)

Sets intervalMs as the interval for the next TimedOut signal call, in milliseconds.

◆ SetSingleShot()

void CYITimer::SetSingleShot ( bool  singleShot)

Specifies if this timer is single shot.

Timers are single shot by default. After the first TimedOut signal call, they will be stopped.

When set to false, the TimedOut signal will be called after each interval until Stop() is called.

◆ SetTimerID()

void CYITimer::SetTimerID ( int32_t  timerID)

Specify timerID as the ID to be passed back when the timer expires. The default value is 0.

See also
TimedOut

◆ Start() [1/2]

void CYITimer::Start ( uint64_t  intervalMs)

Sets the interval to intervalMs and starts or re-starts the timer.

As a result the timer will be in the CYITimer::State::Running state and the timer starts counting from 0.

If the timer was already running when Start() is called, the TimedOut signal will not be fired until the end of the new interval.

See also
SetInterval

◆ Start() [2/2]

void CYITimer::Start ( )

Starts or re-starts the timer with the currently configured interval value.

See also
SetInterval
Start(uint64_t)

◆ Stop()

void CYITimer::Stop ( )

Stops the timer.

As a result the timer will be in the CYITimer::State::Off state. If the timer was running, the TimedOut signal will not be fired.

◆ Suspend()

void CYITimer::Suspend ( )

Suspends the timer. When suspended, a timer will not accrue more time and will not expire.

Suspending a CYITimer::State::Running timer moves it to the CYITimer::State::Suspended state. Suspending has no effect if the timer is not CYITimer::State::Running.

Member Data Documentation

◆ TimedOut

CYISignal<int32_t> CYITimer::TimedOut

Emitted when the timer is in the CYITimer::State::Running state and the timer interval ends.

The integer parameter indicates the ID set on this timer.


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