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/ContentPack.hpp"
#include "debug/Logger.hpp"
#include "io/engine_paths.hpp"
#include "engine/EnginePaths.hpp"
#include "io/io.hpp"
#include "graphics/core/Texture.hpp"
#include "logic/scripting/scripting.hpp"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,4 +1,4 @@
#include "engine_paths.hpp"
#include "EnginePaths.hpp"
#include "debug/Logger.hpp"
#include "io/devices/StdfsDevice.hpp"
@ -39,10 +39,10 @@ static std::string generate_random_base64() {
return util::base64_urlsafe_encode(bytes, n);
}
void EnginePaths::prepare(CoreParameters& params) {
resourcesFolder = params.resFolder;
userFilesFolder = params.userFolder;
projectFolder = params.projectFolder;
EnginePaths::EnginePaths(CoreParameters& params)
: resourcesFolder(params.resFolder),
userFilesFolder(params.userFolder),
projectFolder(params.projectFolder) {
if (!params.scriptFile.empty()) {
scriptFolder = params.scriptFile.parent_path();
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");
}
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 {
auto folder = SCREENSHOTS_FOLDER;
if (!io::is_directory(folder)) {
@ -107,10 +99,6 @@ io::path EnginePaths::getWorldsFolder() const {
return WORLDS_FOLDER;
}
io::path EnginePaths::getCurrentWorldFolder() {
return currentWorldFolder;
}
io::path EnginePaths::getWorldFolderByName(const std::string& name) {
return getWorldsFolder() / name;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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