< index < 3. System layer | ===================================== 3.1 High precision time functions ===================================== |

These are functions specifically aimed at real time game development.
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.

    C++ : static void TCODSystem::setFps(int val)
    C   : void TCOD_sys_set_fps(int val)
    Py  : sys_set_fps(val)

Parameter | Description
--- | ---
val | Maximum number of frames per second. 0 means unlimited frame rate.

Example :

    C++ : TCODSystem::setFps(25);
    C   : TCOD_sys_set_fps(25);
    Py  : libtcod.sys_set_fps(25)

The getFps function returns the actual number of frames rendered during the last second.
This value is updated every second.

    C++ : static int TCODSystem::getFps()
    C   : int TCOD_sys_get_fps()
    Py  : sys_get_fps()

Example :

    C++ : int fps = TCODSystem::getFps();
    C   : int fps = TCOD_sys_get_fps();
    Py  : fps = libtcod.sys_get_fps()

The getLastFrameLength function return the length in seconds of the last rendered frame.
You can use this value to update every time dependant object in the world.

    C++ : static float TCODSystem::getLastFrameLength()
    C   : float TCOD_sys_get_last_frame_length()
    Py  : sys_get_last_frame_length()

Example : moving an objet at 5 console cells per second

    C++ : float x=0,y=0; // object coordinates
          x += 5 * TCODSystem::getLastFrameLength();
          TCODConsole::root->putChar((int)(x),(int)(y),'@');
    C   : float x=0,y=0;
          x += 5 * TCOD_sys_get_last_frame_length();
          TCOD_console_put_char(NULL,(int)(x),(int)(y),'@');
    Py  : x=0.0
          y=0.0
          x += 5 * libtcod.sys_get_last_frame_length()
          libtcod.console_put_char(0,int(x),int(y),'@')

The sleepMilli function allows you to stop the program execution for a specified number of milliseconds.

    C++ : static void TCODSystem::sleepMilli(uint32 val)
    C   : void TCOD_sys_sleep_milli(uint32 val)
    Py  : sys_sleep_milli(val)

Parameter | Description
--- | ---
val | Number of milliseconds before the function returns.

Example :

    C++ : TCODSystem::sleepMilli(50);
    C   : TCOD_sys_sleep_milli(50);
    Py  : libtcod.sys_sleep_milli(50)

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

    C++ : static uint32 TCODSystem::getElapsedMilli()
    C   : uint32 TCOD_sys_elapsed_milli()
    Py  : sys_elapsed_milli()

Example :

    C++ : uint32 milli=TCODSystem::getElapsedMilli();
    C   : uint32 milli=TCOD_sys_elapsed_milli();
    Py  : milli=libtcod.sys_elapsed_milli()

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

    C++ : static float TCODSystem::getElapsedSeconds()
    C   : float TCOD_sys_elapsed_seconds()
    Py  : sys_elapsed_seconds()

Example :

    C++ : float seconds = TCODSystem::getElapsedSeconds();
    C   : float seconds = TCOD_sys_elapsed_seconds();
    Py  : seconds = libtcod.sys_elapsed_seconds()