mirror of
https://github.com/HarbourMasters/Starship.git
synced 2025-02-03 08:43:56 +03:00
Merge pull request #3 from inspectredc/generic-array-importer
generic array importer
This commit is contained in:
commit
834dbc7e99
@ -6,6 +6,7 @@
|
||||
#include "resource/importers/AnimFactory.h"
|
||||
#include "resource/importers/ColPolyFactory.h"
|
||||
#include "resource/importers/EnvSettingsFactory.h"
|
||||
#include "resource/importers/GenericArrayFactory.h"
|
||||
#include "resource/importers/HitboxFactory.h"
|
||||
#include "resource/importers/LimbFactory.h"
|
||||
#include "resource/importers/MessageFactory.h"
|
||||
@ -65,6 +66,7 @@ GameEngine::GameEngine() {
|
||||
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryColPolyV0>(), RESOURCE_FORMAT_BINARY, "ColPoly", static_cast<uint32_t>(SF64::ResourceType::ColPoly), 0);
|
||||
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryVec3fV0>(), RESOURCE_FORMAT_BINARY, "Vec3f", static_cast<uint32_t>(SF64::ResourceType::Vec3f), 0);
|
||||
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryVec3sV0>(), RESOURCE_FORMAT_BINARY, "Vec3s", static_cast<uint32_t>(SF64::ResourceType::Vec3s), 0);
|
||||
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryGenericArrayV0>(), RESOURCE_FORMAT_BINARY, "GenericArray", static_cast<uint32_t>(SF64::ResourceType::GenericArray), 0);
|
||||
}
|
||||
|
||||
void GameEngine::Create(){
|
||||
|
117
src/port/resource/importers/GenericArrayFactory.cpp
Normal file
117
src/port/resource/importers/GenericArrayFactory.cpp
Normal file
@ -0,0 +1,117 @@
|
||||
#include "GenericArrayFactory.h"
|
||||
#include "../type/GenericArray.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
|
||||
namespace SF64 {
|
||||
std::shared_ptr<LUS::IResource> ResourceFactoryBinaryGenericArrayV0::ReadResource(std::shared_ptr<LUS::File> file) {
|
||||
if (!FileHasValidFormatAndReader(file)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto arr = std::make_shared<GenericArray>(file->InitData);
|
||||
auto reader = std::get<std::shared_ptr<LUS::BinaryReader>>(file->Reader);
|
||||
|
||||
auto type = reader->ReadUInt32();
|
||||
|
||||
SPDLOG_INFO("GenericArray Type Num: {}", type);
|
||||
|
||||
auto count = reader->ReadUInt32();
|
||||
|
||||
SPDLOG_INFO("GenericArray Count: {}", count);
|
||||
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
switch (static_cast<ArrayType>(type)) {
|
||||
case ArrayType::u8: {
|
||||
auto x = reader->ReadUByte();
|
||||
arr->mData.emplace_back(x);
|
||||
break;
|
||||
}
|
||||
case ArrayType::s8: {
|
||||
auto x = reader->ReadInt8();
|
||||
arr->mData.emplace_back(x);
|
||||
break;
|
||||
}
|
||||
case ArrayType::u16: {
|
||||
auto x = reader->ReadUInt16();
|
||||
arr->mData.emplace_back(x);
|
||||
break;
|
||||
}
|
||||
case ArrayType::s16: {
|
||||
auto x = reader->ReadInt16();
|
||||
arr->mData.emplace_back(x);
|
||||
break;
|
||||
}
|
||||
case ArrayType::u32: {
|
||||
auto x = reader->ReadUInt32();
|
||||
arr->mData.emplace_back(x);
|
||||
break;
|
||||
}
|
||||
case ArrayType::s32: {
|
||||
auto x = reader->ReadInt32();
|
||||
arr->mData.emplace_back(x);
|
||||
break;
|
||||
}
|
||||
case ArrayType::u64: {
|
||||
auto x = reader->ReadUInt64();
|
||||
arr->mData.emplace_back(x);
|
||||
break;
|
||||
}
|
||||
case ArrayType::f32: {
|
||||
auto x = reader->ReadFloat();
|
||||
arr->mData.emplace_back(x);
|
||||
break;
|
||||
}
|
||||
case ArrayType::f64: {
|
||||
auto x = reader->ReadDouble();
|
||||
arr->mData.emplace_back(x);
|
||||
break;
|
||||
}
|
||||
case ArrayType::Vec2f: {
|
||||
auto x = reader->ReadFloat();
|
||||
auto y = reader->ReadFloat();
|
||||
arr->mData.emplace_back(Vec2f(x, y));
|
||||
break;
|
||||
}
|
||||
case ArrayType::Vec3f: {
|
||||
auto x = reader->ReadFloat();
|
||||
auto y = reader->ReadFloat();
|
||||
auto z = reader->ReadFloat();
|
||||
arr->mData.emplace_back(Vec3f(x, y, z));
|
||||
break;
|
||||
}
|
||||
case ArrayType::Vec3s: {
|
||||
auto x = reader->ReadInt16();
|
||||
auto y = reader->ReadInt16();
|
||||
auto z = reader->ReadInt16();
|
||||
arr->mData.emplace_back(Vec3s(x, y, z));
|
||||
break;
|
||||
}
|
||||
case ArrayType::Vec3i: {
|
||||
auto x = reader->ReadInt32();
|
||||
auto y = reader->ReadInt32();
|
||||
auto z = reader->ReadInt32();
|
||||
arr->mData.emplace_back(Vec3i(x, y, z));
|
||||
break;
|
||||
}
|
||||
case ArrayType::Vec4f: {
|
||||
auto x = reader->ReadFloat();
|
||||
auto y = reader->ReadFloat();
|
||||
auto z = reader->ReadFloat();
|
||||
auto w = reader->ReadFloat();
|
||||
arr->mData.emplace_back(Vec4f(x, y, z, w));
|
||||
break;
|
||||
}
|
||||
case ArrayType::Vec4s: {
|
||||
auto x = reader->ReadInt16();
|
||||
auto y = reader->ReadInt16();
|
||||
auto z = reader->ReadInt16();
|
||||
auto w = reader->ReadInt16();
|
||||
arr->mData.emplace_back(Vec4s(x, y, z, w));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return arr;
|
||||
}
|
||||
} // namespace LUS
|
11
src/port/resource/importers/GenericArrayFactory.h
Normal file
11
src/port/resource/importers/GenericArrayFactory.h
Normal file
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "Resource.h"
|
||||
#include "ResourceFactoryBinary.h"
|
||||
|
||||
namespace SF64 {
|
||||
class ResourceFactoryBinaryGenericArrayV0 : public LUS::ResourceFactoryBinary {
|
||||
public:
|
||||
std::shared_ptr<LUS::IResource> ReadResource(std::shared_ptr<LUS::File> file) override;
|
||||
};
|
||||
}; // namespace LUS
|
11
src/port/resource/type/GenericArray.cpp
Normal file
11
src/port/resource/type/GenericArray.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include "GenericArray.h"
|
||||
|
||||
namespace SF64 {
|
||||
GenericArrayData* GenericArray::GetPointer() {
|
||||
return mData.data();
|
||||
}
|
||||
|
||||
size_t GenericArray::GetPointerSize() {
|
||||
return sizeof(mData);
|
||||
}
|
||||
}
|
56
src/port/resource/type/GenericArray.h
Normal file
56
src/port/resource/type/GenericArray.h
Normal file
@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <Resource.h>
|
||||
#include <libultraship/libultra/types.h>
|
||||
|
||||
namespace SF64 {
|
||||
|
||||
struct Vec2f {
|
||||
float x, y;
|
||||
Vec2f(float x, float y) : x(x), y(y) {}
|
||||
};
|
||||
|
||||
struct Vec3f {
|
||||
float x, y, z;
|
||||
Vec3f(float x, float y, float z) : x(x), y(y), z(z) {}
|
||||
};
|
||||
|
||||
struct Vec3s {
|
||||
int16_t x, y, z;
|
||||
Vec3s(int16_t x, int16_t y, int16_t z) : x(x), y(y), z(z) {}
|
||||
};
|
||||
|
||||
struct Vec3i {
|
||||
int32_t x, y, z;
|
||||
Vec3i(int32_t x, int32_t y, int32_t z) : x(x), y(y), z(z) {}
|
||||
};
|
||||
|
||||
struct Vec4f {
|
||||
float x, y, z, w;
|
||||
Vec4f(float x, float y, float z, float w) : x(x), y(y), z(z), w(w) {}
|
||||
};
|
||||
|
||||
struct Vec4s {
|
||||
int16_t x, y, z, w;
|
||||
Vec4s(int16_t x, int16_t y, int16_t z, int16_t w) : x(x), y(y), z(z), w(w) {}
|
||||
};
|
||||
|
||||
typedef std::variant<uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, float, double, Vec2f, Vec3f, Vec3s, Vec3i, Vec4f, Vec4s> GenericArrayData;
|
||||
|
||||
enum class ArrayType {
|
||||
u8, s8, u16, s16, u32, s32, u64, f32, f64, Vec2f, Vec3f, Vec3s, Vec3i, Vec4f, Vec4s,
|
||||
};
|
||||
|
||||
class GenericArray : public LUS::Resource<GenericArrayData> {
|
||||
public:
|
||||
using Resource::Resource;
|
||||
|
||||
GenericArray() : Resource(std::shared_ptr<LUS::ResourceInitData>()) {}
|
||||
|
||||
GenericArrayData* GetPointer();
|
||||
size_t GetPointerSize();
|
||||
|
||||
std::vector<GenericArrayData> mData;
|
||||
};
|
||||
}
|
@ -16,5 +16,6 @@ enum class ResourceType {
|
||||
ObjectInit = 0x4F42494E, // OBIN
|
||||
Vec3f = 0x56433346, // VC3F
|
||||
Vec3s = 0x56433353, // VC3S
|
||||
GenericArray = 0x47415252, // GARR
|
||||
};
|
||||
} // namespace SOH
|
||||
|
Loading…
Reference in New Issue
Block a user