Add AssetLoader basis

This commit is contained in:
Jan
2021-03-13 14:27:20 +01:00
parent 83080db991
commit a7860c7c76
34 changed files with 736 additions and 149 deletions

View File

@ -8,8 +8,7 @@
using namespace IW4;
const std::string GameAssetPoolIW4::ASSET_TYPE_INVALID = "invalid_asset";
const std::string GameAssetPoolIW4::ASSET_TYPE_NAMES[]
const char* GameAssetPoolIW4::ASSET_TYPE_NAMES[]
{
"physpreset",
"physcollmap",
@ -383,10 +382,15 @@ XAssetInfoGeneric* GameAssetPoolIW4::GetAsset(const asset_type_t type, std::stri
#undef CASE_GET_ASSET
}
const std::string& GameAssetPoolIW4::GetAssetTypeName(const asset_type_t assetType) const
const char* GameAssetPoolIW4::AssetTypeNameByType(asset_type_t assetType)
{
if (assetType >= 0 && assetType < static_cast<int>(std::extent<decltype(ASSET_TYPE_NAMES)>::value))
return ASSET_TYPE_NAMES[assetType];
return ASSET_TYPE_INVALID;
}
const char* GameAssetPoolIW4::GetAssetTypeName(const asset_type_t assetType) const
{
return AssetTypeNameByType(assetType);
}

View File

@ -10,8 +10,8 @@ class GameAssetPoolIW4 final : public ZoneAssetPools
{
int m_priority;
static const std::string ASSET_TYPE_INVALID;
static const std::string ASSET_TYPE_NAMES[];
static constexpr const char* ASSET_TYPE_INVALID = "invalid_asset_type";
static const char* ASSET_TYPE_NAMES[];
protected:
XAssetInfoGeneric* AddAssetToPool(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*>& dependencies) override;
@ -60,5 +60,6 @@ public:
void InitPoolDynamic(asset_type_t type) override;
XAssetInfoGeneric* GetAsset(asset_type_t type, std::string name) const override;
const std::string& GetAssetTypeName(asset_type_t assetType) const override;
static const char* AssetTypeNameByType(asset_type_t assetType);
const char* GetAssetTypeName(asset_type_t assetType) const override;
};

View File

@ -8,8 +8,7 @@
using namespace T6;
const std::string GameAssetPoolT6::ASSET_TYPE_INVALID = "invalid_asset";
const std::string GameAssetPoolT6::ASSET_TYPE_NAMES[]
const char* GameAssetPoolT6::ASSET_TYPE_NAMES[]
{
"xmodelpieces",
"physpreset",
@ -478,10 +477,15 @@ XAssetInfoGeneric* GameAssetPoolT6::GetAsset(const asset_type_t type, std::strin
#undef CASE_GET_ASSET
}
const std::string& GameAssetPoolT6::GetAssetTypeName(const asset_type_t assetType) const
const char* GameAssetPoolT6::AssetTypeNameByType(asset_type_t assetType)
{
if (assetType >= 0 && assetType < static_cast<int>(std::extent<decltype(ASSET_TYPE_NAMES)>::value))
return ASSET_TYPE_NAMES[assetType];
return ASSET_TYPE_INVALID;
}
const char* GameAssetPoolT6::GetAssetTypeName(const asset_type_t assetType) const
{
return AssetTypeNameByType(assetType);
}

View File

@ -8,8 +8,8 @@ class GameAssetPoolT6 final : public ZoneAssetPools
{
int m_priority;
static const std::string ASSET_TYPE_INVALID;
static const std::string ASSET_TYPE_NAMES[];
static constexpr const char* ASSET_TYPE_INVALID = "invalid_asset_type";
static const char* ASSET_TYPE_NAMES[];
protected:
XAssetInfoGeneric* AddAssetToPool(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*>& dependencies) override;
@ -71,5 +71,6 @@ public:
void InitPoolDynamic(asset_type_t type) override;
XAssetInfoGeneric* GetAsset(asset_type_t type, std::string name) const override;
const std::string& GetAssetTypeName(asset_type_t assetType) const override;
static const char* AssetTypeNameByType(asset_type_t assetType);
const char* GetAssetTypeName(asset_type_t assetType) const override;
};

View File

@ -1,7 +1,7 @@
#pragma once
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cassert>
@ -25,7 +25,7 @@ class GlobalAssetPool
};
static std::vector<LinkedAssetPool*> m_linked_asset_pools;
static std::map<std::string, GameAssetPoolEntry> m_assets;
static std::unordered_map<std::string, GameAssetPoolEntry> m_assets;
static void SortLinkedAssetPools()
{
@ -159,10 +159,19 @@ public:
iAssetEntry = m_assets.erase(iAssetEntry);
}
}
static XAssetInfo<T>* GetAssetByName(const std::string& name)
{
const auto foundEntry = m_assets.find(name);
if (foundEntry == m_assets.end())
return nullptr;
return foundEntry->second.m_asset;
}
};
template<typename T>
std::vector<typename GlobalAssetPool<T>::LinkedAssetPool*> GlobalAssetPool<T>::m_linked_asset_pools = std::vector<LinkedAssetPool*>();
template<typename T>
std::map<std::string, typename GlobalAssetPool<T>::GameAssetPoolEntry> GlobalAssetPool<T>::m_assets = std::map<std::string, GameAssetPoolEntry>();
std::unordered_map<std::string, typename GlobalAssetPool<T>::GameAssetPoolEntry> GlobalAssetPool<T>::m_assets = std::unordered_map<std::string, GameAssetPoolEntry>();

View File

@ -9,7 +9,7 @@ class Zone;
class XAssetInfoGeneric
{
public:
int m_type = -1;
asset_type_t m_type = -1;
std::string m_name;
Zone* m_zone;
std::vector<XAssetInfoGeneric*> m_dependencies;

View File

@ -25,7 +25,7 @@ public:
XAssetInfoGeneric* AddAsset(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*>& dependencies);
virtual XAssetInfoGeneric* GetAsset(asset_type_t type, std::string name) const = 0;
virtual const std::string& GetAssetTypeName(asset_type_t assetType) const = 0;
virtual const char* GetAssetTypeName(asset_type_t assetType) const = 0;
virtual void InitPoolStatic(asset_type_t type, size_t capacity) = 0;
virtual void InitPoolDynamic(asset_type_t type) = 0;