2016-02-16 05:50:41 +00:00
|
|
|
#include "ProjectResourceFactory.hpp"
|
|
|
|
#include "Runtime/IOStreams.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/Particle/CParticleDataFactory.hpp"
|
2016-02-17 05:20:34 +00:00
|
|
|
#include "Runtime/Particle/CGenDescription.hpp"
|
|
|
|
#include "Runtime/Particle/CElectricDescription.hpp"
|
|
|
|
#include "Runtime/Particle/CSwooshDescription.hpp"
|
|
|
|
#include "Runtime/CModel.hpp"
|
2016-02-16 05:50:41 +00:00
|
|
|
#include "Runtime/CTexture.hpp"
|
|
|
|
|
|
|
|
namespace URDE
|
|
|
|
{
|
|
|
|
|
|
|
|
ProjectResourceFactory::ProjectResourceFactory()
|
|
|
|
{
|
|
|
|
m_factoryMgr.AddFactory(HECL::FOURCC('TXTR'), pshag::FTextureFactory);
|
|
|
|
m_factoryMgr.AddFactory(HECL::FOURCC('PART'), pshag::FParticleFactory);
|
|
|
|
}
|
|
|
|
|
2016-02-20 12:40:58 +00:00
|
|
|
void ProjectResourceFactory::BuildObjectMap(const HECL::Database::Project::ProjectDataSpec &spec)
|
2016-02-16 05:50:41 +00:00
|
|
|
{
|
2016-03-01 03:08:25 +00:00
|
|
|
m_tagToPath.clear();
|
|
|
|
m_catalogNameToTag.clear();
|
2016-02-24 20:53:26 +00:00
|
|
|
HECL::SystemString catalogPath = HECL::ProjectPath(spec.cookedPath, HECL::SystemString(spec.spec.m_name) + _S("/catalog.yaml")).getAbsolutePath();
|
2016-02-20 12:40:58 +00:00
|
|
|
FILE* catalogFile = HECL::Fopen(catalogPath.c_str(), _S("r"));
|
2016-03-01 03:08:25 +00:00
|
|
|
Athena::io::YAMLDocReader reader;
|
|
|
|
yaml_parser_set_input_file(reader.getParser(), catalogFile);
|
|
|
|
reader.parse();
|
|
|
|
const Athena::io::YAMLNode* catalogRoot = reader.getRootNode();
|
|
|
|
if (catalogRoot)
|
|
|
|
{
|
|
|
|
m_catalogNameToPath.reserve(catalogRoot->m_mapChildren.size());
|
|
|
|
for (const std::pair<std::string, std::unique_ptr<Athena::io::YAMLNode>>& ch : catalogRoot->m_mapChildren)
|
|
|
|
{
|
|
|
|
if (ch.second->m_type == YAML_SCALAR_NODE)
|
|
|
|
m_catalogNameToPath[ch.first] = HECL::ProjectPath(spec.cookedPath, HECL::SystemString(ch.second->m_scalarString));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-24 20:53:26 +00:00
|
|
|
if (!HECL::StrCmp(spec.spec.m_name, _S("MP3")))
|
2016-02-16 05:50:41 +00:00
|
|
|
{
|
2016-02-20 12:40:58 +00:00
|
|
|
DataSpec::NamedResourceCatalog<DataSpec::UniqueID64> catalog;
|
|
|
|
if (catalogFile)
|
|
|
|
catalog.fromYAMLFile(catalogFile);
|
|
|
|
RecursiveAddDirObjects(spec.cookedPath, catalog);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DataSpec::NamedResourceCatalog<DataSpec::UniqueID32> catalog;
|
|
|
|
if (catalogFile)
|
|
|
|
catalog.fromYAMLFile(catalogFile);
|
|
|
|
RecursiveAddDirObjects(spec.cookedPath, catalog);
|
2016-02-16 05:50:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<pshag::IObj> ProjectResourceFactory::Build(const pshag::SObjectTag& tag,
|
|
|
|
const pshag::CVParamTransfer& paramXfer)
|
|
|
|
{
|
2016-03-01 03:08:25 +00:00
|
|
|
auto search = m_tagToPath.find(tag);
|
|
|
|
if (search == m_tagToPath.end())
|
2016-02-16 05:50:41 +00:00
|
|
|
return {};
|
|
|
|
|
2016-02-28 01:03:46 +00:00
|
|
|
fprintf(stderr, "Loading resource %s\n", search->second.getRelativePath().c_str());
|
2016-02-16 05:50:41 +00:00
|
|
|
Athena::io::FileReader fr(search->second.getAbsolutePath(), 32 * 1024, false);
|
|
|
|
if (fr.hasError())
|
|
|
|
return {};
|
|
|
|
|
|
|
|
return m_factoryMgr.MakeObject(tag, fr, paramXfer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectResourceFactory::BuildAsync(const pshag::SObjectTag& tag,
|
|
|
|
const pshag::CVParamTransfer& paramXfer,
|
|
|
|
pshag::IObj** objOut)
|
|
|
|
{
|
|
|
|
std::unique_ptr<pshag::IObj> obj = Build(tag, paramXfer);
|
|
|
|
*objOut = obj.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectResourceFactory::CancelBuild(const pshag::SObjectTag&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ProjectResourceFactory::CanBuild(const pshag::SObjectTag& tag)
|
|
|
|
{
|
2016-03-01 03:08:25 +00:00
|
|
|
auto search = m_tagToPath.find(tag);
|
|
|
|
if (search == m_tagToPath.end())
|
2016-02-16 05:50:41 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
Athena::io::FileReader fr(search->second.getAbsolutePath(), 32 * 1024, false);
|
|
|
|
if (fr.hasError())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-20 12:40:58 +00:00
|
|
|
const pshag::SObjectTag* ProjectResourceFactory::GetResourceIdByName(const char* name) const
|
2016-02-16 05:50:41 +00:00
|
|
|
{
|
2016-03-01 03:08:25 +00:00
|
|
|
if (m_catalogNameToTag.find(name) == m_catalogNameToTag.end())
|
2016-02-20 12:40:58 +00:00
|
|
|
return nullptr;
|
2016-03-01 03:08:25 +00:00
|
|
|
const pshag::SObjectTag& tag = m_catalogNameToTag.at(name);
|
2016-02-20 12:40:58 +00:00
|
|
|
return &tag;
|
2016-02-16 05:50:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|