mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 16:15:43 +00:00
Fix not supporting nullptr scriptstrings
This commit is contained in:
parent
7283cc5640
commit
538c4be839
@ -98,8 +98,8 @@ XAssetInfoGeneric* AssetLoadingManager::LoadAssetDependency(const asset_type_t a
|
|||||||
|
|
||||||
// Make sure any used script string is available in the created zone
|
// Make sure any used script string is available in the created zone
|
||||||
// The replacement of the scr_string_t values will be done upon writing
|
// The replacement of the scr_string_t values will be done upon writing
|
||||||
for(auto scrString : existingAsset->m_used_script_strings)
|
for(const auto scrString : existingAsset->m_used_script_strings)
|
||||||
m_context.m_zone->m_script_strings.AddOrGetScriptString(existingAsset->m_zone->m_script_strings[scrString]);
|
m_context.m_zone->m_script_strings.AddOrGetScriptString(existingAsset->m_zone->m_script_strings.CValue(scrString));
|
||||||
|
|
||||||
AddAsset(existingAsset->m_type, existingAsset->m_name, existingAsset->m_ptr, std::move(dependencies), existingAsset->m_used_script_strings, existingAsset->m_zone);
|
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;
|
auto* lastDependency = m_last_dependency_loaded;
|
||||||
|
@ -1,8 +1,51 @@
|
|||||||
#include "ZoneScriptStrings.h"
|
#include "ZoneScriptStrings.h"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
ZoneScriptStrings::ZoneScriptStrings()
|
||||||
|
: m_null_entry_pos(0)
|
||||||
|
{
|
||||||
|
// Make script string 0 a nullptr string
|
||||||
|
m_scr_strings.emplace_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZoneScriptStrings::InitializeForExistingZone()
|
||||||
|
{
|
||||||
|
m_null_entry_pos = -1;
|
||||||
|
m_scr_strings.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZoneScriptStrings::InitializeForExistingZone(const char** scrStrList, const size_t scrStrCount)
|
||||||
|
{
|
||||||
|
InitializeForExistingZone();
|
||||||
|
|
||||||
|
if (!scrStrList)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (auto i = 0u; i < scrStrCount; i++)
|
||||||
|
AddScriptString(scrStrList[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZoneScriptStrings::AddScriptString(const char* value)
|
||||||
|
{
|
||||||
|
const auto newStringIndex = m_scr_strings.size();
|
||||||
|
const auto newScrStringIndex = static_cast<scr_string_t>(newStringIndex);
|
||||||
|
|
||||||
|
if (value != nullptr)
|
||||||
|
{
|
||||||
|
m_scr_strings.emplace_back(value);
|
||||||
|
m_scr_string_lookup[value] = newScrStringIndex;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
assert(m_null_entry_pos < 0); // If null index is already set, the previous cost will not be considered null string anymore.
|
||||||
|
m_scr_strings.emplace_back();
|
||||||
|
m_null_entry_pos = static_cast<int>(newStringIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ZoneScriptStrings::AddScriptString(const std::string& value)
|
void ZoneScriptStrings::AddScriptString(const std::string& value)
|
||||||
{
|
{
|
||||||
const auto newScrStringIndex = static_cast<scr_string_t>(m_scr_strings.size());
|
const auto newScrStringIndex = static_cast<scr_string_t>(m_scr_strings.size());
|
||||||
@ -10,20 +53,36 @@ void ZoneScriptStrings::AddScriptString(const std::string& value)
|
|||||||
m_scr_string_lookup[value] = newScrStringIndex;
|
m_scr_string_lookup[value] = newScrStringIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
scr_string_t ZoneScriptStrings::AddOrGetScriptString(const std::string& value)
|
scr_string_t ZoneScriptStrings::AddOrGetScriptString(const char* value)
|
||||||
{
|
{
|
||||||
if (m_scr_strings.empty())
|
if (value != nullptr)
|
||||||
{
|
|
||||||
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);
|
const auto existingScriptString = m_scr_string_lookup.find(value);
|
||||||
if (existingScriptString != m_scr_string_lookup.end())
|
if (existingScriptString != m_scr_string_lookup.end())
|
||||||
return existingScriptString->second;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_null_entry_pos < 0)
|
||||||
|
{
|
||||||
|
const auto newStringIndex = m_scr_strings.size();
|
||||||
|
m_scr_strings.emplace_back();
|
||||||
|
m_null_entry_pos = static_cast<int>(newStringIndex);
|
||||||
|
return static_cast<scr_string_t>(newStringIndex);
|
||||||
|
}
|
||||||
|
return static_cast<scr_string_t>(m_null_entry_pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
scr_string_t ZoneScriptStrings::AddOrGetScriptString(const std::string& value)
|
||||||
|
{
|
||||||
|
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());
|
const auto newScrStringIndex = static_cast<scr_string_t>(m_scr_strings.size());
|
||||||
m_scr_strings.emplace_back(value);
|
m_scr_strings.emplace_back(value);
|
||||||
m_scr_string_lookup[value] = newScrStringIndex;
|
m_scr_string_lookup[value] = newScrStringIndex;
|
||||||
@ -31,6 +90,27 @@ scr_string_t ZoneScriptStrings::AddOrGetScriptString(const std::string& value)
|
|||||||
return newScrStringIndex;
|
return newScrStringIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scr_string_t ZoneScriptStrings::GetScriptString(const char* value) const
|
||||||
|
{
|
||||||
|
if (value == nullptr)
|
||||||
|
{
|
||||||
|
if (m_null_entry_pos >= 0)
|
||||||
|
return static_cast<scr_string_t>(m_null_entry_pos);
|
||||||
|
|
||||||
|
std::ostringstream str;
|
||||||
|
str << "Unable to find script string nullptr";
|
||||||
|
throw std::runtime_error(str.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto existingScriptString = m_scr_string_lookup.find(value);
|
||||||
|
if (existingScriptString != m_scr_string_lookup.end())
|
||||||
|
return existingScriptString->second;
|
||||||
|
|
||||||
|
std::ostringstream str;
|
||||||
|
str << "Unable to find script string \"" << value << "\"";
|
||||||
|
throw std::runtime_error(str.str());
|
||||||
|
}
|
||||||
|
|
||||||
scr_string_t ZoneScriptStrings::GetScriptString(const std::string& value) const
|
scr_string_t ZoneScriptStrings::GetScriptString(const std::string& value) const
|
||||||
{
|
{
|
||||||
const auto existingScriptString = m_scr_string_lookup.find(value);
|
const auto existingScriptString = m_scr_string_lookup.find(value);
|
||||||
@ -52,9 +132,42 @@ bool ZoneScriptStrings::Empty() const
|
|||||||
return m_scr_strings.empty();
|
return m_scr_strings.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* ZoneScriptStrings::CValue(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());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_null_entry_pos == static_cast<int>(index))
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
return m_scr_strings[index].c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& ZoneScriptStrings::Value(const size_t index) const
|
||||||
|
{
|
||||||
|
return (*this)[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& ZoneScriptStrings::Value(const size_t index, bool& isNull) 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());
|
||||||
|
}
|
||||||
|
|
||||||
|
isNull = m_null_entry_pos == static_cast<int>(index);
|
||||||
|
return m_scr_strings[index];
|
||||||
|
}
|
||||||
|
|
||||||
const std::string& ZoneScriptStrings::operator[](const size_t index) const
|
const std::string& ZoneScriptStrings::operator[](const size_t index) const
|
||||||
{
|
{
|
||||||
if(index > m_scr_strings.size())
|
if (index > m_scr_strings.size())
|
||||||
{
|
{
|
||||||
std::ostringstream str;
|
std::ostringstream str;
|
||||||
str << "Script string index '" << index << "' is not inside range of zone script strings (count: " << m_scr_strings.size() << ")";
|
str << "Script string index '" << index << "' is not inside range of zone script strings (count: " << m_scr_strings.size() << ")";
|
||||||
|
@ -10,16 +10,29 @@
|
|||||||
|
|
||||||
class ZoneScriptStrings
|
class ZoneScriptStrings
|
||||||
{
|
{
|
||||||
|
int m_null_entry_pos;
|
||||||
std::vector<std::string> m_scr_strings;
|
std::vector<std::string> m_scr_strings;
|
||||||
std::unordered_map<std::string, scr_string_t> m_scr_string_lookup;
|
std::unordered_map<std::string, scr_string_t> m_scr_string_lookup;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
ZoneScriptStrings();
|
||||||
|
|
||||||
|
void InitializeForExistingZone();
|
||||||
|
void InitializeForExistingZone(const char** scrStrList, size_t scrStrCount);
|
||||||
|
|
||||||
|
void AddScriptString(const char* value);
|
||||||
void AddScriptString(const std::string& value);
|
void AddScriptString(const std::string& value);
|
||||||
|
scr_string_t AddOrGetScriptString(const char* value);
|
||||||
scr_string_t AddOrGetScriptString(const std::string& value);
|
scr_string_t AddOrGetScriptString(const std::string& value);
|
||||||
|
_NODISCARD scr_string_t GetScriptString(const char* value) const;
|
||||||
_NODISCARD scr_string_t GetScriptString(const std::string& value) const;
|
_NODISCARD scr_string_t GetScriptString(const std::string& value) const;
|
||||||
|
|
||||||
_NODISCARD size_t Count() const;
|
_NODISCARD size_t Count() const;
|
||||||
_NODISCARD bool Empty() const;
|
_NODISCARD bool Empty() const;
|
||||||
|
|
||||||
|
_NODISCARD const char* CValue(size_t index) const;
|
||||||
|
_NODISCARD const std::string& Value(size_t index) const;
|
||||||
|
_NODISCARD const std::string& Value(size_t index, bool& isNull) const;
|
||||||
_NODISCARD const std::string& operator[](size_t index) 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 begin() const;
|
||||||
_NODISCARD std::vector<std::string>::const_iterator end() const;
|
_NODISCARD std::vector<std::string>::const_iterator end() const;
|
||||||
|
@ -33,9 +33,9 @@
|
|||||||
using namespace IW3;
|
using namespace IW3;
|
||||||
|
|
||||||
ContentLoader::ContentLoader()
|
ContentLoader::ContentLoader()
|
||||||
|
: varXAsset(nullptr),
|
||||||
|
varScriptStringList(nullptr)
|
||||||
{
|
{
|
||||||
varXAsset = nullptr;
|
|
||||||
varScriptStringList = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
||||||
@ -55,17 +55,8 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
|||||||
varXString = varScriptStringList->strings;
|
varXString = varScriptStringList->strings;
|
||||||
LoadXStringArray(true, varScriptStringList->count);
|
LoadXStringArray(true, varScriptStringList->count);
|
||||||
|
|
||||||
for (int i = 0; i < varScriptStringList->count; i++)
|
if (varScriptStringList->strings && varScriptStringList->count > 0)
|
||||||
{
|
m_zone->m_script_strings.InitializeForExistingZone(varScriptStringList->strings, static_cast<size_t>(varScriptStringList->count));
|
||||||
if (varScriptStringList->strings[i])
|
|
||||||
{
|
|
||||||
m_zone->m_script_strings.AddScriptString(varScriptStringList->strings[i]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_zone->m_script_strings.AddScriptString("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_stream->PopBlock();
|
m_stream->PopBlock();
|
||||||
@ -73,7 +64,7 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
|||||||
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLoader::LoadXAsset(const bool atStreamStart)
|
void ContentLoader::LoadXAsset(const bool atStreamStart) const
|
||||||
{
|
{
|
||||||
#define LOAD_ASSET(type_index, typeName, headerEntry) \
|
#define LOAD_ASSET(type_index, typeName, headerEntry) \
|
||||||
case type_index: \
|
case type_index: \
|
||||||
|
@ -12,7 +12,7 @@ namespace IW3
|
|||||||
|
|
||||||
void LoadScriptStringList(bool atStreamStart);
|
void LoadScriptStringList(bool atStreamStart);
|
||||||
|
|
||||||
void LoadXAsset(bool atStreamStart);
|
void LoadXAsset(bool atStreamStart) const;
|
||||||
void LoadXAssetArray(bool atStreamStart, size_t count);
|
void LoadXAssetArray(bool atStreamStart, size_t count);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -43,9 +43,9 @@
|
|||||||
using namespace IW4;
|
using namespace IW4;
|
||||||
|
|
||||||
ContentLoader::ContentLoader()
|
ContentLoader::ContentLoader()
|
||||||
|
: varXAsset(nullptr),
|
||||||
|
varScriptStringList(nullptr)
|
||||||
{
|
{
|
||||||
varXAsset = nullptr;
|
|
||||||
varScriptStringList = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
||||||
@ -65,17 +65,8 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
|||||||
varXString = varScriptStringList->strings;
|
varXString = varScriptStringList->strings;
|
||||||
LoadXStringArray(true, varScriptStringList->count);
|
LoadXStringArray(true, varScriptStringList->count);
|
||||||
|
|
||||||
for (int i = 0; i < varScriptStringList->count; i++)
|
if (varScriptStringList->strings && varScriptStringList->count > 0)
|
||||||
{
|
m_zone->m_script_strings.InitializeForExistingZone(varScriptStringList->strings, static_cast<size_t>(varScriptStringList->count));
|
||||||
if (varScriptStringList->strings[i])
|
|
||||||
{
|
|
||||||
m_zone->m_script_strings.AddScriptString(varScriptStringList->strings[i]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_zone->m_script_strings.AddScriptString("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_stream->PopBlock();
|
m_stream->PopBlock();
|
||||||
@ -83,7 +74,7 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
|||||||
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLoader::LoadXAsset(const bool atStreamStart)
|
void ContentLoader::LoadXAsset(const bool atStreamStart) const
|
||||||
{
|
{
|
||||||
#define LOAD_ASSET(type_index, typeName, headerEntry) \
|
#define LOAD_ASSET(type_index, typeName, headerEntry) \
|
||||||
case type_index: \
|
case type_index: \
|
||||||
|
@ -12,7 +12,7 @@ namespace IW4
|
|||||||
|
|
||||||
void LoadScriptStringList(bool atStreamStart);
|
void LoadScriptStringList(bool atStreamStart);
|
||||||
|
|
||||||
void LoadXAsset(bool atStreamStart);
|
void LoadXAsset(bool atStreamStart) const;
|
||||||
void LoadXAssetArray(bool atStreamStart, size_t count);
|
void LoadXAssetArray(bool atStreamStart, size_t count);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -48,9 +48,9 @@
|
|||||||
using namespace IW5;
|
using namespace IW5;
|
||||||
|
|
||||||
ContentLoader::ContentLoader()
|
ContentLoader::ContentLoader()
|
||||||
|
: varXAsset(nullptr),
|
||||||
|
varScriptStringList(nullptr)
|
||||||
{
|
{
|
||||||
varXAsset = nullptr;
|
|
||||||
varScriptStringList = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
||||||
@ -70,17 +70,8 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
|||||||
varXString = varScriptStringList->strings;
|
varXString = varScriptStringList->strings;
|
||||||
LoadXStringArray(true, varScriptStringList->count);
|
LoadXStringArray(true, varScriptStringList->count);
|
||||||
|
|
||||||
for (int i = 0; i < varScriptStringList->count; i++)
|
if (varScriptStringList->strings && varScriptStringList->count > 0)
|
||||||
{
|
m_zone->m_script_strings.InitializeForExistingZone(varScriptStringList->strings, static_cast<size_t>(varScriptStringList->count));
|
||||||
if (varScriptStringList->strings[i])
|
|
||||||
{
|
|
||||||
m_zone->m_script_strings.AddScriptString(varScriptStringList->strings[i]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_zone->m_script_strings.AddScriptString("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_stream->PopBlock();
|
m_stream->PopBlock();
|
||||||
@ -88,7 +79,7 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
|||||||
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLoader::LoadXAsset(const bool atStreamStart)
|
void ContentLoader::LoadXAsset(const bool atStreamStart) const
|
||||||
{
|
{
|
||||||
#define LOAD_ASSET(type_index, typeName, headerEntry) \
|
#define LOAD_ASSET(type_index, typeName, headerEntry) \
|
||||||
case type_index: \
|
case type_index: \
|
||||||
|
@ -12,7 +12,7 @@ namespace IW5
|
|||||||
|
|
||||||
void LoadScriptStringList(bool atStreamStart);
|
void LoadScriptStringList(bool atStreamStart);
|
||||||
|
|
||||||
void LoadXAsset(bool atStreamStart);
|
void LoadXAsset(bool atStreamStart) const;
|
||||||
void LoadXAssetArray(bool atStreamStart, size_t count);
|
void LoadXAssetArray(bool atStreamStart, size_t count);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -40,9 +40,9 @@
|
|||||||
using namespace T5;
|
using namespace T5;
|
||||||
|
|
||||||
ContentLoader::ContentLoader()
|
ContentLoader::ContentLoader()
|
||||||
|
: varXAsset(nullptr),
|
||||||
|
varScriptStringList(nullptr)
|
||||||
{
|
{
|
||||||
varXAsset = nullptr;
|
|
||||||
varScriptStringList = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
||||||
@ -62,17 +62,8 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
|||||||
varXString = varScriptStringList->strings;
|
varXString = varScriptStringList->strings;
|
||||||
LoadXStringArray(true, varScriptStringList->count);
|
LoadXStringArray(true, varScriptStringList->count);
|
||||||
|
|
||||||
for (int i = 0; i < varScriptStringList->count; i++)
|
if (varScriptStringList->strings && varScriptStringList->count > 0)
|
||||||
{
|
m_zone->m_script_strings.InitializeForExistingZone(varScriptStringList->strings, static_cast<size_t>(varScriptStringList->count));
|
||||||
if (varScriptStringList->strings[i])
|
|
||||||
{
|
|
||||||
m_zone->m_script_strings.AddScriptString(varScriptStringList->strings[i]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_zone->m_script_strings.AddScriptString("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_stream->PopBlock();
|
m_stream->PopBlock();
|
||||||
@ -80,7 +71,7 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
|||||||
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLoader::LoadXAsset(const bool atStreamStart)
|
void ContentLoader::LoadXAsset(const bool atStreamStart) const
|
||||||
{
|
{
|
||||||
#define LOAD_ASSET(type_index, typeName, headerEntry) \
|
#define LOAD_ASSET(type_index, typeName, headerEntry) \
|
||||||
case type_index: \
|
case type_index: \
|
||||||
|
@ -12,7 +12,7 @@ namespace T5
|
|||||||
|
|
||||||
void LoadScriptStringList(bool atStreamStart);
|
void LoadScriptStringList(bool atStreamStart);
|
||||||
|
|
||||||
void LoadXAsset(bool atStreamStart);
|
void LoadXAsset(bool atStreamStart) const;
|
||||||
void LoadXAssetArray(bool atStreamStart, size_t count);
|
void LoadXAssetArray(bool atStreamStart, size_t count);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -56,9 +56,9 @@
|
|||||||
using namespace T6;
|
using namespace T6;
|
||||||
|
|
||||||
ContentLoader::ContentLoader()
|
ContentLoader::ContentLoader()
|
||||||
|
: varXAsset(nullptr),
|
||||||
|
varScriptStringList(nullptr)
|
||||||
{
|
{
|
||||||
varXAsset = nullptr;
|
|
||||||
varScriptStringList = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
||||||
@ -78,17 +78,8 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
|||||||
varXString = varScriptStringList->strings;
|
varXString = varScriptStringList->strings;
|
||||||
LoadXStringArray(true, varScriptStringList->count);
|
LoadXStringArray(true, varScriptStringList->count);
|
||||||
|
|
||||||
for (int i = 0; i < varScriptStringList->count; i++)
|
if (varScriptStringList->strings && varScriptStringList->count > 0)
|
||||||
{
|
m_zone->m_script_strings.InitializeForExistingZone(varScriptStringList->strings, static_cast<size_t>(varScriptStringList->count));
|
||||||
if (varScriptStringList->strings[i])
|
|
||||||
{
|
|
||||||
m_zone->m_script_strings.AddScriptString(varScriptStringList->strings[i]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_zone->m_script_strings.AddScriptString("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_stream->PopBlock();
|
m_stream->PopBlock();
|
||||||
@ -96,7 +87,7 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
|||||||
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentLoader::LoadXAsset(const bool atStreamStart)
|
void ContentLoader::LoadXAsset(const bool atStreamStart) const
|
||||||
{
|
{
|
||||||
#define LOAD_ASSET(type_index, typeName, headerEntry) \
|
#define LOAD_ASSET(type_index, typeName, headerEntry) \
|
||||||
case type_index: \
|
case type_index: \
|
||||||
|
@ -12,7 +12,7 @@ namespace T6
|
|||||||
|
|
||||||
void LoadScriptStringList(bool atStreamStart);
|
void LoadScriptStringList(bool atStreamStart);
|
||||||
|
|
||||||
void LoadXAsset(bool atStreamStart);
|
void LoadXAsset(bool atStreamStart) const;
|
||||||
void LoadXAssetArray(bool atStreamStart, size_t count);
|
void LoadXAssetArray(bool atStreamStart, size_t count);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -8,10 +8,6 @@ AssetLoader::AssetLoader(const asset_type_t assetType, Zone* zone, IZoneInputStr
|
|||||||
m_asset_type(assetType),
|
m_asset_type(assetType),
|
||||||
varScriptString(nullptr)
|
varScriptString(nullptr)
|
||||||
{
|
{
|
||||||
m_asset_type = assetType;
|
|
||||||
m_zone = zone;
|
|
||||||
m_stream = stream;
|
|
||||||
varScriptString = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssetLoader::AddDependency(XAssetInfoGeneric* assetInfo)
|
void AssetLoader::AddDependency(XAssetInfoGeneric* assetInfo)
|
||||||
|
@ -45,13 +45,11 @@ void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memo
|
|||||||
if (!m_zone->m_script_strings.Empty())
|
if (!m_zone->m_script_strings.Empty())
|
||||||
{
|
{
|
||||||
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
||||||
xAssetList.stringList.count = m_zone->m_script_strings.Count();
|
xAssetList.stringList.count = static_cast<int>(m_zone->m_script_strings.Count());
|
||||||
xAssetList.stringList.strings = static_cast<const char**>(memory.Alloc(sizeof(const char*) * 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.Count(); i++)
|
for (auto i = 0u; i < m_zone->m_script_strings.Count(); i++)
|
||||||
{
|
xAssetList.stringList.strings[i] = m_zone->m_script_strings.CValue(i);
|
||||||
xAssetList.stringList.strings[i] = m_zone->m_script_strings[i].c_str();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -62,7 +60,7 @@ void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memo
|
|||||||
const auto assetCount = m_zone->m_pools->GetTotalAssetCount();
|
const auto assetCount = m_zone->m_pools->GetTotalAssetCount();
|
||||||
if (assetCount > 0)
|
if (assetCount > 0)
|
||||||
{
|
{
|
||||||
xAssetList.assetCount = assetCount;
|
xAssetList.assetCount = static_cast<int>(assetCount);
|
||||||
xAssetList.assets = static_cast<XAsset*>(memory.Alloc(sizeof(XAsset) * assetCount));
|
xAssetList.assets = static_cast<XAsset*>(memory.Alloc(sizeof(XAsset) * assetCount));
|
||||||
|
|
||||||
const auto end = m_zone->m_pools->end();
|
const auto end = m_zone->m_pools->end();
|
||||||
|
@ -55,13 +55,11 @@ void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memo
|
|||||||
if (!m_zone->m_script_strings.Empty())
|
if (!m_zone->m_script_strings.Empty())
|
||||||
{
|
{
|
||||||
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
||||||
xAssetList.stringList.count = m_zone->m_script_strings.Count();
|
xAssetList.stringList.count = static_cast<int>(m_zone->m_script_strings.Count());
|
||||||
xAssetList.stringList.strings = static_cast<const char**>(memory.Alloc(sizeof(const char*) * 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.Count(); i++)
|
for (auto i = 0u; i < m_zone->m_script_strings.Count(); i++)
|
||||||
{
|
xAssetList.stringList.strings[i] = m_zone->m_script_strings.CValue(i);
|
||||||
xAssetList.stringList.strings[i] = m_zone->m_script_strings[i].c_str();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -72,7 +70,7 @@ void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memo
|
|||||||
const auto assetCount = m_zone->m_pools->GetTotalAssetCount();
|
const auto assetCount = m_zone->m_pools->GetTotalAssetCount();
|
||||||
if (assetCount > 0)
|
if (assetCount > 0)
|
||||||
{
|
{
|
||||||
xAssetList.assetCount = assetCount;
|
xAssetList.assetCount = static_cast<int>(assetCount);
|
||||||
xAssetList.assets = static_cast<XAsset*>(memory.Alloc(sizeof(XAsset) * assetCount));
|
xAssetList.assets = static_cast<XAsset*>(memory.Alloc(sizeof(XAsset) * assetCount));
|
||||||
|
|
||||||
const auto end = m_zone->m_pools->end();
|
const auto end = m_zone->m_pools->end();
|
||||||
|
@ -60,13 +60,11 @@ void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memo
|
|||||||
if (!m_zone->m_script_strings.Empty())
|
if (!m_zone->m_script_strings.Empty())
|
||||||
{
|
{
|
||||||
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
||||||
xAssetList.stringList.count = m_zone->m_script_strings.Count();
|
xAssetList.stringList.count = static_cast<int>(m_zone->m_script_strings.Count());
|
||||||
xAssetList.stringList.strings = static_cast<const char**>(memory.Alloc(sizeof(const char*) * 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.Count(); i++)
|
for (auto i = 0u; i < m_zone->m_script_strings.Count(); i++)
|
||||||
{
|
xAssetList.stringList.strings[i] = m_zone->m_script_strings.CValue(i);
|
||||||
xAssetList.stringList.strings[i] = m_zone->m_script_strings[i].c_str();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -77,7 +75,7 @@ void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memo
|
|||||||
const auto assetCount = m_zone->m_pools->GetTotalAssetCount();
|
const auto assetCount = m_zone->m_pools->GetTotalAssetCount();
|
||||||
if (assetCount > 0)
|
if (assetCount > 0)
|
||||||
{
|
{
|
||||||
xAssetList.assetCount = assetCount;
|
xAssetList.assetCount = static_cast<int>(assetCount);
|
||||||
xAssetList.assets = static_cast<XAsset*>(memory.Alloc(sizeof(XAsset) * assetCount));
|
xAssetList.assets = static_cast<XAsset*>(memory.Alloc(sizeof(XAsset) * assetCount));
|
||||||
|
|
||||||
const auto end = m_zone->m_pools->end();
|
const auto end = m_zone->m_pools->end();
|
||||||
|
@ -52,13 +52,11 @@ void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memo
|
|||||||
if (!m_zone->m_script_strings.Empty())
|
if (!m_zone->m_script_strings.Empty())
|
||||||
{
|
{
|
||||||
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
||||||
xAssetList.stringList.count = m_zone->m_script_strings.Count();
|
xAssetList.stringList.count = static_cast<int>(m_zone->m_script_strings.Count());
|
||||||
xAssetList.stringList.strings = static_cast<const char**>(memory.Alloc(sizeof(const char*) * 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.Count(); i++)
|
for (auto i = 0u; i < m_zone->m_script_strings.Count(); i++)
|
||||||
{
|
xAssetList.stringList.strings[i] = m_zone->m_script_strings.CValue(i);
|
||||||
xAssetList.stringList.strings[i] = m_zone->m_script_strings[i].c_str();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -69,7 +67,7 @@ void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memo
|
|||||||
const auto assetCount = m_zone->m_pools->GetTotalAssetCount();
|
const auto assetCount = m_zone->m_pools->GetTotalAssetCount();
|
||||||
if (assetCount > 0)
|
if (assetCount > 0)
|
||||||
{
|
{
|
||||||
xAssetList.assetCount = assetCount;
|
xAssetList.assetCount = static_cast<int>(assetCount);
|
||||||
xAssetList.assets = static_cast<XAsset*>(memory.Alloc(sizeof(XAsset) * assetCount));
|
xAssetList.assets = static_cast<XAsset*>(memory.Alloc(sizeof(XAsset) * assetCount));
|
||||||
|
|
||||||
const auto end = m_zone->m_pools->end();
|
const auto end = m_zone->m_pools->end();
|
||||||
|
@ -68,13 +68,11 @@ void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memo
|
|||||||
if (!m_zone->m_script_strings.Empty())
|
if (!m_zone->m_script_strings.Empty())
|
||||||
{
|
{
|
||||||
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
||||||
xAssetList.stringList.count = m_zone->m_script_strings.Count();
|
xAssetList.stringList.count = static_cast<int>(m_zone->m_script_strings.Count());
|
||||||
xAssetList.stringList.strings = static_cast<const char**>(memory.Alloc(sizeof(const char*) * 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.Count(); i++)
|
for (auto i = 0u; i < m_zone->m_script_strings.Count(); i++)
|
||||||
{
|
xAssetList.stringList.strings[i] = m_zone->m_script_strings.CValue(i);
|
||||||
xAssetList.stringList.strings[i] = m_zone->m_script_strings[i].c_str();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -88,7 +86,7 @@ void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memo
|
|||||||
const auto assetCount = m_zone->m_pools->GetTotalAssetCount();
|
const auto assetCount = m_zone->m_pools->GetTotalAssetCount();
|
||||||
if (assetCount > 0)
|
if (assetCount > 0)
|
||||||
{
|
{
|
||||||
xAssetList.assetCount = assetCount;
|
xAssetList.assetCount = static_cast<int>(assetCount);
|
||||||
xAssetList.assets = static_cast<XAsset*>(memory.Alloc(sizeof(XAsset) * assetCount));
|
xAssetList.assets = static_cast<XAsset*>(memory.Alloc(sizeof(XAsset) * assetCount));
|
||||||
|
|
||||||
const auto end = m_zone->m_pools->end();
|
const auto end = m_zone->m_pools->end();
|
||||||
|
@ -17,7 +17,7 @@ scr_string_t AssetWriter::UseScriptString(const scr_string_t scrString) const
|
|||||||
if (m_asset->m_zone == m_zone)
|
if (m_asset->m_zone == m_zone)
|
||||||
return scrString;
|
return scrString;
|
||||||
|
|
||||||
const auto strValue = m_asset->m_zone->m_script_strings[scrString];
|
const auto strValue = m_asset->m_zone->m_script_strings.CValue(scrString);
|
||||||
return m_zone->m_script_strings.GetScriptString(strValue);
|
return m_zone->m_script_strings.GetScriptString(strValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user