mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-14 10:46:10 +00:00
Tons of PART rendering preparation
This commit is contained in:
87
Editor/ProjectResourceFactory.cpp
Normal file
87
Editor/ProjectResourceFactory.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
#include "ProjectResourceFactory.hpp"
|
||||
#include "Runtime/IOStreams.hpp"
|
||||
|
||||
#include "Runtime/Particle/CParticleDataFactory.hpp"
|
||||
#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::RecursiveAddDirObjects(const HECL::ProjectPath& path)
|
||||
{
|
||||
HECL::DirectoryEnumerator de = path.enumerateDir();
|
||||
for (const HECL::DirectoryEnumerator::Entry& ent : de)
|
||||
{
|
||||
if (ent.m_isDir)
|
||||
RecursiveAddDirObjects(HECL::ProjectPath(path, ent.m_name));
|
||||
if (ent.m_name.size() == 13 && ent.m_name[4] == _S('_'))
|
||||
{
|
||||
HECL::SystemUTF8View entu8(ent.m_name);
|
||||
u32 id = strtoul(entu8.c_str() + 5, nullptr, 16);
|
||||
if (id)
|
||||
{
|
||||
pshag::SObjectTag objTag = {HECL::FourCC(entu8.c_str()), id};
|
||||
if (m_resPaths.find(objTag) == m_resPaths.end())
|
||||
m_resPaths[objTag] = HECL::ProjectPath(path, ent.m_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectResourceFactory::BuildObjectMap(const HECL::Database::Project::ProjectDataSpec& spec)
|
||||
{
|
||||
m_resPaths.clear();
|
||||
RecursiveAddDirObjects(spec.cookedPath);
|
||||
}
|
||||
|
||||
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*) const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user