metaforce/Runtime/Character/CAllFormatsAnimSource.cpp

83 lines
2.6 KiB
C++
Raw Normal View History

2016-04-11 23:35:37 +00:00
#include "CAllFormatsAnimSource.hpp"
#include "logvisor/logvisor.hpp"
2016-04-12 06:15:32 +00:00
#include "CSimplePool.hpp"
#include "CAnimSourceReader.hpp"
2016-08-27 04:54:53 +00:00
#include "CFBStreamedAnimReader.hpp"
2016-04-11 23:35:37 +00:00
namespace urde
{
static logvisor::Module Log("urde::CAllFormatsAnimSource");
void CAnimFormatUnion::SubConstruct(u8* storage, EAnimFormat fmt,
CInputStream& in, IObjectStore& store)
{
switch (fmt)
{
case EAnimFormat::Uncompressed:
new (storage) CAnimSource(in, store);
break;
2016-08-27 04:54:53 +00:00
case EAnimFormat::BitstreamCompressed:
new (storage) CFBStreamedCompression(in, store, false);
break;
case EAnimFormat::BitstreamCompressed24:
2016-08-27 04:54:53 +00:00
new (storage) CFBStreamedCompression(in, store, true);
break;
2016-04-11 23:35:37 +00:00
default:
Log.report(logvisor::Fatal, "unable to read ANIM format %d", int(fmt));
}
}
CAnimFormatUnion::CAnimFormatUnion(CInputStream& in, IObjectStore& store)
{
x0_format = EAnimFormat(in.readUint32Big());
SubConstruct(x4_storage, x0_format, in, store);
}
2016-04-12 06:15:32 +00:00
CAnimFormatUnion::~CAnimFormatUnion()
{
switch (x0_format)
{
case EAnimFormat::Uncompressed:
reinterpret_cast<CAnimSource*>(x4_storage)->~CAnimSource();
2016-08-27 04:54:53 +00:00
break;
case EAnimFormat::BitstreamCompressed:
case EAnimFormat::BitstreamCompressed24:
reinterpret_cast<CFBStreamedCompression*>(x4_storage)->~CFBStreamedCompression();
2016-04-12 06:15:32 +00:00
default: break;
}
}
2016-08-27 04:54:53 +00:00
std::shared_ptr<IAnimReader>
2016-04-12 06:15:32 +00:00
CAllFormatsAnimSource::GetNewReader(const TLockedToken<CAllFormatsAnimSource>& tok,
const CCharAnimTime& startTime)
{
2016-08-28 19:57:55 +00:00
switch (tok->x0_format)
{
case EAnimFormat::Uncompressed:
return std::make_shared<CAnimSourceReader>(tok, startTime);
case EAnimFormat::BitstreamCompressed:
case EAnimFormat::BitstreamCompressed24:
return std::make_shared<CFBStreamedAnimReader>(tok, startTime);
default: break;
}
return {};
2016-04-12 06:15:32 +00:00
}
2016-04-11 23:35:37 +00:00
CAllFormatsAnimSource::CAllFormatsAnimSource(CInputStream& in,
IObjectStore& store,
const SObjectTag& tag)
: CAnimFormatUnion(in, store), x74_tag(tag) {}
2016-04-12 06:15:32 +00:00
CFactoryFnReturn AnimSourceFactory(const SObjectTag& tag, CInputStream& in,
const CVParamTransfer& params,
CObjectReference* selfRef)
2016-04-12 06:15:32 +00:00
{
CSimplePool* sp = static_cast<CSimplePool*>(
static_cast<TObjOwnerParam<IObjectStore*>*>(
params.GetObj())->GetParam());
return TToken<CAllFormatsAnimSource>::GetIObjObjectFor(
std::make_unique<CAllFormatsAnimSource>(in, *sp, tag));
}
2016-04-11 23:35:37 +00:00
}