metaforce/Runtime/Character/CAllFormatsAnimSource.cpp

71 lines
2.4 KiB
C++
Raw Normal View History

#include "Runtime/Character/CAllFormatsAnimSource.hpp"
#include "Runtime/CSimplePool.hpp"
#include "Runtime/Character/CAnimSourceReader.hpp"
#include "Runtime/Character/CFBStreamedAnimReader.hpp"
#include <logvisor/logvisor.hpp>
2016-04-11 16:35:37 -07:00
2021-04-10 01:42:06 -07:00
namespace metaforce {
static logvisor::Module Log("metaforce::CAllFormatsAnimSource");
2016-04-11 16:35:37 -07:00
2018-12-07 21:30:43 -08:00
void CAnimFormatUnion::SubConstruct(u8* storage, EAnimFormat fmt, CInputStream& in, IObjectStore& store) {
switch (fmt) {
case EAnimFormat::Uncompressed:
new (storage) CAnimSource(in, store);
break;
case EAnimFormat::BitstreamCompressed:
new (storage) CFBStreamedCompression(in, store, false);
break;
case EAnimFormat::BitstreamCompressed24:
new (storage) CFBStreamedCompression(in, store, true);
break;
default:
2020-04-11 15:51:39 -07:00
Log.report(logvisor::Fatal, FMT_STRING("unable to read ANIM format {}"), int(fmt));
2018-12-07 21:30:43 -08:00
}
2016-04-11 16:35:37 -07:00
}
2018-12-07 21:30:43 -08:00
CAnimFormatUnion::CAnimFormatUnion(CInputStream& in, IObjectStore& store) {
x0_format = EAnimFormat(in.ReadLong());
2018-12-07 21:30:43 -08:00
SubConstruct(x4_storage, x0_format, in, store);
2016-04-11 16:35:37 -07:00
}
2018-12-07 21:30:43 -08:00
CAnimFormatUnion::~CAnimFormatUnion() {
switch (x0_format) {
case EAnimFormat::Uncompressed:
reinterpret_cast<CAnimSource*>(x4_storage)->~CAnimSource();
break;
case EAnimFormat::BitstreamCompressed:
case EAnimFormat::BitstreamCompressed24:
reinterpret_cast<CFBStreamedCompression*>(x4_storage)->~CFBStreamedCompression();
2019-02-17 21:47:46 -08:00
break;
2018-12-07 21:30:43 -08:00
default:
break;
}
2016-04-11 23:15:32 -07:00
}
2018-12-07 21:30:43 -08:00
std::shared_ptr<IAnimReader> CAllFormatsAnimSource::GetNewReader(const TLockedToken<CAllFormatsAnimSource>& tok,
const CCharAnimTime& startTime) {
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-11 23:15:32 -07:00
}
2018-12-07 21:30:43 -08:00
CAllFormatsAnimSource::CAllFormatsAnimSource(CInputStream& in, IObjectStore& store, const SObjectTag& tag)
2016-04-11 16:35:37 -07:00
: CAnimFormatUnion(in, store), x74_tag(tag) {}
2018-12-07 21:30:43 -08:00
CFactoryFnReturn AnimSourceFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& params,
CObjectReference* selfRef) {
CSimplePool* sp = params.GetOwnedObj<CSimplePool*>();
return TToken<CAllFormatsAnimSource>::GetIObjObjectFor(std::make_unique<CAllFormatsAnimSource>(in, *sp, tag));
2016-04-11 23:15:32 -07:00
}
2021-04-10 01:42:06 -07:00
} // namespace metaforce