#pragma once #include "CoreParameters.hpp" #include "PostRunnables.hpp" #include "Time.hpp" #include "settings.hpp" #include "util/ObjectsKeeper.hpp" #include #include class Assets; class ContentControl; class EngineController; class EnginePaths; class Input; class Level; class ResPaths; class Screen; class SettingsHandler; class Window; class WindowControl; struct Project; namespace gui { class GUI; } namespace cmd { class CommandsInterpreter; } namespace network { class Network; } namespace devtools { class Editor; class DebuggingServer; } class initialize_error : public std::runtime_error { public: initialize_error(const std::string& message) : std::runtime_error(message) {} }; using OnWorldOpen = std::function, int64_t)>; class Engine : public util::ObjectsKeeper { CoreParameters params; EngineSettings settings; std::unique_ptr paths; std::unique_ptr project; std::unique_ptr settingsHandler; std::unique_ptr assets; std::shared_ptr screen; std::unique_ptr content; std::unique_ptr controller; std::unique_ptr cmd; std::unique_ptr network; std::unique_ptr window; std::unique_ptr input; std::unique_ptr gui; std::unique_ptr editor; std::unique_ptr debuggingServer; std::unique_ptr windowControl; PostRunnables postRunnables; Time time; OnWorldOpen levelConsumer; bool quitSignal = false; void loadControls(); void loadSettings(); void saveSettings(); void updateHotkeys(); void loadAssets(); void loadProject(); void initializeClient(); void onContentLoad(); public: Engine(); ~Engine(); static Engine& getInstance(); void initialize(CoreParameters coreParameters); void close(); static void terminate(); /// @brief Start the engine void run(); void postUpdate(); void applicationTick(); void updateFrontend(); void renderFrame(); void nextFrame(bool waitForRefresh); void startPauseLoop(); /// @brief Set screen (scene). /// nullptr may be used to delete previous screen before creating new one, /// not-null value must be set before next frame /// @param screen nullable screen void setScreen(std::shared_ptr screen); /// @brief Get active assets storage instance Assets* getAssets(); /// @brief Get writeable engine settings structure instance EngineSettings& getSettings(); /// @brief Get engine filesystem paths source EnginePaths& getPaths(); /// @brief Get engine resource paths controller ResPaths& getResPaths(); void onWorldOpen(std::unique_ptr level, int64_t localPlayer); void onWorldClosed(); void quit(); bool isQuitSignal() const; /// @brief Get current screen std::shared_ptr getScreen(); /// @brief Enqueue function call to the end of current frame in draw thread void postRunnable(const runnable& callback) { postRunnables.postRunnable(callback); } EngineController* getController(); void setLevelConsumer(OnWorldOpen levelConsumer); SettingsHandler& getSettingsHandler(); Time& getTime(); const CoreParameters& getCoreParameters() const; bool isHeadless() const; ContentControl& getContentControl(); gui::GUI& getGUI() { return *gui; } Input& getInput() { return *input; } Window& getWindow() { return *window; } network::Network* getNetwork() { return network.get(); } cmd::CommandsInterpreter& getCmd() { return *cmd; } devtools::Editor& getEditor() { return *editor; } const Project& getProject() { return *project; } devtools::DebuggingServer* getDebuggingServer() { return debuggingServer.get(); } void detachDebugger(); };