mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-26 06:37:52 -05:00
chore: generalize default asset creators
This commit is contained in:
@ -3,6 +3,8 @@
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
IgnoredAssetLookup::IgnoredAssetLookup() = default;
|
||||
|
||||
IgnoredAssetLookup::IgnoredAssetLookup(const AssetList& assetList)
|
||||
{
|
||||
m_ignored_asset_lookup.reserve(assetList.m_entries.size());
|
||||
|
@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "AssetCreatorCollection.h"
|
||||
#include "AssetLoading/IZoneAssetLoaderState.h"
|
||||
#include "AssetRegistration.h"
|
||||
#include "Game/IAsset.h"
|
||||
@ -20,6 +19,7 @@ class AssetCreatorCollection;
|
||||
class IgnoredAssetLookup
|
||||
{
|
||||
public:
|
||||
IgnoredAssetLookup();
|
||||
explicit IgnoredAssetLookup(const AssetList& assetList);
|
||||
|
||||
[[nodiscard]] bool IsAssetIgnored(asset_type_t assetType, const std::string& name) const;
|
||||
@ -90,3 +90,5 @@ private:
|
||||
const IgnoredAssetLookup* m_ignored_asset_lookup;
|
||||
std::unordered_map<std::type_index, std::unique_ptr<IZoneAssetLoaderState>> m_zone_asset_loader_states;
|
||||
};
|
||||
|
||||
#include "AssetCreatorCollection.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "IAssetCreator.h"
|
||||
#include "AssetCreationResult.h"
|
||||
|
||||
AssetCreationResult AssetCreationResult::Success(XAssetInfoGeneric* assetInfo)
|
||||
{
|
22
src/ObjLoading/Asset/AssetCreationResult.h
Normal file
22
src/ObjLoading/Asset/AssetCreationResult.h
Normal file
@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "Pool/XAssetInfo.h"
|
||||
|
||||
class AssetCreationResult
|
||||
{
|
||||
public:
|
||||
static AssetCreationResult Success(XAssetInfoGeneric* assetInfo);
|
||||
static AssetCreationResult Failure();
|
||||
static AssetCreationResult NoAction();
|
||||
|
||||
[[nodiscard]] bool HasBeenSuccessful() const;
|
||||
[[nodiscard]] bool HasTakenAction() const;
|
||||
[[nodiscard]] bool HasFailed() const;
|
||||
[[nodiscard]] XAssetInfoGeneric* GetAssetInfo() const;
|
||||
|
||||
private:
|
||||
AssetCreationResult(bool takenAction, XAssetInfoGeneric* assetInfo);
|
||||
|
||||
bool m_taken_action;
|
||||
XAssetInfoGeneric* m_asset_info;
|
||||
};
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "AssetCreationContext.h"
|
||||
#include "AssetCreationResult.h"
|
||||
#include "Game/IAsset.h"
|
||||
#include "Pool/XAssetInfo.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
@ -10,25 +11,6 @@
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
class AssetCreationResult
|
||||
{
|
||||
public:
|
||||
static AssetCreationResult Success(XAssetInfoGeneric* assetInfo);
|
||||
static AssetCreationResult Failure();
|
||||
static AssetCreationResult NoAction();
|
||||
|
||||
[[nodiscard]] bool HasBeenSuccessful() const;
|
||||
[[nodiscard]] bool HasTakenAction() const;
|
||||
[[nodiscard]] bool HasFailed() const;
|
||||
[[nodiscard]] XAssetInfoGeneric* GetAssetInfo() const;
|
||||
|
||||
private:
|
||||
AssetCreationResult(bool takenAction, XAssetInfoGeneric* assetInfo);
|
||||
|
||||
bool m_taken_action;
|
||||
XAssetInfoGeneric* m_asset_info;
|
||||
};
|
||||
|
||||
class AssetCreationContext;
|
||||
|
||||
class IAssetCreator
|
||||
|
@ -1,16 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "AssetCreationContext.h"
|
||||
#include "AssetCreationResult.h"
|
||||
#include "Game/IAsset.h"
|
||||
#include "IAssetCreator.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
#include "Zone/ZoneTypes.h"
|
||||
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
class AssetCreationResult;
|
||||
class AssetCreationContext;
|
||||
|
||||
class IDefaultAssetCreator
|
||||
{
|
||||
public:
|
||||
@ -30,8 +29,24 @@ template<typename AssetType> class DefaultAssetCreator : public IDefaultAssetCre
|
||||
public:
|
||||
static_assert(std::is_base_of_v<IAssetBase, AssetType>);
|
||||
|
||||
DefaultAssetCreator(MemoryManager& memory)
|
||||
: m_memory(memory)
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] asset_type_t GetHandlingAssetType() const override
|
||||
{
|
||||
return AssetType::EnumEntry;
|
||||
}
|
||||
|
||||
AssetCreationResult CreateDefaultAsset(const std::string& assetName, AssetCreationContext& context) const override
|
||||
{
|
||||
auto* asset = m_memory.Alloc<typename AssetType::Type>();
|
||||
AssetNameAccessor<AssetType>{}(*asset) = m_memory.Dup(assetName.c_str());
|
||||
|
||||
return AssetCreationResult::Success(context.AddAsset<AssetType>(assetName, asset));
|
||||
}
|
||||
|
||||
private:
|
||||
MemoryManager& m_memory;
|
||||
};
|
||||
|
Reference in New Issue
Block a user