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

@ -50,6 +50,8 @@ ContentLoader::ContentLoader()
void ContentLoader::LoadScriptStringList(const bool atStreamStart)
{
assert(m_zone->m_script_strings.empty());
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
if (atStreamStart)
@ -67,16 +69,18 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart)
{
if (varScriptStringList->strings[i])
{
m_script_strings.emplace_back(varScriptStringList->strings[i]);
m_zone->m_script_strings.emplace_back(varScriptStringList->strings[i]);
}
else
{
m_script_strings.emplace_back("");
m_zone->m_script_strings.emplace_back("");
}
}
}
m_stream->PopBlock();
assert(m_zone->m_script_strings.size() <= SCR_STRING_MAX + 1);
}
void ContentLoader::LoadXAsset(const bool atStreamStart)
@ -84,7 +88,7 @@ void ContentLoader::LoadXAsset(const bool atStreamStart)
#define LOAD_ASSET(type_index, typeName, headerEntry) \
case type_index: \
{ \
Loader_##typeName loader(this, m_zone, m_stream); \
Loader_##typeName loader(m_zone, m_stream); \
loader.Load(&varXAsset->header.headerEntry); \
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++)
{
m_zone->GetPools()->InitPoolDynamic(assetType);
m_zone->m_pools->InitPoolDynamic(assetType);
}
for (size_t index = 0; index < count; index++)
@ -189,15 +193,3 @@ void ContentLoader::Load(Zone* zone, IZoneInputStream* stream)
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/IContentLoadingEntryPoint.h"
#include "Game/IW4/IW4.h"
#include "Loading/IZoneScriptStringProvider.h"
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;
ScriptStringList* varScriptStringList;
@ -21,6 +19,5 @@ namespace IW4
ContentLoader();
void Load(Zone* zone, IZoneInputStream* stream) override;
std::string& GetZoneScriptString(scr_string_t scrString) override;
};
}

View File

@ -204,7 +204,8 @@ public:
return nullptr;
// 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);
// 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)
{
assert(m_zone->m_script_strings.empty());
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
if (atStreamStart)
@ -80,16 +82,18 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart)
{
if (varScriptStringList->strings[i])
{
m_script_strings.emplace_back(varScriptStringList->strings[i]);
m_zone->m_script_strings.emplace_back(varScriptStringList->strings[i]);
}
else
{
m_script_strings.emplace_back("");
m_zone->m_script_strings.emplace_back("");
}
}
}
m_stream->PopBlock();
assert(m_zone->m_script_strings.size() <= SCR_STRING_MAX + 1);
}
void ContentLoader::LoadXAsset(const bool atStreamStart)
@ -97,7 +101,7 @@ void ContentLoader::LoadXAsset(const bool atStreamStart)
#define LOAD_ASSET(type_index, typeName, headerEntry) \
case type_index: \
{ \
Loader_##typeName loader(this, m_zone, m_stream); \
Loader_##typeName loader(m_zone, m_stream); \
loader.Load(&varXAsset->header.headerEntry); \
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++)
{
m_zone->GetPools()->InitPoolDynamic(assetType);
m_zone->m_pools->InitPoolDynamic(assetType);
}
for (size_t index = 0; index < count; index++)
@ -220,15 +224,3 @@ void ContentLoader::Load(Zone* zone, IZoneInputStream* stream)
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/IContentLoadingEntryPoint.h"
#include "Game/T6/T6.h"
#include "Loading/IZoneScriptStringProvider.h"
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;
ScriptStringList* varScriptStringList;
@ -21,6 +19,5 @@ namespace T6
ContentLoader();
void Load(Zone* zone, IZoneInputStream* stream) override;
std::string& GetZoneScriptString(scr_string_t scrString) override;
};
}

View File

@ -238,7 +238,8 @@ public:
return nullptr;
// 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);
// File is supported. Now setup all required steps for loading this file.