|
libtcod
|
Any new project should use the getting-started guide so that they can start using contexts right way. Older projects will have to convert to contexts over a series of steps.
The old way of initializing a global state with TCOD_console_init_root() or TCODConsole::initRoot() has been deprecated. These have been replaced with a public context object.
You can switch away from TCOD_console_set_custom_font before using contexts by using the TCOD_set_default_tileset function.
Later when you upgrade to contexts you will replace TCOD_set_default_tileset with TCOD_ContextParams.
There is less state with the new functions. Instead of setting colors before calling the print functions you now pass the colors and flags needed for each print call.
Before initializing a context properly you can access both the context and the root console. This lets you use context methods like TCOD_Context::present easily in older code. This also lets you use the root console on functions which can't accept nullptr.
Using the context present function like this will break some functions which say they're not compatible with contexts. Most importantly any timing-related functions will need to be updated. See Timing_ below.
The next step is to actually replace TCOD_console_init_root with contexts.
With the temporary context from the previous step or with TCOD_sys_get_sdl_window you can access the SDL_Window pointer. You use this to replace several window-related functions such as TCOD_console_set_fullscreen, TCOD_console_is_active or TCOD_console_set_window_title. See the SDL2 window documentation <https://wiki.libsdl.org/CategoryVideo>_ for what you can do with the SDL_Window pointer.
Libtcod's event systems have been deprecated in favor of using SDL2_ directly for events. TCOD_Context::convert_event_coordinates is the recommended way to convert pixel coordinates to tiles. tcod::sdl2::process_event might work better for converting old code to use the new system.
All of the libtcod timing functions have been deprecated. Many will stop working once you switch to using contexts. Instead you should use tcod::Timer and SDL2's timing functions. Remember that you have to add #include <libtcod/timer.hpp> to access tcod::Timer, this also requires the SDL2 headers.
With all the above done you can now switch away from TCOD_console_init_root and start using TCOD_ContextParams and tcod::new_context.
The largest and most influential change to libtcod, between versions 1.5.2 and 1.6.0, was the move to replace SDL with SDL2_. SDL2 made many extensive changes to concepts used in SDL. Only one of these changes, the separation of text and key events, required a change in the libtcod API requiring users to update their code in the process of updating the version of libtcod they use.
When a user presses a key, they may be pressing SHIFT and =. On some keyboards, depending on the user's language and location, this may show + on the screen. On other user's keyboards, who knows what it may show on screen. SDL2 changes the way "the text which is displayed on the user's screen" is sent in key events. This means that the key event for SHIFT and = will be what happens for presses of both + and = (for user's with applicable keyboards), and there will be a new text event that happens with the displayed +.
SDL would when sending key events, provide the unicode character for the key event, ready for use. This meant that if the user happened to be using a British keyboard (or any that are similarly laid out), and pressed SHIFT and =, the event would be for the character +.
With SDL2, the raw key-presses still occur, but they are fundamentally linked to the keyboard of the user. Now there will still be an event where it says SHIFT and = are pressed, but the event will always be for the unmodified character =. The unicode text arrives in a new kind of event, and getting it requires explicitly checking that the event is the new text event, and then looking for the value in the relevant text field for the language being used.
Run your code from a terminal or DOS window and print out the event attributes/fields and look at what is going on. Have your code print out the modifiers, the keycode, the character, the text, and then run it and try pressing some keys. It will be much faster than posting "I don't understand" or "Can someone explain" somewhere and waiting for a response.
.. _SDL2: https://www.libsdl.org/index.php