libtcod
Loading...
Searching...
No Matches
sys.h
Go to the documentation of this file.
1/* BSD 3-Clause License
2 *
3 * Copyright © 2008-2025, Jice and the libtcod contributors.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * 3. Neither the name of the copyright holder nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
34#pragma once
35#ifndef TCOD_SYS_H_
36#define TCOD_SYS_H_
37
38#include "image.h"
39#include "list.h"
40#include "mouse_types.h"
41#include "portability.h"
42
43TCOD_DEPRECATED("The libtcod event API has been deprecated, switch to using SDL event types exclusively")
44typedef enum TCOD_event_t {
45 TCOD_EVENT_NONE = 0,
46 TCOD_EVENT_KEY_PRESS = 1,
47 TCOD_EVENT_KEY_RELEASE = 2,
48 TCOD_EVENT_KEY = TCOD_EVENT_KEY_PRESS | TCOD_EVENT_KEY_RELEASE,
49 TCOD_EVENT_MOUSE_MOVE = 4,
50 TCOD_EVENT_MOUSE_PRESS = 8,
51 TCOD_EVENT_MOUSE_RELEASE = 16,
52 TCOD_EVENT_MOUSE = TCOD_EVENT_MOUSE_MOVE | TCOD_EVENT_MOUSE_PRESS | TCOD_EVENT_MOUSE_RELEASE,
53 /* #ifdef TCOD_TOUCH_INPUT */
54 TCOD_EVENT_FINGER_MOVE = 32,
55 TCOD_EVENT_FINGER_PRESS = 64,
56 TCOD_EVENT_FINGER_RELEASE = 128,
57 TCOD_EVENT_FINGER = TCOD_EVENT_FINGER_MOVE | TCOD_EVENT_FINGER_PRESS | TCOD_EVENT_FINGER_RELEASE,
58 /* #endif */
59 TCOD_EVENT_ANY = TCOD_EVENT_KEY | TCOD_EVENT_MOUSE | TCOD_EVENT_FINGER,
60} TCOD_event_t;
61
62struct SDL_Surface;
63typedef void (*SDL_renderer_t)(struct SDL_Surface* sdl_renderer);
64
65/* thread stuff */
66typedef void* TCOD_thread_t;
67typedef void* TCOD_semaphore_t;
68typedef void* TCOD_mutex_t;
69typedef void* TCOD_cond_t;
70
71#ifdef __cplusplus
72extern "C" {
73#endif
74TCODLIB_API void TCOD_sys_startup(void);
75TCODLIB_API void TCOD_sys_shutdown(void);
76
77/* filesystem stuff */
78TCOD_DEPRECATED_NOMESSAGE
79TCODLIB_API bool TCOD_sys_create_directory(const char* path);
80TCOD_DEPRECATED_NOMESSAGE
81TCODLIB_API bool TCOD_sys_delete_file(const char* path);
82TCOD_DEPRECATED_NOMESSAGE
83TCODLIB_API bool TCOD_sys_delete_directory(const char* path);
84TCOD_DEPRECATED_NOMESSAGE
85TCODLIB_API bool TCOD_sys_is_directory(const char* path);
86TCOD_DEPRECATED_NOMESSAGE
87TCODLIB_API TCOD_list_t TCOD_sys_get_directory_content(const char* path, const char* pattern);
88TCOD_DEPRECATED_NOMESSAGE
89TCODLIB_API bool TCOD_sys_file_exists(const char* filename, ...);
90TCOD_DEPRECATED_NOMESSAGE
91TCODLIB_API bool TCOD_sys_read_file(const char* filename, unsigned char** buf, size_t* size);
92TCOD_DEPRECATED_NOMESSAGE
93TCODLIB_API bool TCOD_sys_write_file(const char* filename, unsigned char* buf, uint32_t size);
94#ifndef TCOD_NO_THREADS
95/* threads */
96TCOD_DEPRECATED_NOMESSAGE
97TCODLIB_API TCOD_thread_t TCOD_thread_new(int (*func)(void*), void* data);
98TCOD_DEPRECATED_NOMESSAGE
99TCODLIB_API void TCOD_thread_delete(TCOD_thread_t th);
100TCOD_DEPRECATED_NOMESSAGE
101TCODLIB_API int TCOD_sys_get_num_cores(void);
102TCOD_DEPRECATED_NOMESSAGE
103TCODLIB_API void TCOD_thread_wait(TCOD_thread_t th);
104/* mutex */
105TCOD_DEPRECATED_NOMESSAGE
106TCODLIB_API TCOD_mutex_t TCOD_mutex_new(void);
107TCOD_DEPRECATED_NOMESSAGE
108TCODLIB_API void TCOD_mutex_in(TCOD_mutex_t mut);
109TCOD_DEPRECATED_NOMESSAGE
110TCODLIB_API void TCOD_mutex_out(TCOD_mutex_t mut);
111TCOD_DEPRECATED_NOMESSAGE
112TCODLIB_API void TCOD_mutex_delete(TCOD_mutex_t mut);
113/* semaphore */
114TCOD_DEPRECATED_NOMESSAGE
115TCODLIB_API TCOD_semaphore_t TCOD_semaphore_new(int initVal);
116TCOD_DEPRECATED_NOMESSAGE
117TCODLIB_API void TCOD_semaphore_lock(TCOD_semaphore_t sem);
118TCOD_DEPRECATED_NOMESSAGE
119TCODLIB_API void TCOD_semaphore_unlock(TCOD_semaphore_t sem);
120TCOD_DEPRECATED_NOMESSAGE
121TCODLIB_API void TCOD_semaphore_delete(TCOD_semaphore_t sem);
122/* condition */
123TCOD_DEPRECATED_NOMESSAGE
124TCODLIB_API TCOD_cond_t TCOD_condition_new(void);
125TCOD_DEPRECATED_NOMESSAGE
126TCODLIB_API void TCOD_condition_signal(TCOD_cond_t sem);
127TCOD_DEPRECATED_NOMESSAGE
128TCODLIB_API void TCOD_condition_broadcast(TCOD_cond_t sem);
129TCOD_DEPRECATED_NOMESSAGE
130TCODLIB_API void TCOD_condition_wait(TCOD_cond_t sem, TCOD_mutex_t mut);
131TCOD_DEPRECATED_NOMESSAGE
132TCODLIB_API void TCOD_condition_delete(TCOD_cond_t sem);
133#endif // TCOD_NO_THREADS
134#ifndef NO_SDL
135/* dynamic library */
136typedef void* TCOD_library_t;
137TCOD_DEPRECATED_NOMESSAGE
138TCODLIB_API TCOD_library_t TCOD_load_library(const char* path);
139TCOD_DEPRECATED_NOMESSAGE
140TCODLIB_API void* TCOD_get_function_address(TCOD_library_t library, const char* function_name);
141TCOD_DEPRECATED_NOMESSAGE
142TCODLIB_API void TCOD_close_library(TCOD_library_t);
143
144
152TCOD_DEPRECATED("Use SDL_GetTicks instead.")
153TCODLIB_API uint32_t TCOD_sys_elapsed_milli(void);
154
162TCOD_DEPRECATED("Use SDL_GetTicks instead.")
163TCODLIB_API float TCOD_sys_elapsed_seconds(void);
164
172TCOD_DEPRECATED("Use SDL_Delay instead.")
173TCODLIB_API void TCOD_sys_sleep_milli(uint32_t val);
174
183TCOD_DEPRECATED("This function is not compatible with contexts. Use tcod::Timer or SDL timing functions instead.")
184TCODLIB_API void TCOD_sys_set_fps(int val);
185
194TCOD_DEPRECATED("This function is not compatible with contexts. Use tcod::Timer or SDL timing functions instead.")
195TCODLIB_API int TCOD_sys_get_fps(void);
196
205TCOD_DEPRECATED("This function is not compatible with contexts. Use tcod::Timer or SDL timing functions instead.")
206TCODLIB_API float TCOD_sys_get_last_frame_length(void);
207
208TCOD_DEPRECATED("This function is not compatible with contexts.")
209TCODLIB_API void TCOD_sys_save_screenshot(const char* filename);
210TCOD_DEPRECATED("This function is not compatible with contexts.")
211TCODLIB_API void TCOD_sys_force_fullscreen_resolution(int width, int height);
212TCOD_DEPRECATED("This function is not compatible with contexts.")
213TCODLIB_API TCOD_NODISCARD int TCOD_sys_set_renderer(TCOD_renderer_t renderer);
214TCOD_DEPRECATED("This function is not compatible with contexts.")
215TCODLIB_API TCOD_renderer_t TCOD_sys_get_renderer(void);
219TCOD_DEPRECATED("Use SDL to determine the screen resolution instead.")
220TCODLIB_API TCOD_Error TCOD_sys_get_current_resolution(int* w, int* h);
221TCOD_DEPRECATED("This function is not compatible with contexts.")
222TCODLIB_API void TCOD_sys_get_fullscreen_offsets(int* offset_x, int* offset_y);
223TCOD_DEPRECATED("This function is not compatible with contexts.")
224TCODLIB_API void TCOD_sys_get_char_size(int* w, int* h);
225
237TCODLIB_API void TCOD_sys_update_char(int asciiCode, int font_x, int font_y, const TCOD_Image* img, int x, int y);
238
239TCODLIB_API struct SDL_Window* TCOD_sys_get_SDL_window(void);
240TCODLIB_API struct SDL_Renderer* TCOD_sys_get_SDL_renderer(void);
241
242TCODLIB_BEGIN_IGNORE_DEPRECATIONS
243TCOD_DEPRECATED("This API is deprecated, use SDL_WaitEvent instead.")
244TCODLIB_API TCOD_event_t TCOD_sys_wait_for_event(int eventMask, TCOD_key_t* key, TCOD_mouse_t* mouse, bool flush);
245TCOD_DEPRECATED("This API is deprecated, use SDL_PollEvent instead.")
246TCODLIB_API TCOD_event_t TCOD_sys_check_for_event(int eventMask, TCOD_key_t* key, TCOD_mouse_t* mouse);
247TCODLIB_END_IGNORE_DEPRECATIONS
248
249/* clipboard */
250TCOD_DEPRECATED("Use the SDL API to handle the clipboard.")
251TCODLIB_API bool TCOD_sys_clipboard_set(const char* value);
252TCOD_DEPRECATED("Use the SDL API to handle the clipboard.")
253TCODLIB_API char* TCOD_sys_clipboard_get(void);
254
255/* SDL renderer callback */
256TCOD_DEPRECATED_NOMESSAGE
257TCODLIB_API void TCOD_sys_register_SDL_renderer(SDL_renderer_t renderer);
258#endif // NO_SDL
259#ifdef __cplusplus
260} // extern "C"
261#endif
262#endif // TCOD_SYS_H_
TCOD_renderer_t
Libtcod rendering modes.
Definition console_types.h:491
TCOD_Error
An enum of libtcod error codes.
Definition error.h:48
Image handling module.
Deprecated libtcod list module.
Mouse state provided by the libtcod event system.
Miscellaneous tools needed across platforms.
Definition image.h:54
Libtcod key event data, as a keycode or text character.
Definition console_types.h:207
Mouse state provided by the libtcod event system.
Definition mouse_types.h:50
uint32_t TCOD_sys_elapsed_milli(void)
Alias for SDL_GetTicks.
int TCOD_sys_get_fps(void)
Get the current framerate.
float TCOD_sys_get_last_frame_length(void)
Get the delta time between the last two frames.
void TCOD_sys_update_char(int asciiCode, int font_x, int font_y, const TCOD_Image *img, int x, int y)
Upload a tile to the active tileset.
float TCOD_sys_elapsed_seconds(void)
Returns the number of seconds since the start of the program.
void TCOD_sys_sleep_milli(uint32_t val)
Alias for SDL_Delay.
TCOD_Error TCOD_sys_get_current_resolution(int *w, int *h)
Return the resolution of the current monitor.
void TCOD_sys_set_fps(int val)
Set the desired framerate.