metaforce/Editor/ProjectResourceFactory.cpp

91 lines
2.9 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
namespace URDE
{
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
{
m_resPaths.clear();
m_namedResources.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"));
if (!hecl::StrCmp(spec.spec.m_name, _S("MP3")))
2016-02-16 05:50:41 +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
}
}
2016-03-04 23:04:53 +00:00
std::unique_ptr<urde::IObj> ProjectResourceFactory::Build(const urde::SObjectTag& tag,
const urde::CVParamTransfer& paramXfer)
2016-02-16 05:50:41 +00:00
{
auto search = m_resPaths.find(tag);
if (search == m_resPaths.end())
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_resPaths.find(tag);
if (search == m_resPaths.end())
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_namedResources.find(name) == m_namedResources.end())
return nullptr;
2016-03-04 23:04:53 +00:00
const urde::SObjectTag& tag = m_namedResources.at(name);
return &tag;
2016-02-16 05:50:41 +00:00
}
}