lxgui
Public Types | Public Member Functions | List of all members
lxgui::utils::periodic_timer Class Reference

A repeating timer. More...

#include <utils_periodic_timer.hpp>

Public Types

enum class  start_type { paused , now , first_tick }
 

Public Member Functions

 periodic_timer (double duration, start_type type, bool ticks_now)
 Default constructor. More...
 
double get_elapsed () const
 Returns the time elapsed since the last tick. More...
 
double get_period () const
 Returns the period of the periodic_timer. More...
 
bool is_paused () const
 Cheks if this periodic_timer is paused. More...
 
bool ticks ()
 Checks if the timer's period has been reached. More...
 
void stop ()
 Pauses the timer and resets it. More...
 
void start ()
 Starts the timer but doesn't reset it. More...
 
void pause ()
 Pauses the timer. More...
 
void zero ()
 Resets the timer but doesn't pause it. More...
 
void update (double delta)
 Updates this timer (adds time). More...
 

Detailed Description

A repeating timer.

This timer is meant to tick periodicaly, so you can use it for any periodic event such as key repetition or a count down.

Definition at line 14 of file utils_periodic_timer.hpp.

Member Enumeration Documentation

◆ start_type

Enumerator
paused 

The timer will start if you call start()

now 

The timer starts immediatly after it is created.

first_tick 

The timer will start when you first call ticks()

Definition at line 16 of file utils_periodic_timer.hpp.

Constructor & Destructor Documentation

◆ periodic_timer()

lxgui::utils::periodic_timer::periodic_timer ( double  duration,
start_type  type,
bool  ticks_now 
)

Default constructor.

Parameters
durationThe time interval between each tick
typeSee TimerType
ticks_nowThe timer ticks immediately

Definition at line 5 of file utils_periodic_timer.cpp.

Member Function Documentation

◆ get_elapsed()

double lxgui::utils::periodic_timer::get_elapsed ( ) const

Returns the time elapsed since the last tick.

Returns
The time elapsed since last tick

Definition at line 11 of file utils_periodic_timer.cpp.

◆ get_period()

double lxgui::utils::periodic_timer::get_period ( ) const

Returns the period of the periodic_timer.

Returns
The period of the periodic_timer

Definition at line 15 of file utils_periodic_timer.cpp.

◆ is_paused()

bool lxgui::utils::periodic_timer::is_paused ( ) const

Cheks if this periodic_timer is paused.

Returns
'true' if this periodic_timer is paused

Definition at line 19 of file utils_periodic_timer.cpp.

◆ pause()

void lxgui::utils::periodic_timer::pause ( )

Pauses the timer.

Definition at line 43 of file utils_periodic_timer.cpp.

◆ start()

void lxgui::utils::periodic_timer::start ( )

Starts the timer but doesn't reset it.

Definition at line 47 of file utils_periodic_timer.cpp.

◆ stop()

void lxgui::utils::periodic_timer::stop ( )

Pauses the timer and resets it.

Definition at line 38 of file utils_periodic_timer.cpp.

◆ ticks()

bool lxgui::utils::periodic_timer::ticks ( )

Checks if the timer's period has been reached.

Returns
'true' if the period has been reached

Definition at line 23 of file utils_periodic_timer.cpp.

◆ update()

void lxgui::utils::periodic_timer::update ( double  delta)

Updates this timer (adds time).

Parameters
deltaThe time elapsed since last update

Definition at line 55 of file utils_periodic_timer.cpp.

◆ zero()

void lxgui::utils::periodic_timer::zero ( )

Resets the timer but doesn't pause it.

Definition at line 51 of file utils_periodic_timer.cpp.


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