NAME

TCOD::Sys - System functions for TCOD

SYNOPSIS

use TCOD;

...

DESCRIPTION

Handle events in TCOD applications.

FUNCTIONS

set_fps

TCOD::Sys::set_fps( $fps );

The set_fps 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.

get_fps

$fps = TCOD::Sys::get_fps;

The value returned by this function is updated every second.

get_last_frame_length

$seconds = TCOD::Sys::get_last_frame_length;

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.

sleep_milli

TCOD::Sys::sleep_milli( $milliseconds );

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

elapsed_milli

$milliseconds = TCOD::Sys::elapsed_milli;

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

elapsed_seconds

$seconds = TCOD::Sys::elapsed_seconds;

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

save_screnshot

TCOD::Sys::save_screenshot( $path );

This function allows you to save the current game screen in a PNG file, or possibly a BMP file if you provide a filename ending with .bmp.

update_char

TCOD::Sys::update_char( $code, $x, $y, $image, $x, $y );

You can dynamically change the bitmap of a character in the font. All cells using this ASCII code will be updated at next flush call.

set_renderer

TCOD::Sys::set_renderer( $renderer );

As of 1.5.1, libtcod contains 3 different renderers:

  • SDL

    Historic libtcod renderer. Should work and be pretty fast everywhere

  • OpenGL

    Requires OpenGL compatible video card. Might be much faster or much slower than SDL, depending on the drivers

  • GLSDL

    Requires OpenGL 1.4 compatible video card with GL_ARB_shader_objects extension. Blazing fast if you have the proper hardware and drivers.

This function switches the current renderer dynamically. The value in $renderer must be an element of the Renderer enum.

get_renderer

$renderer = TCOD::Sys::get_renderer;

Get the internal renderer. This will be an element of the Renderer enum.

get_char_size

( $w, $h ) = TCOD::Sys::get_char_size;

You can get the size in pixels of the characters in the font.

get_current_resolution

( $w, $h ) = TCOD::Sys::get_current_resolution;

You can get the current screen resolution with get_current_resolution.

You can use it for example to get the desktop resolution before initializing the root console.

force_fullscreen_resolution

TCOD::Sys::force_fullscreen_resolution( $width, $height );

This function allows you to force the use of a specific resolution in fullscreen mode. The default resolution depends on the root console size and the font character size.

get_directory_contents

@filenames = TCOD::Sys::get_directory_contents( $path );

Returns a list of the contents of a directory (including files and subdirectories), not including . and ... Will die with an error message if the operation fails.

This function is implemented here for compatibility. Standard Perl solutions are probably preferable.

wait_for_event

# Deprecated
TCOD::Sys::wait_for_event( $mask, \$key, \$mouse, $flush );

This function waits for an event from the user. The $mask shows what events we're waiting for. The return value indicate what event was actually triggered. Values in key and mouse structures are updated accordingly.

If flush is false, the function waits only if there are no pending events, else it returns the first event in the buffer.

This function is deprecated. Use SDL_WaitEvent from SDL instead.

check_for_event

# Deprecated
$event = TCOD::Sys::check_for_event( $mask, \$key, \$mouse );

This function checks if an event from the user is in the buffer. The $mask shows what events we're waiting for. The return value indicates what event was actually found. Values in key and mouse structures are updated accordingly.

This function is deprecated. Use SDL_PollEvent from SDL instead.

clipboard_set

# Deprecated
$bool = TCOD::Sys::clipboard_set( $contents );

Takes UTF-8 text and copies it into the system clipboard. On Linux, because an application cannot access the system clipboard unless a window is open, if no window is open the call will do nothing.

This function is deprecated. Use SDL2 to handle the clipboard.

clipboard_get

# Deprecated
$contents = TCOD::Sys::clipboard_get;

Returns the UTF-8 text currently in the system clipboard. On Linux, because an application cannot access the system clipboard unless a window is open, if no window is open an empty string will be returned.

This function is deprecated. Use SDL2 to handle the clipboard.

SEE ALSO

TCOD
TCOD::Console
TCOD::Key
TCOD::Mouse

COPYRIGHT AND LICENSE

Copyright 2021 José Joaquín Atria

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.