libtcod
Loading...
Searching...
No Matches
TCODSystem Class Reference

Static Public Member Functions

static void setFps (int val)
 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 int getFps ()
 The value returned by this function is updated every second.
static float getLastFrameLength ()
 Return the duration of the last frame in seconds.
static void sleepMilli (uint32_t val)
 Use this function to stop the program execution for a specified number of milliseconds.
static uint32_t getElapsedMilli ()
 This function returns the number of milliseconds since the program has started.
static float getElapsedSeconds ()
 This function returns the number of seconds since the program has started.
static TCODLIB_BEGIN_IGNORE_DEPRECATIONS TCOD_event_t waitForEvent (int eventMask, TCOD_key_t *key, TCOD_mouse_t *mouse, bool flush)
 This function waits for an event from the user.
static TCOD_event_t checkForEvent (int eventMask, TCOD_key_t *key, TCOD_mouse_t *mouse)
 This function checks if an event from the user is in the buffer.
static TCODLIB_END_IGNORE_DEPRECATIONS void saveScreenshot (const char *filename)
 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.
static bool createDirectory (const char *path)
static bool deleteDirectory (const char *path)
static bool deleteFile (const char *path)
static bool isDirectory (const char *path)
static TCOD_list_t getDirectoryContent (const char *path, const char *pattern)
 To get the list of entries in a directory (including sub-directories, except .
static bool fileExists (const char *filename,...)
 In order to check whether a given file exists in the filesystem.
static bool readFile (const char *filename, unsigned char **buf, size_t *size)
 This is a portable function to read the content of a file from disk or from the application apk (android).
static bool writeFile (const char *filename, unsigned char *buf, uint32_t size)
 This is a portable function to write some data to a file.
static void registerSDLRenderer (ITCODSDLRenderer *renderer)
 To disable the custom renderer, call the same method with a NULL parameter. Note that to keep libtcod from requiring the SDL headers, the callback parameter is a void pointer. You have to include SDL headers and cast it to SDL_Surface in your code.class TCODLIB_API ITCODSDLRenderer { public : virtual void render(void *sdlSurface) = 0; }; static void TCODSystem::registerSDLRenderer(ITCODSDLRenderer *callback);typedef void (*SDL_renderer_t) (void *sdl_surface); void TCOD_sys_register_SDL_renderer(SDL_renderer_t callback)def renderer ( sdl_surface ) : ... TCOD_sys_register_SDL_renderer( callback ).
static void forceFullscreenResolution (int width, int height)
 libtcod is not aware of the part of the screen your SDL renderer has updated.
static void getCurrentResolution (int *width, int *height)
 You can get the current screen resolution with getCurrentResolution.
static void getFullscreenOffsets (int *offset_x, int *offset_y)
 If the fullscreen resolution does not matches the console size in pixels, black borders are added.
static void getCharSize (int *w, int *h)
 You can get the size of the characters in the font.
static void updateChar (int asciiCode, int font_x, int font_y, const TCODImage *img, int x, int y)
 You can dynamically change the bitmap of a character in the font.
static void setRenderer (TCOD_renderer_t renderer)
 As of 1.5.1, libtcod contains 3 different renderers : SDL : historic libtcod renderer.
static TCOD_renderer_t getRenderer ()
static bool setClipboard (const char *value)
 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.
static char * getClipboard ()
 Returns the UTF-8 text currently in the system clipboard.
static int getNumCores ()
static TCOD_thread_t newThread (int(*func)(void *), void *data)
static void deleteThread (TCOD_thread_t th)
static void waitThread (TCOD_thread_t th)
static TCOD_mutex_t newMutex ()
static void mutexIn (TCOD_mutex_t mut)
static void mutexOut (TCOD_mutex_t mut)
static void deleteMutex (TCOD_mutex_t mut)
static TCOD_semaphore_t newSemaphore (int initVal)
static void lockSemaphore (TCOD_semaphore_t sem)
static void unlockSemaphore (TCOD_semaphore_t sem)
static void deleteSemaphore (TCOD_semaphore_t sem)
static TCOD_cond_t newCondition ()
static void signalCondition (TCOD_cond_t sem)
static void broadcastCondition (TCOD_cond_t sem)
static void waitCondition (TCOD_cond_t sem, TCOD_mutex_t mut)
static void deleteCondition (TCOD_cond_t sem)

Member Function Documentation

◆ checkForEvent()

TCOD_event_t TCODSystem::checkForEvent ( int eventMask,
TCOD_key_t * key,
TCOD_mouse_t * mouse )
static

This function checks if an event from the user is in the buffer.

The eventMask shows what events we're waiting for. The return value indicate what event was actually found. Values in key and mouse structures are updated accordingly.

TCOD_EVENT_KEY_PRESS=1, TCOD_EVENT_KEY_RELEASE=2, TCOD_EVENT_KEY=TCOD_EVENT_KEY_PRESS|TCOD_EVENT_KEY_RELEASE, TCOD_EVENT_MOUSE_MOVE=4, TCOD_EVENT_MOUSE_PRESS=8, TCOD_EVENT_MOUSE_RELEASE=16, TCOD_EVENT_MOUSE=TCOD_EVENT_MOUSE_MOVE|TCOD_EVENT_MOUSE_PRESS|TCOD_EVENT_MOUSE_RELEASE, TCOD_EVENT_ANY=TCOD_EVENT_KEY|TCOD_EVENT_MOUSE, } TCOD_event_t; static TCOD_event_t TCODSystem::checkForEvent(int eventMask, TCOD_key_t *key, TCOD_mouse_t *mouse)

Parameters
eventMaskevent types to wait for (other types are discarded)
keyupdated in case of a key event. Can be null if eventMask contains no key event type
mouseupdated in case of a mouse event. Can be null if eventMask contains no mouse event type

TCOD_key_t key; TCOD_mouse_t mouse; TCOD_event_t ev = TCODSystem::checkForEvent(TCOD_EVENT_ANY,&key,&mouse); if ( ev == TCOD_EVENT_KEY_PRESS && key.c == 'i' ) { ... open inventory ... }

TCOD_key_t key; TCOD_mouse_t mouse; TCOD_event_t ev = TCOD_sys_check_for_event(TCOD_EVENT_ANY,&key,&mouse); if ( ev == TCOD_EVENT_KEY_PRESS && key.c == 'i' ) { ... open inventory ... }

◆ createDirectory()

bool TCODSystem::createDirectory ( const char * path)
static

Those are a few function that cannot be easily implemented in a portable way in C/C++. They have no Python wrapper since Python provides its own builtin functions. All those functions return false if an error occurred.

Parameters
pathDirectory path. The immediate father directory (<path>/..) must exist and be writable.

◆ deleteDirectory()

bool TCODSystem::deleteDirectory ( const char * path)
static
Parameters
pathdirectory path. This directory must exist, be writable and empty

◆ deleteFile()

bool TCODSystem::deleteFile ( const char * path)
static
Parameters
pathFile path. This file must exist and be writable.

◆ fileExists()

bool TCODSystem::fileExists ( const char * filename,
... )
static

In order to check whether a given file exists in the filesystem.

Useful for detecting errors caused by missing files.

Parameters
filenamethe file name, using printf-like formatting
...optional arguments for filename formatting

if (!TCODSystem::fileExists("myfile.%s","txt")) { fprintf(stderr,"no such file!"); }

if (!TCOD_sys_file_exists("myfile.%s","txt")) { fprintf(stderr,"no such file!"); }

◆ forceFullscreenResolution()

void TCODSystem::forceFullscreenResolution ( int width,
int height )
static

libtcod is not aware of the part of the screen your SDL renderer has updated.

If no change occurred in the console, it won't redraw them except if you tell him to do so with this function

Parameters
x,y,w,hPart of the root console you want to redraw even if nothing has changed in the console back/fore/char.

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.

Parameters
width,heightResolution to use when switching to fullscreen. Will use the smallest available resolution so that : resolution width >= width and resolution width >= root console width * font char width resolution width >= height and resolution height >= root console height * font char height

TCODSystem::forceFullscreenResolution(800,600); // use 800x600 in fullscreen instead of 640x400 TCODConsole::initRoot(80,50,"",true); // 80x50 console with 8x8 char => 640x400 default resolution

TCOD_sys_force_fullscreen_resolution(800,600); TCOD_console_init_root(80,50,"",true);

libtcod.sys_force_fullscreen_resolution(800,600) libtcod.console_init_root(80,50,"",True)

tcod.system.forceFullscreenResolution(800,600) – use 800x600 in fullscreen instead of 640x400 tcod.console.initRoot(80,50,"",true) – 80x50 console with 8x8 char => 640x400 default resolution

◆ getCharSize()

void TCODSystem::getCharSize ( int * w,
int * h )
static

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

Parameters
width,heightcontains a character size when the function returns

◆ getClipboard()

char * TCODSystem::getClipboard ( )
static

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. For C and C++, note that the pointer is borrowed, and libtcod will take care of freeing the memory.

◆ getCurrentResolution()

void TCODSystem::getCurrentResolution ( int * width,
int * height )
static

You can get the current screen resolution with getCurrentResolution.

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

Parameters
width,heightcontains current resolution when the function returns

◆ getDirectoryContent()

TCOD_list_t TCODSystem::getDirectoryContent ( const char * path,
const char * pattern )
static

To get the list of entries in a directory (including sub-directories, except .

and ..). The returned list is allocated by the function and must be deleted by you. All the const char * inside must be also freed with TCODList::clearAndDelete.

Parameters
patha directory
patternIf NULL or empty, returns all directory entries. Else returns only entries matching the pattern. The pattern is NOT a regular expression. It can only handle one '' wildcard. Examples : *.png, saveGame, font*.png

◆ getFullscreenOffsets()

void TCODSystem::getFullscreenOffsets ( int * offset_x,
int * offset_y )
static

If the fullscreen resolution does not matches the console size in pixels, black borders are added.

This function returns the position in pixels of the console top left corner in the screen.

Parameters
offset_x,offset_ycontains the position of the console on the screen when using fullscreen mode.

◆ isDirectory()

bool TCODSystem::isDirectory ( const char * path)
static
Parameters
patha path to check

◆ readFile()

bool TCODSystem::readFile ( const char * filename,
unsigned char ** buf,
size_t * size )
static

This is a portable function to read the content of a file from disk or from the application apk (android).

buf must be freed with free(buf).

Parameters
filenamethe file name
bufa buffer to be allocated and filled with the file content
sizethe size of the allocated buffer.

unsigned char *buf; uint32_t size; if (TCODSystem::readFile("myfile.dat",&buf,&size)) { do something with buf free(buf); }

if (TCOD_sys_read_file("myfile.dat",&buf,&size)) { do something with buf free(buf); }

◆ registerSDLRenderer()

void TCODSystem::registerSDLRenderer ( ITCODSDLRenderer * renderer)
static

To disable the custom renderer, call the same method with a NULL parameter. Note that to keep libtcod from requiring the SDL headers, the callback parameter is a void pointer. You have to include SDL headers and cast it to SDL_Surface in your code.class TCODLIB_API ITCODSDLRenderer { public : virtual void render(void *sdlSurface) = 0; }; static void TCODSystem::registerSDLRenderer(ITCODSDLRenderer *callback);typedef void (*SDL_renderer_t) (void *sdl_surface); void TCOD_sys_register_SDL_renderer(SDL_renderer_t callback)def renderer ( sdl_surface ) : ... TCOD_sys_register_SDL_renderer( callback ).

You can register a callback that will be called after the libtcod rendering phase, but before the screen buffer is swapped. This callback receives the screen SDL_Surface reference. This makes it possible to use any SDL drawing functions (including openGL) on top of the libtcod console.

Parameters
callbackThe renderer to call before swapping the screen buffer. If NULL, custom rendering is disabled

class MyRenderer : public ITCODSDLRenderer { public : void render(void *sdlSurface) { SDL_Surface *s = (SDL_Surface *)sdlSurface; ... draw something on s } }; TCODSystem::registerSDLRenderer(new MyRenderer());

void my_renderer( void *sdl_surface ) { SDL_Surface *s = (SDL_Surface *)sdl_surface; ... draw something on s } TCOD_sys_register_SDL_renderer(my_renderer);

def my_renderer(sdl_surface) : ... draw something on sdl_surface using pygame libtcod.sys_register_SDL_renderer(my_renderer)

◆ saveScreenshot()

TCODLIB_END_IGNORE_DEPRECATIONS void TCODSystem::saveScreenshot ( const char * filename)
static

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.

Parameters
filenameName of the file. If NULL, a filename is automatically generated with the form "./screenshotNNN.png", NNN being the first free number (if a file named screenshot000.png already exist, screenshot001.png will be used, and so on...).

◆ setClipboard()

bool TCODSystem::setClipboard ( const char * value)
static

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.

With these functions, you can copy data in your operating system's clipboard from the game or retrieve data from the clipboard.

Parameters
valueUTF-8 text to copy into the clipboard

◆ setFps()

void TCODSystem::setFps ( int val)
static

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.

These are functions specifically aimed at real time game development.

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

◆ setRenderer()

void TCODSystem::setRenderer ( TCOD_renderer_t renderer)
static

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.

Parameters
rendererEither TCOD_RENDERER_GLSL, TCOD_RENDERER_OPENGL or TCOD_RENDERER_SDL

◆ sleepMilli()

void TCODSystem::sleepMilli ( uint32_t val)
static

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

Parameters
valnumber of milliseconds before the function returns

◆ updateChar()

void TCODSystem::updateChar ( int asciiCode,
int font_x,
int font_y,
const TCODImage * img,
int x,
int y )
static

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.

Parameters
asciiCodeascii code corresponding to the character to update
font_x,font_ycoordinate of the character in the bitmap font (in characters, not pixels)
imgimage containing the new character bitmap
x,yposition in pixels of the top-left corner of the character in the image

◆ waitForEvent()

TCODLIB_BEGIN_IGNORE_DEPRECATIONS TCOD_event_t TCODSystem::waitForEvent ( int eventMask,
TCOD_key_t * key,
TCOD_mouse_t * mouse,
bool flush )
static

This function waits for an event from the user.

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

TCOD_EVENT_NONE=0, TCOD_EVENT_KEY_PRESS=1, TCOD_EVENT_KEY_RELEASE=2, TCOD_EVENT_KEY=TCOD_EVENT_KEY_PRESS|TCOD_EVENT_KEY_RELEASE, TCOD_EVENT_MOUSE_MOVE=4, TCOD_EVENT_MOUSE_PRESS=8, TCOD_EVENT_MOUSE_RELEASE=16, TCOD_EVENT_MOUSE=TCOD_EVENT_MOUSE_MOVE|TCOD_EVENT_MOUSE_PRESS|TCOD_EVENT_MOUSE_RELEASE, TCOD_EVENT_ANY=TCOD_EVENT_KEY|TCOD_EVENT_MOUSE, } TCOD_event_t; static TCOD_event_t TCODSystem::waitForEvent(int eventMask, TCOD_key_t *key, TCOD_mouse_t *mouse, bool flush)

Parameters
eventMaskevent types to wait for (other types are discarded)
keyupdated in case of a key event. Can be null if eventMask contains no key event type
mouseupdated in case of a mouse event. Can be null if eventMask contains no mouse event type
flushif true, all pending events are flushed from the buffer. Else, return the first available event

TCOD_key_t key; TCOD_mouse_t mouse; TCOD_event_t ev = TCODSystem::waitForEvent(TCOD_EVENT_ANY,&key,&mouse,true); if ( ev == TCOD_EVENT_KEY_PRESS && key.c == 'i' ) { ... open inventory ... }

TCOD_key_t key; TCOD_mouse_t mouse; TCOD_event_t ev = TCOD_sys_wait_for_event(TCOD_EVENT_ANY,&key,&mouse,true); if ( ev == TCOD_EVENT_KEY_PRESS && key.c == 'i' ) { ... open inventory ... }

◆ writeFile()

bool TCODSystem::writeFile ( const char * filename,
unsigned char * buf,
uint32_t size )
static

This is a portable function to write some data to a file.

Parameters
filenamethe file name
bufa buffer containing the data to write
sizethe number of bytes to write.

TCODSystem::writeFile("myfile.dat",buf,size));

TCOD_sys_write_file("myfile.dat",buf,size));


The documentation for this class was generated from the following file:
  • C:/Users/4b796/Projects/libtcod/src/libtcod/sys.hpp