Save scriptstrings per zone and not per asset since that solves all problems with multiple assets of the same zone referencing the same struct in memory that has scriptstring indices

This commit is contained in:
Jan
2020-10-23 15:54:27 +02:00
parent f8e7a10789
commit eed7164b5b
36 changed files with 387 additions and 447 deletions

View File

@ -1,9 +1,13 @@
#pragma once
#include "XAssetInfo.h"
#include <string>
#include <map>
#include "XAssetInfo.h"
#include "zone/Zone.h"
class Zone;
template<typename T>
class AssetPool
{
@ -43,7 +47,7 @@ public:
virtual ~AssetPool() = default;
virtual XAssetInfo<T>* AddAsset(std::string name, T* asset, std::vector<std::string>& scriptStrings, std::vector<XAssetInfoGeneric*>& dependencies) = 0;
virtual XAssetInfo<T>* AddAsset(std::string name, T* asset, Zone* zone, std::vector<XAssetInfoGeneric*>& dependencies) = 0;
XAssetInfo<T>* GetAsset(const std::string& name)
{

View File

@ -40,12 +40,12 @@ public:
m_asset_lookup.clear();
}
XAssetInfo<T>* AddAsset(std::string name, T* asset, std::vector<std::string>& scriptStrings, std::vector<XAssetInfoGeneric*>& dependencies) override
XAssetInfo<T>* AddAsset(std::string name, T* asset, Zone* zone, 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_zone = zone;
newInfo->m_dependencies = std::move(dependencies);
T* newAsset = new T();

View File

@ -81,7 +81,7 @@ public:
m_capacity = 0;
}
XAssetInfo<T>* AddAsset(std::string name, T* asset, std::vector<std::string>& scriptStrings, std::vector<XAssetInfoGeneric*>& dependencies) override
XAssetInfo<T>* AddAsset(std::string name, T* asset, Zone* zone, std::vector<XAssetInfoGeneric*>& dependencies) override
{
if(m_free == nullptr)
{
@ -96,7 +96,7 @@ public:
poolSlot->m_info->m_type = m_type;
poolSlot->m_info->m_name = std::move(name);
poolSlot->m_info->m_ptr = &poolSlot->m_entry;
poolSlot->m_info->m_script_strings = std::move(scriptStrings);
poolSlot->m_info->m_zone = zone;
poolSlot->m_info->m_dependencies = std::move(dependencies);
m_asset_lookup[poolSlot->m_info->m_name] = poolSlot->m_info;

View File

@ -1,24 +0,0 @@
#pragma once
#include "XAssetInfo.h"
#include "Zone/ZoneTypes.h"
#include <vector>
#include <string>
class IZoneAssetPools
{
public:
using iterator = std::vector<XAssetInfoGeneric*>::const_iterator;
virtual ~IZoneAssetPools() = default;
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) const = 0;
virtual const std::string& 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;
virtual iterator begin() const = 0;
virtual iterator end() const = 0;
};

View File

@ -2,12 +2,16 @@
#include <vector>
#include <string>
#include "Zone/Zone.h"
class Zone;
class XAssetInfoGeneric
{
public:
int m_type = -1;
std::string m_name;
std::vector<std::string> m_script_strings;
Zone* m_zone;
std::vector<XAssetInfoGeneric*> m_dependencies;
void* m_ptr;
};

View File

@ -0,0 +1,27 @@
#include "ZoneAssetPools.h"
ZoneAssetPools::ZoneAssetPools(Zone* zone)
: m_zone(zone)
{
}
XAssetInfoGeneric* ZoneAssetPools::AddAsset(const asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*>& dependencies)
{
auto* assetInfo = AddAssetToPool(type, std::move(name), asset, dependencies);
if(assetInfo)
{
m_assets_in_order.push_back(assetInfo);
}
return assetInfo;
}
ZoneAssetPools::iterator ZoneAssetPools::begin() const
{
return m_assets_in_order.begin();
}
ZoneAssetPools::iterator ZoneAssetPools::end() const
{
return m_assets_in_order.end();
}

View File

@ -0,0 +1,35 @@
#pragma once
#include "XAssetInfo.h"
#include "Zone/ZoneTypes.h"
#include "Zone/Zone.h"
#include <vector>
#include <string>
class Zone;
class XAssetInfoGeneric;
class ZoneAssetPools
{
protected:
Zone* m_zone;
std::vector<XAssetInfoGeneric*> m_assets_in_order;
virtual XAssetInfoGeneric* AddAssetToPool(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*>& dependencies) = 0;
public:
using iterator = std::vector<XAssetInfoGeneric*>::const_iterator;
explicit ZoneAssetPools(Zone* zone);
virtual ~ZoneAssetPools() = default;
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 void InitPoolStatic(asset_type_t type, size_t capacity) = 0;
virtual void InitPoolDynamic(asset_type_t type) = 0;
iterator begin() const;
iterator end() const;
};