metaforce/Editor/ProjectResourceFactory.cpp

101 lines
3.2 KiB
C++
Raw Normal View History

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
{
#if 0
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;
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();
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)
{
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-04 23:04:53 +00:00
if (!hecl::StrCmp(spec.spec.m_name, _S("MP3")))
2016-02-16 05:50:41 +00:00
{
RecursiveAddDirObjects(spec.cookedPath);
}
else
{
RecursiveAddDirObjects(spec.cookedPath);
2016-02-16 05:50:41 +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
{
auto search = m_tagToPath.find(tag);
if (search == m_tagToPath.end())
2016-02-16 05:50:41 +00:00
return {};
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
{
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
{
if (m_catalogNameToTag.find(name) == m_catalogNameToTag.end())
return nullptr;
2016-03-05 00:03:41 +00:00
const urde::SObjectTag& tag = m_catalogNameToTag.at(name);
return &tag;
2016-02-16 05:50:41 +00:00
}
}