playeranimation

This commit is contained in:
briaguya 2024-02-09 14:08:17 -05:00
parent e87ade4ebd
commit 60e27edab5
5 changed files with 17 additions and 44 deletions

View File

@ -322,8 +322,8 @@ OTRGlobals::OTRGlobals() {
auto loader = context->GetResourceManager()->GetResourceLoader();
loader->RegisterResourceFactory(std::make_shared<ResourceFactoryBinaryAnimationV0>(), RESOURCE_FORMAT_BINARY, "SOH_Animation", static_cast<uint32_t>(SohResourceType::SOH_Animation), 0);
loader->RegisterResourceFactory(std::make_shared<ResourceFactoryBinaryPlayerAnimationV0>(), RESOURCE_FORMAT_BINARY, "SOH_PlayerAnimation", static_cast<uint32_t>(SohResourceType::SOH_PlayerAnimation), 0);
loader->RegisterResourceFactory(static_cast<uint32_t>(SohResourceType::SOH_PlayerAnimation), std::make_shared<LUS::PlayerAnimationFactory>());
loader->RegisterResourceFactory(static_cast<uint32_t>(SohResourceType::SOH_Room), std::make_shared<LUS::SceneFactory>()); // Is room scene? maybe?
loader->RegisterResourceFactory(static_cast<uint32_t>(SohResourceType::SOH_CollisionHeader), std::make_shared<LUS::CollisionHeaderFactory>());
loader->RegisterResourceFactory(static_cast<uint32_t>(SohResourceType::SOH_Skeleton), std::make_shared<LUS::SkeletonFactory>());

View File

@ -2,40 +2,26 @@
#include "soh/resource/type/PlayerAnimation.h"
#include "spdlog/spdlog.h"
namespace LUS {
std::shared_ptr<IResource>
PlayerAnimationFactory::ReadResource(std::shared_ptr<ResourceInitData> initData, std::shared_ptr<BinaryReader> reader) {
auto resource = std::make_shared<PlayerAnimation>(initData);
std::shared_ptr<ResourceVersionFactory> factory = nullptr;
switch (resource->GetInitData()->ResourceVersion) {
case 0:
factory = std::make_shared<PlayerAnimationFactoryV0>();
break;
std::shared_ptr<LUS::IResource> ResourceFactoryBinaryPlayerAnimationV0::ReadResource(std::shared_ptr<LUS::File> file) {
if (file->InitData->Format != RESOURCE_FORMAT_BINARY) {
SPDLOG_ERROR("resource file format does not match factory format.");
return nullptr;
}
if (factory == nullptr)
{
SPDLOG_ERROR("Failed to load PlayerAnimation with version {}", resource->GetInitData()->ResourceVersion);
return nullptr;
if (file->Reader == nullptr) {
SPDLOG_ERROR("Failed to load resource: File has Reader ({} - {})", file->InitData->Type,
file->InitData->Path);
return nullptr;
}
factory->ParseFileBinary(reader, resource);
auto playerAnimation = std::make_shared<PlayerAnimation>(file->InitData);
return resource;
}
void LUS::PlayerAnimationFactoryV0::ParseFileBinary(std::shared_ptr<BinaryReader> reader,
std::shared_ptr<IResource> resource)
{
std::shared_ptr<PlayerAnimation> playerAnimation = std::static_pointer_cast<PlayerAnimation>(resource);
ResourceVersionFactory::ParseFileBinary(reader, playerAnimation);
uint32_t numEntries = reader->ReadUInt32();
uint32_t numEntries = file->Reader->ReadUInt32();
playerAnimation->limbRotData.reserve(numEntries);
for (uint32_t i = 0; i < numEntries; i++) {
playerAnimation->limbRotData.push_back(reader->ReadInt16());
playerAnimation->limbRotData.push_back(file->Reader->ReadInt16());
}
}
} // namespace LUS
return playerAnimation;
};

View File

@ -3,15 +3,7 @@
#include "Resource.h"
#include "ResourceFactory.h"
namespace LUS {
class PlayerAnimationFactory : public ResourceFactory {
class ResourceFactoryBinaryPlayerAnimationV0 : public LUS::ResourceFactory {
public:
std::shared_ptr<IResource>
ReadResource(std::shared_ptr<ResourceInitData> initData, std::shared_ptr<BinaryReader> reader) override;
std::shared_ptr<LUS::IResource> ReadResource(std::shared_ptr<LUS::File> file) override;
};
class PlayerAnimationFactoryV0 : public ResourceVersionFactory {
public:
void ParseFileBinary(std::shared_ptr<BinaryReader> reader, std::shared_ptr<IResource> resource) override;
};
}; // namespace LUS

View File

@ -1,7 +1,6 @@
#include "PlayerAnimation.h"
#include <libultraship/libultra/gbi.h>
namespace LUS {
int16_t* PlayerAnimation::GetPointer() {
return limbRotData.data();
}
@ -9,4 +8,3 @@ int16_t* PlayerAnimation::GetPointer() {
size_t PlayerAnimation::GetPointerSize() {
return limbRotData.size() * sizeof(int16_t);
}
} // namespace LUS

View File

@ -7,8 +7,6 @@
#include "Vec3f.h"
#include "Color3b.h"
namespace LUS {
class PlayerAnimation : public Resource<int16_t> {
public:
using Resource::Resource;
@ -20,4 +18,3 @@ class PlayerAnimation : public Resource<int16_t> {
std::vector<int16_t> limbRotData;
};
} // namespace LUS