Squashed 'deps/nostalgia/' changes from 7e3e0461..be518387
be518387 [nostalgia/gfx/studio/tilesheet] Add flip x and flip y functionality 1207dade [studio] Add ability to move directories 109e1898 [studio] Add ability to drag files between directories a24bf7ff [studio] Fix config to update when open file name changes 046834c2 [studio,nostalgia] Update tab name when corresponding file's name changes f840240a [nostalgia/gfx/studio/tilesheeteditor] Rework system for tracking current palette path cfa91d3d [keel,studio] Add ability to rename files f7a7a66a [ox/event] Add Signal::connectionCnt 5145595d [ox/std] Fix HashMap collision handling f01d3033 [ox/std] Fix UPtr compare with nullptr 098c8cb8 [nostalgia/gfx/studio] Make move color commands affect all pages 04ad0f02 [studio] Add drag/drop functions that use model TypeName for name 695e7a45 [nostalgia/gfx/studio/paletteeditor] Change move color mechanism to use drag/drop 7d53028f [studio] Cleanup git-subtree-dir: deps/nostalgia git-subtree-split: be51838775cd37d8c0778378a5d944f8f261830c
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
#endif
|
||||
|
||||
#include <ox/event/signal.hpp>
|
||||
#include <ox/fs/fs.hpp>
|
||||
#include <ox/model/typenamecatcher.hpp>
|
||||
#include <ox/std/hashmap.hpp>
|
||||
#include <ox/std/utility.hpp>
|
||||
@@ -190,6 +189,8 @@ class AssetManager {
|
||||
public:
|
||||
~AssetTypeManagerBase() override = default;
|
||||
|
||||
virtual ox::Error updateAssetId(ox::StringViewCR oldId, ox::StringViewCR newId) noexcept = 0;
|
||||
|
||||
virtual void gc() noexcept = 0;
|
||||
};
|
||||
|
||||
@@ -202,7 +203,7 @@ class AssetManager {
|
||||
ox::HashMap<ox::String, ox::UPtr<AssetContainer<T>>> m_cache;
|
||||
|
||||
public:
|
||||
AssetTypeManager(Loader &&loader) noexcept: m_loader(std::move(loader)) {}
|
||||
explicit AssetTypeManager(Loader &&loader) noexcept: m_loader(std::move(loader)) {}
|
||||
|
||||
ox::Result<AssetRef<T>> getAsset(ox::StringViewCR assetId) const noexcept {
|
||||
OX_REQUIRE(out, m_cache.at(assetId));
|
||||
@@ -236,18 +237,33 @@ class AssetManager {
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error updateAssetId(ox::StringViewCR oldId, ox::StringViewCR newId) noexcept final {
|
||||
if (!m_cache.contains(oldId)) {
|
||||
return {};
|
||||
}
|
||||
auto &o = m_cache[oldId];
|
||||
auto &n = m_cache[newId];
|
||||
n = std::move(o);
|
||||
m_cache.erase(oldId);
|
||||
return {};
|
||||
}
|
||||
|
||||
void gc() noexcept final {
|
||||
for (auto const&ack : m_cache.keys()) {
|
||||
for (size_t i = 0; i < m_cache.keys().size();) {
|
||||
auto const &ack = m_cache.keys()[i];
|
||||
auto &ac = m_cache[ack];
|
||||
if (!ac->references()) {
|
||||
m_cache.erase(ack);
|
||||
continue;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
ox::HashMap<ox::String, ox::UPtr<AssetTypeManagerBase>> m_assetTypeManagers;
|
||||
ox::HashMap<ox::String, ox::Signal<ox::Error(ox::StringViewCR assetId)>> m_fileUpdated;
|
||||
ox::HashMap<ox::String, ox::UPtr<ox::Signal<ox::Error(ox::StringViewCR assetId)>>> m_fileUpdated;
|
||||
|
||||
template<typename T>
|
||||
ox::Result<AssetTypeManager<T>*> getTypeManager() noexcept {
|
||||
@@ -279,7 +295,7 @@ class AssetManager {
|
||||
}
|
||||
|
||||
ox::Error reloadAsset(ox::StringViewCR assetId) noexcept {
|
||||
m_fileUpdated[assetId].emit(assetId);
|
||||
m_fileUpdated[assetId]->emit(assetId);
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -287,15 +303,43 @@ class AssetManager {
|
||||
ox::Result<AssetRef<T>> loadAsset(ox::StringViewCR assetId) noexcept {
|
||||
OX_REQUIRE(m, getTypeManager<T>());
|
||||
OX_REQUIRE(out, m->loadAsset(assetId));
|
||||
m_fileUpdated[assetId].connect(m, &AssetTypeManager<T>::reloadAsset);
|
||||
if (!m_fileUpdated.contains(assetId)) [[unlikely]] {
|
||||
m_fileUpdated[assetId] = ox::make_unique<ox::Signal<ox::Error(ox::StringViewCR assetId)>>();
|
||||
}
|
||||
m_fileUpdated[assetId]->connect(m, &AssetTypeManager<T>::reloadAsset);
|
||||
return out;
|
||||
}
|
||||
|
||||
ox::Error updateAssetId(ox::StringViewCR oldId, ox::StringViewCR newId) noexcept {
|
||||
gc();
|
||||
if (m_fileUpdated.contains(newId)) {
|
||||
return ox::Error{1, "new asset ID already has an entry"};
|
||||
}
|
||||
if (!m_fileUpdated.contains(oldId)) {
|
||||
return {};
|
||||
}
|
||||
auto &o = m_fileUpdated[oldId];
|
||||
auto &n = m_fileUpdated[newId];
|
||||
n = std::move(o);
|
||||
m_fileUpdated.erase(oldId);
|
||||
for (auto &k : m_assetTypeManagers.keys()) {
|
||||
auto const &tm = m_assetTypeManagers[k];
|
||||
std::ignore = tm->updateAssetId(oldId, newId);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void gc() noexcept {
|
||||
for (auto const&amk : m_assetTypeManagers.keys()) {
|
||||
auto &am = m_assetTypeManagers[amk];
|
||||
am->gc();
|
||||
}
|
||||
for (auto const&k : m_fileUpdated.keys()) {
|
||||
auto &s = m_fileUpdated[k];
|
||||
if (s->connectionCnt() == 0) {
|
||||
m_fileUpdated.erase(k);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
#else
|
||||
|
@@ -47,6 +47,8 @@ ox::Result<ox::CStringView> getPath(Context &ctx, ox::FileAddress const&fileAddr
|
||||
|
||||
ox::Result<ox::CStringView> getPath(Context &ctx, ox::CStringViewCR fileId) noexcept;
|
||||
|
||||
ox::Error updatePath(Context &ctx, ox::StringViewCR oldPath, ox::StringViewCR newPath) noexcept;
|
||||
|
||||
constexpr ox::Result<ox::UUID> uuidUrlToUuid(ox::StringViewCR uuidUrl) noexcept {
|
||||
return ox::UUID::fromString(substr(uuidUrl, 7));
|
||||
}
|
||||
|
@@ -129,6 +129,21 @@ ox::Result<ox::CStringView> getPath(Context &ctx, ox::CStringViewCR fileId) noex
|
||||
}
|
||||
}
|
||||
|
||||
ox::Error updatePath(Context &ctx, ox::StringViewCR oldPath, ox::StringViewCR newPath) noexcept {
|
||||
#ifndef OX_BARE_METAL
|
||||
if (auto const r = ctx.pathToUuid.at(oldPath); r.ok()) {
|
||||
auto const ustr = r.value->toString();
|
||||
ctx.pathToUuid[newPath] = *r.value;
|
||||
ctx.pathToUuid.erase(oldPath);
|
||||
ctx.uuidToPath[ustr] = newPath;
|
||||
return {};
|
||||
}
|
||||
return ctx.assetManager.updateAssetId(oldPath, newPath);
|
||||
#else
|
||||
return ox::Error(1, "updating path is not supported on this platform");
|
||||
#endif
|
||||
}
|
||||
|
||||
ox::Result<ox::CStringView> uuidUrlToPath(Context &ctx, ox::StringViewCR uuid) noexcept {
|
||||
#ifndef OX_BARE_METAL
|
||||
OX_REQUIRE_M(out, ctx.uuidToPath.at(substr(uuid, 7)));
|
||||
|
@@ -39,10 +39,11 @@ static ox::Error pathToInode(
|
||||
auto const uuid = ox::substr(path, 7);
|
||||
OX_RETURN_ERROR(keel::uuidToPath(ctx, uuid).to<ox::String>().moveTo(path));
|
||||
}
|
||||
OX_REQUIRE(s, dest.stat(path));
|
||||
auto const s = dest.stat(path);
|
||||
auto const inode = s.ok() ? s.value.inode : 0;
|
||||
OX_RETURN_ERROR(typeVal->set(static_cast<int8_t>(ox::FileAddressType::Inode)));
|
||||
oxOutf("\tpath to inode: {} => {}\n", path, s.inode);
|
||||
return data.set(2, s.inode);
|
||||
oxOutf("\tpath to inode: {} => {}\n", path, inode);
|
||||
return data.set(2, inode);
|
||||
}
|
||||
|
||||
static ox::Error transformFileAddressesObj(
|
||||
|
Reference in New Issue
Block a user