metaforce/Editor/ProjectResourceFactory.cpp

90 lines
2.8 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"
#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);
}
void ProjectResourceFactory::BuildObjectMap(const HECL::Database::Project::ProjectDataSpec &spec)
2016-02-16 05:50:41 +00:00
{
m_resPaths.clear();
m_namedResources.clear();
HECL::SystemString catalogPath = HECL::ProjectPath(spec.cookedPath, std::string(spec.spec.m_name) + "/catalog.yaml").getAbsolutePath();
FILE* catalogFile = HECL::Fopen(catalogPath.c_str(), _S("r"));
if (!HECL::StrCmp(spec.spec.m_name, "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
}
}
std::unique_ptr<pshag::IObj> ProjectResourceFactory::Build(const pshag::SObjectTag& tag,
const pshag::CVParamTransfer& paramXfer)
{
auto search = m_resPaths.find(tag);
if (search == m_resPaths.end())
return {};
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)
{
auto search = m_resPaths.find(tag);
if (search == m_resPaths.end())
return false;
Athena::io::FileReader fr(search->second.getAbsolutePath(), 32 * 1024, false);
if (fr.hasError())
return false;
return true;
}
const pshag::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;
const pshag::SObjectTag& tag = m_namedResources.at(name);
return &tag;
2016-02-16 05:50:41 +00:00
}
}