libtcoddocumentation

3.1. High precision time functions

These are functions specifically aimed at real time game development.

Limit the frames per second

The setFps function allows you to limit the number of frames per second.
If a frame is rendered faster than expected, the TCOD_console_flush function will wait so that the frame rate never exceed this value.
You can call this function during your game initialization.
You can dynamically change the frame rate. Just call this function once again.
You should always limit the frame rate, except during benchmarks, else your game will use 100% of the CPU power

static void TCODSystem::setFps(int val)

void TCOD_sys_set_fps(int val)

sys_set_fps(val)

static void TCODSystem::setFps(int val)

tcod.system.setFps(val)

ParameterDescription
valMaximum number of frames per second. 0 means unlimited frame rate.

Get the number of frames rendered during the last second

The value returned by this function is updated every second.

static int TCODSystem::getFps()

int TCOD_sys_get_fps()

sys_get_fps()

static int TCODSystem::getFps()

tcod.system.getFps()

Get the duration of the last frame

This function returns the length in seconds of the last rendered frame.
You can use this value to update every time dependent object in the world.

static float TCODSystem::getLastFrameLength()

float TCOD_sys_get_last_frame_length()

sys_get_last_frame_length()

static float TCODSystem::getLastFrameLength()

tcod.system.getLastFrameLength()

Example:

// moving an objet at 5 console cells per second
float x=0,y=0; // object coordinates
x += 5 * TCODSystem::getLastFrameLength();
TCODConsole::root->putChar((int)(x),(int)(y),'X');

float x=0,y=0;
x += 5 * TCOD_sys_get_last_frame_length();
TCOD_console_put_char(NULL,(int)(x),(int)(y),'X');

x=0.0
y=0.0
x += 5 * libtcod.sys_get_last_frame_length()
libtcod.console_put_char(0,int(x),int(y),'X')

-- moving an objet at 5 console cells per second
x=0
y=0 -- object coordinates
x = x + 5 * tcod.system.getLastFrameLength()
libtcod.TCODConsole_root:putChar(x,y,'X')


Pause the program

Use this function to stop the program execution for a specified number of milliseconds.

static void TCODSystem::sleepMilli(uint32 val)

void TCOD_sys_sleep_milli(uint32 val)

sys_sleep_milli(val)

static void TCODSystem::sleepMilli(uint val)

tcod.system.sleepMilli(val)

ParameterDescription
valnumber of milliseconds before the function returns

Get global timer in milliseconds

This function returns the number of milliseconds since the program has started.

static uint32 TCODSystem::getElapsedMilli()

uint32 TCOD_sys_elapsed_milli()

sys_elapsed_milli()

static uint TCODSystem::getElapsedMilli()

tcod.system.getElapsedMilli()

Get global timer in seconds

This function returns the number of seconds since the program has started.

static float TCODSystem::getElapsedSeconds()

float TCOD_sys_elapsed_seconds()

sys_elapsed_seconds()

static float TCODSystem::getElapsedSeconds()

tcod.system.getElapsedSeconds()