sculpto
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
scl::timer Class Reference

#include <timer.h>

Public Member Functions

 timer ()
 
void Response ()
 

Static Public Member Functions

static bool GetIsPause ()
 
static float GetTime ()
 
static float GetDeltaTime ()
 
static float GetFps ()
 
static void SetIsPause (bool IsPause)
 
static void SwitchIsPause ()
 
static shared< timer > & Get ()
 

Static Public Attributes

static const float UpdateDelay = 0.2f
 

Detailed Description

Definition at line 17 of file timer.h.

Constructor & Destructor Documentation

◆ timer()

scl::timer::timer ( )

Timer default constructor.

Definition at line 16 of file timer.cpp.

17{
18 LastFpsCalcutionTime = OldTime = StartTime = high_resolution_clock::now();
19}

Member Function Documentation

◆ Get()

static shared< timer > & scl::timer::Get ( )
inlinestatic
  • Global timer getter function.
Parameters
None.
Returns
None.

Definition at line 71 of file timer.h.

71{ return GlobalTimerInstance; }

◆ GetDeltaTime()

static float scl::timer::GetDeltaTime ( )
inlinestatic

Inter-frame delta time getter function.

Definition at line 42 of file timer.h.

42{ return GlobalTimerInstance->DeltaTime; }

◆ GetFps()

static float scl::timer::GetFps ( )
inlinestatic

Frames per second count getter function.

Definition at line 44 of file timer.h.

44{ return GlobalTimerInstance->Fps; }

◆ GetIsPause()

static bool scl::timer::GetIsPause ( )
inlinestatic

Timer update delay in seconds.

Is timer paused flag getter function.

Definition at line 38 of file timer.h.

38{ return GlobalTimerInstance->IsPause; }

◆ GetTime()

static float scl::timer::GetTime ( )
inlinestatic

Current time since 1970 1st Jan getter function.

Definition at line 40 of file timer.h.

40{ return GlobalTimerInstance->Time; }

◆ Response()

void scl::timer::Response ( )
  • Timer response function. Calculate inter-frame delta time each call, but FPS only once second.
Parameters
None.
Returns
None.

Definition at line 21 of file timer.cpp.

22{
23 time_point current_time = high_resolution_clock::now();
24 Time = duration<float>(current_time - StartTime).count();
25
26 LastFpsCalcutionFramesCount++;
27 float fps_calculation_delta_time = duration<float>(current_time - LastFpsCalcutionTime).count();
28 if (fps_calculation_delta_time >= UpdateDelay)
29 {
30 Fps = LastFpsCalcutionFramesCount / fps_calculation_delta_time;
31 LastFpsCalcutionTime = high_resolution_clock::now();
32 LastFpsCalcutionFramesCount = 0;
33 }
34
35 DeltaTime = duration<float>(current_time - OldTime).count();
36 OldTime = current_time;
37}
static const float UpdateDelay
Definition: timer.h:35

◆ SetIsPause()

static void scl::timer::SetIsPause ( bool  IsPause)
inlinestatic

Is timer paused flag setter function.

Definition at line 47 of file timer.h.

47{ GlobalTimerInstance->IsPause = IsPause; }

◆ SwitchIsPause()

static void scl::timer::SwitchIsPause ( )
inlinestatic

Is timer paused flag toffle function.

Definition at line 49 of file timer.h.

49{ GlobalTimerInstance->IsPause = !GlobalTimerInstance->IsPause; }

Member Data Documentation

◆ UpdateDelay

const float scl::timer::UpdateDelay = 0.2f
static

Timer getter/setter functions.

Definition at line 35 of file timer.h.


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