2016-03-26 00:51:59 +00:00
|
|
|
#include "ProjectResourceFactoryBase.hpp"
|
|
|
|
#include "Runtime/IObj.hpp"
|
|
|
|
|
2016-04-16 03:24:25 +00:00
|
|
|
#define DUMP_CACHE_FILL 1
|
|
|
|
|
2016-03-26 00:51:59 +00:00
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
static logvisor::Module Log("urde::ProjectResourceFactoryBase");
|
|
|
|
|
|
|
|
void ProjectResourceFactoryBase::Clear()
|
|
|
|
{
|
|
|
|
m_tagToPath.clear();
|
|
|
|
m_catalogNameToTag.clear();
|
|
|
|
}
|
|
|
|
|
2016-03-28 21:38:48 +00:00
|
|
|
void ProjectResourceFactoryBase::ReadCatalog(const hecl::ProjectPath& catalogPath,
|
|
|
|
athena::io::YAMLDocWriter& nameWriter)
|
2016-03-26 00:51:59 +00:00
|
|
|
{
|
2016-08-22 03:47:48 +00:00
|
|
|
athena::io::FileReader freader(catalogPath.getAbsolutePath());
|
|
|
|
if (!freader.isOpen())
|
2016-03-26 00:51:59 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
athena::io::YAMLDocReader reader;
|
2016-08-22 03:47:48 +00:00
|
|
|
bool res = reader.parse(&freader);
|
2016-03-26 00:51:59 +00:00
|
|
|
if (!res)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const athena::io::YAMLNode* root = reader.getRootNode();
|
|
|
|
for (const auto& p : root->m_mapChildren)
|
|
|
|
{
|
|
|
|
hecl::ProjectPath path(m_proj->getProjectWorkingPath(), p.second->m_scalarString);
|
|
|
|
if (path.getPathType() != hecl::ProjectPath::Type::File)
|
|
|
|
continue;
|
2016-03-31 21:06:41 +00:00
|
|
|
SObjectTag pathTag = TagFromPath(path, m_backgroundBlender);
|
2016-03-26 00:51:59 +00:00
|
|
|
if (pathTag)
|
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> lk(m_backgroundIndexMutex);
|
|
|
|
m_catalogNameToTag[p.first] = pathTag;
|
2016-03-28 21:38:48 +00:00
|
|
|
|
|
|
|
char idStr[9];
|
|
|
|
snprintf(idStr, 9, "%08X", uint32_t(pathTag.id));
|
|
|
|
nameWriter.writeString(p.first.c_str(), idStr);
|
2016-03-28 04:36:55 +00:00
|
|
|
#if 0
|
|
|
|
fprintf(stderr, "%s %s %08X\n",
|
|
|
|
p.first.c_str(),
|
|
|
|
pathTag.type.toString().c_str(), uint32_t(pathTag.id));
|
|
|
|
#endif
|
2016-03-26 00:51:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-28 21:38:48 +00:00
|
|
|
void ProjectResourceFactoryBase::BackgroundIndexRecursiveCatalogs(const hecl::ProjectPath& dir,
|
|
|
|
athena::io::YAMLDocWriter& nameWriter,
|
|
|
|
int level)
|
|
|
|
{
|
|
|
|
hecl::DirectoryEnumerator dEnum(dir.getAbsolutePath(),
|
|
|
|
hecl::DirectoryEnumerator::Mode::DirsThenFilesSorted,
|
|
|
|
false, false, true);
|
|
|
|
|
|
|
|
/* Enumerate all items */
|
|
|
|
for (const hecl::DirectoryEnumerator::Entry& ent : dEnum)
|
|
|
|
{
|
|
|
|
hecl::ProjectPath path(dir, ent.m_name);
|
|
|
|
if (ent.m_isDir && level < 1)
|
|
|
|
BackgroundIndexRecursiveCatalogs(path, nameWriter, level+1);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (path.getPathType() != hecl::ProjectPath::Type::File)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Read catalog.yaml for .pak directory if exists */
|
|
|
|
if (level == 1 && !ent.m_name.compare(_S("catalog.yaml")))
|
|
|
|
{
|
|
|
|
ReadCatalog(path, nameWriter);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* bail if cancelled by client */
|
|
|
|
if (!m_backgroundRunning)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-05 01:51:25 +00:00
|
|
|
static void WriteTag(athena::io::YAMLDocWriter& cacheWriter,
|
|
|
|
const SObjectTag& pathTag, const hecl::ProjectPath& path)
|
|
|
|
{
|
|
|
|
char idStr[9];
|
|
|
|
snprintf(idStr, 9, "%08X", uint32_t(pathTag.id));
|
|
|
|
cacheWriter.enterSubVector(idStr);
|
|
|
|
cacheWriter.writeString(nullptr, pathTag.type.toString().c_str());
|
|
|
|
cacheWriter.writeString(nullptr, path.getRelativePathUTF8().c_str());
|
2016-08-31 01:13:58 +00:00
|
|
|
if (path.getAuxInfo().size())
|
|
|
|
cacheWriter.writeString(nullptr, path.getAuxInfoUTF8().c_str());
|
2016-04-05 01:51:25 +00:00
|
|
|
cacheWriter.leaveSubVector();
|
|
|
|
}
|
|
|
|
|
2016-04-16 03:24:25 +00:00
|
|
|
#if DUMP_CACHE_FILL
|
|
|
|
static void DumpCacheAdd(const SObjectTag& pathTag, const hecl::ProjectPath& path)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s %08X %s\n",
|
|
|
|
pathTag.type.toString().c_str(), uint32_t(pathTag.id),
|
|
|
|
path.getRelativePathUTF8().c_str());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-03-28 21:38:48 +00:00
|
|
|
void ProjectResourceFactoryBase::BackgroundIndexRecursiveProc(const hecl::ProjectPath& dir,
|
|
|
|
athena::io::YAMLDocWriter& cacheWriter,
|
|
|
|
athena::io::YAMLDocWriter& nameWriter,
|
|
|
|
int level)
|
2016-03-26 00:51:59 +00:00
|
|
|
{
|
2016-03-28 04:36:55 +00:00
|
|
|
hecl::DirectoryEnumerator dEnum(dir.getAbsolutePath(),
|
2016-03-26 00:51:59 +00:00
|
|
|
hecl::DirectoryEnumerator::Mode::DirsThenFilesSorted,
|
|
|
|
false, false, true);
|
|
|
|
|
|
|
|
/* Enumerate all items */
|
|
|
|
for (const hecl::DirectoryEnumerator::Entry& ent : dEnum)
|
|
|
|
{
|
2016-03-28 04:36:55 +00:00
|
|
|
hecl::ProjectPath path(dir, ent.m_name);
|
2016-03-26 00:51:59 +00:00
|
|
|
if (ent.m_isDir)
|
2016-03-28 21:38:48 +00:00
|
|
|
BackgroundIndexRecursiveProc(path, cacheWriter, nameWriter, level+1);
|
2016-03-26 00:51:59 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (path.getPathType() != hecl::ProjectPath::Type::File)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Read catalog.yaml for .pak directory if exists */
|
|
|
|
if (level == 1 && !ent.m_name.compare(_S("catalog.yaml")))
|
|
|
|
{
|
2016-03-28 21:38:48 +00:00
|
|
|
ReadCatalog(path, nameWriter);
|
2016-03-26 00:51:59 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Classify intermediate into tag */
|
2016-03-31 21:06:41 +00:00
|
|
|
SObjectTag pathTag = TagFromPath(path, m_backgroundBlender);
|
2016-03-26 00:51:59 +00:00
|
|
|
if (pathTag)
|
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> lk(m_backgroundIndexMutex);
|
|
|
|
m_tagToPath[pathTag] = path;
|
2016-04-05 01:51:25 +00:00
|
|
|
WriteTag(cacheWriter, pathTag, path);
|
2016-04-16 03:24:25 +00:00
|
|
|
#if DUMP_CACHE_FILL
|
|
|
|
DumpCacheAdd(pathTag, path);
|
2016-03-28 04:36:55 +00:00
|
|
|
#endif
|
2016-04-05 01:51:25 +00:00
|
|
|
|
|
|
|
/* Special multi-resource intermediates */
|
2016-04-12 22:28:08 +00:00
|
|
|
if (pathTag.type == SBIG('ANCS'))
|
2016-04-05 01:51:25 +00:00
|
|
|
{
|
2016-04-07 03:40:25 +00:00
|
|
|
hecl::BlenderConnection& conn = m_backgroundBlender.getBlenderConnection();
|
|
|
|
if (!conn.openBlend(path) || conn.getBlendType() != hecl::BlenderConnection::BlendType::Actor)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
hecl::BlenderConnection::DataStream ds = conn.beginData();
|
|
|
|
std::vector<std::string> armatureNames = ds.getArmatureNames();
|
2016-04-12 22:28:08 +00:00
|
|
|
std::vector<std::string> subtypeNames = ds.getSubtypeNames();
|
2016-04-07 03:40:25 +00:00
|
|
|
std::vector<std::string> actionNames = ds.getActionNames();
|
|
|
|
|
|
|
|
for (const std::string& arm : armatureNames)
|
2016-04-05 01:51:25 +00:00
|
|
|
{
|
2016-04-07 03:40:25 +00:00
|
|
|
hecl::SystemStringView sysStr(arm);
|
2016-08-31 01:13:58 +00:00
|
|
|
hecl::ProjectPath subPath = path.ensureAuxInfo(sysStr.sys_str() + _S(".CINF"));
|
2016-04-12 22:28:08 +00:00
|
|
|
SObjectTag pathTag = TagFromPath(subPath, m_backgroundBlender);
|
2016-04-16 03:24:25 +00:00
|
|
|
m_tagToPath[pathTag] = subPath;
|
|
|
|
WriteTag(cacheWriter, pathTag, subPath);
|
|
|
|
#if DUMP_CACHE_FILL
|
|
|
|
DumpCacheAdd(pathTag, subPath);
|
|
|
|
#endif
|
2016-04-12 22:28:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (const std::string& sub : subtypeNames)
|
|
|
|
{
|
|
|
|
hecl::SystemStringView sysStr(sub);
|
2016-08-31 01:13:58 +00:00
|
|
|
hecl::ProjectPath subPath = path.ensureAuxInfo(sysStr.sys_str() + _S(".CSKR"));
|
2016-04-07 03:40:25 +00:00
|
|
|
SObjectTag pathTag = TagFromPath(subPath, m_backgroundBlender);
|
2016-04-16 03:24:25 +00:00
|
|
|
m_tagToPath[pathTag] = subPath;
|
|
|
|
WriteTag(cacheWriter, pathTag, subPath);
|
|
|
|
#if DUMP_CACHE_FILL
|
|
|
|
DumpCacheAdd(pathTag, subPath);
|
|
|
|
#endif
|
2016-04-07 03:40:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (const std::string& act : actionNames)
|
|
|
|
{
|
|
|
|
hecl::SystemStringView sysStr(act);
|
2016-08-31 01:13:58 +00:00
|
|
|
hecl::ProjectPath subPath = path.ensureAuxInfo(sysStr.sys_str() + _S(".ANIM"));
|
2016-04-07 03:40:25 +00:00
|
|
|
SObjectTag pathTag = TagFromPath(subPath, m_backgroundBlender);
|
2016-04-16 03:24:25 +00:00
|
|
|
m_tagToPath[pathTag] = subPath;
|
|
|
|
WriteTag(cacheWriter, pathTag, subPath);
|
|
|
|
#if DUMP_CACHE_FILL
|
|
|
|
DumpCacheAdd(pathTag, subPath);
|
|
|
|
#endif
|
2016-04-05 01:51:25 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-26 00:51:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* bail if cancelled by client */
|
|
|
|
if (!m_backgroundRunning)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectResourceFactoryBase::BackgroundIndexProc()
|
|
|
|
{
|
2016-03-28 21:38:48 +00:00
|
|
|
hecl::ProjectPath tagCachePath(m_proj->getProjectCookedPath(*m_origSpec), _S("tag_cache.yaml"));
|
|
|
|
hecl::ProjectPath nameCachePath(m_proj->getProjectCookedPath(*m_origSpec), _S("name_cache.yaml"));
|
2016-03-26 00:51:59 +00:00
|
|
|
hecl::ProjectPath specRoot(m_proj->getProjectWorkingPath(), m_origSpec->m_name);
|
2016-03-28 21:38:48 +00:00
|
|
|
|
|
|
|
/* Read in tag cache */
|
|
|
|
if (tagCachePath.getPathType() == hecl::ProjectPath::Type::File)
|
|
|
|
{
|
2016-08-22 03:47:48 +00:00
|
|
|
athena::io::FileReader reader(tagCachePath.getAbsolutePath());
|
|
|
|
if (reader.isOpen())
|
2016-03-28 21:38:48 +00:00
|
|
|
{
|
|
|
|
Log.report(logvisor::Info, _S("Cache index of '%s' loading"), m_origSpec->m_name);
|
|
|
|
athena::io::YAMLDocReader cacheReader;
|
2016-08-22 03:47:48 +00:00
|
|
|
if (cacheReader.parse(&reader))
|
2016-03-28 21:38:48 +00:00
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> lk(m_backgroundIndexMutex);
|
|
|
|
m_tagToPath.reserve(cacheReader.getRootNode()->m_mapChildren.size());
|
2016-04-03 05:25:34 +00:00
|
|
|
size_t loadIdx = 0;
|
2016-03-28 21:38:48 +00:00
|
|
|
for (const auto& child : cacheReader.getRootNode()->m_mapChildren)
|
|
|
|
{
|
2016-08-31 01:13:58 +00:00
|
|
|
const athena::io::YAMLNode& node = *child.second;
|
2016-03-28 21:38:48 +00:00
|
|
|
unsigned long id = strtoul(child.first.c_str(), nullptr, 16);
|
2016-08-31 01:13:58 +00:00
|
|
|
hecl::FourCC type(node.m_seqChildren.at(0)->m_scalarString.c_str());
|
2016-03-28 21:38:48 +00:00
|
|
|
hecl::ProjectPath path(m_proj->getProjectWorkingPath(),
|
2016-08-31 01:13:58 +00:00
|
|
|
node.m_seqChildren.at(1)->m_scalarString);
|
|
|
|
if (node.m_seqChildren.size() >= 3)
|
|
|
|
{
|
|
|
|
hecl::SystemStringView sys(node.m_seqChildren[2]->m_scalarString);
|
|
|
|
path = path.ensureAuxInfo(sys.sys_str());
|
|
|
|
}
|
2016-03-28 21:38:48 +00:00
|
|
|
m_tagToPath[SObjectTag(type, id)] = path;
|
2016-08-31 01:13:58 +00:00
|
|
|
fprintf(stderr, "\r %" PRISize " / %" PRISize, ++loadIdx,
|
2016-04-03 05:25:34 +00:00
|
|
|
cacheReader.getRootNode()->m_mapChildren.size());
|
2016-03-28 21:38:48 +00:00
|
|
|
}
|
2016-04-03 05:25:34 +00:00
|
|
|
fprintf(stderr, "\n");
|
2016-03-28 21:38:48 +00:00
|
|
|
}
|
|
|
|
Log.report(logvisor::Info, _S("Cache index of '%s' loaded; %d tags"),
|
|
|
|
m_origSpec->m_name, m_tagToPath.size());
|
|
|
|
|
|
|
|
if (nameCachePath.getPathType() == hecl::ProjectPath::Type::File)
|
|
|
|
{
|
|
|
|
/* Read in name cache */
|
|
|
|
Log.report(logvisor::Info, _S("Name index of '%s' loading"), m_origSpec->m_name);
|
2016-08-22 03:47:48 +00:00
|
|
|
athena::io::FileReader nreader(nameCachePath.getAbsolutePath());
|
2016-03-28 21:38:48 +00:00
|
|
|
athena::io::YAMLDocReader nameReader;
|
2016-08-22 03:47:48 +00:00
|
|
|
if (nameReader.parse(&nreader))
|
2016-03-28 21:38:48 +00:00
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> lk(m_backgroundIndexMutex);
|
|
|
|
m_catalogNameToTag.reserve(nameReader.getRootNode()->m_mapChildren.size());
|
|
|
|
for (const auto& child : nameReader.getRootNode()->m_mapChildren)
|
|
|
|
{
|
|
|
|
unsigned long id = strtoul(child.second->m_scalarString.c_str(), nullptr, 16);
|
|
|
|
auto search = m_tagToPath.find(SObjectTag(FourCC(), uint32_t(id)));
|
|
|
|
if (search != m_tagToPath.cend())
|
|
|
|
m_catalogNameToTag[child.first] = search->first;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Log.report(logvisor::Info, _S("Name index of '%s' loaded; %d names"),
|
|
|
|
m_origSpec->m_name, m_catalogNameToTag.size());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Build name cache */
|
|
|
|
Log.report(logvisor::Info, _S("Name index of '%s' started"), m_origSpec->m_name);
|
|
|
|
athena::io::YAMLDocWriter nameWriter(nullptr);
|
|
|
|
BackgroundIndexRecursiveCatalogs(specRoot, nameWriter, 0);
|
2016-08-22 03:47:48 +00:00
|
|
|
athena::io::FileWriter nwriter(nameCachePath.getAbsolutePath());
|
|
|
|
nameWriter.finish(&nwriter);
|
2016-03-28 21:38:48 +00:00
|
|
|
Log.report(logvisor::Info, _S("Name index of '%s' complete; %d names"),
|
|
|
|
m_origSpec->m_name, m_catalogNameToTag.size());
|
|
|
|
}
|
|
|
|
m_backgroundRunning = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Log.report(logvisor::Info, _S("Background index of '%s' started"), m_origSpec->m_name);
|
|
|
|
athena::io::YAMLDocWriter cacheWriter(nullptr);
|
|
|
|
athena::io::YAMLDocWriter nameWriter(nullptr);
|
|
|
|
BackgroundIndexRecursiveProc(specRoot, cacheWriter, nameWriter, 0);
|
|
|
|
|
2016-07-07 04:23:36 +00:00
|
|
|
tagCachePath.makeDirChain(false);
|
2016-08-22 03:47:48 +00:00
|
|
|
athena::io::FileWriter twriter(tagCachePath.getAbsolutePath());
|
|
|
|
cacheWriter.finish(&twriter);
|
|
|
|
|
|
|
|
athena::io::FileWriter nwriter(nameCachePath.getAbsolutePath());
|
|
|
|
nameWriter.finish(&nwriter);
|
2016-03-28 21:38:48 +00:00
|
|
|
|
2016-03-31 21:06:41 +00:00
|
|
|
m_backgroundBlender.shutdown();
|
2016-03-28 21:38:48 +00:00
|
|
|
Log.report(logvisor::Info, _S("Background index of '%s' complete; %d tags, %d names"),
|
|
|
|
m_origSpec->m_name, m_tagToPath.size(), m_catalogNameToTag.size());
|
2016-03-26 00:51:59 +00:00
|
|
|
m_backgroundRunning = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectResourceFactoryBase::CancelBackgroundIndex()
|
|
|
|
{
|
2016-03-28 22:39:56 +00:00
|
|
|
m_backgroundRunning = false;
|
|
|
|
if (m_backgroundIndexTh.joinable())
|
|
|
|
m_backgroundIndexTh.join();
|
2016-03-26 00:51:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectResourceFactoryBase::BeginBackgroundIndex
|
2016-03-28 04:36:55 +00:00
|
|
|
(hecl::Database::Project& proj,
|
2016-03-26 00:51:59 +00:00
|
|
|
const hecl::Database::DataSpecEntry& origSpec,
|
|
|
|
const hecl::Database::DataSpecEntry& pcSpec)
|
|
|
|
{
|
|
|
|
CancelBackgroundIndex();
|
|
|
|
Clear();
|
|
|
|
m_proj = &proj;
|
|
|
|
m_origSpec = &origSpec;
|
|
|
|
m_pcSpec = &pcSpec;
|
2016-03-28 04:36:55 +00:00
|
|
|
m_cookSpec.reset(pcSpec.m_factory(proj, hecl::Database::DataSpecTool::Cook));
|
2016-03-26 00:51:59 +00:00
|
|
|
m_backgroundRunning = true;
|
|
|
|
m_backgroundIndexTh =
|
|
|
|
std::thread(std::bind(&ProjectResourceFactoryBase::BackgroundIndexProc, this));
|
|
|
|
}
|
|
|
|
|
2016-03-28 04:36:55 +00:00
|
|
|
hecl::ProjectPath ProjectResourceFactoryBase::GetCookedPath(const hecl::ProjectPath& working,
|
|
|
|
bool pcTarget) const
|
|
|
|
{
|
|
|
|
const hecl::Database::DataSpecEntry* spec = m_origSpec;
|
|
|
|
if (pcTarget)
|
2016-03-28 22:39:56 +00:00
|
|
|
spec = m_cookSpec->overrideDataSpec(working, m_pcSpec, hecl::SharedBlenderToken);
|
2016-03-28 04:36:55 +00:00
|
|
|
if (!spec)
|
|
|
|
return {};
|
2016-08-31 01:13:58 +00:00
|
|
|
return working.getCookedPath(*spec);
|
2016-03-28 04:36:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ProjectResourceFactoryBase::SyncCook(const hecl::ProjectPath& working)
|
|
|
|
{
|
2016-03-28 22:39:56 +00:00
|
|
|
return m_clientProc.syncCook(working, m_cookSpec.get(), hecl::SharedBlenderToken);
|
2016-03-28 04:36:55 +00:00
|
|
|
}
|
|
|
|
|
2016-03-29 23:14:14 +00:00
|
|
|
CFactoryFnReturn ProjectResourceFactoryBase::BuildSync(const SObjectTag& tag,
|
|
|
|
const hecl::ProjectPath& path,
|
2016-09-02 19:32:57 +00:00
|
|
|
const CVParamTransfer& paramXfer,
|
|
|
|
CObjectReference* selfRef)
|
2016-03-26 00:51:59 +00:00
|
|
|
{
|
|
|
|
/* Ensure cooked rep is on the filesystem */
|
2016-07-23 21:41:18 +00:00
|
|
|
std::experimental::optional<athena::io::FileReader> fr;
|
|
|
|
if (!PrepForReadSync(tag, path, fr))
|
2016-03-26 00:51:59 +00:00
|
|
|
return {};
|
|
|
|
|
|
|
|
/* All good, build resource */
|
2016-03-29 23:14:14 +00:00
|
|
|
if (m_factoryMgr.CanMakeMemory(tag))
|
|
|
|
{
|
2016-07-23 21:41:18 +00:00
|
|
|
u32 length = fr->length();
|
|
|
|
std::unique_ptr<u8[]> memBuf = fr->readUBytes(length);
|
2016-09-02 19:32:57 +00:00
|
|
|
return m_factoryMgr.MakeObjectFromMemory(tag, std::move(memBuf), length, false, paramXfer, selfRef);
|
2016-03-29 23:14:14 +00:00
|
|
|
}
|
|
|
|
|
2016-09-02 19:32:57 +00:00
|
|
|
return m_factoryMgr.MakeObject(tag, *fr, paramXfer, selfRef);
|
2016-03-26 00:51:59 +00:00
|
|
|
}
|
|
|
|
|
2016-03-31 21:06:41 +00:00
|
|
|
void ProjectResourceFactoryBase::AsyncTask::EnsurePath(const urde::SObjectTag& tag,
|
|
|
|
const hecl::ProjectPath& path)
|
2016-03-28 04:36:55 +00:00
|
|
|
{
|
|
|
|
if (!m_workingPath)
|
|
|
|
{
|
|
|
|
m_workingPath = path;
|
|
|
|
|
|
|
|
/* Ensure requested resource is on the filesystem */
|
|
|
|
if (path.getPathType() != hecl::ProjectPath::Type::File)
|
|
|
|
{
|
|
|
|
Log.report(logvisor::Error, _S("unable to find resource path '%s'"),
|
2016-03-31 21:06:41 +00:00
|
|
|
path.getRelativePath().c_str());
|
|
|
|
m_failed = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Last chance type validation */
|
|
|
|
urde::SObjectTag verifyTag = m_parent.TagFromPath(path, hecl::SharedBlenderToken);
|
|
|
|
if (verifyTag.type != tag.type)
|
|
|
|
{
|
|
|
|
Log.report(logvisor::Error, _S("%s: expected type '%.4s', found '%.4s'"),
|
|
|
|
path.getRelativePath().c_str(),
|
|
|
|
tag.type.toString().c_str(), verifyTag.type.toString().c_str());
|
2016-03-28 04:36:55 +00:00
|
|
|
m_failed = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get cooked representation path */
|
|
|
|
m_cookedPath = m_parent.GetCookedPath(path, true);
|
|
|
|
|
|
|
|
/* Perform mod-time comparison */
|
|
|
|
if (m_cookedPath.getPathType() != hecl::ProjectPath::Type::File ||
|
|
|
|
m_cookedPath.getModtime() < path.getModtime())
|
|
|
|
{
|
|
|
|
/* Start a background cook here */
|
2016-03-28 22:39:56 +00:00
|
|
|
m_cookTransaction = m_parent.m_clientProc.addCookTransaction(path, m_parent.m_cookSpec.get());
|
2016-03-28 04:36:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CookComplete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectResourceFactoryBase::AsyncTask::CookComplete()
|
|
|
|
{
|
|
|
|
/* Ensure cooked rep is on the filesystem */
|
|
|
|
athena::io::FileReader fr(m_cookedPath.getAbsolutePath(), 32 * 1024, false);
|
|
|
|
if (fr.hasError())
|
|
|
|
{
|
|
|
|
Log.report(logvisor::Error, _S("unable to open cooked resource path '%s'"),
|
|
|
|
m_cookedPath.getAbsolutePath().c_str());
|
|
|
|
m_failed = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ready for buffer transaction at this point */
|
2016-07-30 03:53:45 +00:00
|
|
|
u32 availSz = std::max(0, s32(fr.length()) - s32(x14_resOffset));
|
2016-08-31 23:31:12 +00:00
|
|
|
x14_resSize = std::min(x14_resSize, availSz);
|
|
|
|
x10_loadBuffer.reset(new u8[x14_resSize]);
|
2016-03-28 04:36:55 +00:00
|
|
|
m_bufTransaction = m_parent.m_clientProc.addBufferTransaction(m_cookedPath,
|
|
|
|
x10_loadBuffer.get(),
|
2016-08-31 23:31:12 +00:00
|
|
|
x14_resSize, x14_resOffset);
|
2016-03-28 04:36:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ProjectResourceFactoryBase::AsyncTask::AsyncPump()
|
|
|
|
{
|
|
|
|
if (m_failed)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (m_bufTransaction)
|
|
|
|
{
|
|
|
|
if (m_bufTransaction->m_complete)
|
2016-03-28 21:38:48 +00:00
|
|
|
{
|
|
|
|
m_complete = true;
|
2016-03-28 04:36:55 +00:00
|
|
|
return true;
|
2016-03-28 21:38:48 +00:00
|
|
|
}
|
2016-03-28 04:36:55 +00:00
|
|
|
}
|
|
|
|
else if (m_cookTransaction)
|
|
|
|
{
|
|
|
|
if (m_cookTransaction->m_complete)
|
|
|
|
CookComplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_failed;
|
|
|
|
}
|
|
|
|
|
2016-07-23 21:41:18 +00:00
|
|
|
bool ProjectResourceFactoryBase::WaitForTagReady(const urde::SObjectTag& tag, const hecl::ProjectPath*& pathOut)
|
2016-03-26 00:51:59 +00:00
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> lk(m_backgroundIndexMutex);
|
|
|
|
auto search = m_tagToPath.find(tag);
|
|
|
|
if (search == m_tagToPath.end())
|
|
|
|
{
|
|
|
|
if (m_backgroundRunning)
|
|
|
|
{
|
|
|
|
while (m_backgroundRunning)
|
|
|
|
{
|
|
|
|
lk.unlock();
|
|
|
|
lk.lock();
|
|
|
|
search = m_tagToPath.find(tag);
|
|
|
|
if (search != m_tagToPath.end())
|
|
|
|
break;
|
|
|
|
}
|
2016-03-28 21:38:48 +00:00
|
|
|
if (search == m_tagToPath.end())
|
2016-07-23 21:41:18 +00:00
|
|
|
return false;
|
2016-03-26 00:51:59 +00:00
|
|
|
}
|
|
|
|
else
|
2016-07-23 21:41:18 +00:00
|
|
|
return false;
|
2016-03-26 00:51:59 +00:00
|
|
|
}
|
2016-03-31 21:06:41 +00:00
|
|
|
lk.unlock();
|
2016-07-23 21:41:18 +00:00
|
|
|
pathOut = &search->second;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ProjectResourceFactoryBase::PrepForReadSync(const SObjectTag& tag,
|
|
|
|
const hecl::ProjectPath& path,
|
|
|
|
std::experimental::optional<athena::io::FileReader>& fr)
|
|
|
|
{
|
|
|
|
/* Ensure requested resource is on the filesystem */
|
|
|
|
if (path.getPathType() != hecl::ProjectPath::Type::File)
|
|
|
|
{
|
|
|
|
Log.report(logvisor::Error, _S("unable to find resource path '%s'"),
|
|
|
|
path.getAbsolutePath().c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Last chance type validation */
|
|
|
|
urde::SObjectTag verifyTag = TagFromPath(path, hecl::SharedBlenderToken);
|
|
|
|
if (verifyTag.type != tag.type)
|
|
|
|
{
|
|
|
|
Log.report(logvisor::Error, _S("%s: expected type '%.4s', found '%.4s'"),
|
|
|
|
path.getRelativePath().c_str(),
|
|
|
|
tag.type.toString().c_str(), verifyTag.type.toString().c_str());
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-26 00:51:59 +00:00
|
|
|
|
2016-07-23 21:41:18 +00:00
|
|
|
/* Get cooked representation path */
|
|
|
|
hecl::ProjectPath cooked = GetCookedPath(path, true);
|
|
|
|
|
|
|
|
/* Perform mod-time comparison */
|
|
|
|
if (cooked.getPathType() != hecl::ProjectPath::Type::File ||
|
|
|
|
cooked.getModtime() < path.getModtime())
|
|
|
|
{
|
|
|
|
/* Do a blocking cook here */
|
|
|
|
if (!SyncCook(path))
|
|
|
|
{
|
|
|
|
Log.report(logvisor::Error, _S("unable to cook resource path '%s'"),
|
|
|
|
path.getAbsolutePath().c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ensure cooked rep is on the filesystem */
|
|
|
|
fr.emplace(cooked.getAbsolutePath(), 32 * 1024, false);
|
|
|
|
if (fr->hasError())
|
|
|
|
{
|
|
|
|
Log.report(logvisor::Error, _S("unable to open cooked resource path '%s'"),
|
|
|
|
cooked.getAbsolutePath().c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<urde::IObj> ProjectResourceFactoryBase::Build(const urde::SObjectTag& tag,
|
2016-09-02 19:32:57 +00:00
|
|
|
const urde::CVParamTransfer& paramXfer,
|
|
|
|
CObjectReference* selfRef)
|
2016-07-23 21:41:18 +00:00
|
|
|
{
|
|
|
|
const hecl::ProjectPath* resPath = nullptr;
|
|
|
|
if (!WaitForTagReady(tag, resPath))
|
|
|
|
return {};
|
2016-04-01 01:00:37 +00:00
|
|
|
auto asyncSearch = m_asyncLoadList.find(tag);
|
|
|
|
if (asyncSearch != m_asyncLoadList.end())
|
|
|
|
{
|
|
|
|
/* Async spinloop */
|
2016-08-08 04:48:18 +00:00
|
|
|
AsyncTask& task = *asyncSearch->second;
|
2016-07-23 21:41:18 +00:00
|
|
|
task.EnsurePath(task.x0_tag, *resPath);
|
2016-04-01 01:00:37 +00:00
|
|
|
|
|
|
|
/* Pump load pipeline (cooking if needed) */
|
|
|
|
while (!task.AsyncPump()) {std::this_thread::sleep_for(std::chrono::milliseconds(2));}
|
|
|
|
|
|
|
|
if (task.m_complete)
|
|
|
|
{
|
|
|
|
/* Load complete, build resource */
|
|
|
|
std::unique_ptr<IObj> newObj;
|
|
|
|
if (m_factoryMgr.CanMakeMemory(task.x0_tag))
|
|
|
|
{
|
|
|
|
newObj = m_factoryMgr.MakeObjectFromMemory(tag, std::move(task.x10_loadBuffer),
|
2016-09-02 19:32:57 +00:00
|
|
|
task.x14_resSize, false, task.x18_cvXfer, selfRef);
|
2016-04-01 01:00:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
athena::io::MemoryReader mr(task.x10_loadBuffer.get(), task.x14_resSize);
|
2016-09-02 19:32:57 +00:00
|
|
|
newObj = m_factoryMgr.MakeObject(task.x0_tag, mr, task.x18_cvXfer, selfRef);
|
2016-04-01 01:00:37 +00:00
|
|
|
}
|
|
|
|
|
2016-07-23 21:41:18 +00:00
|
|
|
*task.xc_targetObjPtr = newObj.get();
|
2016-04-01 01:00:37 +00:00
|
|
|
Log.report(logvisor::Warning, "spin-built %.4s %08X",
|
|
|
|
task.x0_tag.type.toString().c_str(),
|
|
|
|
u32(task.x0_tag.id));
|
2016-07-23 21:41:18 +00:00
|
|
|
|
2016-04-01 01:00:37 +00:00
|
|
|
m_asyncLoadList.erase(asyncSearch);
|
|
|
|
return newObj;
|
|
|
|
}
|
|
|
|
Log.report(logvisor::Error, "unable to spin-build %.4s %08X",
|
|
|
|
task.x0_tag.type.toString().c_str(),
|
|
|
|
u32(task.x0_tag.id));
|
|
|
|
m_asyncLoadList.erase(asyncSearch);
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fall-back to sync build */
|
2016-09-02 19:32:57 +00:00
|
|
|
return BuildSync(tag, *resPath, paramXfer, selfRef);
|
2016-03-26 00:51:59 +00:00
|
|
|
}
|
|
|
|
|
2016-08-08 04:48:18 +00:00
|
|
|
std::shared_ptr<ProjectResourceFactoryBase::AsyncTask>
|
|
|
|
ProjectResourceFactoryBase::BuildAsyncInternal(const urde::SObjectTag& tag,
|
|
|
|
const urde::CVParamTransfer& paramXfer,
|
2016-09-02 19:32:57 +00:00
|
|
|
urde::IObj** objOut,
|
|
|
|
CObjectReference* selfRef)
|
2016-08-08 04:48:18 +00:00
|
|
|
{
|
|
|
|
if (m_asyncLoadList.find(tag) != m_asyncLoadList.end())
|
|
|
|
return {};
|
2016-09-02 19:32:57 +00:00
|
|
|
return m_asyncLoadList.emplace(std::make_pair(tag, std::make_unique<AsyncTask>(*this, tag, objOut, paramXfer, selfRef))).first->second;
|
2016-08-08 04:48:18 +00:00
|
|
|
}
|
|
|
|
|
2016-03-26 00:51:59 +00:00
|
|
|
void ProjectResourceFactoryBase::BuildAsync(const urde::SObjectTag& tag,
|
|
|
|
const urde::CVParamTransfer& paramXfer,
|
2016-09-02 19:32:57 +00:00
|
|
|
urde::IObj** objOut,
|
|
|
|
CObjectReference* selfRef)
|
2016-03-26 00:51:59 +00:00
|
|
|
{
|
2016-09-02 19:32:57 +00:00
|
|
|
BuildAsyncInternal(tag, paramXfer, objOut, selfRef);
|
2016-03-26 00:51:59 +00:00
|
|
|
}
|
|
|
|
|
2016-07-23 21:41:18 +00:00
|
|
|
u32 ProjectResourceFactoryBase::ResourceSize(const SObjectTag& tag)
|
|
|
|
{
|
|
|
|
/* Ensure resource at requested path is indexed and not cooking */
|
|
|
|
const hecl::ProjectPath* resPath = nullptr;
|
|
|
|
if (!WaitForTagReady(tag, resPath))
|
|
|
|
return {};
|
|
|
|
|
|
|
|
/* Ensure cooked rep is on the filesystem */
|
|
|
|
std::experimental::optional<athena::io::FileReader> fr;
|
|
|
|
if (!PrepForReadSync(tag, *resPath, fr))
|
|
|
|
return {};
|
|
|
|
|
|
|
|
return fr->length();
|
|
|
|
}
|
|
|
|
|
2016-08-08 04:48:18 +00:00
|
|
|
std::shared_ptr<ProjectResourceFactoryBase::AsyncTask>
|
|
|
|
ProjectResourceFactoryBase::LoadResourceAsync(const urde::SObjectTag& tag,
|
|
|
|
std::unique_ptr<u8[]>& target)
|
2016-07-23 21:41:18 +00:00
|
|
|
{
|
|
|
|
if (m_asyncLoadList.find(tag) != m_asyncLoadList.end())
|
2016-08-08 04:48:18 +00:00
|
|
|
return {};
|
|
|
|
return m_asyncLoadList.emplace(std::make_pair(tag, std::make_shared<AsyncTask>(*this, tag, target))).first->second;
|
2016-07-23 21:41:18 +00:00
|
|
|
}
|
|
|
|
|
2016-08-08 04:48:18 +00:00
|
|
|
std::shared_ptr<ProjectResourceFactoryBase::AsyncTask>
|
|
|
|
ProjectResourceFactoryBase::LoadResourcePartAsync(const urde::SObjectTag& tag,
|
|
|
|
u32 size, u32 off,
|
|
|
|
std::unique_ptr<u8[]>& target)
|
2016-07-23 21:41:18 +00:00
|
|
|
{
|
|
|
|
if (m_asyncLoadList.find(tag) != m_asyncLoadList.end())
|
2016-08-08 04:48:18 +00:00
|
|
|
return {};
|
|
|
|
return m_asyncLoadList.emplace(std::make_pair(tag, std::make_shared<AsyncTask>(*this, tag, target, size, off))).first->second;
|
2016-07-23 21:41:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<u8[]> ProjectResourceFactoryBase::LoadResourceSync(const urde::SObjectTag& tag)
|
|
|
|
{
|
|
|
|
/* Ensure resource at requested path is indexed and not cooking */
|
|
|
|
const hecl::ProjectPath* resPath = nullptr;
|
|
|
|
if (!WaitForTagReady(tag, resPath))
|
|
|
|
return {};
|
|
|
|
|
|
|
|
/* Ensure cooked rep is on the filesystem */
|
|
|
|
std::experimental::optional<athena::io::FileReader> fr;
|
|
|
|
if (!PrepForReadSync(tag, *resPath, fr))
|
|
|
|
return {};
|
|
|
|
|
|
|
|
return fr->readUBytes(fr->length());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<u8[]> ProjectResourceFactoryBase::LoadResourcePartSync(const urde::SObjectTag& tag,
|
|
|
|
u32 size, u32 off)
|
|
|
|
{
|
|
|
|
/* Ensure resource at requested path is indexed and not cooking */
|
|
|
|
const hecl::ProjectPath* resPath = nullptr;
|
|
|
|
if (!WaitForTagReady(tag, resPath))
|
|
|
|
return {};
|
|
|
|
|
|
|
|
/* Ensure cooked rep is on the filesystem */
|
|
|
|
std::experimental::optional<athena::io::FileReader> fr;
|
|
|
|
if (!PrepForReadSync(tag, *resPath, fr))
|
|
|
|
return {};
|
|
|
|
|
|
|
|
s32 sz = std::min(s32(size), std::max(0, s32(fr->length()) - s32(off)));
|
|
|
|
fr->seek(off, athena::SeekOrigin::Begin);
|
|
|
|
return fr->readUBytes(sz);
|
|
|
|
}
|
|
|
|
|
2016-03-26 00:51:59 +00:00
|
|
|
void ProjectResourceFactoryBase::CancelBuild(const urde::SObjectTag& tag)
|
|
|
|
{
|
|
|
|
m_asyncLoadList.erase(tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ProjectResourceFactoryBase::CanBuild(const urde::SObjectTag& tag)
|
|
|
|
{
|
2016-07-23 21:41:18 +00:00
|
|
|
const hecl::ProjectPath* resPath = nullptr;
|
|
|
|
if (!WaitForTagReady(tag, resPath))
|
|
|
|
return false;
|
2016-03-26 00:51:59 +00:00
|
|
|
|
2016-07-23 21:41:18 +00:00
|
|
|
if (resPath->getPathType() == hecl::ProjectPath::Type::File)
|
2016-03-26 00:51:59 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const urde::SObjectTag* ProjectResourceFactoryBase::GetResourceIdByName(const char* name) const
|
|
|
|
{
|
2016-08-29 04:22:54 +00:00
|
|
|
std::unique_lock<std::mutex> lk(const_cast<ProjectResourceFactoryBase*>(this)->m_backgroundIndexMutex);
|
2016-03-26 00:51:59 +00:00
|
|
|
auto search = m_catalogNameToTag.find(name);
|
|
|
|
if (search == m_catalogNameToTag.end())
|
|
|
|
{
|
|
|
|
if (m_backgroundRunning)
|
|
|
|
{
|
|
|
|
while (m_backgroundRunning)
|
|
|
|
{
|
|
|
|
lk.unlock();
|
|
|
|
lk.lock();
|
|
|
|
search = m_catalogNameToTag.find(name);
|
|
|
|
if (search != m_catalogNameToTag.end())
|
|
|
|
break;
|
|
|
|
}
|
2016-03-28 21:38:48 +00:00
|
|
|
if (search == m_catalogNameToTag.end())
|
|
|
|
return nullptr;
|
2016-03-26 00:51:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return &search->second;
|
|
|
|
}
|
|
|
|
|
2016-04-14 21:42:47 +00:00
|
|
|
FourCC ProjectResourceFactoryBase::GetResourceTypeById(ResId id) const
|
|
|
|
{
|
2016-08-29 04:22:54 +00:00
|
|
|
std::unique_lock<std::mutex> lk(const_cast<ProjectResourceFactoryBase*>(this)->m_backgroundIndexMutex);
|
2016-04-14 21:42:47 +00:00
|
|
|
SObjectTag searchTag = {FourCC(), id};
|
|
|
|
auto search = m_tagToPath.find(searchTag);
|
|
|
|
if (search == m_tagToPath.end())
|
|
|
|
{
|
|
|
|
if (m_backgroundRunning)
|
|
|
|
{
|
|
|
|
while (m_backgroundRunning)
|
|
|
|
{
|
|
|
|
lk.unlock();
|
|
|
|
lk.lock();
|
|
|
|
search = m_tagToPath.find(searchTag);
|
|
|
|
if (search != m_tagToPath.end())
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (search == m_tagToPath.end())
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
return search->first.type;
|
|
|
|
}
|
|
|
|
|
2016-03-26 00:51:59 +00:00
|
|
|
void ProjectResourceFactoryBase::AsyncIdle()
|
|
|
|
{
|
2016-03-28 04:36:55 +00:00
|
|
|
/* Consume completed transactions, they will be processed this cycle at the latest */
|
2016-04-19 00:17:49 +00:00
|
|
|
std::list<std::shared_ptr<hecl::ClientProcess::Transaction>> completed;
|
2016-03-28 04:36:55 +00:00
|
|
|
m_clientProc.swapCompletedQueue(completed);
|
|
|
|
|
|
|
|
/* Begin self-profiling loop */
|
2016-03-26 00:51:59 +00:00
|
|
|
std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
|
2016-03-28 04:36:55 +00:00
|
|
|
for (auto it=m_asyncLoadList.begin() ; it != m_asyncLoadList.end() ;)
|
2016-03-26 00:51:59 +00:00
|
|
|
{
|
|
|
|
/* Allow 8 milliseconds (roughly 1/2 frame-time) for each async build cycle */
|
|
|
|
if (std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
|
|
std::chrono::steady_clock::now() - start).count() > 8)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Ensure requested resource is in the index */
|
|
|
|
std::unique_lock<std::mutex> lk(m_backgroundIndexMutex);
|
2016-08-08 04:48:18 +00:00
|
|
|
AsyncTask& task = *it->second;
|
2016-03-28 21:38:48 +00:00
|
|
|
auto search = m_tagToPath.find(task.x0_tag);
|
2016-03-26 00:51:59 +00:00
|
|
|
if (search == m_tagToPath.end())
|
|
|
|
{
|
|
|
|
if (!m_backgroundRunning)
|
|
|
|
{
|
|
|
|
Log.report(logvisor::Error, _S("unable to find async load resource (%s, %08X)"),
|
2016-03-28 21:38:48 +00:00
|
|
|
task.x0_tag.type.toString().c_str(), task.x0_tag.id);
|
2016-03-26 00:51:59 +00:00
|
|
|
it = m_asyncLoadList.erase(it);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2016-03-31 21:06:41 +00:00
|
|
|
lk.unlock();
|
|
|
|
task.EnsurePath(task.x0_tag, search->second);
|
2016-03-26 00:51:59 +00:00
|
|
|
|
2016-03-28 04:36:55 +00:00
|
|
|
/* Pump load pipeline (cooking if needed) */
|
2016-03-28 21:38:48 +00:00
|
|
|
if (task.AsyncPump())
|
2016-03-28 04:36:55 +00:00
|
|
|
{
|
2016-03-28 21:38:48 +00:00
|
|
|
if (task.m_complete)
|
|
|
|
{
|
|
|
|
/* Load complete, build resource */
|
2016-07-23 21:41:18 +00:00
|
|
|
if (task.xc_targetObjPtr)
|
2016-04-01 01:00:37 +00:00
|
|
|
{
|
2016-07-23 21:41:18 +00:00
|
|
|
/* Factory build */
|
|
|
|
std::unique_ptr<IObj> newObj;
|
|
|
|
if (m_factoryMgr.CanMakeMemory(task.x0_tag))
|
|
|
|
{
|
|
|
|
newObj = m_factoryMgr.MakeObjectFromMemory(task.x0_tag, std::move(task.x10_loadBuffer),
|
2016-09-02 19:32:57 +00:00
|
|
|
task.x14_resSize, false, task.x18_cvXfer,
|
|
|
|
task.m_selfRef);
|
2016-07-23 21:41:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
athena::io::MemoryReader mr(task.x10_loadBuffer.get(), task.x14_resSize);
|
2016-09-02 19:32:57 +00:00
|
|
|
newObj = m_factoryMgr.MakeObject(task.x0_tag, mr, task.x18_cvXfer, task.m_selfRef);
|
2016-07-23 21:41:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*task.xc_targetObjPtr = newObj.release();
|
|
|
|
Log.report(logvisor::Info, "async-built %.4s %08X",
|
|
|
|
task.x0_tag.type.toString().c_str(),
|
|
|
|
u32(task.x0_tag.id));
|
2016-04-01 01:00:37 +00:00
|
|
|
}
|
2016-07-23 21:41:18 +00:00
|
|
|
else if (task.xc_targetDataPtr)
|
2016-04-01 01:00:37 +00:00
|
|
|
{
|
2016-07-23 21:41:18 +00:00
|
|
|
/* Buffer only */
|
|
|
|
*task.xc_targetDataPtr = std::move(task.x10_loadBuffer);
|
|
|
|
Log.report(logvisor::Info, "async-loaded %.4s %08X",
|
|
|
|
task.x0_tag.type.toString().c_str(),
|
|
|
|
u32(task.x0_tag.id));
|
2016-04-01 01:00:37 +00:00
|
|
|
}
|
2016-03-28 21:38:48 +00:00
|
|
|
}
|
2016-03-28 04:36:55 +00:00
|
|
|
it = m_asyncLoadList.erase(it);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
++it;
|
2016-03-26 00:51:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|