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

@ -71,7 +71,7 @@ namespace IW4
void ObjLoader::LoadImageData(ISearchPath* searchPath, Zone* zone) void ObjLoader::LoadImageData(ISearchPath* searchPath, Zone* zone)
{ {
auto* assetPool = dynamic_cast<GameAssetPoolIW4*>(zone->GetPools()); auto* assetPool = dynamic_cast<GameAssetPoolIW4*>(zone->m_pools.get());
if (assetPool && assetPool->m_image != nullptr) if (assetPool && assetPool->m_image != nullptr)
{ {

View File

@ -107,7 +107,7 @@ namespace T6
void ObjLoader::LoadReferencedContainersForZone(ISearchPath* searchPath, Zone* zone) const void ObjLoader::LoadReferencedContainersForZone(ISearchPath* searchPath, Zone* zone) const
{ {
auto* assetPoolT6 = dynamic_cast<GameAssetPoolT6*>(zone->GetPools()); auto* assetPoolT6 = dynamic_cast<GameAssetPoolT6*>(zone->m_pools.get());
const int zoneNameHash = CommonT6::Com_HashKey(zone->m_name.c_str(), 64); const int zoneNameHash = CommonT6::Com_HashKey(zone->m_name.c_str(), 64);
LoadCommonIPaks(searchPath, zone); LoadCommonIPaks(searchPath, zone);
@ -197,7 +197,7 @@ namespace T6
void ObjLoader::LoadImageData(ISearchPath* searchPath, Zone* zone) void ObjLoader::LoadImageData(ISearchPath* searchPath, Zone* zone)
{ {
auto* assetPoolT6 = dynamic_cast<GameAssetPoolT6*>(zone->GetPools()); auto* assetPoolT6 = dynamic_cast<GameAssetPoolT6*>(zone->m_pools.get());
if (assetPoolT6 && assetPoolT6->m_image != nullptr) if (assetPoolT6 && assetPoolT6->m_image != nullptr)
{ {

View File

@ -26,7 +26,7 @@ bool ZoneDumper::DumpZone(Zone* zone, const std::string& basePath) const
dumper.DumpPool(zone, assetPools->poolName.get(), basePath); \ dumper.DumpPool(zone, assetPools->poolName.get(), basePath); \
} }
const auto* assetPools = dynamic_cast<GameAssetPoolIW4*>(zone->GetPools()); const auto* assetPools = dynamic_cast<GameAssetPoolIW4*>(zone->m_pools.get());
// DUMP_ASSET_POOL(AssetDumperPhysPreset, m_phys_preset) // DUMP_ASSET_POOL(AssetDumperPhysPreset, m_phys_preset)
// DUMP_ASSET_POOL(AssetDumperPhysCollmap, m_phys_collmap) // DUMP_ASSET_POOL(AssetDumperPhysCollmap, m_phys_collmap)

View File

@ -1450,7 +1450,7 @@ namespace T6
std::stringstream ss; std::stringstream ss;
bool first = true; bool first = true;
for(auto i = 0u; i < _countof(WeaponFullDef::notetrackSoundMapKeys); i++) for (auto i = 0u; i < _countof(WeaponFullDef::notetrackSoundMapKeys); i++)
{ {
const auto& key = m_get_scr_string(keys[i]); const auto& key = m_get_scr_string(keys[i]);
const auto& value = m_get_scr_string(values[i]); const auto& value = m_get_scr_string(values[i]);
@ -1634,10 +1634,11 @@ void AssetDumperWeapon::DumpAsset(Zone* zone, XAssetInfo<WeaponVariantDef>* asse
InfoStringFromWeaponConverter converter(fullDef, weapon_fields, _countof(weapon_fields), [asset](const scr_string_t scrStr) -> std::string InfoStringFromWeaponConverter converter(fullDef, weapon_fields, _countof(weapon_fields), [asset](const scr_string_t scrStr) -> std::string
{ {
if (scrStr >= asset->m_script_strings.size()) assert(scrStr < asset->m_zone->m_script_strings.size());
if (scrStr >= asset->m_zone->m_script_strings.size())
return ""; return "";
return asset->m_script_strings[scrStr]; return asset->m_zone->m_script_strings[scrStr];
}); });
const auto infoString = converter.Convert(); const auto infoString = converter.Convert();

View File

@ -29,7 +29,7 @@ bool ZoneDumper::DumpZone(Zone* zone, const std::string& basePath) const
dumper.DumpPool(zone, assetPools->poolName, basePath); \ dumper.DumpPool(zone, assetPools->poolName, basePath); \
} }
const auto assetPools = dynamic_cast<GameAssetPoolT6*>(zone->GetPools()); const auto assetPools = dynamic_cast<GameAssetPoolT6*>(zone->m_pools.get());
// DUMP_ASSET_POOL(AssetDumperPhysPreset, m_phys_preset); // DUMP_ASSET_POOL(AssetDumperPhysPreset, m_phys_preset);
// DUMP_ASSET_POOL(AssetDumperPhysConstraints, m_phys_constraints); // DUMP_ASSET_POOL(AssetDumperPhysConstraints, m_phys_constraints);

View File

@ -7,7 +7,7 @@ ContentPrinter::ContentPrinter(Zone* zone)
void ContentPrinter::PrintContent() const void ContentPrinter::PrintContent() const
{ {
const auto* pools = m_zone->GetPools(); const auto* pools = m_zone->m_pools.get();
printf("Zone '%s' (%s)\n", m_zone->m_name.c_str(), m_zone->m_game->GetName().c_str()); printf("Zone '%s' (%s)\n", m_zone->m_name.c_str(), m_zone->m_game->GetName().c_str());
puts("Content:"); puts("Content:");

View File

@ -15,7 +15,7 @@ namespace IW4
{ {
void WriteContent() const void WriteContent() const
{ {
const auto* pools = dynamic_cast<GameAssetPoolIW4*>(m_zone->GetPools()); const auto* pools = dynamic_cast<GameAssetPoolIW4*>(m_zone->m_pools.get());
assert(pools); assert(pools);
if (!pools) if (!pools)

View File

@ -52,7 +52,7 @@ namespace T6
void WriteContent() const void WriteContent() const
{ {
const auto* pools = dynamic_cast<GameAssetPoolT6*>(m_zone->GetPools()); const auto* pools = dynamic_cast<GameAssetPoolT6*>(m_zone->m_pools.get());
assert(pools); assert(pools);
if (!pools) if (!pools)
@ -91,7 +91,7 @@ namespace T6
WriteMetaData(META_DATA_KEY_GAME, "t6"); WriteMetaData(META_DATA_KEY_GAME, "t6");
EmptyLine(); EmptyLine();
auto* assetPoolT6 = dynamic_cast<GameAssetPoolT6*>(m_zone->GetPools()); auto* assetPoolT6 = dynamic_cast<GameAssetPoolT6*>(m_zone->m_pools.get());
if (assetPoolT6 && !assetPoolT6->m_key_value_pairs->m_asset_lookup.empty()) if (assetPoolT6 && !assetPoolT6->m_key_value_pairs->m_asset_lookup.empty())
{ {

View File

@ -40,12 +40,7 @@ $TypeVarName(structure.Type)$->$member.Member.Name$$PrintArrayIndices(reference)
$\n$ $\n$
varScriptString = $TypeVarName(structure.Type)$->$member.Member.Name$$PrintArrayIndices(reference)$;$\n$ varScriptString = $TypeVarName(structure.Type)$->$member.Member.Name$$PrintArrayIndices(reference)$;$\n$
$if(!member.IsReusable)$
LoadScriptStringArray(true, $PrintEvaluation(reference.ArrayPointerCountEvaluation)$); LoadScriptStringArray(true, $PrintEvaluation(reference.ArrayPointerCountEvaluation)$);
$else$
LoadScriptStringArrayRealloc(true, $PrintEvaluation(reference.ArrayPointerCountEvaluation)$);$\n$
$TypeVarName(structure.Type)$->$member.Member.Name$$PrintArrayIndices(reference)$ = varScriptString;
$endif$
%> %>
@ -75,11 +70,6 @@ if($TypeVarName(structure.Type)$->$member.Member.Name$$PrintArrayIndices(referen
else else
{ {
$TypeVarName(structure.Type)$->$member.Member.Name$$PrintArrayIndices(reference)$ = m_stream->ConvertOffsetToPointer($TypeVarName(structure.Type)$->$member.Member.Name$$PrintArrayIndices(reference)$); $TypeVarName(structure.Type)$->$member.Member.Name$$PrintArrayIndices(reference)$ = m_stream->ConvertOffsetToPointer($TypeVarName(structure.Type)$->$member.Member.Name$$PrintArrayIndices(reference)$);
$if(member.IsScriptString)$
varScriptString = $TypeVarName(structure.Type)$->$member.Member.Name$$PrintArrayIndices(reference)$;
LoadScriptStringArrayRealloc(false, $PrintEvaluation(reference.ArrayPointerCountEvaluation)$);
$TypeVarName(structure.Type)$->$member.Member.Name$$PrintArrayIndices(reference)$ = varScriptString;
$endif$
}$\\$ }$\\$
$endif$ $endif$
>> >>
@ -129,7 +119,7 @@ $endif$
%> %>
LoadPointerArrayMethod_Asset(context, type, structure) ::= << LoadPointerArrayMethod_Asset(context, type, structure) ::= <<
$LoaderClassName(structure)$ loader(m_script_string_provider, m_zone, m_stream); $LoaderClassName(structure)$ loader(m_zone, m_stream);
AddDependency(loader.Load($TypePtrVarName(type)$)); AddDependency(loader.Load($TypePtrVarName(type)$));
>> >>

View File

@ -38,7 +38,7 @@ $endif$
>> >>
LoadSinglePointerAsset(context, structure, member, reference) ::= << LoadSinglePointerAsset(context, structure, member, reference) ::= <<
$LoaderClassName(member.StructureType)$ loader(m_script_string_provider, m_zone, m_stream); $LoaderClassName(member.StructureType)$ loader(m_zone, m_stream);
AddDependency(loader.Load(&$TypeVarName(structure.Type)$->$member.Member.Name$$PrintArrayIndices(reference)$)); AddDependency(loader.Load(&$TypeVarName(structure.Type)$->$member.Member.Name$$PrintArrayIndices(reference)$));
>> >>

View File

@ -12,7 +12,7 @@ import "Loading/PointerArray.stg"
// Loading common // Loading common
LoaderClassName(asset) ::= "Loader_$asset.Type.Name$" LoaderClassName(asset) ::= "Loader_$asset.Type.Name$"
HeaderConstructor(context) ::= "$LoaderClassName(context.Asset)$(IZoneScriptStringProvider* scriptStringProvider, Zone* zone, IZoneInputStream* stream);" HeaderConstructor(context) ::= "$LoaderClassName(context.Asset)$(Zone* zone, IZoneInputStream* stream);"
HeaderTempPtrLoadMethodDeclaration(structure) ::= "void LoadPtr_$structure.Type.Name$(bool atStreamStart);" HeaderTempPtrLoadMethodDeclaration(structure) ::= "void LoadPtr_$structure.Type.Name$(bool atStreamStart);"
HeaderArrayLoadMethodDeclaration(type) ::= "void LoadArray_$SafeTypeName(type)$(bool atStreamStart, size_t count);" HeaderArrayLoadMethodDeclaration(type) ::= "void LoadArray_$SafeTypeName(type)$(bool atStreamStart, size_t count);"
@ -290,8 +290,8 @@ var$type.Name$Ptr = nullptr;
>> >>
ConstructorMethod(context) ::= << ConstructorMethod(context) ::= <<
$LoaderClassName(context.Asset)$::$LoaderClassName(context.Asset)$(IZoneScriptStringProvider* scriptStringProvider, Zone* zone, IZoneInputStream* stream) $LoaderClassName(context.Asset)$::$LoaderClassName(context.Asset)$(Zone* zone, IZoneInputStream* stream)
: AssetLoader($context.Asset.AssetEnumEntry.Name$, scriptStringProvider, zone, stream)$\\$ : AssetLoader($context.Asset.AssetEnumEntry.Name$, zone, stream)$\\$
$if(context.HasActions)$, m_actions(zone)$endif$ $if(context.HasActions)$, m_actions(zone)$endif$
{ {
m_asset_info = nullptr; m_asset_info = nullptr;

View File

@ -97,12 +97,12 @@ const std::string GameAssetPoolIW4::ASSET_TYPE_NAMES[]
ASSET_TYPE_ADDON_MAP_ENTS, AddonMapEnts, addonMapEnts, m_addon_map_ents ASSET_TYPE_ADDON_MAP_ENTS, AddonMapEnts, addonMapEnts, m_addon_map_ents
*/ */
GameAssetPoolIW4::GameAssetPoolIW4(const int priority) GameAssetPoolIW4::GameAssetPoolIW4(Zone* zone, const int priority)
: ZoneAssetPools(zone),
m_priority(priority)
{ {
assert(_countof(ASSET_TYPE_NAMES) == ASSET_TYPE_COUNT); assert(_countof(ASSET_TYPE_NAMES) == ASSET_TYPE_COUNT);
m_priority = priority;
m_phys_preset = nullptr; m_phys_preset = nullptr;
m_phys_collmap = nullptr; m_phys_collmap = nullptr;
m_xanim_parts = nullptr; m_xanim_parts = nullptr;
@ -258,9 +258,7 @@ void GameAssetPoolIW4::InitPoolDynamic(const asset_type_t type)
#undef CASE_INIT_POOL_STATIC #undef CASE_INIT_POOL_STATIC
} }
XAssetInfoGeneric* GameAssetPoolIW4::AddAsset(asset_type_t type, std::string name, void* asset, XAssetInfoGeneric* GameAssetPoolIW4::AddAssetToPool(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*>& dependencies)
std::vector<std::string>& scriptStrings,
std::vector<XAssetInfoGeneric*>& dependencies)
{ {
XAsset xAsset{}; XAsset xAsset{};
@ -271,7 +269,7 @@ XAssetInfoGeneric* GameAssetPoolIW4::AddAsset(asset_type_t type, std::string nam
case assetType: \ case assetType: \
{ \ { \
assert((poolName) != nullptr); \ assert((poolName) != nullptr); \
auto* assetInfo = (poolName)->AddAsset(std::move(name), xAsset.header.headerName, scriptStrings, dependencies); \ auto* assetInfo = (poolName)->AddAsset(std::move(name), xAsset.header.headerName, m_zone, dependencies); \
if(assetInfo) \ if(assetInfo) \
{ \ { \
m_assets_in_order.push_back(assetInfo); \ m_assets_in_order.push_back(assetInfo); \
@ -394,13 +392,3 @@ const std::string& GameAssetPoolIW4::GetAssetTypeName(const asset_type_t assetTy
return ASSET_TYPE_INVALID; return ASSET_TYPE_INVALID;
} }
IZoneAssetPools::iterator GameAssetPoolIW4::begin() const
{
return m_assets_in_order.begin();
}
IZoneAssetPools::iterator GameAssetPoolIW4::end() const
{
return m_assets_in_order.end();
}

View File

@ -2,18 +2,20 @@
#include <memory> #include <memory>
#include "Pool/IZoneAssetPools.h" #include "Pool/ZoneAssetPools.h"
#include "Pool/AssetPool.h" #include "Pool/AssetPool.h"
#include "IW4.h" #include "IW4.h"
class GameAssetPoolIW4 final : public IZoneAssetPools class GameAssetPoolIW4 final : public ZoneAssetPools
{ {
int m_priority; int m_priority;
std::vector<XAssetInfoGeneric*> m_assets_in_order;
static const std::string ASSET_TYPE_INVALID; static const std::string ASSET_TYPE_INVALID;
static const std::string ASSET_TYPE_NAMES[]; static const std::string ASSET_TYPE_NAMES[];
protected:
XAssetInfoGeneric* AddAssetToPool(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*>& dependencies) override;
public: public:
std::unique_ptr<AssetPool<IW4::PhysPreset>> m_phys_preset; std::unique_ptr<AssetPool<IW4::PhysPreset>> m_phys_preset;
std::unique_ptr<AssetPool<IW4::PhysCollmap>> m_phys_collmap; std::unique_ptr<AssetPool<IW4::PhysCollmap>> m_phys_collmap;
@ -51,18 +53,12 @@ public:
std::unique_ptr<AssetPool<IW4::VehicleDef>> m_vehicle; std::unique_ptr<AssetPool<IW4::VehicleDef>> m_vehicle;
std::unique_ptr<AssetPool<IW4::AddonMapEnts>> m_addon_map_ents; std::unique_ptr<AssetPool<IW4::AddonMapEnts>> m_addon_map_ents;
explicit GameAssetPoolIW4(int priority); GameAssetPoolIW4(Zone* zone, int priority);
~GameAssetPoolIW4() override = default; ~GameAssetPoolIW4() override = default;
void InitPoolStatic(asset_type_t type, size_t capacity) override; void InitPoolStatic(asset_type_t type, size_t capacity) override;
void InitPoolDynamic(asset_type_t type) override; void InitPoolDynamic(asset_type_t type) override;
XAssetInfoGeneric* AddAsset(asset_type_t type, std::string name, void* asset,
std::vector<std::string>& scriptStrings,
std::vector<XAssetInfoGeneric*>& dependencies) override;
XAssetInfoGeneric* GetAsset(asset_type_t type, std::string name) const override; XAssetInfoGeneric* GetAsset(asset_type_t type, std::string name) const override;
const std::string& GetAssetTypeName(asset_type_t assetType) const override; const std::string& GetAssetTypeName(asset_type_t assetType) const override;
iterator begin() const override;
iterator end() const override;
}; };

View File

@ -70,12 +70,12 @@ const std::string GameAssetPoolT6::ASSET_TYPE_NAMES[]
"zbarrier" "zbarrier"
}; };
GameAssetPoolT6::GameAssetPoolT6(const int priority) GameAssetPoolT6::GameAssetPoolT6(Zone* zone, const int priority)
: ZoneAssetPools(zone),
m_priority(priority)
{ {
assert(_countof(ASSET_TYPE_NAMES) == ASSET_TYPE_COUNT); assert(_countof(ASSET_TYPE_NAMES) == ASSET_TYPE_COUNT);
m_priority = priority;
m_phys_preset = nullptr; m_phys_preset = nullptr;
m_phys_constraints = nullptr; m_phys_constraints = nullptr;
m_destructible_def = nullptr; m_destructible_def = nullptr;
@ -195,7 +195,7 @@ void GameAssetPoolT6::InitPoolStatic(const asset_type_t type, const size_t capac
break; \ break; \
} }
switch(type) switch (type)
{ {
CASE_INIT_POOL_STATIC(ASSET_TYPE_PHYSPRESET, m_phys_preset, PhysPreset); CASE_INIT_POOL_STATIC(ASSET_TYPE_PHYSPRESET, m_phys_preset, PhysPreset);
CASE_INIT_POOL_STATIC(ASSET_TYPE_PHYSCONSTRAINTS, m_phys_constraints, PhysConstraints); CASE_INIT_POOL_STATIC(ASSET_TYPE_PHYSCONSTRAINTS, m_phys_constraints, PhysConstraints);
@ -267,7 +267,7 @@ void GameAssetPoolT6::InitPoolDynamic(const asset_type_t type)
break; \ break; \
} }
switch(type) switch (type)
{ {
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_PHYSPRESET, m_phys_preset, PhysPreset); CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_PHYSPRESET, m_phys_preset, PhysPreset);
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_PHYSCONSTRAINTS, m_phys_constraints, PhysConstraints); CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_PHYSCONSTRAINTS, m_phys_constraints, PhysConstraints);
@ -327,7 +327,7 @@ void GameAssetPoolT6::InitPoolDynamic(const asset_type_t type)
#undef CASE_INIT_POOL_STATIC #undef CASE_INIT_POOL_STATIC
} }
XAssetInfoGeneric* GameAssetPoolT6::AddAsset(asset_type_t type, std::string name, void* asset, std::vector<std::string>& scriptStrings, std::vector<XAssetInfoGeneric*>& dependencies) XAssetInfoGeneric* GameAssetPoolT6::AddAssetToPool(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*>& dependencies)
{ {
XAsset xAsset{}; XAsset xAsset{};
@ -338,7 +338,7 @@ XAssetInfoGeneric* GameAssetPoolT6::AddAsset(asset_type_t type, std::string name
case assetType: \ case assetType: \
{ \ { \
assert((poolName) != nullptr); \ assert((poolName) != nullptr); \
auto* assetInfo = (poolName)->AddAsset(std::move(name), xAsset.header.headerName, scriptStrings, dependencies); \ auto* assetInfo = (poolName)->AddAsset(std::move(name), xAsset.header.headerName, m_zone, dependencies); \
if(assetInfo) \ if(assetInfo) \
{ \ { \
m_assets_in_order.push_back(assetInfo); \ m_assets_in_order.push_back(assetInfo); \
@ -346,7 +346,7 @@ XAssetInfoGeneric* GameAssetPoolT6::AddAsset(asset_type_t type, std::string name
return assetInfo; \ return assetInfo; \
} }
switch(xAsset.type) switch (xAsset.type)
{ {
CASE_ADD_TO_POOL(ASSET_TYPE_PHYSPRESET, m_phys_preset, physPreset); CASE_ADD_TO_POOL(ASSET_TYPE_PHYSPRESET, m_phys_preset, physPreset);
CASE_ADD_TO_POOL(ASSET_TYPE_PHYSCONSTRAINTS, m_phys_constraints, physConstraints); CASE_ADD_TO_POOL(ASSET_TYPE_PHYSCONSTRAINTS, m_phys_constraints, physConstraints);
@ -487,13 +487,3 @@ const std::string& GameAssetPoolT6::GetAssetTypeName(const asset_type_t assetTyp
return ASSET_TYPE_INVALID; return ASSET_TYPE_INVALID;
} }
IZoneAssetPools::iterator GameAssetPoolT6::begin() const
{
return m_assets_in_order.begin();
}
IZoneAssetPools::iterator GameAssetPoolT6::end() const
{
return m_assets_in_order.end();
}

View File

@ -1,17 +1,19 @@
#pragma once #pragma once
#include "Pool/IZoneAssetPools.h" #include "Pool/ZoneAssetPools.h"
#include "Pool/AssetPool.h" #include "Pool/AssetPool.h"
#include "T6.h" #include "T6.h"
class GameAssetPoolT6 final : public IZoneAssetPools class GameAssetPoolT6 final : public ZoneAssetPools
{ {
int m_priority; int m_priority;
std::vector<XAssetInfoGeneric*> m_assets_in_order;
static const std::string ASSET_TYPE_INVALID; static const std::string ASSET_TYPE_INVALID;
static const std::string ASSET_TYPE_NAMES[]; static const std::string ASSET_TYPE_NAMES[];
protected:
XAssetInfoGeneric* AddAssetToPool(asset_type_t type, std::string name, void* asset, std::vector<XAssetInfoGeneric*>& dependencies) override;
public: public:
AssetPool<T6::PhysPreset>* m_phys_preset; AssetPool<T6::PhysPreset>* m_phys_preset;
AssetPool<T6::PhysConstraints>* m_phys_constraints; AssetPool<T6::PhysConstraints>* m_phys_constraints;
@ -62,16 +64,12 @@ public:
AssetPool<T6::FootstepFXTableDef>* m_footstep_fx_table; AssetPool<T6::FootstepFXTableDef>* m_footstep_fx_table;
AssetPool<T6::ZBarrierDef>* m_zbarrier; AssetPool<T6::ZBarrierDef>* m_zbarrier;
explicit GameAssetPoolT6(int priority); GameAssetPoolT6(Zone* zone, int priority);
~GameAssetPoolT6() override; ~GameAssetPoolT6() override;
void InitPoolStatic(asset_type_t type, size_t capacity) override; void InitPoolStatic(asset_type_t type, size_t capacity) override;
void InitPoolDynamic(asset_type_t type) override; void InitPoolDynamic(asset_type_t type) override;
XAssetInfoGeneric* AddAsset(asset_type_t type, std::string name, void* asset, std::vector<std::string>& scriptStrings, std::vector<XAssetInfoGeneric*>& dependencies) override;
XAssetInfoGeneric* GetAsset(asset_type_t type, std::string name) const override; XAssetInfoGeneric* GetAsset(asset_type_t type, std::string name) const override;
const std::string& GetAssetTypeName(asset_type_t assetType) const override; const std::string& GetAssetTypeName(asset_type_t assetType) const override;
iterator begin() const override;
iterator end() const override;
}; };

View File

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

View File

@ -40,12 +40,12 @@ public:
m_asset_lookup.clear(); 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>(); auto* newInfo = new XAssetInfo<T>();
newInfo->m_type = m_type; newInfo->m_type = m_type;
newInfo->m_name = std::move(name); newInfo->m_name = std::move(name);
newInfo->m_script_strings = std::move(scriptStrings); newInfo->m_zone = zone;
newInfo->m_dependencies = std::move(dependencies); newInfo->m_dependencies = std::move(dependencies);
T* newAsset = new T(); T* newAsset = new T();

View File

@ -81,7 +81,7 @@ public:
m_capacity = 0; 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) if(m_free == nullptr)
{ {
@ -96,7 +96,7 @@ public:
poolSlot->m_info->m_type = m_type; poolSlot->m_info->m_type = m_type;
poolSlot->m_info->m_name = std::move(name); poolSlot->m_info->m_name = std::move(name);
poolSlot->m_info->m_ptr = &poolSlot->m_entry; 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); poolSlot->m_info->m_dependencies = std::move(dependencies);
m_asset_lookup[poolSlot->m_info->m_name] = poolSlot->m_info; 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 <vector>
#include <string> #include <string>
#include "Zone/Zone.h"
class Zone;
class XAssetInfoGeneric class XAssetInfoGeneric
{ {
public: public:
int m_type = -1; int m_type = -1;
std::string m_name; std::string m_name;
std::vector<std::string> m_script_strings; Zone* m_zone;
std::vector<XAssetInfoGeneric*> m_dependencies; std::vector<XAssetInfoGeneric*> m_dependencies;
void* m_ptr; 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;
};

View File

@ -1,28 +1,21 @@
#include "Zone.h" #include "Zone.h"
Zone::Zone(std::string name, const zone_priority_t priority, IZoneAssetPools* pools, IGame* game) Zone::Zone(std::string name, const zone_priority_t priority, IGame* game)
: m_memory(std::make_unique<ZoneMemory>()),
m_registered(false),
m_name(std::move(name)),
m_priority(priority),
m_language(GameLanguage::LANGUAGE_NONE),
m_game(game)
{ {
m_name = std::move(name);
m_priority = priority;
m_pools = pools;
m_game = game;
m_language = GameLanguage::LANGUAGE_NONE;
m_memory = new ZoneMemory();
m_registered = false;
} }
Zone::~Zone() Zone::~Zone()
{ {
if(m_registered) if (m_registered)
{ {
m_game->RemoveZone(this); m_game->RemoveZone(this);
} }
delete m_pools;
m_pools = nullptr;
delete m_memory;
m_memory = nullptr;
} }
void Zone::Register() void Zone::Register()
@ -34,12 +27,7 @@ void Zone::Register()
} }
} }
IZoneAssetPools* Zone::GetPools() const
{
return m_pools;
}
ZoneMemory* Zone::GetMemory() const ZoneMemory* Zone::GetMemory() const
{ {
return m_memory; return m_memory.get();
} }

View File

@ -1,19 +1,22 @@
#pragma once #pragma once
#include <memory>
#include "ZoneTypes.h" #include "ZoneTypes.h"
#include "Pool/IZoneAssetPools.h" #include "Pool/ZoneAssetPools.h"
#include "Game/IGame.h" #include "Game/IGame.h"
#include "Game/GameLanguage.h" #include "Game/GameLanguage.h"
#include "Zone/XBlock.h" #include "Zone/XBlock.h"
#include "ZoneMemory.h" #include "ZoneMemory.h"
#include <string> #include <string>
#include <vector>
class IGame; class IGame;
class ZoneAssetPools;
class Zone class Zone
{ {
IZoneAssetPools* m_pools;
std::vector<XBlock*> m_blocks; std::vector<XBlock*> m_blocks;
ZoneMemory* m_memory; std::unique_ptr<ZoneMemory> m_memory;
bool m_registered; bool m_registered;
@ -22,12 +25,13 @@ public:
zone_priority_t m_priority; zone_priority_t m_priority;
GameLanguage m_language; GameLanguage m_language;
IGame* m_game; IGame* m_game;
std::vector<std::string> m_script_strings;
std::unique_ptr<ZoneAssetPools> m_pools;
Zone(std::string name, zone_priority_t priority, IZoneAssetPools* pools, IGame* game); Zone(std::string name, zone_priority_t priority, IGame* game);
~Zone(); ~Zone();
void Register(); void Register();
IZoneAssetPools* GetPools() const;
ZoneMemory* GetMemory() const; ZoneMemory* GetMemory() const;
}; };

View File

@ -12,11 +12,15 @@ typedef uint32_t scr_string_t;
typedef uint64_t xchunk_size_t; typedef uint64_t xchunk_size_t;
typedef uint64_t xblock_size_t; typedef uint64_t xblock_size_t;
typedef uint64_t zone_pointer_t; typedef uint64_t zone_pointer_t;
constexpr uint16_t SCR_STRING_MAX = UINT32_MAX;
#elif _WIN32 #elif _WIN32
typedef uint16_t scr_string_t; typedef uint16_t scr_string_t;
typedef uint32_t xchunk_size_t; typedef uint32_t xchunk_size_t;
typedef uint32_t xblock_size_t; typedef uint32_t xblock_size_t;
typedef uint32_t zone_pointer_t; typedef uint32_t zone_pointer_t;
constexpr uint16_t SCR_STRING_MAX = UINT16_MAX;
#endif #endif
typedef int block_t; typedef int block_t;

View File

@ -50,6 +50,8 @@ ContentLoader::ContentLoader()
void ContentLoader::LoadScriptStringList(const bool atStreamStart) void ContentLoader::LoadScriptStringList(const bool atStreamStart)
{ {
assert(m_zone->m_script_strings.empty());
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL); m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
if (atStreamStart) if (atStreamStart)
@ -67,16 +69,18 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart)
{ {
if (varScriptStringList->strings[i]) if (varScriptStringList->strings[i])
{ {
m_script_strings.emplace_back(varScriptStringList->strings[i]); m_zone->m_script_strings.emplace_back(varScriptStringList->strings[i]);
} }
else else
{ {
m_script_strings.emplace_back(""); m_zone->m_script_strings.emplace_back("");
} }
} }
} }
m_stream->PopBlock(); m_stream->PopBlock();
assert(m_zone->m_script_strings.size() <= SCR_STRING_MAX + 1);
} }
void ContentLoader::LoadXAsset(const bool atStreamStart) void ContentLoader::LoadXAsset(const bool atStreamStart)
@ -84,7 +88,7 @@ void ContentLoader::LoadXAsset(const bool atStreamStart)
#define LOAD_ASSET(type_index, typeName, headerEntry) \ #define LOAD_ASSET(type_index, typeName, headerEntry) \
case type_index: \ case type_index: \
{ \ { \
Loader_##typeName loader(this, m_zone, m_stream); \ Loader_##typeName loader(m_zone, m_stream); \
loader.Load(&varXAsset->header.headerEntry); \ loader.Load(&varXAsset->header.headerEntry); \
break; \ break; \
} }
@ -155,7 +159,7 @@ void ContentLoader::LoadXAssetArray(const bool atStreamStart, const size_t count
for (asset_type_t assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++) for (asset_type_t assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++)
{ {
m_zone->GetPools()->InitPoolDynamic(assetType); m_zone->m_pools->InitPoolDynamic(assetType);
} }
for (size_t index = 0; index < count; index++) for (size_t index = 0; index < count; index++)
@ -189,15 +193,3 @@ void ContentLoader::Load(Zone* zone, IZoneInputStream* stream)
m_stream->PopBlock(); m_stream->PopBlock();
} }
std::string& ContentLoader::GetZoneScriptString(const scr_string_t scrString)
{
assert(scrString >= 0 && scrString < m_script_strings.size());
if (scrString >= m_script_strings.size())
{
return m_script_strings[0];
}
return m_script_strings[scrString];
}

View File

@ -2,13 +2,11 @@
#include "Loading/ContentLoaderBase.h" #include "Loading/ContentLoaderBase.h"
#include "Loading/IContentLoadingEntryPoint.h" #include "Loading/IContentLoadingEntryPoint.h"
#include "Game/IW4/IW4.h" #include "Game/IW4/IW4.h"
#include "Loading/IZoneScriptStringProvider.h"
namespace IW4 namespace IW4
{ {
class ContentLoader final : public ContentLoaderBase, public IContentLoadingEntryPoint, public IZoneScriptStringProvider class ContentLoader final : public ContentLoaderBase, public IContentLoadingEntryPoint
{ {
std::vector<std::string> m_script_strings;
XAsset* varXAsset; XAsset* varXAsset;
ScriptStringList* varScriptStringList; ScriptStringList* varScriptStringList;
@ -21,6 +19,5 @@ namespace IW4
ContentLoader(); ContentLoader();
void Load(Zone* zone, IZoneInputStream* stream) override; void Load(Zone* zone, IZoneInputStream* stream) override;
std::string& GetZoneScriptString(scr_string_t scrString) override;
}; };
} }

View File

@ -204,7 +204,8 @@ public:
return nullptr; return nullptr;
// Create new zone // Create new zone
auto* zone = new Zone(fileName, 0, new GameAssetPoolIW4(0), &g_GameIW4); auto* zone = new Zone(fileName, 0, &g_GameIW4);
zone->m_pools = std::make_unique<GameAssetPoolIW4>(zone, 0);
zone->m_language = GetZoneLanguage(fileName); zone->m_language = GetZoneLanguage(fileName);
// File is supported. Now setup all required steps for loading this file. // File is supported. Now setup all required steps for loading this file.

View File

@ -63,6 +63,8 @@ ContentLoader::ContentLoader()
void ContentLoader::LoadScriptStringList(const bool atStreamStart) void ContentLoader::LoadScriptStringList(const bool atStreamStart)
{ {
assert(m_zone->m_script_strings.empty());
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL); m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
if (atStreamStart) if (atStreamStart)
@ -80,16 +82,18 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart)
{ {
if (varScriptStringList->strings[i]) if (varScriptStringList->strings[i])
{ {
m_script_strings.emplace_back(varScriptStringList->strings[i]); m_zone->m_script_strings.emplace_back(varScriptStringList->strings[i]);
} }
else else
{ {
m_script_strings.emplace_back(""); m_zone->m_script_strings.emplace_back("");
} }
} }
} }
m_stream->PopBlock(); m_stream->PopBlock();
assert(m_zone->m_script_strings.size() <= SCR_STRING_MAX + 1);
} }
void ContentLoader::LoadXAsset(const bool atStreamStart) void ContentLoader::LoadXAsset(const bool atStreamStart)
@ -97,7 +101,7 @@ void ContentLoader::LoadXAsset(const bool atStreamStart)
#define LOAD_ASSET(type_index, typeName, headerEntry) \ #define LOAD_ASSET(type_index, typeName, headerEntry) \
case type_index: \ case type_index: \
{ \ { \
Loader_##typeName loader(this, m_zone, m_stream); \ Loader_##typeName loader(m_zone, m_stream); \
loader.Load(&varXAsset->header.headerEntry); \ loader.Load(&varXAsset->header.headerEntry); \
break; \ break; \
} }
@ -177,7 +181,7 @@ void ContentLoader::LoadXAssetArray(const bool atStreamStart, const size_t count
for (asset_type_t assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++) for (asset_type_t assetType = 0; assetType < ASSET_TYPE_COUNT; assetType++)
{ {
m_zone->GetPools()->InitPoolDynamic(assetType); m_zone->m_pools->InitPoolDynamic(assetType);
} }
for (size_t index = 0; index < count; index++) for (size_t index = 0; index < count; index++)
@ -220,15 +224,3 @@ void ContentLoader::Load(Zone* zone, IZoneInputStream* stream)
m_stream->PopBlock(); m_stream->PopBlock();
} }
std::string& ContentLoader::GetZoneScriptString(const scr_string_t scrString)
{
assert(scrString >= 0 && scrString < m_script_strings.size());
if (scrString >= m_script_strings.size())
{
return m_script_strings[0];
}
return m_script_strings[scrString];
}

View File

@ -2,13 +2,11 @@
#include "Loading/ContentLoaderBase.h" #include "Loading/ContentLoaderBase.h"
#include "Loading/IContentLoadingEntryPoint.h" #include "Loading/IContentLoadingEntryPoint.h"
#include "Game/T6/T6.h" #include "Game/T6/T6.h"
#include "Loading/IZoneScriptStringProvider.h"
namespace T6 namespace T6
{ {
class ContentLoader final : public ContentLoaderBase, public IContentLoadingEntryPoint, public IZoneScriptStringProvider class ContentLoader final : public ContentLoaderBase, public IContentLoadingEntryPoint
{ {
std::vector<std::string> m_script_strings;
XAsset* varXAsset; XAsset* varXAsset;
ScriptStringList* varScriptStringList; ScriptStringList* varScriptStringList;
@ -21,6 +19,5 @@ namespace T6
ContentLoader(); ContentLoader();
void Load(Zone* zone, IZoneInputStream* stream) override; void Load(Zone* zone, IZoneInputStream* stream) override;
std::string& GetZoneScriptString(scr_string_t scrString) override;
}; };
} }

View File

@ -238,7 +238,8 @@ public:
return nullptr; return nullptr;
// Create new zone // Create new zone
auto* zone = new Zone(fileName, 0, new GameAssetPoolT6(0), &g_GameT6); auto* zone = new Zone(fileName, 0, &g_GameT6);
zone->m_pools = std::make_unique<GameAssetPoolT6>(zone, 0);
zone->m_language = GetZoneLanguage(fileName); zone->m_language = GetZoneLanguage(fileName);
// File is supported. Now setup all required steps for loading this file. // File is supported. Now setup all required steps for loading this file.

View File

@ -1,10 +1,12 @@
#include "AssetLoader.h" #include "AssetLoader.h"
#include <cassert> #include <cassert>
AssetLoader::AssetLoader(const asset_type_t assetType, IZoneScriptStringProvider* scriptStringProvider, Zone* zone, IZoneInputStream* stream) AssetLoader::AssetLoader(const asset_type_t assetType, Zone* zone, IZoneInputStream* stream)
: ContentLoaderBase(zone, stream),
m_asset_type(assetType),
varScriptString(nullptr)
{ {
m_asset_type = assetType; m_asset_type = assetType;
m_script_string_provider = scriptStringProvider;
m_zone = zone; m_zone = zone;
m_stream = stream; m_stream = stream;
varScriptString = nullptr; varScriptString = nullptr;
@ -16,7 +18,7 @@ void AssetLoader::AddDependency(XAssetInfoGeneric* assetInfo)
return; return;
const auto existingEntry = std::find(m_dependencies.begin(), m_dependencies.end(), assetInfo); const auto existingEntry = std::find(m_dependencies.begin(), m_dependencies.end(), assetInfo);
if(existingEntry != m_dependencies.end()) if (existingEntry != m_dependencies.end())
{ {
return; return;
} }
@ -26,31 +28,12 @@ void AssetLoader::AddDependency(XAssetInfoGeneric* assetInfo)
scr_string_t AssetLoader::UseScriptString(const scr_string_t scrString) scr_string_t AssetLoader::UseScriptString(const scr_string_t scrString)
{ {
std::string& scrStringValue = m_script_string_provider->GetZoneScriptString(scrString); assert(scrString < m_zone->m_script_strings.size());
scr_string_t scriptStringIndex = 0; if (scrString >= m_zone->m_script_strings.size())
for(auto& existingScriptString : m_used_script_strings) return 0u;
{
if(existingScriptString == scrStringValue)
{
return scriptStringIndex;
}
scriptStringIndex++; return scrString;
}
scriptStringIndex = static_cast<scr_string_t>(m_used_script_strings.size());
// If an asset uses script strings make sure that script string 0 is always empty
if(scriptStringIndex == 0 && !scrStringValue.empty())
{
m_used_script_strings.emplace_back("");
scriptStringIndex++;
}
m_used_script_strings.push_back(scrStringValue);
return scriptStringIndex;
} }
void AssetLoader::LoadScriptStringArray(const bool atStreamStart, const size_t count) void AssetLoader::LoadScriptStringArray(const bool atStreamStart, const size_t count)
@ -68,31 +51,12 @@ void AssetLoader::LoadScriptStringArray(const bool atStreamStart, const size_t c
} }
} }
void AssetLoader::LoadScriptStringArrayRealloc(const bool atStreamStart, const size_t count)
{
assert(varScriptString != nullptr);
if (atStreamStart)
m_stream->Load<scr_string_t>(varScriptString, count);
auto* scriptStringsNew = static_cast<scr_string_t*>(m_zone->GetMemory()->Alloc(sizeof scr_string_t * count));
memcpy_s(scriptStringsNew, sizeof scr_string_t * count, varScriptString, sizeof scr_string_t * count);
varScriptString = scriptStringsNew;
auto* ptr = varScriptString;
for (size_t index = 0; index < count; index++)
{
*ptr = UseScriptString(*ptr);
ptr++;
}
}
XAssetInfoGeneric* AssetLoader::LinkAsset(std::string name, void* asset) XAssetInfoGeneric* AssetLoader::LinkAsset(std::string name, void* asset)
{ {
return m_zone->GetPools()->AddAsset(m_asset_type, std::move(name), asset, m_used_script_strings, m_dependencies);; return m_zone->m_pools->AddAsset(m_asset_type, std::move(name), asset, m_dependencies);
} }
XAssetInfoGeneric* AssetLoader::GetAssetInfo(std::string name) const XAssetInfoGeneric* AssetLoader::GetAssetInfo(std::string name) const
{ {
return m_zone->GetPools()->GetAsset(m_asset_type, std::move(name)); return m_zone->m_pools->GetAsset(m_asset_type, std::move(name));
} }

View File

@ -1,28 +1,22 @@
#pragma once #pragma once
#include "Pool/XAssetInfo.h" #include "Pool/XAssetInfo.h"
#include "ContentLoaderBase.h" #include "ContentLoaderBase.h"
#include "IZoneScriptStringProvider.h"
class AssetLoader : public ContentLoaderBase class AssetLoader : public ContentLoaderBase
{ {
asset_type_t m_asset_type; asset_type_t m_asset_type;
std::vector<std::string> m_used_script_strings;
std::vector<XAssetInfoGeneric*> m_dependencies; std::vector<XAssetInfoGeneric*> m_dependencies;
protected: protected:
IZoneScriptStringProvider* m_script_string_provider;
scr_string_t* varScriptString; scr_string_t* varScriptString;
AssetLoader(asset_type_t assetType, IZoneScriptStringProvider* scriptStringProvider, Zone* zone, IZoneInputStream* stream); AssetLoader(asset_type_t assetType, Zone* zone, IZoneInputStream* stream);
void AddDependency(XAssetInfoGeneric* assetInfo); void AddDependency(XAssetInfoGeneric* assetInfo);
scr_string_t UseScriptString(scr_string_t scrString); scr_string_t UseScriptString(scr_string_t scrString);
void LoadScriptStringArray(bool atStreamStart, size_t count); void LoadScriptStringArray(bool atStreamStart, size_t count);
void LoadScriptStringArrayRealloc(bool atStreamStart, size_t count);
XAssetInfoGeneric* LinkAsset(std::string name, void* asset); XAssetInfoGeneric* LinkAsset(std::string name, void* asset);

View File

@ -5,11 +5,17 @@ const void* ContentLoaderBase::PTR_FOLLOWING = reinterpret_cast<void*>(-1);
const void* ContentLoaderBase::PTR_INSERT = reinterpret_cast<void*>(-2); const void* ContentLoaderBase::PTR_INSERT = reinterpret_cast<void*>(-2);
ContentLoaderBase::ContentLoaderBase() ContentLoaderBase::ContentLoaderBase()
: varXString(nullptr),
m_zone(nullptr),
m_stream(nullptr)
{ {
varXString = nullptr; }
m_zone = nullptr; ContentLoaderBase::ContentLoaderBase(Zone* zone, IZoneInputStream* stream)
m_stream = nullptr; : varXString(nullptr),
m_zone(zone),
m_stream(stream)
{
} }
void ContentLoaderBase::LoadXString(const bool atStreamStart) const void ContentLoaderBase::LoadXString(const bool atStreamStart) const
@ -19,9 +25,9 @@ void ContentLoaderBase::LoadXString(const bool atStreamStart) const
if (atStreamStart) if (atStreamStart)
m_stream->Load<const char*>(varXString); m_stream->Load<const char*>(varXString);
if(*varXString != nullptr) if (*varXString != nullptr)
{ {
if(*varXString == PTR_FOLLOWING) if (*varXString == PTR_FOLLOWING)
{ {
*varXString = m_stream->Alloc<const char>(alignof(const char)); *varXString = m_stream->Alloc<const char>(alignof(const char));
m_stream->LoadNullTerminated(const_cast<char*>(*varXString)); m_stream->LoadNullTerminated(const_cast<char*>(*varXString));
@ -37,10 +43,10 @@ void ContentLoaderBase::LoadXStringArray(const bool atStreamStart, const size_t
{ {
assert(varXString != nullptr); assert(varXString != nullptr);
if(atStreamStart) if (atStreamStart)
m_stream->Load<const char*>(varXString, count); m_stream->Load<const char*>(varXString, count);
for(size_t index = 0; index < count; index++) for (size_t index = 0; index < count; index++)
{ {
LoadXString(false); LoadXString(false);
varXString++; varXString++;

View File

@ -15,6 +15,7 @@ protected:
IZoneInputStream* m_stream; IZoneInputStream* m_stream;
ContentLoaderBase(); ContentLoaderBase();
ContentLoaderBase(Zone* zone, IZoneInputStream* stream);
void LoadXString(bool atStreamStart) const; void LoadXString(bool atStreamStart) const;
void LoadXStringArray(bool atStreamStart, size_t count); void LoadXStringArray(bool atStreamStart, size_t count);

View File

@ -1,10 +0,0 @@
#pragma once
#include "Zone/ZoneTypes.h"
#include <string>
class IZoneScriptStringProvider
{
public:
virtual std::string& GetZoneScriptString(scr_string_t scrString) = 0;
};