1 /***************************************************************************** 2 * Copyright (c) 2014-2020 OpenRCT2 developers 3 * 4 * For a complete list of all authors, please refer to contributors.md 5 * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 6 * 7 * OpenRCT2 is licensed under the GNU General Public License version 3. 8 *****************************************************************************/ 9 10 #pragma once 11 12 #include "common.h" 13 #include "world/Location.hpp" 14 15 #include <memory> 16 #include <string> 17 18 struct IObjectManager; 19 struct IObjectRepository; 20 struct IScenarioRepository; 21 enum class DrawingEngine : int32_t; 22 enum class CursorID : uint8_t; 23 24 namespace OpenRCT2 25 { 26 struct IStream; 27 } 28 struct ITrackDesignRepository; 29 struct IGameStateSnapshots; 30 31 class Intent; 32 struct rct_window; 33 using rct_windowclass = uint8_t; 34 struct NewVersionInfo; 35 36 struct CursorState 37 { 38 ScreenCoordsXY position; 39 uint8_t left, middle, right, any; 40 int32_t wheel; 41 int32_t old; 42 bool touch, touchIsDouble; 43 uint32_t touchDownTimestamp; 44 }; 45 46 struct TextInputSession 47 { 48 utf8* Buffer; // UTF-8 stream 49 size_t BufferSize; // Maximum number of bytes (excluding null terminator) 50 size_t Size; // Number of bytes (excluding null terminator) 51 size_t Length; // Number of codepoints 52 size_t SelectionStart; // Selection start, in bytes 53 size_t SelectionSize; // Selection length in bytes 54 55 const utf8* ImeBuffer; // IME UTF-8 stream 56 }; 57 58 struct Resolution 59 { 60 int32_t Width; 61 int32_t Height; 62 }; 63 64 enum 65 { 66 CURSOR_UP = 0, 67 CURSOR_DOWN = 1, 68 CURSOR_CHANGED = 2, 69 CURSOR_RELEASED = CURSOR_UP | CURSOR_CHANGED, 70 CURSOR_PRESSED = CURSOR_DOWN | CURSOR_CHANGED, 71 }; 72 73 class NetworkBase; 74 75 namespace OpenRCT2 76 { 77 class GameState; 78 79 struct IPlatformEnvironment; 80 struct IReplayManager; 81 82 namespace Audio 83 { 84 struct IAudioContext; 85 } 86 87 namespace Drawing 88 { 89 struct IDrawingEngine; 90 } 91 92 namespace Localisation 93 { 94 class LocalisationService; 95 } 96 97 namespace Scripting 98 { 99 class ScriptEngine; 100 } 101 102 namespace Ui 103 { 104 struct IUiContext; 105 } 106 107 namespace Paint 108 { 109 struct Painter; 110 } 111 112 /** 113 * Represents an instance of OpenRCT2 and can be used to get various services. 114 */ 115 struct IContext 116 { 117 virtual ~IContext() = default; 118 119 [[nodiscard]] virtual std::shared_ptr<Audio::IAudioContext> GetAudioContext() abstract; 120 [[nodiscard]] virtual std::shared_ptr<Ui::IUiContext> GetUiContext() abstract; 121 virtual GameState* GetGameState() abstract; 122 [[nodiscard]] virtual std::shared_ptr<IPlatformEnvironment> GetPlatformEnvironment() abstract; 123 virtual Localisation::LocalisationService& GetLocalisationService() abstract; 124 virtual IObjectManager& GetObjectManager() abstract; 125 virtual IObjectRepository& GetObjectRepository() abstract; 126 #ifdef ENABLE_SCRIPTING 127 virtual Scripting::ScriptEngine& GetScriptEngine() abstract; 128 #endif 129 virtual ITrackDesignRepository* GetTrackDesignRepository() abstract; 130 virtual IScenarioRepository* GetScenarioRepository() abstract; 131 virtual IReplayManager* GetReplayManager() abstract; 132 virtual IGameStateSnapshots* GetGameStateSnapshots() abstract; 133 virtual DrawingEngine GetDrawingEngineType() abstract; 134 virtual Drawing::IDrawingEngine* GetDrawingEngine() abstract; 135 virtual Paint::Painter* GetPainter() abstract; 136 #ifndef DISABLE_NETWORK 137 virtual NetworkBase& GetNetwork() abstract; 138 #endif 139 virtual int32_t RunOpenRCT2(int argc, const char** argv) abstract; 140 141 virtual bool Initialise() abstract; 142 virtual void InitialiseDrawingEngine() abstract; 143 virtual void DisposeDrawingEngine() abstract; 144 virtual bool LoadParkFromFile(const std::string& path, bool loadTitleScreenOnFail = false) abstract; 145 virtual bool LoadParkFromStream( 146 IStream* stream, const std::string& path, bool loadTitleScreenFirstOnFail = false) abstract; 147 virtual void WriteLine(const std::string& s) abstract; 148 virtual void WriteErrorLine(const std::string& s) abstract; 149 virtual void Finish() abstract; 150 virtual void Quit() abstract; 151 152 virtual bool HasNewVersionInfo() const abstract; 153 virtual const NewVersionInfo* GetNewVersionInfo() const abstract; 154 /** 155 * This is deprecated, use IPlatformEnvironment. 156 */ 157 virtual std::string GetPathLegacy(int32_t pathId) abstract; 158 159 virtual void SetTimeScale(float newScale) abstract; 160 virtual float GetTimeScale() const abstract; 161 }; 162 163 [[nodiscard]] std::unique_ptr<IContext> CreateContext(); 164 [[nodiscard]] std::unique_ptr<IContext> CreateContext( 165 const std::shared_ptr<IPlatformEnvironment>& env, const std::shared_ptr<Audio::IAudioContext>& audioContext, 166 const std::shared_ptr<Ui::IUiContext>& uiContext); 167 [[nodiscard]] IContext* GetContext(); 168 } // namespace OpenRCT2 169 170 enum 171 { 172 // The game update interval in milliseconds, (1000 / 40fps) = 25ms 173 GAME_UPDATE_TIME_MS = 25, 174 // The number of logical update / ticks per second. 175 GAME_UPDATE_FPS = 40, 176 // The maximum amount of updates in case rendering is slower 177 GAME_MAX_UPDATES = 4, 178 // The maximum threshold to advance. 179 GAME_UPDATE_MAX_THRESHOLD = GAME_UPDATE_TIME_MS * GAME_MAX_UPDATES, 180 }; 181 182 constexpr float GAME_MIN_TIME_SCALE = 0.1f; 183 constexpr float GAME_MAX_TIME_SCALE = 5.0f; 184 185 /** 186 * Legacy get_file_path IDs. 187 * Remove when context_get_path_legacy is removed. 188 */ 189 enum 190 { 191 PATH_ID_G1, 192 PATH_ID_PLUGIN, 193 PATH_ID_CSS1, 194 PATH_ID_CSS2, 195 PATH_ID_CSS4, 196 PATH_ID_CSS5, 197 PATH_ID_CSS6, 198 PATH_ID_CSS7, 199 PATH_ID_CSS8, 200 PATH_ID_CSS9, 201 PATH_ID_CSS11, 202 PATH_ID_CSS12, 203 PATH_ID_CSS13, 204 PATH_ID_CSS14, 205 PATH_ID_CSS15, 206 PATH_ID_CSS3, 207 PATH_ID_CSS17, 208 PATH_ID_CSS18, 209 PATH_ID_CSS19, 210 PATH_ID_CSS20, 211 PATH_ID_CSS21, 212 PATH_ID_CSS22, 213 PATH_ID_SCORES, 214 PATH_ID_CSS23, 215 PATH_ID_CSS24, 216 PATH_ID_CSS25, 217 PATH_ID_CSS26, 218 PATH_ID_CSS27, 219 PATH_ID_CSS28, 220 PATH_ID_CSS29, 221 PATH_ID_CSS30, 222 PATH_ID_CSS31, 223 PATH_ID_CSS32, 224 PATH_ID_CSS33, 225 PATH_ID_CSS34, 226 PATH_ID_CSS35, 227 PATH_ID_CSS36, 228 PATH_ID_CSS37, 229 PATH_ID_CSS38, 230 PATH_ID_CUSTOM1, 231 PATH_ID_CUSTOM2, 232 PATH_ID_CSS39, 233 PATH_ID_CSS40, 234 PATH_ID_CSS41, 235 PATH_ID_SIXFLAGS_MAGICMOUNTAIN, 236 PATH_ID_CSS42, 237 PATH_ID_CSS43, 238 PATH_ID_CSS44, 239 PATH_ID_CSS45, 240 PATH_ID_CSS46, 241 PATH_ID_CSS50, 242 PATH_ID_END, 243 }; 244 245 void context_init(); 246 void context_setcurrentcursor(CursorID cursor); 247 void context_update_cursor_scale(); 248 void context_hide_cursor(); 249 void context_show_cursor(); 250 ScreenCoordsXY context_get_cursor_position(); 251 ScreenCoordsXY context_get_cursor_position_scaled(); 252 void context_set_cursor_position(const ScreenCoordsXY& cursorPosition); 253 const CursorState* context_get_cursor_state(); 254 const uint8_t* context_get_keys_state(); 255 const uint8_t* context_get_keys_pressed(); 256 TextInputSession* context_start_text_input(utf8* buffer, size_t maxLength); 257 void context_stop_text_input(); 258 bool context_is_input_active(); 259 void context_trigger_resize(); 260 void context_set_fullscreen_mode(int32_t mode); 261 void context_recreate_window(); 262 int32_t context_get_width(); 263 int32_t context_get_height(); 264 bool context_has_focus(); 265 void context_set_cursor_trap(bool value); 266 rct_window* context_open_window(rct_windowclass wc); 267 rct_window* context_open_detail_window(uint8_t type, int32_t id); 268 rct_window* context_open_window_view(uint8_t view); 269 rct_window* context_show_error(rct_string_id title, rct_string_id message, const class Formatter& args); 270 rct_window* context_open_intent(Intent* intent); 271 void context_broadcast_intent(Intent* intent); 272 void context_force_close_window_by_class(rct_windowclass wc); 273 void context_update_map_tooltip(); 274 void context_handle_input(); 275 void context_input_handle_keyboard(bool isTitle); 276 void context_quit(); 277 const utf8* context_get_path_legacy(int32_t pathId); 278 bool context_load_park_from_file(const utf8* path); 279 bool context_load_park_from_stream(void* stream); 280