ZoneLoading: Properly link assets as dependencies instead of only saving the name of the dependency

This commit is contained in:
Jan
2020-02-18 13:16:39 +01:00
parent 246d74992c
commit 992e9cea30
16 changed files with 159 additions and 61 deletions

View File

@ -43,7 +43,7 @@ public:
virtual ~AssetPool() = default;
virtual XAssetInfo<T>* AddAsset(std::string name, T* asset, std::vector<std::string>& scriptStrings, std::vector<XAssetDependency>& dependencies) = 0;
virtual XAssetInfo<T>* AddAsset(std::string name, T* asset, std::vector<std::string>& scriptStrings, std::vector<XAssetInfoGeneric*>& dependencies) = 0;
XAssetInfo<T>* GetAsset(const std::string& name)
{

View File

@ -12,11 +12,13 @@ class AssetPoolDynamic final : public AssetPool<T>
using AssetPool<T>::m_asset_lookup;
std::vector<XAssetInfo<T>*> m_assets;
asset_type_t m_type;
public:
explicit AssetPoolDynamic(const int priority)
AssetPoolDynamic(const int priority, const asset_type_t type)
{
GlobalAssetPool<T>::LinkAssetPool(this, priority);
m_type = type;
}
AssetPoolDynamic(AssetPoolDynamic<T>&) = delete;
@ -30,7 +32,7 @@ public:
for(auto* entry : m_assets)
{
delete entry->m_asset;
delete entry->m_ptr;
delete entry;
}
@ -38,16 +40,17 @@ public:
m_asset_lookup.clear();
}
XAssetInfo<T>* AddAsset(std::string name, T* asset, std::vector<std::string>& scriptStrings, std::vector<XAssetDependency>& dependencies) override
XAssetInfo<T>* AddAsset(std::string name, T* asset, std::vector<std::string>& scriptStrings, std::vector<XAssetInfoGeneric*>& dependencies) override
{
auto* newInfo = new XAssetInfo<T>();
newInfo->m_type = m_type;
newInfo->m_name = std::move(name);
newInfo->m_script_strings = std::move(scriptStrings);
newInfo->m_dependencies = std::move(dependencies);
T* newAsset = new T();
memcpy(newAsset, asset, sizeof(T));
newInfo->m_asset = newAsset;
newInfo->m_ptr = newAsset;
m_assets.push_back(newInfo);
m_asset_lookup[newInfo->m_name] = newInfo;

View File

@ -2,6 +2,7 @@
#include "GlobalAssetPool.h"
#include "AssetPool.h"
#include "XAssetInfo.h"
#include <cstring>
@ -25,9 +26,10 @@ class AssetPoolStatic final : public AssetPool<T>
AssetPoolEntry* m_pool;
XAssetInfo<T>* m_info_pool;
size_t m_capacity;
asset_type_t m_type;
public:
AssetPoolStatic(const size_t capacity, const int priority)
AssetPoolStatic(const size_t capacity, const int priority, asset_type_t type)
{
m_capacity = capacity;
@ -78,7 +80,7 @@ public:
m_capacity = 0;
}
XAssetInfo<T>* AddAsset(std::string name, T* asset, std::vector<std::string>& scriptStrings, std::vector<XAssetDependency>& dependencies) override
XAssetInfo<T>* AddAsset(std::string name, T* asset, std::vector<std::string>& scriptStrings, std::vector<XAssetInfoGeneric*>& dependencies) override
{
if(m_free == nullptr)
{
@ -90,8 +92,9 @@ public:
memcpy(&poolSlot->m_entry, asset, sizeof(T));
poolSlot->m_info->m_type = m_type;
poolSlot->m_info->m_name = std::move(name);
poolSlot->m_info->m_asset = &poolSlot->m_entry;
poolSlot->m_info->m_ptr = &poolSlot->m_entry;
poolSlot->m_info->m_script_strings = std::move(scriptStrings);
poolSlot->m_info->m_dependencies = std::move(dependencies);

View File

@ -3,13 +3,16 @@
#include "XAssetInfo.h"
#include "Zone/ZoneTypes.h"
#include "Zone/ZoneContent.h"
#include <vector>
#include <string>
class IZoneAssetPools
{
public:
virtual ~IZoneAssetPools() = default;
virtual void* AddAsset(asset_type_t type, std::string name, void* asset, std::vector<std::string>& scriptStrings, std::vector<XAssetDependency>& dependencies) = 0;
virtual XAssetInfoGeneric* AddAsset(asset_type_t type, std::string name, void* asset, std::vector<std::string>& scriptStrings, std::vector<XAssetInfoGeneric*>& dependencies) = 0;
virtual XAssetInfoGeneric* GetAsset(asset_type_t type, std::string name) = 0;
virtual void InitPoolStatic(asset_type_t type, size_t capacity) = 0;
virtual void InitPoolDynamic(asset_type_t type) = 0;
virtual ZoneContent GetContent() const = 0;

View File

@ -1,13 +1,23 @@
#pragma once
#include <vector>
#include "Zone/XAssetDependency.h"
#include <string>
template<typename T>
class XAssetInfo
class XAssetInfoGeneric
{
public:
int m_type = -1;
std::string m_name;
T* m_asset;
std::vector<std::string> m_script_strings;
std::vector<XAssetDependency> m_dependencies;
std::vector<XAssetInfoGeneric*> m_dependencies;
void* m_ptr;
};
template<typename T>
class XAssetInfo : public XAssetInfoGeneric
{
public:
T* Asset()
{
return static_cast<T*>(m_ptr);
}
};