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 {
  OFF = 0,
  RUNNING,
  SUSPENDED
}
 

Public Member Functions

 CYITimer ()
 
 CYITimer (int32_t nTimerID)
 
virtual ~CYITimer ()
 
uint64_t GetInterval () const
 
STATE GetState () const
 
bool IsSingleShot () const
 
void SetInterval (uint64_t uIntervalMs)
 
void SetSingleShot (bool bSingleShot)
 
void Start (uint64_t uIntervalMs)
 
void Start ()
 
void Stop ()
 
void Suspend ()
 
void Resume ()
 
void SetTimerID (int32_t nTimerID)
 
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 Member Functions inherited from CYIScriptableObject
 CYIScriptableObject ()
 
 CYIScriptableObject (const CYIScriptableObject &other)
 
CYIScriptableObjectoperator= (const CYIScriptableObject &other)
 
virtual ~CYIScriptableObject ()
 
CYIBindingImplementationGetBindingImplementation () const
 
void SetBindingImplementation (CYIBindingImplementation *pBindingImplementation)
 
virtual const CYIRuntimeTypeInfoGetRuntimeTypeInfoForScriptObject () const
 

Public Attributes

CYISignal< int32_t > TimedOut
 

Member Enumeration Documentation

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::CYITimer ( )

Creates a new timer instance with ID defaulted to 0.

The initial state is OFF.

CYITimer::CYITimer ( int32_t  nTimerID)

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

The initial state is OFF.

See also
SetTimerID
virtual CYITimer::~CYITimer ( )
virtual

Member Function Documentation

uint64_t CYITimer::GetInterval ( ) const

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

See also
SetInterval
STATE CYITimer::GetState ( ) const

Returns the state of the timer.

See also
STATE
int32_t CYITimer::GetTimerID ( ) const
See also
SetTimerID
bool CYITimer::IsSingleShot ( ) const

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

See also
SetSingleShot.
void CYITimer::Resume ( )

Resumes a suspended timer.

Resuming a timer moves it from the SUSPENDED state to the RUNNING state. Resuming has no effect if the timer is not SUSPENDED.

void CYITimer::SetInterval ( uint64_t  uIntervalMs)

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

void CYITimer::SetSingleShot ( bool  bSingleShot)

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.

void CYITimer::SetTimerID ( int32_t  nTimerID)

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

See also
TimedOut
void CYITimer::Start ( uint64_t  uIntervalMs)

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

As a result the timer will be in the 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
void CYITimer::Start ( )

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

See also
SetInterval
Start(uint64_t)
void CYITimer::Stop ( )

Stops the timer.

As a result the timer will be in the OFF state. If the timer was running, the TimedOut signal will not be fired.

void CYITimer::Suspend ( )

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

Suspending a RUNNING timer moves it to the SUSPENDED state. Suspending has no effect if the timer is not RUNNING.

Member Data Documentation

CYISignal<int32_t> CYITimer::TimedOut

Emitted when the timer is in the 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: