#pragma once #include "delegates.hpp" #include "typedefs.hpp" #include "settings.hpp" #include "content/content_fwd.hpp" #include "content/ContentPack.hpp" #include "content/PacksManager.hpp" #include "io/engine_paths.hpp" #include "io/settings_io.hpp" #include "util/ObjectsKeeper.hpp" #include "PostRunnables.hpp" #include "Time.hpp" #include #include #include class Assets; class Level; class Screen; class EnginePaths; class ResPaths; class EngineController; class SettingsHandler; struct EngineSettings; class Input; namespace gui { class GUI; } namespace cmd { class CommandsInterpreter; } namespace network { class Network; } class initialize_error : public std::runtime_error { public: initialize_error(const std::string& message) : std::runtime_error(message) {} }; struct CoreParameters { bool headless = false; bool testMode = false; std::filesystem::path resFolder = "res"; std::filesystem::path userFolder = "."; std::filesystem::path scriptFile; }; using OnWorldOpen = std::function, int64_t)>; class Engine : public util::ObjectsKeeper { CoreParameters params; EngineSettings settings; EnginePaths paths; std::unique_ptr settingsHandler; std::unique_ptr assets; std::shared_ptr screen; std::vector contentPacks; std::unique_ptr content; std::unique_ptr resPaths; std::unique_ptr controller; std::unique_ptr cmd; std::unique_ptr network; std::unique_ptr input; std::vector basePacks; std::unique_ptr gui; PostRunnables postRunnables; Time time; OnWorldOpen levelConsumer; bool quitSignal = false; void loadControls(); void loadSettings(); void saveSettings(); void updateHotkeys(); void loadAssets(); public: Engine(); ~Engine(); static Engine& getInstance(); void initialize(CoreParameters coreParameters); void close(); static void terminate(); /// @brief Start the engine void run(); void postUpdate(); void updateFrontend(); void renderFrame(); void nextFrame(); /// @brief Called after assets loading when all engine systems are initialized void onAssetsLoaded(); /// @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 Change locale to specified /// @param locale isolanguage_ISOCOUNTRY (example: en_US) void setLanguage(std::string locale); /// @brief Load all selected content-packs and reload assets void loadContent(); /// @brief Reset content to base packs list void resetContent(); /// @brief Collect world content-packs and load content /// @see loadContent /// @param folder world folder void loadWorldContent(const io::path& folder); /// @brief Collect all available content-packs from res/content void loadAllPacks(); /// @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 Content instance const Content* getContent() const; Content* getWriteableContent(); /// @brief Get selected content packs std::vector& getContentPacks(); std::vector getAllContentPacks(); std::vector& getBasePacks(); /// @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); } void saveScreenshot(); EngineController* getController(); PacksManager createPacksManager(const io::path& worldFolder); void setLevelConsumer(OnWorldOpen levelConsumer); SettingsHandler& getSettingsHandler(); Time& getTime(); const CoreParameters& getCoreParameters() const; bool isHeadless() const; gui::GUI& getGUI() { return *gui; } Input& getInput() { return *input; } network::Network& getNetwork() { return *network; } cmd::CommandsInterpreter& getCmd() { return *cmd; } };