KTech 1.1.0
C++ 2D terminal game engine library
Loading...
Searching...
No Matches
KTech::Time Class Reference

Engine component responsible for game loop timing. More...

#include <time.hpp>

Classes

struct  Invocation
 Calls a function after a given time. More...
 

Public Types

enum class  Measurement : uint8_t { ticks , seconds , milliseconds , microseconds }
 Time measurement.
 

Public Member Functions

void CallInvocations ()
 Call callback functions of finished Invocations.
 
void WaitUntilNextTick ()
 Sleeps and returns when the next tick should start.
 

Public Attributes

unsigned long tpsLimit
 Max ticks allowed to occur in a second. You set this value in Engine::Engine(), and you can change it whenever you want.
 
float tps = 0
 Actual ticks per second. Corresponds to Time::deltaTime.
 
float tpsPotential = 0
 Ticks per second if it wasn't limited by Time::tpsLimit.
 
long deltaTime = 0
 Duration of the last tick, in microseconds.
 
unsigned long ticksCounter = 0
 Total ticks since game started.
 

Friends

class Invocation
 
class Output
 
class Engine
 

Detailed Description

Engine component responsible for game loop timing.

This engine component schedules ticks (game loop iterations). Its member variables, which hold various information on tick timing, are at your disposal. Time also manages your Invocations.

Member Function Documentation

◆ CallInvocations()

void KTech::Time::CallInvocations ( )

Call callback functions of finished Invocations.

Progresses all Invocations by Time::deltaTime, and calls those which waited their time.

Normally placed at the start of your game loop, among the other callback-calling functions. For example:

// Game loop
while (engine.running)
{
// Call various callback-functions
engine.input.CallCallbacks();
engine.time.CallInvocations(); // <- Call due invocations.
engine.memory.CallOnTicks();
// Graphics...
}
bool running
States whether the game loop should be running or not.
Definition engine.hpp:43
Time time
Time engine component.
Definition engine.hpp:50
Memory memory
Memory engine component.
Definition engine.hpp:48
Input input
Input engine component.
Definition engine.hpp:47
void CallCallbacks()
Distribute accumulated inputs.
Definition input.cpp:159
void CallOnTicks()
Call the virtual OnTick() functions of all registered world structures.
Definition memory.cpp:51
void CallInvocations()
Call callback functions of finished Invocations.
Definition time.cpp:51
See also
Time::Invoke()

◆ WaitUntilNextTick()

void KTech::Time::WaitUntilNextTick ( )

Sleeps and returns when the next tick should start.

Calculates how long to sleep (based on how long the current tick is, and Time::tpsLimit). It enters sleep and returns when the following tick should occur. This function also updates Time::tpsPotential, Time::deltaTime, Time::tps, and Time::ticksCounter.

Normally placed at the end of your game loop:

// Game loop
while (engine.running)
{
// Call various callback-functions...
// Graphics...
}
void WaitUntilNextTick()
Sleeps and returns when the next tick should start.
Definition time.cpp:111
See also
Time::tpsLimit
Time::tpsPotential
Time::deltaTime
Time::tps
Time::ticksCounter

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