mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-26 06:37:52 -05:00
chore: refactor IW4 asset loaders
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
#include "AssetCreationContext.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
@ -51,6 +52,8 @@ void GenericAssetRegistration::AddIndirectAssetReference(IndirectAssetReference
|
||||
|
||||
std::unique_ptr<XAssetInfoGeneric> GenericAssetRegistration::CreateXAssetInfo()
|
||||
{
|
||||
assert(m_asset);
|
||||
|
||||
std::vector<XAssetInfoGeneric*> dependencies(m_dependencies.begin(), m_dependencies.end());
|
||||
std::vector<scr_string_t> scriptStrings(m_used_script_strings.begin(), m_used_script_strings.end());
|
||||
std::vector<IndirectAssetReference> indirectAssetReferences(m_indirect_asset_references.begin(), m_indirect_asset_references.end());
|
||||
|
@ -52,7 +52,7 @@ public:
|
||||
{
|
||||
static_assert(std::is_base_of_v<IAssetBase, AssetType>);
|
||||
|
||||
return static_cast<XAssetInfo<typename AssetType::Type>*>(LoadDependencyInternal(AssetType::EnumEntry, assetName));
|
||||
return static_cast<XAssetInfo<typename AssetType::Type>*>(LoadDependencyGeneric(AssetType::EnumEntry, assetName));
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* LoadDependencyGeneric(asset_type_t assetType, const std::string& assetName);
|
||||
@ -76,7 +76,7 @@ public:
|
||||
return dynamic_cast<T*>(foundEntry->second.get());
|
||||
|
||||
auto newState = std::make_unique<T>();
|
||||
newState->SetZone(&m_zone);
|
||||
newState->SetZone(m_zone);
|
||||
auto* newStatePtr = newState.get();
|
||||
m_zone_asset_loader_states.emplace(std::make_pair<std::type_index, std::unique_ptr<IZoneAssetLoaderState>>(typeid(T), std::move(newState)));
|
||||
return newStatePtr;
|
||||
|
@ -25,7 +25,7 @@ public:
|
||||
|
||||
std::unique_ptr<XAssetInfoGeneric> CreateXAssetInfo();
|
||||
|
||||
private:
|
||||
protected:
|
||||
asset_type_t m_type;
|
||||
std::string m_name;
|
||||
void* m_asset;
|
||||
@ -39,6 +39,11 @@ template<typename AssetType> class AssetRegistration : public GenericAssetRegist
|
||||
static_assert(std::is_base_of_v<IAssetBase, AssetType>);
|
||||
|
||||
public:
|
||||
AssetRegistration(std::string assetName)
|
||||
: GenericAssetRegistration(AssetType::EnumEntry, std::move(assetName), nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
AssetRegistration(std::string assetName, typename AssetType::Type* asset)
|
||||
: GenericAssetRegistration(AssetType::EnumEntry, std::move(assetName), asset)
|
||||
{
|
||||
@ -48,4 +53,9 @@ public:
|
||||
AssetRegistration(AssetRegistration&& other) = default;
|
||||
AssetRegistration& operator=(const AssetRegistration& other) = delete;
|
||||
AssetRegistration& operator=(AssetRegistration&& other) noexcept = default;
|
||||
|
||||
void SetAsset(typename AssetType::Type* asset)
|
||||
{
|
||||
m_asset = asset;
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user