Skip to content

Commit

Permalink
objects temp cache issues
Browse files Browse the repository at this point in the history
  • Loading branch information
1445643474 committed Nov 7, 2023
1 parent 1a1b4b5 commit ba3734a
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 37 deletions.
5 changes: 5 additions & 0 deletions ui/zenoedit/cache/zcachemgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,8 @@ bool ZCacheMgr::hasCacheOnly(QDir dir, bool& empty)
}
return bHasCacheOnly;
}

void ZCacheMgr::removeObjTmpCacheDir()
{
m_objTmpCacheDir.remove();
}
1 change: 1 addition & 0 deletions ui/zenoedit/cache/zcachemgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ZCacheMgr
cacheOption getCacheOption();
void cleanCacheDir();
bool hasCacheOnly(QDir dir, bool& empty);
void removeObjTmpCacheDir();

private:
QTemporaryDir m_objTmpCacheDir;
Expand Down
2 changes: 2 additions & 0 deletions ui/zenoedit/res/icons.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
<file>icons/ONCE_light.svg</file>
<file>icons/VIEW_dark.svg</file>
<file>icons/VIEW_light.svg</file>
<file>icons/CACHE_dark.svg</file>
<file>icons/CACHE_light.svg</file>
<file>icons/ic_openfile.svg</file>
<file>icons/ic_openfile-on.svg</file>
<file>icons/ic_MUTE.svg</file>
Expand Down
15 changes: 15 additions & 0 deletions ui/zenoedit/res/icons/CACHE_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions ui/zenoedit/res/icons/CACHE_light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion ui/zenoedit/res/icons/min_CACHE_light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions ui/zenoedit/zenomainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1339,9 +1339,12 @@ void ZenoMainWindow::closeEvent(QCloseEvent *event)
killOptix();

QSettings settings(zsCompanyName, zsEditor);
if (settings.value("zencache-autoclean").isValid() ? settings.value("zencache-autoclean").toBool() : true)
bool autoClean = settings.value("zencache-autoclean").isValid() ? settings.value("zencache-autoclean").toBool() : true;
bool autoRemove = settings.value("zencache-autoremove").isValid() ? settings.value("zencache-autoremove").toBool() : false;
std::shared_ptr<ZCacheMgr> mgr = zenoApp->cacheMgr();
mgr->removeObjTmpCacheDir();
if (autoClean || autoRemove)
{
std::shared_ptr<ZCacheMgr> mgr = zenoApp->cacheMgr();
mgr->cleanCacheDir();
}

Expand Down
6 changes: 3 additions & 3 deletions ui/zenoui/comctrl/gv/zenoparamwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1373,9 +1373,9 @@ ZenoMinStatusBtnItem::ZenoMinStatusBtnItem(const StatusComponent& statusComp, QG
ZenoStyle::dpiScaledSize(QSize(50, 42)),
this);
m_cache = new ZenoImageItem(
":/icons/ONCE_dark.svg",
":/icons/ONCE_light.svg",
":/icons/ONCE_light.svg",
":/icons/CACHE_dark.svg",
":/icons/CACHE_light.svg",
":/icons/CACHE_light.svg",
ZenoStyle::dpiScaledSize(QSize(50, 42)),
this);
//m_once->setFlag(QGraphicsItem::ItemIgnoresTransformations);
Expand Down
4 changes: 2 additions & 2 deletions zeno/include/zeno/extra/GlobalComm.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ struct GlobalComm {
ZENO_API std::string cachePath();
ZENO_API bool removeCache(int frame);
ZENO_API void removeCachePath();
static void toDisk(std::string cachedir, int frameid, GlobalComm::ViewObjects& objs, bool cacheLightCameraOnly, bool cacheMaterialOnly, std::vector<std::string> strVec = std::vector<std::string>());
static bool fromDisk(std::string cachedir, int frameid, GlobalComm::ViewObjects& objs, std::vector<std::string> strVec = std::vector<std::string>());
static void toDisk(std::string cachedir, int frameid, GlobalComm::ViewObjects& objs, bool cacheLightCameraOnly, bool cacheMaterialOnly, std::string fileName = "");
static bool fromDisk(std::string cachedir, int frameid, GlobalComm::ViewObjects& objs, std::string fileName = "");
private:
ViewObjects const *_getViewObjects(const int frameid);
};
Expand Down
8 changes: 2 additions & 6 deletions zeno/src/core/INode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,9 @@ ZENO_API void INode::complete() {}
ZENO_API bool zeno::INode::getTmpCache()
{
GlobalComm::ViewObjects objs;
std::vector<std::string> vec;
std::string fileName = myname + ".zenocache";
vec.push_back(fileName);
log_debug("get cache {}", fileName);
bool ret = GlobalComm::fromDisk(zeno::getSession().globalComm->objTmpCachePath, zeno::getSession().globalState->frameid, objs, vec);
bool ret = GlobalComm::fromDisk(zeno::getSession().globalComm->objTmpCachePath, zeno::getSession().globalState->frameid, objs, fileName);
if (ret)
{
for (const auto& [key, obj] : objs)
Expand All @@ -102,10 +100,8 @@ ZENO_API void zeno::INode::writeTmpCaches()

}
int frameid = zeno::getSession().globalState->frameid;
std::vector<std::string> vec;
std::string fileName = myname + ".zenocache";
vec.push_back(fileName);
GlobalComm::toDisk(zeno::getSession().globalComm->objTmpCachePath, frameid, objs, false, false, vec);
GlobalComm::toDisk(zeno::getSession().globalComm->objTmpCachePath, frameid, objs, false, false, fileName);
}

ZENO_API void INode::preApply() {
Expand Down
49 changes: 26 additions & 23 deletions zeno/src/extra/GlobalComm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ std::unordered_set<std::string> lightCameraNodes({
});
std::string matlNode = "ShaderFinalize";

void GlobalComm::toDisk(std::string cachedir, int frameid, GlobalComm::ViewObjects &objs, bool cacheLightCameraOnly, bool cacheMaterialOnly, std::vector<std::string> strVec) {
void GlobalComm::toDisk(std::string cachedir, int frameid, GlobalComm::ViewObjects &objs, bool cacheLightCameraOnly, bool cacheMaterialOnly, std::string fileName) {
if (cachedir.empty()) return;
std::filesystem::path dir = std::filesystem::u8path(cachedir + "/" + std::to_string(1000000 + frameid).substr(1));
if (!std::filesystem::exists(dir) && !std::filesystem::create_directories(dir))
Expand Down Expand Up @@ -89,18 +89,20 @@ void GlobalComm::toDisk(std::string cachedir, int frameid, GlobalComm::ViewObjec
}
}

if (strVec.size() == 0)
if (fileName == "")
{
strVec.push_back("lightCameraObj.zencache");
strVec.push_back("materialObj.zencache");
strVec.push_back("normalObj.zencache");
cachepath[0] = dir / "lightCameraObj.zencache";
cachepath[1] = dir / "materialObj.zencache";
cachepath[2] = dir / "normalObj.zencache";
}
else
{
cachepath[2] = dir / fileName;
}
size_t currentFrameSize = 0;
for (int i = 0; i < strVec.size(); i++)
for (int i = 0; i < 3; i++)
{
if (strVec.size() == 1)
i = 2;
if (poses[i].size() == 0 && (cacheLightCameraOnly && i != 0 || cacheMaterialOnly && i != 1))
if (poses[i].size() == 0 && (cacheLightCameraOnly && i != 0 || cacheMaterialOnly && i != 1 || fileName != "" && i != 2))
continue;
keys[i].push_back('\a');
keys[i] = "ZENCACHE" + std::to_string(poses[i].size()) + keys[i];
Expand Down Expand Up @@ -130,15 +132,12 @@ void GlobalComm::toDisk(std::string cachedir, int frameid, GlobalComm::ViewObjec
freeSpace = std::filesystem::space(std::filesystem::u8path(cachedir)).free;
#endif
}
for (int i = 0; i < strVec.size(); i++)
for (int i = 0; i < 3; i++)
{
auto path = dir / strVec[i];
if (strVec.size() == 1)
i = 2;
if (poses[i].size() == 0 && (cacheLightCameraOnly && i != 0 || cacheMaterialOnly && i != 1))
if (poses[i].size() == 0 && (cacheLightCameraOnly && i != 0 || cacheMaterialOnly && i != 1 || fileName != "" && i != 2))
continue;
log_critical("dump cache to disk {}", path);
std::ofstream ofs(path, std::ios::binary);
log_critical("dump cache to disk {}", cachepath[i]);
std::ofstream ofs(cachepath[i], std::ios::binary);
std::ostreambuf_iterator<char> oit(ofs);
std::copy(keys[i].begin(), keys[i].end(), oit);
std::copy_n((const char *)poses[i].data(), poses[i].size() * sizeof(size_t), oit);
Expand All @@ -147,20 +146,24 @@ void GlobalComm::toDisk(std::string cachedir, int frameid, GlobalComm::ViewObjec
objs.clear();
}

bool GlobalComm::fromDisk(std::string cachedir, int frameid, GlobalComm::ViewObjects &objs, std::vector<std::string> strVec) {
bool GlobalComm::fromDisk(std::string cachedir, int frameid, GlobalComm::ViewObjects &objs, std::string fileName) {
if (cachedir.empty())
return false;
objs.clear();
if (strVec.size() == 0)
auto dir = std::filesystem::u8path(cachedir) / std::to_string(1000000 + frameid).substr(1);
if (fileName == "")
{
cachepath[0] = dir / "lightCameraObj.zencache";
cachepath[1] = dir / "materialObj.zencache";
cachepath[2] = dir / "normalObj.zencache";
}
else
{
strVec.push_back("lightCameraObj.zencache");
strVec.push_back("materialObj.zencache");
strVec.push_back("normalObj.zencache");
cachepath[2] = dir / fileName;
}

for (auto str : strVec)
for (auto path : cachepath)
{
auto path = std::filesystem::u8path(cachedir) / std::to_string(1000000 + frameid).substr(1) / str;
if (!std::filesystem::exists(path))
{
continue;
Expand Down

0 comments on commit ba3734a

Please sign in to comment.