mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-29 08:07:52 -05:00
chore: rename ZoneAssetLoaderState to ZoneAssetCreationState
This commit is contained in:
@ -63,7 +63,7 @@ std::unique_ptr<XAssetInfoGeneric> GenericAssetRegistration::CreateXAssetInfo()
|
||||
}
|
||||
|
||||
AssetCreationContext::AssetCreationContext(Zone& zone, const AssetCreatorCollection* creators, const IgnoredAssetLookup* ignoredAssetLookup)
|
||||
: ZoneAssetLoaderContainer(zone),
|
||||
: ZoneAssetCreationStateContainer(zone),
|
||||
m_creators(creators),
|
||||
m_ignored_asset_lookup(ignoredAssetLookup)
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IZoneAssetLoaderState.h"
|
||||
#include "Asset/IZoneAssetCreationState.h"
|
||||
#include "AssetRegistration.h"
|
||||
#include "Game/IAsset.h"
|
||||
#include "Pool/XAssetInfo.h"
|
||||
@ -26,7 +26,7 @@ public:
|
||||
std::unordered_multimap<std::string, asset_type_t> m_ignored_asset_lookup;
|
||||
};
|
||||
|
||||
class AssetCreationContext : public ZoneAssetLoaderContainer
|
||||
class AssetCreationContext : public ZoneAssetCreationStateContainer
|
||||
{
|
||||
public:
|
||||
AssetCreationContext(Zone& zone, const AssetCreatorCollection* creators, const IgnoredAssetLookup* ignoredAssetLookup);
|
||||
|
57
src/ObjLoading/Asset/IZoneAssetCreationState.h
Normal file
57
src/ObjLoading/Asset/IZoneAssetCreationState.h
Normal file
@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include "Zone/Zone.h"
|
||||
|
||||
#include <memory>
|
||||
#include <typeindex>
|
||||
#include <unordered_map>
|
||||
|
||||
class IZoneAssetCreationState
|
||||
{
|
||||
protected:
|
||||
IZoneAssetCreationState() = default;
|
||||
|
||||
public:
|
||||
virtual ~IZoneAssetCreationState() = default;
|
||||
IZoneAssetCreationState(const IZoneAssetCreationState& other) = default;
|
||||
IZoneAssetCreationState(IZoneAssetCreationState&& other) noexcept = default;
|
||||
IZoneAssetCreationState& operator=(const IZoneAssetCreationState& other) = default;
|
||||
IZoneAssetCreationState& operator=(IZoneAssetCreationState&& other) noexcept = default;
|
||||
|
||||
virtual void SetZone(Zone* zone)
|
||||
{
|
||||
// Do nothing by default
|
||||
}
|
||||
};
|
||||
|
||||
class ZoneAssetCreationStateContainer
|
||||
{
|
||||
public:
|
||||
ZoneAssetCreationStateContainer(Zone& zone)
|
||||
: m_zone(zone)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T> T& GetZoneAssetCreationState()
|
||||
{
|
||||
static_assert(std::is_base_of_v<IZoneAssetCreationState, T>, "T must inherit IZoneAssetCreationState");
|
||||
// T must also have a public default constructor
|
||||
|
||||
const auto foundEntry = m_zone_asset_creation_states.find(typeid(T));
|
||||
if (foundEntry != m_zone_asset_creation_states.end())
|
||||
return *dynamic_cast<T*>(foundEntry->second.get());
|
||||
|
||||
auto newState = std::make_unique<T>();
|
||||
newState->SetZone(&m_zone);
|
||||
auto* newStatePtr = newState.get();
|
||||
m_zone_asset_creation_states.emplace(std::make_pair<std::type_index, std::unique_ptr<IZoneAssetCreationState>>(typeid(T), std::move(newState)));
|
||||
|
||||
return *newStatePtr;
|
||||
}
|
||||
|
||||
protected:
|
||||
Zone& m_zone;
|
||||
|
||||
private:
|
||||
std::unordered_map<std::type_index, std::unique_ptr<IZoneAssetCreationState>> m_zone_asset_creation_states;
|
||||
};
|
@ -1,57 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Zone/Zone.h"
|
||||
|
||||
#include <memory>
|
||||
#include <typeindex>
|
||||
#include <unordered_map>
|
||||
|
||||
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;
|
||||
|
||||
virtual void SetZone(Zone* zone)
|
||||
{
|
||||
// Do nothing by default
|
||||
}
|
||||
};
|
||||
|
||||
class ZoneAssetLoaderContainer
|
||||
{
|
||||
public:
|
||||
ZoneAssetLoaderContainer(Zone& zone)
|
||||
: m_zone(zone)
|
||||
{
|
||||
}
|
||||
|
||||
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>();
|
||||
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;
|
||||
}
|
||||
|
||||
protected:
|
||||
Zone& m_zone;
|
||||
|
||||
private:
|
||||
std::unordered_map<std::type_index, std::unique_ptr<IZoneAssetLoaderState>> m_zone_asset_loader_states;
|
||||
};
|
Reference in New Issue
Block a user