2016-02-16 05:50:41 +00:00
|
|
|
#ifndef URDE_PROJECT_RESOURCE_FACTORY_HPP
|
|
|
|
#define URDE_PROJECT_RESOURCE_FACTORY_HPP
|
|
|
|
|
|
|
|
#include "Runtime/IFactory.hpp"
|
|
|
|
#include "Runtime/CFactoryMgr.hpp"
|
2016-02-20 12:40:58 +00:00
|
|
|
#include "DataSpec/DNACommon/NamedResourceCatalog.hpp"
|
2016-02-16 05:50:41 +00:00
|
|
|
|
|
|
|
namespace URDE
|
|
|
|
{
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
class ProjectResourceFactory : public urde::IFactory
|
2016-02-16 05:50:41 +00:00
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
std::unordered_map<urde::SObjectTag, hecl::ProjectPath> m_resPaths;
|
|
|
|
std::unordered_map<std::string, urde::SObjectTag> m_namedResources;
|
|
|
|
urde::CFactoryMgr m_factoryMgr;
|
2016-02-20 12:40:58 +00:00
|
|
|
template <class IDType>
|
2016-03-04 23:04:53 +00:00
|
|
|
void RecursiveAddDirObjects(const hecl::ProjectPath& path, const DataSpec::NamedResourceCatalog<IDType>& catalog)
|
2016-02-20 12:40:58 +00:00
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
hecl::DirectoryEnumerator de = path.enumerateDir();
|
2016-02-20 12:40:58 +00:00
|
|
|
const int idLen = 5 + (IDType::BinarySize() * 2);
|
2016-03-04 23:04:53 +00:00
|
|
|
for (const hecl::DirectoryEnumerator::Entry& ent : de)
|
2016-02-20 12:40:58 +00:00
|
|
|
{
|
|
|
|
if (ent.m_isDir)
|
2016-03-04 23:04:53 +00:00
|
|
|
RecursiveAddDirObjects(hecl::ProjectPath(path, ent.m_name), catalog);
|
2016-02-20 12:40:58 +00:00
|
|
|
if (ent.m_name.size() == idLen && ent.m_name[4] == _S('_'))
|
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
hecl::SystemUTF8View entu8(ent.m_name);
|
2016-02-24 20:53:26 +00:00
|
|
|
#if _WIN32
|
|
|
|
u64 id = _strtoui64(entu8.c_str() + 5, nullptr, 16);
|
|
|
|
#else
|
2016-02-20 12:40:58 +00:00
|
|
|
u64 id = strtouq(entu8.c_str() + 5, nullptr, 16);
|
2016-02-24 20:53:26 +00:00
|
|
|
#endif
|
2016-02-20 12:40:58 +00:00
|
|
|
|
|
|
|
if (id)
|
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
urde::SObjectTag objTag = {hecl::FourCC(entu8.c_str()), id};
|
2016-02-20 12:40:58 +00:00
|
|
|
if (m_resPaths.find(objTag) == m_resPaths.end())
|
2016-03-04 23:04:53 +00:00
|
|
|
m_resPaths[objTag] = hecl::ProjectPath(path, ent.m_name);
|
2016-02-20 12:40:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
hecl::SystemUTF8View nameView(ent.m_name);
|
2016-02-20 12:40:58 +00:00
|
|
|
auto it = std::find_if(catalog.namedResources.begin(), catalog.namedResources.end(),
|
|
|
|
[&nameView](const typename DataSpec::NamedResourceCatalog<IDType>::NamedResource& res) -> bool
|
|
|
|
{ return res.name == nameView.str(); });
|
|
|
|
if (it == catalog.namedResources.end())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const typename DataSpec::NamedResourceCatalog<IDType>::NamedResource& nr = *it;
|
2016-03-04 23:04:53 +00:00
|
|
|
urde::SObjectTag objTag = GetTag<IDType>(nr);
|
2016-02-20 12:40:58 +00:00
|
|
|
|
|
|
|
m_namedResources[nr.name.c_str()] = objTag;
|
2016-03-04 23:04:53 +00:00
|
|
|
m_resPaths[objTag] = hecl::ProjectPath(path, ent.m_name);
|
2016-02-20 12:40:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class IDType>
|
2016-03-04 23:04:53 +00:00
|
|
|
urde::SObjectTag GetTag(const DataSpec::NamedResourceCatalog<DataSpec::UniqueID32>::NamedResource &nr,
|
2016-02-20 12:40:58 +00:00
|
|
|
typename std::enable_if<std::is_same<IDType, DataSpec::UniqueID32>::value>::type* = 0)
|
|
|
|
{ return { nr.type, nr.uid.toUint32() }; }
|
|
|
|
|
|
|
|
template <class IDType>
|
2016-03-04 23:04:53 +00:00
|
|
|
urde::SObjectTag GetTag(const typename DataSpec::NamedResourceCatalog<IDType>::NamedResource& nr,
|
2016-02-20 12:40:58 +00:00
|
|
|
typename std::enable_if<std::is_same<IDType, DataSpec::UniqueID64>::value>::type* = 0)
|
|
|
|
{ return { nr.type, nr.uid.toUint64() }; }
|
|
|
|
|
2016-02-16 05:50:41 +00:00
|
|
|
public:
|
|
|
|
ProjectResourceFactory();
|
2016-03-04 23:04:53 +00:00
|
|
|
void BuildObjectMap(const hecl::Database::Project::ProjectDataSpec& spec);
|
2016-02-16 05:50:41 +00:00
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
std::unique_ptr<urde::IObj> Build(const urde::SObjectTag&, const urde::CVParamTransfer&);
|
|
|
|
void BuildAsync(const urde::SObjectTag&, const urde::CVParamTransfer&, urde::IObj**);
|
|
|
|
void CancelBuild(const urde::SObjectTag&);
|
|
|
|
bool CanBuild(const urde::SObjectTag&);
|
|
|
|
const urde::SObjectTag* GetResourceIdByName(const char*) const;
|
2016-02-16 05:50:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // URDE_PROJECT_RESOURCE_FACTORY_HPP
|