From cc38a86b0463a96043ef6e03eb649888aaa080cd Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Fri, 9 Feb 2024 00:43:34 -0500 Subject: [PATCH 01/25] checking in what i have to test something --- src/CMakeLists.txt | 9 ++++++++- src/resource/ResourceFactory.cpp | 22 --------------------- src/resource/ResourceFactory.h | 17 ++-------------- src/resource/ResourceLoader.cpp | 21 +++++++++++++------- src/resource/ResourceLoader.h | 13 +++++++++--- src/resource/ResourceType.h | 2 +- src/resource/factory/DisplayListFactory.h | 5 +++++ src/resource/factory/TextureFactory.cpp | 24 +++++++++++++++++++---- src/resource/factory/TextureFactory.h | 16 +++++++-------- src/resource/readerbox/BinaryReaderBox.h | 20 +++++++++++++++++++ src/resource/readerbox/ReaderBox.h | 3 +++ src/resource/readerbox/XMLReaderBox.h | 11 +++++++++++ 12 files changed, 101 insertions(+), 62 deletions(-) delete mode 100644 src/resource/ResourceFactory.cpp create mode 100644 src/resource/readerbox/BinaryReaderBox.h create mode 100644 src/resource/readerbox/ReaderBox.h create mode 100644 src/resource/readerbox/XMLReaderBox.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 15b724dcb..0a1555f42 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -373,7 +373,14 @@ set(Source_Files__Resource__Archive ) source_group("resource/archive" FILES ${Source_Files__Resource__Archive}) -target_sources(libultraship PRIVATE ${Source_Files__Resource} ${Source_Files__Resource__Types} ${Source_Files__Resource__Factories} ${Source_Files__Resource__Archive}) +set(Source_Files__Resource__ReaderBox + ${CMAKE_CURRENT_SOURCE_DIR}/resource/readerbox/ReaderBox.h + ${CMAKE_CURRENT_SOURCE_DIR}/resource/readerbox/BinaryReaderBox.h + ${CMAKE_CURRENT_SOURCE_DIR}/resource/readerbox/XMLReaderBox.h +) +source_group("resource/readerbox" FILES ${Source_Files__Resource__ReaderBox}) + +target_sources(libultraship PRIVATE ${Source_Files__Resource} ${Source_Files__Resource__Types} ${Source_Files__Resource__Factories} ${Source_Files__Resource__Archive} ${Source_Files__Resource__ReaderBox}) #=================== Graphic =================== diff --git a/src/resource/ResourceFactory.cpp b/src/resource/ResourceFactory.cpp deleted file mode 100644 index 81619ef84..000000000 --- a/src/resource/ResourceFactory.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "ResourceFactory.h" - -namespace LUS { -void ResourceVersionFactory::ParseFileBinary(std::shared_ptr reader, - std::shared_ptr resource) { -} - -void ResourceVersionFactory::ParseFileXML(tinyxml2::XMLElement* reader, std::shared_ptr resource) { -} - -void ResourceVersionFactory::WriteFileBinary(std::shared_ptr writer, - std::shared_ptr resource) { -} - -void ResourceVersionFactory::WriteFileXML(tinyxml2::XMLElement* writer, std::shared_ptr resource) { -} - -std::shared_ptr ResourceFactory::ReadResourceXML(std::shared_ptr initData, - tinyxml2::XMLElement* reader) { - return nullptr; -} -} // namespace LUS diff --git a/src/resource/ResourceFactory.h b/src/resource/ResourceFactory.h index 1831057fa..2f74cf00a 100644 --- a/src/resource/ResourceFactory.h +++ b/src/resource/ResourceFactory.h @@ -1,26 +1,13 @@ #pragma once #include -#include "utils/binarytools/BinaryReader.h" -#include "utils/binarytools/BinaryWriter.h" -#include +#include "readerbox/ReaderBox.h" #include "Resource.h" namespace LUS { -class ResourceManager; class ResourceFactory { public: virtual std::shared_ptr ReadResource(std::shared_ptr initData, - std::shared_ptr reader) = 0; - virtual std::shared_ptr ReadResourceXML(std::shared_ptr initData, - tinyxml2::XMLElement* reader); -}; - -class ResourceVersionFactory { - public: - virtual void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource); - virtual void ParseFileXML(tinyxml2::XMLElement* reader, std::shared_ptr resource); - virtual void WriteFileBinary(std::shared_ptr writer, std::shared_ptr resource); - virtual void WriteFileXML(tinyxml2::XMLElement* writer, std::shared_ptr resource); + std::shared_ptr readerBox) = 0; }; } // namespace LUS diff --git a/src/resource/ResourceLoader.cpp b/src/resource/ResourceLoader.cpp index f49bda0a5..a7735d75e 100644 --- a/src/resource/ResourceLoader.cpp +++ b/src/resource/ResourceLoader.cpp @@ -23,6 +23,7 @@ ResourceLoader::~ResourceLoader() { } void ResourceLoader::RegisterGlobalResourceFactories() { + // include strings so we register types for mResourceTypes RegisterResourceFactory(static_cast(ResourceType::Texture), std::make_shared()); RegisterResourceFactory(static_cast(ResourceType::Vertex), std::make_shared()); RegisterResourceFactory(static_cast(ResourceType::DisplayList), std::make_shared()); @@ -31,17 +32,19 @@ void ResourceLoader::RegisterGlobalResourceFactories() { RegisterResourceFactory(static_cast(ResourceType::Blob), std::make_shared()); } -bool ResourceLoader::RegisterResourceFactory(uint32_t resourceType, std::shared_ptr factory) { - if (mFactories.contains(resourceType)) { +bool ResourceLoader::RegisterResourceFactory(std::shared_ptr factory, uint32_t format, std::string typeName, uint32_t type, uint32_t version) { + if (mResourceTypes.contains(typeName)) { return false; } + mResourceTypes[typeName] = type; - mFactories[resourceType] = factory; - return true; -} + ResourceFactoryKey key = {resourceFormat: format, resourceType: type, resourceVersion: version}; + if (mFactories.contains(key)) { + return false; + } + mFactories[key] = factory; -uint32_t ResourceLoader::GetVersionFromString(const std::string& version) { - return mFactoriesTypes[version]; + return true; } std::shared_ptr ResourceLoader::LoadResource(std::shared_ptr fileToLoad) { @@ -57,6 +60,10 @@ std::shared_ptr ResourceLoader::LoadResource(std::shared_ptr fi return result; } + // call method to get factory based on factorykey (generate using params) + // make a method that takes in a string instead of an int for the type too + // make those protected + auto factory = mFactories[fileToLoad->InitData->Type]; if (factory == nullptr) { SPDLOG_ERROR("Failed to load resource: Factory does not exist ({} - {})", fileToLoad->InitData->Type, diff --git a/src/resource/ResourceLoader.h b/src/resource/ResourceLoader.h index ff5120b3c..8f2899abf 100644 --- a/src/resource/ResourceLoader.h +++ b/src/resource/ResourceLoader.h @@ -9,19 +9,26 @@ namespace LUS { struct File; +struct ResourceFactoryKey { + uint32_t resourceFormat; + uint32_t resourceType; + uint32_t resourceVersion; +}; + class ResourceLoader { public: ResourceLoader(); ~ResourceLoader(); std::shared_ptr LoadResource(std::shared_ptr fileToLoad); - bool RegisterResourceFactory(uint32_t resourceType, std::shared_ptr factory); - uint32_t GetVersionFromString(const std::string& version); + bool RegisterResourceFactory(std::shared_ptr factory, uint32_t format, std::string typeName, uint32_t type, uint32_t version); protected: void RegisterGlobalResourceFactories(); private: - std::unordered_map> mFactories; + uint32_t GetResourceType(const std::string& type); + std::unordered_map mResourceTypes; + std::unordered_map> mFactories; }; } // namespace LUS diff --git a/src/resource/ResourceType.h b/src/resource/ResourceType.h index 59d1cfae3..8516120f8 100644 --- a/src/resource/ResourceType.h +++ b/src/resource/ResourceType.h @@ -36,7 +36,7 @@ enum class ResourceType { SOH_SceneCommand = 0x4F52434D, // ORCM }; -inline std::unordered_map mFactoriesTypes{ +inline std::unordered_map mResourceTypes { { "None", static_cast(ResourceType::None) }, { "Archive", static_cast(ResourceType::Archive) }, { "DisplayList", static_cast(ResourceType::DisplayList) }, diff --git a/src/resource/factory/DisplayListFactory.h b/src/resource/factory/DisplayListFactory.h index 23fe884ce..d5be726a6 100644 --- a/src/resource/factory/DisplayListFactory.h +++ b/src/resource/factory/DisplayListFactory.h @@ -19,4 +19,9 @@ class DisplayListFactoryV0 : public ResourceVersionFactory { uint32_t GetCombineLERPValue(std::string valStr); }; + +// XMLDisplayListV0 +// XMLDisplayListV0Factory +// ResourceFactoryXMLDisplayListV0 + } // namespace LUS diff --git a/src/resource/factory/TextureFactory.cpp b/src/resource/factory/TextureFactory.cpp index 1058461f3..b9b24fde0 100644 --- a/src/resource/factory/TextureFactory.cpp +++ b/src/resource/factory/TextureFactory.cpp @@ -1,12 +1,28 @@ #include "resource/factory/TextureFactory.h" #include "resource/type/Texture.h" +#include "resource/readerbox/BinaryReaderBox.h" #include "spdlog/spdlog.h" namespace LUS { -std::shared_ptr TextureFactory::ReadResource(std::shared_ptr initData, - std::shared_ptr reader) { - auto resource = std::make_shared(initData); +std::shared_ptr ResourceFactoryBinaryTextureV0::ReadResource(std::shared_ptr initData, + std::shared_ptr readerBox) { + auto binaryReaderBox = std::dynamic_pointer_cast(readerBox); + if (binaryReaderBox == nullptr) { + SPDLOG_ERROR("ReaderBox must be a BinaryReaderBox."); + return nullptr; + } + + auto reader = binaryReaderBox->GetReader(); + if (reader == nullptr) { + SPDLOG_ERROR("null reader in box."); + return nullptr; + } + + auto texture = std::make_shared(initData); + + + std::shared_ptr factory = nullptr; switch (resource->GetInitData()->ResourceVersion) { @@ -29,7 +45,7 @@ std::shared_ptr TextureFactory::ReadResource(std::shared_ptr reader, std::shared_ptr resource) { - std::shared_ptr texture = std::static_pointer_cast(resource); + // std::shared_ptr texture = std::static_pointer_cast(resource); ResourceVersionFactory::ParseFileBinary(reader, texture); texture->Type = (TextureType)reader->ReadUInt32(); diff --git a/src/resource/factory/TextureFactory.h b/src/resource/factory/TextureFactory.h index be3b0c8f0..f3cc2bba5 100644 --- a/src/resource/factory/TextureFactory.h +++ b/src/resource/factory/TextureFactory.h @@ -2,21 +2,19 @@ #include "resource/Resource.h" #include "resource/ResourceFactory.h" +#include "resource/readerbox/BinaryReaderBox.h" namespace LUS { -class TextureFactory : public ResourceFactory { +// ResourceFactoryXMLDisplayListV0 +class ResourceFactoryBinaryTextureV0 : public ResourceFactory { public: std::shared_ptr ReadResource(std::shared_ptr initData, - std::shared_ptr reader) override; + std::shared_ptr readerBox) override; }; -class TextureFactoryV0 : public ResourceVersionFactory { +class ResourceFactoryBinaryTextureV1 : public ResourceFactory { public: - void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; -}; - -class TextureFactoryV1 : public ResourceVersionFactory { - public: - void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; + std::shared_ptr ReadResource(std::shared_ptr initData, + std::shared_ptr readerBox) override; }; } // namespace LUS diff --git a/src/resource/readerbox/BinaryReaderBox.h b/src/resource/readerbox/BinaryReaderBox.h new file mode 100644 index 000000000..ccf8ea465 --- /dev/null +++ b/src/resource/readerbox/BinaryReaderBox.h @@ -0,0 +1,20 @@ +#include "ReaderBox.h" +#include "utils/binarytools/BinaryReader.h" + +namespace LUS { +class BinaryReaderBox : public ReaderBox { + public: + BinaryReaderBox(std::shared_ptr reader) { + mReader = reader; + }; + std::shared_ptr GetReader() { + return mReader; + }; + ~BinaryReaderBox() { + mReader = nullptr; + }; + + private: + std::shared_ptr mReader; +}; +} // namespace LUS diff --git a/src/resource/readerbox/ReaderBox.h b/src/resource/readerbox/ReaderBox.h new file mode 100644 index 000000000..6669be4e2 --- /dev/null +++ b/src/resource/readerbox/ReaderBox.h @@ -0,0 +1,3 @@ +namespace LUS { +class ReaderBox {}; +} // namespace LUS diff --git a/src/resource/readerbox/XMLReaderBox.h b/src/resource/readerbox/XMLReaderBox.h new file mode 100644 index 000000000..9d22a8fca --- /dev/null +++ b/src/resource/readerbox/XMLReaderBox.h @@ -0,0 +1,11 @@ +#include "ReaderBox.h" + +namespace LUS { +class XMLReaderBox : public ReaderBox { + public: + // std::shared_ptr GetXMLReader(); + + private: + +}; +} // namespace LUS \ No newline at end of file From 2eab0fa0710488ada122c12e90562e1247c86d95 Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Fri, 9 Feb 2024 01:12:29 -0500 Subject: [PATCH 02/25] i think this is a somewhat reasonable way for these to look? --- src/resource/factory/TextureFactory.cpp | 49 ++++++++++--------------- 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/src/resource/factory/TextureFactory.cpp b/src/resource/factory/TextureFactory.cpp index b9b24fde0..b8e67db4f 100644 --- a/src/resource/factory/TextureFactory.cpp +++ b/src/resource/factory/TextureFactory.cpp @@ -21,33 +21,6 @@ std::shared_ptr ResourceFactoryBinaryTextureV0::ReadResource(std::sha auto texture = std::make_shared(initData); - - - std::shared_ptr factory = nullptr; - - switch (resource->GetInitData()->ResourceVersion) { - case 0: - factory = std::make_shared(); - break; - case 1: - factory = std::make_shared(); - break; - } - - if (factory == nullptr) { - SPDLOG_ERROR("Failed to load Texture with version {}", resource->GetInitData()->ResourceVersion); - return nullptr; - } - - factory->ParseFileBinary(reader, resource); - - return resource; -} - -void TextureFactoryV0::ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) { - // std::shared_ptr texture = std::static_pointer_cast(resource); - ResourceVersionFactory::ParseFileBinary(reader, texture); - texture->Type = (TextureType)reader->ReadUInt32(); texture->Width = reader->ReadUInt32(); texture->Height = reader->ReadUInt32(); @@ -55,11 +28,25 @@ void TextureFactoryV0::ParseFileBinary(std::shared_ptr reader, std texture->ImageData = new uint8_t[texture->ImageDataSize]; reader->Read((char*)texture->ImageData, texture->ImageDataSize); + + return texture; } -void TextureFactoryV1::ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) { - std::shared_ptr texture = std::static_pointer_cast(resource); - ResourceVersionFactory::ParseFileBinary(reader, texture); +std::shared_ptr ResourceFactoryBinaryTextureV1::ReadResource(std::shared_ptr initData, + std::shared_ptr readerBox) { + auto binaryReaderBox = std::dynamic_pointer_cast(readerBox); + if (binaryReaderBox == nullptr) { + SPDLOG_ERROR("ReaderBox must be a BinaryReaderBox."); + return nullptr; + } + + auto reader = binaryReaderBox->GetReader(); + if (reader == nullptr) { + SPDLOG_ERROR("null reader in box."); + return nullptr; + } + + auto texture = std::make_shared(initData); texture->Type = (TextureType)reader->ReadUInt32(); texture->Width = reader->ReadUInt32(); @@ -71,5 +58,7 @@ void TextureFactoryV1::ParseFileBinary(std::shared_ptr reader, std texture->ImageData = new uint8_t[texture->ImageDataSize]; reader->Read((char*)texture->ImageData, texture->ImageDataSize); + + return texture; } } // namespace LUS From 6f7b32c7a68d560166add0b0d14b5abf910caede Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Fri, 9 Feb 2024 01:34:21 -0500 Subject: [PATCH 03/25] i think this is how vertex can look --- src/resource/factory/TextureFactory.h | 2 - src/resource/factory/VertexFactory.cpp | 73 +++++++++++--------------- src/resource/factory/VertexFactory.h | 13 ++--- src/resource/readerbox/XMLReaderBox.h | 14 ++++- 4 files changed, 49 insertions(+), 53 deletions(-) diff --git a/src/resource/factory/TextureFactory.h b/src/resource/factory/TextureFactory.h index f3cc2bba5..d562b0f0e 100644 --- a/src/resource/factory/TextureFactory.h +++ b/src/resource/factory/TextureFactory.h @@ -2,10 +2,8 @@ #include "resource/Resource.h" #include "resource/ResourceFactory.h" -#include "resource/readerbox/BinaryReaderBox.h" namespace LUS { -// ResourceFactoryXMLDisplayListV0 class ResourceFactoryBinaryTextureV0 : public ResourceFactory { public: std::shared_ptr ReadResource(std::shared_ptr initData, diff --git a/src/resource/factory/VertexFactory.cpp b/src/resource/factory/VertexFactory.cpp index f9fca26f6..ce14d1dfc 100644 --- a/src/resource/factory/VertexFactory.cpp +++ b/src/resource/factory/VertexFactory.cpp @@ -1,53 +1,25 @@ #include "resource/factory/VertexFactory.h" #include "resource/type/Vertex.h" +#include "resource/readerbox/BinaryReaderBox.h" +#include "resource/readerbox/XMLReaderBox.h" #include "spdlog/spdlog.h" namespace LUS { -std::shared_ptr VertexFactory::ReadResource(std::shared_ptr initData, - std::shared_ptr reader) { - auto resource = std::make_shared(initData); - std::shared_ptr factory = nullptr; - - switch (resource->GetInitData()->ResourceVersion) { - case 0: - factory = std::make_shared(); - break; - } - - if (factory == nullptr) { - SPDLOG_ERROR("Failed to load Vertex with version {}", resource->GetInitData()->ResourceVersion); +std::shared_ptr ResourceFactoryBinaryVertexV0::ReadResource(std::shared_ptr initData, + std::shared_ptr readerBox) { + auto binaryReaderBox = std::dynamic_pointer_cast(readerBox); + if (binaryReaderBox == nullptr) { + SPDLOG_ERROR("ReaderBox must be a BinaryReaderBox."); return nullptr; } - factory->ParseFileBinary(reader, resource); - - return resource; -} - -std::shared_ptr VertexFactory::ReadResourceXML(std::shared_ptr initData, - tinyxml2::XMLElement* reader) { - auto resource = std::make_shared(initData); - std::shared_ptr factory = nullptr; - - switch (resource->GetInitData()->ResourceVersion) { - case 0: - factory = std::make_shared(); - break; - } - - if (factory == nullptr) { - SPDLOG_ERROR("Failed to load Vertex with version {}", resource->GetInitData()->ResourceVersion); + auto reader = binaryReaderBox->GetReader(); + if (reader == nullptr) { + SPDLOG_ERROR("null reader in box."); return nullptr; } - factory->ParseFileXML(reader, resource); - - return resource; -} - -void VertexFactoryV0::ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) { - std::shared_ptr vertex = std::static_pointer_cast(resource); - ResourceVersionFactory::ParseFileBinary(reader, vertex); + auto vertex = std::make_shared(initData); uint32_t count = reader->ReadUInt32(); vertex->VertexList.reserve(count); @@ -66,9 +38,26 @@ void VertexFactoryV0::ParseFileBinary(std::shared_ptr reader, std: data.v.cn[3] = reader->ReadUByte(); vertex->VertexList.push_back(data); } + + return vertex; } -void LUS::VertexFactoryV0::ParseFileXML(tinyxml2::XMLElement* reader, std::shared_ptr resource) { - std::shared_ptr vertex = std::static_pointer_cast(resource); + +std::shared_ptr ResourceFactoryXMLVertexV0::ReadResource(std::shared_ptr initData, + std::shared_ptr readerBox) { + auto xmlReaderBox = std::dynamic_pointer_cast(readerBox); + if (xmlReaderBox == nullptr) { + SPDLOG_ERROR("ReaderBox must be an XMLReaderBox."); + return nullptr; + } + + auto reader = xmlReaderBox->GetReader(); + if (reader == nullptr) { + SPDLOG_ERROR("null reader in box."); + return nullptr; + } + + auto vertex = std::make_shared(initData); + auto child = reader->FirstChildElement(); while (child != nullptr) { @@ -92,5 +81,7 @@ void LUS::VertexFactoryV0::ParseFileXML(tinyxml2::XMLElement* reader, std::share child = child->NextSiblingElement(); } + + return vertex; } } // namespace LUS diff --git a/src/resource/factory/VertexFactory.h b/src/resource/factory/VertexFactory.h index cb552446c..0056d858d 100644 --- a/src/resource/factory/VertexFactory.h +++ b/src/resource/factory/VertexFactory.h @@ -4,18 +4,15 @@ #include "resource/ResourceFactory.h" namespace LUS { - -class VertexFactory : public ResourceFactory { +class ResourceFactoryBinaryVertexV0 : public ResourceFactory { public: std::shared_ptr ReadResource(std::shared_ptr initData, - std::shared_ptr reader) override; - std::shared_ptr ReadResourceXML(std::shared_ptr initData, - tinyxml2::XMLElement* reader); + std::shared_ptr readerBox) override; }; -class VertexFactoryV0 : public ResourceVersionFactory { +class ResourceFactoryXMLVertexV0 : public ResourceFactory { public: - void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; - void ParseFileXML(tinyxml2::XMLElement* reader, std::shared_ptr resource) override; + std::shared_ptr ReadResource(std::shared_ptr initData, + std::shared_ptr readerBox) override; }; } // namespace LUS diff --git a/src/resource/readerbox/XMLReaderBox.h b/src/resource/readerbox/XMLReaderBox.h index 9d22a8fca..8983c55e7 100644 --- a/src/resource/readerbox/XMLReaderBox.h +++ b/src/resource/readerbox/XMLReaderBox.h @@ -1,11 +1,21 @@ #include "ReaderBox.h" +#include +#include namespace LUS { class XMLReaderBox : public ReaderBox { public: - // std::shared_ptr GetXMLReader(); + XMLReaderBox(std::shared_ptr reader) { + mReader = reader; + }; + std::shared_ptr GetReader() { + return mReader; + }; + ~XMLReaderBox() { + mReader = nullptr; + }; private: - + std::shared_ptr mReader; }; } // namespace LUS \ No newline at end of file From b7387bbdc34be4dfeacaddae05966ce0398c4f4e Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Fri, 9 Feb 2024 01:41:52 -0500 Subject: [PATCH 04/25] matrix --- src/resource/factory/MatrixFactory.cpp | 34 +++++++++++--------------- src/resource/factory/MatrixFactory.h | 9 ++----- 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/src/resource/factory/MatrixFactory.cpp b/src/resource/factory/MatrixFactory.cpp index ba1533b33..f858d4a77 100644 --- a/src/resource/factory/MatrixFactory.cpp +++ b/src/resource/factory/MatrixFactory.cpp @@ -1,37 +1,31 @@ #include "resource/factory/MatrixFactory.h" #include "resource/type/Matrix.h" +#include "resource/readerbox/BinaryReaderBox.h" #include "spdlog/spdlog.h" namespace LUS { -std::shared_ptr MatrixFactory::ReadResource(std::shared_ptr initData, - std::shared_ptr reader) { - auto resource = std::make_shared(initData); - std::shared_ptr factory = nullptr; - - switch (resource->GetInitData()->ResourceVersion) { - case 0: - factory = std::make_shared(); - break; +std::shared_ptr ResourceFactoryBinaryMatrixV0::ReadResource(std::shared_ptr initData, + std::shared_ptr readerBox) { + auto binaryReaderBox = std::dynamic_pointer_cast(readerBox); + if (binaryReaderBox == nullptr) { + SPDLOG_ERROR("ReaderBox must be a BinaryReaderBox."); + return nullptr; } - if (factory == nullptr) { - SPDLOG_ERROR("Failed to load Matrix with version {}", resource->GetInitData()->ResourceVersion); + auto reader = binaryReaderBox->GetReader(); + if (reader == nullptr) { + SPDLOG_ERROR("null reader in box."); return nullptr; } - factory->ParseFileBinary(reader, resource); - - return resource; -} - -void MatrixFactoryV0::ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) { - std::shared_ptr mtx = static_pointer_cast(resource); - ResourceVersionFactory::ParseFileBinary(reader, resource); + auto matrix = std::make_shared(initData); for (size_t i = 0; i < 4; i++) { for (size_t j = 0; j < 4; j++) { - mtx->Matrx.m[i][j] = reader->ReadInt32(); + matrix->Matrx.m[i][j] = reader->ReadInt32(); } } + + return matrix; } } // namespace LUS diff --git a/src/resource/factory/MatrixFactory.h b/src/resource/factory/MatrixFactory.h index f50774e10..2ee988bc3 100644 --- a/src/resource/factory/MatrixFactory.h +++ b/src/resource/factory/MatrixFactory.h @@ -4,14 +4,9 @@ #include "resource/ResourceFactory.h" namespace LUS { -class MatrixFactory : public ResourceFactory { +class ResourceFactoryBinaryMatrixV0 : public ResourceFactory { public: std::shared_ptr ReadResource(std::shared_ptr initData, - std::shared_ptr reader) override; -}; - -class MatrixFactoryV0 : public ResourceVersionFactory { - public: - void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; + std::shared_ptr readerBox) override; }; } // namespace LUS From a4df46a5d19eb1b7b84a6392482e616256116015 Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Fri, 9 Feb 2024 01:54:00 -0500 Subject: [PATCH 05/25] dlists --- src/resource/factory/DisplayListFactory.cpp | 167 +++++++++----------- src/resource/factory/DisplayListFactory.h | 24 ++- 2 files changed, 88 insertions(+), 103 deletions(-) diff --git a/src/resource/factory/DisplayListFactory.cpp b/src/resource/factory/DisplayListFactory.cpp index e731fff3b..d80289a8d 100644 --- a/src/resource/factory/DisplayListFactory.cpp +++ b/src/resource/factory/DisplayListFactory.cpp @@ -1,55 +1,27 @@ #include "resource/factory/DisplayListFactory.h" #include "resource/type/DisplayList.h" +#include "resource/readerbox/BinaryReaderBox.h" +#include "resource/readerbox/XMLReaderBox.h" #include "spdlog/spdlog.h" #define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0])) namespace LUS { -std::shared_ptr DisplayListFactory::ReadResource(std::shared_ptr initData, - std::shared_ptr reader) { - auto resource = std::make_shared(initData); - std::shared_ptr factory = nullptr; - - switch (resource->GetInitData()->ResourceVersion) { - case 0: - factory = std::make_shared(); - break; - } - - if (factory == nullptr) { - SPDLOG_ERROR("Failed to load DisplayList with version {}", resource->GetInitData()->ResourceVersion); +std::shared_ptr ResourceFactoryBinaryDisplayListV0::ReadResource(std::shared_ptr initData, + std::shared_ptr readerBox) { + auto binaryReaderBox = std::dynamic_pointer_cast(readerBox); + if (binaryReaderBox == nullptr) { + SPDLOG_ERROR("ReaderBox must be a BinaryReaderBox."); return nullptr; } - factory->ParseFileBinary(reader, resource); - - return resource; -} - -std::shared_ptr DisplayListFactory::ReadResourceXML(std::shared_ptr initData, - tinyxml2::XMLElement* reader) { - auto resource = std::make_shared(initData); - std::shared_ptr factory = nullptr; - - switch (resource->GetInitData()->ResourceVersion) { - case 0: - factory = std::make_shared(); - break; - } - - if (factory == nullptr) { - SPDLOG_ERROR("Failed to load DisplayList with version {}", resource->GetInitData()->ResourceVersion); + auto reader = binaryReaderBox->GetReader(); + if (reader == nullptr) { + SPDLOG_ERROR("null reader in box."); return nullptr; } - factory->ParseFileXML(reader, resource); - - return resource; -} - -void DisplayListFactoryV0::ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) { - std::shared_ptr displayList = std::static_pointer_cast(resource); - ResourceVersionFactory::ParseFileBinary(reader, displayList); + auto displayList = std::make_shared(initData); while (reader->GetBaseAddress() % 8 != 0) { reader->ReadInt8(); @@ -77,60 +49,25 @@ void DisplayListFactoryV0::ParseFileBinary(std::shared_ptr reader, break; } } -} - -std::unordered_map renderModes = { { "G_RM_ZB_OPA_SURF", G_RM_ZB_OPA_SURF }, - { "G_RM_AA_ZB_OPA_SURF", G_RM_AA_ZB_OPA_SURF }, - { "G_RM_AA_ZB_OPA_DECAL", G_RM_AA_ZB_OPA_DECAL }, - { "G_RM_AA_ZB_OPA_INTER", G_RM_AA_ZB_OPA_INTER }, - { "G_RM_AA_ZB_TEX_EDGE", G_RM_AA_ZB_TEX_EDGE }, - { "G_RM_AA_ZB_XLU_SURF", G_RM_AA_ZB_XLU_SURF }, - { "G_RM_AA_ZB_XLU_DECAL", G_RM_AA_ZB_XLU_DECAL }, - { "G_RM_AA_ZB_XLU_INTER", G_RM_AA_ZB_XLU_INTER }, - { "G_RM_FOG_SHADE_A", G_RM_FOG_SHADE_A }, - { "G_RM_FOG_PRIM_A", G_RM_FOG_PRIM_A }, - { "G_RM_PASS", G_RM_PASS }, - { "G_RM_ADD", G_RM_ADD }, - { "G_RM_NOOP", G_RM_NOOP }, - { "G_RM_ZB_OPA_SURF", G_RM_ZB_OPA_SURF }, - { "G_RM_ZB_OPA_DECAL", G_RM_ZB_OPA_DECAL }, - { "G_RM_ZB_XLU_SURF", G_RM_ZB_XLU_SURF }, - { "G_RM_ZB_XLU_DECAL", G_RM_ZB_XLU_DECAL }, - { "G_RM_OPA_SURF", G_RM_OPA_SURF }, - { "G_RM_ZB_CLD_SURF", G_RM_ZB_CLD_SURF }, - { "G_RM_ZB_OPA_SURF2", G_RM_ZB_OPA_SURF2 }, - { "G_RM_AA_ZB_OPA_SURF2", G_RM_AA_ZB_OPA_SURF2 }, - { "G_RM_AA_ZB_OPA_DECAL2", G_RM_AA_ZB_OPA_DECAL2 }, - { "G_RM_AA_ZB_OPA_INTER2", G_RM_AA_ZB_OPA_INTER2 }, - { "G_RM_AA_ZB_TEX_EDGE2", G_RM_AA_ZB_TEX_EDGE2 }, - { "G_RM_AA_ZB_XLU_SURF2", G_RM_AA_ZB_XLU_SURF2 }, - { "G_RM_AA_ZB_XLU_DECAL2", G_RM_AA_ZB_XLU_DECAL2 }, - { "G_RM_AA_ZB_XLU_INTER2", G_RM_AA_ZB_XLU_INTER2 }, - { "G_RM_ADD2", G_RM_ADD2 }, - { "G_RM_ZB_OPA_SURF2", G_RM_ZB_OPA_SURF2 }, - { "G_RM_ZB_OPA_DECAL2", G_RM_ZB_OPA_DECAL2 }, - { "G_RM_ZB_XLU_SURF2", G_RM_ZB_XLU_SURF2 }, - { "G_RM_ZB_XLU_DECAL2", G_RM_ZB_XLU_DECAL2 }, - { "G_RM_ZB_CLD_SURF2", G_RM_ZB_CLD_SURF2 } }; - -static Gfx GsSpVertexOtR2P1(char* filePathPtr) { - Gfx g; - g.words.w0 = G_VTX_OTR_FILEPATH << 24; - g.words.w1 = (uintptr_t)filePathPtr; - return g; + return displayList; } -static Gfx GsSpVertexOtR2P2(int vtxCnt, int vtxBufOffset, int vtxDataOffset) { - Gfx g; - g.words.w0 = (uintptr_t)vtxCnt; - g.words.w1 = (uintptr_t)((vtxBufOffset << 16) | vtxDataOffset); +std::shared_ptr ResourceFactoryXMLDisplayListV0::ReadResource(std::shared_ptr initData, + std::shared_ptr readerBox) { + auto xmlReaderBox = std::dynamic_pointer_cast(readerBox); + if (xmlReaderBox == nullptr) { + SPDLOG_ERROR("ReaderBox must be an XMLReaderBox."); + return nullptr; + } - return g; -} + auto reader = xmlReaderBox->GetReader(); + if (reader == nullptr) { + SPDLOG_ERROR("null reader in box."); + return nullptr; + } -void DisplayListFactoryV0::ParseFileXML(tinyxml2::XMLElement* reader, std::shared_ptr resource) { - std::shared_ptr dl = std::static_pointer_cast(resource); + auto dl = std::make_shared(initData); auto child = reader->FirstChildElement(); @@ -1031,9 +968,61 @@ void DisplayListFactoryV0::ParseFileXML(tinyxml2::XMLElement* reader, std::share child = child->NextSiblingElement(); } + + return displayList; +} + +std::unordered_map renderModes = { { "G_RM_ZB_OPA_SURF", G_RM_ZB_OPA_SURF }, + { "G_RM_AA_ZB_OPA_SURF", G_RM_AA_ZB_OPA_SURF }, + { "G_RM_AA_ZB_OPA_DECAL", G_RM_AA_ZB_OPA_DECAL }, + { "G_RM_AA_ZB_OPA_INTER", G_RM_AA_ZB_OPA_INTER }, + { "G_RM_AA_ZB_TEX_EDGE", G_RM_AA_ZB_TEX_EDGE }, + { "G_RM_AA_ZB_XLU_SURF", G_RM_AA_ZB_XLU_SURF }, + { "G_RM_AA_ZB_XLU_DECAL", G_RM_AA_ZB_XLU_DECAL }, + { "G_RM_AA_ZB_XLU_INTER", G_RM_AA_ZB_XLU_INTER }, + { "G_RM_FOG_SHADE_A", G_RM_FOG_SHADE_A }, + { "G_RM_FOG_PRIM_A", G_RM_FOG_PRIM_A }, + { "G_RM_PASS", G_RM_PASS }, + { "G_RM_ADD", G_RM_ADD }, + { "G_RM_NOOP", G_RM_NOOP }, + { "G_RM_ZB_OPA_SURF", G_RM_ZB_OPA_SURF }, + { "G_RM_ZB_OPA_DECAL", G_RM_ZB_OPA_DECAL }, + { "G_RM_ZB_XLU_SURF", G_RM_ZB_XLU_SURF }, + { "G_RM_ZB_XLU_DECAL", G_RM_ZB_XLU_DECAL }, + { "G_RM_OPA_SURF", G_RM_OPA_SURF }, + { "G_RM_ZB_CLD_SURF", G_RM_ZB_CLD_SURF }, + { "G_RM_ZB_OPA_SURF2", G_RM_ZB_OPA_SURF2 }, + { "G_RM_AA_ZB_OPA_SURF2", G_RM_AA_ZB_OPA_SURF2 }, + { "G_RM_AA_ZB_OPA_DECAL2", G_RM_AA_ZB_OPA_DECAL2 }, + { "G_RM_AA_ZB_OPA_INTER2", G_RM_AA_ZB_OPA_INTER2 }, + { "G_RM_AA_ZB_TEX_EDGE2", G_RM_AA_ZB_TEX_EDGE2 }, + { "G_RM_AA_ZB_XLU_SURF2", G_RM_AA_ZB_XLU_SURF2 }, + { "G_RM_AA_ZB_XLU_DECAL2", G_RM_AA_ZB_XLU_DECAL2 }, + { "G_RM_AA_ZB_XLU_INTER2", G_RM_AA_ZB_XLU_INTER2 }, + { "G_RM_ADD2", G_RM_ADD2 }, + { "G_RM_ZB_OPA_SURF2", G_RM_ZB_OPA_SURF2 }, + { "G_RM_ZB_OPA_DECAL2", G_RM_ZB_OPA_DECAL2 }, + { "G_RM_ZB_XLU_SURF2", G_RM_ZB_XLU_SURF2 }, + { "G_RM_ZB_XLU_DECAL2", G_RM_ZB_XLU_DECAL2 }, + { "G_RM_ZB_CLD_SURF2", G_RM_ZB_CLD_SURF2 } }; + +static Gfx GsSpVertexOtR2P1(char* filePathPtr) { + Gfx g; + g.words.w0 = G_VTX_OTR_FILEPATH << 24; + g.words.w1 = (uintptr_t)filePathPtr; + + return g; +} + +static Gfx GsSpVertexOtR2P2(int vtxCnt, int vtxBufOffset, int vtxDataOffset) { + Gfx g; + g.words.w0 = (uintptr_t)vtxCnt; + g.words.w1 = (uintptr_t)((vtxBufOffset << 16) | vtxDataOffset); + + return g; } -uint32_t DisplayListFactoryV0::GetCombineLERPValue(std::string valStr) { +uint32_t ResourceFactoryDisplayList::GetCombineLERPValue(std::string valStr) { std::string strings[] = { "G_CCMUX_COMBINED", "G_CCMUX_TEXEL0", "G_CCMUX_TEXEL1", diff --git a/src/resource/factory/DisplayListFactory.h b/src/resource/factory/DisplayListFactory.h index d5be726a6..74c78b889 100644 --- a/src/resource/factory/DisplayListFactory.h +++ b/src/resource/factory/DisplayListFactory.h @@ -4,24 +4,20 @@ #include "resource/ResourceFactory.h" namespace LUS { -class DisplayListFactory : public ResourceFactory { +class ResourceFactoryDisplayList : public ResourceFactory { + protected: + uint32_t GetCombineLERPValue(std::string valStr); +}; + +class ResourceFactoryBinaryDisplayListV0 : public ResourceFactoryDisplayList { public: std::shared_ptr ReadResource(std::shared_ptr initData, - std::shared_ptr reader) override; - std::shared_ptr ReadResourceXML(std::shared_ptr initData, - tinyxml2::XMLElement* reader) override; + std::shared_ptr readerBox) override; }; -class DisplayListFactoryV0 : public ResourceVersionFactory { +class ResourceFactoryXMLDisplayListV0 : public ResourceFactoryDisplayList { public: - void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; - void ParseFileXML(tinyxml2::XMLElement* reader, std::shared_ptr resource) override; - - uint32_t GetCombineLERPValue(std::string valStr); + std::shared_ptr ReadResource(std::shared_ptr initData, + std::shared_ptr readerBox) override; }; - -// XMLDisplayListV0 -// XMLDisplayListV0Factory -// ResourceFactoryXMLDisplayListV0 - } // namespace LUS From b2cb7d68862d95131d4583238805da53defddd45 Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Fri, 9 Feb 2024 02:02:24 -0500 Subject: [PATCH 06/25] blobber --- src/resource/factory/BlobFactory.cpp | 32 +++++++++++----------------- src/resource/factory/BlobFactory.h | 9 ++------ 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/src/resource/factory/BlobFactory.cpp b/src/resource/factory/BlobFactory.cpp index dc729a503..693c61360 100644 --- a/src/resource/factory/BlobFactory.cpp +++ b/src/resource/factory/BlobFactory.cpp @@ -1,32 +1,24 @@ #include "resource/factory/BlobFactory.h" #include "resource/type/Blob.h" +#include "resource/readerbox/BinaryReaderBox.h" #include "spdlog/spdlog.h" namespace LUS { -std::shared_ptr BlobFactory::ReadResource(std::shared_ptr initData, - std::shared_ptr reader) { - auto resource = std::make_shared(initData); - std::shared_ptr factory = nullptr; - - switch (resource->GetInitData()->ResourceVersion) { - case 0: - factory = std::make_shared(); - break; +std::shared_ptr ResourceFactoryBinaryBlobV0::ReadResource(std::shared_ptr initData, + std::shared_ptr readerBox) { + auto binaryReaderBox = std::dynamic_pointer_cast(readerBox); + if (binaryReaderBox == nullptr) { + SPDLOG_ERROR("ReaderBox must be a BinaryReaderBox."); + return nullptr; } - if (factory == nullptr) { - SPDLOG_ERROR("Failed to load Blob with version {}", resource->GetInitData()->ResourceVersion); + auto reader = binaryReaderBox->GetReader(); + if (reader == nullptr) { + SPDLOG_ERROR("null reader in box."); return nullptr; } - factory->ParseFileBinary(reader, resource); - - return resource; -} - -void BlobFactoryV0::ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) { - std::shared_ptr blob = std::static_pointer_cast(resource); - ResourceVersionFactory::ParseFileBinary(reader, blob); + auto blob = std::make_shared(initData); uint32_t dataSize = reader->ReadUInt32(); @@ -35,5 +27,7 @@ void BlobFactoryV0::ParseFileBinary(std::shared_ptr reader, std::s for (uint32_t i = 0; i < dataSize; i++) { blob->Data.push_back(reader->ReadUByte()); } + + return blob; } } // namespace LUS diff --git a/src/resource/factory/BlobFactory.h b/src/resource/factory/BlobFactory.h index 139c594db..967ed717d 100644 --- a/src/resource/factory/BlobFactory.h +++ b/src/resource/factory/BlobFactory.h @@ -4,14 +4,9 @@ #include "resource/ResourceFactory.h" namespace LUS { -class BlobFactory : public ResourceFactory { +class ResourceFactoryBinaryBlobV0 : public ResourceFactory { public: std::shared_ptr ReadResource(std::shared_ptr initData, - std::shared_ptr reader) override; -}; - -class BlobFactoryV0 : public ResourceVersionFactory { - public: - void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; + std::shared_ptr readerBox) override; }; }; // namespace LUS From 92c7d905c843f446be009ce15f1c06300e973068 Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Fri, 9 Feb 2024 02:08:54 -0500 Subject: [PATCH 07/25] array hooray --- src/resource/factory/ArrayFactory.cpp | 32 ++++++++++++--------------- src/resource/factory/ArrayFactory.h | 9 ++------ 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/resource/factory/ArrayFactory.cpp b/src/resource/factory/ArrayFactory.cpp index 57d7ca3cf..2194565e4 100644 --- a/src/resource/factory/ArrayFactory.cpp +++ b/src/resource/factory/ArrayFactory.cpp @@ -1,32 +1,26 @@ #include "resource/factory/ArrayFactory.h" #include "resource/type/Array.h" +#include "resource/readerbox/BinaryReaderBox.h" #include "spdlog/spdlog.h" namespace LUS { -std::shared_ptr ArrayFactory::ReadResource(std::shared_ptr initData, - std::shared_ptr reader) { - auto resource = std::make_shared(initData); - std::shared_ptr factory = nullptr; - - switch (resource->GetInitData()->ResourceVersion) { - case 0: - factory = std::make_shared(); - break; +std::shared_ptr ResourceFactoryBinaryArrayV0::ReadResource(std::shared_ptr initData, + std::shared_ptr readerBox) { + auto binaryReaderBox = std::dynamic_pointer_cast(readerBox); + if (binaryReaderBox == nullptr) { + SPDLOG_ERROR("ReaderBox must be a BinaryReaderBox."); + return nullptr; } - if (factory == nullptr) { - SPDLOG_ERROR("Failed to load Array with version {}", resource->GetInitData()->ResourceVersion); + auto reader = binaryReaderBox->GetReader(); + if (reader == nullptr) { + SPDLOG_ERROR("null reader in box."); return nullptr; } - factory->ParseFileBinary(reader, resource); + auto array = std::make_shared(initData); - return resource; -} - -void ArrayFactoryV0::ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) { - std::shared_ptr array = std::static_pointer_cast(resource); - ResourceVersionFactory::ParseFileBinary(reader, array); + uint32_t dataSize = reader->ReadUInt32(); array->ArrayType = (ArrayResourceType)reader->ReadUInt32(); array->ArrayCount = reader->ReadUInt32(); @@ -74,5 +68,7 @@ void ArrayFactoryV0::ParseFileBinary(std::shared_ptr reader, std:: } } } + + return array; } } // namespace LUS diff --git a/src/resource/factory/ArrayFactory.h b/src/resource/factory/ArrayFactory.h index 2724033be..eecca1a17 100644 --- a/src/resource/factory/ArrayFactory.h +++ b/src/resource/factory/ArrayFactory.h @@ -4,14 +4,9 @@ #include "resource/ResourceFactory.h" namespace LUS { -class ArrayFactory : public ResourceFactory { +class ResourceFactoryBinaryArrayV0 : public ResourceFactory { public: std::shared_ptr ReadResource(std::shared_ptr initData, - std::shared_ptr reader) override; -}; - -class ArrayFactoryV0 : public ResourceVersionFactory { - public: - void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; + std::shared_ptr readerBox) override; }; } // namespace LUS From 053012c42fc8f368fa7354add6910981101b0b1a Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Fri, 9 Feb 2024 02:42:04 -0500 Subject: [PATCH 08/25] ok so this is just a bunch of stuff --- src/CMakeLists.txt | 1 - src/resource/File.h | 5 +- src/resource/ResourceLoader.cpp | 47 +++- src/resource/ResourceLoader.h | 5 +- src/resource/archive/Archive.cpp | 2 +- src/resource/factory/DisplayListFactory.cpp | 249 ++++++++++---------- src/resource/readerbox/ReaderBox.h | 2 + 7 files changed, 173 insertions(+), 138 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0a1555f42..8cf0925b0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -325,7 +325,6 @@ set(Source_Files__Resource ${CMAKE_CURRENT_SOURCE_DIR}/resource/ResourceLoader.cpp ${CMAKE_CURRENT_SOURCE_DIR}/resource/ResourceLoader.h ${CMAKE_CURRENT_SOURCE_DIR}/resource/ResourceFactory.h - ${CMAKE_CURRENT_SOURCE_DIR}/resource/ResourceFactory.cpp ) source_group("resource" FILES ${Source_Files__Resource}) diff --git a/src/resource/File.h b/src/resource/File.h index 648b4c49e..2a9282834 100644 --- a/src/resource/File.h +++ b/src/resource/File.h @@ -11,6 +11,9 @@ namespace LUS { class Archive; +#define RESOURCE_FORMAT_BINARY 0 +#define RESOURCE_FORMAT_XML 1 + struct ResourceInitData { std::string Path; Endianness ByteOrder; @@ -18,7 +21,7 @@ struct ResourceInitData { int32_t ResourceVersion; uint64_t Id; bool IsCustom; - bool IsXml; + uint32_t Format; }; struct File { diff --git a/src/resource/ResourceLoader.cpp b/src/resource/ResourceLoader.cpp index a7735d75e..c8a1cbfc6 100644 --- a/src/resource/ResourceLoader.cpp +++ b/src/resource/ResourceLoader.cpp @@ -24,22 +24,30 @@ ResourceLoader::~ResourceLoader() { void ResourceLoader::RegisterGlobalResourceFactories() { // include strings so we register types for mResourceTypes - RegisterResourceFactory(static_cast(ResourceType::Texture), std::make_shared()); - RegisterResourceFactory(static_cast(ResourceType::Vertex), std::make_shared()); - RegisterResourceFactory(static_cast(ResourceType::DisplayList), std::make_shared()); - RegisterResourceFactory(static_cast(ResourceType::Matrix), std::make_shared()); - RegisterResourceFactory(static_cast(ResourceType::Array), std::make_shared()); - RegisterResourceFactory(static_cast(ResourceType::Blob), std::make_shared()); + RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Texture", static_cast(ResourceType::Texture), 0); + RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Texture", static_cast(ResourceType::Texture), 1); + RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Vertex", static_cast(ResourceType::Vertex), 0); + RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_XML, "Vertex", static_cast(ResourceType::Vertex), 0); + RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "DisplayList", static_cast(ResourceType::DisplayList), 0); + RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_XML, "DisplayList", static_cast(ResourceType::DisplayList), 0); + RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Matrix", static_cast(ResourceType::Matrix), 0); + RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Array", static_cast(ResourceType::Array), 0); + RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Blob", static_cast(ResourceType::Blob), 0); } bool ResourceLoader::RegisterResourceFactory(std::shared_ptr factory, uint32_t format, std::string typeName, uint32_t type, uint32_t version) { if (mResourceTypes.contains(typeName)) { - return false; + if(mResourceTypes[typeName] != type) { + SPDLOG_ERROR("Failed to register resource factory: conflicting types for name {}", typeName); + return false; + } + } else { + mResourceTypes[typeName] = type; } - mResourceTypes[typeName] = type; ResourceFactoryKey key = {resourceFormat: format, resourceType: type, resourceVersion: version}; if (mFactories.contains(key)) { + SPDLOG_ERROR("Failed to register resource factory: factory with key {}{}{} already exists", format, type, version); return false; } mFactories[key] = factory; @@ -47,6 +55,25 @@ bool ResourceLoader::RegisterResourceFactory(std::shared_ptr fa return true; } +std::shared_ptr ResourceLoader::GetFactory(uint32_t format, uint32_t type, uint32_t version) { + ResourceFactoryKey key = {resourceFormat: format, resourceType: type, resourceVersion: version}; + if (!mFactories.contains(key)) { + SPDLOG_ERROR("Could not find resource factory with key {}{}{}", format, type, version); + return nullptr; + } + + return mFactories[key]; +} + +std::shared_ptr ResourceLoader::GetFactory(uint32_t format, std::string typeName, uint32_t version) { + if (!mResourceTypes.contains(typeName)) { + SPDLOG_ERROR("Could not find resource type for name {}", typeName); + return nullptr; + } + + return GetFactory(format, mResourceTypes[typeName], version); +} + std::shared_ptr ResourceLoader::LoadResource(std::shared_ptr fileToLoad) { std::shared_ptr result = nullptr; @@ -64,7 +91,9 @@ std::shared_ptr ResourceLoader::LoadResource(std::shared_ptr fi // make a method that takes in a string instead of an int for the type too // make those protected - auto factory = mFactories[fileToLoad->InitData->Type]; + + + auto factory = GetFactory(fileToLoad->InitData->IsXml) mFactories[fileToLoad->InitData->Type]; if (factory == nullptr) { SPDLOG_ERROR("Failed to load resource: Factory does not exist ({} - {})", fileToLoad->InitData->Type, fileToLoad->InitData->Path); diff --git a/src/resource/ResourceLoader.h b/src/resource/ResourceLoader.h index 8f2899abf..0a8d35396 100644 --- a/src/resource/ResourceLoader.h +++ b/src/resource/ResourceLoader.h @@ -23,11 +23,14 @@ class ResourceLoader { std::shared_ptr LoadResource(std::shared_ptr fileToLoad); bool RegisterResourceFactory(std::shared_ptr factory, uint32_t format, std::string typeName, uint32_t type, uint32_t version); + uint32_t GetResourceType(const std::string& type); + protected: void RegisterGlobalResourceFactories(); + std::shared_ptr GetFactory(uint32_t format, uint32_t type, uint32_t version); + std::shared_ptr GetFactory(uint32_t format, std::string typeName, uint32_t version); private: - uint32_t GetResourceType(const std::string& type); std::unordered_map mResourceTypes; std::unordered_map> mFactories; }; diff --git a/src/resource/archive/Archive.cpp b/src/resource/archive/Archive.cpp index 433a31b7f..a9ecbc136 100644 --- a/src/resource/archive/Archive.cpp +++ b/src/resource/archive/Archive.cpp @@ -233,7 +233,7 @@ std::shared_ptr Archive::ReadResourceInitDataXml(const std::st resourceInitData->IsXml = true; auto root = document->FirstChildElement(); - resourceInitData->Type = mFactoriesTypes[root->Name()]; + resourceInitData->Type = Context::GetInstance()->GetResourceManager()->GetResourceLoader()->GetResourceType(root->Name()); resourceInitData->ResourceVersion = root->IntAttribute("Version"); return resourceInitData; diff --git a/src/resource/factory/DisplayListFactory.cpp b/src/resource/factory/DisplayListFactory.cpp index d80289a8d..856f0f9ed 100644 --- a/src/resource/factory/DisplayListFactory.cpp +++ b/src/resource/factory/DisplayListFactory.cpp @@ -7,6 +7,129 @@ #define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0])) namespace LUS { +std::unordered_map renderModes = { { "G_RM_ZB_OPA_SURF", G_RM_ZB_OPA_SURF }, + { "G_RM_AA_ZB_OPA_SURF", G_RM_AA_ZB_OPA_SURF }, + { "G_RM_AA_ZB_OPA_DECAL", G_RM_AA_ZB_OPA_DECAL }, + { "G_RM_AA_ZB_OPA_INTER", G_RM_AA_ZB_OPA_INTER }, + { "G_RM_AA_ZB_TEX_EDGE", G_RM_AA_ZB_TEX_EDGE }, + { "G_RM_AA_ZB_XLU_SURF", G_RM_AA_ZB_XLU_SURF }, + { "G_RM_AA_ZB_XLU_DECAL", G_RM_AA_ZB_XLU_DECAL }, + { "G_RM_AA_ZB_XLU_INTER", G_RM_AA_ZB_XLU_INTER }, + { "G_RM_FOG_SHADE_A", G_RM_FOG_SHADE_A }, + { "G_RM_FOG_PRIM_A", G_RM_FOG_PRIM_A }, + { "G_RM_PASS", G_RM_PASS }, + { "G_RM_ADD", G_RM_ADD }, + { "G_RM_NOOP", G_RM_NOOP }, + { "G_RM_ZB_OPA_SURF", G_RM_ZB_OPA_SURF }, + { "G_RM_ZB_OPA_DECAL", G_RM_ZB_OPA_DECAL }, + { "G_RM_ZB_XLU_SURF", G_RM_ZB_XLU_SURF }, + { "G_RM_ZB_XLU_DECAL", G_RM_ZB_XLU_DECAL }, + { "G_RM_OPA_SURF", G_RM_OPA_SURF }, + { "G_RM_ZB_CLD_SURF", G_RM_ZB_CLD_SURF }, + { "G_RM_ZB_OPA_SURF2", G_RM_ZB_OPA_SURF2 }, + { "G_RM_AA_ZB_OPA_SURF2", G_RM_AA_ZB_OPA_SURF2 }, + { "G_RM_AA_ZB_OPA_DECAL2", G_RM_AA_ZB_OPA_DECAL2 }, + { "G_RM_AA_ZB_OPA_INTER2", G_RM_AA_ZB_OPA_INTER2 }, + { "G_RM_AA_ZB_TEX_EDGE2", G_RM_AA_ZB_TEX_EDGE2 }, + { "G_RM_AA_ZB_XLU_SURF2", G_RM_AA_ZB_XLU_SURF2 }, + { "G_RM_AA_ZB_XLU_DECAL2", G_RM_AA_ZB_XLU_DECAL2 }, + { "G_RM_AA_ZB_XLU_INTER2", G_RM_AA_ZB_XLU_INTER2 }, + { "G_RM_ADD2", G_RM_ADD2 }, + { "G_RM_ZB_OPA_SURF2", G_RM_ZB_OPA_SURF2 }, + { "G_RM_ZB_OPA_DECAL2", G_RM_ZB_OPA_DECAL2 }, + { "G_RM_ZB_XLU_SURF2", G_RM_ZB_XLU_SURF2 }, + { "G_RM_ZB_XLU_DECAL2", G_RM_ZB_XLU_DECAL2 }, + { "G_RM_ZB_CLD_SURF2", G_RM_ZB_CLD_SURF2 } }; + +static Gfx GsSpVertexOtR2P1(char* filePathPtr) { + Gfx g; + g.words.w0 = G_VTX_OTR_FILEPATH << 24; + g.words.w1 = (uintptr_t)filePathPtr; + + return g; +} + +static Gfx GsSpVertexOtR2P2(int vtxCnt, int vtxBufOffset, int vtxDataOffset) { + Gfx g; + g.words.w0 = (uintptr_t)vtxCnt; + g.words.w1 = (uintptr_t)((vtxBufOffset << 16) | vtxDataOffset); + + return g; +} + +uint32_t ResourceFactoryDisplayList::GetCombineLERPValue(std::string valStr) { + std::string strings[] = { "G_CCMUX_COMBINED", + "G_CCMUX_TEXEL0", + "G_CCMUX_TEXEL1", + "G_CCMUX_PRIMITIVE", + "G_CCMUX_SHADE", + "G_CCMUX_ENVIRONMENT", + "G_CCMUX_1", + "G_CCMUX_NOISE", + "G_CCMUX_0", + "G_CCMUX_CENTER", + "G_CCMUX_K4", + "G_CCMUX_SCALE", + "G_CCMUX_COMBINED_ALPHA", + "G_CCMUX_TEXEL0_ALPHA", + "G_CCMUX_TEXEL1_ALPHA", + "G_CCMUX_PRIMITIVE_ALPHA", + "G_CCMUX_SHADE_ALPHA", + "G_CCMUX_ENV_ALPHA", + "G_CCMUX_LOD_FRACTION", + "G_CCMUX_PRIM_LOD_FRAC", + "G_CCMUX_K5", + "G_ACMUX_COMBINED", + "G_ACMUX_TEXEL0", + "G_ACMUX_TEXEL1", + "G_ACMUX_PRIMITIVE", + "G_ACMUX_SHADE", + "G_ACMUX_ENVIRONMENT", + "G_ACMUX_1", + "G_ACMUX_0", + "G_ACMUX_LOD_FRACTION", + "G_ACMUX_PRIM_LOD_FRAC" }; + uint32_t values[] = { G_CCMUX_COMBINED, + G_CCMUX_TEXEL0, + G_CCMUX_TEXEL1, + G_CCMUX_PRIMITIVE, + G_CCMUX_SHADE, + G_CCMUX_ENVIRONMENT, + G_CCMUX_1, + G_CCMUX_NOISE, + G_CCMUX_0, + G_CCMUX_CENTER, + G_CCMUX_K4, + G_CCMUX_SCALE, + G_CCMUX_COMBINED_ALPHA, + G_CCMUX_TEXEL0_ALPHA, + G_CCMUX_TEXEL1_ALPHA, + G_CCMUX_PRIMITIVE_ALPHA, + G_CCMUX_SHADE_ALPHA, + G_CCMUX_ENV_ALPHA, + G_CCMUX_LOD_FRACTION, + G_CCMUX_PRIM_LOD_FRAC, + G_CCMUX_K5, + G_ACMUX_COMBINED, + G_ACMUX_TEXEL0, + G_ACMUX_TEXEL1, + G_ACMUX_PRIMITIVE, + G_ACMUX_SHADE, + G_ACMUX_ENVIRONMENT, + G_ACMUX_1, + G_ACMUX_0, + G_ACMUX_LOD_FRACTION, + G_ACMUX_PRIM_LOD_FRAC }; + + for (int i = 0; i < ARRAY_COUNT(values); i++) { + if (valStr == strings[i]) { + return values[i]; + } + } + + return G_CCMUX_1; +} + std::shared_ptr ResourceFactoryBinaryDisplayListV0::ReadResource(std::shared_ptr initData, std::shared_ptr readerBox) { auto binaryReaderBox = std::dynamic_pointer_cast(readerBox); @@ -969,130 +1092,6 @@ std::shared_ptr ResourceFactoryXMLDisplayListV0::ReadResource(std::sh child = child->NextSiblingElement(); } - return displayList; -} - -std::unordered_map renderModes = { { "G_RM_ZB_OPA_SURF", G_RM_ZB_OPA_SURF }, - { "G_RM_AA_ZB_OPA_SURF", G_RM_AA_ZB_OPA_SURF }, - { "G_RM_AA_ZB_OPA_DECAL", G_RM_AA_ZB_OPA_DECAL }, - { "G_RM_AA_ZB_OPA_INTER", G_RM_AA_ZB_OPA_INTER }, - { "G_RM_AA_ZB_TEX_EDGE", G_RM_AA_ZB_TEX_EDGE }, - { "G_RM_AA_ZB_XLU_SURF", G_RM_AA_ZB_XLU_SURF }, - { "G_RM_AA_ZB_XLU_DECAL", G_RM_AA_ZB_XLU_DECAL }, - { "G_RM_AA_ZB_XLU_INTER", G_RM_AA_ZB_XLU_INTER }, - { "G_RM_FOG_SHADE_A", G_RM_FOG_SHADE_A }, - { "G_RM_FOG_PRIM_A", G_RM_FOG_PRIM_A }, - { "G_RM_PASS", G_RM_PASS }, - { "G_RM_ADD", G_RM_ADD }, - { "G_RM_NOOP", G_RM_NOOP }, - { "G_RM_ZB_OPA_SURF", G_RM_ZB_OPA_SURF }, - { "G_RM_ZB_OPA_DECAL", G_RM_ZB_OPA_DECAL }, - { "G_RM_ZB_XLU_SURF", G_RM_ZB_XLU_SURF }, - { "G_RM_ZB_XLU_DECAL", G_RM_ZB_XLU_DECAL }, - { "G_RM_OPA_SURF", G_RM_OPA_SURF }, - { "G_RM_ZB_CLD_SURF", G_RM_ZB_CLD_SURF }, - { "G_RM_ZB_OPA_SURF2", G_RM_ZB_OPA_SURF2 }, - { "G_RM_AA_ZB_OPA_SURF2", G_RM_AA_ZB_OPA_SURF2 }, - { "G_RM_AA_ZB_OPA_DECAL2", G_RM_AA_ZB_OPA_DECAL2 }, - { "G_RM_AA_ZB_OPA_INTER2", G_RM_AA_ZB_OPA_INTER2 }, - { "G_RM_AA_ZB_TEX_EDGE2", G_RM_AA_ZB_TEX_EDGE2 }, - { "G_RM_AA_ZB_XLU_SURF2", G_RM_AA_ZB_XLU_SURF2 }, - { "G_RM_AA_ZB_XLU_DECAL2", G_RM_AA_ZB_XLU_DECAL2 }, - { "G_RM_AA_ZB_XLU_INTER2", G_RM_AA_ZB_XLU_INTER2 }, - { "G_RM_ADD2", G_RM_ADD2 }, - { "G_RM_ZB_OPA_SURF2", G_RM_ZB_OPA_SURF2 }, - { "G_RM_ZB_OPA_DECAL2", G_RM_ZB_OPA_DECAL2 }, - { "G_RM_ZB_XLU_SURF2", G_RM_ZB_XLU_SURF2 }, - { "G_RM_ZB_XLU_DECAL2", G_RM_ZB_XLU_DECAL2 }, - { "G_RM_ZB_CLD_SURF2", G_RM_ZB_CLD_SURF2 } }; - -static Gfx GsSpVertexOtR2P1(char* filePathPtr) { - Gfx g; - g.words.w0 = G_VTX_OTR_FILEPATH << 24; - g.words.w1 = (uintptr_t)filePathPtr; - - return g; -} - -static Gfx GsSpVertexOtR2P2(int vtxCnt, int vtxBufOffset, int vtxDataOffset) { - Gfx g; - g.words.w0 = (uintptr_t)vtxCnt; - g.words.w1 = (uintptr_t)((vtxBufOffset << 16) | vtxDataOffset); - - return g; -} - -uint32_t ResourceFactoryDisplayList::GetCombineLERPValue(std::string valStr) { - std::string strings[] = { "G_CCMUX_COMBINED", - "G_CCMUX_TEXEL0", - "G_CCMUX_TEXEL1", - "G_CCMUX_PRIMITIVE", - "G_CCMUX_SHADE", - "G_CCMUX_ENVIRONMENT", - "G_CCMUX_1", - "G_CCMUX_NOISE", - "G_CCMUX_0", - "G_CCMUX_CENTER", - "G_CCMUX_K4", - "G_CCMUX_SCALE", - "G_CCMUX_COMBINED_ALPHA", - "G_CCMUX_TEXEL0_ALPHA", - "G_CCMUX_TEXEL1_ALPHA", - "G_CCMUX_PRIMITIVE_ALPHA", - "G_CCMUX_SHADE_ALPHA", - "G_CCMUX_ENV_ALPHA", - "G_CCMUX_LOD_FRACTION", - "G_CCMUX_PRIM_LOD_FRAC", - "G_CCMUX_K5", - "G_ACMUX_COMBINED", - "G_ACMUX_TEXEL0", - "G_ACMUX_TEXEL1", - "G_ACMUX_PRIMITIVE", - "G_ACMUX_SHADE", - "G_ACMUX_ENVIRONMENT", - "G_ACMUX_1", - "G_ACMUX_0", - "G_ACMUX_LOD_FRACTION", - "G_ACMUX_PRIM_LOD_FRAC" }; - uint32_t values[] = { G_CCMUX_COMBINED, - G_CCMUX_TEXEL0, - G_CCMUX_TEXEL1, - G_CCMUX_PRIMITIVE, - G_CCMUX_SHADE, - G_CCMUX_ENVIRONMENT, - G_CCMUX_1, - G_CCMUX_NOISE, - G_CCMUX_0, - G_CCMUX_CENTER, - G_CCMUX_K4, - G_CCMUX_SCALE, - G_CCMUX_COMBINED_ALPHA, - G_CCMUX_TEXEL0_ALPHA, - G_CCMUX_TEXEL1_ALPHA, - G_CCMUX_PRIMITIVE_ALPHA, - G_CCMUX_SHADE_ALPHA, - G_CCMUX_ENV_ALPHA, - G_CCMUX_LOD_FRACTION, - G_CCMUX_PRIM_LOD_FRAC, - G_CCMUX_K5, - G_ACMUX_COMBINED, - G_ACMUX_TEXEL0, - G_ACMUX_TEXEL1, - G_ACMUX_PRIMITIVE, - G_ACMUX_SHADE, - G_ACMUX_ENVIRONMENT, - G_ACMUX_1, - G_ACMUX_0, - G_ACMUX_LOD_FRACTION, - G_ACMUX_PRIM_LOD_FRAC }; - - for (int i = 0; i < ARRAY_COUNT(values); i++) { - if (valStr == strings[i]) { - return values[i]; - } - } - - return G_CCMUX_1; + return dl; } - } // namespace LUS diff --git a/src/resource/readerbox/ReaderBox.h b/src/resource/readerbox/ReaderBox.h index 6669be4e2..b9628bd03 100644 --- a/src/resource/readerbox/ReaderBox.h +++ b/src/resource/readerbox/ReaderBox.h @@ -1,3 +1,5 @@ +#pragma once + namespace LUS { class ReaderBox {}; } // namespace LUS From e118c40c734afa4e9e80a31e59c0d89fdcd60249 Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Fri, 9 Feb 2024 03:04:19 -0500 Subject: [PATCH 09/25] ok actually lets refactor to file rn --- src/resource/ResourceLoader.cpp | 14 +++++++++++++- src/resource/archive/Archive.cpp | 4 ++-- src/resource/factory/DisplayListFactory.cpp | 2 +- src/resource/factory/VertexFactory.cpp | 2 +- src/resource/readerbox/ReaderBox.h | 5 ++++- src/resource/readerbox/XMLReaderBox.h | 6 +++--- 6 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/resource/ResourceLoader.cpp b/src/resource/ResourceLoader.cpp index c8a1cbfc6..d69e52e30 100644 --- a/src/resource/ResourceLoader.cpp +++ b/src/resource/ResourceLoader.cpp @@ -93,12 +93,24 @@ std::shared_ptr ResourceLoader::LoadResource(std::shared_ptr fi - auto factory = GetFactory(fileToLoad->InitData->IsXml) mFactories[fileToLoad->InitData->Type]; + auto factory = GetFactory(fileToLoad->InitData->Format, fileToLoad->InitData->Type, fileToLoad->InitData->ResourceVersion); if (factory == nullptr) { SPDLOG_ERROR("Failed to load resource: Factory does not exist ({} - {})", fileToLoad->InitData->Type, fileToLoad->InitData->Path); } + // todo: figure out a better way to handle this + // probably just have it so ReadReasource takes in the pointer to fileToLoad directly + switch (fileToLoad->InitData->Format) { + case RESOURCE_FORMAT_BINARY: + factory->ReadResource(fileToLoad->InitData, std::make_shared()) + case RESOURCE_FORMAT_XML: + + default: + SPDLOG_ERROR("invalid resource format {}", fileToLoad->InitData->Format); + return nullptr; + } + if (fileToLoad->InitData->IsXml) { if (fileToLoad->XmlDocument == nullptr) { SPDLOG_ERROR("Failed to load resource: File has no XML document ({} - {})", fileToLoad->InitData->Type, diff --git a/src/resource/archive/Archive.cpp b/src/resource/archive/Archive.cpp index a9ecbc136..0bd4170f0 100644 --- a/src/resource/archive/Archive.cpp +++ b/src/resource/archive/Archive.cpp @@ -173,7 +173,7 @@ std::shared_ptr Archive::CreateDefaultResourceInitData() { resourceInitData->Type = static_cast(ResourceType::None); resourceInitData->ResourceVersion = -1; resourceInitData->IsCustom = false; - resourceInitData->IsXml = false; + resourceInitData->Format = RESOURCE_FORMAT_BINARY; resourceInitData->ByteOrder = Endianness::Native; return resourceInitData; } @@ -230,7 +230,7 @@ std::shared_ptr Archive::ReadResourceInitDataXml(const std::st // XML resourceInitData->IsCustom = true; - resourceInitData->IsXml = true; + resourceInitData->Format = RESOURCE_FORMAT_XML; auto root = document->FirstChildElement(); resourceInitData->Type = Context::GetInstance()->GetResourceManager()->GetResourceLoader()->GetResourceType(root->Name()); diff --git a/src/resource/factory/DisplayListFactory.cpp b/src/resource/factory/DisplayListFactory.cpp index 856f0f9ed..249a2daad 100644 --- a/src/resource/factory/DisplayListFactory.cpp +++ b/src/resource/factory/DisplayListFactory.cpp @@ -192,7 +192,7 @@ std::shared_ptr ResourceFactoryXMLDisplayListV0::ReadResource(std::sh auto dl = std::make_shared(initData); - auto child = reader->FirstChildElement(); + auto child = reader->FirstChildElement()->FirstChildElement(); while (child != nullptr) { std::string childName = child->Name(); diff --git a/src/resource/factory/VertexFactory.cpp b/src/resource/factory/VertexFactory.cpp index ce14d1dfc..bf63699e4 100644 --- a/src/resource/factory/VertexFactory.cpp +++ b/src/resource/factory/VertexFactory.cpp @@ -58,7 +58,7 @@ std::shared_ptr ResourceFactoryXMLVertexV0::ReadResource(std::shared_ auto vertex = std::make_shared(initData); - auto child = reader->FirstChildElement(); + auto child = reader->FirstChildElement()->FirstChildElement(); while (child != nullptr) { std::string childName = child->Name(); diff --git a/src/resource/readerbox/ReaderBox.h b/src/resource/readerbox/ReaderBox.h index b9628bd03..cd24096a1 100644 --- a/src/resource/readerbox/ReaderBox.h +++ b/src/resource/readerbox/ReaderBox.h @@ -1,5 +1,8 @@ #pragma once namespace LUS { -class ReaderBox {}; +class ReaderBox { + public: + virtual ~ReaderBox() = 0; +}; } // namespace LUS diff --git a/src/resource/readerbox/XMLReaderBox.h b/src/resource/readerbox/XMLReaderBox.h index 8983c55e7..eaff5743c 100644 --- a/src/resource/readerbox/XMLReaderBox.h +++ b/src/resource/readerbox/XMLReaderBox.h @@ -5,10 +5,10 @@ namespace LUS { class XMLReaderBox : public ReaderBox { public: - XMLReaderBox(std::shared_ptr reader) { + XMLReaderBox(std::shared_ptr reader) { mReader = reader; }; - std::shared_ptr GetReader() { + std::shared_ptr GetReader() { return mReader; }; ~XMLReaderBox() { @@ -16,6 +16,6 @@ class XMLReaderBox : public ReaderBox { }; private: - std::shared_ptr mReader; + std::shared_ptr mReader; }; } // namespace LUS \ No newline at end of file From 5c114538eda9bb24f56b870ca71dd666de2b6327 Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Fri, 9 Feb 2024 03:45:05 -0500 Subject: [PATCH 10/25] start swapping everything over --- src/resource/ResourceFactory.h | 5 +- src/resource/ResourceLoader.cpp | 43 +-------------- src/resource/factory/ArrayFactory.cpp | 51 +++++++++--------- src/resource/factory/ArrayFactory.h | 3 +- src/resource/factory/BlobFactory.cpp | 20 ++++--- src/resource/factory/BlobFactory.h | 3 +- src/resource/factory/DisplayListFactory.cpp | 49 ++++++++--------- src/resource/factory/DisplayListFactory.h | 6 +-- src/resource/factory/MatrixFactory.cpp | 18 +++---- src/resource/factory/MatrixFactory.h | 3 +- src/resource/factory/TextureFactory.cpp | 58 ++++++++++----------- src/resource/factory/TextureFactory.h | 6 +-- src/resource/factory/VertexFactory.cpp | 32 +++++------- src/resource/factory/VertexFactory.h | 6 +-- src/resource/readerbox/BinaryReaderBox.h | 20 ------- src/resource/readerbox/ReaderBox.h | 8 --- src/resource/readerbox/XMLReaderBox.h | 21 -------- 17 files changed, 117 insertions(+), 235 deletions(-) delete mode 100644 src/resource/readerbox/BinaryReaderBox.h delete mode 100644 src/resource/readerbox/ReaderBox.h delete mode 100644 src/resource/readerbox/XMLReaderBox.h diff --git a/src/resource/ResourceFactory.h b/src/resource/ResourceFactory.h index 2f74cf00a..6aead3cbd 100644 --- a/src/resource/ResourceFactory.h +++ b/src/resource/ResourceFactory.h @@ -1,13 +1,12 @@ #pragma once #include -#include "readerbox/ReaderBox.h" +#include "File.h" #include "Resource.h" namespace LUS { class ResourceFactory { public: - virtual std::shared_ptr ReadResource(std::shared_ptr initData, - std::shared_ptr readerBox) = 0; + virtual std::shared_ptr ReadResource(std::shared_ptr file) = 0; }; } // namespace LUS diff --git a/src/resource/ResourceLoader.cpp b/src/resource/ResourceLoader.cpp index d69e52e30..ecbfec958 100644 --- a/src/resource/ResourceLoader.cpp +++ b/src/resource/ResourceLoader.cpp @@ -87,53 +87,12 @@ std::shared_ptr ResourceLoader::LoadResource(std::shared_ptr fi return result; } - // call method to get factory based on factorykey (generate using params) - // make a method that takes in a string instead of an int for the type too - // make those protected - - - auto factory = GetFactory(fileToLoad->InitData->Format, fileToLoad->InitData->Type, fileToLoad->InitData->ResourceVersion); if (factory == nullptr) { SPDLOG_ERROR("Failed to load resource: Factory does not exist ({} - {})", fileToLoad->InitData->Type, fileToLoad->InitData->Path); } - // todo: figure out a better way to handle this - // probably just have it so ReadReasource takes in the pointer to fileToLoad directly - switch (fileToLoad->InitData->Format) { - case RESOURCE_FORMAT_BINARY: - factory->ReadResource(fileToLoad->InitData, std::make_shared()) - case RESOURCE_FORMAT_XML: - - default: - SPDLOG_ERROR("invalid resource format {}", fileToLoad->InitData->Format); - return nullptr; - } - - if (fileToLoad->InitData->IsXml) { - if (fileToLoad->XmlDocument == nullptr) { - SPDLOG_ERROR("Failed to load resource: File has no XML document ({} - {})", fileToLoad->InitData->Type, - fileToLoad->InitData->Path); - return result; - } - - result = factory->ReadResourceXML(fileToLoad->InitData, fileToLoad->XmlDocument->FirstChildElement()); - } else { - if (fileToLoad->Reader == nullptr) { - SPDLOG_ERROR("Failed to load resource: File has Reader ({} - {})", fileToLoad->InitData->Type, - fileToLoad->InitData->Path); - return result; - } - - result = factory->ReadResource(fileToLoad->InitData, fileToLoad->Reader); - } - - if (result == nullptr) { - SPDLOG_ERROR("Failed to load resource of type {} \"{}\"", fileToLoad->InitData->Type, - fileToLoad->InitData->Path); - } - - return result; + return factory->ReadResource(fileToLoad); } } // namespace LUS diff --git a/src/resource/factory/ArrayFactory.cpp b/src/resource/factory/ArrayFactory.cpp index 2194565e4..b72248aa2 100644 --- a/src/resource/factory/ArrayFactory.cpp +++ b/src/resource/factory/ArrayFactory.cpp @@ -1,52 +1,49 @@ #include "resource/factory/ArrayFactory.h" #include "resource/type/Array.h" -#include "resource/readerbox/BinaryReaderBox.h" #include "spdlog/spdlog.h" namespace LUS { -std::shared_ptr ResourceFactoryBinaryArrayV0::ReadResource(std::shared_ptr initData, - std::shared_ptr readerBox) { - auto binaryReaderBox = std::dynamic_pointer_cast(readerBox); - if (binaryReaderBox == nullptr) { - SPDLOG_ERROR("ReaderBox must be a BinaryReaderBox."); +std::shared_ptr ResourceFactoryBinaryArrayV0::ReadResource(std::shared_ptr file) { + if (file->InitData->Format != RESOURCE_FORMAT_BINARY) { + SPDLOG_ERROR("resource file format does not match factory format."); return nullptr; } - auto reader = binaryReaderBox->GetReader(); - if (reader == nullptr) { - SPDLOG_ERROR("null reader in box."); + if (file->Reader == nullptr) { + SPDLOG_ERROR("Failed to load resource: File has Reader ({} - {})", file->InitData->Type, + file->InitData->Path); return nullptr; } - auto array = std::make_shared(initData); + auto array = std::make_shared(file->InitData); - uint32_t dataSize = reader->ReadUInt32(); + uint32_t dataSize = file->Reader->ReadUInt32(); - array->ArrayType = (ArrayResourceType)reader->ReadUInt32(); - array->ArrayCount = reader->ReadUInt32(); + array->ArrayType = (ArrayResourceType)file->Reader->ReadUInt32(); + array->ArrayCount = file->Reader->ReadUInt32(); for (uint32_t i = 0; i < array->ArrayCount; i++) { if (array->ArrayType == ArrayResourceType::Vertex) { // OTRTODO: Implement Vertex arrays as just a vertex resource. Vtx data; - data.v.ob[0] = reader->ReadInt16(); - data.v.ob[1] = reader->ReadInt16(); - data.v.ob[2] = reader->ReadInt16(); - data.v.flag = reader->ReadUInt16(); - data.v.tc[0] = reader->ReadInt16(); - data.v.tc[1] = reader->ReadInt16(); - data.v.cn[0] = reader->ReadUByte(); - data.v.cn[1] = reader->ReadUByte(); - data.v.cn[2] = reader->ReadUByte(); - data.v.cn[3] = reader->ReadUByte(); + data.v.ob[0] = file->Reader->ReadInt16(); + data.v.ob[1] = file->Reader->ReadInt16(); + data.v.ob[2] = file->Reader->ReadInt16(); + data.v.flag = file->Reader->ReadUInt16(); + data.v.tc[0] = file->Reader->ReadInt16(); + data.v.tc[1] = file->Reader->ReadInt16(); + data.v.cn[0] = file->Reader->ReadUByte(); + data.v.cn[1] = file->Reader->ReadUByte(); + data.v.cn[2] = file->Reader->ReadUByte(); + data.v.cn[3] = file->Reader->ReadUByte(); array->Vertices.push_back(data); } else { - array->ArrayScalarType = (ScalarType)reader->ReadUInt32(); + array->ArrayScalarType = (ScalarType)file->Reader->ReadUInt32(); int iter = 1; if (array->ArrayType == ArrayResourceType::Vector) { - iter = reader->ReadUInt32(); + iter = file->Reader->ReadUInt32(); } for (int k = 0; k < iter; k++) { @@ -54,10 +51,10 @@ std::shared_ptr ResourceFactoryBinaryArrayV0::ReadResource(std::share switch (array->ArrayScalarType) { case ScalarType::ZSCALAR_S16: - data.s16 = reader->ReadInt16(); + data.s16 = file->Reader->ReadInt16(); break; case ScalarType::ZSCALAR_U16: - data.u16 = reader->ReadUInt16(); + data.u16 = file->Reader->ReadUInt16(); break; default: // OTRTODO: IMPLEMENT OTHER TYPES! diff --git a/src/resource/factory/ArrayFactory.h b/src/resource/factory/ArrayFactory.h index eecca1a17..8471fbbe5 100644 --- a/src/resource/factory/ArrayFactory.h +++ b/src/resource/factory/ArrayFactory.h @@ -6,7 +6,6 @@ namespace LUS { class ResourceFactoryBinaryArrayV0 : public ResourceFactory { public: - std::shared_ptr ReadResource(std::shared_ptr initData, - std::shared_ptr readerBox) override; + std::shared_ptr ReadResource(std::shared_ptr file) override; }; } // namespace LUS diff --git a/src/resource/factory/BlobFactory.cpp b/src/resource/factory/BlobFactory.cpp index 693c61360..408f2e3a9 100644 --- a/src/resource/factory/BlobFactory.cpp +++ b/src/resource/factory/BlobFactory.cpp @@ -4,28 +4,26 @@ #include "spdlog/spdlog.h" namespace LUS { -std::shared_ptr ResourceFactoryBinaryBlobV0::ReadResource(std::shared_ptr initData, - std::shared_ptr readerBox) { - auto binaryReaderBox = std::dynamic_pointer_cast(readerBox); - if (binaryReaderBox == nullptr) { - SPDLOG_ERROR("ReaderBox must be a BinaryReaderBox."); +std::shared_ptr ResourceFactoryBinaryBlobV0::ReadResource(std::shared_ptr file) { + if (file->InitData->Format != RESOURCE_FORMAT_BINARY) { + SPDLOG_ERROR("resource file format does not match factory format."); return nullptr; } - auto reader = binaryReaderBox->GetReader(); - if (reader == nullptr) { - SPDLOG_ERROR("null reader in box."); + if (file->Reader == nullptr) { + SPDLOG_ERROR("Failed to load resource: File has Reader ({} - {})", file->InitData->Type, + file->InitData->Path); return nullptr; } - auto blob = std::make_shared(initData); + auto blob = std::make_shared(file->InitData); - uint32_t dataSize = reader->ReadUInt32(); + uint32_t dataSize = file->Reader->ReadUInt32(); blob->Data.reserve(dataSize); for (uint32_t i = 0; i < dataSize; i++) { - blob->Data.push_back(reader->ReadUByte()); + blob->Data.push_back(file->Reader->ReadUByte()); } return blob; diff --git a/src/resource/factory/BlobFactory.h b/src/resource/factory/BlobFactory.h index 967ed717d..52e721da9 100644 --- a/src/resource/factory/BlobFactory.h +++ b/src/resource/factory/BlobFactory.h @@ -6,7 +6,6 @@ namespace LUS { class ResourceFactoryBinaryBlobV0 : public ResourceFactory { public: - std::shared_ptr ReadResource(std::shared_ptr initData, - std::shared_ptr readerBox) override; + std::shared_ptr ReadResource(std::shared_ptr file) override; }; }; // namespace LUS diff --git a/src/resource/factory/DisplayListFactory.cpp b/src/resource/factory/DisplayListFactory.cpp index 249a2daad..c734136e9 100644 --- a/src/resource/factory/DisplayListFactory.cpp +++ b/src/resource/factory/DisplayListFactory.cpp @@ -130,30 +130,28 @@ uint32_t ResourceFactoryDisplayList::GetCombineLERPValue(std::string valStr) { return G_CCMUX_1; } -std::shared_ptr ResourceFactoryBinaryDisplayListV0::ReadResource(std::shared_ptr initData, - std::shared_ptr readerBox) { - auto binaryReaderBox = std::dynamic_pointer_cast(readerBox); - if (binaryReaderBox == nullptr) { - SPDLOG_ERROR("ReaderBox must be a BinaryReaderBox."); +std::shared_ptr ResourceFactoryBinaryDisplayListV0::ReadResource(std::shared_ptr file) { + if (file->InitData->Format != RESOURCE_FORMAT_BINARY) { + SPDLOG_ERROR("resource file format does not match factory format."); return nullptr; } - auto reader = binaryReaderBox->GetReader(); - if (reader == nullptr) { - SPDLOG_ERROR("null reader in box."); + if (file->Reader == nullptr) { + SPDLOG_ERROR("Failed to load resource: File has Reader ({} - {})", file->InitData->Type, + file->InitData->Path); return nullptr; } - auto displayList = std::make_shared(initData); + auto displayList = std::make_shared(file->InitData); - while (reader->GetBaseAddress() % 8 != 0) { - reader->ReadInt8(); + while (file->Reader->GetBaseAddress() % 8 != 0) { + file->Reader->ReadInt8(); } while (true) { Gfx command; - command.words.w0 = reader->ReadUInt32(); - command.words.w1 = reader->ReadUInt32(); + command.words.w0 = file->Reader->ReadUInt32(); + command.words.w1 = file->Reader->ReadUInt32(); displayList->Instructions.push_back(command); @@ -162,8 +160,8 @@ std::shared_ptr ResourceFactoryBinaryDisplayListV0::ReadResource(std: // These are 128-bit commands, so read an extra 64 bits... if (opcode == G_SETTIMG_OTR_HASH || opcode == G_DL_OTR_HASH || opcode == G_VTX_OTR_HASH || opcode == G_BRANCH_Z_OTR || opcode == G_MARKER || opcode == G_MTX_OTR) { - command.words.w0 = reader->ReadUInt32(); - command.words.w1 = reader->ReadUInt32(); + command.words.w0 = file->Reader->ReadUInt32(); + command.words.w1 = file->Reader->ReadUInt32(); displayList->Instructions.push_back(command); } @@ -176,23 +174,22 @@ std::shared_ptr ResourceFactoryBinaryDisplayListV0::ReadResource(std: return displayList; } -std::shared_ptr ResourceFactoryXMLDisplayListV0::ReadResource(std::shared_ptr initData, - std::shared_ptr readerBox) { - auto xmlReaderBox = std::dynamic_pointer_cast(readerBox); - if (xmlReaderBox == nullptr) { - SPDLOG_ERROR("ReaderBox must be an XMLReaderBox."); +std::shared_ptr ResourceFactoryXMLDisplayListV0::ReadResource(std::shared_ptr file) { + if (file->InitData->Format != RESOURCE_FORMAT_XML) { + SPDLOG_ERROR("resource file format does not match factory format."); return nullptr; } - auto reader = xmlReaderBox->GetReader(); - if (reader == nullptr) { - SPDLOG_ERROR("null reader in box."); - return nullptr; + if (file->XmlDocument == nullptr) { + SPDLOG_ERROR("Failed to load resource: File has no XML document ({} - {})", file->InitData->Type, + file->InitData->Path); + return result; } - auto dl = std::make_shared(initData); - auto child = reader->FirstChildElement()->FirstChildElement(); + auto dl = std::make_shared(file->InitData); + + auto child = file->XmlDocument->FirstChildElement()->FirstChildElement(); while (child != nullptr) { std::string childName = child->Name(); diff --git a/src/resource/factory/DisplayListFactory.h b/src/resource/factory/DisplayListFactory.h index 74c78b889..5250316f2 100644 --- a/src/resource/factory/DisplayListFactory.h +++ b/src/resource/factory/DisplayListFactory.h @@ -11,13 +11,11 @@ class ResourceFactoryDisplayList : public ResourceFactory { class ResourceFactoryBinaryDisplayListV0 : public ResourceFactoryDisplayList { public: - std::shared_ptr ReadResource(std::shared_ptr initData, - std::shared_ptr readerBox) override; + std::shared_ptr ReadResource(std::shared_ptr file) override; }; class ResourceFactoryXMLDisplayListV0 : public ResourceFactoryDisplayList { public: - std::shared_ptr ReadResource(std::shared_ptr initData, - std::shared_ptr readerBox) override; + std::shared_ptr ReadResource(std::shared_ptr file) override; }; } // namespace LUS diff --git a/src/resource/factory/MatrixFactory.cpp b/src/resource/factory/MatrixFactory.cpp index f858d4a77..0023378df 100644 --- a/src/resource/factory/MatrixFactory.cpp +++ b/src/resource/factory/MatrixFactory.cpp @@ -4,25 +4,23 @@ #include "spdlog/spdlog.h" namespace LUS { -std::shared_ptr ResourceFactoryBinaryMatrixV0::ReadResource(std::shared_ptr initData, - std::shared_ptr readerBox) { - auto binaryReaderBox = std::dynamic_pointer_cast(readerBox); - if (binaryReaderBox == nullptr) { - SPDLOG_ERROR("ReaderBox must be a BinaryReaderBox."); +std::shared_ptr ResourceFactoryBinaryMatrixV0::ReadResource(std::shared_ptr file) { + if (file->InitData->Format != RESOURCE_FORMAT_BINARY) { + SPDLOG_ERROR("resource file format does not match factory format."); return nullptr; } - auto reader = binaryReaderBox->GetReader(); - if (reader == nullptr) { - SPDLOG_ERROR("null reader in box."); + if (file->Reader == nullptr) { + SPDLOG_ERROR("Failed to load resource: File has Reader ({} - {})", file->InitData->Type, + file->InitData->Path); return nullptr; } - auto matrix = std::make_shared(initData); + auto matrix = std::make_shared(file->InitData); for (size_t i = 0; i < 4; i++) { for (size_t j = 0; j < 4; j++) { - matrix->Matrx.m[i][j] = reader->ReadInt32(); + matrix->Matrx.m[i][j] = file->Reader->ReadInt32(); } } diff --git a/src/resource/factory/MatrixFactory.h b/src/resource/factory/MatrixFactory.h index 2ee988bc3..f35d8a566 100644 --- a/src/resource/factory/MatrixFactory.h +++ b/src/resource/factory/MatrixFactory.h @@ -6,7 +6,6 @@ namespace LUS { class ResourceFactoryBinaryMatrixV0 : public ResourceFactory { public: - std::shared_ptr ReadResource(std::shared_ptr initData, - std::shared_ptr readerBox) override; + std::shared_ptr ReadResource(std::shared_ptr file) override; }; } // namespace LUS diff --git a/src/resource/factory/TextureFactory.cpp b/src/resource/factory/TextureFactory.cpp index b8e67db4f..910d2afed 100644 --- a/src/resource/factory/TextureFactory.cpp +++ b/src/resource/factory/TextureFactory.cpp @@ -5,59 +5,55 @@ namespace LUS { -std::shared_ptr ResourceFactoryBinaryTextureV0::ReadResource(std::shared_ptr initData, - std::shared_ptr readerBox) { - auto binaryReaderBox = std::dynamic_pointer_cast(readerBox); - if (binaryReaderBox == nullptr) { - SPDLOG_ERROR("ReaderBox must be a BinaryReaderBox."); +std::shared_ptr ResourceFactoryBinaryTextureV0::ReadResource(std::shared_ptr file) { + if (file->InitData->Format != RESOURCE_FORMAT_BINARY) { + SPDLOG_ERROR("resource file format does not match factory format."); return nullptr; } - auto reader = binaryReaderBox->GetReader(); - if (reader == nullptr) { - SPDLOG_ERROR("null reader in box."); + if (file->Reader == nullptr) { + SPDLOG_ERROR("Failed to load resource: File has Reader ({} - {})", file->InitData->Type, + file->InitData->Path); return nullptr; } - auto texture = std::make_shared(initData); + auto texture = std::make_shared(file->InitData); - texture->Type = (TextureType)reader->ReadUInt32(); - texture->Width = reader->ReadUInt32(); - texture->Height = reader->ReadUInt32(); - texture->ImageDataSize = reader->ReadUInt32(); + texture->Type = (TextureType)file->Reader->ReadUInt32(); + texture->Width = file->Reader->ReadUInt32(); + texture->Height = file->Reader->ReadUInt32(); + texture->ImageDataSize = file->Reader->ReadUInt32(); texture->ImageData = new uint8_t[texture->ImageDataSize]; - reader->Read((char*)texture->ImageData, texture->ImageDataSize); + file->Reader->Read((char*)texture->ImageData, texture->ImageDataSize); return texture; } -std::shared_ptr ResourceFactoryBinaryTextureV1::ReadResource(std::shared_ptr initData, - std::shared_ptr readerBox) { - auto binaryReaderBox = std::dynamic_pointer_cast(readerBox); - if (binaryReaderBox == nullptr) { - SPDLOG_ERROR("ReaderBox must be a BinaryReaderBox."); +std::shared_ptr ResourceFactoryBinaryTextureV1::ReadResource(std::shared_ptr file) { + if (file->InitData->Format != RESOURCE_FORMAT_BINARY) { + SPDLOG_ERROR("resource file format does not match factory format."); return nullptr; } - auto reader = binaryReaderBox->GetReader(); - if (reader == nullptr) { - SPDLOG_ERROR("null reader in box."); + if (file->Reader == nullptr) { + SPDLOG_ERROR("Failed to load resource: File has Reader ({} - {})", file->InitData->Type, + file->InitData->Path); return nullptr; } - auto texture = std::make_shared(initData); + auto texture = std::make_shared(file->InitData); - texture->Type = (TextureType)reader->ReadUInt32(); - texture->Width = reader->ReadUInt32(); - texture->Height = reader->ReadUInt32(); - texture->Flags = reader->ReadUInt32(); - texture->HByteScale = reader->ReadFloat(); - texture->VPixelScale = reader->ReadFloat(); - texture->ImageDataSize = reader->ReadUInt32(); + texture->Type = (TextureType)file->Reader->ReadUInt32(); + texture->Width = file->Reader->ReadUInt32(); + texture->Height = file->Reader->ReadUInt32(); + texture->Flags = file->Reader->ReadUInt32(); + texture->HByteScale = file->Reader->ReadFloat(); + texture->VPixelScale = file->Reader->ReadFloat(); + texture->ImageDataSize = file->Reader->ReadUInt32(); texture->ImageData = new uint8_t[texture->ImageDataSize]; - reader->Read((char*)texture->ImageData, texture->ImageDataSize); + file->Reader->Read((char*)texture->ImageData, texture->ImageDataSize); return texture; } diff --git a/src/resource/factory/TextureFactory.h b/src/resource/factory/TextureFactory.h index d562b0f0e..304bece98 100644 --- a/src/resource/factory/TextureFactory.h +++ b/src/resource/factory/TextureFactory.h @@ -6,13 +6,11 @@ namespace LUS { class ResourceFactoryBinaryTextureV0 : public ResourceFactory { public: - std::shared_ptr ReadResource(std::shared_ptr initData, - std::shared_ptr readerBox) override; + std::shared_ptr ReadResource(std::shared_ptr file) override; }; class ResourceFactoryBinaryTextureV1 : public ResourceFactory { public: - std::shared_ptr ReadResource(std::shared_ptr initData, - std::shared_ptr readerBox) override; + std::shared_ptr ReadResource(std::shared_ptr file) override; }; } // namespace LUS diff --git a/src/resource/factory/VertexFactory.cpp b/src/resource/factory/VertexFactory.cpp index bf63699e4..94296c9c3 100644 --- a/src/resource/factory/VertexFactory.cpp +++ b/src/resource/factory/VertexFactory.cpp @@ -5,17 +5,15 @@ #include "spdlog/spdlog.h" namespace LUS { -std::shared_ptr ResourceFactoryBinaryVertexV0::ReadResource(std::shared_ptr initData, - std::shared_ptr readerBox) { - auto binaryReaderBox = std::dynamic_pointer_cast(readerBox); - if (binaryReaderBox == nullptr) { - SPDLOG_ERROR("ReaderBox must be a BinaryReaderBox."); +std::shared_ptr ResourceFactoryBinaryVertexV0::ReadResource(std::shared_ptr file) { + if (file->InitData->Format != RESOURCE_FORMAT_BINARY) { + SPDLOG_ERROR("resource file format does not match factory format."); return nullptr; } - auto reader = binaryReaderBox->GetReader(); - if (reader == nullptr) { - SPDLOG_ERROR("null reader in box."); + if (file->Reader == nullptr) { + SPDLOG_ERROR("Failed to load resource: File has Reader ({} - {})", file->InitData->Type, + file->InitData->Path); return nullptr; } @@ -42,23 +40,21 @@ std::shared_ptr ResourceFactoryBinaryVertexV0::ReadResource(std::shar return vertex; } -std::shared_ptr ResourceFactoryXMLVertexV0::ReadResource(std::shared_ptr initData, - std::shared_ptr readerBox) { - auto xmlReaderBox = std::dynamic_pointer_cast(readerBox); - if (xmlReaderBox == nullptr) { - SPDLOG_ERROR("ReaderBox must be an XMLReaderBox."); +std::shared_ptr ResourceFactoryXMLVertexV0::ReadResource(std::shared_ptr file) { + if (file->InitData->Format != RESOURCE_FORMAT_XML) { + SPDLOG_ERROR("resource file format does not match factory format."); return nullptr; } - auto reader = xmlReaderBox->GetReader(); - if (reader == nullptr) { - SPDLOG_ERROR("null reader in box."); - return nullptr; + if (file->XmlDocument == nullptr) { + SPDLOG_ERROR("Failed to load resource: File has no XML document ({} - {})", file->InitData->Type, + file->InitData->Path); + return result; } auto vertex = std::make_shared(initData); - auto child = reader->FirstChildElement()->FirstChildElement(); + auto child = file->XmlDocument->FirstChildElement()->FirstChildElement(); while (child != nullptr) { std::string childName = child->Name(); diff --git a/src/resource/factory/VertexFactory.h b/src/resource/factory/VertexFactory.h index 0056d858d..a3749b780 100644 --- a/src/resource/factory/VertexFactory.h +++ b/src/resource/factory/VertexFactory.h @@ -6,13 +6,11 @@ namespace LUS { class ResourceFactoryBinaryVertexV0 : public ResourceFactory { public: - std::shared_ptr ReadResource(std::shared_ptr initData, - std::shared_ptr readerBox) override; + std::shared_ptr ReadResource(std::shared_ptr file) override; }; class ResourceFactoryXMLVertexV0 : public ResourceFactory { public: - std::shared_ptr ReadResource(std::shared_ptr initData, - std::shared_ptr readerBox) override; + std::shared_ptr ReadResource(std::shared_ptr file) override; }; } // namespace LUS diff --git a/src/resource/readerbox/BinaryReaderBox.h b/src/resource/readerbox/BinaryReaderBox.h deleted file mode 100644 index ccf8ea465..000000000 --- a/src/resource/readerbox/BinaryReaderBox.h +++ /dev/null @@ -1,20 +0,0 @@ -#include "ReaderBox.h" -#include "utils/binarytools/BinaryReader.h" - -namespace LUS { -class BinaryReaderBox : public ReaderBox { - public: - BinaryReaderBox(std::shared_ptr reader) { - mReader = reader; - }; - std::shared_ptr GetReader() { - return mReader; - }; - ~BinaryReaderBox() { - mReader = nullptr; - }; - - private: - std::shared_ptr mReader; -}; -} // namespace LUS diff --git a/src/resource/readerbox/ReaderBox.h b/src/resource/readerbox/ReaderBox.h deleted file mode 100644 index cd24096a1..000000000 --- a/src/resource/readerbox/ReaderBox.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -namespace LUS { -class ReaderBox { - public: - virtual ~ReaderBox() = 0; -}; -} // namespace LUS diff --git a/src/resource/readerbox/XMLReaderBox.h b/src/resource/readerbox/XMLReaderBox.h deleted file mode 100644 index eaff5743c..000000000 --- a/src/resource/readerbox/XMLReaderBox.h +++ /dev/null @@ -1,21 +0,0 @@ -#include "ReaderBox.h" -#include -#include - -namespace LUS { -class XMLReaderBox : public ReaderBox { - public: - XMLReaderBox(std::shared_ptr reader) { - mReader = reader; - }; - std::shared_ptr GetReader() { - return mReader; - }; - ~XMLReaderBox() { - mReader = nullptr; - }; - - private: - std::shared_ptr mReader; -}; -} // namespace LUS \ No newline at end of file From 5987d3bcf448f6ca77415d9b5f7e779a426ccbaa Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Fri, 9 Feb 2024 03:52:04 -0500 Subject: [PATCH 11/25] clean up --- src/CMakeLists.txt | 9 +------ src/resource/factory/BlobFactory.cpp | 1 - src/resource/factory/DisplayListFactory.cpp | 4 +-- src/resource/factory/MatrixFactory.cpp | 1 - src/resource/factory/TextureFactory.cpp | 1 - src/resource/factory/VertexFactory.cpp | 30 ++++++++++----------- 6 files changed, 16 insertions(+), 30 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8cf0925b0..6fcf0cf46 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -372,14 +372,7 @@ set(Source_Files__Resource__Archive ) source_group("resource/archive" FILES ${Source_Files__Resource__Archive}) -set(Source_Files__Resource__ReaderBox - ${CMAKE_CURRENT_SOURCE_DIR}/resource/readerbox/ReaderBox.h - ${CMAKE_CURRENT_SOURCE_DIR}/resource/readerbox/BinaryReaderBox.h - ${CMAKE_CURRENT_SOURCE_DIR}/resource/readerbox/XMLReaderBox.h -) -source_group("resource/readerbox" FILES ${Source_Files__Resource__ReaderBox}) - -target_sources(libultraship PRIVATE ${Source_Files__Resource} ${Source_Files__Resource__Types} ${Source_Files__Resource__Factories} ${Source_Files__Resource__Archive} ${Source_Files__Resource__ReaderBox}) +target_sources(libultraship PRIVATE ${Source_Files__Resource} ${Source_Files__Resource__Types} ${Source_Files__Resource__Factories} ${Source_Files__Resource__Archive}) #=================== Graphic =================== diff --git a/src/resource/factory/BlobFactory.cpp b/src/resource/factory/BlobFactory.cpp index 408f2e3a9..ebc21a978 100644 --- a/src/resource/factory/BlobFactory.cpp +++ b/src/resource/factory/BlobFactory.cpp @@ -1,6 +1,5 @@ #include "resource/factory/BlobFactory.h" #include "resource/type/Blob.h" -#include "resource/readerbox/BinaryReaderBox.h" #include "spdlog/spdlog.h" namespace LUS { diff --git a/src/resource/factory/DisplayListFactory.cpp b/src/resource/factory/DisplayListFactory.cpp index c734136e9..de14e3fd1 100644 --- a/src/resource/factory/DisplayListFactory.cpp +++ b/src/resource/factory/DisplayListFactory.cpp @@ -1,7 +1,5 @@ #include "resource/factory/DisplayListFactory.h" #include "resource/type/DisplayList.h" -#include "resource/readerbox/BinaryReaderBox.h" -#include "resource/readerbox/XMLReaderBox.h" #include "spdlog/spdlog.h" #define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0])) @@ -183,7 +181,7 @@ std::shared_ptr ResourceFactoryXMLDisplayListV0::ReadResource(std::sh if (file->XmlDocument == nullptr) { SPDLOG_ERROR("Failed to load resource: File has no XML document ({} - {})", file->InitData->Type, file->InitData->Path); - return result; + return nullptr; } diff --git a/src/resource/factory/MatrixFactory.cpp b/src/resource/factory/MatrixFactory.cpp index 0023378df..c181200db 100644 --- a/src/resource/factory/MatrixFactory.cpp +++ b/src/resource/factory/MatrixFactory.cpp @@ -1,6 +1,5 @@ #include "resource/factory/MatrixFactory.h" #include "resource/type/Matrix.h" -#include "resource/readerbox/BinaryReaderBox.h" #include "spdlog/spdlog.h" namespace LUS { diff --git a/src/resource/factory/TextureFactory.cpp b/src/resource/factory/TextureFactory.cpp index 910d2afed..53d9e8040 100644 --- a/src/resource/factory/TextureFactory.cpp +++ b/src/resource/factory/TextureFactory.cpp @@ -1,6 +1,5 @@ #include "resource/factory/TextureFactory.h" #include "resource/type/Texture.h" -#include "resource/readerbox/BinaryReaderBox.h" #include "spdlog/spdlog.h" namespace LUS { diff --git a/src/resource/factory/VertexFactory.cpp b/src/resource/factory/VertexFactory.cpp index 94296c9c3..5209bbd9d 100644 --- a/src/resource/factory/VertexFactory.cpp +++ b/src/resource/factory/VertexFactory.cpp @@ -1,7 +1,5 @@ #include "resource/factory/VertexFactory.h" #include "resource/type/Vertex.h" -#include "resource/readerbox/BinaryReaderBox.h" -#include "resource/readerbox/XMLReaderBox.h" #include "spdlog/spdlog.h" namespace LUS { @@ -17,23 +15,23 @@ std::shared_ptr ResourceFactoryBinaryVertexV0::ReadResource(std::shar return nullptr; } - auto vertex = std::make_shared(initData); + auto vertex = std::make_shared(file->InitData); - uint32_t count = reader->ReadUInt32(); + uint32_t count = file->Reader->ReadUInt32(); vertex->VertexList.reserve(count); for (uint32_t i = 0; i < count; i++) { Vtx data; - data.v.ob[0] = reader->ReadInt16(); - data.v.ob[1] = reader->ReadInt16(); - data.v.ob[2] = reader->ReadInt16(); - data.v.flag = reader->ReadUInt16(); - data.v.tc[0] = reader->ReadInt16(); - data.v.tc[1] = reader->ReadInt16(); - data.v.cn[0] = reader->ReadUByte(); - data.v.cn[1] = reader->ReadUByte(); - data.v.cn[2] = reader->ReadUByte(); - data.v.cn[3] = reader->ReadUByte(); + data.v.ob[0] = file->Reader->ReadInt16(); + data.v.ob[1] = file->Reader->ReadInt16(); + data.v.ob[2] = file->Reader->ReadInt16(); + data.v.flag = file->Reader->ReadUInt16(); + data.v.tc[0] = file->Reader->ReadInt16(); + data.v.tc[1] = file->Reader->ReadInt16(); + data.v.cn[0] = file->Reader->ReadUByte(); + data.v.cn[1] = file->Reader->ReadUByte(); + data.v.cn[2] = file->Reader->ReadUByte(); + data.v.cn[3] = file->Reader->ReadUByte(); vertex->VertexList.push_back(data); } @@ -49,10 +47,10 @@ std::shared_ptr ResourceFactoryXMLVertexV0::ReadResource(std::shared_ if (file->XmlDocument == nullptr) { SPDLOG_ERROR("Failed to load resource: File has no XML document ({} - {})", file->InitData->Type, file->InitData->Path); - return result; + return nullptr; } - auto vertex = std::make_shared(initData); + auto vertex = std::make_shared(file->InitData); auto child = file->XmlDocument->FirstChildElement()->FirstChildElement(); From a5d269dc484451170183515a079d3419deac3bd5 Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Fri, 9 Feb 2024 12:15:22 -0500 Subject: [PATCH 12/25] move some stuff out --- src/resource/ResourceLoader.cpp | 1 - src/resource/ResourceType.h | 46 --------------------------------- 2 files changed, 47 deletions(-) diff --git a/src/resource/ResourceLoader.cpp b/src/resource/ResourceLoader.cpp index ecbfec958..57ba6b67e 100644 --- a/src/resource/ResourceLoader.cpp +++ b/src/resource/ResourceLoader.cpp @@ -23,7 +23,6 @@ ResourceLoader::~ResourceLoader() { } void ResourceLoader::RegisterGlobalResourceFactories() { - // include strings so we register types for mResourceTypes RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Texture", static_cast(ResourceType::Texture), 0); RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Texture", static_cast(ResourceType::Texture), 1); RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Vertex", static_cast(ResourceType::Vertex), 0); diff --git a/src/resource/ResourceType.h b/src/resource/ResourceType.h index 8516120f8..5f777210b 100644 --- a/src/resource/ResourceType.h +++ b/src/resource/ResourceType.h @@ -1,8 +1,5 @@ #pragma once -#include -#include - namespace LUS { enum class ResourceType { @@ -17,48 +14,5 @@ enum class ResourceType { Array = 0x4F415252, // OARR Blob = 0x4F424C42, // OBLB Texture = 0x4F544558, // OTEX - - // LUS of Harkinian - SOH_Animation = 0x4F414E4D, // OANM - SOH_PlayerAnimation = 0x4F50414D, // OPAM - SOH_Room = 0x4F524F4D, // OROM - SOH_CollisionHeader = 0x4F434F4C, // OCOL - SOH_Skeleton = 0x4F534B4C, // OSKL - SOH_SkeletonLimb = 0x4F534C42, // OSLB - SOH_Path = 0x4F505448, // OPTH - SOH_Cutscene = 0x4F435654, // OCUT - SOH_Text = 0x4F545854, // OTXT - SOH_Audio = 0x4F415544, // OAUD - SOH_AudioSample = 0x4F534D50, // OSMP - SOH_AudioSoundFont = 0x4F534654, // OSFT - SOH_AudioSequence = 0x4F534551, // OSEQ - SOH_Background = 0x4F424749, // OBGI - SOH_SceneCommand = 0x4F52434D, // ORCM -}; - -inline std::unordered_map mResourceTypes { - { "None", static_cast(ResourceType::None) }, - { "Archive", static_cast(ResourceType::Archive) }, - { "DisplayList", static_cast(ResourceType::DisplayList) }, - { "Vertex", static_cast(ResourceType::Vertex) }, - { "Matrix", static_cast(ResourceType::Matrix) }, - { "Array", static_cast(ResourceType::Array) }, - { "Blob", static_cast(ResourceType::Blob) }, - { "Texture", static_cast(ResourceType::Texture) }, - { "SOH_Animation", static_cast(ResourceType::SOH_Animation) }, - { "SOH_PlayerAnimation", static_cast(ResourceType::SOH_PlayerAnimation) }, - { "SOH_Room", static_cast(ResourceType::SOH_Room) }, - { "SOH_CollisionHeader", static_cast(ResourceType::SOH_CollisionHeader) }, - { "SOH_Skeleton", static_cast(ResourceType::SOH_Skeleton) }, - { "SOH_SkeletonLimb", static_cast(ResourceType::SOH_SkeletonLimb) }, - { "SOH_Path", static_cast(ResourceType::SOH_Path) }, - { "SOH_Cutscene", static_cast(ResourceType::SOH_Cutscene) }, - { "SOH_Text", static_cast(ResourceType::SOH_Text) }, - { "SOH_Audio", static_cast(ResourceType::SOH_Audio) }, - { "SOH_AudioSample", static_cast(ResourceType::SOH_AudioSample) }, - { "SOH_AudioSoundFont", static_cast(ResourceType::SOH_AudioSoundFont) }, - { "SOH_AudioSequence", static_cast(ResourceType::SOH_AudioSequence) }, - { "SOH_Background", static_cast(ResourceType::SOH_Background) }, - { "SOH_SceneCommand", static_cast(ResourceType::SOH_SceneCommand) }, }; } // namespace LUS From 0ca1721044a6c6999d8a97a6f4566e2a28011615 Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Sat, 10 Feb 2024 04:26:23 -0500 Subject: [PATCH 13/25] reduce copypasta --- src/CMakeLists.txt | 4 ++++ src/resource/ResourceFactory.h | 2 ++ src/resource/ResourceFactoryBinary.cpp | 19 ++++++++++++++++++ src/resource/ResourceFactoryBinary.h | 10 ++++++++++ src/resource/ResourceFactoryXML.cpp | 19 ++++++++++++++++++ src/resource/ResourceFactoryXML.h | 10 ++++++++++ src/resource/factory/ArrayFactory.cpp | 9 +-------- src/resource/factory/ArrayFactory.h | 4 ++-- src/resource/factory/BlobFactory.cpp | 9 +-------- src/resource/factory/BlobFactory.h | 4 ++-- src/resource/factory/DisplayListFactory.cpp | 19 ++---------------- src/resource/factory/DisplayListFactory.h | 9 +++++---- src/resource/factory/MatrixFactory.cpp | 9 +-------- src/resource/factory/MatrixFactory.h | 4 ++-- src/resource/factory/TextureFactory.cpp | 22 ++++----------------- src/resource/factory/TextureFactory.h | 6 +++--- src/resource/factory/VertexFactory.cpp | 18 ++--------------- src/resource/factory/VertexFactory.h | 7 ++++--- 18 files changed, 93 insertions(+), 91 deletions(-) create mode 100644 src/resource/ResourceFactoryBinary.cpp create mode 100644 src/resource/ResourceFactoryBinary.h create mode 100644 src/resource/ResourceFactoryXML.cpp create mode 100644 src/resource/ResourceFactoryXML.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6fcf0cf46..de1c2c623 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -325,6 +325,10 @@ set(Source_Files__Resource ${CMAKE_CURRENT_SOURCE_DIR}/resource/ResourceLoader.cpp ${CMAKE_CURRENT_SOURCE_DIR}/resource/ResourceLoader.h ${CMAKE_CURRENT_SOURCE_DIR}/resource/ResourceFactory.h + ${CMAKE_CURRENT_SOURCE_DIR}/resource/ResourceFactoryBinary.h + ${CMAKE_CURRENT_SOURCE_DIR}/resource/ResourceFactoryBinary.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/resource/ResourceFactoryXML.h + ${CMAKE_CURRENT_SOURCE_DIR}/resource/ResourceFactoryXML.cpp ) source_group("resource" FILES ${Source_Files__Resource}) diff --git a/src/resource/ResourceFactory.h b/src/resource/ResourceFactory.h index 6aead3cbd..6e819d9ef 100644 --- a/src/resource/ResourceFactory.h +++ b/src/resource/ResourceFactory.h @@ -8,5 +8,7 @@ namespace LUS { class ResourceFactory { public: virtual std::shared_ptr ReadResource(std::shared_ptr file) = 0; + protected: + virtual bool FileHasValidFormatAndReader(std::shared_ptr file) = 0; }; } // namespace LUS diff --git a/src/resource/ResourceFactoryBinary.cpp b/src/resource/ResourceFactoryBinary.cpp new file mode 100644 index 000000000..59117e89d --- /dev/null +++ b/src/resource/ResourceFactoryBinary.cpp @@ -0,0 +1,19 @@ +#include "ResourceFactoryBinary.h" +#include "spdlog/spdlog.h" + +namespace LUS { +bool ResourceFactoryBinary::FileHasValidFormatAndReader(std::shared_ptr file) { + if (file->InitData->Format != RESOURCE_FORMAT_BINARY) { + SPDLOG_ERROR("resource file format does not match factory format."); + return false; + } + + if (file->Reader == nullptr) { + SPDLOG_ERROR("Failed to load resource: File has Reader ({} - {})", file->InitData->Type, + file->InitData->Path); + return false; + } + + return true; +}; +} // namespace LUS \ No newline at end of file diff --git a/src/resource/ResourceFactoryBinary.h b/src/resource/ResourceFactoryBinary.h new file mode 100644 index 000000000..a7058e9b3 --- /dev/null +++ b/src/resource/ResourceFactoryBinary.h @@ -0,0 +1,10 @@ +#pragma once + +#include "ResourceFactory.h" + +namespace LUS { +class ResourceFactoryBinary : public ResourceFactory { + protected: + bool FileHasValidFormatAndReader(std::shared_ptr file) override; +}; +} // namespace LUS diff --git a/src/resource/ResourceFactoryXML.cpp b/src/resource/ResourceFactoryXML.cpp new file mode 100644 index 000000000..bc1fff7d8 --- /dev/null +++ b/src/resource/ResourceFactoryXML.cpp @@ -0,0 +1,19 @@ +#include "ResourceFactoryXML.h" +#include "spdlog/spdlog.h" + +namespace LUS { +bool ResourceFactoryXML::FileHasValidFormatAndReader(std::shared_ptr file) { + if (file->InitData->Format != RESOURCE_FORMAT_XML) { + SPDLOG_ERROR("resource file format does not match factory format."); + return false; + } + + if (file->XmlDocument == nullptr) { + SPDLOG_ERROR("Failed to load resource: File has no XML document ({} - {})", file->InitData->Type, + file->InitData->Path); + return false; + } + + return true; +}; +} // namespace LUS \ No newline at end of file diff --git a/src/resource/ResourceFactoryXML.h b/src/resource/ResourceFactoryXML.h new file mode 100644 index 000000000..6d4abed0e --- /dev/null +++ b/src/resource/ResourceFactoryXML.h @@ -0,0 +1,10 @@ +#pragma once + +#include "ResourceFactory.h" + +namespace LUS { +class ResourceFactoryXML : public ResourceFactory { + protected: + bool FileHasValidFormatAndReader(std::shared_ptr file) override; +}; +} // namespace LUS diff --git a/src/resource/factory/ArrayFactory.cpp b/src/resource/factory/ArrayFactory.cpp index b72248aa2..ccf273bdd 100644 --- a/src/resource/factory/ArrayFactory.cpp +++ b/src/resource/factory/ArrayFactory.cpp @@ -4,14 +4,7 @@ namespace LUS { std::shared_ptr ResourceFactoryBinaryArrayV0::ReadResource(std::shared_ptr file) { - if (file->InitData->Format != RESOURCE_FORMAT_BINARY) { - SPDLOG_ERROR("resource file format does not match factory format."); - return nullptr; - } - - if (file->Reader == nullptr) { - SPDLOG_ERROR("Failed to load resource: File has Reader ({} - {})", file->InitData->Type, - file->InitData->Path); + if (!FileHasValidFormatAndReader()) { return nullptr; } diff --git a/src/resource/factory/ArrayFactory.h b/src/resource/factory/ArrayFactory.h index 8471fbbe5..31904a373 100644 --- a/src/resource/factory/ArrayFactory.h +++ b/src/resource/factory/ArrayFactory.h @@ -1,10 +1,10 @@ #pragma once #include "resource/Resource.h" -#include "resource/ResourceFactory.h" +#include "resource/BinaryResourceFactory.h" namespace LUS { -class ResourceFactoryBinaryArrayV0 : public ResourceFactory { +class ResourceFactoryBinaryArrayV0 : public ResourceFactoryBinary { public: std::shared_ptr ReadResource(std::shared_ptr file) override; }; diff --git a/src/resource/factory/BlobFactory.cpp b/src/resource/factory/BlobFactory.cpp index ebc21a978..3b3ac2cc5 100644 --- a/src/resource/factory/BlobFactory.cpp +++ b/src/resource/factory/BlobFactory.cpp @@ -4,14 +4,7 @@ namespace LUS { std::shared_ptr ResourceFactoryBinaryBlobV0::ReadResource(std::shared_ptr file) { - if (file->InitData->Format != RESOURCE_FORMAT_BINARY) { - SPDLOG_ERROR("resource file format does not match factory format."); - return nullptr; - } - - if (file->Reader == nullptr) { - SPDLOG_ERROR("Failed to load resource: File has Reader ({} - {})", file->InitData->Type, - file->InitData->Path); + if (!FileHasValidFormatAndReader()) { return nullptr; } diff --git a/src/resource/factory/BlobFactory.h b/src/resource/factory/BlobFactory.h index 52e721da9..f809b4932 100644 --- a/src/resource/factory/BlobFactory.h +++ b/src/resource/factory/BlobFactory.h @@ -1,10 +1,10 @@ #pragma once #include "resource/Resource.h" -#include "resource/ResourceFactory.h" +#include "resource/BinaryResourceFactory.h" namespace LUS { -class ResourceFactoryBinaryBlobV0 : public ResourceFactory { +class ResourceFactoryBinaryBlobV0 : public ResourceFactoryBinary { public: std::shared_ptr ReadResource(std::shared_ptr file) override; }; diff --git a/src/resource/factory/DisplayListFactory.cpp b/src/resource/factory/DisplayListFactory.cpp index de14e3fd1..2e087cb7d 100644 --- a/src/resource/factory/DisplayListFactory.cpp +++ b/src/resource/factory/DisplayListFactory.cpp @@ -129,14 +129,7 @@ uint32_t ResourceFactoryDisplayList::GetCombineLERPValue(std::string valStr) { } std::shared_ptr ResourceFactoryBinaryDisplayListV0::ReadResource(std::shared_ptr file) { - if (file->InitData->Format != RESOURCE_FORMAT_BINARY) { - SPDLOG_ERROR("resource file format does not match factory format."); - return nullptr; - } - - if (file->Reader == nullptr) { - SPDLOG_ERROR("Failed to load resource: File has Reader ({} - {})", file->InitData->Type, - file->InitData->Path); + if (!FileHasValidFormatAndReader()) { return nullptr; } @@ -173,18 +166,10 @@ std::shared_ptr ResourceFactoryBinaryDisplayListV0::ReadResource(std: } std::shared_ptr ResourceFactoryXMLDisplayListV0::ReadResource(std::shared_ptr file) { - if (file->InitData->Format != RESOURCE_FORMAT_XML) { - SPDLOG_ERROR("resource file format does not match factory format."); + if (!FileHasValidFormatAndReader()) { return nullptr; } - if (file->XmlDocument == nullptr) { - SPDLOG_ERROR("Failed to load resource: File has no XML document ({} - {})", file->InitData->Type, - file->InitData->Path); - return nullptr; - } - - auto dl = std::make_shared(file->InitData); auto child = file->XmlDocument->FirstChildElement()->FirstChildElement(); diff --git a/src/resource/factory/DisplayListFactory.h b/src/resource/factory/DisplayListFactory.h index 5250316f2..06c10bd39 100644 --- a/src/resource/factory/DisplayListFactory.h +++ b/src/resource/factory/DisplayListFactory.h @@ -1,20 +1,21 @@ #pragma once #include "resource/Resource.h" -#include "resource/ResourceFactory.h" +#include "resource/BinaryResourceFactory.h" +#include "resource/XMLResourceFactory.h" namespace LUS { -class ResourceFactoryDisplayList : public ResourceFactory { +class ResourceFactoryDisplayList { protected: uint32_t GetCombineLERPValue(std::string valStr); }; -class ResourceFactoryBinaryDisplayListV0 : public ResourceFactoryDisplayList { +class ResourceFactoryBinaryDisplayListV0 : public ResourceFactoryDisplayList, public BinaryResourceFactory { public: std::shared_ptr ReadResource(std::shared_ptr file) override; }; -class ResourceFactoryXMLDisplayListV0 : public ResourceFactoryDisplayList { +class ResourceFactoryXMLDisplayListV0 : public ResourceFactoryDisplayList, public XMLResourceFactory { public: std::shared_ptr ReadResource(std::shared_ptr file) override; }; diff --git a/src/resource/factory/MatrixFactory.cpp b/src/resource/factory/MatrixFactory.cpp index c181200db..e33193fb5 100644 --- a/src/resource/factory/MatrixFactory.cpp +++ b/src/resource/factory/MatrixFactory.cpp @@ -4,14 +4,7 @@ namespace LUS { std::shared_ptr ResourceFactoryBinaryMatrixV0::ReadResource(std::shared_ptr file) { - if (file->InitData->Format != RESOURCE_FORMAT_BINARY) { - SPDLOG_ERROR("resource file format does not match factory format."); - return nullptr; - } - - if (file->Reader == nullptr) { - SPDLOG_ERROR("Failed to load resource: File has Reader ({} - {})", file->InitData->Type, - file->InitData->Path); + if (!FileHasValidFormatAndReader()) { return nullptr; } diff --git a/src/resource/factory/MatrixFactory.h b/src/resource/factory/MatrixFactory.h index f35d8a566..a1662c8ff 100644 --- a/src/resource/factory/MatrixFactory.h +++ b/src/resource/factory/MatrixFactory.h @@ -1,10 +1,10 @@ #pragma once #include "resource/Resource.h" -#include "resource/ResourceFactory.h" +#include "resource/BinaryResourceFactory.h" namespace LUS { -class ResourceFactoryBinaryMatrixV0 : public ResourceFactory { +class ResourceFactoryBinaryMatrixV0 : public ResourceFactoryBinary { public: std::shared_ptr ReadResource(std::shared_ptr file) override; }; diff --git a/src/resource/factory/TextureFactory.cpp b/src/resource/factory/TextureFactory.cpp index 53d9e8040..05062caa2 100644 --- a/src/resource/factory/TextureFactory.cpp +++ b/src/resource/factory/TextureFactory.cpp @@ -5,14 +5,7 @@ namespace LUS { std::shared_ptr ResourceFactoryBinaryTextureV0::ReadResource(std::shared_ptr file) { - if (file->InitData->Format != RESOURCE_FORMAT_BINARY) { - SPDLOG_ERROR("resource file format does not match factory format."); - return nullptr; - } - - if (file->Reader == nullptr) { - SPDLOG_ERROR("Failed to load resource: File has Reader ({} - {})", file->InitData->Type, - file->InitData->Path); + if (!FileHasValidFormatAndReader()) { return nullptr; } @@ -30,16 +23,9 @@ std::shared_ptr ResourceFactoryBinaryTextureV0::ReadResource(std::sha } std::shared_ptr ResourceFactoryBinaryTextureV1::ReadResource(std::shared_ptr file) { - if (file->InitData->Format != RESOURCE_FORMAT_BINARY) { - SPDLOG_ERROR("resource file format does not match factory format."); - return nullptr; - } - - if (file->Reader == nullptr) { - SPDLOG_ERROR("Failed to load resource: File has Reader ({} - {})", file->InitData->Type, - file->InitData->Path); - return nullptr; - } +if (!FileHasValidFormatAndReader()) { + return nullptr; +} auto texture = std::make_shared(file->InitData); diff --git a/src/resource/factory/TextureFactory.h b/src/resource/factory/TextureFactory.h index 304bece98..c8394d171 100644 --- a/src/resource/factory/TextureFactory.h +++ b/src/resource/factory/TextureFactory.h @@ -1,15 +1,15 @@ #pragma once #include "resource/Resource.h" -#include "resource/ResourceFactory.h" +#include "resource/BinaryResourceFactory.h" namespace LUS { -class ResourceFactoryBinaryTextureV0 : public ResourceFactory { +class ResourceFactoryBinaryTextureV0 : public ResourceFactoryBinary { public: std::shared_ptr ReadResource(std::shared_ptr file) override; }; -class ResourceFactoryBinaryTextureV1 : public ResourceFactory { +class ResourceFactoryBinaryTextureV1 : public ResourceFactoryBinary { public: std::shared_ptr ReadResource(std::shared_ptr file) override; }; diff --git a/src/resource/factory/VertexFactory.cpp b/src/resource/factory/VertexFactory.cpp index 5209bbd9d..427dc4193 100644 --- a/src/resource/factory/VertexFactory.cpp +++ b/src/resource/factory/VertexFactory.cpp @@ -4,14 +4,7 @@ namespace LUS { std::shared_ptr ResourceFactoryBinaryVertexV0::ReadResource(std::shared_ptr file) { - if (file->InitData->Format != RESOURCE_FORMAT_BINARY) { - SPDLOG_ERROR("resource file format does not match factory format."); - return nullptr; - } - - if (file->Reader == nullptr) { - SPDLOG_ERROR("Failed to load resource: File has Reader ({} - {})", file->InitData->Type, - file->InitData->Path); + if (!FileHasValidFormatAndReader()) { return nullptr; } @@ -39,14 +32,7 @@ std::shared_ptr ResourceFactoryBinaryVertexV0::ReadResource(std::shar } std::shared_ptr ResourceFactoryXMLVertexV0::ReadResource(std::shared_ptr file) { - if (file->InitData->Format != RESOURCE_FORMAT_XML) { - SPDLOG_ERROR("resource file format does not match factory format."); - return nullptr; - } - - if (file->XmlDocument == nullptr) { - SPDLOG_ERROR("Failed to load resource: File has no XML document ({} - {})", file->InitData->Type, - file->InitData->Path); + if (!FileHasValidFormatAndReader()) { return nullptr; } diff --git a/src/resource/factory/VertexFactory.h b/src/resource/factory/VertexFactory.h index a3749b780..6f0ba5a4b 100644 --- a/src/resource/factory/VertexFactory.h +++ b/src/resource/factory/VertexFactory.h @@ -1,15 +1,16 @@ #pragma once #include "resource/Resource.h" -#include "resource/ResourceFactory.h" +#include "resource/BinaryResourceFactory.h" +#include "resource/XMLResourceFactory.h" namespace LUS { -class ResourceFactoryBinaryVertexV0 : public ResourceFactory { +class ResourceFactoryBinaryVertexV0 : public ResourceFactoryBinary { public: std::shared_ptr ReadResource(std::shared_ptr file) override; }; -class ResourceFactoryXMLVertexV0 : public ResourceFactory { +class ResourceFactoryXMLVertexV0 : public ResourceFactoryXML { public: std::shared_ptr ReadResource(std::shared_ptr file) override; }; From 211bd8bb4cc5b27ba4657e1315c1ca82c00bc726 Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Sat, 10 Feb 2024 04:39:18 -0500 Subject: [PATCH 14/25] fix --- src/resource/factory/ArrayFactory.cpp | 2 +- src/resource/factory/BlobFactory.cpp | 2 +- src/resource/factory/DisplayListFactory.cpp | 4 ++-- src/resource/factory/MatrixFactory.cpp | 2 +- src/resource/factory/TextureFactory.cpp | 4 ++-- src/resource/factory/VertexFactory.cpp | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/resource/factory/ArrayFactory.cpp b/src/resource/factory/ArrayFactory.cpp index ccf273bdd..1ae6ace26 100644 --- a/src/resource/factory/ArrayFactory.cpp +++ b/src/resource/factory/ArrayFactory.cpp @@ -4,7 +4,7 @@ namespace LUS { std::shared_ptr ResourceFactoryBinaryArrayV0::ReadResource(std::shared_ptr file) { - if (!FileHasValidFormatAndReader()) { + if (!FileHasValidFormatAndReader(file)) { return nullptr; } diff --git a/src/resource/factory/BlobFactory.cpp b/src/resource/factory/BlobFactory.cpp index 3b3ac2cc5..52b9c7acd 100644 --- a/src/resource/factory/BlobFactory.cpp +++ b/src/resource/factory/BlobFactory.cpp @@ -4,7 +4,7 @@ namespace LUS { std::shared_ptr ResourceFactoryBinaryBlobV0::ReadResource(std::shared_ptr file) { - if (!FileHasValidFormatAndReader()) { + if (!FileHasValidFormatAndReader(file)) { return nullptr; } diff --git a/src/resource/factory/DisplayListFactory.cpp b/src/resource/factory/DisplayListFactory.cpp index 2e087cb7d..e72b20048 100644 --- a/src/resource/factory/DisplayListFactory.cpp +++ b/src/resource/factory/DisplayListFactory.cpp @@ -129,7 +129,7 @@ uint32_t ResourceFactoryDisplayList::GetCombineLERPValue(std::string valStr) { } std::shared_ptr ResourceFactoryBinaryDisplayListV0::ReadResource(std::shared_ptr file) { - if (!FileHasValidFormatAndReader()) { + if (!FileHasValidFormatAndReader(file)) { return nullptr; } @@ -166,7 +166,7 @@ std::shared_ptr ResourceFactoryBinaryDisplayListV0::ReadResource(std: } std::shared_ptr ResourceFactoryXMLDisplayListV0::ReadResource(std::shared_ptr file) { - if (!FileHasValidFormatAndReader()) { + if (!FileHasValidFormatAndReader(file)) { return nullptr; } diff --git a/src/resource/factory/MatrixFactory.cpp b/src/resource/factory/MatrixFactory.cpp index e33193fb5..025e8258b 100644 --- a/src/resource/factory/MatrixFactory.cpp +++ b/src/resource/factory/MatrixFactory.cpp @@ -4,7 +4,7 @@ namespace LUS { std::shared_ptr ResourceFactoryBinaryMatrixV0::ReadResource(std::shared_ptr file) { - if (!FileHasValidFormatAndReader()) { + if (!FileHasValidFormatAndReader(file)) { return nullptr; } diff --git a/src/resource/factory/TextureFactory.cpp b/src/resource/factory/TextureFactory.cpp index 05062caa2..88f1bf720 100644 --- a/src/resource/factory/TextureFactory.cpp +++ b/src/resource/factory/TextureFactory.cpp @@ -5,7 +5,7 @@ namespace LUS { std::shared_ptr ResourceFactoryBinaryTextureV0::ReadResource(std::shared_ptr file) { - if (!FileHasValidFormatAndReader()) { + if (!FileHasValidFormatAndReader(file)) { return nullptr; } @@ -23,7 +23,7 @@ std::shared_ptr ResourceFactoryBinaryTextureV0::ReadResource(std::sha } std::shared_ptr ResourceFactoryBinaryTextureV1::ReadResource(std::shared_ptr file) { -if (!FileHasValidFormatAndReader()) { +if (!FileHasValidFormatAndReader(file)) { return nullptr; } diff --git a/src/resource/factory/VertexFactory.cpp b/src/resource/factory/VertexFactory.cpp index 427dc4193..3b914691a 100644 --- a/src/resource/factory/VertexFactory.cpp +++ b/src/resource/factory/VertexFactory.cpp @@ -4,7 +4,7 @@ namespace LUS { std::shared_ptr ResourceFactoryBinaryVertexV0::ReadResource(std::shared_ptr file) { - if (!FileHasValidFormatAndReader()) { + if (!FileHasValidFormatAndReader(file)) { return nullptr; } @@ -32,7 +32,7 @@ std::shared_ptr ResourceFactoryBinaryVertexV0::ReadResource(std::shar } std::shared_ptr ResourceFactoryXMLVertexV0::ReadResource(std::shared_ptr file) { - if (!FileHasValidFormatAndReader()) { + if (!FileHasValidFormatAndReader(file)) { return nullptr; } From 92fa05465fcdda7893b2f994c1191cf9c616f497 Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Sat, 10 Feb 2024 05:16:20 -0500 Subject: [PATCH 15/25] clean up --- src/resource/factory/ArrayFactory.h | 2 +- src/resource/factory/BlobFactory.h | 2 +- src/resource/factory/DisplayListFactory.h | 8 ++++---- src/resource/factory/MatrixFactory.h | 2 +- src/resource/factory/TextureFactory.h | 2 +- src/resource/factory/VertexFactory.h | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/resource/factory/ArrayFactory.h b/src/resource/factory/ArrayFactory.h index 31904a373..3f7e96c8b 100644 --- a/src/resource/factory/ArrayFactory.h +++ b/src/resource/factory/ArrayFactory.h @@ -1,7 +1,7 @@ #pragma once #include "resource/Resource.h" -#include "resource/BinaryResourceFactory.h" +#include "resource/ResourceFactoryBinary.h" namespace LUS { class ResourceFactoryBinaryArrayV0 : public ResourceFactoryBinary { diff --git a/src/resource/factory/BlobFactory.h b/src/resource/factory/BlobFactory.h index f809b4932..38295858d 100644 --- a/src/resource/factory/BlobFactory.h +++ b/src/resource/factory/BlobFactory.h @@ -1,7 +1,7 @@ #pragma once #include "resource/Resource.h" -#include "resource/BinaryResourceFactory.h" +#include "resource/ResourceFactoryBinary.h" namespace LUS { class ResourceFactoryBinaryBlobV0 : public ResourceFactoryBinary { diff --git a/src/resource/factory/DisplayListFactory.h b/src/resource/factory/DisplayListFactory.h index 06c10bd39..6e8e74567 100644 --- a/src/resource/factory/DisplayListFactory.h +++ b/src/resource/factory/DisplayListFactory.h @@ -1,8 +1,8 @@ #pragma once #include "resource/Resource.h" -#include "resource/BinaryResourceFactory.h" -#include "resource/XMLResourceFactory.h" +#include "resource/ResourceFactoryBinary.h" +#include "resource/ResourceFactoryXML.h" namespace LUS { class ResourceFactoryDisplayList { @@ -10,12 +10,12 @@ class ResourceFactoryDisplayList { uint32_t GetCombineLERPValue(std::string valStr); }; -class ResourceFactoryBinaryDisplayListV0 : public ResourceFactoryDisplayList, public BinaryResourceFactory { +class ResourceFactoryBinaryDisplayListV0 : public ResourceFactoryDisplayList, public ResourceFactoryBinary { public: std::shared_ptr ReadResource(std::shared_ptr file) override; }; -class ResourceFactoryXMLDisplayListV0 : public ResourceFactoryDisplayList, public XMLResourceFactory { +class ResourceFactoryXMLDisplayListV0 : public ResourceFactoryDisplayList, public ResourceFactoryXML { public: std::shared_ptr ReadResource(std::shared_ptr file) override; }; diff --git a/src/resource/factory/MatrixFactory.h b/src/resource/factory/MatrixFactory.h index a1662c8ff..6f8df8684 100644 --- a/src/resource/factory/MatrixFactory.h +++ b/src/resource/factory/MatrixFactory.h @@ -1,7 +1,7 @@ #pragma once #include "resource/Resource.h" -#include "resource/BinaryResourceFactory.h" +#include "resource/ResourceFactoryBinary.h" namespace LUS { class ResourceFactoryBinaryMatrixV0 : public ResourceFactoryBinary { diff --git a/src/resource/factory/TextureFactory.h b/src/resource/factory/TextureFactory.h index c8394d171..a0d926f95 100644 --- a/src/resource/factory/TextureFactory.h +++ b/src/resource/factory/TextureFactory.h @@ -1,7 +1,7 @@ #pragma once #include "resource/Resource.h" -#include "resource/BinaryResourceFactory.h" +#include "resource/ResourceFactoryBinary.h" namespace LUS { class ResourceFactoryBinaryTextureV0 : public ResourceFactoryBinary { diff --git a/src/resource/factory/VertexFactory.h b/src/resource/factory/VertexFactory.h index 6f0ba5a4b..127704c80 100644 --- a/src/resource/factory/VertexFactory.h +++ b/src/resource/factory/VertexFactory.h @@ -1,8 +1,8 @@ #pragma once #include "resource/Resource.h" -#include "resource/BinaryResourceFactory.h" -#include "resource/XMLResourceFactory.h" +#include "resource/ResourceFactoryBinary.h" +#include "resource/ResourceFactoryXML.h" namespace LUS { class ResourceFactoryBinaryVertexV0 : public ResourceFactoryBinary { From ec4fcc3b1356469c167504af311c819bf176f16d Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Sat, 10 Feb 2024 07:55:56 -0500 Subject: [PATCH 16/25] keyhash --- src/resource/ResourceLoader.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/resource/ResourceLoader.h b/src/resource/ResourceLoader.h index 0a8d35396..4fba4947d 100644 --- a/src/resource/ResourceLoader.h +++ b/src/resource/ResourceLoader.h @@ -13,6 +13,16 @@ struct ResourceFactoryKey { uint32_t resourceFormat; uint32_t resourceType; uint32_t resourceVersion; + + bool operator==(const ResourceFactoryKey& o) const { + return (resourceFormat == o.resourceFormat) && (resourceType == o.resourceType) && (resourceVersion == o.resourceVersion); + } +}; + +struct ResourceFactoryKeyHash { + std::size_t operator()(const ResourceFactoryKey& key) const { + return std::hash()(key.resourceFormat) ^ std::hash()(key.resourceType) ^ std::hash()(key.resourceVersion); + } }; class ResourceLoader { @@ -32,6 +42,6 @@ class ResourceLoader { private: std::unordered_map mResourceTypes; - std::unordered_map> mFactories; + std::unordered_map, ResourceFactoryKeyHash> mFactories; }; } // namespace LUS From 956371627d533dc331191241598c0f99c874d0f7 Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Sat, 10 Feb 2024 09:32:24 -0500 Subject: [PATCH 17/25] implement a thing --- src/resource/ResourceLoader.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/resource/ResourceLoader.cpp b/src/resource/ResourceLoader.cpp index 57ba6b67e..3cece2b0b 100644 --- a/src/resource/ResourceLoader.cpp +++ b/src/resource/ResourceLoader.cpp @@ -94,4 +94,8 @@ std::shared_ptr ResourceLoader::LoadResource(std::shared_ptr fi return factory->ReadResource(fileToLoad); } + +uint32_t ResourceLoader::GetResourceType(const std::string& type) { + return mResourceTypes.contains(type) ? mResourceTypes[type] : static_cast(ResourceType::None); +} } // namespace LUS From c16d7c8d23df6e34b96b4f999306b778a5fe7526 Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Sat, 10 Feb 2024 14:35:53 -0500 Subject: [PATCH 18/25] factory logging --- src/resource/ResourceLoader.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/resource/ResourceLoader.cpp b/src/resource/ResourceLoader.cpp index 3cece2b0b..ab0ba907b 100644 --- a/src/resource/ResourceLoader.cpp +++ b/src/resource/ResourceLoader.cpp @@ -74,22 +74,25 @@ std::shared_ptr ResourceLoader::GetFactory(uint32_t format, std } std::shared_ptr ResourceLoader::LoadResource(std::shared_ptr fileToLoad) { - std::shared_ptr result = nullptr; - if (fileToLoad == nullptr) { SPDLOG_ERROR("Failed to load resource: File not loaded"); - return result; + return nullptr; } if (fileToLoad->InitData == nullptr) { SPDLOG_ERROR("Failed to load resource: ResourceInitData not loaded"); - return result; + return nullptr; } auto factory = GetFactory(fileToLoad->InitData->Format, fileToLoad->InitData->Type, fileToLoad->InitData->ResourceVersion); if (factory == nullptr) { - SPDLOG_ERROR("Failed to load resource: Factory does not exist ({} - {})", fileToLoad->InitData->Type, - fileToLoad->InitData->Path); + SPDLOG_ERROR("Failed to load resource: Factory does not exist.\n" \ + "Path: {}\n" \ + "Type: {}\n" \ + "Format: {}\n" \ + "Version: {}", + fileToLoad->InitData->Path, fileToLoad->InitData->Type, fileToLoad->InitData->Format, fileToLoad->InitData->ResourceVersion); + return nullptr; } return factory->ReadResource(fileToLoad); From be9f894f7526b0d61237a16a5dd2ab1e6b1c3fa6 Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Sat, 10 Feb 2024 18:53:24 -0500 Subject: [PATCH 19/25] fix array oopsie --- src/resource/factory/ArrayFactory.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/resource/factory/ArrayFactory.cpp b/src/resource/factory/ArrayFactory.cpp index 1ae6ace26..1260ae209 100644 --- a/src/resource/factory/ArrayFactory.cpp +++ b/src/resource/factory/ArrayFactory.cpp @@ -10,8 +10,6 @@ std::shared_ptr ResourceFactoryBinaryArrayV0::ReadResource(std::share auto array = std::make_shared(file->InitData); - uint32_t dataSize = file->Reader->ReadUInt32(); - array->ArrayType = (ArrayResourceType)file->Reader->ReadUInt32(); array->ArrayCount = file->Reader->ReadUInt32(); From 4621d4c6012314107d8db1c9f9c5039485e6331c Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Sat, 10 Feb 2024 19:10:08 -0500 Subject: [PATCH 20/25] clang format --- src/resource/ResourceFactory.h | 1 + src/resource/ResourceFactoryBinary.cpp | 3 +- src/resource/ResourceFactoryXML.cpp | 2 +- src/resource/ResourceLoader.cpp | 53 ++++++++++++++--------- src/resource/ResourceLoader.h | 19 ++++---- src/resource/archive/Archive.cpp | 3 +- src/resource/factory/DisplayListFactory.h | 2 +- src/resource/factory/TextureFactory.cpp | 6 +-- src/resource/factory/TextureFactory.h | 2 +- src/resource/factory/VertexFactory.h | 2 +- 10 files changed, 55 insertions(+), 38 deletions(-) diff --git a/src/resource/ResourceFactory.h b/src/resource/ResourceFactory.h index 6e819d9ef..8940bfe24 100644 --- a/src/resource/ResourceFactory.h +++ b/src/resource/ResourceFactory.h @@ -8,6 +8,7 @@ namespace LUS { class ResourceFactory { public: virtual std::shared_ptr ReadResource(std::shared_ptr file) = 0; + protected: virtual bool FileHasValidFormatAndReader(std::shared_ptr file) = 0; }; diff --git a/src/resource/ResourceFactoryBinary.cpp b/src/resource/ResourceFactoryBinary.cpp index 59117e89d..574fe4191 100644 --- a/src/resource/ResourceFactoryBinary.cpp +++ b/src/resource/ResourceFactoryBinary.cpp @@ -9,8 +9,7 @@ bool ResourceFactoryBinary::FileHasValidFormatAndReader(std::shared_ptr fi } if (file->Reader == nullptr) { - SPDLOG_ERROR("Failed to load resource: File has Reader ({} - {})", file->InitData->Type, - file->InitData->Path); + SPDLOG_ERROR("Failed to load resource: File has Reader ({} - {})", file->InitData->Type, file->InitData->Path); return false; } diff --git a/src/resource/ResourceFactoryXML.cpp b/src/resource/ResourceFactoryXML.cpp index bc1fff7d8..cae03d918 100644 --- a/src/resource/ResourceFactoryXML.cpp +++ b/src/resource/ResourceFactoryXML.cpp @@ -10,7 +10,7 @@ bool ResourceFactoryXML::FileHasValidFormatAndReader(std::shared_ptr file) if (file->XmlDocument == nullptr) { SPDLOG_ERROR("Failed to load resource: File has no XML document ({} - {})", file->InitData->Type, - file->InitData->Path); + file->InitData->Path); return false; } diff --git a/src/resource/ResourceLoader.cpp b/src/resource/ResourceLoader.cpp index ab0ba907b..d5064cde7 100644 --- a/src/resource/ResourceLoader.cpp +++ b/src/resource/ResourceLoader.cpp @@ -23,20 +23,30 @@ ResourceLoader::~ResourceLoader() { } void ResourceLoader::RegisterGlobalResourceFactories() { - RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Texture", static_cast(ResourceType::Texture), 0); - RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Texture", static_cast(ResourceType::Texture), 1); - RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Vertex", static_cast(ResourceType::Vertex), 0); - RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_XML, "Vertex", static_cast(ResourceType::Vertex), 0); - RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "DisplayList", static_cast(ResourceType::DisplayList), 0); - RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_XML, "DisplayList", static_cast(ResourceType::DisplayList), 0); - RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Matrix", static_cast(ResourceType::Matrix), 0); - RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Array", static_cast(ResourceType::Array), 0); - RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Blob", static_cast(ResourceType::Blob), 0); + RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Texture", + static_cast(ResourceType::Texture), 0); + RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Texture", + static_cast(ResourceType::Texture), 1); + RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Vertex", + static_cast(ResourceType::Vertex), 0); + RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_XML, "Vertex", + static_cast(ResourceType::Vertex), 0); + RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, + "DisplayList", static_cast(ResourceType::DisplayList), 0); + RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_XML, "DisplayList", + static_cast(ResourceType::DisplayList), 0); + RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Matrix", + static_cast(ResourceType::Matrix), 0); + RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Array", + static_cast(ResourceType::Array), 0); + RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Blob", + static_cast(ResourceType::Blob), 0); } -bool ResourceLoader::RegisterResourceFactory(std::shared_ptr factory, uint32_t format, std::string typeName, uint32_t type, uint32_t version) { +bool ResourceLoader::RegisterResourceFactory(std::shared_ptr factory, uint32_t format, + std::string typeName, uint32_t type, uint32_t version) { if (mResourceTypes.contains(typeName)) { - if(mResourceTypes[typeName] != type) { + if (mResourceTypes[typeName] != type) { SPDLOG_ERROR("Failed to register resource factory: conflicting types for name {}", typeName); return false; } @@ -44,9 +54,10 @@ bool ResourceLoader::RegisterResourceFactory(std::shared_ptr fa mResourceTypes[typeName] = type; } - ResourceFactoryKey key = {resourceFormat: format, resourceType: type, resourceVersion: version}; + ResourceFactoryKey key = { resourceFormat : format, resourceType : type, resourceVersion : version }; if (mFactories.contains(key)) { - SPDLOG_ERROR("Failed to register resource factory: factory with key {}{}{} already exists", format, type, version); + SPDLOG_ERROR("Failed to register resource factory: factory with key {}{}{} already exists", format, type, + version); return false; } mFactories[key] = factory; @@ -55,7 +66,7 @@ bool ResourceLoader::RegisterResourceFactory(std::shared_ptr fa } std::shared_ptr ResourceLoader::GetFactory(uint32_t format, uint32_t type, uint32_t version) { - ResourceFactoryKey key = {resourceFormat: format, resourceType: type, resourceVersion: version}; + ResourceFactoryKey key = { resourceFormat : format, resourceType : type, resourceVersion : version }; if (!mFactories.contains(key)) { SPDLOG_ERROR("Could not find resource factory with key {}{}{}", format, type, version); return nullptr; @@ -84,14 +95,16 @@ std::shared_ptr ResourceLoader::LoadResource(std::shared_ptr fi return nullptr; } - auto factory = GetFactory(fileToLoad->InitData->Format, fileToLoad->InitData->Type, fileToLoad->InitData->ResourceVersion); + auto factory = + GetFactory(fileToLoad->InitData->Format, fileToLoad->InitData->Type, fileToLoad->InitData->ResourceVersion); if (factory == nullptr) { - SPDLOG_ERROR("Failed to load resource: Factory does not exist.\n" \ - "Path: {}\n" \ - "Type: {}\n" \ - "Format: {}\n" \ + SPDLOG_ERROR("Failed to load resource: Factory does not exist.\n" + "Path: {}\n" + "Type: {}\n" + "Format: {}\n" "Version: {}", - fileToLoad->InitData->Path, fileToLoad->InitData->Type, fileToLoad->InitData->Format, fileToLoad->InitData->ResourceVersion); + fileToLoad->InitData->Path, fileToLoad->InitData->Type, fileToLoad->InitData->Format, + fileToLoad->InitData->ResourceVersion); return nullptr; } diff --git a/src/resource/ResourceLoader.h b/src/resource/ResourceLoader.h index 4fba4947d..1709be953 100644 --- a/src/resource/ResourceLoader.h +++ b/src/resource/ResourceLoader.h @@ -10,18 +10,20 @@ namespace LUS { struct File; struct ResourceFactoryKey { - uint32_t resourceFormat; - uint32_t resourceType; - uint32_t resourceVersion; + uint32_t resourceFormat; + uint32_t resourceType; + uint32_t resourceVersion; - bool operator==(const ResourceFactoryKey& o) const { - return (resourceFormat == o.resourceFormat) && (resourceType == o.resourceType) && (resourceVersion == o.resourceVersion); - } + bool operator==(const ResourceFactoryKey& o) const { + return (resourceFormat == o.resourceFormat) && (resourceType == o.resourceType) && + (resourceVersion == o.resourceVersion); + } }; struct ResourceFactoryKeyHash { std::size_t operator()(const ResourceFactoryKey& key) const { - return std::hash()(key.resourceFormat) ^ std::hash()(key.resourceType) ^ std::hash()(key.resourceVersion); + return std::hash()(key.resourceFormat) ^ std::hash()(key.resourceType) ^ + std::hash()(key.resourceVersion); } }; @@ -31,7 +33,8 @@ class ResourceLoader { ~ResourceLoader(); std::shared_ptr LoadResource(std::shared_ptr fileToLoad); - bool RegisterResourceFactory(std::shared_ptr factory, uint32_t format, std::string typeName, uint32_t type, uint32_t version); + bool RegisterResourceFactory(std::shared_ptr factory, uint32_t format, std::string typeName, + uint32_t type, uint32_t version); uint32_t GetResourceType(const std::string& type); diff --git a/src/resource/archive/Archive.cpp b/src/resource/archive/Archive.cpp index 0bd4170f0..af4ae976f 100644 --- a/src/resource/archive/Archive.cpp +++ b/src/resource/archive/Archive.cpp @@ -233,7 +233,8 @@ std::shared_ptr Archive::ReadResourceInitDataXml(const std::st resourceInitData->Format = RESOURCE_FORMAT_XML; auto root = document->FirstChildElement(); - resourceInitData->Type = Context::GetInstance()->GetResourceManager()->GetResourceLoader()->GetResourceType(root->Name()); + resourceInitData->Type = + Context::GetInstance()->GetResourceManager()->GetResourceLoader()->GetResourceType(root->Name()); resourceInitData->ResourceVersion = root->IntAttribute("Version"); return resourceInitData; diff --git a/src/resource/factory/DisplayListFactory.h b/src/resource/factory/DisplayListFactory.h index 6e8e74567..bed189158 100644 --- a/src/resource/factory/DisplayListFactory.h +++ b/src/resource/factory/DisplayListFactory.h @@ -17,6 +17,6 @@ class ResourceFactoryBinaryDisplayListV0 : public ResourceFactoryDisplayList, pu class ResourceFactoryXMLDisplayListV0 : public ResourceFactoryDisplayList, public ResourceFactoryXML { public: - std::shared_ptr ReadResource(std::shared_ptr file) override; + std::shared_ptr ReadResource(std::shared_ptr file) override; }; } // namespace LUS diff --git a/src/resource/factory/TextureFactory.cpp b/src/resource/factory/TextureFactory.cpp index 88f1bf720..b6cc6a71f 100644 --- a/src/resource/factory/TextureFactory.cpp +++ b/src/resource/factory/TextureFactory.cpp @@ -23,9 +23,9 @@ std::shared_ptr ResourceFactoryBinaryTextureV0::ReadResource(std::sha } std::shared_ptr ResourceFactoryBinaryTextureV1::ReadResource(std::shared_ptr file) { -if (!FileHasValidFormatAndReader(file)) { - return nullptr; -} + if (!FileHasValidFormatAndReader(file)) { + return nullptr; + } auto texture = std::make_shared(file->InitData); diff --git a/src/resource/factory/TextureFactory.h b/src/resource/factory/TextureFactory.h index a0d926f95..b2e463520 100644 --- a/src/resource/factory/TextureFactory.h +++ b/src/resource/factory/TextureFactory.h @@ -11,6 +11,6 @@ class ResourceFactoryBinaryTextureV0 : public ResourceFactoryBinary { class ResourceFactoryBinaryTextureV1 : public ResourceFactoryBinary { public: - std::shared_ptr ReadResource(std::shared_ptr file) override; + std::shared_ptr ReadResource(std::shared_ptr file) override; }; } // namespace LUS diff --git a/src/resource/factory/VertexFactory.h b/src/resource/factory/VertexFactory.h index 127704c80..898e4550c 100644 --- a/src/resource/factory/VertexFactory.h +++ b/src/resource/factory/VertexFactory.h @@ -12,6 +12,6 @@ class ResourceFactoryBinaryVertexV0 : public ResourceFactoryBinary { class ResourceFactoryXMLVertexV0 : public ResourceFactoryXML { public: - std::shared_ptr ReadResource(std::shared_ptr file) override; + std::shared_ptr ReadResource(std::shared_ptr file) override; }; } // namespace LUS From d72e5a926f941294e0032ed7e1cc8fe54e38dce9 Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Sat, 10 Feb 2024 19:30:15 -0500 Subject: [PATCH 21/25] get your shit together msvc --- src/resource/ResourceLoader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/resource/ResourceLoader.cpp b/src/resource/ResourceLoader.cpp index d5064cde7..5001441dc 100644 --- a/src/resource/ResourceLoader.cpp +++ b/src/resource/ResourceLoader.cpp @@ -54,7 +54,7 @@ bool ResourceLoader::RegisterResourceFactory(std::shared_ptr fa mResourceTypes[typeName] = type; } - ResourceFactoryKey key = { resourceFormat : format, resourceType : type, resourceVersion : version }; + ResourceFactoryKey key = { format, type, version }; if (mFactories.contains(key)) { SPDLOG_ERROR("Failed to register resource factory: factory with key {}{}{} already exists", format, type, version); @@ -66,7 +66,7 @@ bool ResourceLoader::RegisterResourceFactory(std::shared_ptr fa } std::shared_ptr ResourceLoader::GetFactory(uint32_t format, uint32_t type, uint32_t version) { - ResourceFactoryKey key = { resourceFormat : format, resourceType : type, resourceVersion : version }; + ResourceFactoryKey key = { format, type, version }; if (!mFactories.contains(key)) { SPDLOG_ERROR("Could not find resource factory with key {}{}{}", format, type, version); return nullptr; From ab027b57627d76368764ec6bcb6dbb9a5a99aa29 Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Sat, 10 Feb 2024 19:37:33 -0500 Subject: [PATCH 22/25] back to naming things --- src/resource/ResourceLoader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/resource/ResourceLoader.cpp b/src/resource/ResourceLoader.cpp index 5001441dc..fce4a2e96 100644 --- a/src/resource/ResourceLoader.cpp +++ b/src/resource/ResourceLoader.cpp @@ -54,7 +54,7 @@ bool ResourceLoader::RegisterResourceFactory(std::shared_ptr fa mResourceTypes[typeName] = type; } - ResourceFactoryKey key = { format, type, version }; + ResourceFactoryKey key{ .resourceFormat = format, .resourceType = type, .resourceVersion = version }; if (mFactories.contains(key)) { SPDLOG_ERROR("Failed to register resource factory: factory with key {}{}{} already exists", format, type, version); @@ -66,7 +66,7 @@ bool ResourceLoader::RegisterResourceFactory(std::shared_ptr fa } std::shared_ptr ResourceLoader::GetFactory(uint32_t format, uint32_t type, uint32_t version) { - ResourceFactoryKey key = { format, type, version }; + ResourceFactoryKey key{ .resourceFormat = format, .resourceType = type, .resourceVersion = version }; if (!mFactories.contains(key)) { SPDLOG_ERROR("Could not find resource factory with key {}{}{}", format, type, version); return nullptr; From e6382dd04c72374a163f67b9d946cbaac5c8beb2 Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Mon, 12 Feb 2024 21:56:47 -0500 Subject: [PATCH 23/25] variant --- src/resource/File.h | 4 +-- src/resource/ResourceFactoryBinary.cpp | 3 +- src/resource/ResourceFactoryXML.cpp | 2 +- src/resource/archive/Archive.cpp | 17 ++++++----- src/resource/factory/ArrayFactory.cpp | 33 +++++++++++---------- src/resource/factory/BlobFactory.cpp | 5 ++-- src/resource/factory/DisplayListFactory.cpp | 16 +++++----- src/resource/factory/MatrixFactory.cpp | 3 +- src/resource/factory/TextureFactory.cpp | 30 ++++++++++--------- src/resource/factory/VertexFactory.cpp | 25 ++++++++-------- 10 files changed, 74 insertions(+), 64 deletions(-) diff --git a/src/resource/File.h b/src/resource/File.h index 2a9282834..0287a5aff 100644 --- a/src/resource/File.h +++ b/src/resource/File.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include @@ -28,8 +29,7 @@ struct File { std::shared_ptr Parent; std::shared_ptr InitData; std::shared_ptr> Buffer; - std::shared_ptr XmlDocument; - std::shared_ptr Reader; + std::variant, std::shared_ptr> Reader; bool IsLoaded = false; }; } // namespace LUS diff --git a/src/resource/ResourceFactoryBinary.cpp b/src/resource/ResourceFactoryBinary.cpp index 574fe4191..8ef2470c0 100644 --- a/src/resource/ResourceFactoryBinary.cpp +++ b/src/resource/ResourceFactoryBinary.cpp @@ -1,4 +1,5 @@ #include "ResourceFactoryBinary.h" +#include #include "spdlog/spdlog.h" namespace LUS { @@ -8,7 +9,7 @@ bool ResourceFactoryBinary::FileHasValidFormatAndReader(std::shared_ptr fi return false; } - if (file->Reader == nullptr) { + if (!std::holds_alternative>(file->Reader)) { SPDLOG_ERROR("Failed to load resource: File has Reader ({} - {})", file->InitData->Type, file->InitData->Path); return false; } diff --git a/src/resource/ResourceFactoryXML.cpp b/src/resource/ResourceFactoryXML.cpp index cae03d918..d1d978dd6 100644 --- a/src/resource/ResourceFactoryXML.cpp +++ b/src/resource/ResourceFactoryXML.cpp @@ -8,7 +8,7 @@ bool ResourceFactoryXML::FileHasValidFormatAndReader(std::shared_ptr file) return false; } - if (file->XmlDocument == nullptr) { + if (!std::holds_alternative>(file->Reader)) { SPDLOG_ERROR("Failed to load resource: File has no XML document ({} - {})", file->InitData->Type, file->InitData->Path); return false; diff --git a/src/resource/archive/Archive.cpp b/src/resource/archive/Archive.cpp index af4ae976f..ff25612da 100644 --- a/src/resource/archive/Archive.cpp +++ b/src/resource/archive/Archive.cpp @@ -114,14 +114,16 @@ std::shared_ptr Archive::LoadFile(const std::string& filePath) { // File is XML // Read the xml document auto stream = std::make_shared(fileToLoad->Buffer); - auto reader = fileToLoad->Reader = std::make_shared(stream); - fileToLoad->XmlDocument = std::make_shared(); - fileToLoad->XmlDocument->Parse(reader->ReadCString().data()); - if (fileToLoad->XmlDocument->Error()) { - SPDLOG_ERROR("Failed to parse XML file {}. Error: {}", filePath, fileToLoad->XmlDocument->ErrorStr()); + auto binaryReader = std::make_shared(stream); + fileToLoad->Reader = std::make_shared(); + auto xmlReader = std::get>(fileToLoad->Reader); + + xmlReader->Parse(binaryReader->ReadCString().data()); + if (xmlReader->Error()) { + SPDLOG_ERROR("Failed to parse XML file {}. Error: {}", filePath, xmlReader->ErrorStr()); return nullptr; } - fileToLoad->InitData = ReadResourceInitDataXml(filePath, fileToLoad->XmlDocument); + fileToLoad->InitData = ReadResourceInitDataXml(filePath, xmlReader); } else { // File is Binary auto fileToLoadMeta = LoadFileMeta(filePath); @@ -155,7 +157,8 @@ std::shared_ptr Archive::LoadFile(const std::string& filePath) { fileToLoad->Reader = std::make_shared(stream); fileToLoad->InitData = fileToLoadMeta; - fileToLoad->Reader->SetEndianness(fileToLoad->InitData->ByteOrder); + auto binaryReader = std::get>(fileToLoad->Reader); + binaryReader->SetEndianness(fileToLoad->InitData->ByteOrder); } return fileToLoad; diff --git a/src/resource/factory/ArrayFactory.cpp b/src/resource/factory/ArrayFactory.cpp index 1260ae209..9db2aae66 100644 --- a/src/resource/factory/ArrayFactory.cpp +++ b/src/resource/factory/ArrayFactory.cpp @@ -9,32 +9,33 @@ std::shared_ptr ResourceFactoryBinaryArrayV0::ReadResource(std::share } auto array = std::make_shared(file->InitData); + auto reader = std::get>(file->Reader); - array->ArrayType = (ArrayResourceType)file->Reader->ReadUInt32(); - array->ArrayCount = file->Reader->ReadUInt32(); + array->ArrayType = (ArrayResourceType)reader->ReadUInt32(); + array->ArrayCount = reader->ReadUInt32(); for (uint32_t i = 0; i < array->ArrayCount; i++) { if (array->ArrayType == ArrayResourceType::Vertex) { // OTRTODO: Implement Vertex arrays as just a vertex resource. Vtx data; - data.v.ob[0] = file->Reader->ReadInt16(); - data.v.ob[1] = file->Reader->ReadInt16(); - data.v.ob[2] = file->Reader->ReadInt16(); - data.v.flag = file->Reader->ReadUInt16(); - data.v.tc[0] = file->Reader->ReadInt16(); - data.v.tc[1] = file->Reader->ReadInt16(); - data.v.cn[0] = file->Reader->ReadUByte(); - data.v.cn[1] = file->Reader->ReadUByte(); - data.v.cn[2] = file->Reader->ReadUByte(); - data.v.cn[3] = file->Reader->ReadUByte(); + data.v.ob[0] = reader->ReadInt16(); + data.v.ob[1] = reader->ReadInt16(); + data.v.ob[2] = reader->ReadInt16(); + data.v.flag = reader->ReadUInt16(); + data.v.tc[0] = reader->ReadInt16(); + data.v.tc[1] = reader->ReadInt16(); + data.v.cn[0] = reader->ReadUByte(); + data.v.cn[1] = reader->ReadUByte(); + data.v.cn[2] = reader->ReadUByte(); + data.v.cn[3] = reader->ReadUByte(); array->Vertices.push_back(data); } else { - array->ArrayScalarType = (ScalarType)file->Reader->ReadUInt32(); + array->ArrayScalarType = (ScalarType)reader->ReadUInt32(); int iter = 1; if (array->ArrayType == ArrayResourceType::Vector) { - iter = file->Reader->ReadUInt32(); + iter = reader->ReadUInt32(); } for (int k = 0; k < iter; k++) { @@ -42,10 +43,10 @@ std::shared_ptr ResourceFactoryBinaryArrayV0::ReadResource(std::share switch (array->ArrayScalarType) { case ScalarType::ZSCALAR_S16: - data.s16 = file->Reader->ReadInt16(); + data.s16 = reader->ReadInt16(); break; case ScalarType::ZSCALAR_U16: - data.u16 = file->Reader->ReadUInt16(); + data.u16 = reader->ReadUInt16(); break; default: // OTRTODO: IMPLEMENT OTHER TYPES! diff --git a/src/resource/factory/BlobFactory.cpp b/src/resource/factory/BlobFactory.cpp index 52b9c7acd..b1c79167a 100644 --- a/src/resource/factory/BlobFactory.cpp +++ b/src/resource/factory/BlobFactory.cpp @@ -9,13 +9,14 @@ std::shared_ptr ResourceFactoryBinaryBlobV0::ReadResource(std::shared } auto blob = std::make_shared(file->InitData); + auto reader = std::get>(file->Reader); - uint32_t dataSize = file->Reader->ReadUInt32(); + uint32_t dataSize = reader->ReadUInt32(); blob->Data.reserve(dataSize); for (uint32_t i = 0; i < dataSize; i++) { - blob->Data.push_back(file->Reader->ReadUByte()); + blob->Data.push_back(reader->ReadUByte()); } return blob; diff --git a/src/resource/factory/DisplayListFactory.cpp b/src/resource/factory/DisplayListFactory.cpp index e72b20048..dd0d8fa19 100644 --- a/src/resource/factory/DisplayListFactory.cpp +++ b/src/resource/factory/DisplayListFactory.cpp @@ -134,15 +134,16 @@ std::shared_ptr ResourceFactoryBinaryDisplayListV0::ReadResource(std: } auto displayList = std::make_shared(file->InitData); + auto reader = std::get>(file->Reader); - while (file->Reader->GetBaseAddress() % 8 != 0) { - file->Reader->ReadInt8(); + while (reader->GetBaseAddress() % 8 != 0) { + reader->ReadInt8(); } while (true) { Gfx command; - command.words.w0 = file->Reader->ReadUInt32(); - command.words.w1 = file->Reader->ReadUInt32(); + command.words.w0 = reader->ReadUInt32(); + command.words.w1 = reader->ReadUInt32(); displayList->Instructions.push_back(command); @@ -151,8 +152,8 @@ std::shared_ptr ResourceFactoryBinaryDisplayListV0::ReadResource(std: // These are 128-bit commands, so read an extra 64 bits... if (opcode == G_SETTIMG_OTR_HASH || opcode == G_DL_OTR_HASH || opcode == G_VTX_OTR_HASH || opcode == G_BRANCH_Z_OTR || opcode == G_MARKER || opcode == G_MTX_OTR) { - command.words.w0 = file->Reader->ReadUInt32(); - command.words.w1 = file->Reader->ReadUInt32(); + command.words.w0 = reader->ReadUInt32(); + command.words.w1 = reader->ReadUInt32(); displayList->Instructions.push_back(command); } @@ -171,8 +172,7 @@ std::shared_ptr ResourceFactoryXMLDisplayListV0::ReadResource(std::sh } auto dl = std::make_shared(file->InitData); - - auto child = file->XmlDocument->FirstChildElement()->FirstChildElement(); + auto child = std::get>(file->Reader)->FirstChildElement()->FirstChildElement(); while (child != nullptr) { std::string childName = child->Name(); diff --git a/src/resource/factory/MatrixFactory.cpp b/src/resource/factory/MatrixFactory.cpp index 025e8258b..b7a84f1ed 100644 --- a/src/resource/factory/MatrixFactory.cpp +++ b/src/resource/factory/MatrixFactory.cpp @@ -9,10 +9,11 @@ std::shared_ptr ResourceFactoryBinaryMatrixV0::ReadResource(std::shar } auto matrix = std::make_shared(file->InitData); + auto reader = std::get>(file->Reader); for (size_t i = 0; i < 4; i++) { for (size_t j = 0; j < 4; j++) { - matrix->Matrx.m[i][j] = file->Reader->ReadInt32(); + matrix->Matrx.m[i][j] = reader->ReadInt32(); } } diff --git a/src/resource/factory/TextureFactory.cpp b/src/resource/factory/TextureFactory.cpp index b6cc6a71f..991805477 100644 --- a/src/resource/factory/TextureFactory.cpp +++ b/src/resource/factory/TextureFactory.cpp @@ -10,14 +10,15 @@ std::shared_ptr ResourceFactoryBinaryTextureV0::ReadResource(std::sha } auto texture = std::make_shared(file->InitData); + auto reader = std::get>(file->Reader); - texture->Type = (TextureType)file->Reader->ReadUInt32(); - texture->Width = file->Reader->ReadUInt32(); - texture->Height = file->Reader->ReadUInt32(); - texture->ImageDataSize = file->Reader->ReadUInt32(); + texture->Type = (TextureType)reader->ReadUInt32(); + texture->Width = reader->ReadUInt32(); + texture->Height = reader->ReadUInt32(); + texture->ImageDataSize = reader->ReadUInt32(); texture->ImageData = new uint8_t[texture->ImageDataSize]; - file->Reader->Read((char*)texture->ImageData, texture->ImageDataSize); + reader->Read((char*)texture->ImageData, texture->ImageDataSize); return texture; } @@ -28,17 +29,18 @@ std::shared_ptr ResourceFactoryBinaryTextureV1::ReadResource(std::sha } auto texture = std::make_shared(file->InitData); - - texture->Type = (TextureType)file->Reader->ReadUInt32(); - texture->Width = file->Reader->ReadUInt32(); - texture->Height = file->Reader->ReadUInt32(); - texture->Flags = file->Reader->ReadUInt32(); - texture->HByteScale = file->Reader->ReadFloat(); - texture->VPixelScale = file->Reader->ReadFloat(); - texture->ImageDataSize = file->Reader->ReadUInt32(); + auto reader = std::get>(file->Reader); + + texture->Type = (TextureType)reader->ReadUInt32(); + texture->Width = reader->ReadUInt32(); + texture->Height = reader->ReadUInt32(); + texture->Flags = reader->ReadUInt32(); + texture->HByteScale = reader->ReadFloat(); + texture->VPixelScale = reader->ReadFloat(); + texture->ImageDataSize = reader->ReadUInt32(); texture->ImageData = new uint8_t[texture->ImageDataSize]; - file->Reader->Read((char*)texture->ImageData, texture->ImageDataSize); + reader->Read((char*)texture->ImageData, texture->ImageDataSize); return texture; } diff --git a/src/resource/factory/VertexFactory.cpp b/src/resource/factory/VertexFactory.cpp index 3b914691a..c41ad7b09 100644 --- a/src/resource/factory/VertexFactory.cpp +++ b/src/resource/factory/VertexFactory.cpp @@ -9,22 +9,23 @@ std::shared_ptr ResourceFactoryBinaryVertexV0::ReadResource(std::shar } auto vertex = std::make_shared(file->InitData); + auto reader = std::get>(file->Reader); - uint32_t count = file->Reader->ReadUInt32(); + uint32_t count = reader->ReadUInt32(); vertex->VertexList.reserve(count); for (uint32_t i = 0; i < count; i++) { Vtx data; - data.v.ob[0] = file->Reader->ReadInt16(); - data.v.ob[1] = file->Reader->ReadInt16(); - data.v.ob[2] = file->Reader->ReadInt16(); - data.v.flag = file->Reader->ReadUInt16(); - data.v.tc[0] = file->Reader->ReadInt16(); - data.v.tc[1] = file->Reader->ReadInt16(); - data.v.cn[0] = file->Reader->ReadUByte(); - data.v.cn[1] = file->Reader->ReadUByte(); - data.v.cn[2] = file->Reader->ReadUByte(); - data.v.cn[3] = file->Reader->ReadUByte(); + data.v.ob[0] = reader->ReadInt16(); + data.v.ob[1] = reader->ReadInt16(); + data.v.ob[2] = reader->ReadInt16(); + data.v.flag = reader->ReadUInt16(); + data.v.tc[0] = reader->ReadInt16(); + data.v.tc[1] = reader->ReadInt16(); + data.v.cn[0] = reader->ReadUByte(); + data.v.cn[1] = reader->ReadUByte(); + data.v.cn[2] = reader->ReadUByte(); + data.v.cn[3] = reader->ReadUByte(); vertex->VertexList.push_back(data); } @@ -38,7 +39,7 @@ std::shared_ptr ResourceFactoryXMLVertexV0::ReadResource(std::shared_ auto vertex = std::make_shared(file->InitData); - auto child = file->XmlDocument->FirstChildElement()->FirstChildElement(); + auto child = std::get>(file->Reader)->FirstChildElement()->FirstChildElement(); while (child != nullptr) { std::string childName = child->Name(); From 37d5a9c9315bd750056c65b10ce7519b3c3d8132 Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Mon, 12 Feb 2024 21:58:58 -0500 Subject: [PATCH 24/25] clang format --- src/resource/factory/DisplayListFactory.cpp | 3 ++- src/resource/factory/VertexFactory.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/resource/factory/DisplayListFactory.cpp b/src/resource/factory/DisplayListFactory.cpp index dd0d8fa19..82e1455ec 100644 --- a/src/resource/factory/DisplayListFactory.cpp +++ b/src/resource/factory/DisplayListFactory.cpp @@ -172,7 +172,8 @@ std::shared_ptr ResourceFactoryXMLDisplayListV0::ReadResource(std::sh } auto dl = std::make_shared(file->InitData); - auto child = std::get>(file->Reader)->FirstChildElement()->FirstChildElement(); + auto child = + std::get>(file->Reader)->FirstChildElement()->FirstChildElement(); while (child != nullptr) { std::string childName = child->Name(); diff --git a/src/resource/factory/VertexFactory.cpp b/src/resource/factory/VertexFactory.cpp index c41ad7b09..c70b1cacd 100644 --- a/src/resource/factory/VertexFactory.cpp +++ b/src/resource/factory/VertexFactory.cpp @@ -39,7 +39,8 @@ std::shared_ptr ResourceFactoryXMLVertexV0::ReadResource(std::shared_ auto vertex = std::make_shared(file->InitData); - auto child = std::get>(file->Reader)->FirstChildElement()->FirstChildElement(); + auto child = + std::get>(file->Reader)->FirstChildElement()->FirstChildElement(); while (child != nullptr) { std::string childName = child->Name(); From 20e80b843156dae29c9f478c292d232a7373b1c8 Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Mon, 12 Feb 2024 22:06:22 -0500 Subject: [PATCH 25/25] newlines at end of file --- src/resource/ResourceFactoryBinary.cpp | 2 +- src/resource/ResourceFactoryXML.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/resource/ResourceFactoryBinary.cpp b/src/resource/ResourceFactoryBinary.cpp index 8ef2470c0..40ba8b2a3 100644 --- a/src/resource/ResourceFactoryBinary.cpp +++ b/src/resource/ResourceFactoryBinary.cpp @@ -16,4 +16,4 @@ bool ResourceFactoryBinary::FileHasValidFormatAndReader(std::shared_ptr fi return true; }; -} // namespace LUS \ No newline at end of file +} // namespace LUS diff --git a/src/resource/ResourceFactoryXML.cpp b/src/resource/ResourceFactoryXML.cpp index d1d978dd6..d3d622516 100644 --- a/src/resource/ResourceFactoryXML.cpp +++ b/src/resource/ResourceFactoryXML.cpp @@ -16,4 +16,4 @@ bool ResourceFactoryXML::FileHasValidFormatAndReader(std::shared_ptr file) return true; }; -} // namespace LUS \ No newline at end of file +} // namespace LUS