FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
fge::Timer Class Reference

A timer that can be used with the timer manager to handle time. More...

#include <C_timer.hpp>

Public Member Functions

 Timer (fge::Timer const &timer)
 
 Timer (fge::Timer &&timer) noexcept
 
 Timer (std::chrono::milliseconds const &goal)
 Create a new timer with the given time goal.
 
 Timer (std::chrono::milliseconds const &goal, bool paused)
 Create a new timer with the given time goal and pause state.
 
 Timer (std::chrono::milliseconds const &goal, std::string name, bool paused)
 Create a new timer with the given time goal, name and pause state.
 
void setName (std::string const &name)
 Set the timer name.
 
std::string const & getName () const
 Get the timer name.
 
void setGoalDuration (std::chrono::milliseconds const &t)
 Set the goal duration of the timer.
 
void addToGoal (std::chrono::milliseconds const &t)
 Add an amount of time to the goal duration of the timer.
 
void subToGoal (std::chrono::milliseconds const &t)
 Subtract an amount of time to the goal duration of the timer.
 
void setElapsedTime (std::chrono::milliseconds const &t)
 Set the elapsed time of the timer.
 
void addToElapsedTime (std::chrono::milliseconds const &t)
 Add an amount of time to the elapsed time of the timer.
 
void subToElapsedTime (std::chrono::milliseconds const &t)
 Subtract an amount of time to the elapsed time of the timer.
 
std::chrono::steady_clock::time_point const & getLifeTimePoint () const
 Get the life time of the timer.
 
std::chrono::milliseconds getLifeDuration () const
 Get the life time of the timer as milliseconds.
 
std::chrono::milliseconds const & getElapsedTime () const
 Get the elapsed time of the timer.
 
std::chrono::milliseconds const & getGoalDuration () const
 Get the goal time of the timer.
 
std::chrono::milliseconds getTimeLeft () const
 Get the remaining time of the timer.
 
bool goalReached () const
 Check if the goal has been reached.
 
void restart ()
 Restart the timer.
 
void pause ()
 Pause the timer.
 
void resume ()
 Unpause the timer.
 
bool isPaused () const
 Check if the timer is paused.
 

Public Attributes

fge::CallbackHandler< fge::Timer & > _onTimeReached
 The callback called when the timer reaches the goal.
 

Detailed Description

A timer that can be used with the timer manager to handle time.

Constructor & Destructor Documentation

◆ Timer() [1/3]

fge::Timer::Timer ( std::chrono::milliseconds const & goal)
explicit

Create a new timer with the given time goal.

Parameters
goalThe time goal of the timer

◆ Timer() [2/3]

fge::Timer::Timer ( std::chrono::milliseconds const & goal,
bool paused )

Create a new timer with the given time goal and pause state.

Parameters
goalThe time goal of the timer
pausedThe pause state of the timer

◆ Timer() [3/3]

fge::Timer::Timer ( std::chrono::milliseconds const & goal,
std::string name,
bool paused )

Create a new timer with the given time goal, name and pause state.

Parameters
goalThe time goal of the timer
nameThe name of the timer
pausedThe pause state of the timer

Member Function Documentation

◆ addToElapsedTime()

void fge::Timer::addToElapsedTime ( std::chrono::milliseconds const & t)

Add an amount of time to the elapsed time of the timer.

Parameters
tThe amount of time to add to the elapsed time

◆ addToGoal()

void fge::Timer::addToGoal ( std::chrono::milliseconds const & t)

Add an amount of time to the goal duration of the timer.

See also
setGoalDuration
Parameters
tThe amount of time to add to the goal duration

◆ getElapsedTime()

std::chrono::milliseconds const & fge::Timer::getElapsedTime ( ) const

Get the elapsed time of the timer.

Returns
The elapsed time of the timer

◆ getGoalDuration()

std::chrono::milliseconds const & fge::Timer::getGoalDuration ( ) const

Get the goal time of the timer.

Returns
The goal time of the timer

◆ getLifeDuration()

std::chrono::milliseconds fge::Timer::getLifeDuration ( ) const

Get the life time of the timer as milliseconds.

Returns
The life time of the timer as milliseconds

◆ getLifeTimePoint()

std::chrono::steady_clock::time_point const & fge::Timer::getLifeTimePoint ( ) const

Get the life time of the timer.

This is the time elapsed since the timer was created.

Returns
The life time of the timer

◆ getName()

std::string const & fge::Timer::getName ( ) const

Get the timer name.

Returns
The name of the timer

◆ getTimeLeft()

std::chrono::milliseconds fge::Timer::getTimeLeft ( ) const

Get the remaining time of the timer.

Returns
The remaining time of the timer

◆ goalReached()

bool fge::Timer::goalReached ( ) const

Check if the goal has been reached.

Returns
true if the goal has been reached, false otherwise

◆ isPaused()

bool fge::Timer::isPaused ( ) const

Check if the timer is paused.

Returns
true if the timer is paused, false otherwise

◆ pause()

void fge::Timer::pause ( )

Pause the timer.

◆ restart()

void fge::Timer::restart ( )

Restart the timer.

This will reset the elapsed time to 0.

◆ resume()

void fge::Timer::resume ( )

Unpause the timer.

◆ setElapsedTime()

void fge::Timer::setElapsedTime ( std::chrono::milliseconds const & t)

Set the elapsed time of the timer.

Parameters
tThe elapsed time of the timer

◆ setGoalDuration()

void fge::Timer::setGoalDuration ( std::chrono::milliseconds const & t)

Set the goal duration of the timer.

This is the time goal of the timer, once reached the timer will be stopped and an callback will be called, you will be able to restart the timer in this callback.

Parameters
tThe goal duration of the timer

◆ setName()

void fge::Timer::setName ( std::string const & name)

Set the timer name.

Parameters
nameThe name of the timer

◆ subToElapsedTime()

void fge::Timer::subToElapsedTime ( std::chrono::milliseconds const & t)

Subtract an amount of time to the elapsed time of the timer.

Parameters
tThe amount of time to subtract to the elapsed time

◆ subToGoal()

void fge::Timer::subToGoal ( std::chrono::milliseconds const & t)

Subtract an amount of time to the goal duration of the timer.

See also
setGoalDuration
Parameters
tThe amount of time to subtract to the goal duration

Member Data Documentation

◆ _onTimeReached

fge::CallbackHandler<fge::Timer&> fge::Timer::_onTimeReached

The callback called when the timer reaches the goal.


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