OpenRCT2/src/openrct2/Context.h

239 lines
7.6 KiB
C
Raw Permalink Normal View History

/*****************************************************************************
* Copyright (c) 2014-2024 OpenRCT2 developers
*
* 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.
*****************************************************************************/
#pragma once
#include "common.h"
#include "core/String.hpp"
#include "interface/WindowClasses.h"
#include "world/Location.hpp"
#include <memory>
#include <string>
struct IObjectManager;
struct IObjectRepository;
struct IScenarioRepository;
enum class DrawingEngine : int32_t;
enum class CursorID : uint8_t;
namespace OpenRCT2
{
struct IStream;
}
struct ITrackDesignRepository;
struct IGameStateSnapshots;
class Intent;
struct WindowBase;
struct NewVersionInfo;
struct TTFFontDescriptor;
namespace OpenRCT2::Ui
{
struct FileDialogDesc;
}
struct CursorState
2017-03-25 18:42:14 +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;
};
2017-03-25 18:42:14 +01:00
struct TextInputSession
2017-03-26 04:36:22 +02:00
{
u8string* Buffer; // UTF-8 string buffer, non-owning.
2018-06-22 23:25:16 +02:00
size_t Length; // Number of codepoints
size_t MaxLength; // Maximum length of text, Length can't be larger than this.
2018-06-22 23:25:16 +02:00
size_t SelectionStart; // Selection start, in bytes
size_t SelectionSize; // Selection length in bytes
const utf8* ImeBuffer; // IME UTF-8 stream
};
2017-03-26 04:36:22 +02:00
struct Resolution
{
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;
namespace OpenRCT2
{
2022-09-18 17:15:42 +02:00
class AssetPackManager;
struct IPlatformEnvironment;
struct IReplayManager;
struct IScene;
2017-06-11 13:53:37 +02:00
2017-03-28 20:58:15 +02:00
namespace Audio
{
struct IAudioContext;
2017-03-28 20:58:15 +02:00
}
namespace Drawing
{
struct IDrawingEngine;
}
2018-04-24 14:18:05 +02:00
namespace Localisation
{
class LocalisationService;
}
namespace Scripting
{
class ScriptEngine;
}
namespace Ui
{
struct IUiContext;
}
2019-02-19 16:03:08 +01:00
namespace Paint
{
struct Painter;
2019-02-19 16:03:08 +01:00
}
/**
* Represents an instance of OpenRCT2 and can be used to get various services.
*/
struct IContext
{
virtual ~IContext() = default;
[[nodiscard]] virtual std::shared_ptr<Audio::IAudioContext> GetAudioContext() abstract;
[[nodiscard]] virtual std::shared_ptr<Ui::IUiContext> GetUiContext() abstract;
[[nodiscard]] virtual std::shared_ptr<IPlatformEnvironment> GetPlatformEnvironment() abstract;
virtual Localisation::LocalisationService& GetLocalisationService() abstract;
virtual IObjectManager& GetObjectManager() abstract;
virtual IObjectRepository& GetObjectRepository() abstract;
#ifdef ENABLE_SCRIPTING
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;
virtual IReplayManager* GetReplayManager() abstract;
2022-09-18 17:15:42 +02:00
virtual AssetPackManager* GetAssetPackManager() abstract;
virtual IGameStateSnapshots* GetGameStateSnapshots() abstract;
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
virtual IScene* GetPreloaderScene() abstract;
virtual IScene* GetIntroScene() abstract;
virtual IScene* GetTitleScene() abstract;
virtual IScene* GetGameScene() abstract;
virtual IScene* GetEditorScene() abstract;
virtual IScene* GetActiveScene() abstract;
virtual void SetActiveScene(IScene* screen) abstract;
2018-06-22 23:25:16 +02:00
virtual int32_t RunOpenRCT2(int argc, const char** argv) abstract;
virtual bool Initialise() abstract;
virtual void InitialiseDrawingEngine() abstract;
virtual void DisposeDrawingEngine() abstract;
virtual void OpenProgress(StringId captionStringId) abstract;
virtual void SetProgress(uint32_t currentProgress, uint32_t totalCount, StringId format = STR_NONE) abstract;
virtual void CloseProgress() abstract;
virtual bool LoadParkFromFile(
const u8string& path, bool loadTitleScreenOnFail = false, bool asScenario = false) abstract;
virtual bool LoadParkFromStream(
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;
virtual void Finish() abstract;
2017-07-28 19:43:48 +02:00
virtual void Quit() abstract;
virtual bool HasNewVersionInfo() const abstract;
virtual const NewVersionInfo* GetNewVersionInfo() const abstract;
virtual void SetTimeScale(float newScale) abstract;
virtual float GetTimeScale() const abstract;
};
[[nodiscard]] std::unique_ptr<IContext> CreateContext();
[[nodiscard]] std::unique_ptr<IContext> CreateContext(
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);
[[nodiscard]] IContext* GetContext();
2018-05-04 22:40:09 +02:00
} // namespace OpenRCT2
namespace
{
// The number of logical update / ticks per second.
constexpr uint32_t kGameUpdateFPS = 40;
// The maximum amount of updates in case rendering is slower
constexpr uint32_t kGameMaxUpdates = 4;
// The game update interval in milliseconds, (1000 / 40fps) = 25ms
constexpr float kGameUpdateTimeMS = 1.0f / kGameUpdateFPS;
// The maximum threshold to advance.
constexpr float kGameUpdateMaxThreshold = kGameUpdateTimeMS * kGameMaxUpdates;
}; // namespace
constexpr float kGameMinTimeScale = 0.1f;
constexpr float kGameMaxTimeScale = 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(u8string& buffer, size_t maxLength);
2022-11-06 21:49:07 +01:00
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);
WindowBase* ContextOpenWindow(WindowClass wc);
WindowBase* ContextOpenDetailWindow(uint8_t type, int32_t id);
WindowBase* ContextOpenWindowView(uint8_t view);
WindowBase* ContextShowError(StringId title, StringId message, const class Formatter& args, bool autoClose = false);
WindowBase* ContextOpenIntent(Intent* intent);
2022-11-06 21:49:07 +01:00
void ContextBroadcastIntent(Intent* intent);
void ContextForceCloseWindowByClass(WindowClass wc);
void ContextHandleInput();
void ContextInputHandleKeyboard(bool isTitle);
void ContextQuit();
bool ContextLoadParkFromStream(void* stream);
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);