2016-02-16 05:50:41 +00:00
|
|
|
#include "CFactoryMgr.hpp"
|
|
|
|
#include "IObj.hpp"
|
2017-11-19 07:10:54 +00:00
|
|
|
#include "CStopwatch.hpp"
|
2016-02-16 05:50:41 +00:00
|
|
|
|
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-09-02 19:32:57 +00:00
|
|
|
const CVParamTransfer& paramXfer, CObjectReference* selfRef)
|
2016-02-16 05:50:41 +00:00
|
|
|
{
|
|
|
|
auto search = m_factories.find(tag.type);
|
|
|
|
if (search == m_factories.end())
|
|
|
|
return {};
|
|
|
|
|
2016-09-02 19:32:57 +00:00
|
|
|
return search->second(tag, in, paramXfer, selfRef);
|
2016-02-16 05:50:41 +00:00
|
|
|
}
|
|
|
|
|
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-09-02 19:32:57 +00:00
|
|
|
bool compressed, const CVParamTransfer& paramXfer,
|
|
|
|
CObjectReference* selfRef)
|
2016-02-16 05:50:41 +00:00
|
|
|
{
|
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);
|
2016-09-02 19:32:57 +00:00
|
|
|
return search->second(tag, std::move(decompBuf), decompLen, paramXfer, selfRef);
|
2016-03-29 23:14:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-02 19:32:57 +00:00
|
|
|
return search->second(tag, std::move(localBuf), size, paramXfer, selfRef);
|
2016-03-29 23:14:14 +00:00
|
|
|
}
|
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);
|
2018-05-25 06:39:38 +00:00
|
|
|
compRead->readUint32Big();
|
2016-03-29 23:14:14 +00:00
|
|
|
CZipInputStream r(std::move(compRead));
|
2016-09-02 19:32:57 +00:00
|
|
|
return search->second(tag, r, paramXfer, selfRef);
|
2016-03-29 23:14:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CMemoryInStream r(localBuf.get(), size);
|
2016-09-02 19:32:57 +00:00
|
|
|
return search->second(tag, r, paramXfer, selfRef);
|
2016-03-29 23:14:14 +00:00
|
|
|
}
|
2016-02-16 05:50:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-26 05:37:46 +00:00
|
|
|
static const FourCC TypeTable[] =
|
|
|
|
{
|
|
|
|
FOURCC('CLSN'), FOURCC('CMDL'), FOURCC('CSKR'), FOURCC('ANIM'), FOURCC('CINF'), FOURCC('TXTR'),
|
|
|
|
FOURCC('PLTT'), FOURCC('FONT'), FOURCC('ANCS'), FOURCC('EVNT'), FOURCC('MADF'), FOURCC('MLVL'),
|
|
|
|
FOURCC('MREA'), FOURCC('MAPW'), FOURCC('MAPA'), FOURCC('SAVW'), FOURCC('SAVA'), FOURCC('PART'),
|
|
|
|
FOURCC('WPSC'), FOURCC('SWHC'), FOURCC('DPSC'), FOURCC('ELSC'), FOURCC('CRSC'), FOURCC('AFSM'),
|
|
|
|
FOURCC('DCLN'), FOURCC('AGSC'), FOURCC('ATBL'), FOURCC('CSNG'), FOURCC('STRG'), FOURCC('SCAN'),
|
|
|
|
FOURCC('PATH'), FOURCC('DGRP'), FOURCC('HMAP'), FOURCC('CTWK'), FOURCC('FRME'), FOURCC('HINT'),
|
2017-10-27 10:10:32 +00:00
|
|
|
FOURCC('MAPU'), FOURCC('DUMB'), FOURCC('OIDS')
|
2017-10-26 05:37:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
CFactoryMgr::ETypeTable CFactoryMgr::FourCCToTypeIdx(FourCC fcc)
|
|
|
|
{
|
|
|
|
for (int i=0 ; i<4 ; ++i)
|
2017-10-30 07:29:32 +00:00
|
|
|
fcc.getChars()[i] = char(toupper(fcc.getChars()[i]));
|
2017-10-26 05:37:46 +00:00
|
|
|
auto search = std::find_if(std::begin(TypeTable), std::end(TypeTable),
|
|
|
|
[fcc](const FourCC& test) { return test == fcc; });
|
|
|
|
if (search == std::end(TypeTable))
|
|
|
|
return ETypeTable::Invalid;
|
|
|
|
return ETypeTable(search - std::begin(TypeTable));
|
|
|
|
}
|
|
|
|
|
|
|
|
FourCC CFactoryMgr::TypeIdxToFourCC(ETypeTable fcc)
|
|
|
|
{
|
|
|
|
return TypeTable[int(fcc)];
|
|
|
|
}
|
|
|
|
|
2016-02-16 05:50:41 +00:00
|
|
|
}
|