Add ZoneScriptString class to store zone script strings

This commit is contained in:
Jan 2021-03-18 16:55:30 +01:00
parent 8736280ea8
commit 2a6d7c84c2
33 changed files with 239 additions and 119 deletions

View File

@ -13,9 +13,17 @@ bool AssetLoadingManager::LoadAssetFromLoader(const asset_type_t assetType, cons
return LoadDependency(assetType, assetName) != nullptr;
}
void AssetLoadingManager::AddAsset(const asset_type_t assetType, const std::string& assetName, void* asset, std::vector<XAssetInfoGeneric*>& dependencies)
void AssetLoadingManager::AddAsset(const asset_type_t assetType, const std::string& assetName, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings,
Zone* zone)
{
m_last_dependency_loaded = m_context.m_zone->m_pools->AddAsset(assetType, assetName, asset, dependencies);
m_last_dependency_loaded = m_context.m_zone->m_pools->AddAsset(assetType, assetName, asset, std::move(dependencies), std::move(usedScriptStrings), zone);
if (m_last_dependency_loaded == nullptr)
std::cout << "Failed to add asset of type \"" << m_context.m_zone->m_pools->GetAssetTypeName(assetType) << "\" to pool: \"" << assetName << "\"" << std::endl;
}
void AssetLoadingManager::AddAsset(const asset_type_t assetType, const std::string& assetName, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings)
{
m_last_dependency_loaded = m_context.m_zone->m_pools->AddAsset(assetType, assetName, asset, std::move(dependencies), std::move(usedScriptStrings));
if (m_last_dependency_loaded == nullptr)
std::cout << "Failed to add asset of type \"" << m_context.m_zone->m_pools->GetAssetTypeName(assetType) << "\" to pool: \"" << assetName << "\"" << std::endl;
}
@ -29,8 +37,7 @@ XAssetInfoGeneric* AssetLoadingManager::LoadIgnoredDependency(const asset_type_t
auto* linkAsset = loader->CreateEmptyAsset(assetName, m_context.m_zone->GetMemory());
if (linkAsset)
{
std::vector<XAssetInfoGeneric*> dependencies;
AddAsset(assetType, assetName, linkAsset, dependencies);
AddAsset(assetType, assetName, linkAsset, std::vector<XAssetInfoGeneric*>(), std::vector<scr_string_t>());
auto* lastDependency = m_last_dependency_loaded;
m_last_dependency_loaded = nullptr;
return lastDependency;
@ -40,7 +47,7 @@ XAssetInfoGeneric* AssetLoadingManager::LoadIgnoredDependency(const asset_type_t
if (existingAsset)
{
std::vector<XAssetInfoGeneric*> dependencies;
AddAsset(existingAsset->m_type, existingAsset->m_name, existingAsset->m_ptr, dependencies);
AddAsset(existingAsset->m_type, existingAsset->m_name, existingAsset->m_ptr, std::vector<XAssetInfoGeneric*>(), std::vector<scr_string_t>(), existingAsset->m_zone);
auto* lastDependency = m_last_dependency_loaded;
m_last_dependency_loaded = nullptr;
return lastDependency;
@ -79,7 +86,7 @@ XAssetInfoGeneric* AssetLoadingManager::LoadAssetDependency(const asset_type_t a
return nullptr;
}
AddAsset(existingAsset->m_type, existingAsset->m_name, existingAsset->m_ptr, dependencies);
AddAsset(existingAsset->m_type, existingAsset->m_name, existingAsset->m_ptr, std::move(dependencies), existingAsset->m_used_script_strings, existingAsset->m_zone);
auto* lastDependency = m_last_dependency_loaded;
m_last_dependency_loaded = nullptr;
return lastDependency;
@ -99,7 +106,7 @@ XAssetInfoGeneric* AssetLoadingManager::LoadDependency(const asset_type_t assetT
if (loader != m_asset_loaders_by_type.end())
{
const auto ignoreEntry = m_context.m_ignored_asset_map.find(assetName);
if(ignoreEntry != m_context.m_ignored_asset_map.end() && ignoreEntry->second == assetType)
if (ignoreEntry != m_context.m_ignored_asset_map.end() && ignoreEntry->second == assetType)
{
const auto linkAssetName = ',' + assetName;

View File

@ -14,10 +14,12 @@ class AssetLoadingManager final : public IAssetLoadingManager
XAssetInfoGeneric* LoadIgnoredDependency(asset_type_t assetType, const std::string& assetName, IAssetLoader* loader);
XAssetInfoGeneric* LoadAssetDependency(asset_type_t assetType, const std::string& assetName, IAssetLoader* loader);
void AddAsset(asset_type_t assetType, const std::string& assetName, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings, Zone* zone);
public:
AssetLoadingManager(const std::unordered_map<asset_type_t, std::unique_ptr<IAssetLoader>>& assetLoadersByType, AssetLoadingContext& context);
bool LoadAssetFromLoader(asset_type_t assetType, const std::string& assetName);
void AddAsset(asset_type_t assetType, const std::string& assetName, void* asset, std::vector<XAssetInfoGeneric*>& dependencies) override;
void AddAsset(asset_type_t assetType, const std::string& assetName, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings) override;
XAssetInfoGeneric* LoadDependency(asset_type_t assetType, const std::string& assetName) override;
};

View File

@ -14,11 +14,10 @@ public:
IAssetLoadingManager& operator=(const IAssetLoadingManager& other) = default;
IAssetLoadingManager& operator=(IAssetLoadingManager&& other) noexcept = default;
virtual void AddAsset(asset_type_t assetType, const std::string& assetName, void* asset, std::vector<XAssetInfoGeneric*>& dependencies) = 0;
virtual void AddAsset(asset_type_t assetType, const std::string& assetName, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings) = 0;
void AddAsset(const asset_type_t assetType, const std::string& assetName, void* asset)
{
std::vector<XAssetInfoGeneric*> dependencies;
AddAsset(assetType, assetName, asset, dependencies);
AddAsset(assetType, assetName, asset, std::vector<XAssetInfoGeneric*>(), std::vector<scr_string_t>());
}
virtual XAssetInfoGeneric* LoadDependency(asset_type_t assetType, const std::string& assetName) = 0;
};

View File

@ -218,8 +218,8 @@ InfoString AssetDumperVehicle::CreateInfoString(XAssetInfo<VehicleDef>* asset)
{
InfoStringFromVehicleConverter converter(asset->Asset(), vehicle_fields, std::extent<decltype(vehicle_fields)>::value, [asset](const scr_string_t scrStr) -> std::string
{
assert(scrStr < asset->m_zone->m_script_strings.size());
if (scrStr >= asset->m_zone->m_script_strings.size())
assert(scrStr < asset->m_zone->m_script_strings.Count());
if (scrStr >= asset->m_zone->m_script_strings.Count())
return "";
return asset->m_zone->m_script_strings[scrStr];

View File

@ -998,8 +998,8 @@ InfoString AssetDumperWeapon::CreateInfoString(XAssetInfo<WeaponCompleteDef>* as
InfoStringFromWeaponConverter converter(fullDef.get(), weapon_fields, std::extent<decltype(weapon_fields)>::value, [asset](const scr_string_t scrStr) -> std::string
{
assert(scrStr < asset->m_zone->m_script_strings.size());
if (scrStr >= asset->m_zone->m_script_strings.size())
assert(scrStr < asset->m_zone->m_script_strings.Count());
if (scrStr >= asset->m_zone->m_script_strings.Count())
return "";
return asset->m_zone->m_script_strings[scrStr];

View File

@ -122,8 +122,8 @@ InfoString AssetDumperPhysConstraints::CreateInfoString(XAssetInfo<PhysConstrain
InfoStringFromPhysConstraintsConverter converter(asset->Asset(), phys_constraints_fields, std::extent<decltype(phys_constraints_fields)>::value, [asset](const scr_string_t scrStr) -> std::string
{
assert(scrStr < asset->m_zone->m_script_strings.size());
if (scrStr >= asset->m_zone->m_script_strings.size())
assert(scrStr < asset->m_zone->m_script_strings.Count());
if (scrStr >= asset->m_zone->m_script_strings.Count())
return "";
return asset->m_zone->m_script_strings[scrStr];

View File

@ -84,8 +84,8 @@ InfoString AssetDumperPhysPreset::CreateInfoString(XAssetInfo<PhysPreset>* asset
InfoStringFromPhysPresetConverter converter(physPresetInfo, physpreset_fields, std::extent<decltype(physpreset_fields)>::value, [asset](const scr_string_t scrStr) -> std::string
{
assert(scrStr < asset->m_zone->m_script_strings.size());
if (scrStr >= asset->m_zone->m_script_strings.size())
assert(scrStr < asset->m_zone->m_script_strings.Count());
if (scrStr >= asset->m_zone->m_script_strings.Count())
return "";
return asset->m_zone->m_script_strings[scrStr];

View File

@ -10,37 +10,37 @@ using namespace T6;
cspField_t AssetDumperTracer::tracer_fields[]
{
{ "type", offsetof(TracerDef, type), TFT_TRACERTYPE },
{ "material", offsetof(TracerDef, material), CSPFT_MATERIAL },
{ "drawInterval", offsetof(TracerDef, drawInterval), CSPFT_INT },
{ "speed", offsetof(TracerDef, speed), CSPFT_FLOAT },
{ "beamLength", offsetof(TracerDef, beamLength), CSPFT_FLOAT },
{ "beamWidth", offsetof(TracerDef, beamWidth), CSPFT_FLOAT },
{ "screwRadius", offsetof(TracerDef, screwRadius), CSPFT_FLOAT },
{ "screwDist", offsetof(TracerDef, screwDist), CSPFT_FLOAT },
{ "fadeTime", offsetof(TracerDef, fadeTime), CSPFT_FLOAT },
{ "fadeScale", offsetof(TracerDef, fadeScale), CSPFT_FLOAT },
{ "texRepeatRate", offsetof(TracerDef, texRepeatRate), CSPFT_FLOAT },
{ "colorR0", offsetof(TracerDef, colors[0].r), CSPFT_FLOAT },
{ "colorG0", offsetof(TracerDef, colors[0].g), CSPFT_FLOAT },
{ "colorB0", offsetof(TracerDef, colors[0].b), CSPFT_FLOAT },
{ "colorA0", offsetof(TracerDef, colors[0].a), CSPFT_FLOAT },
{ "colorR1", offsetof(TracerDef, colors[1].r), CSPFT_FLOAT },
{ "colorG1", offsetof(TracerDef, colors[1].g), CSPFT_FLOAT },
{ "colorB1", offsetof(TracerDef, colors[1].b), CSPFT_FLOAT },
{ "colorA1", offsetof(TracerDef, colors[1].a), CSPFT_FLOAT },
{ "colorR2", offsetof(TracerDef, colors[2].r), CSPFT_FLOAT },
{ "colorG2", offsetof(TracerDef, colors[2].g), CSPFT_FLOAT },
{ "colorB2", offsetof(TracerDef, colors[2].b), CSPFT_FLOAT },
{ "colorA2", offsetof(TracerDef, colors[2].a), CSPFT_FLOAT },
{ "colorR3", offsetof(TracerDef, colors[3].r), CSPFT_FLOAT },
{ "colorG3", offsetof(TracerDef, colors[3].g), CSPFT_FLOAT },
{ "colorB3", offsetof(TracerDef, colors[3].b), CSPFT_FLOAT },
{ "colorA3", offsetof(TracerDef, colors[3].a), CSPFT_FLOAT },
{ "colorR4", offsetof(TracerDef, colors[4].r), CSPFT_FLOAT },
{ "colorG4", offsetof(TracerDef, colors[4].g), CSPFT_FLOAT },
{ "colorB4", offsetof(TracerDef, colors[4].b), CSPFT_FLOAT },
{ "colorA4", offsetof(TracerDef, colors[4].a), CSPFT_FLOAT }
{"type", offsetof(TracerDef, type), TFT_TRACERTYPE},
{"material", offsetof(TracerDef, material), CSPFT_MATERIAL},
{"drawInterval", offsetof(TracerDef, drawInterval), CSPFT_INT},
{"speed", offsetof(TracerDef, speed), CSPFT_FLOAT},
{"beamLength", offsetof(TracerDef, beamLength), CSPFT_FLOAT},
{"beamWidth", offsetof(TracerDef, beamWidth), CSPFT_FLOAT},
{"screwRadius", offsetof(TracerDef, screwRadius), CSPFT_FLOAT},
{"screwDist", offsetof(TracerDef, screwDist), CSPFT_FLOAT},
{"fadeTime", offsetof(TracerDef, fadeTime), CSPFT_FLOAT},
{"fadeScale", offsetof(TracerDef, fadeScale), CSPFT_FLOAT},
{"texRepeatRate", offsetof(TracerDef, texRepeatRate), CSPFT_FLOAT},
{"colorR0", offsetof(TracerDef, colors[0].r), CSPFT_FLOAT},
{"colorG0", offsetof(TracerDef, colors[0].g), CSPFT_FLOAT},
{"colorB0", offsetof(TracerDef, colors[0].b), CSPFT_FLOAT},
{"colorA0", offsetof(TracerDef, colors[0].a), CSPFT_FLOAT},
{"colorR1", offsetof(TracerDef, colors[1].r), CSPFT_FLOAT},
{"colorG1", offsetof(TracerDef, colors[1].g), CSPFT_FLOAT},
{"colorB1", offsetof(TracerDef, colors[1].b), CSPFT_FLOAT},
{"colorA1", offsetof(TracerDef, colors[1].a), CSPFT_FLOAT},
{"colorR2", offsetof(TracerDef, colors[2].r), CSPFT_FLOAT},
{"colorG2", offsetof(TracerDef, colors[2].g), CSPFT_FLOAT},
{"colorB2", offsetof(TracerDef, colors[2].b), CSPFT_FLOAT},
{"colorA2", offsetof(TracerDef, colors[2].a), CSPFT_FLOAT},
{"colorR3", offsetof(TracerDef, colors[3].r), CSPFT_FLOAT},
{"colorG3", offsetof(TracerDef, colors[3].g), CSPFT_FLOAT},
{"colorB3", offsetof(TracerDef, colors[3].b), CSPFT_FLOAT},
{"colorA3", offsetof(TracerDef, colors[3].a), CSPFT_FLOAT},
{"colorR4", offsetof(TracerDef, colors[4].r), CSPFT_FLOAT},
{"colorG4", offsetof(TracerDef, colors[4].g), CSPFT_FLOAT},
{"colorB4", offsetof(TracerDef, colors[4].b), CSPFT_FLOAT},
{"colorA4", offsetof(TracerDef, colors[4].a), CSPFT_FLOAT}
};
namespace T6
@ -74,13 +74,13 @@ namespace T6
InfoString AssetDumperTracer::CreateInfoString(XAssetInfo<TracerDef>* asset)
{
InfoStringFromTracerConverter converter(asset->Asset(), tracer_fields, std::extent<decltype(tracer_fields)>::value, [asset](const scr_string_t scrStr) -> std::string
{
assert(scrStr < asset->m_zone->m_script_strings.size());
if (scrStr >= asset->m_zone->m_script_strings.size())
return "";
{
assert(scrStr < asset->m_zone->m_script_strings.Count());
if (scrStr >= asset->m_zone->m_script_strings.Count())
return "";
return asset->m_zone->m_script_strings[scrStr];
});
return asset->m_zone->m_script_strings[scrStr];
});
return converter.Convert();
}
@ -119,4 +119,4 @@ void AssetDumperTracer::DumpRaw(AssetDumpingContext& context, XAssetInfo<TracerD
const auto infoString = CreateInfoString(asset);
const auto stringValue = infoString.ToString("TRACER");
stream.write(stringValue.c_str(), stringValue.size());
}
}

View File

@ -646,13 +646,13 @@ namespace T6
InfoString AssetDumperVehicle::CreateInfoString(XAssetInfo<VehicleDef>* asset)
{
InfoStringFromVehicleConverter converter(asset->Asset(), vehicle_fields, std::extent<decltype(vehicle_fields)>::value, [asset](const scr_string_t scrStr) -> std::string
{
assert(scrStr < asset->m_zone->m_script_strings.size());
if (scrStr >= asset->m_zone->m_script_strings.size())
return "";
{
assert(scrStr < asset->m_zone->m_script_strings.Count());
if (scrStr >= asset->m_zone->m_script_strings.Count())
return "";
return asset->m_zone->m_script_strings[scrStr];
});
return asset->m_zone->m_script_strings[scrStr];
});
return converter.Convert();
}

View File

@ -1385,13 +1385,13 @@ InfoString AssetDumperWeapon::CreateInfoString(XAssetInfo<WeaponVariantDef>* ass
CopyToFullDef(asset->Asset(), fullDef.get());
InfoStringFromWeaponConverter converter(fullDef.get(), weapon_fields, std::extent<decltype(weapon_fields)>::value, [asset](const scr_string_t scrStr) -> std::string
{
assert(scrStr < asset->m_zone->m_script_strings.size());
if (scrStr >= asset->m_zone->m_script_strings.size())
return "";
{
assert(scrStr < asset->m_zone->m_script_strings.Count());
if (scrStr >= asset->m_zone->m_script_strings.Count())
return "";
return asset->m_zone->m_script_strings[scrStr];
});
return asset->m_zone->m_script_strings[scrStr];
});
return converter.Convert();
}

View File

@ -128,8 +128,8 @@ InfoString AssetDumperWeaponAttachment::CreateInfoString(XAssetInfo<WeaponAttach
{
InfoStringFromAttachmentConverter converter(asset->Asset(), attachment_fields, std::extent<decltype(attachment_fields)>::value, [asset](const scr_string_t scrStr) -> std::string
{
assert(scrStr < asset->m_zone->m_script_strings.size());
if (scrStr >= asset->m_zone->m_script_strings.size())
assert(scrStr < asset->m_zone->m_script_strings.Count());
if (scrStr >= asset->m_zone->m_script_strings.Count())
return "";
return asset->m_zone->m_script_strings[scrStr];

View File

@ -319,8 +319,8 @@ InfoString AssetDumperWeaponAttachmentUnique::CreateInfoString(XAssetInfo<Weapon
fullDef.get(), attachment_unique_fields, std::extent<decltype(attachment_unique_fields)>::value,
[asset](const scr_string_t scrStr) -> std::string
{
assert(scrStr < asset->m_zone->m_script_strings.size());
if (scrStr >= asset->m_zone->m_script_strings.size())
assert(scrStr < asset->m_zone->m_script_strings.Count());
if (scrStr >= asset->m_zone->m_script_strings.Count())
return "";
return asset->m_zone->m_script_strings[scrStr];

View File

@ -178,8 +178,8 @@ InfoString AssetDumperZBarrier::CreateInfoString(XAssetInfo<ZBarrierDef>* asset)
{
InfoStringFromZBarrierConverter converter(asset->Asset(), zbarrier_fields, std::extent<decltype(zbarrier_fields)>::value, [asset](const scr_string_t scrStr) -> std::string
{
assert(scrStr < asset->m_zone->m_script_strings.size());
if (scrStr >= asset->m_zone->m_script_strings.size())
assert(scrStr < asset->m_zone->m_script_strings.Count());
if (scrStr >= asset->m_zone->m_script_strings.Count())
return "";
return asset->m_zone->m_script_strings[scrStr];

View File

@ -260,7 +260,7 @@ void GameAssetPoolIW4::InitPoolDynamic(const asset_type_t type)
#undef CASE_INIT_POOL_STATIC
}
XAssetInfoGeneric* GameAssetPoolIW4::AddAssetToPool(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*>& dependencies)
XAssetInfoGeneric* GameAssetPoolIW4::AddAssetToPool(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings, Zone* zone)
{
XAsset xAsset{};
@ -271,7 +271,7 @@ XAssetInfoGeneric* GameAssetPoolIW4::AddAssetToPool(asset_type_t type, std::stri
case assetType: \
{ \
assert((poolName) != nullptr); \
return (poolName)->AddAsset(std::move(name), xAsset.header.headerName, m_zone, dependencies); \
return (poolName)->AddAsset(std::move(name), xAsset.header.headerName, zone, std::move(dependencies), std::move(usedScriptStrings)); \
}
switch (xAsset.type)

View File

@ -14,7 +14,7 @@ class GameAssetPoolIW4 final : public ZoneAssetPools
static const char* ASSET_TYPE_NAMES[];
protected:
XAssetInfoGeneric* AddAssetToPool(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*>& dependencies) override;
XAssetInfoGeneric* AddAssetToPool(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings, Zone* zone) override;
public:
std::unique_ptr<AssetPool<IW4::PhysPreset>> m_phys_preset;

View File

@ -329,7 +329,8 @@ void GameAssetPoolT6::InitPoolDynamic(const asset_type_t type)
#undef CASE_INIT_POOL_STATIC
}
XAssetInfoGeneric* GameAssetPoolT6::AddAssetToPool(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*>& dependencies)
XAssetInfoGeneric* GameAssetPoolT6::AddAssetToPool(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings,
Zone* zone)
{
XAsset xAsset{};
@ -340,7 +341,7 @@ XAssetInfoGeneric* GameAssetPoolT6::AddAssetToPool(asset_type_t type, std::strin
case assetType: \
{ \
assert((poolName) != nullptr); \
return (poolName)->AddAsset(std::move(name), xAsset.header.headerName, m_zone, dependencies); \
return (poolName)->AddAsset(std::move(name), xAsset.header.headerName, zone, std::move(dependencies), std::move(usedScriptStrings)); \
}
switch (xAsset.type)

View File

@ -12,7 +12,7 @@ class GameAssetPoolT6 final : public ZoneAssetPools
static const char* ASSET_TYPE_NAMES[];
protected:
XAssetInfoGeneric* AddAssetToPool(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*>& dependencies) override;
XAssetInfoGeneric* AddAssetToPool(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings, Zone* zone) override;
public:
AssetPool<T6::PhysPreset>* m_phys_preset;

View File

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

View File

@ -40,13 +40,14 @@ public:
m_asset_lookup.clear();
}
XAssetInfo<T>* AddAsset(std::string name, T* asset, Zone* zone, std::vector<XAssetInfoGeneric*>& dependencies) override
XAssetInfo<T>* AddAsset(std::string name, T* asset, Zone* zone, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings) override
{
auto* newInfo = new XAssetInfo<T>();
newInfo->m_type = m_type;
newInfo->m_name = std::move(name);
newInfo->m_zone = zone;
newInfo->m_dependencies = std::move(dependencies);
newInfo->m_used_script_strings = std::move(usedScriptStrings);
T* newAsset = new T();
memcpy(newAsset, asset, sizeof(T));

View File

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

View File

@ -13,6 +13,7 @@ public:
std::string m_name;
Zone* m_zone;
std::vector<XAssetInfoGeneric*> m_dependencies;
std::vector<scr_string_t> m_used_script_strings;
void* m_ptr;
};

View File

@ -5,10 +5,15 @@ ZoneAssetPools::ZoneAssetPools(Zone* zone)
{
}
XAssetInfoGeneric* ZoneAssetPools::AddAsset(const asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*>& dependencies)
XAssetInfoGeneric* ZoneAssetPools::AddAsset(const asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings)
{
auto* assetInfo = AddAssetToPool(type, std::move(name), asset, dependencies);
if(assetInfo)
return AddAsset(type, std::move(name), asset, std::move(dependencies), std::move(usedScriptStrings), m_zone);
}
XAssetInfoGeneric* ZoneAssetPools::AddAsset(const asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings, Zone* zone)
{
auto* assetInfo = AddAssetToPool(type, std::move(name), asset, std::move(dependencies), std::move(usedScriptStrings), zone);
if (assetInfo)
{
m_assets_in_order.push_back(assetInfo);
}

View File

@ -17,17 +17,23 @@ 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;
virtual XAssetInfoGeneric* AddAssetToPool(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings,
Zone* zone) = 0;
public:
using iterator = std::vector<XAssetInfoGeneric*>::const_iterator;
explicit ZoneAssetPools(Zone* zone);
virtual ~ZoneAssetPools() = default;
ZoneAssetPools(const ZoneAssetPools& other) = delete;
ZoneAssetPools(ZoneAssetPools&& other) noexcept = default;
ZoneAssetPools& operator=(const ZoneAssetPools& other) = delete;
ZoneAssetPools& operator=(ZoneAssetPools&& other) noexcept = 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 char* GetAssetTypeName(asset_type_t assetType) const = 0;
XAssetInfoGeneric* AddAsset(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings);
XAssetInfoGeneric* AddAsset(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings, Zone* zone);
_NODISCARD virtual XAssetInfoGeneric* GetAsset(asset_type_t type, std::string name) const = 0;
_NODISCARD 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;

View File

@ -2,13 +2,14 @@
#include <memory>
#include <string>
#include <vector>
#include "Utils/ClassUtils.h"
#include "Zone/ZoneTypes.h"
#include "Pool/ZoneAssetPools.h"
#include "Game/IGame.h"
#include "Game/GameLanguage.h"
#include "ZoneMemory.h"
#include "ZoneScriptStrings.h"
class IGame;
class ZoneAssetPools;
@ -24,7 +25,7 @@ public:
zone_priority_t m_priority;
GameLanguage m_language;
IGame* m_game;
std::vector<std::string> m_script_strings;
ZoneScriptStrings m_script_strings;
std::unique_ptr<ZoneAssetPools> m_pools;
Zone(std::string name, zone_priority_t priority, IGame* game);
@ -36,5 +37,5 @@ public:
void Register();
ZoneMemory* GetMemory() const;
_NODISCARD ZoneMemory* GetMemory() const;
};

View File

@ -0,0 +1,57 @@
#include "ZoneScriptStrings.h"
#include <stdexcept>
#include <sstream>
scr_string_t ZoneScriptStrings::AddScriptString(const std::string& value)
{
if(m_scr_strings.empty())
{
m_scr_strings.emplace_back("");
m_scr_string_lookup[""] = static_cast<scr_string_t>(0);
}
else
{
const auto existingScriptString = m_scr_string_lookup.find(value);
if (existingScriptString != m_scr_string_lookup.end())
return existingScriptString->second;
}
const auto newScrStringIndex = static_cast<scr_string_t>(m_scr_strings.size());
m_scr_strings.emplace_back(value);
m_scr_string_lookup[value] = newScrStringIndex;
return newScrStringIndex;
}
size_t ZoneScriptStrings::Count() const
{
return m_scr_strings.size();
}
bool ZoneScriptStrings::Empty() const
{
return m_scr_strings.empty();
}
const std::string& ZoneScriptStrings::operator[](const size_t index) const
{
if(index > m_scr_strings.size())
{
std::ostringstream str;
str << "Script string index '" << index << "' is not inside range of zone script strings (count: " << m_scr_strings.size() << ")";
throw std::runtime_error(str.str());
}
return m_scr_strings[index];
}
std::vector<std::string>::const_iterator ZoneScriptStrings::begin() const
{
return m_scr_strings.cbegin();
}
std::vector<std::string>::const_iterator ZoneScriptStrings::end() const
{
return m_scr_strings.end();
}

View File

@ -0,0 +1,24 @@
#pragma once
#include <cstddef>
#include <string>
#include <unordered_map>
#include <vector>
#include "Utils/ClassUtils.h"
#include "Zone/ZoneTypes.h"
class ZoneScriptStrings
{
std::vector<std::string> m_scr_strings;
std::unordered_map<std::string, scr_string_t> m_scr_string_lookup;
public:
scr_string_t AddScriptString(const std::string& value);
_NODISCARD size_t Count() const;
_NODISCARD bool Empty() const;
_NODISCARD const std::string& operator[](size_t index) const;
_NODISCARD std::vector<std::string>::const_iterator begin() const;
_NODISCARD std::vector<std::string>::const_iterator end() const;
};

View File

@ -50,7 +50,7 @@ ContentLoader::ContentLoader()
void ContentLoader::LoadScriptStringList(const bool atStreamStart)
{
assert(m_zone->m_script_strings.empty());
assert(m_zone->m_script_strings.Empty());
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
@ -69,18 +69,18 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart)
{
if (varScriptStringList->strings[i])
{
m_zone->m_script_strings.emplace_back(varScriptStringList->strings[i]);
m_zone->m_script_strings.AddScriptString(varScriptStringList->strings[i]);
}
else
{
m_zone->m_script_strings.emplace_back("");
m_zone->m_script_strings.AddScriptString("");
}
}
}
m_stream->PopBlock();
assert(m_zone->m_script_strings.size() <= SCR_STRING_MAX + 1);
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
}
void ContentLoader::LoadXAsset(const bool atStreamStart)

View File

@ -63,7 +63,7 @@ ContentLoader::ContentLoader()
void ContentLoader::LoadScriptStringList(const bool atStreamStart)
{
assert(m_zone->m_script_strings.empty());
assert(m_zone->m_script_strings.Empty());
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
@ -82,18 +82,18 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart)
{
if (varScriptStringList->strings[i])
{
m_zone->m_script_strings.emplace_back(varScriptStringList->strings[i]);
m_zone->m_script_strings.AddScriptString(varScriptStringList->strings[i]);
}
else
{
m_zone->m_script_strings.emplace_back("");
m_zone->m_script_strings.AddScriptString("");
}
}
}
m_stream->PopBlock();
assert(m_zone->m_script_strings.size() <= SCR_STRING_MAX + 1);
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
}
void ContentLoader::LoadXAsset(const bool atStreamStart)

View File

@ -30,11 +30,12 @@ void AssetLoader::AddDependency(XAssetInfoGeneric* assetInfo)
scr_string_t AssetLoader::UseScriptString(const scr_string_t scrString)
{
assert(scrString < m_zone->m_script_strings.size());
assert(scrString < m_zone->m_script_strings.Count());
if (scrString >= m_zone->m_script_strings.size())
if (scrString >= m_zone->m_script_strings.Count())
return 0u;
m_used_script_strings.emplace(scrString);
return scrString;
}
@ -55,7 +56,19 @@ void AssetLoader::LoadScriptStringArray(const bool atStreamStart, const size_t c
XAssetInfoGeneric* AssetLoader::LinkAsset(std::string name, void* asset)
{
return m_zone->m_pools->AddAsset(m_asset_type, std::move(name), asset, m_dependencies);
std::vector<scr_string_t> usedScriptStrings;
if(!m_used_script_strings.empty())
{
for(auto scrString : m_used_script_strings)
{
usedScriptStrings.push_back(scrString);
}
std::sort(usedScriptStrings.begin(), usedScriptStrings.end());
m_used_script_strings.clear();
}
return m_zone->m_pools->AddAsset(m_asset_type, std::move(name), asset, std::move(m_dependencies), std::move(usedScriptStrings));
}
XAssetInfoGeneric* AssetLoader::GetAssetInfo(std::string name) const

View File

@ -1,5 +1,8 @@
#pragma once
#include <vector>
#include <unordered_set>
#include "Zone/ZoneTypes.h"
#include "Pool/XAssetInfo.h"
#include "ContentLoaderBase.h"
@ -9,6 +12,7 @@ class AssetLoader : public ContentLoaderBase
asset_type_t m_asset_type;
std::vector<XAssetInfoGeneric*> m_dependencies;
std::unordered_set<scr_string_t> m_used_script_strings;
protected:
scr_string_t* varScriptString;

View File

@ -52,13 +52,13 @@ ContentWriter::ContentWriter()
void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memory) const
{
if (!m_zone->m_script_strings.empty())
if (!m_zone->m_script_strings.Empty())
{
assert(m_zone->m_script_strings.size() <= SCR_STRING_MAX + 1);
xAssetList.stringList.count = m_zone->m_script_strings.size();
xAssetList.stringList.strings = static_cast<const char**>(memory.Alloc(sizeof(const char*) * m_zone->m_script_strings.size()));
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
xAssetList.stringList.count = m_zone->m_script_strings.Count();
xAssetList.stringList.strings = static_cast<const char**>(memory.Alloc(sizeof(const char*) * m_zone->m_script_strings.Count()));
for (auto i = 0u; i < m_zone->m_script_strings.size(); i++)
for (auto i = 0u; i < m_zone->m_script_strings.Count(); i++)
{
xAssetList.stringList.strings[i] = m_zone->m_script_strings[i].c_str();
}
@ -93,8 +93,6 @@ void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memo
void ContentWriter::WriteScriptStringList(const bool atStreamStart)
{
assert(m_zone->m_script_strings.empty());
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
if (atStreamStart)

View File

@ -65,13 +65,13 @@ ContentWriter::ContentWriter()
void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memory) const
{
if (!m_zone->m_script_strings.empty())
if (!m_zone->m_script_strings.Empty())
{
assert(m_zone->m_script_strings.size() <= SCR_STRING_MAX + 1);
xAssetList.stringList.count = m_zone->m_script_strings.size();
xAssetList.stringList.strings = static_cast<const char**>(memory.Alloc(sizeof(const char*) * m_zone->m_script_strings.size()));
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
xAssetList.stringList.count = m_zone->m_script_strings.Count();
xAssetList.stringList.strings = static_cast<const char**>(memory.Alloc(sizeof(const char*) * m_zone->m_script_strings.Count()));
for (auto i = 0u; i < m_zone->m_script_strings.size(); i++)
for (auto i = 0u; i < m_zone->m_script_strings.Count(); i++)
{
xAssetList.stringList.strings[i] = m_zone->m_script_strings[i].c_str();
}
@ -109,8 +109,6 @@ void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memo
void ContentWriter::WriteScriptStringList(const bool atStreamStart)
{
assert(m_zone->m_script_strings.empty());
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
if (atStreamStart)

View File

@ -13,6 +13,8 @@ AssetWriter::AssetWriter(XAssetInfoGeneric* asset, Zone* zone, IZoneOutputStream
scr_string_t AssetWriter::UseScriptString(const scr_string_t scrString) const
{
assert(scrString < m_asset->m_zone->m_script_strings.Count());
if (m_asset->m_zone == m_zone)
return scrString;