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"
|
2016-03-04 23:04:53 +00:00
|
|
|
#include "Runtime/Graphics/CModel.hpp"
|
|
|
|
#include "Runtime/Graphics/CTexture.hpp"
|
2016-02-16 05:50:41 +00:00
|
|
|
|
2016-03-05 00:03:41 +00:00
|
|
|
namespace urde
|
2016-02-16 05:50:41 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
ProjectResourceFactory::ProjectResourceFactory()
|
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
m_factoryMgr.AddFactory(hecl::FOURCC('TXTR'), urde::FTextureFactory);
|
|
|
|
m_factoryMgr.AddFactory(hecl::FOURCC('PART'), urde::FParticleFactory);
|
2016-02-16 05:50:41 +00:00
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
void ProjectResourceFactory::BuildObjectMap(const hecl::Database::Project::ProjectDataSpec &spec)
|
2016-02-16 05:50:41 +00:00
|
|
|
{
|
2016-03-07 22:48:54 +00:00
|
|
|
#if 0
|
2016-03-01 03:08:25 +00:00
|
|
|
m_tagToPath.clear();
|
|
|
|
m_catalogNameToTag.clear();
|
2016-03-04 23:04:53 +00:00
|
|
|
hecl::SystemString catalogPath = hecl::ProjectPath(spec.cookedPath, hecl::SystemString(spec.spec.m_name) + _S("/catalog.yaml")).getAbsolutePath();
|
|
|
|
FILE* catalogFile = hecl::Fopen(catalogPath.c_str(), _S("r"));
|
2016-03-05 00:03:41 +00:00
|
|
|
athena::io::YAMLDocReader reader;
|
2016-03-01 03:08:25 +00:00
|
|
|
yaml_parser_set_input_file(reader.getParser(), catalogFile);
|
|
|
|
reader.parse();
|
2016-03-05 00:03:41 +00:00
|
|
|
const athena::io::YAMLNode* catalogRoot = reader.getRootNode();
|
2016-03-01 03:08:25 +00:00
|
|
|
if (catalogRoot)
|
|
|
|
{
|
|
|
|
m_catalogNameToPath.reserve(catalogRoot->m_mapChildren.size());
|
2016-03-05 00:03:41 +00:00
|
|
|
for (const std::pair<std::string, std::unique_ptr<athena::io::YAMLNode>>& ch : catalogRoot->m_mapChildren)
|
2016-03-01 03:08:25 +00:00
|
|
|
{
|
|
|
|
if (ch.second->m_type == YAML_SCALAR_NODE)
|
2016-03-05 00:03:41 +00:00
|
|
|
m_catalogNameToPath[ch.first] = hecl::ProjectPath(spec.cookedPath, hecl::SystemString(ch.second->m_scalarString));
|
2016-03-01 03:08:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
if (!hecl::StrCmp(spec.spec.m_name, _S("MP3")))
|
2016-02-16 05:50:41 +00:00
|
|
|
{
|
2016-03-01 20:29:18 +00:00
|
|
|
RecursiveAddDirObjects(spec.cookedPath);
|
2016-02-20 12:40:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-01 20:29:18 +00:00
|
|
|
RecursiveAddDirObjects(spec.cookedPath);
|
2016-02-16 05:50:41 +00:00
|
|
|
}
|
2016-03-07 22:48:54 +00:00
|
|
|
#endif
|
2016-02-16 05:50:41 +00:00
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
std::unique_ptr<urde::IObj> ProjectResourceFactory::Build(const urde::SObjectTag& tag,
|
2016-03-05 00:03:41 +00:00
|
|
|
const urde::CVParamTransfer& paramXfer)
|
2016-02-16 05:50:41 +00:00
|
|
|
{
|
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-03-04 23:04:53 +00:00
|
|
|
athena::io::FileReader fr(search->second.getAbsolutePath(), 32 * 1024, false);
|
2016-02-16 05:50:41 +00:00
|
|
|
if (fr.hasError())
|
|
|
|
return {};
|
|
|
|
|
|
|
|
return m_factoryMgr.MakeObject(tag, fr, paramXfer);
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
void ProjectResourceFactory::BuildAsync(const urde::SObjectTag& tag,
|
|
|
|
const urde::CVParamTransfer& paramXfer,
|
|
|
|
urde::IObj** objOut)
|
2016-02-16 05:50:41 +00:00
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
std::unique_ptr<urde::IObj> obj = Build(tag, paramXfer);
|
2016-02-16 05:50:41 +00:00
|
|
|
*objOut = obj.release();
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
void ProjectResourceFactory::CancelBuild(const urde::SObjectTag&)
|
2016-02-16 05:50:41 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
bool ProjectResourceFactory::CanBuild(const urde::SObjectTag& tag)
|
2016-02-16 05:50:41 +00:00
|
|
|
{
|
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;
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
athena::io::FileReader fr(search->second.getAbsolutePath(), 32 * 1024, false);
|
2016-02-16 05:50:41 +00:00
|
|
|
if (fr.hasError())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
const urde::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-05 00:03:41 +00:00
|
|
|
const urde::SObjectTag& tag = m_catalogNameToTag.at(name);
|
2016-02-20 12:40:58 +00:00
|
|
|
return &tag;
|
2016-02-16 05:50:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|