diff --git a/src/ObjLoading/Game/T6/ObjLoaderT6.cpp b/src/ObjLoading/Game/T6/ObjLoaderT6.cpp index cb804970..6abdaaab 100644 --- a/src/ObjLoading/Game/T6/ObjLoaderT6.cpp +++ b/src/ObjLoading/Game/T6/ObjLoaderT6.cpp @@ -43,6 +43,7 @@ #include "ZBarrier/GdtLoaderZBarrierT6.h" #include "ZBarrier/RawLoaderZBarrierT6.h" #include "CustomMap/LoaderCustomMapT6.h" +#include "TechniqueSet/LoaderTechniqueSetT6.h" #include #include @@ -393,7 +394,7 @@ namespace T6 // collection.AddAssetCreator(std::make_unique(memory)); collection.AddAssetCreator(xmodel::CreateLoaderT6(memory, searchPath, zone)); collection.AddAssetCreator(material::CreateLoaderT6(memory, searchPath)); - // collection.AddAssetCreator(std::make_unique(memory)); + collection.AddAssetCreator(technique_set::CreateLoaderT6(memory, searchPath)); collection.AddAssetCreator(image::CreateLoaderT6(memory, searchPath)); collection.AddAssetCreator(sound::CreateSoundBankLoaderT6(memory, searchPath)); // collection.AddAssetCreator(std::make_unique(memory)); diff --git a/src/ObjLoading/Game/T6/TechniqueSet/LoaderTechniqueSetT6.cpp b/src/ObjLoading/Game/T6/TechniqueSet/LoaderTechniqueSetT6.cpp index b2e97370..a0e9501c 100644 --- a/src/ObjLoading/Game/T6/TechniqueSet/LoaderTechniqueSetT6.cpp +++ b/src/ObjLoading/Game/T6/TechniqueSet/LoaderTechniqueSetT6.cpp @@ -175,10 +175,10 @@ namespace }; } // namespace -namespace T6 +namespace technique_set { - std::unique_ptr> CreateTechniqueSetLoader(MemoryManager& memory, ISearchPath& searchPath) + std::unique_ptr> CreateLoaderT6(MemoryManager& memory, ISearchPath& searchPath) { return std::make_unique(memory, searchPath); } -} // namespace T6 +} // namespace technique_set diff --git a/src/ObjLoading/Game/T6/TechniqueSet/LoaderTechniqueSetT6.h b/src/ObjLoading/Game/T6/TechniqueSet/LoaderTechniqueSetT6.h index 78081a86..35b2b710 100644 --- a/src/ObjLoading/Game/T6/TechniqueSet/LoaderTechniqueSetT6.h +++ b/src/ObjLoading/Game/T6/TechniqueSet/LoaderTechniqueSetT6.h @@ -7,7 +7,7 @@ #include -namespace T6 +namespace technique_set { - std::unique_ptr> CreateTechniqueSetLoader(MemoryManager& memory, ISearchPath& searchPath); -} // namespace T6 + std::unique_ptr> CreateLoaderT6(MemoryManager& memory, ISearchPath& searchPath); +} // namespace technique_set diff --git a/src/ObjLoading/Material/JsonMaterialLoader.cpp.template b/src/ObjLoading/Material/JsonMaterialLoader.cpp.template index 248d12cc..cf8a6b49 100644 --- a/src/ObjLoading/Material/JsonMaterialLoader.cpp.template +++ b/src/ObjLoading/Material/JsonMaterialLoader.cpp.template @@ -52,50 +52,39 @@ namespace class JsonLoader { public: - JsonLoader(std::istream& stream, MemoryManager& memory, AssetCreationContext& context, AssetRegistration& registration) - : m_stream(stream), - m_memory(memory), + JsonLoader(MemoryManager& memory, AssetCreationContext& context, AssetRegistration& registration) + : m_memory(memory), m_context(context), m_registration(registration) { } - bool Load(Material& material) const + bool Load(json& jRoot, Material& material) const { - try - { - const auto jRoot = json::parse(m_stream); - std::string type; - unsigned version; - - jRoot.at("_type").get_to(type); - jRoot.at("_version").get_to(version); - - if (type != "material" || version != 1u) - { - con::error("Tried to load material \"{}\" but did not find expected type material of version 1", material.info.name); - return false; - } + std::string type; + unsigned version; + + jRoot.at("_type").get_to(type); + jRoot.at("_version").get_to(version); + + if (type != "material" || version != 1u) + { + con::error("Tried to load material \"{}\" but did not find expected type material of version 1", material.info.name); + return false; + } #ifndef FEATURE_T6 // T6 did not have this check in version 1, so to stay backwards compatible, let it stay that way - std::string game; - jRoot.at("_game").get_to(game); - if (game != GAME_LOWER) - { - con::error("Tried to load material \"{}\" but \"_game\" did not find expected type value {}", material.info.name, GAME_LOWER); - return false; - } + std::string game; + jRoot.at("_game").get_to(game); + if (game != GAME_LOWER) + { + con::error("Tried to load material \"{}\" but \"_game\" did not find expected type value {}", material.info.name, GAME_LOWER); + return false; + } #endif - const auto jMaterial = jRoot.get(); - return CreateMaterialFromJson(jMaterial, material); - } - catch (const json::exception& e) - { - con::error("Failed to parse json of material: {}", e.what()); - } - - return false; + const auto jMaterial = jRoot.get(); + return CreateMaterialFromJson(jMaterial, material); } private: @@ -519,7 +508,6 @@ namespace return true; } - std::istream& m_stream; MemoryManager& m_memory; AssetCreationContext& m_context; AssetRegistration& m_registration; @@ -529,10 +517,28 @@ namespace namespace GAME { bool LoadMaterialAsJson( - std::istream& stream, Material& material, MemoryManager& memory, AssetCreationContext& context, AssetRegistration& registration) - { - const JsonLoader loader(stream, memory, context, registration); - - return loader.Load(material); - } + std::istream& stream, Material& material, MemoryManager& memory, AssetCreationContext& context, AssetRegistration& registration) + { + const JsonLoader loader(memory, context, registration); + + try + { + auto jRoot = json::parse(stream); + + return loader.Load(jRoot, material); + } + catch (const json::exception& e) + { + con::error("Failed to parse json of material: {}", e.what()); + return false; + } + } + + bool LoadMaterialAsJson( + json& json, Material& material, MemoryManager& memory, AssetCreationContext& context, AssetRegistration& registration) + { + const JsonLoader loader(memory, context, registration); + + return loader.Load(json, material); + } } // namespace GAME