2021-08-23 21:18:25 +02:00
|
|
|
/*****************************************************************************
|
2023-01-01 11:58:01 +01:00
|
|
|
* Copyright (c) 2014-2023 OpenRCT2 developers
|
2018-06-15 14:07:34 +02:00
|
|
|
*
|
|
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
|
|
|
*
|
|
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
|
|
|
*****************************************************************************/
|
2017-03-24 03:47:43 +01:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2017-03-24 20:02:23 +01:00
|
|
|
#include "common.h"
|
2022-01-25 16:41:45 +01:00
|
|
|
#include "core/String.hpp"
|
2022-08-21 18:38:25 +02:00
|
|
|
#include "interface/WindowClasses.h"
|
2019-12-14 22:52:18 +01:00
|
|
|
#include "world/Location.hpp"
|
2017-10-19 10:01:05 +02:00
|
|
|
|
2018-04-20 20:58:59 +02:00
|
|
|
#include <memory>
|
2018-03-13 13:14:02 +01:00
|
|
|
#include <string>
|
|
|
|
|
2020-07-30 23:19:53 +02:00
|
|
|
struct IObjectManager;
|
|
|
|
struct IObjectRepository;
|
|
|
|
struct IScenarioRepository;
|
2020-10-03 03:41:30 +02:00
|
|
|
enum class DrawingEngine : int32_t;
|
2020-10-11 18:01:14 +02:00
|
|
|
enum class CursorID : uint8_t;
|
2020-10-03 03:41:30 +02:00
|
|
|
|
2020-07-30 23:01:22 +02:00
|
|
|
namespace OpenRCT2
|
|
|
|
{
|
2020-07-30 23:19:53 +02:00
|
|
|
struct IStream;
|
2020-07-30 23:01:22 +02:00
|
|
|
}
|
2020-07-30 23:19:53 +02:00
|
|
|
struct ITrackDesignRepository;
|
|
|
|
struct IGameStateSnapshots;
|
2018-04-10 14:19:23 +02:00
|
|
|
|
2017-10-19 10:01:05 +02:00
|
|
|
class Intent;
|
2018-02-14 09:42:26 +01:00
|
|
|
struct rct_window;
|
2020-07-21 23:22:48 +02:00
|
|
|
struct NewVersionInfo;
|
2017-06-11 16:16:47 +02:00
|
|
|
|
2022-02-18 21:57:00 +01:00
|
|
|
struct TTFFontDescriptor;
|
|
|
|
namespace OpenRCT2::Ui
|
|
|
|
{
|
|
|
|
struct FileDialogDesc;
|
|
|
|
}
|
|
|
|
|
2018-02-14 09:42:26 +01:00
|
|
|
struct CursorState
|
2017-03-25 18:42:14 +01:00
|
|
|
{
|
2019-12-15 03:30:55 +01:00
|
|
|
ScreenCoordsXY position;
|
2018-06-22 23:25:16 +02:00
|
|
|
uint8_t left, middle, right, any;
|
|
|
|
int32_t wheel;
|
|
|
|
int32_t old;
|
|
|
|
bool touch, touchIsDouble;
|
|
|
|
uint32_t touchDownTimestamp;
|
2018-02-14 09:42:26 +01:00
|
|
|
};
|
2017-03-25 18:42:14 +01:00
|
|
|
|
2018-02-14 09:42:26 +01:00
|
|
|
struct TextInputSession
|
2017-03-26 04:36:22 +02:00
|
|
|
{
|
2018-06-22 23:25:16 +02:00
|
|
|
utf8* Buffer; // UTF-8 stream
|
|
|
|
size_t BufferSize; // Maximum number of bytes (excluding null terminator)
|
|
|
|
size_t Size; // Number of bytes (excluding null terminator)
|
|
|
|
size_t Length; // Number of codepoints
|
|
|
|
size_t SelectionStart; // Selection start, in bytes
|
|
|
|
size_t SelectionSize; // Selection length in bytes
|
|
|
|
|
|
|
|
const utf8* ImeBuffer; // IME UTF-8 stream
|
2018-02-14 09:42:26 +01:00
|
|
|
};
|
2017-03-26 04:36:22 +02:00
|
|
|
|
|
|
|
struct Resolution
|
|
|
|
{
|
2018-06-20 17:28:51 +02:00
|
|
|
int32_t Width;
|
|
|
|
int32_t Height;
|
2017-03-26 04:36:22 +02:00
|
|
|
};
|
|
|
|
|
2017-03-25 18:42:14 +01:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
CURSOR_UP = 0,
|
|
|
|
CURSOR_DOWN = 1,
|
|
|
|
CURSOR_CHANGED = 2,
|
|
|
|
CURSOR_RELEASED = CURSOR_UP | CURSOR_CHANGED,
|
|
|
|
CURSOR_PRESSED = CURSOR_DOWN | CURSOR_CHANGED,
|
|
|
|
};
|
|
|
|
|
2021-08-17 05:20:07 +02:00
|
|
|
class NetworkBase;
|
|
|
|
|
2017-03-24 03:47:43 +01:00
|
|
|
namespace OpenRCT2
|
|
|
|
{
|
2022-09-18 17:15:42 +02:00
|
|
|
class AssetPackManager;
|
2018-05-30 13:50:25 +02:00
|
|
|
class GameState;
|
2018-12-06 06:34:27 +01:00
|
|
|
|
2020-07-30 23:19:53 +02:00
|
|
|
struct IPlatformEnvironment;
|
|
|
|
struct IReplayManager;
|
2017-06-11 13:53:37 +02:00
|
|
|
|
2017-03-28 20:58:15 +02:00
|
|
|
namespace Audio
|
|
|
|
{
|
2020-07-30 23:19:53 +02:00
|
|
|
struct IAudioContext;
|
2017-03-28 20:58:15 +02:00
|
|
|
}
|
|
|
|
|
2018-05-13 16:52:59 +02:00
|
|
|
namespace Drawing
|
|
|
|
{
|
2020-07-30 23:19:53 +02:00
|
|
|
struct IDrawingEngine;
|
2018-05-13 16:52:59 +02:00
|
|
|
}
|
|
|
|
|
2018-04-24 14:18:05 +02:00
|
|
|
namespace Localisation
|
|
|
|
{
|
|
|
|
class LocalisationService;
|
|
|
|
}
|
|
|
|
|
2018-03-17 20:31:06 +01:00
|
|
|
namespace Scripting
|
|
|
|
{
|
|
|
|
class ScriptEngine;
|
|
|
|
}
|
|
|
|
|
2017-03-25 04:16:40 +01:00
|
|
|
namespace Ui
|
2017-03-24 17:26:43 +01:00
|
|
|
{
|
2020-07-30 23:19:53 +02:00
|
|
|
struct IUiContext;
|
2017-03-24 17:26:43 +01:00
|
|
|
}
|
|
|
|
|
2019-02-19 16:03:08 +01:00
|
|
|
namespace Paint
|
|
|
|
{
|
2020-07-30 23:19:53 +02:00
|
|
|
struct Painter;
|
2019-02-19 16:03:08 +01:00
|
|
|
}
|
|
|
|
|
2017-03-24 03:47:43 +01:00
|
|
|
/**
|
|
|
|
* Represents an instance of OpenRCT2 and can be used to get various services.
|
|
|
|
*/
|
2020-07-30 23:19:53 +02:00
|
|
|
struct IContext
|
2017-03-24 03:47:43 +01:00
|
|
|
{
|
2017-03-24 17:26:43 +01:00
|
|
|
virtual ~IContext() = default;
|
2017-03-25 04:16:40 +01:00
|
|
|
|
2021-08-23 20:09:43 +02:00
|
|
|
[[nodiscard]] virtual std::shared_ptr<Audio::IAudioContext> GetAudioContext() abstract;
|
|
|
|
[[nodiscard]] virtual std::shared_ptr<Ui::IUiContext> GetUiContext() abstract;
|
2018-06-22 23:25:16 +02:00
|
|
|
virtual GameState* GetGameState() abstract;
|
2021-08-23 20:09:43 +02:00
|
|
|
[[nodiscard]] virtual std::shared_ptr<IPlatformEnvironment> GetPlatformEnvironment() abstract;
|
2018-04-27 19:38:59 +02:00
|
|
|
virtual Localisation::LocalisationService& GetLocalisationService() abstract;
|
2018-08-29 00:52:10 +02:00
|
|
|
virtual IObjectManager& GetObjectManager() abstract;
|
|
|
|
virtual IObjectRepository& GetObjectRepository() abstract;
|
2020-04-24 16:58:01 +02:00
|
|
|
#ifdef ENABLE_SCRIPTING
|
2018-03-17 20:31:06 +01:00
|
|
|
virtual Scripting::ScriptEngine& GetScriptEngine() abstract;
|
2020-02-23 13:55:48 +01:00
|
|
|
#endif
|
2018-06-22 23:25:16 +02:00
|
|
|
virtual ITrackDesignRepository* GetTrackDesignRepository() abstract;
|
|
|
|
virtual IScenarioRepository* GetScenarioRepository() abstract;
|
2018-12-06 06:34:27 +01:00
|
|
|
virtual IReplayManager* GetReplayManager() abstract;
|
2022-09-18 17:15:42 +02:00
|
|
|
virtual AssetPackManager* GetAssetPackManager() abstract;
|
2019-05-11 21:31:34 +02:00
|
|
|
virtual IGameStateSnapshots* GetGameStateSnapshots() abstract;
|
2020-10-03 03:41:30 +02:00
|
|
|
virtual DrawingEngine GetDrawingEngineType() abstract;
|
2018-06-22 23:25:16 +02:00
|
|
|
virtual Drawing::IDrawingEngine* GetDrawingEngine() abstract;
|
2019-02-19 16:03:08 +01:00
|
|
|
virtual Paint::Painter* GetPainter() abstract;
|
2021-08-17 05:20:07 +02:00
|
|
|
#ifndef DISABLE_NETWORK
|
|
|
|
virtual NetworkBase& GetNetwork() abstract;
|
|
|
|
#endif
|
2018-06-22 23:25:16 +02:00
|
|
|
virtual int32_t RunOpenRCT2(int argc, const char** argv) abstract;
|
2017-06-04 00:10:20 +02:00
|
|
|
|
|
|
|
virtual bool Initialise() abstract;
|
2018-05-13 16:52:59 +02:00
|
|
|
virtual void InitialiseDrawingEngine() abstract;
|
|
|
|
virtual void DisposeDrawingEngine() abstract;
|
2021-10-27 14:21:14 +02:00
|
|
|
virtual bool LoadParkFromFile(
|
|
|
|
const std::string& path, bool loadTitleScreenOnFail = false, bool asScenario = false) abstract;
|
2020-07-30 23:19:53 +02:00
|
|
|
virtual bool LoadParkFromStream(
|
2021-10-27 14:21:14 +02:00
|
|
|
IStream* stream, const std::string& path, bool loadTitleScreenFirstOnFail = false,
|
|
|
|
bool asScenario = false) abstract;
|
2018-06-22 23:25:16 +02:00
|
|
|
virtual void WriteLine(const std::string& s) abstract;
|
2021-02-13 01:15:27 +01:00
|
|
|
virtual void WriteErrorLine(const std::string& s) abstract;
|
2017-03-26 22:04:14 +02:00
|
|
|
virtual void Finish() abstract;
|
2017-07-28 19:43:48 +02:00
|
|
|
virtual void Quit() abstract;
|
2017-07-28 20:11:12 +02:00
|
|
|
|
2020-07-21 23:22:48 +02:00
|
|
|
virtual bool HasNewVersionInfo() const abstract;
|
|
|
|
virtual const NewVersionInfo* GetNewVersionInfo() const abstract;
|
2021-01-19 18:44:36 +01:00
|
|
|
|
|
|
|
virtual void SetTimeScale(float newScale) abstract;
|
|
|
|
virtual float GetTimeScale() const abstract;
|
2017-03-24 03:47:43 +01:00
|
|
|
};
|
|
|
|
|
2021-08-23 20:09:43 +02:00
|
|
|
[[nodiscard]] std::unique_ptr<IContext> CreateContext();
|
|
|
|
[[nodiscard]] std::unique_ptr<IContext> CreateContext(
|
2018-07-21 13:51:54 +02:00
|
|
|
const std::shared_ptr<IPlatformEnvironment>& env, const std::shared_ptr<Audio::IAudioContext>& audioContext,
|
2018-04-27 19:47:57 +02:00
|
|
|
const std::shared_ptr<Ui::IUiContext>& uiContext);
|
2021-08-23 20:09:43 +02:00
|
|
|
[[nodiscard]] IContext* GetContext();
|
2018-05-04 22:40:09 +02:00
|
|
|
} // namespace OpenRCT2
|
2017-07-16 09:54:34 +02:00
|
|
|
|
2021-12-02 16:28:59 +01:00
|
|
|
namespace
|
2017-07-16 09:54:34 +02:00
|
|
|
{
|
2017-07-02 01:04:32 +02:00
|
|
|
// The number of logical update / ticks per second.
|
2021-12-02 16:28:59 +01:00
|
|
|
constexpr uint32_t GAME_UPDATE_FPS = 40;
|
2017-07-16 09:54:34 +02:00
|
|
|
// The maximum amount of updates in case rendering is slower
|
2021-12-02 16:28:59 +01:00
|
|
|
constexpr uint32_t GAME_MAX_UPDATES = 4;
|
|
|
|
// The game update interval in milliseconds, (1000 / 40fps) = 25ms
|
|
|
|
constexpr float GAME_UPDATE_TIME_MS = 1.0f / GAME_UPDATE_FPS;
|
2017-07-16 09:54:34 +02:00
|
|
|
// The maximum threshold to advance.
|
2021-12-02 16:28:59 +01:00
|
|
|
constexpr float GAME_UPDATE_MAX_THRESHOLD = GAME_UPDATE_TIME_MS * GAME_MAX_UPDATES;
|
|
|
|
}; // namespace
|
2017-03-25 15:57:02 +01:00
|
|
|
|
2021-01-19 18:44:36 +01:00
|
|
|
constexpr float GAME_MIN_TIME_SCALE = 0.1f;
|
|
|
|
constexpr float GAME_MAX_TIME_SCALE = 5.0f;
|
|
|
|
|
2022-11-06 21:49:07 +01:00
|
|
|
void ContextInit();
|
|
|
|
void ContextSetCurrentCursor(CursorID cursor);
|
|
|
|
void ContextUpdateCursorScale();
|
|
|
|
void ContextHideCursor();
|
|
|
|
void ContextShowCursor();
|
|
|
|
ScreenCoordsXY ContextGetCursorPosition();
|
|
|
|
ScreenCoordsXY ContextGetCursorPositionScaled();
|
|
|
|
void ContextSetCursorPosition(const ScreenCoordsXY& cursorPosition);
|
|
|
|
const CursorState* ContextGetCursorState();
|
|
|
|
const uint8_t* ContextGetKeysState();
|
|
|
|
const uint8_t* ContextGetKeysPressed();
|
|
|
|
TextInputSession* ContextStartTextInput(utf8* buffer, size_t maxLength);
|
|
|
|
void ContextStopTextInput();
|
|
|
|
bool ContextIsInputActive();
|
|
|
|
void ContextTriggerResize();
|
|
|
|
void ContextSetFullscreenMode(int32_t mode);
|
|
|
|
void ContextRecreateWindow();
|
|
|
|
int32_t ContextGetWidth();
|
|
|
|
int32_t ContextGetHeight();
|
|
|
|
bool ContextHasFocus();
|
|
|
|
void ContextSetCursorTrap(bool value);
|
|
|
|
rct_window* ContextOpenWindow(WindowClass wc);
|
|
|
|
rct_window* ContextOpenDetailWindow(uint8_t type, int32_t id);
|
|
|
|
rct_window* ContextOpenWindowView(uint8_t view);
|
|
|
|
rct_window* ContextShowError(StringId title, StringId message, const class Formatter& args);
|
|
|
|
rct_window* ContextOpenIntent(Intent* intent);
|
|
|
|
void ContextBroadcastIntent(Intent* intent);
|
|
|
|
void ContextForceCloseWindowByClass(WindowClass wc);
|
|
|
|
void ContextUpdateMapTooltip();
|
|
|
|
void ContextHandleInput();
|
|
|
|
void ContextInputHandleKeyboard(bool isTitle);
|
|
|
|
void ContextQuit();
|
|
|
|
bool ContextLoadParkFromStream(void* stream);
|
2022-02-18 21:57:00 +01:00
|
|
|
bool ContextOpenCommonFileDialog(utf8* outFilename, OpenRCT2::Ui::FileDialogDesc& desc, size_t outSize);
|
2022-03-10 00:12:05 +01:00
|
|
|
u8string ContextOpenCommonFileDialog(OpenRCT2::Ui::FileDialogDesc& desc);
|