mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-10 23:08:05 -05:00
Add asset loading states per zone for the usecase of saving loaded menus and menu functions
This commit is contained in:
@ -1,8 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
#include <typeindex>
|
||||
#include <type_traits>
|
||||
|
||||
#include "IGdtQueryable.h"
|
||||
#include "IZoneAssetLoaderState.h"
|
||||
#include "Obj/Gdt/Gdt.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
#include "Zone/Zone.h"
|
||||
@ -10,6 +13,7 @@
|
||||
class AssetLoadingContext final : public IGdtQueryable
|
||||
{
|
||||
std::unordered_map<std::string, std::unordered_map<std::string, GdtEntry*>> m_entries_by_gdf_and_by_name;
|
||||
std::unordered_map<std::type_index, std::unique_ptr<IZoneAssetLoaderState>> m_zone_asset_loader_states;
|
||||
|
||||
void BuildGdtEntryCache();
|
||||
|
||||
@ -21,4 +25,20 @@ public:
|
||||
|
||||
AssetLoadingContext(Zone* zone, ISearchPath* rawSearchPath, std::vector<Gdt*> gdtFiles);
|
||||
GdtEntry* GetGdtEntryByGdfAndName(const std::string& gdfName, const std::string& entryName) override;
|
||||
|
||||
template<typename T>
|
||||
T* GetZoneAssetLoaderState()
|
||||
{
|
||||
static_assert(std::is_base_of_v<IZoneAssetLoaderState, T>, "T must inherit IZoneAssetLoaderState");
|
||||
// T must also have a public default constructor
|
||||
|
||||
const auto foundEntry = m_zone_asset_loader_states.find(typeid(T));
|
||||
if(foundEntry != m_zone_asset_loader_states.end())
|
||||
return dynamic_cast<T*>(foundEntry->second.get());
|
||||
|
||||
auto newState = std::make_unique<T>();
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
@ -13,6 +13,11 @@ bool AssetLoadingManager::LoadAssetFromLoader(const asset_type_t assetType, cons
|
||||
return LoadDependency(assetType, assetName) != nullptr;
|
||||
}
|
||||
|
||||
AssetLoadingContext* AssetLoadingManager::GetAssetLoadingContext() const
|
||||
{
|
||||
return &m_context;
|
||||
}
|
||||
|
||||
void AssetLoadingManager::AddAsset(const asset_type_t assetType, const std::string& assetName, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings,
|
||||
Zone* zone)
|
||||
{
|
||||
|
@ -20,6 +20,9 @@ public:
|
||||
AssetLoadingManager(const std::unordered_map<asset_type_t, std::unique_ptr<IAssetLoader>>& assetLoadersByType, AssetLoadingContext& context);
|
||||
|
||||
bool LoadAssetFromLoader(asset_type_t assetType, const std::string& assetName);
|
||||
|
||||
_NODISCARD AssetLoadingContext* GetAssetLoadingContext() const override;
|
||||
|
||||
void AddAsset(asset_type_t assetType, const std::string& assetName, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings) override;
|
||||
XAssetInfoGeneric* LoadDependency(asset_type_t assetType, const std::string& assetName) override;
|
||||
};
|
||||
|
@ -1,8 +1,10 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
#include "AssetLoadingContext.h"
|
||||
#include "Pool/XAssetInfo.h"
|
||||
#include "Zone/ZoneTypes.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
|
||||
class IAssetLoadingManager
|
||||
{
|
||||
@ -14,6 +16,8 @@ public:
|
||||
IAssetLoadingManager& operator=(const IAssetLoadingManager& other) = default;
|
||||
IAssetLoadingManager& operator=(IAssetLoadingManager&& other) noexcept = default;
|
||||
|
||||
_NODISCARD virtual AssetLoadingContext* GetAssetLoadingContext() const = 0;
|
||||
|
||||
virtual void AddAsset(asset_type_t assetType, const std::string& assetName, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings) = 0;
|
||||
void AddAsset(const asset_type_t assetType, const std::string& assetName, void* asset)
|
||||
{
|
||||
|
14
src/ObjLoading/AssetLoading/IZoneAssetLoaderState.h
Normal file
14
src/ObjLoading/AssetLoading/IZoneAssetLoaderState.h
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
class IZoneAssetLoaderState
|
||||
{
|
||||
protected:
|
||||
IZoneAssetLoaderState() = default;
|
||||
|
||||
public:
|
||||
virtual ~IZoneAssetLoaderState() = default;
|
||||
IZoneAssetLoaderState(const IZoneAssetLoaderState& other) = default;
|
||||
IZoneAssetLoaderState(IZoneAssetLoaderState&& other) noexcept = default;
|
||||
IZoneAssetLoaderState& operator=(const IZoneAssetLoaderState& other) = default;
|
||||
IZoneAssetLoaderState& operator=(IZoneAssetLoaderState&& other) noexcept = default;
|
||||
};
|
Reference in New Issue
Block a user