AppEasy Core SDK  1.5.0
Cross platform mobile and desktop app and game development SDK - The easy way to make apps
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
CzTimer Class Reference

Polled timer. More...

#include <CzTime.h>

List of all members.

Public Member Functions

void setDuration (uint64 millseconds_duration, bool start=true)
 Sets the duration of the timer.
uint64 getDuration () const
 Gets the duration of the timer.
void setAutoReset (bool auto_reset)
 If true the timer will aito restart once it times out.
bool getAutoReset () const
 Returns auto resset status.
bool hasStarted () const
 Returns true if the timer has started.
bool hasStopped () const
 Returns true if the timer has stopped.
 CzTimer ()
 CzTimer (int millseconds_duration)
virtual ~CzTimer ()
virtual bool HasTimedOut ()
 Returns true if the timer has timed out.
uint64 GetElapsedTime () const
 Return the amount of time since the timer was started.
uint64 GetTimeDiff (uint64 this_time) const
 returns the difference in time between the supplied time and the timers current time
uint64 GetTimeDiff () const
 returns the difference in time between the current time and the timers current time
uint64 GetTimeLeft () const
 Returns the amount of time left before the timer times out.
void Reset ()
 Restarts the timer.
void Start ()
 Starts the timer.
void Stop ()
 Stops the timer.

Static Public Member Functions

static uint64 GetCurrentTimeMs ()
 Static method that returns the current system time in millseconds.
static int64 GetCurrentTimeUTC ()
 Static method that returns the current system UTC time.

Protected Attributes

bool Started
 true if timer started
uint64 LastTime
 Time that the timer was set (milliseconds)

Detailed Description

Polled timer.

Introduction

Time plays a very important role in app and game development. Time allows us to perform useful tasks such as time events, fire off events at regular intervals and stabilise animations etc..

CzTimer provides a software based timer mechanism for timing events as well a static method for retrieving the current time in milliseconds. Timers will not automatically fire off events when they expire, instead they have to be polled.

Timers provide additional functionality for calculating how much time is left on the timer as well as how much time has expired since the timer was started.

Timers don't really have much of an overhead so you can create as many as you like.

Getting the Current Time

To retrieve the current time in milliseconds CzTimer provides a static method:

To retrieve the current time in UTC (universal coordinated time) CzTimer provides a static method:

Creating and Using Timers

Creating a timer is a simple case of declaring or allocating a CzTimer then setting it off going. To check the timer you then poll it to check to see if it has timed out. Here's an example:

// Create a timer that expires after 10 seconds
CzTimer BusyTimer;
BusyTimer.setDuration(10000);

// Check to see if the timer has timed out
if (BusyTimer.HasTimedOut())
{
}

Timers can be reset, stopped and started using Reset(), Stop() and Start().


Constructor & Destructor Documentation

CzTimer::CzTimer ( ) [inline]
CzTimer::CzTimer ( int  millseconds_duration)
virtual CzTimer::~CzTimer ( ) [inline, virtual]

Member Function Documentation

bool CzTimer::getAutoReset ( ) const

Returns auto resset status.

uint64 CzTimer::GetCurrentTimeMs ( ) [static]

Static method that returns the current system time in millseconds.

int64 CzTimer::GetCurrentTimeUTC ( ) [static]

Static method that returns the current system UTC time.

uint64 CzTimer::getDuration ( ) const

Gets the duration of the timer.

uint64 CzTimer::GetElapsedTime ( ) const

Return the amount of time since the timer was started.

uint64 CzTimer::GetTimeDiff ( uint64  this_time) const

returns the difference in time between the supplied time and the timers current time

uint64 CzTimer::GetTimeDiff ( ) const

returns the difference in time between the current time and the timers current time

uint64 CzTimer::GetTimeLeft ( ) const

Returns the amount of time left before the timer times out.

bool CzTimer::hasStarted ( ) const

Returns true if the timer has started.

bool CzTimer::hasStopped ( ) const

Returns true if the timer has stopped.

bool CzTimer::HasTimedOut ( ) [virtual]

Returns true if the timer has timed out.

void CzTimer::Reset ( )

Restarts the timer.

void CzTimer::setAutoReset ( bool  auto_reset)

If true the timer will aito restart once it times out.

void CzTimer::setDuration ( uint64  millseconds_duration,
bool  start = true 
)

Sets the duration of the timer.

void CzTimer::Start ( )

Starts the timer.

void CzTimer::Stop ( )

Stops the timer.


Member Data Documentation

uint64 CzTimer::LastTime [protected]

Time that the timer was set (milliseconds)

bool CzTimer::Started [protected]

true if timer started


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