refactor: move and rename EnginePaths

This commit is contained in:
MihailRis 2025-11-09 20:13:59 +03:00
parent 3b583d4dd6
commit 17ffa73ce7
30 changed files with 57 additions and 63 deletions

View File

@ -9,7 +9,7 @@
#include "content/Content.hpp" #include "content/Content.hpp"
#include "content/ContentPack.hpp" #include "content/ContentPack.hpp"
#include "debug/Logger.hpp" #include "debug/Logger.hpp"
#include "io/engine_paths.hpp" #include "engine/EnginePaths.hpp"
#include "io/io.hpp" #include "io/io.hpp"
#include "graphics/core/Texture.hpp" #include "graphics/core/Texture.hpp"
#include "logic/scripting/scripting.hpp" #include "logic/scripting/scripting.hpp"

View File

@ -15,7 +15,7 @@
#include "coders/vec3.hpp" #include "coders/vec3.hpp"
#include "constants.hpp" #include "constants.hpp"
#include "debug/Logger.hpp" #include "debug/Logger.hpp"
#include "io/engine_paths.hpp" #include "engine/EnginePaths.hpp"
#include "io/io.hpp" #include "io/io.hpp"
#include "frontend/UiDocument.hpp" #include "frontend/UiDocument.hpp"
#include "graphics/core/Atlas.hpp" #include "graphics/core/Atlas.hpp"

View File

@ -6,7 +6,7 @@
#include <utility> #include <utility>
#include "debug/Logger.hpp" #include "debug/Logger.hpp"
#include "io/engine_paths.hpp" #include "engine/EnginePaths.hpp"
#include "typedefs.hpp" #include "typedefs.hpp"
#include "util/stringutil.hpp" #include "util/stringutil.hpp"
#include "coders/json.hpp" #include "coders/json.hpp"

View File

@ -1,7 +1,7 @@
#include "ContentControl.hpp" #include "ContentControl.hpp"
#include "io/io.hpp" #include "io/io.hpp"
#include "io/engine_paths.hpp" #include "engine/EnginePaths.hpp"
#include "Content.hpp" #include "Content.hpp"
#include "ContentPack.hpp" #include "ContentPack.hpp"
#include "ContentBuilder.hpp" #include "ContentBuilder.hpp"

View File

@ -13,7 +13,7 @@
#include "objects/rigging.hpp" #include "objects/rigging.hpp"
#include "util/listutil.hpp" #include "util/listutil.hpp"
#include "util/stringutil.hpp" #include "util/stringutil.hpp"
#include "io/engine_paths.hpp" #include "engine/EnginePaths.hpp"
static debug::Logger logger("content-loader"); static debug::Logger logger("content-loader");

View File

@ -8,7 +8,7 @@
#include "coders/json.hpp" #include "coders/json.hpp"
#include "constants.hpp" #include "constants.hpp"
#include "data/dv.hpp" #include "data/dv.hpp"
#include "io/engine_paths.hpp" #include "engine/EnginePaths.hpp"
#include "io/io.hpp" #include "io/io.hpp"
#include "coders/commons.hpp" #include "coders/commons.hpp"
#include "debug/Logger.hpp" #include "debug/Logger.hpp"

View File

@ -6,7 +6,7 @@
#include "../ContentPack.hpp" #include "../ContentPack.hpp"
#include "io/io.hpp" #include "io/io.hpp"
#include "io/engine_paths.hpp" #include "engine/EnginePaths.hpp"
#include "logic/scripting/scripting.hpp" #include "logic/scripting/scripting.hpp"
#include "util/stringutil.hpp" #include "util/stringutil.hpp"
#include "world/generator/GeneratorDef.hpp" #include "world/generator/GeneratorDef.hpp"

View File

@ -4,7 +4,7 @@
#include "content/Content.hpp" #include "content/Content.hpp"
#include "content/ContentBuilder.hpp" #include "content/ContentBuilder.hpp"
#include "io/io.hpp" #include "io/io.hpp"
#include "io/engine_paths.hpp" #include "engine/EnginePaths.hpp"
#include "window/input.hpp" #include "window/input.hpp"
#include "voxels/Block.hpp" #include "voxels/Block.hpp"
#include "coders/toml.hpp" #include "coders/toml.hpp"

View File

@ -1,7 +1,7 @@
#include "Editor.hpp" #include "Editor.hpp"
#include "engine/Engine.hpp" #include "engine/Engine.hpp"
#include "io/engine_paths.hpp" #include "engine/EnginePaths.hpp"
#include "coders/syntax_parser.hpp" #include "coders/syntax_parser.hpp"
#include "SyntaxProcessor.hpp" #include "SyntaxProcessor.hpp"

View File

@ -37,6 +37,7 @@
#include "Mainloop.hpp" #include "Mainloop.hpp"
#include "ServerMainloop.hpp" #include "ServerMainloop.hpp"
#include "WindowControl.hpp" #include "WindowControl.hpp"
#include "EnginePaths.hpp"
#include <iostream> #include <iostream>
#include <assert.h> #include <assert.h>
@ -61,7 +62,7 @@ Engine& Engine::getInstance() {
void Engine::onContentLoad() { void Engine::onContentLoad() {
editor->loadTools(); editor->loadTools();
langs::setup(langs::get_current(), paths.resPaths.collectRoots()); langs::setup(langs::get_current(), paths->resPaths.collectRoots());
if (isHeadless()) { if (isHeadless()) {
return; return;
@ -130,7 +131,7 @@ void Engine::initialize(CoreParameters coreParameters) {
if (params.projectFolder.empty()) { if (params.projectFolder.empty()) {
params.projectFolder = params.resFolder; params.projectFolder = params.resFolder;
} }
paths.prepare(params); paths = std::make_unique<EnginePaths>(params);
loadProject(); loadProject();
editor = std::make_unique<devtools::Editor>(*this); editor = std::make_unique<devtools::Editor>(*this);
@ -161,7 +162,7 @@ void Engine::initialize(CoreParameters coreParameters) {
langs::locale_by_envlocale(platform::detect_locale()) langs::locale_by_envlocale(platform::detect_locale())
); );
} }
content = std::make_unique<ContentControl>(*project, paths, *input, [this]() { content = std::make_unique<ContentControl>(*project, *paths, *input, [this]() {
onContentLoad(); onContentLoad();
}); });
scripting::initialize(this); scripting::initialize(this);
@ -170,7 +171,7 @@ void Engine::initialize(CoreParameters coreParameters) {
gui->setPageLoader(scripting::create_page_loader()); gui->setPageLoader(scripting::create_page_loader());
} }
keepAlive(settings.ui.language.observe([this](auto lang) { keepAlive(settings.ui.language.observe([this](auto lang) {
langs::setup(lang, paths.resPaths.collectRoots()); langs::setup(lang, paths->resPaths.collectRoots());
}, true)); }, true));
project->loadProjectStartScript(); project->loadProjectStartScript();
@ -345,12 +346,12 @@ void Engine::setLevelConsumer(OnWorldOpen levelConsumer) {
void Engine::loadAssets() { void Engine::loadAssets() {
logger.info() << "loading assets"; logger.info() << "loading assets";
Shader::preprocessor->setPaths(&paths.resPaths); Shader::preprocessor->setPaths(&paths->resPaths);
auto content = this->content->get(); auto content = this->content->get();
auto new_assets = std::make_unique<Assets>(); auto new_assets = std::make_unique<Assets>();
AssetsLoader loader(*this, *new_assets, paths.resPaths); AssetsLoader loader(*this, *new_assets, paths->resPaths);
AssetsLoader::addDefaults(loader, content); AssetsLoader::addDefaults(loader, content);
// no need // no need
@ -426,11 +427,11 @@ Assets* Engine::getAssets() {
} }
EnginePaths& Engine::getPaths() { EnginePaths& Engine::getPaths() {
return paths; return *paths;
} }
ResPaths& Engine::getResPaths() { ResPaths& Engine::getResPaths() {
return paths.resPaths; return paths->resPaths;
} }
std::shared_ptr<Screen> Engine::getScreen() { std::shared_ptr<Screen> Engine::getScreen() {

View File

@ -4,7 +4,6 @@
#include "PostRunnables.hpp" #include "PostRunnables.hpp"
#include "Time.hpp" #include "Time.hpp"
#include "delegates.hpp" #include "delegates.hpp"
#include "io/engine_paths.hpp"
#include "settings.hpp" #include "settings.hpp"
#include "typedefs.hpp" #include "typedefs.hpp"
#include "util/ObjectsKeeper.hpp" #include "util/ObjectsKeeper.hpp"
@ -15,8 +14,10 @@
class Assets; class Assets;
class ContentControl; class ContentControl;
class EngineController; class EngineController;
class EnginePaths;
class Input; class Input;
class Level; class Level;
class ResPaths;
class Screen; class Screen;
class SettingsHandler; class SettingsHandler;
class Window; class Window;
@ -50,8 +51,7 @@ using OnWorldOpen = std::function<void(std::unique_ptr<Level>, int64_t)>;
class Engine : public util::ObjectsKeeper { class Engine : public util::ObjectsKeeper {
CoreParameters params; CoreParameters params;
EngineSettings settings; EngineSettings settings;
EnginePaths paths; std::unique_ptr<EnginePaths> paths;
std::unique_ptr<Project> project; std::unique_ptr<Project> project;
std::unique_ptr<SettingsHandler> settingsHandler; std::unique_ptr<SettingsHandler> settingsHandler;
std::unique_ptr<Assets> assets; std::unique_ptr<Assets> assets;

View File

@ -1,4 +1,4 @@
#include "engine_paths.hpp" #include "EnginePaths.hpp"
#include "debug/Logger.hpp" #include "debug/Logger.hpp"
#include "io/devices/StdfsDevice.hpp" #include "io/devices/StdfsDevice.hpp"
@ -39,10 +39,10 @@ static std::string generate_random_base64() {
return util::base64_urlsafe_encode(bytes, n); return util::base64_urlsafe_encode(bytes, n);
} }
void EnginePaths::prepare(CoreParameters& params) { EnginePaths::EnginePaths(CoreParameters& params)
resourcesFolder = params.resFolder; : resourcesFolder(params.resFolder),
userFilesFolder = params.userFolder; userFilesFolder(params.userFolder),
projectFolder = params.projectFolder; projectFolder(params.projectFolder) {
if (!params.scriptFile.empty()) { if (!params.scriptFile.empty()) {
scriptFolder = params.scriptFile.parent_path(); scriptFolder = params.scriptFile.parent_path();
io::set_device("script", std::make_shared<io::StdfsDevice>(*scriptFolder)); io::set_device("script", std::make_shared<io::StdfsDevice>(*scriptFolder));
@ -71,14 +71,6 @@ void EnginePaths::prepare(CoreParameters& params) {
io::create_subdevice("config", "user", "config"); io::create_subdevice("config", "user", "config");
} }
const fs::path& EnginePaths::getUserFilesFolder() const {
return userFilesFolder;
}
const fs::path& EnginePaths::getResourcesFolder() const {
return resourcesFolder;
}
io::path EnginePaths::getNewScreenshotFile(const std::string& ext) const { io::path EnginePaths::getNewScreenshotFile(const std::string& ext) const {
auto folder = SCREENSHOTS_FOLDER; auto folder = SCREENSHOTS_FOLDER;
if (!io::is_directory(folder)) { if (!io::is_directory(folder)) {
@ -107,10 +99,6 @@ io::path EnginePaths::getWorldsFolder() const {
return WORLDS_FOLDER; return WORLDS_FOLDER;
} }
io::path EnginePaths::getCurrentWorldFolder() {
return currentWorldFolder;
}
io::path EnginePaths::getWorldFolderByName(const std::string& name) { io::path EnginePaths::getWorldFolderByName(const std::string& name) {
return getWorldsFolder() / name; return getWorldsFolder() / name;
} }

View File

@ -1,8 +1,8 @@
#pragma once #pragma once
#include "io.hpp" #include "io/io.hpp"
#include "data/dv.hpp" #include "data/dv.hpp"
#include "engine/CoreParameters.hpp" #include "CoreParameters.hpp"
#include <unordered_map> #include <unordered_map>
#include <optional> #include <optional>
@ -46,16 +46,12 @@ class EnginePaths {
public: public:
ResPaths resPaths; ResPaths resPaths;
void prepare(CoreParameters& params); EnginePaths(CoreParameters& params);
const std::filesystem::path& getUserFilesFolder() const;
const std::filesystem::path& getResourcesFolder() const;
io::path getWorldFolderByName(const std::string& name); io::path getWorldFolderByName(const std::string& name);
io::path getWorldsFolder() const; io::path getWorldsFolder() const;
void setCurrentWorldFolder(io::path folder); void setCurrentWorldFolder(io::path folder);
io::path getCurrentWorldFolder();
io::path getNewScreenshotFile(const std::string& ext) const; io::path getNewScreenshotFile(const std::string& ext) const;
std::string mount(const io::path& file); std::string mount(const io::path& file);
@ -73,9 +69,9 @@ public:
static inline io::path CONTROLS_FILE = "user:controls.toml"; static inline io::path CONTROLS_FILE = "user:controls.toml";
static inline io::path SETTINGS_FILE = "user:settings.toml"; static inline io::path SETTINGS_FILE = "user:settings.toml";
private: private:
std::filesystem::path userFilesFolder {"."}; std::filesystem::path resourcesFolder;
std::filesystem::path resourcesFolder {"res"}; std::filesystem::path userFilesFolder;
std::filesystem::path projectFolder = resourcesFolder; std::filesystem::path projectFolder;
io::path currentWorldFolder; io::path currentWorldFolder;
std::optional<std::filesystem::path> scriptFolder; std::optional<std::filesystem::path> scriptFolder;
std::vector<PathsRoot> entryPoints; std::vector<PathsRoot> entryPoints;

View File

@ -1,6 +1,7 @@
#include "ServerMainloop.hpp" #include "ServerMainloop.hpp"
#include "Engine.hpp" #include "Engine.hpp"
#include "EnginePaths.hpp"
#include "logic/scripting/scripting.hpp" #include "logic/scripting/scripting.hpp"
#include "logic/LevelController.hpp" #include "logic/LevelController.hpp"
#include "interfaces/Process.hpp" #include "interfaces/Process.hpp"

View File

@ -1,6 +1,7 @@
#include "WindowControl.hpp" #include "WindowControl.hpp"
#include "Engine.hpp" #include "Engine.hpp"
#include "engine/EnginePaths.hpp"
#include "devtools/Project.hpp" #include "devtools/Project.hpp"
#include "coders/imageio.hpp" #include "coders/imageio.hpp"
#include "window/Window.hpp" #include "window/Window.hpp"

View File

@ -11,7 +11,7 @@
#include "graphics/ui/elements/Menu.hpp" #include "graphics/ui/elements/Menu.hpp"
#include "graphics/ui/gui_util.hpp" #include "graphics/ui/gui_util.hpp"
#include "interfaces/Task.hpp" #include "interfaces/Task.hpp"
#include "io/engine_paths.hpp" #include "engine/EnginePaths.hpp"
#include "locale.hpp" #include "locale.hpp"
#include "logic/scripting/scripting.hpp" #include "logic/scripting/scripting.hpp"
#include "screens/MenuScreen.hpp" #include "screens/MenuScreen.hpp"

View File

@ -6,6 +6,7 @@
#include "core_defs.hpp" #include "core_defs.hpp"
#include "debug/Logger.hpp" #include "debug/Logger.hpp"
#include "engine/Engine.hpp" #include "engine/Engine.hpp"
#include "engine/EnginePaths.hpp"
#include "assets/Assets.hpp" #include "assets/Assets.hpp"
#include "frontend/ContentGfxCache.hpp" #include "frontend/ContentGfxCache.hpp"
#include "frontend/LevelFrontend.hpp" #include "frontend/LevelFrontend.hpp"

View File

@ -19,6 +19,7 @@
#include "logic/LevelController.hpp" #include "logic/LevelController.hpp"
#include "util/stringutil.hpp" #include "util/stringutil.hpp"
#include "engine/Engine.hpp" #include "engine/Engine.hpp"
#include "engine/EnginePaths.hpp"
#include "io/io.hpp" #include "io/io.hpp"
#include "audio/audio.hpp" #include "audio/audio.hpp"
#include "maths/util.hpp" #include "maths/util.hpp"

View File

@ -4,28 +4,29 @@
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
#include "engine/Engine.hpp"
#include "coders/commons.hpp" #include "coders/commons.hpp"
#include "debug/Logger.hpp"
#include "coders/json.hpp" #include "coders/json.hpp"
#include "content/ContentReport.hpp"
#include "content/ContentControl.hpp" #include "content/ContentControl.hpp"
#include "content/ContentReport.hpp"
#include "content/PacksManager.hpp" #include "content/PacksManager.hpp"
#include "world/files/WorldConverter.hpp" #include "debug/Logger.hpp"
#include "world/files/WorldFiles.hpp" #include "engine/Engine.hpp"
#include "engine/EnginePaths.hpp"
#include "frontend/locale.hpp" #include "frontend/locale.hpp"
#include "frontend/menu.hpp" #include "frontend/menu.hpp"
#include "frontend/screens/LevelScreen.hpp" #include "frontend/screens/LevelScreen.hpp"
#include "frontend/screens/MenuScreen.hpp" #include "frontend/screens/MenuScreen.hpp"
#include "graphics/ui/GUI.hpp"
#include "graphics/ui/elements/Menu.hpp" #include "graphics/ui/elements/Menu.hpp"
#include "graphics/ui/gui_util.hpp" #include "graphics/ui/gui_util.hpp"
#include "objects/Players.hpp" #include "graphics/ui/GUI.hpp"
#include "interfaces/Task.hpp" #include "interfaces/Task.hpp"
#include "LevelController.hpp"
#include "objects/Players.hpp"
#include "util/stringutil.hpp" #include "util/stringutil.hpp"
#include "world/files/WorldConverter.hpp"
#include "world/files/WorldFiles.hpp"
#include "world/Level.hpp" #include "world/Level.hpp"
#include "world/World.hpp" #include "world/World.hpp"
#include "LevelController.hpp"
static debug::Logger logger("engine-control"); static debug::Logger logger("engine-control");

View File

@ -1,6 +1,7 @@
#include "audio/audio.hpp" #include "audio/audio.hpp"
#include "assets/Assets.hpp" #include "assets/Assets.hpp"
#include "engine/Engine.hpp" #include "engine/Engine.hpp"
#include "engine/EnginePaths.hpp"
#include "api_lua.hpp" #include "api_lua.hpp"
inline const char* DEFAULT_CHANNEL = "regular"; inline const char* DEFAULT_CHANNEL = "regular";

View File

@ -8,7 +8,7 @@
#include "content/Content.hpp" #include "content/Content.hpp"
#include "content/ContentControl.hpp" #include "content/ContentControl.hpp"
#include "engine/Engine.hpp" #include "engine/Engine.hpp"
#include "io/engine_paths.hpp" #include "engine/EnginePaths.hpp"
#include "io/io.hpp" #include "io/io.hpp"
#include "io/settings_io.hpp" #include "io/settings_io.hpp"
#include "frontend/menu.hpp" #include "frontend/menu.hpp"

View File

@ -2,6 +2,7 @@
#include "content/Content.hpp" #include "content/Content.hpp"
#include "engine/Engine.hpp" #include "engine/Engine.hpp"
#include "engine/EnginePaths.hpp"
#include "objects/Entities.hpp" #include "objects/Entities.hpp"
#include "objects/EntityDef.hpp" #include "objects/EntityDef.hpp"
#include "objects/Entity.hpp" #include "objects/Entity.hpp"

View File

@ -3,7 +3,7 @@
#include "coders/gzip.hpp" #include "coders/gzip.hpp"
#include "engine/Engine.hpp" #include "engine/Engine.hpp"
#include "io/engine_paths.hpp" #include "engine/EnginePaths.hpp"
#include "io/io.hpp" #include "io/io.hpp"
#include "io/devices/ZipFileDevice.hpp" #include "io/devices/ZipFileDevice.hpp"
#include "util/stringutil.hpp" #include "util/stringutil.hpp"

View File

@ -9,6 +9,7 @@
#include "content/Content.hpp" #include "content/Content.hpp"
#include "content/ContentControl.hpp" #include "content/ContentControl.hpp"
#include "engine/Engine.hpp" #include "engine/Engine.hpp"
#include "engine/EnginePaths.hpp"
#include "../lua_custom_types.hpp" #include "../lua_custom_types.hpp"
using namespace scripting; using namespace scripting;

View File

@ -10,7 +10,7 @@
#include "graphics/ui/elements/Menu.hpp" #include "graphics/ui/elements/Menu.hpp"
#include "frontend/locale.hpp" #include "frontend/locale.hpp"
#include "world/files/WorldFiles.hpp" #include "world/files/WorldFiles.hpp"
#include "io/engine_paths.hpp" #include "engine/EnginePaths.hpp"
#include "world/Level.hpp" #include "world/Level.hpp"
#include "world/World.hpp" #include "world/World.hpp"
#include "api_lua.hpp" #include "api_lua.hpp"

View File

@ -10,7 +10,7 @@
#include "content/ContentControl.hpp" #include "content/ContentControl.hpp"
#include "engine/Engine.hpp" #include "engine/Engine.hpp"
#include "world/files/WorldFiles.hpp" #include "world/files/WorldFiles.hpp"
#include "io/engine_paths.hpp" #include "engine/EnginePaths.hpp"
#include "io/io.hpp" #include "io/io.hpp"
#include "lighting/Lighting.hpp" #include "lighting/Lighting.hpp"
#include "voxels/Chunk.hpp" #include "voxels/Chunk.hpp"

View File

@ -4,7 +4,7 @@
#include <iostream> #include <iostream>
#include "io/io.hpp" #include "io/io.hpp"
#include "io/engine_paths.hpp" #include "engine/EnginePaths.hpp"
#include "debug/Logger.hpp" #include "debug/Logger.hpp"
#include "util/stringutil.hpp" #include "util/stringutil.hpp"
#include "libs/api_lua.hpp" #include "libs/api_lua.hpp"

View File

@ -13,6 +13,7 @@
#include "graphics/core/ImageData.hpp" #include "graphics/core/ImageData.hpp"
#include "maths/Heightmap.hpp" #include "maths/Heightmap.hpp"
#include "engine/Engine.hpp" #include "engine/Engine.hpp"
#include "engine/EnginePaths.hpp"
#include "../lua_util.hpp" #include "../lua_util.hpp"
using namespace lua; using namespace lua;

View File

@ -9,7 +9,7 @@
#include "content/ContentControl.hpp" #include "content/ContentControl.hpp"
#include "debug/Logger.hpp" #include "debug/Logger.hpp"
#include "engine/Engine.hpp" #include "engine/Engine.hpp"
#include "io/engine_paths.hpp" #include "engine/EnginePaths.hpp"
#include "io/io.hpp" #include "io/io.hpp"
#include "frontend/UiDocument.hpp" #include "frontend/UiDocument.hpp"
#include "items/Inventory.hpp" #include "items/Inventory.hpp"

View File

@ -6,7 +6,7 @@
#include <string> #include <string>
#include <iomanip> #include <iomanip>
#include "io/engine_paths.hpp" #include "engine/EnginePaths.hpp"
#include "util/ArgsReader.hpp" #include "util/ArgsReader.hpp"
#include "engine/Engine.hpp" #include "engine/Engine.hpp"