WIP - removing LUMIX_MAX_PATH - support for long paths

This commit is contained in:
Mikulas Florek 2023-03-23 23:25:09 +01:00
parent ab1d55e605
commit 950620aee6
24 changed files with 190 additions and 164 deletions

View file

@ -189,7 +189,7 @@ struct Runner final
loadProject();
const StaticString<LUMIX_MAX_PATH> unv_path("universes/", m_startup_world, ".unv");
const Path unv_path("universes/", m_startup_world, ".unv");
if (!loadWorld(unv_path, m_startup_world)) {
initDemoScene();
}

View file

@ -150,9 +150,9 @@ struct AssetBrowserImpl : AssetBrowser {
void onBasePathChanged() {
const char* base_path = m_app.getEngine().getFileSystem().getBasePath();
StaticString<LUMIX_MAX_PATH> path(base_path, ".lumix");
Path path(base_path, ".lumix");
bool success = os::makePath(path);
path << "/asset_tiles";
path.append("/asset_tiles");
success = os::makePath(path) && success;
if (!success) logError("Could not create ", path);
}
@ -224,7 +224,7 @@ struct AssetBrowserImpl : AssetBrowser {
void onResourceListChanged(const Path& path) {
Engine& engine = m_app.getEngine();
FileSystem& fs = engine.getFileSystem();
StaticString<LUMIX_MAX_PATH> fullpath(fs.getBasePath(), path.c_str());
const Path fullpath(fs.getBasePath(), path.c_str());
if (os::dirExists(fullpath)) {
changeDir(m_dir, false);
return;
@ -466,11 +466,11 @@ struct AssetBrowserImpl : AssetBrowser {
};
static TileState getState(const FileInfo& info, FileSystem& fs) {
StaticString<LUMIX_MAX_PATH> path(".lumix/asset_tiles/", info.file_path_hash, ".lbc");
const Path path(".lumix/asset_tiles/", info.file_path_hash, ".lbc");
if (!fs.fileExists(info.filepath)) return TileState::DELETED;
if (!fs.fileExists(path)) return TileState::NOT_CREATED;
StaticString<LUMIX_MAX_PATH> compiled_path(".lumix/resources/", info.file_path_hash, ".res");
const Path compiled_path(".lumix/resources/", info.file_path_hash, ".res");
const u64 last_modified = fs.getLastModified(path);
if (last_modified < fs.getLastModified(info.filepath) || last_modified < fs.getLastModified(compiled_path)) {
return TileState::OUTDATED;
@ -501,8 +501,8 @@ struct AssetBrowserImpl : AssetBrowser {
else
{
ImGuiEx::Rect(img_size.x, img_size.y, 0xffffFFFF);
StaticString<LUMIX_MAX_PATH> compiled_asset_path(".lumix/resources/", tile.file_path_hash, ".res");
StaticString<LUMIX_MAX_PATH> path(".lumix/asset_tiles/", tile.file_path_hash, ".lbc");
const Path compiled_asset_path(".lumix/resources/", tile.file_path_hash, ".res");
const Path path(".lumix/asset_tiles/", tile.file_path_hash, ".lbc");
FileSystem& fs = m_app.getEngine().getFileSystem();
switch (getState(tile, fs)) {
case TileState::OK:
@ -531,7 +531,7 @@ struct AssetBrowserImpl : AssetBrowser {
void deleteTile(u32 idx) {
FileSystem& fs = m_app.getEngine().getFileSystem();
StaticString<LUMIX_MAX_PATH> res_path(".lumix/resources/", m_file_infos[idx].file_path_hash, ".res");
const Path res_path(".lumix/resources/", m_file_infos[idx].file_path_hash, ".res");
fs.deleteFile(res_path);
if (!fs.deleteFile(m_file_infos[idx].filepath)) {
logError("Failed to delete ", m_file_infos[idx].filepath);
@ -550,7 +550,7 @@ struct AssetBrowserImpl : AssetBrowser {
void recreateTiles() {
for (FileInfo& fi : m_file_infos) {
StaticString<LUMIX_MAX_PATH> path(".lumix/asset_tiles/", fi.file_path_hash, ".res");
const Path path(".lumix/asset_tiles/", fi.file_path_hash, ".res");
createTile(fi, path);
}
}
@ -630,14 +630,14 @@ struct AssetBrowserImpl : AssetBrowser {
}
if (ImGui::MenuItem("View in explorer")) {
StaticString<LUMIX_MAX_PATH> dir_full_path(base_path, "/", m_dir);
const Path dir_full_path(base_path, "/", m_dir);
os::openExplorer(dir_full_path);
}
if (ImGui::BeginMenu("Create directory")) {
ImGui::InputTextWithHint("##dirname", "New directory name", tmp, sizeof(tmp), ImGuiInputTextFlags_AutoSelectAll);
ImGui::SameLine();
if (ImGui::Button("Create")) {
StaticString<LUMIX_MAX_PATH> path(base_path, "/", m_dir, "/", tmp);
const Path path(base_path, "/", m_dir, "/", tmp);
if (!os::makePath(path)) {
logError("Failed to create ", path);
}
@ -1053,12 +1053,12 @@ struct AssetBrowserImpl : AssetBrowser {
{
FileSystem& fs = m_app.getEngine().getFileSystem();
if (os::dirExists(path)) {
StaticString<LUMIX_MAX_PATH> tmp(fs.getBasePath(), "/", m_dir, "/");
const Path tmp(fs.getBasePath(), "/", m_dir, "/");
IAllocator& allocator = m_app.getAllocator();
copyDir(path, tmp, allocator);
}
PathInfo fi(path);
StaticString<LUMIX_MAX_PATH> dest(fs.getBasePath(), "/", m_dir, "/", fi.m_basename, ".", fi.m_extension);
const Path dest(fs.getBasePath(), "/", m_dir, "/", fi.m_basename, ".", fi.m_extension);
return os::copyFile(path, dest);
}
@ -1080,10 +1080,10 @@ struct AssetBrowserImpl : AssetBrowser {
static StaticString<LUMIX_MAX_PATH> getImGuiLabelID(const ResourceLocator& rl, bool hash_id) {
StaticString<LUMIX_MAX_PATH> res("");
if (rl.full.length() > 0) {
res << rl.subresource << (rl.subresource.length() > 0 ? ":" : "") << rl.basename << "." << rl.ext;
res.append(rl.subresource, (rl.subresource.length() > 0 ? ":" : ""), rl.basename, ".", rl.ext);
}
if (hash_id) {
res << "##h" << RuntimeHash(rl.full.m_begin, rl.full.length()).getHashValue();
res.append("##h", RuntimeHash(rl.full.m_begin, rl.full.length()).getHashValue());
}
return res;
}
@ -1177,11 +1177,9 @@ struct AssetBrowserImpl : AssetBrowser {
}
Engine& engine = m_app.getEngine();
StaticString<LUMIX_MAX_PATH> src_full_path;
StaticString<LUMIX_MAX_PATH> dest_full_path;
const char* base_path = engine.getFileSystem().getBasePath();
src_full_path << base_path << tmp_path;
dest_full_path << base_path << resource.getPath().c_str();
StaticString<LUMIX_MAX_PATH> src_full_path(base_path, tmp_path);
StaticString<LUMIX_MAX_PATH> dest_full_path(base_path, resource.getPath().c_str());
os::deleteFile(dest_full_path);
@ -1289,11 +1287,11 @@ struct AssetBrowserImpl : AssetBrowser {
void openInExternalEditor(const char* path) const override
{
StaticString<LUMIX_MAX_PATH> full_path(m_app.getEngine().getFileSystem().getBasePath());
full_path << path;
const char* base_path = m_app.getEngine().getFileSystem().getBasePath();
StaticString<LUMIX_MAX_PATH> full_path(base_path, path);
const os::ExecuteOpenResult res = os::shellExecuteOpen(full_path);
if (res == os::ExecuteOpenResult::NO_ASSOCIATION) {
logError(full_path << " is not associated with any app.");
logError(full_path, " is not associated with any app.");
}
else if (res == os::ExecuteOpenResult::OTHER_ERROR) {
logError("Failed to open ", full_path, " in exeternal editor.");

View file

@ -110,12 +110,12 @@ struct AssetCompilerImpl : AssetCompiler {
m_watcher = FileSystemWatcher::create(base_path, app.getAllocator());
m_watcher->getCallback().bind<&AssetCompilerImpl::onFileChanged>(this);
m_task.create("Asset compiler", true);
StaticString<LUMIX_MAX_PATH> path(base_path, ".lumix/resources");
Path path(base_path, ".lumix/resources");
if (!os::dirExists(path)) {
if (!os::makePath(path)) logError("Could not create ", path);
else {
os::OutputFile file;
path.add("/_version.bin");
path.append("/_version.bin");
if (!file.open(path)) {
logError("Could not open ", path);
}
@ -140,7 +140,7 @@ struct AssetCompilerImpl : AssetCompiler {
bool all_deleted = true;
while (os::getNextFile(iter, &info)) {
if (!info.is_directory) {
StaticString<LUMIX_MAX_PATH> filepath(".lumix/resources/", info.filename);
const Path filepath(".lumix/resources/", info.filename);
if (!os::deleteFile(filepath)) {
all_deleted = false;
}
@ -255,7 +255,7 @@ struct AssetCompilerImpl : AssetCompiler {
makeLowercase(Span(normalized), normalized);
const FilePathHash hash(normalized);
FileSystem& fs = m_app.getEngine().getFileSystem();
StaticString<LUMIX_MAX_PATH> out_path(".lumix/resources/", hash, ".res");
const Path out_path(".lumix/resources/", hash, ".res");
os::OutputFile file;
if(!fs.open(out_path, file)) {
logError("Could not create ", out_path);
@ -407,7 +407,7 @@ struct AssetCompilerImpl : AssetCompiler {
void fillDB() {
FileSystem& fs = m_app.getEngine().getFileSystem();
const StaticString<LUMIX_MAX_PATH> list_path(fs.getBasePath(), ".lumix/resources/_list.txt");
const Path list_path(fs.getBasePath(), ".lumix/resources/_list.txt");
OutputMemoryStream content(m_app.getAllocator());
if (fs.getContentSync(Path(".lumix/resources/_list.txt"), content)) {
lua_State* L = luaL_newstate();
@ -430,7 +430,7 @@ struct AssetCompilerImpl : AssetCompiler {
LuaWrapper::forEachArrayItem<Path>(L, -1, "array of strings expected", [this, &fs](const Path& p){
const ResourceType type = getResourceType(p.c_str());
#ifdef CACHE_MASTER
StaticString<LUMIX_MAX_PATH> res_path(".lumix/resources/", p.getHash(), ".res");
const Path res_path(".lumix/resources/", p.getHash(), ".res");
if (type.isValid() && fs.fileExists(res_path)) {
m_resources.insert(p.getHash(), {p, type, dirHash(p.c_str())});
}
@ -443,7 +443,7 @@ struct AssetCompilerImpl : AssetCompiler {
m_resources.insert(p.getHash(), {p, type, dirHash(p.c_str())});
}
else {
StaticString<LUMIX_MAX_PATH> res_path(".lumix/resources/", p.getHash(), ".res");
const Path res_path(".lumix/resources/", p.getHash(), ".res");
fs.deleteFile(res_path);
}
}
@ -504,7 +504,7 @@ struct AssetCompilerImpl : AssetCompiler {
if (equalIStrings(path, "lumix.log")) return;
const char* base_path = m_app.getEngine().getFileSystem().getBasePath();
const StaticString<LUMIX_MAX_PATH> full_path(base_path, "/", path);
const Path full_path(base_path, "/", path);
if (os::dirExists(full_path)) {
MutexGuard lock(m_changed_mutex);
@ -602,7 +602,7 @@ struct AssetCompilerImpl : AssetCompiler {
if (startsWith(filepath, ".lumix/asset_tiles/")) return ResourceManagerHub::LoadHook::Action::IMMEDIATE;
const FilePathHash hash = res.getPath().getHash();
const StaticString<LUMIX_MAX_PATH> dst_path(".lumix/resources/", hash, ".res");
const Path dst_path(".lumix/resources/", hash, ".res");
const StaticString<LUMIX_MAX_PATH> meta_path(filepath, ".meta");
if (!fs.fileExists(dst_path)
@ -741,9 +741,9 @@ struct AssetCompilerImpl : AssetCompiler {
if (!path_obj.isEmpty()) {
FileSystem& fs = m_app.getEngine().getFileSystem();
const StaticString<LUMIX_MAX_PATH> list_path(fs.getBasePath(), ".lumix/resources/_list.txt");
const Path list_path(fs.getBasePath(), ".lumix/resources/_list.txt");
const u64 list_last_modified = os::getLastModified(list_path);
StaticString<LUMIX_MAX_PATH> fullpath(fs.getBasePath(), path_obj.c_str());
const Path fullpath(fs.getBasePath(), path_obj.c_str());
if (os::dirExists(fullpath)) {
processDir(path_obj.c_str(), list_last_modified);
m_on_list_changed.invoke(path_obj);

View file

@ -829,7 +829,7 @@ void PropertyGrid::showCoreProperties(const Array<EntityRef>& entities, WorldEdi
const Vec3 old_euler = rot.toEuler();
Vec3 euler = old_euler;
if (ImGuiEx::InputRotation("##rot", &euler.x)) {
Array<Quat> rots(editor.getAllocator());
Array<Quat> rots(m_app.getAllocator());
for (EntityRef entity : entities) {
Vec3 tmp = world.getRotation(entity).toEuler();

View file

@ -365,7 +365,7 @@ struct StudioAppImpl final : StudioApp
m_asset_browser = AssetBrowser::create(*this);
m_property_grid.create(*this);
m_profiler_ui = ProfilerUI::create(*this);
m_log_ui.create(*this, m_editor->getAllocator());
m_log_ui.create(*this, m_allocator);
ImGui::SetAllocatorFunctions(imguiAlloc, imguiFree, this);
ImGui::CreateContext();
@ -426,12 +426,12 @@ struct StudioAppImpl final : StudioApp
destroyAddCmpTreeNode(m_add_cmp_root.child);
for (auto* i : m_plugins) {
LUMIX_DELETE(m_editor->getAllocator(), i);
LUMIX_DELETE(m_allocator, i);
}
m_plugins.clear();
for (auto* i : m_gui_plugins) {
LUMIX_DELETE(m_editor->getAllocator(), i);
LUMIX_DELETE(m_allocator, i);
}
m_gui_plugins.clear();
@ -440,7 +440,7 @@ struct StudioAppImpl final : StudioApp
for (auto* i : m_add_cmp_plugins)
{
LUMIX_DELETE(m_editor->getAllocator(), i);
LUMIX_DELETE(m_allocator, i);
}
m_add_cmp_plugins.clear();
@ -596,8 +596,7 @@ struct StudioAppImpl final : StudioApp
char label[50];
};
auto& allocator = m_editor->getAllocator();
auto* plugin = LUMIX_NEW(allocator, Plugin);
Plugin* plugin = LUMIX_NEW(m_allocator, Plugin);
plugin->property_grid = m_property_grid.get();
plugin->asset_browser = m_asset_browser.get();
plugin->type = cmp_type;
@ -653,8 +652,7 @@ struct StudioAppImpl final : StudioApp
char label[64];
};
auto& allocator = m_editor->getAllocator();
auto* plugin = LUMIX_NEW(allocator, Plugin);
Plugin* plugin = LUMIX_NEW(m_allocator, Plugin);
plugin->property_grid = m_property_grid.get();
plugin->type = type;
copyString(plugin->label, label);
@ -877,9 +875,9 @@ struct StudioAppImpl final : StudioApp
u32 size;
fromCStringOctal(Span(header.size, sizeof(header.size)), size);
if (header.name[0] && (header.typeflag == 0 || header.typeflag == '0')) {
const StaticString<LUMIX_MAX_PATH> path(m_engine->getFileSystem().getBasePath(), "/", header.name);
const Path path(m_engine->getFileSystem().getBasePath(), "/", header.name);
char dir[LUMIX_MAX_PATH];
copyString(Span(dir), Path::getDir(path));
copyString(Span(dir), Path::getDir(path.c_str()));
if (!os::makePath(dir)) logError("");
if (!os::fileExists(path)) {
os::OutputFile file;
@ -1303,7 +1301,7 @@ struct StudioAppImpl final : StudioApp
template <void (StudioAppImpl::*Func)()>
Action& addAction(const char* label_short, const char* label_long, const char* name, const char* font_icon = "")
{
Action* a = LUMIX_NEW(m_editor->getAllocator(), Action);
Action* a = LUMIX_NEW(m_allocator, Action);
a->init(label_short, label_long, name, font_icon, true);
a->func.bind<Func>(this);
addAction(a);
@ -1320,7 +1318,7 @@ struct StudioAppImpl final : StudioApp
os::Keycode shortcut,
Action::Modifiers modifiers)
{
Action* a = LUMIX_NEW(m_editor->getAllocator(), Action);
Action* a = LUMIX_NEW(m_allocator, Action);
a->init(label_short, label_long, name, font_icon, shortcut, modifiers, true);
a->func.bind<Func>(this);
m_owned_actions.push(a);
@ -1582,10 +1580,9 @@ struct StudioAppImpl final : StudioApp
getAction("nextFrame")->toolbarButton(m_big_icon_font);
StaticString<200> stats("");
if (m_engine->getFileSystem().hasWork()) stats << ICON_FA_HOURGLASS_HALF "Loading... | ";
stats << "FPS: ";
stats << (u32)(m_fps + 0.5f);
if (!isFocused()) stats << " - inactive window";
if (m_engine->getFileSystem().hasWork()) stats.add(ICON_FA_HOURGLASS_HALF "Loading... | ");
stats.append("FPS: ", u32(m_fps + 0.5f));
if (!isFocused()) stats.add(" - inactive window");
auto stats_size = ImGui::CalcTextSize(stats);
ImGui::SameLine(ImGui::GetContentRegionMax().x - stats_size.x);
ImGui::Text("%s", (const char*)stats);
@ -2251,12 +2248,10 @@ struct StudioAppImpl final : StudioApp
{
char tmp_path[LUMIX_MAX_PATH];
os::getExecutablePath(Span(tmp_path));
StaticString<LUMIX_MAX_PATH> copy_path;
copyString(Span(copy_path.data), Path::getDir(tmp_path));
copy_path << "plugins/" << iteration;
StaticString<LUMIX_MAX_PATH> copy_path(Path::getDir(tmp_path), "plugins/", iteration);
if (!os::makePath(copy_path)) logError("Could not create ", copy_path);
copyString(Span(tmp_path), Path::getBasename(src));
copy_path << "/" << tmp_path << "." << getPluginExtension();
copy_path.append("/", tmp_path, ".", getPluginExtension());
#ifdef _WIN32
StaticString<LUMIX_MAX_PATH> src_pdb(src);
StaticString<LUMIX_MAX_PATH> dest_pdb(copy_path);
@ -2942,7 +2937,8 @@ struct StudioAppImpl final : StudioApp
fromCString(Span(basename), tmp_hash);
rec.hash = FilePathHash::fromU64(tmp_hash);
rec.offset = 0;
rec.size = os::getFileSize(StaticString<LUMIX_MAX_PATH>(base_path, ".lumix/resources/", info.filename));
const Path path(base_path, ".lumix/resources/", info.filename);
rec.size = os::getFileSize(path);
copyString(rec.path, ".lumix/resources/");
catString(rec.path, info.filename);
infos.insert(rec.hash, rec);
@ -2962,7 +2958,8 @@ struct StudioAppImpl final : StudioApp
auto& out_info = infos.emplace(hash);
copyString(out_info.path, file_path);
out_info.hash = hash;
out_info.size = os::getFileSize(StaticString<LUMIX_MAX_PATH>(base_path, file_path));
const Path path(base_path, file_path);
out_info.size = os::getFileSize(path);
out_info.offset = ~0UL;
}
@ -3004,7 +3001,8 @@ struct StudioAppImpl final : StudioApp
auto& out_info = infos.emplace(hash);
copyString(out_info.path, out_path);
out_info.hash = hash;
out_info.size = os::getFileSize(StaticString<LUMIX_MAX_PATH>(base_path, out_path.data));
const Path path(base_path, out_path.data);
out_info.size = os::getFileSize(path);
out_info.offset = ~0UL;
}
os::destroyFileIterator(iter);
@ -3018,10 +3016,10 @@ struct StudioAppImpl final : StudioApp
const auto& resources = iter.value()->getResourceTable();
for (Resource* res : resources) {
const FilePathHash hash = res->getPath().getHash();
const StaticString<LUMIX_MAX_PATH> baked_path(".lumix/resources/", hash, ".res");
const Path baked_path(".lumix/resources/", hash, ".res");
auto& out_info = infos.emplace(hash);
copyString(Span(out_info.path), baked_path);
copyString(Span(out_info.path), baked_path.c_str());
out_info.hash = hash;
out_info.size = os::getFileSize(baked_path);
out_info.offset = ~0UL;
@ -3080,8 +3078,8 @@ struct StudioAppImpl final : StudioApp
OutputMemoryStream prj_blob(m_allocator);
m_engine->serializeProject(prj_blob, m_export.startup_world);
StaticString<LUMIX_MAX_PATH> project_path(fs.getBasePath(), "lumix.prj");
if (!fs.saveContentSync(Path(project_path), prj_blob)) {
const Path project_path(fs.getBasePath(), "lumix.prj");
if (!fs.saveContentSync(project_path, prj_blob)) {
logError("Could not save ", project_path);
return;
}
@ -3147,7 +3145,7 @@ struct StudioAppImpl final : StudioApp
copyString(dest, m_export.dest_dir);
const char* base_path = fs.getBasePath();
for (auto& info : infos) {
StaticString<LUMIX_MAX_PATH> src(base_path, info.path);
const Path src(base_path, info.path);
StaticString<LUMIX_MAX_PATH> dst(dest, info.path);
StaticString<LUMIX_MAX_PATH> dst_dir(dest, Path::getDir(info.path));

View file

@ -283,7 +283,7 @@ void FileSelector::fillSubitems() {
FileSystem& fs = m_app.getEngine().getFileSystem();
const char* base_path = fs.getBasePath();
StaticString<LUMIX_MAX_PATH> path(base_path, "/", m_current_dir.c_str());
const Path path(base_path, "/", m_current_dir.c_str());
os::FileIterator* iter = os::createFileIterator(path, m_app.getAllocator());
os::FileInfo info;
const char* ext = m_accepted_extension.c_str();
@ -357,7 +357,7 @@ void DirSelector::fillSubitems() {
FileSystem& fs = m_app.getEngine().getFileSystem();
const char* base_path = fs.getBasePath();
StaticString<LUMIX_MAX_PATH> path(base_path, "/", m_current_dir.c_str());
const Path path(base_path, "/", m_current_dir.c_str());
os::FileIterator* iter = os::createFileIterator(path, m_app.getAllocator());
os::FileInfo info;
while (os::getNextFile(iter, &info)) {
@ -433,7 +433,7 @@ bool DirSelector::gui(const char* label, bool* open) {
if (ImGui::IsItemDeactivatedAfterEdit()) {
if (m_new_folder_name[0]) {
FileSystem& fs = m_app.getEngine().getFileSystem();
StaticString<LUMIX_MAX_PATH> fullpath(fs.getBasePath(), m_current_dir.c_str(), "/", m_new_folder_name);
const Path fullpath(fs.getBasePath(), m_current_dir.c_str(), "/", m_new_folder_name);
if (!os::makePath(fullpath)) {
logError("Failed to create ", fullpath);
}

View file

@ -1483,8 +1483,8 @@ private:
struct MakeParentCommand final : IEditorCommand
{
public:
explicit MakeParentCommand(WorldEditor& editor)
: m_editor(static_cast<WorldEditorImpl&>(editor))
explicit MakeParentCommand(WorldEditorImpl& editor)
: m_editor(editor)
{
}
@ -1540,8 +1540,8 @@ private:
struct DestroyEntitiesCommand final : IEditorCommand
{
public:
explicit DestroyEntitiesCommand(WorldEditor& editor)
: m_editor(static_cast<WorldEditorImpl&>(editor))
explicit DestroyEntitiesCommand(WorldEditorImpl& editor)
: m_editor(editor)
, m_entities(editor.getAllocator())
, m_transformations(editor.getAllocator())
, m_old_values(editor.getAllocator())
@ -1728,8 +1728,8 @@ private:
struct DestroyComponentCommand final : IEditorCommand
{
public:
explicit DestroyComponentCommand(WorldEditor& editor)
: m_editor(static_cast<WorldEditorImpl&>(editor))
explicit DestroyComponentCommand(WorldEditorImpl& editor)
: m_editor(editor)
, m_old_values(editor.getAllocator())
, m_entities(editor.getAllocator())
, m_cmp_type(INVALID_COMPONENT_TYPE)
@ -1952,9 +1952,9 @@ public:
logInfo("Saving world ", basename, "...");
StaticString<LUMIX_MAX_PATH> path(m_engine.getFileSystem().getBasePath(), "universes");
Path path(m_engine.getFileSystem().getBasePath(), "universes");
if (!os::makePath(path)) logError("Could not create directory universes/");
path << "/" << basename << ".unv";
path.append("/", basename, ".unv");
StaticString<LUMIX_MAX_PATH> bkp_path(path, ".bak");
if (os::fileExists(path)) {
if (!os::copyFile(path, bkp_path)) {
@ -2482,7 +2482,7 @@ public:
m_world->setName(basename);
logInfo("Loading world ", basename, "...");
os::InputFile file;
const StaticString<LUMIX_MAX_PATH> path(m_engine.getFileSystem().getBasePath(), "universes/", basename, ".unv");
const Path path(m_engine.getFileSystem().getBasePath(), "universes/", basename, ".unv");
if (file.open(path)) {
if (!load(file, path)) {
logError("Failed to parse ", path);
@ -2701,7 +2701,7 @@ public:
if (m_is_game_mode) stopGameMode(false);
ASSERT(m_world);
destroyUndoStack();
clearUndoStack();
m_entity_folders.destroy();
m_world_destroyed.invoke();
m_prefab_system->setWorld(nullptr);
@ -2726,7 +2726,7 @@ public:
return m_entity_selection_changed;
}
void destroyUndoStack()
void clearUndoStack()
{
m_undo_index = -1;
m_undo_stack.clear();
@ -2738,7 +2738,7 @@ public:
ASSERT(!m_world);
m_is_world_changed = false;
destroyUndoStack();
clearUndoStack();
m_world = &m_engine.createWorld(true);
World* world = m_world;
@ -2848,7 +2848,7 @@ private:
struct PasteEntityCommand final : IEditorCommand
{
public:
PasteEntityCommand(WorldEditor& editor, const OutputMemoryStream& copy_buffer, bool identity = false)
PasteEntityCommand(WorldEditorImpl& editor, const OutputMemoryStream& copy_buffer, bool identity = false)
: m_copy_buffer(copy_buffer)
, m_editor(editor)
, m_entities(editor.getAllocator())

View file

@ -87,13 +87,13 @@ struct FileSystemImpl : FileSystem {
{
Path::normalize(dir, Span(m_base_path.data));
if (!endsWith(m_base_path, "/") && !endsWith(m_base_path, "\\")) {
m_base_path << '/';
m_base_path.add('/');
}
}
bool saveContentSync(const Path& path, Span<const u8> content) override {
os::OutputFile file;
StaticString<LUMIX_MAX_PATH> full_path(m_base_path, path.c_str());
const Path full_path(m_base_path, path.c_str());
if (!file.open(full_path)) return false;
bool res = file.write(content.begin(), content.length());
@ -104,7 +104,7 @@ struct FileSystemImpl : FileSystem {
bool getContentSync(const Path& path, OutputMemoryStream& content) override {
os::InputFile file;
StaticString<LUMIX_MAX_PATH> full_path(m_base_path, path.c_str());
const Path full_path(m_base_path, path.c_str());
if (!file.open(full_path)) return false;
@ -157,58 +157,58 @@ struct FileSystemImpl : FileSystem {
bool open(const char* path, os::InputFile& file) override
{
StaticString<LUMIX_MAX_PATH> full_path(m_base_path, path);
const Path full_path(m_base_path, path);
return file.open(full_path);
}
bool open(const char* path, os::OutputFile& file) override
{
StaticString<LUMIX_MAX_PATH> full_path(m_base_path, path);
const Path full_path(m_base_path, path);
return file.open(full_path);
}
bool deleteFile(const char* path) override
{
StaticString<LUMIX_MAX_PATH> full_path(m_base_path, path);
const Path full_path(m_base_path, path);
return os::deleteFile(full_path);
}
bool moveFile(const char* from, const char* to) override
{
StaticString<LUMIX_MAX_PATH> full_path_from(m_base_path, from);
StaticString<LUMIX_MAX_PATH> full_path_to(m_base_path, to);
const Path full_path_from(m_base_path, from);
const Path full_path_to(m_base_path, to);
return os::moveFile(full_path_from, full_path_to);
}
bool copyFile(const char* from, const char* to) override
{
StaticString<LUMIX_MAX_PATH> full_path_from(m_base_path, from);
StaticString<LUMIX_MAX_PATH> full_path_to(m_base_path, to);
const Path full_path_from(m_base_path, from);
const Path full_path_to(m_base_path, to);
return os::copyFile(full_path_from, full_path_to);
}
bool fileExists(const char* path) override
{
StaticString<LUMIX_MAX_PATH> full_path(m_base_path, path);
const Path full_path(m_base_path, path);
return os::fileExists(full_path);
}
u64 getLastModified(const char* path) override
{
StaticString<LUMIX_MAX_PATH> full_path(m_base_path, path);
const Path full_path(m_base_path, path);
return os::getLastModified(full_path);
}
os::FileIterator* createFileIterator(const char* dir) override
{
StaticString<LUMIX_MAX_PATH> path(m_base_path, dir);
const Path path(m_base_path, dir);
return os::createFileIterator(path, m_allocator);
}

View file

@ -398,12 +398,12 @@ static int LUA_packageLoader(lua_State* L)
OutputMemoryStream buf(engine->getAllocator());
bool loaded = true;
if (!fs.getContentSync(Path(tmp), buf)) {
tmp << ".lua";
tmp.add(".lua");
if (!fs.getContentSync(Path(tmp), buf)) {
loaded = false;
logError("Failed to open file ", tmp);
StaticString<LUMIX_MAX_PATH + 40> msg("Failed to open file ");
msg << tmp;
msg.add(tmp);
lua_pushstring(L, msg);
}
}
@ -663,7 +663,7 @@ static int LUA_loadWorld(lua_State* L)
Callback* inst = LUMIX_NEW(engine->getAllocator(), Callback);
inst->engine = engine;
inst->world = world;
StaticString<LUMIX_MAX_PATH> path("universes/", name, ".unv");
const Path path("universes/", name, ".unv");
inst->path = path;
inst->L = L;
inst->lua_func = luaL_ref(L, LUA_REGISTRYINDEX);

View file

@ -23,6 +23,23 @@ Path::Path(const char* path) {
endUpdate();
}
void Path::add(const char* value) {
const i32 len = stringLength(m_path);
normalize(value, Span(m_path + len, lengthOf(m_path) - len));
}
void Path::add(StableHash hash) {
char tmp[32];
toCString(hash.getHashValue(), Span(tmp));
catString(m_path, tmp);
}
void Path::add(u64 value) {
char tmp[32];
toCString(value, Span(tmp));
catString(m_path, tmp);
}
i32 Path::length() const {
return stringLength(m_path);
}
@ -221,6 +238,8 @@ Path::operator Span<const char>() const {
return Span(m_path, stringLength(m_path));
}
Path::operator const char*() const { return m_path; }
PathInfo::PathInfo(const char* path) {
char tmp[LUMIX_MAX_PATH];
Path::normalize(path, Span(tmp));

View file

@ -28,6 +28,7 @@ struct LUMIX_ENGINE_API Path {
Path();
explicit Path(const char* path);
template <typename... Args> explicit Path(Args... args);
void operator=(const char* rhs);
bool operator==(const char* rhs) const;
@ -36,17 +37,37 @@ struct LUMIX_ENGINE_API Path {
i32 length() const;
FilePathHash getHash() const { return m_hash; }
template <typename... Args> void append(Args... args);
char* beginUpdate() { return m_path; }
void endUpdate();
const char* c_str() const { return m_path; }
bool isEmpty() const { return m_path[0] == '\0'; }
static u32 capacity() { return LUMIX_MAX_PATH; }
operator Span<const char>() const;
operator const char*() const;
private:
void add(const char*);
void add(StableHash hash);
void add(u64 value);
char m_path[LUMIX_MAX_PATH];
FilePathHash m_hash;
};
template <typename... Args> Path::Path(Args... args) {
m_path[0] = '\0';
int tmp[] = { (add(args), 0)... };
(void)tmp;
endUpdate();
}
template <typename... Args> void Path::append(Args... args) {
int tmp[] = { (add(args), 0)... };
(void)tmp;
endUpdate();
}
} // namespace Lumix

View file

@ -210,8 +210,8 @@ void Resource::doLoad()
m_async_op = fs.getContent(m_path, cb);
}
else {
const StaticString<LUMIX_MAX_PATH> res_path(".lumix/resources/", hash.getHashValue(), ".res");
m_async_op = fs.getContent(Path(res_path), cb);
const Path res_path(".lumix/resources/", hash, ".res");
m_async_op = fs.getContent(res_path, cb);
}
}

View file

@ -85,16 +85,10 @@ template <int SIZE> struct StaticString
(void)tmp;
}
template <int value_size> StaticString& operator<<(StaticString<value_size>& value)
template <typename... Args> void append(Args... args)
{
add(value);
return *this;
}
template <typename T> StaticString& operator<<(T value)
{
add(value);
return *this;
int tmp[] = { (add(args), 0)... };
(void)tmp;
}
template <int value_size> void add(StaticString<value_size>& value) { catString(data, value.data); }

View file

@ -753,9 +753,9 @@ static LONG WINAPI unhandledExceptionHandler(LPEXCEPTION_POINTERS info)
if(info)
{
getStack(*info->ContextRecord, Span(message.data));
message << "\nCode: " << (u32)info->ExceptionRecord->ExceptionCode;
message << "\nAddress: " << (uintptr)info->ExceptionRecord->ExceptionAddress;
message << "\nBase: " << (uintptr)base;
message.append("\nCode: ", (u32)info->ExceptionRecord->ExceptionCode);
message.append("\nAddress: ", (uintptr)info->ExceptionRecord->ExceptionAddress);
message.append("\nBase: ", (uintptr)base);
os::messageBox(message);
}
else

View file

@ -1519,8 +1519,8 @@ namespace Lumix
}
StaticString<1024> tmp(name, " = ");
if (prop.type == Property::STRING) tmp << "\"" << value << "\"";
else tmp << value;
if (prop.type == Property::STRING) tmp.append("\"", value, "\"");
else tmp.add(value);
bool errors = luaL_loadbuffer(state, tmp, stringLength(tmp), nullptr) != 0;
if (errors)

View file

@ -10,6 +10,7 @@
#include "engine/file_system.h"
#include "engine/geometry.h"
#include "engine/log.h"
#include "engine/path.h"
#include "engine/os.h"
#include "engine/world.h"
#include "navigation/navigation_scene.h"
@ -112,7 +113,7 @@ struct PropertyGridPlugin final : PropertyGrid::IPlugin {
if(scene->isNavmeshReady(entities[0])) {
ImGui::SameLine();
if (ImGui::Button("Save")) {
StaticString<LUMIX_MAX_PATH> dir(m_app.getEngine().getFileSystem().getBasePath(), "/universes/navzones/");
const Path dir(m_app.getEngine().getFileSystem().getBasePath(), "/universes/navzones/");
if (!os::makePath(dir) && !os::dirExists(dir)) {
logError("Could not create ", dir);
}

View file

@ -693,9 +693,9 @@ struct NavigationSceneImpl final : NavigationScene
LoadCallback* lcb = LUMIX_NEW(m_allocator, LoadCallback)(*this, zone_entity);
StaticString<LUMIX_MAX_PATH> path("universes/navzones/", zone.zone.guid, ".nav");
const Path path("universes/navzones/", zone.zone.guid, ".nav");
FileSystem& fs = m_engine.getFileSystem();
return fs.getContent(Path(path), makeDelegate<&LoadCallback::fileLoaded>(lcb)).isValid();
return fs.getContent(path, makeDelegate<&LoadCallback::fileLoaded>(lcb)).isValid();
}
bool saveZone(EntityRef zone_entity) override {
@ -705,7 +705,7 @@ struct NavigationSceneImpl final : NavigationScene
FileSystem& fs = m_engine.getFileSystem();
os::OutputFile file;
StaticString<LUMIX_MAX_PATH> path("universes/navzones/", zone.zone.guid, ".nav");
const Path path("universes/navzones/", zone.zone.guid, ".nav");
if (!fs.open(path, file)) return false;
bool success = file.write(zone.m_num_tiles_x);

View file

@ -552,7 +552,7 @@ struct PhysicsUIPlugin final : StudioApp::GUIPlugin
for (int j = 0; j <= i; ++j)
{
bool b = system->canLayersCollide(i, j);
if (ImGui::Checkbox(StaticString<10>("###", i, "-") << j, &b))
if (ImGui::Checkbox(StaticString<10>("###", i, "-", j), &b))
{
system->setLayersCanCollide(i, j, b);
}

View file

@ -57,18 +57,15 @@ struct EditorIconsImpl final : EditorIcons
ResourceManagerHub& rm = engine.getResourceManager();
for (u32 i = 0; i < lengthOf(ICONS); ++i)
{
StaticString<LUMIX_MAX_PATH> tmp("editor/models/", ICONS[i], "_3d.fbx");
m_is_3d[i] = fs.fileExists(tmp);
const Path path_3d("editor/models/", ICONS[i], "_3d.fbx");
m_is_3d[i] = fs.fileExists(path_3d);
if (m_is_3d[i])
{
Path path(tmp);
m_models[i] = rm.load<Model>(path);
m_models[i] = rm.load<Model>(path_3d);
}
else
{
tmp.data[0] = '\0';
tmp << "editor/models/" << ICONS[i] << ".fbx";
Path path(tmp);
const Path path("editor/models/", ICONS[i], ".fbx");
m_models[i] = rm.load<Model>(path);
}
}

View file

@ -149,17 +149,17 @@ static void extractEmbedded(const ofbx::IScene& scene, const char* src_dir)
bool FBXImporter::findTexture(const char* src_dir, const char* ext, FBXImporter::ImportTexture& tex) const {
PathInfo file_info(tex.path);
tex.src = src_dir;
tex.src << file_info.m_basename << "." << ext;
tex.src.append(file_info.m_basename, ".", ext);
tex.is_valid = m_filesystem.fileExists(tex.src);
if (!tex.is_valid) {
tex.src = src_dir;
tex.src << file_info.m_dir << "/" << file_info.m_basename << "." << ext;
tex.src.append(file_info.m_dir, "/", file_info.m_basename, ".", ext);
tex.is_valid = m_filesystem.fileExists(tex.src);
if (!tex.is_valid) {
tex.src = src_dir;
tex.src << "textures/" << file_info.m_basename << "." << ext;
tex.src.append("textures/", file_info.m_basename, ".", ext);
tex.is_valid = m_filesystem.fileExists(tex.src);
}
}
@ -336,7 +336,7 @@ void FBXImporter::gatherAnimations(const ofbx::IScene& scene)
take_info->filename.toString(tmp);
copyString(Span(anim.name.data), Path::getBasename(tmp));
}
if (anim.name.empty()) anim.name << "anim";
if (anim.name.empty()) anim.name.add("anim");
}
else
{

View file

@ -1173,7 +1173,7 @@ struct TexturePlugin final : AssetBrowser::Plugin, AssetCompiler::IPlugin
void execute() {
const FilePathHash hash(m_in_path.c_str());
StaticString<LUMIX_MAX_PATH> out_path(".lumix/asset_tiles/", hash, ".lbc");
const Path out_path(".lumix/asset_tiles/", hash, ".lbc");
OutputMemoryStream resized_data(m_allocator);
resized_data.resize(AssetBrowser::TILE_SIZE * AssetBrowser::TILE_SIZE * 4);
FileSystem& fs = m_app.getEngine().getFileSystem();
@ -2721,7 +2721,7 @@ struct ModelPlugin final : AssetBrowser::Plugin, AssetCompiler::IPlugin
}
img_path = fi.m_dir;
img_path << fi.m_basename << "_impostor1.tga";
img_path.append(fi.m_basename, "_impostor1.tga");
if (fs.open(img_path, file)) {
Texture::saveTGA(&file, tile_size.x * 9, tile_size.y * 9, gpu::TextureFormat::RGBA8, (const u8*)gb1.begin(), gpu::isOriginBottomLeft(), Path(img_path), allocator);
file.close();
@ -2731,7 +2731,7 @@ struct ModelPlugin final : AssetBrowser::Plugin, AssetCompiler::IPlugin
}
img_path = fi.m_dir;
img_path << fi.m_basename << "_impostor_depth.raw";
img_path.append(fi.m_basename, "_impostor_depth.raw");
if (fs.open(img_path, file)) {
RawTextureHeader header;
header.width = tile_size.x * 9;
@ -2760,7 +2760,7 @@ struct ModelPlugin final : AssetBrowser::Plugin, AssetCompiler::IPlugin
}
img_path = fi.m_dir;
img_path << fi.m_basename << "_impostor2.tga";
img_path.append(fi.m_basename, "_impostor2.tga");
if (fs.open(img_path, file)) {
Texture::saveTGA(&file, tile_size.x * 9, tile_size.y * 9, gpu::TextureFormat::RGBA8, (const u8*)shadow.begin(), gpu::isOriginBottomLeft(), Path(img_path), allocator);
file.close();
@ -2840,7 +2840,7 @@ struct ModelPlugin final : AssetBrowser::Plugin, AssetCompiler::IPlugin
destroyEntityRecursive(*m_tile.world, (EntityRef)m_tile.entity);
Engine& engine = m_app.getEngine();
FileSystem& fs = engine.getFileSystem();
StaticString<LUMIX_MAX_PATH> path(fs.getBasePath(), ".lumix/asset_tiles/", m_tile.path_hash, ".lbc");
const Path path(fs.getBasePath(), ".lumix/asset_tiles/", m_tile.path_hash, ".lbc");
if (!gpu::isOriginBottomLeft()) {
u32* p = (u32*)m_tile.data.getMutableData();
@ -2866,7 +2866,7 @@ struct ModelPlugin final : AssetBrowser::Plugin, AssetCompiler::IPlugin
Resource* resource = m_tile.queue.front();
if (resource->isFailure()) {
if (resource->getType() == Model::TYPE) {
StaticString<LUMIX_MAX_PATH> out_path(".lumix/asset_tiles/", resource->getPath().getHash(), ".lbc");
const Path out_path(".lumix/asset_tiles/", resource->getPath().getHash(), ".lbc");
m_app.getAssetBrowser().copyTile("editor/textures/tile_animation.tga", out_path);
m_app.getAssetBrowser().reloadTile(m_tile.path_hash);
}
@ -3015,7 +3015,7 @@ struct ModelPlugin final : AssetBrowser::Plugin, AssetCompiler::IPlugin
void renderTile(Material* material) {
const char* in_path = material->getTexture(0)->getPath().c_str();
StaticString<LUMIX_MAX_PATH> out_path(".lumix/asset_tiles/", material->getPath().getHash(), ".lbc");
const Path out_path(".lumix/asset_tiles/", material->getPath().getHash(), ".lbc");
if (material->getTextureCount() == 0) {
m_app.getAssetBrowser().copyTile("editor/textures/tile_material.tga", out_path);
return;
@ -3395,15 +3395,15 @@ struct EnvironmentProbePlugin final : PropertyGrid::IPlugin
bool saveCubemap(u64 probe_guid, const Vec4* data, u32 texture_size, u32 mips_count) {
ASSERT(data);
const char* base_path = m_app.getEngine().getFileSystem().getBasePath();
StaticString<LUMIX_MAX_PATH> path(base_path, "universes");
Path path(base_path, "universes");
if (!os::makePath(path) && !os::dirExists(path)) {
logError("Failed to create ", path);
}
path << "/probes_tmp/";
path.append("/probes_tmp/");
if (!os::makePath(path) && !os::dirExists(path)) {
logError("Failed to create ", path);
}
path << probe_guid << ".lbc";
path.append(probe_guid, ".lbc");
OutputMemoryStream blob(m_app.getAllocator());
@ -3557,11 +3557,11 @@ struct EnvironmentProbePlugin final : PropertyGrid::IPlugin
if (m_done_counter == m_probe_counter && !m_probes.empty()) {
const char* base_path = m_app.getEngine().getFileSystem().getBasePath();
StaticString<LUMIX_MAX_PATH> dir_path(base_path, "universes/");
Path dir_path(base_path, "universes/");
if (!os::dirExists(dir_path) && !os::makePath(dir_path)) {
logError("Failed to create ", dir_path);
}
dir_path << "/probes/";
dir_path.append("/probes/");
if (!os::dirExists(dir_path) && !os::makePath(dir_path)) {
logError("Failed to create ", dir_path);
}
@ -3576,8 +3576,8 @@ struct EnvironmentProbePlugin final : PropertyGrid::IPlugin
const u64 guid = job.reflection_probe.guid;
const StaticString<LUMIX_MAX_PATH> tmp_path(base_path, "/universes/probes_tmp/", guid, ".lbc");
const StaticString<LUMIX_MAX_PATH> path(base_path, "/universes/probes/", guid, ".lbc");
const Path tmp_path(base_path, "/universes/probes_tmp/", guid, ".lbc");
const Path path(base_path, "/universes/probes/", guid, ".lbc");
if (!os::fileExists(tmp_path)) {
if (scene) scene->reloadReflectionProbes();
return;
@ -3738,10 +3738,10 @@ struct EnvironmentProbePlugin final : PropertyGrid::IPlugin
else {
const ReflectionProbe& probe = scene->getReflectionProbe(e);
if (probe.flags.isSet(ReflectionProbe::ENABLED)) {
StaticString<LUMIX_MAX_PATH> path("universes/probes/", probe.guid, ".lbc");
const Path path("universes/probes/", probe.guid, ".lbc");
ImGuiEx::Label("Path");
ImGui::TextUnformatted(path);
if (ImGui::Button("View radiance")) m_app.getAssetBrowser().selectResource(Path(path), true, false);
if (ImGui::Button("View radiance")) m_app.getAssetBrowser().selectResource(path, true, false);
}
if (ImGui::CollapsingHeader("Generator")) {
if (ImGui::Button("Generate")) generateCubemaps(false, world);
@ -4845,11 +4845,11 @@ struct AddTerrainComponentPlugin final : StudioApp::IAddComponentPlugin
Path::normalize(material_path, Span(normalized_material_path));
PathInfo info(normalized_material_path);
StaticString<LUMIX_MAX_PATH> hm_path(info.m_dir, info.m_basename, ".raw");
StaticString<LUMIX_MAX_PATH> albedo_path(info.m_dir, "albedo_detail.ltc");
StaticString<LUMIX_MAX_PATH> normal_path(info.m_dir, "normal_detail.ltc");
StaticString<LUMIX_MAX_PATH> splatmap_path(info.m_dir, "splatmap.tga");
StaticString<LUMIX_MAX_PATH> splatmap_meta_path(info.m_dir, "splatmap.tga.meta");
const Path hm_path(info.m_dir, info.m_basename, ".raw");
const Path albedo_path(info.m_dir, "albedo_detail.ltc");
const Path normal_path(info.m_dir, "normal_detail.ltc");
const Path splatmap_path(info.m_dir, "splatmap.tga");
const Path splatmap_meta_path(info.m_dir, "splatmap.tga.meta");
os::OutputFile file;
FileSystem& fs = m_app.getEngine().getFileSystem();
if (!fs.open(hm_path, file))
@ -4898,7 +4898,7 @@ struct AddTerrainComponentPlugin final : StudioApp::IAddComponentPlugin
OutputMemoryStream splatmap(m_app.getAllocator());
splatmap.resize(size * size * 4);
memset(splatmap.getMutableData(), 0, size * size * 4);
if (!Texture::saveTGA(&file, size, size, gpu::TextureFormat::RGBA8, splatmap.data(), true, Path(splatmap_path), m_app.getAllocator())) {
if (!Texture::saveTGA(&file, size, size, gpu::TextureFormat::RGBA8, splatmap.data(), true, splatmap_path, m_app.getAllocator())) {
logError("Failed to create texture ", splatmap_path);
os::deleteFile(hm_path);
return false;
@ -4907,7 +4907,7 @@ struct AddTerrainComponentPlugin final : StudioApp::IAddComponentPlugin
CompositeTexture albedo(m_app, m_app.getAllocator());
albedo.initTerrainAlbedo();
if (!albedo.save(fs, Path(albedo_path))) {
if (!albedo.save(fs, albedo_path)) {
logError("Failed to create texture ", albedo_path);
os::deleteFile(hm_path);
os::deleteFile(splatmap_path);
@ -4917,7 +4917,7 @@ struct AddTerrainComponentPlugin final : StudioApp::IAddComponentPlugin
CompositeTexture normal(m_app, m_app.getAllocator());
normal.initTerrainNormal();
if (!normal.save(fs, Path(normal_path))) {
if (!normal.save(fs, normal_path)) {
logError("Failed to create texture ", normal_path);
os::deleteFile(albedo_path);
os::deleteFile(hm_path);

View file

@ -728,7 +728,7 @@ TerrainEditor::TerrainEditor(StudioApp& app)
m_rotate_x_spread = m_rotate_y_spread = m_rotate_z_spread = Vec2(0, PI * 2);
FileSystem& fs = app.getEngine().getFileSystem();
StaticString<LUMIX_MAX_PATH> path(fs.getBasePath(), "/universes/distance_fields");
const Path path(fs.getBasePath(), "/universes/distance_fields");
os::FileIterator* iter = os::createFileIterator(path, app.getAllocator());
os::FileInfo info;
while (os::getNextFile(iter, &info)) {
@ -764,7 +764,7 @@ void DistanceField::clear() {
}
bool DistanceField::load(FileSystem& fs, IAllocator& allocator) {
const StaticString<LUMIX_MAX_PATH> path(fs.getBasePath(), "universes/distance_fields/", name.c_str(), ".df");
const Path path(fs.getBasePath(), "universes/distance_fields/", name.c_str(), ".df");
os::InputFile file;
if (!file.open(path)) {
logError("Failed to open ", path);
@ -796,12 +796,12 @@ bool DistanceField::load(InputMemoryStream& blob) {
}
void DistanceField::save(FileSystem& fs, IAllocator& allocator) {
StaticString<LUMIX_MAX_PATH> path(fs.getBasePath(), "universes/distance_fields/");
Path path(fs.getBasePath(), "universes/distance_fields/");
if (!os::makePath(path)) {
logError("Failed to create ", path);
}
path.add(name.c_str());
path.add(".df");
path.append(name.c_str());
path.append(".df");
OutputMemoryStream blob(allocator);
Header header;
@ -1509,7 +1509,7 @@ void TerrainEditor::distanceFieldsUI(ComponentUID terrain_uid) {
ImGui::SameLine();
if (ImGuiEx::IconButton(ICON_FA_TIMES, "Delete")) {
StaticString<LUMIX_MAX_PATH> path("universes/distance_fields/", df.name.c_str(), ".df");
const Path path("universes/distance_fields/", df.name.c_str(), ".df");
if (!m_app.getEngine().getFileSystem().deleteFile(path)) {
logError("Failed to delete ", path);
}

View file

@ -819,15 +819,15 @@ struct RenderSceneImpl final : RenderScene {
}
}
StaticString<LUMIX_MAX_PATH> path_str("universes/probes/", probe.guid, ".lbc");
const Path path("universes/probes/", probe.guid, ".lbc");
if (probe.texture_id == 0xffFFffFF) {
logError("There's not enough space for ", path_str);
logError("There's not enough space for ", path);
return;
}
probe.load_job = LUMIX_NEW(m_allocator, ReflectionProbe::LoadJob)(*this, entity, m_allocator);
FileSystem::ContentCallback cb = makeDelegate<&ReflectionProbe::LoadJob::callback>(probe.load_job);
probe.load_job->m_handle = m_engine.getFileSystem().getContent(Path(path_str), cb);
probe.load_job->m_handle = m_engine.getFileSystem().getContent(path, cb);
}
void deserializeEnvironmentProbes(InputMemoryStream& serializer, const EntityMap& entity_map)
@ -835,7 +835,7 @@ struct RenderSceneImpl final : RenderScene {
u32 count;
serializer.read(count);
m_environment_probes.reserve(count + m_environment_probes.size());
StaticString<LUMIX_MAX_PATH> probe_dir("universes/probes/");
const Path probe_dir("universes/probes/");
for (u32 i = 0; i < count; ++i) {
EntityRef entity;
serializer.read(entity);
@ -3137,8 +3137,6 @@ struct RenderSceneImpl final : RenderScene {
{
ReflectionProbe& probe = m_reflection_probes.insert(entity);
probe.guid = randGUID();
StaticString<LUMIX_MAX_PATH> path;
probe.flags.set(ReflectionProbe::ENABLED);
m_world.onComponentCreated(entity, REFLECTION_PROBE_TYPE, this);

View file

@ -84,7 +84,7 @@ void Shader::compile(gpu::ProgramHandle program
if (defines != 0) {
for(int i = 0; i < sizeof(defines) * 8; ++i) {
if((defines & (1 << i)) == 0) continue;
defines_code[defines_count] << "#define " << m_renderer.getShaderDefine(i) << "\n";
defines_code[defines_count].append("#define ", m_renderer.getShaderDefine(i), "\n");
prefixes[defines_count] = defines_code[defines_count];
++defines_count;
}