metaforce/Runtime/CFactoryMgr.cpp

68 lines
2.0 KiB
C++
Raw Normal View History

2016-02-16 05:50:41 +00:00
#include "CFactoryMgr.hpp"
#include "IObj.hpp"
2016-03-04 23:04:53 +00:00
namespace urde
2016-02-16 05:50:41 +00:00
{
2016-03-04 23:04:53 +00:00
CFactoryFnReturn CFactoryMgr::MakeObject(const SObjectTag& tag, urde::CInputStream& in,
2016-02-16 05:50:41 +00:00
const CVParamTransfer& paramXfer)
{
auto search = m_factories.find(tag.type);
if (search == m_factories.end())
return {};
return search->second(tag, in, paramXfer);
}
2016-03-29 23:14:14 +00:00
bool CFactoryMgr::CanMakeMemory(const urde::SObjectTag& tag) const
{
auto search = m_memFactories.find(tag.type);
return search != m_memFactories.cend();
}
CFactoryFnReturn CFactoryMgr::MakeObjectFromMemory(const SObjectTag& tag, std::unique_ptr<u8[]>&& buf, int size,
2016-02-16 05:50:41 +00:00
bool compressed, const CVParamTransfer& paramXfer)
{
2016-03-29 23:14:14 +00:00
std::unique_ptr<u8[]> localBuf = std::move(buf);
2016-02-16 05:50:41 +00:00
2016-03-29 23:14:14 +00:00
auto search = m_memFactories.find(tag.type);
if (search != m_memFactories.cend())
2016-02-16 05:50:41 +00:00
{
2016-03-29 23:14:14 +00:00
if (compressed)
{
std::unique_ptr<CInputStream> compRead =
std::make_unique<athena::io::MemoryReader>(localBuf.get(), size);
u32 decompLen = compRead->readUint32Big();
CZipInputStream r(std::move(compRead));
std::unique_ptr<u8[]> decompBuf = r.readUBytes(decompLen);
return search->second(tag, std::move(decompBuf), decompLen, paramXfer);
}
else
{
return search->second(tag, std::move(localBuf), size, paramXfer);
}
2016-02-16 05:50:41 +00:00
}
else
{
2016-03-29 23:14:14 +00:00
auto search = m_factories.find(tag.type);
if (search == m_factories.end())
return {};
if (compressed)
{
std::unique_ptr<CInputStream> compRead =
std::make_unique<athena::io::MemoryReader>(localBuf.get(), size);
u32 decompLen = compRead->readUint32Big();
CZipInputStream r(std::move(compRead));
return search->second(tag, r, paramXfer);
}
else
{
CMemoryInStream r(localBuf.get(), size);
return search->second(tag, r, paramXfer);
}
2016-02-16 05:50:41 +00:00
}
}
}