added counting active API threads
[rocksndiamonds.git] / src / libgame / system.h
index c7df978523968fd7427ad9f16aa6060cf687272c..11c88762ff96f9fbd2dd275050b57fd1bbe25d9d 100644 (file)
@@ -4,7 +4,7 @@
 // (c) 1995-2014 by Artsoft Entertainment
 //                         Holger Schemel
 //                 info@artsoft.org
-//                 http://www.artsoft.org/
+//                 https://www.artsoft.org/
 // ----------------------------------------------------------------------------
 // system.h
 // ============================================================================
@@ -22,6 +22,8 @@
 #include "windows.h"
 #elif defined(PLATFORM_ANDROID)
 #include "android.h"
+#elif defined(PLATFORM_EMSCRIPTEN)
+#include "emscripten.h"
 #endif
 
 #include "sdl.h"
 #define STR_SPECIAL_RENDERING_TARGET   "target_texture_only"
 #define STR_SPECIAL_RENDERING_DOUBLE   "stream_and_target_texture"
 
+#if defined(PLATFORM_EMSCRIPTEN)
+#define STR_SPECIAL_RENDERING_DEFAULT  STR_SPECIAL_RENDERING_BITMAP
+#else
 #define STR_SPECIAL_RENDERING_DEFAULT  STR_SPECIAL_RENDERING_DOUBLE
+#endif
 
 #define SPECIAL_RENDERING_OFF          0
 #define SPECIAL_RENDERING_BITMAP       1
 #define SPECIAL_RENDERING_TARGET       2
 #define SPECIAL_RENDERING_DOUBLE       3
 
-#define SPECIAL_RENDERING_DEFAULT      SPECIAL_RENDERING_DOUBLE
-
 // values for vertical screen retrace synchronization (vsync)
 #define STR_VSYNC_MODE_OFF             "off"
 #define STR_VSYNC_MODE_NORMAL          "normal"
 
 #define VSYNC_MODE_DEFAULT             VSYNC_MODE_OFF
 
+#define VSYNC_MODE_STR_TO_INT(s)                                       \
+  (strEqual((s), STR_VSYNC_MODE_NORMAL)                ? VSYNC_MODE_NORMAL :   \
+   strEqual((s), STR_VSYNC_MODE_ADAPTIVE)      ? VSYNC_MODE_ADAPTIVE : \
+   VSYNC_MODE_OFF)
+
+#define VSYNC_MODE_INT_TO_STR(i)                                       \
+  ((i) == VSYNC_MODE_NORMAL            ? STR_VSYNC_MODE_NORMAL :       \
+   (i) == VSYNC_MODE_ADAPTIVE          ? STR_VSYNC_MODE_ADAPTIVE :     \
+   STR_VSYNC_MODE_OFF)
+
 // values for network server settings
 #define STR_NETWORK_AUTO_DETECT                "auto_detect_network_server"
 #define STR_NETWORK_AUTO_DETECT_SETUP  "(auto detect network server)"
 
+// values for API server settings
+#define API_SERVER_HOSTNAME            "api.artsoft.org"
+#define API_SERVER_PORT                        80
+#define API_SERVER_METHOD              "POST"
+#define API_SERVER_URI_ADD             "/api/scores/add"
+#define API_SERVER_URI_GET             "/api/scores/get"
+#define API_SERVER_URI_RENAME          "/api/players/rename"
+
+#if defined(TESTING)
+#undef API_SERVER_HOSTNAME
+#define API_SERVER_HOSTNAME            "api-test.artsoft.org"
+#define TEST_PREFIX                    "test."
+#else
+#define TEST_PREFIX                    ""
+#endif
+
 // values for touch control
 #define TOUCH_CONTROL_OFF              "off"
 #define TOUCH_CONTROL_VIRTUAL_BUTTONS  "virtual_buttons"
 
 // values for special settings for mobile devices
 #if defined(PLATFORM_ANDROID)
+#define HAS_TOUCH_DEVICE
 #define USE_TOUCH_INPUT_OVERLAY
 #define USE_COMPLETE_DISPLAY
 #define HAS_SCREEN_KEYBOARD
 #endif
 
 // values for drag-and-drop support (some parts not added before SDL 2.0.5)
-#if SDL_VERSION_ATLEAST(2,0,5)
-#define USE_DRAG_AND_DROP
+#if !SDL_VERSION_ATLEAST(2,0,5)
+#define SDL_DROPTEXT                   (SDL_DROPFILE + 1)
+#define SDL_DROPBEGIN                  (SDL_DROPFILE + 2)
+#define SDL_DROPCOMPLETE               (SDL_DROPFILE + 3)
 #endif
 
 // default input keys
 
 #define ANIM_DEFAULT           ANIM_LOOP
 
-// values for special drawing styles (currently only for crumbled graphics)
+// values for special drawing styles and event handling
 #define STYLE_NONE             0
+
+// values used for crumbled graphics
 #define STYLE_ACCURATE_BORDERS (1 << 0)
 #define STYLE_INNER_CORNERS    (1 << 1)
+
+// values used for game panel graphics
 #define STYLE_REVERSE          (1 << 2)
+#define STYLE_LEFTMOST_POSITION        (1 << 3)
 
-// values for special event handling style (used for global animation)
-#define STYLE_PASSTHROUGH      (1 << 3)
-#define STYLE_MULTIPLE_ACTIONS (1 << 4)
+// values used for global animations
+#define STYLE_BLOCK            (1 << 4)
+#define STYLE_PASSTHROUGH      (1 << 5)
+#define STYLE_MULTIPLE_ACTIONS (1 << 6)
 
 #define STYLE_DEFAULT          STYLE_NONE
 
+// values for special global animation delay types
+#define ANIM_DELAY_UNDEFINED   -1
+#define ANIM_DELAY_NONE                0
+#define ANIM_DELAY_INIT                1
+#define ANIM_DELAY_ANIM                2
+#define ANIM_DELAY_POST                3
+
+// values for special global animation delay actions
+#define ANIM_DELAY_ACTION_NONE -1
+
 // values for special global animation events
+#define ANIM_EVENT_UNDEFINED   -1
 #define ANIM_EVENT_NONE                0
 #define ANIM_EVENT_SELF                (1 << 16)
 #define ANIM_EVENT_ANY         (1 << 17)
-
+#define ANIM_EVENT_CLICK       (1 << 18)
+#define ANIM_EVENT_INIT                (1 << 19)
+#define ANIM_EVENT_START       (1 << 20)
+#define ANIM_EVENT_END         (1 << 21)
+#define ANIM_EVENT_POST                (1 << 22)
+#define ANIM_EVENT_UNCLICK_ANY (1 << 23)
+
+// anim number: bits 0-7
+// part number: bits 8-15
 #define ANIM_EVENT_ANIM_BIT    0
 #define ANIM_EVENT_PART_BIT    8
 
 
 #define FADE_MODE_DEFAULT      FADE_MODE_FADE
 
+#define AUTO_DELAY_UNIT_MS     0
+#define AUTO_DELAY_UNIT_FRAMES 1
+
+#define AUTO_DELAY_UNIT_DEFAULT        AUTO_DELAY_UNIT_MS
+
 // values for toon positions
 #define POS_UNDEFINED          -1
 #define POS_LEFT               0
                                 y >= gfx.ey && y < gfx.ey + gfx.eysize)
 
 // values for mouse cursor
+#define CURSOR_UNDEFINED       -1
 #define CURSOR_DEFAULT         0
 #define CURSOR_NONE            1
 #define CURSOR_PLAYFIELD       2
 // maximum number of parallel players supported by libgame functions
 #define MAX_PLAYERS            4
 
+// maximum number of player names
+#define MAX_PLAYER_NAMES       12
+
 // maximum allowed length of player name
 #define MAX_PLAYER_NAME_LEN    10
 
                                         JOY_BUTTON_2 :                  \
                                         JOY_NO_ACTION)
 
+// maximum number of level sets in the level set history
+#define MAX_LEVELDIR_HISTORY   12
+
 // default name for empty highscore entry
 #define EMPTY_PLAYER_NAME      "no name"
 
 // default value for undefined levelset
 #define UNDEFINED_LEVELSET     "[NONE]"
 
+// default value for undefined password
+#define UNDEFINED_PASSWORD     "[undefined]"
+
 // default value for undefined parameter
 #define ARG_DEFAULT            "[DEFAULT]"
 
 // default value for off-screen positions
 #define POS_OFFSCREEN          (-1000000)
 
-// definitions for game sub-directories
-#ifndef RO_GAME_DIR
-#define RO_GAME_DIR            "."
-#endif
-
-#ifndef RW_GAME_DIR
-#define RW_GAME_DIR            "."
+// definitions for game base path and sub-directories
+#ifndef BASE_PATH
+#define BASE_PATH              "."
 #endif
 
-#define RO_BASE_PATH           RO_GAME_DIR
-#define RW_BASE_PATH           RW_GAME_DIR
-
 // directory names
 #define GRAPHICS_DIRECTORY     "graphics"
 #define SOUNDS_DIRECTORY       "sounds"
 #define CACHE_DIRECTORY                "cache"
 #define CONF_DIRECTORY         "conf"
 #define NETWORK_DIRECTORY      "network"
+#define USERS_DIRECTORY                "users"
 
 #define GFX_CLASSIC_SUBDIR     "gfx_classic"
 #define SND_CLASSIC_SUBDIR     "snd_classic"
 // file names and filename extensions
 #define LEVELSETUP_DIRECTORY   "levelsetup"
 #define SETUP_FILENAME         "setup.conf"
+#define USERSETUP_FILENAME     "usersetup.conf"
 #define AUTOSETUP_FILENAME     "autosetup.conf"
 #define LEVELSETUP_FILENAME    "levelsetup.conf"
+#define SERVERSETUP_FILENAME   "serversetup.conf"
 #define EDITORSETUP_FILENAME   "editorsetup.conf"
 #define EDITORCASCADE_FILENAME "editorcascade.conf"
 #define HELPANIM_FILENAME      "helpanim.conf"
 #define TREE_TYPE_MUSIC_DIR    ARTWORK_TYPE_MUSIC
 #define TREE_TYPE_LEVEL_DIR    3
 #define TREE_TYPE_LEVEL_NR     4
+#define TREE_TYPE_PLAYER_NAME  5
 
 #define NUM_BASE_TREE_TYPES    4
-#define NUM_TREE_TYPES         5
+#define NUM_TREE_TYPES         6
+
+#define TREE_TYPE_IS_DIR(type) ((type) == TREE_TYPE_GRAPHICS_DIR ||    \
+                                (type) == TREE_TYPE_SOUNDS_DIR ||      \
+                                (type) == TREE_TYPE_MUSIC_DIR ||       \
+                                (type) == TREE_TYPE_LEVEL_DIR)
 
 #define INFOTEXT_UNDEFINED     ""
 #define INFOTEXT_GRAPHICS_DIR  "Custom Graphics"
 #define INFOTEXT_MUSIC_DIR     "Custom Music"
 #define INFOTEXT_LEVEL_DIR     "Level Sets"
 #define INFOTEXT_LEVEL_NR      "Levels"
+#define INFOTEXT_PLAYER_NAME   "Players & Teams"
+
+#define BACKLINK_TEXT_MAIN     ".. (main menu)"
+#define BACKLINK_TEXT_SETUP    ".. (setup menu)"
+#define BACKLINK_TEXT_PARENT   ".. (parent directory)"
 
-#define TREE_INFOTEXT(t)       ((t) == TREE_TYPE_LEVEL_NR ?            \
+#define TREE_INFOTEXT(t)       ((t) == TREE_TYPE_PLAYER_NAME ?         \
+                                INFOTEXT_PLAYER_NAME :                 \
+                                (t) == TREE_TYPE_LEVEL_NR ?            \
                                 INFOTEXT_LEVEL_NR :                    \
                                 (t) == TREE_TYPE_LEVEL_DIR ?           \
                                 INFOTEXT_LEVEL_DIR :                   \
                                 INFOTEXT_MUSIC_DIR :                   \
                                 INFOTEXT_UNDEFINED)
 
+#define TREE_BACKLINK_TEXT(t)  ((t) == TREE_TYPE_LEVEL_DIR ?           \
+                                BACKLINK_TEXT_MAIN :                   \
+                                BACKLINK_TEXT_SETUP)
+
 #define TREE_USERDIR(t)                ((t) == TREE_TYPE_LEVEL_DIR ?           \
                                 getUserLevelDir(NULL) :                \
                                 (t) == TREE_TYPE_GRAPHICS_DIR ?        \
                                 (artwork).snd_first :                  \
                                 (artwork).mus_first)
 
+#define ARTWORK_CURRENT_PTR(artwork, type)                             \
+                               ((type) == ARTWORK_TYPE_GRAPHICS ?      \
+                                &(artwork).gfx_current :               \
+                                (type) == ARTWORK_TYPE_SOUNDS ?        \
+                                &(artwork).snd_current :               \
+                                &(artwork).mus_current)
+
+#define ARTWORK_CURRENT(artwork, type)                                 \
+                               ((type) == ARTWORK_TYPE_GRAPHICS ?      \
+                                (artwork).gfx_current :                \
+                                (type) == ARTWORK_TYPE_SOUNDS ?        \
+                                (artwork).snd_current :                \
+                                (artwork).mus_current)
+
 #define ARTWORK_CURRENT_IDENTIFIER_PTR(artwork, type)                  \
                                ((type) == ARTWORK_TYPE_GRAPHICS ?      \
                                 &(artwork).gfx_current_identifier :    \
@@ -923,8 +1023,7 @@ struct ProgramInfo
   void (*exit_message_function)(char *, va_list);
   void (*exit_function)(int);
 
-  boolean global_scores;
-  boolean many_scores_per_name;
+  int api_thread_count;
 
   boolean headless;
 };
@@ -938,6 +1037,15 @@ struct NetworkInfo
   char *server_host;
   int server_port;
 
+  SDL_Thread *server_thread;
+  boolean is_server_thread;
+};
+
+struct RuntimeInfo
+{
+  boolean uses_touch_device;
+
+  boolean use_api_server;
 };
 
 struct OptionInfo
@@ -945,8 +1053,7 @@ struct OptionInfo
   char *server_host;
   int server_port;
 
-  char *ro_base_directory;
-  char *rw_base_directory;
+  char *base_directory;
   char *level_directory;
   char *graphics_directory;
   char *sounds_directory;
@@ -955,8 +1062,14 @@ struct OptionInfo
   char *conf_directory;
 
   char *execute_command;
+  char *tape_log_filename;
 
   char *special_flags;
+  char *debug_mode;
+
+  char *player_name;
+  char *identifier;
+  char *level_nr;
 
   boolean mytapes;
   boolean serveronly;
@@ -984,6 +1097,7 @@ struct VideoSystemInfo
   int screen_rendering_mode;
   int vsync_mode;
 
+  unsigned int frame_counter;
   unsigned int frame_delay;
   unsigned int frame_delay_value;
 
@@ -1095,6 +1209,9 @@ struct GfxInfo
   void (*draw_tile_cursor_function)(int);
 
   int cursor_mode;
+  int cursor_mode_override;
+  int cursor_mode_final;
+  int mouse_x, mouse_y;
 };
 
 struct TileCursorInfo
@@ -1108,6 +1225,8 @@ struct TileCursorInfo
   int target_x, target_y;      // tile cursor target screen position
 
   int sx, sy;                  // tile cursor screen start position
+
+  boolean xsn_debug;           // enable or disable XSN debugging
 };
 
 struct OverlayInfo
@@ -1201,6 +1320,8 @@ struct SetupEditorInfo
 
   boolean show_element_token;
 
+  boolean show_read_only_warning;
+
   boolean use_template_for_new_levels;
 };
 
@@ -1209,6 +1330,11 @@ struct SetupAutoSetupInfo
   int editor_zoom_tilesize;
 };
 
+struct SetupLevelSetupInfo
+{
+  char *last_level_series[MAX_LEVELDIR_HISTORY + 1];
+};
+
 struct SetupEditorCascadeInfo
 {
   boolean el_bd;
@@ -1258,6 +1384,7 @@ struct SetupShortcutInfo
 
 struct SetupSystemInfo
 {
+  char *sdl_renderdriver;
   char *sdl_videodriver;
   char *sdl_audiodriver;
   int audio_fragment_size;
@@ -1290,6 +1417,19 @@ struct SetupInternalInfo
 
   boolean choose_from_top_leveldir;
   boolean show_scaling_in_title;
+  boolean create_user_levelset;
+
+  boolean menu_game;
+  boolean menu_engines;
+  boolean menu_editor;
+  boolean menu_graphics;
+  boolean menu_sound;
+  boolean menu_artwork;
+  boolean menu_input;
+  boolean menu_touch;
+  boolean menu_shortcuts;
+  boolean menu_exit;
+  boolean menu_save_and_exit;
 };
 
 struct SetupDebugInfo
@@ -1299,11 +1439,16 @@ struct SetupDebugInfo
   boolean frame_delay_use_mod_key;
   boolean frame_delay_game_only;
   boolean show_frames_per_second;
+  int xsn_mode;
+  int xsn_percent;
 };
 
 struct SetupInfo
 {
   char *player_name;
+  char *player_uuid;
+
+  boolean multiple_users;
 
   boolean sound;
   boolean sound_loops;
@@ -1311,7 +1456,8 @@ struct SetupInfo
   boolean sound_simple;
   boolean toons;
   boolean scroll_delay;
-  boolean scroll_delay_value;
+  boolean forced_scroll_delay;
+  int scroll_delay_value;
   char *engine_snapshot_mode;
   int engine_snapshot_memory;
   boolean fade_screens;
@@ -1323,7 +1469,8 @@ struct SetupInfo
   boolean skip_levels;
   boolean increment_levels;
   boolean auto_play_next_level;
-  boolean skip_scores_after_game;
+  boolean count_score_after_game;
+  boolean show_scores_after_game;
   boolean time_limit;
   boolean fullscreen;
   int window_scaling_percent;
@@ -1333,14 +1480,20 @@ struct SetupInfo
   boolean ask_on_escape;
   boolean ask_on_escape_editor;
   boolean ask_on_game_over;
+  boolean ask_on_quit_game;
+  boolean ask_on_quit_program;
   boolean quick_switch;
   boolean input_on_focus;
   boolean prefer_aga_graphics;
+  boolean prefer_lowpass_sounds;
+  boolean prefer_extra_panel_items;
   boolean game_speed_extended;
   int game_frame_delay;
   boolean sp_show_border_elements;
   boolean small_game_graphics;
-  boolean show_snapshot_buttons;
+  boolean show_load_save_buttons;
+  boolean show_undo_redo_buttons;
+  char *scores_in_highscore_list;
 
   char *graphics_set;
   char *sounds_set;
@@ -1357,7 +1510,15 @@ struct SetupInfo
   int network_player_nr;
   char *network_server_hostname;
 
+  boolean use_api_server;
+  char *api_server_hostname;
+  char *api_server_password;
+  boolean ask_for_uploading_tapes;
+  boolean provide_uploading_tapes;
+
   struct SetupAutoSetupInfo auto_setup;
+  struct SetupLevelSetupInfo level_setup;
+
   struct SetupEditorInfo editor;
   struct SetupEditorCascadeInfo editor_cascade;
   struct SetupShortcutInfo shortcut;
@@ -1370,6 +1531,11 @@ struct SetupInfo
   struct OptionInfo options;
 };
 
+struct UserInfo
+{
+  int nr;
+};
+
 struct TreeInfo
 {
   struct TreeInfo **node_top;          // topmost node in tree
@@ -1404,6 +1570,8 @@ struct TreeInfo
   char *graphics_set_ecs; // special EMC custom graphics set (ECS graphics)
   char *graphics_set_aga; // special EMC custom graphics set (AGA graphics)
   char *graphics_set;  // optional custom graphics set (level tree only)
+  char *sounds_set_default; // default EMC custom sounds set
+  char *sounds_set_lowpass; // special EMC custom sounds set (lowpass filter)
   char *sounds_set;    // optional custom sounds set (level tree only)
   char *music_set;     // optional custom music set (level tree only)
   char *graphics_path; // path to optional custom graphics set (level only)
@@ -1424,12 +1592,15 @@ struct TreeInfo
 
   boolean level_group; // directory contains more level series directories
   boolean parent_link; // entry links back to parent directory
+  boolean is_copy;     // this entry is a copy of another entry in the tree
   boolean in_user_dir; // user defined levels are stored in home directory
   boolean user_defined;        // levels in user directory and marked as "private"
   boolean readonly;    // readonly levels can not be changed with editor
   boolean handicap;    // level set has no handicap when set to "false"
   boolean skip_levels; // levels can be skipped when set to "true"
 
+  boolean use_emc_tiles;// use (swapped) V5/V6 EMC tiles when set to "true"
+
   int color;           // color to use on selection screen for this level
   char *class_desc;    // description of level series class
   int handicap_level;  // number of the lowest unsolved level
@@ -1643,6 +1814,8 @@ struct TextPosInfo
   int tile_size;               // special case for list of network players
   int border_size;             // special case for list of preview players
   int vertical;                        // special case for list of preview players
+
+  boolean redefined;           // redefined by custom artwork
 };
 
 struct MouseActionInfo
@@ -1673,6 +1846,7 @@ struct LevelStats
 
 extern struct ProgramInfo      program;
 extern struct NetworkInfo      network;
+extern struct RuntimeInfo      runtime;
 extern struct OptionInfo       options;
 extern struct VideoSystemInfo  video;
 extern struct AudioSystemInfo  audio;
@@ -1683,6 +1857,7 @@ extern struct AnimInfo            anim;
 extern struct ArtworkInfo      artwork;
 extern struct JoystickInfo     joystick;
 extern struct SetupInfo                setup;
+extern struct UserInfo         user;
 
 extern LevelDirTree           *leveldir_first_all;
 extern LevelDirTree           *leveldir_first;
@@ -1700,6 +1875,7 @@ extern int                        button_status;
 extern boolean                 motion_status;
 extern int                     wheel_steps;
 extern boolean                 keyrepeat_status;
+extern boolean                 textinput_status;
 
 extern int                     redraw_mask;
 
@@ -1711,8 +1887,8 @@ extern int                        FrameCounter;
 void InitProgramInfo(char *, char *, char *, char *, char *, char *, char *,
                     char *, int);
 void InitNetworkInfo(boolean, boolean, boolean, char *, int);
+void InitRuntimeInfo(void);
 
-void InitScoresInfo(void);
 void SetWindowTitle(void);
 
 void InitWindowTitleFunction(char *(*window_title_function)(void));
@@ -1737,6 +1913,7 @@ void InitGfxCustomArtworkInfo(void);
 void InitGfxOtherSettings(void);
 void InitTileCursorInfo(void);
 void InitOverlayInfo(void);
+void SetOverlayGridSizeAndButtons(void);
 void SetTileCursorEnabled(boolean);
 void SetTileCursorActive(boolean);
 void SetTileCursorTargetXY(int, int);
@@ -1800,6 +1977,7 @@ Bitmap *LoadImage(char *);
 Bitmap *LoadCustomImage(char *);
 void ReloadCustomImage(Bitmap *, char *);
 
+Bitmap *ZoomBitmap(Bitmap *, int, int);
 void ReCreateGameTileSizeBitmap(Bitmap **);
 void CreateBitmapWithSmallBitmaps(Bitmap **, int, int);
 void CreateBitmapTextures(Bitmap **);
@@ -1807,14 +1985,18 @@ void FreeBitmapTextures(Bitmap **);
 void ScaleBitmap(Bitmap **, int);
 
 void SetMouseCursor(int);
+void UpdateRawMousePosition(int, int);
+void UpdateMousePosition(void);
 
 void OpenAudio(void);
 void CloseAudio(void);
 void SetAudioMode(boolean);
 
+void InitEventFilter(EventFilter);
 boolean PendingEvent(void);
 void WaitEvent(Event *event);
 void PeekEvent(Event *event);
+void PumpEvents(void);
 void CheckQuitEvent(void);
 Key GetEventKey(KeyEvent *, boolean);
 KeyMod HandleKeyModState(Key, int);
@@ -1822,11 +2004,14 @@ KeyMod GetKeyModState(void);
 KeyMod GetKeyModStateFromEvents(void);
 void StartTextInput(int, int, int, int);
 void StopTextInput(void);
-boolean CheckCloseWindowEvent(ClientMessageEvent *);
+void PushUserEvent(int, int, int);
 
 void InitJoysticks(void);
 boolean ReadJoystick(int, int *, int *, boolean *, boolean *);
 boolean CheckJoystickOpened(int);
 void ClearJoystickState(void);
 
+void InitEmscriptenFilesystem(void);
+void SyncEmscriptenFilesystem(void);
+
 #endif // SYSTEM_H