mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-05-07 13:04:58 +00:00
Merge pull request #427 from Laupetin/refactor/zone-loading-code-style
refactor: zone loading code style
This commit is contained in:
commit
0dde2478a7
@ -11,7 +11,7 @@ namespace
|
||||
{
|
||||
void ConfigureCompilers(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
auto& memory = zone.Memory();
|
||||
|
||||
// No compilers yet
|
||||
}
|
||||
@ -23,7 +23,7 @@ namespace
|
||||
ZoneAssetCreationStateContainer& zoneStates,
|
||||
IOutputPath& outDir)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
auto& memory = zone.Memory();
|
||||
|
||||
if (ImageIwdPostProcessor<AssetImage>::AppliesToZoneDefinition(zoneDefinition))
|
||||
collection.AddAssetPostProcessor(std::make_unique<ImageIwdPostProcessor<AssetImage>>(zoneDefinition, searchPath, zoneStates, outDir));
|
||||
|
@ -11,7 +11,7 @@ namespace
|
||||
{
|
||||
void ConfigureCompilers(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
auto& memory = zone.Memory();
|
||||
|
||||
// No compilers yet
|
||||
}
|
||||
@ -23,7 +23,7 @@ namespace
|
||||
ZoneAssetCreationStateContainer& zoneStates,
|
||||
IOutputPath& outDir)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
auto& memory = zone.Memory();
|
||||
|
||||
if (ImageIwdPostProcessor<AssetImage>::AppliesToZoneDefinition(zoneDefinition))
|
||||
collection.AddAssetPostProcessor(std::make_unique<ImageIwdPostProcessor<AssetImage>>(zoneDefinition, searchPath, zoneStates, outDir));
|
||||
|
@ -11,7 +11,7 @@ namespace
|
||||
{
|
||||
void ConfigureCompilers(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
auto& memory = zone.Memory();
|
||||
|
||||
// No compilers yet
|
||||
}
|
||||
@ -23,7 +23,7 @@ namespace
|
||||
ZoneAssetCreationStateContainer& zoneStates,
|
||||
IOutputPath& outDir)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
auto& memory = zone.Memory();
|
||||
|
||||
if (ImageIwdPostProcessor<AssetImage>::AppliesToZoneDefinition(zoneDefinition))
|
||||
collection.AddAssetPostProcessor(std::make_unique<ImageIwdPostProcessor<AssetImage>>(zoneDefinition, searchPath, zoneStates, outDir));
|
||||
|
@ -11,7 +11,7 @@ namespace
|
||||
{
|
||||
void ConfigureCompilers(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
auto& memory = zone.Memory();
|
||||
|
||||
// No compilers yet
|
||||
}
|
||||
@ -23,7 +23,7 @@ namespace
|
||||
ZoneAssetCreationStateContainer& zoneStates,
|
||||
IOutputPath& outDir)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
auto& memory = zone.Memory();
|
||||
|
||||
if (ImageIwdPostProcessor<AssetImage>::AppliesToZoneDefinition(zoneDefinition))
|
||||
collection.AddAssetPostProcessor(std::make_unique<ImageIwdPostProcessor<AssetImage>>(zoneDefinition, searchPath, zoneStates, outDir));
|
||||
|
@ -17,7 +17,7 @@ namespace
|
||||
ISearchPath& searchPath,
|
||||
ZoneAssetCreationStateContainer& zoneStates)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
auto& memory = zone.Memory();
|
||||
|
||||
collection.AddAssetCreator(CreateKeyValuePairsCompiler(memory, zone, zoneDefinition.m_zone_definition, zoneStates));
|
||||
}
|
||||
@ -29,7 +29,7 @@ namespace
|
||||
ZoneAssetCreationStateContainer& zoneStates,
|
||||
IOutputPath& outDir)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
auto& memory = zone.Memory();
|
||||
|
||||
if (ImageIPakPostProcessor<AssetImage>::AppliesToZoneDefinition(zoneDefinition))
|
||||
collection.AddAssetPostProcessor(std::make_unique<ImageIPakPostProcessor<AssetImage>>(zoneDefinition, searchPath, zoneStates, outDir));
|
||||
|
@ -21,7 +21,7 @@ namespace
|
||||
{
|
||||
void ConfigureDefaultCreators(AssetCreatorCollection& collection, Zone& zone)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
auto& memory = zone.Memory();
|
||||
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetPhysPreset>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetXAnim>>(memory));
|
||||
@ -85,7 +85,7 @@ namespace
|
||||
|
||||
void ConfigureLoaders(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
auto& memory = zone.Memory();
|
||||
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderPhysPreset>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderXAnim>(memory));
|
||||
|
@ -12,10 +12,10 @@ MenuConversionZoneState::MenuConversionZoneState()
|
||||
|
||||
void MenuConversionZoneState::Inject(ZoneAssetCreationInjection& inject)
|
||||
{
|
||||
auto* memory = inject.m_zone.GetMemory();
|
||||
auto& memory = inject.m_zone.Memory();
|
||||
|
||||
m_zone = &inject.m_zone;
|
||||
m_supporting_data = memory->Alloc<ExpressionSupportingData>();
|
||||
m_supporting_data = memory.Alloc<ExpressionSupportingData>();
|
||||
}
|
||||
|
||||
Statement_s* MenuConversionZoneState::FindFunction(const std::string& functionName)
|
||||
@ -43,10 +43,10 @@ size_t MenuConversionZoneState::AddStaticDvar(const std::string& dvarName)
|
||||
if (foundDvar != m_dvars_by_name.end())
|
||||
return foundDvar->second;
|
||||
|
||||
auto* memory = m_zone->GetMemory();
|
||||
auto* staticDvar = memory->Alloc<StaticDvar>();
|
||||
auto& memory = m_zone->Memory();
|
||||
auto* staticDvar = memory.Alloc<StaticDvar>();
|
||||
|
||||
staticDvar->dvarName = memory->Dup(dvarName.c_str());
|
||||
staticDvar->dvarName = memory.Dup(dvarName.c_str());
|
||||
staticDvar->dvar = nullptr;
|
||||
|
||||
const auto staticDvarIndex = m_static_dvars.size();
|
||||
@ -63,8 +63,8 @@ const char* MenuConversionZoneState::AddString(const std::string& str)
|
||||
if (foundString != m_strings_by_value.end())
|
||||
return foundString->second;
|
||||
|
||||
auto* memory = m_zone->GetMemory();
|
||||
const auto* strDuped = memory->Dup(str.c_str());
|
||||
auto& memory = m_zone->Memory();
|
||||
const auto* strDuped = memory.Dup(str.c_str());
|
||||
|
||||
m_strings.push_back(strDuped);
|
||||
m_strings_by_value.emplace(std::make_pair(str, strDuped));
|
||||
@ -79,24 +79,24 @@ void MenuConversionZoneState::AddLoadedFile(std::string loadedFileName, std::vec
|
||||
|
||||
void MenuConversionZoneState::FinalizeSupportingData() const
|
||||
{
|
||||
auto* memory = m_zone->GetMemory();
|
||||
auto& memory = m_zone->Memory();
|
||||
|
||||
m_supporting_data->uifunctions.totalFunctions = static_cast<int>(m_functions.size());
|
||||
m_supporting_data->staticDvarList.numStaticDvars = static_cast<int>(m_static_dvars.size());
|
||||
m_supporting_data->uiStrings.totalStrings = static_cast<int>(m_strings.size());
|
||||
|
||||
if (m_supporting_data->uifunctions.functions)
|
||||
memory->Free(m_supporting_data->uifunctions.functions);
|
||||
memory.Free(m_supporting_data->uifunctions.functions);
|
||||
|
||||
if (m_supporting_data->staticDvarList.staticDvars)
|
||||
memory->Free(m_supporting_data->staticDvarList.staticDvars);
|
||||
memory.Free(m_supporting_data->staticDvarList.staticDvars);
|
||||
|
||||
if (m_supporting_data->uiStrings.strings)
|
||||
memory->Free(m_supporting_data->uiStrings.strings);
|
||||
memory.Free(m_supporting_data->uiStrings.strings);
|
||||
|
||||
if (!m_functions.empty())
|
||||
{
|
||||
m_supporting_data->uifunctions.functions = memory->Alloc<Statement_s*>(m_functions.size());
|
||||
m_supporting_data->uifunctions.functions = memory.Alloc<Statement_s*>(m_functions.size());
|
||||
memcpy(m_supporting_data->uifunctions.functions, m_functions.data(), sizeof(void*) * m_functions.size());
|
||||
}
|
||||
else
|
||||
@ -104,7 +104,7 @@ void MenuConversionZoneState::FinalizeSupportingData() const
|
||||
|
||||
if (!m_static_dvars.empty())
|
||||
{
|
||||
m_supporting_data->staticDvarList.staticDvars = memory->Alloc<StaticDvar*>(m_static_dvars.size());
|
||||
m_supporting_data->staticDvarList.staticDvars = memory.Alloc<StaticDvar*>(m_static_dvars.size());
|
||||
memcpy(m_supporting_data->staticDvarList.staticDvars, m_static_dvars.data(), sizeof(void*) * m_static_dvars.size());
|
||||
}
|
||||
else
|
||||
@ -112,7 +112,7 @@ void MenuConversionZoneState::FinalizeSupportingData() const
|
||||
|
||||
if (!m_strings.empty())
|
||||
{
|
||||
m_supporting_data->uiStrings.strings = memory->Alloc<const char*>(m_strings.size());
|
||||
m_supporting_data->uiStrings.strings = memory.Alloc<const char*>(m_strings.size());
|
||||
memcpy(m_supporting_data->uiStrings.strings, m_strings.data(), sizeof(void*) * m_strings.size());
|
||||
}
|
||||
else
|
||||
|
@ -34,7 +34,7 @@ namespace
|
||||
{
|
||||
void ConfigureDefaultCreators(AssetCreatorCollection& collection, Zone& zone)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
auto& memory = zone.Memory();
|
||||
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetPhysPreset>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetPhysCollMap>>(memory));
|
||||
@ -118,7 +118,7 @@ namespace
|
||||
|
||||
void ConfigureLoaders(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath, IGdtQueryable& gdt)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
auto& memory = zone.Memory();
|
||||
|
||||
collection.AddAssetCreator(std::make_unique<RawLoaderPhysPreset>(memory, searchPath, zone));
|
||||
collection.AddAssetCreator(std::make_unique<GdtLoaderPhysPreset>(memory, gdt, zone));
|
||||
|
@ -12,10 +12,10 @@ MenuConversionZoneState::MenuConversionZoneState()
|
||||
|
||||
void MenuConversionZoneState::Inject(ZoneAssetCreationInjection& inject)
|
||||
{
|
||||
auto* memory = inject.m_zone.GetMemory();
|
||||
auto& memory = inject.m_zone.Memory();
|
||||
|
||||
m_zone = &inject.m_zone;
|
||||
m_supporting_data = memory->Alloc<ExpressionSupportingData>();
|
||||
m_supporting_data = memory.Alloc<ExpressionSupportingData>();
|
||||
}
|
||||
|
||||
Statement_s* MenuConversionZoneState::FindFunction(const std::string& functionName)
|
||||
@ -43,10 +43,10 @@ size_t MenuConversionZoneState::AddStaticDvar(const std::string& dvarName)
|
||||
if (foundDvar != m_dvars_by_name.end())
|
||||
return foundDvar->second;
|
||||
|
||||
auto* memory = m_zone->GetMemory();
|
||||
auto* staticDvar = memory->Alloc<StaticDvar>();
|
||||
auto& memory = m_zone->Memory();
|
||||
auto* staticDvar = memory.Alloc<StaticDvar>();
|
||||
|
||||
staticDvar->dvarName = memory->Dup(dvarName.c_str());
|
||||
staticDvar->dvarName = memory.Dup(dvarName.c_str());
|
||||
staticDvar->dvar = nullptr;
|
||||
|
||||
const auto staticDvarIndex = m_static_dvars.size();
|
||||
@ -63,8 +63,8 @@ const char* MenuConversionZoneState::AddString(const std::string& str)
|
||||
if (foundString != m_strings_by_value.end())
|
||||
return foundString->second;
|
||||
|
||||
auto* memory = m_zone->GetMemory();
|
||||
const auto* strDuped = memory->Dup(str.c_str());
|
||||
auto& memory = m_zone->Memory();
|
||||
const auto* strDuped = memory.Dup(str.c_str());
|
||||
|
||||
m_strings.push_back(strDuped);
|
||||
m_strings_by_value.emplace(std::make_pair(str, strDuped));
|
||||
@ -79,24 +79,24 @@ void MenuConversionZoneState::AddLoadedFile(std::string loadedFileName, std::vec
|
||||
|
||||
void MenuConversionZoneState::FinalizeSupportingData() const
|
||||
{
|
||||
auto* memory = m_zone->GetMemory();
|
||||
auto& memory = m_zone->Memory();
|
||||
|
||||
m_supporting_data->uifunctions.totalFunctions = static_cast<int>(m_functions.size());
|
||||
m_supporting_data->staticDvarList.numStaticDvars = static_cast<int>(m_static_dvars.size());
|
||||
m_supporting_data->uiStrings.totalStrings = static_cast<int>(m_strings.size());
|
||||
|
||||
if (m_supporting_data->uifunctions.functions)
|
||||
memory->Free(m_supporting_data->uifunctions.functions);
|
||||
memory.Free(m_supporting_data->uifunctions.functions);
|
||||
|
||||
if (m_supporting_data->staticDvarList.staticDvars)
|
||||
memory->Free(m_supporting_data->staticDvarList.staticDvars);
|
||||
memory.Free(m_supporting_data->staticDvarList.staticDvars);
|
||||
|
||||
if (m_supporting_data->uiStrings.strings)
|
||||
memory->Free(m_supporting_data->uiStrings.strings);
|
||||
memory.Free(m_supporting_data->uiStrings.strings);
|
||||
|
||||
if (!m_functions.empty())
|
||||
{
|
||||
m_supporting_data->uifunctions.functions = memory->Alloc<Statement_s*>(m_functions.size());
|
||||
m_supporting_data->uifunctions.functions = memory.Alloc<Statement_s*>(m_functions.size());
|
||||
memcpy(m_supporting_data->uifunctions.functions, m_functions.data(), sizeof(void*) * m_functions.size());
|
||||
}
|
||||
else
|
||||
@ -104,7 +104,7 @@ void MenuConversionZoneState::FinalizeSupportingData() const
|
||||
|
||||
if (!m_static_dvars.empty())
|
||||
{
|
||||
m_supporting_data->staticDvarList.staticDvars = memory->Alloc<StaticDvar*>(m_static_dvars.size());
|
||||
m_supporting_data->staticDvarList.staticDvars = memory.Alloc<StaticDvar*>(m_static_dvars.size());
|
||||
memcpy(m_supporting_data->staticDvarList.staticDvars, m_static_dvars.data(), sizeof(void*) * m_static_dvars.size());
|
||||
}
|
||||
else
|
||||
@ -112,7 +112,7 @@ void MenuConversionZoneState::FinalizeSupportingData() const
|
||||
|
||||
if (!m_strings.empty())
|
||||
{
|
||||
m_supporting_data->uiStrings.strings = memory->Alloc<const char*>(m_strings.size());
|
||||
m_supporting_data->uiStrings.strings = memory.Alloc<const char*>(m_strings.size());
|
||||
memcpy(m_supporting_data->uiStrings.strings, m_strings.data(), sizeof(void*) * m_strings.size());
|
||||
}
|
||||
else
|
||||
|
@ -29,7 +29,7 @@ namespace
|
||||
{
|
||||
void ConfigureDefaultCreators(AssetCreatorCollection& collection, Zone& zone)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
auto& memory = zone.Memory();
|
||||
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetPhysPreset>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetPhysCollMap>>(memory));
|
||||
@ -119,7 +119,7 @@ namespace
|
||||
|
||||
void ConfigureLoaders(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath, IGdtQueryable& gdt)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
auto& memory = zone.Memory();
|
||||
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderPhysPreset>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderPhysCollMap>(memory));
|
||||
|
@ -21,7 +21,7 @@ namespace
|
||||
{
|
||||
void ConfigureDefaultCreators(AssetCreatorCollection& collection, Zone& zone)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
auto& memory = zone.Memory();
|
||||
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetPhysPreset>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetPhysConstraints>>(memory));
|
||||
@ -97,7 +97,7 @@ namespace
|
||||
|
||||
void ConfigureLoaders(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
auto& memory = zone.Memory();
|
||||
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderPhysPreset>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderPhysConstraints>(memory));
|
||||
|
@ -284,7 +284,7 @@ namespace T6
|
||||
{
|
||||
void ConfigureDefaultCreators(AssetCreatorCollection& collection, Zone& zone)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
auto& memory = zone.Memory();
|
||||
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetPhysPreset>>(memory));
|
||||
collection.AddDefaultAssetCreator(std::make_unique<DefaultAssetCreator<AssetPhysConstraints>>(memory));
|
||||
@ -390,7 +390,7 @@ namespace T6
|
||||
|
||||
void ConfigureLoaders(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath, IGdtQueryable& gdt)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
auto& memory = zone.Memory();
|
||||
|
||||
collection.AddAssetCreator(CreateRawPhysPresetLoader(memory, searchPath, zone));
|
||||
collection.AddAssetCreator(CreateGdtPhysPresetLoader(memory, searchPath, gdt, zone));
|
||||
|
@ -27,7 +27,7 @@ void CodeGenerator::SetupTemplates()
|
||||
m_template_mapping["assetstructtests"] = std::make_unique<AssetStructTestsTemplate>();
|
||||
}
|
||||
|
||||
bool CodeGenerator::GenerateCodeForTemplate(RenderingContext* context, ICodeTemplate* codeTemplate) const
|
||||
bool CodeGenerator::GenerateCodeForTemplate(const RenderingContext& context, ICodeTemplate* codeTemplate) const
|
||||
{
|
||||
for (const auto& codeFile : codeTemplate->GetFilesToRender(context))
|
||||
{
|
||||
@ -110,7 +110,7 @@ bool CodeGenerator::GenerateCode(IDataRepository* repository)
|
||||
for (auto* asset : assets)
|
||||
{
|
||||
auto context = RenderingContext::BuildContext(repository, asset);
|
||||
if (!GenerateCodeForTemplate(context.get(), foundTemplate->second.get()))
|
||||
if (!GenerateCodeForTemplate(*context, foundTemplate->second.get()))
|
||||
{
|
||||
std::cerr << std::format(
|
||||
"Failed to generate code for asset '{}' with preset '{}'\n", asset->m_definition->GetFullName(), foundTemplate->first);
|
||||
@ -128,7 +128,7 @@ bool CodeGenerator::GenerateCode(IDataRepository* repository)
|
||||
return false;
|
||||
|
||||
auto context = RenderingContext::BuildContext(repository, asset);
|
||||
if (!GenerateCodeForTemplate(context.get(), foundTemplate->second.get()))
|
||||
if (!GenerateCodeForTemplate(*context, foundTemplate->second.get()))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ public:
|
||||
private:
|
||||
void SetupTemplates();
|
||||
|
||||
bool GenerateCodeForTemplate(RenderingContext* context, ICodeTemplate* codeTemplate) const;
|
||||
bool GenerateCodeForTemplate(const RenderingContext& context, ICodeTemplate* codeTemplate) const;
|
||||
static bool GetAssetWithName(IDataRepository* repository, const std::string& name, StructureInformation*& asset);
|
||||
|
||||
const ZoneCodeGeneratorArguments* m_args;
|
||||
|
@ -29,6 +29,6 @@ public:
|
||||
ICodeTemplate& operator=(const ICodeTemplate& other) = default;
|
||||
ICodeTemplate& operator=(ICodeTemplate&& other) noexcept = default;
|
||||
|
||||
virtual std::vector<CodeTemplateFile> GetFilesToRender(RenderingContext* context) = 0;
|
||||
virtual void RenderFile(std::ostream& stream, int fileTag, RenderingContext* context) = 0;
|
||||
virtual std::vector<CodeTemplateFile> GetFilesToRender(const RenderingContext& context) = 0;
|
||||
virtual void RenderFile(std::ostream& stream, int fileTag, const RenderingContext& context) = 0;
|
||||
};
|
||||
|
@ -2,18 +2,19 @@
|
||||
|
||||
#include "Domain/Computations/StructureComputations.h"
|
||||
#include "Internal/BaseTemplate.h"
|
||||
#include "Utils/StringUtils.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <cassert>
|
||||
#include <format>
|
||||
|
||||
namespace
|
||||
{
|
||||
static constexpr int TAG_SOURCE = 1;
|
||||
constexpr int TAG_SOURCE = 1;
|
||||
|
||||
class Template final : BaseTemplate
|
||||
{
|
||||
public:
|
||||
Template(std::ostream& stream, RenderingContext* context)
|
||||
Template(std::ostream& stream, const RenderingContext& context)
|
||||
: BaseTemplate(stream, context)
|
||||
{
|
||||
}
|
||||
@ -26,21 +27,22 @@ namespace
|
||||
LINE("// Any changes will be discarded when regenerating.")
|
||||
LINE("// ====================================================================")
|
||||
LINE("")
|
||||
LINEF("#include \"Game/{0}/{0}.h\"", m_env.m_game)
|
||||
LINE("")
|
||||
LINE("#include <catch2/catch_test_macros.hpp>")
|
||||
LINE("#include <catch2/generators/catch_generators.hpp>")
|
||||
LINE("#include <cstddef>")
|
||||
LINE("#include \"Game/" << m_env.m_game << "/" << m_env.m_game << ".h\"")
|
||||
LINE("")
|
||||
LINE("using namespace " << m_env.m_game << ";")
|
||||
LINEF("using namespace {0};", m_env.m_game)
|
||||
LINE("")
|
||||
LINE("namespace game::" << m_env.m_game << "::xassets::asset_" << Lower(m_env.m_asset->m_definition->m_name))
|
||||
LINEF("namespace game::{0}::xassets::asset_{1}", m_env.m_game, Lower(m_env.m_asset->m_definition->m_name))
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
if (m_env.m_asset->m_has_matching_cross_platform_structure)
|
||||
TestMethod(m_env.m_asset);
|
||||
|
||||
for (auto* structure : m_env.m_used_structures)
|
||||
for (const auto* structure : m_env.m_used_structures)
|
||||
{
|
||||
StructureComputations computations(structure->m_info);
|
||||
if (!structure->m_info->m_definition->m_anonymous && !computations.IsAsset() && structure->m_info->m_has_matching_cross_platform_structure)
|
||||
@ -52,10 +54,12 @@ namespace
|
||||
}
|
||||
|
||||
private:
|
||||
void TestMethod(StructureInformation* structure)
|
||||
void TestMethod(const StructureInformation* structure)
|
||||
{
|
||||
LINE("TEST_CASE(\"" << m_env.m_game << "::" << m_env.m_asset->m_definition->GetFullName() << ": Tests for "
|
||||
<< structure->m_definition->GetFullName() << "\", \"[assetstruct]\")")
|
||||
LINEF("TEST_CASE(\"{0}::{1}: Tests for {2}\", \"[assetstruct]\")",
|
||||
m_env.m_game,
|
||||
m_env.m_asset->m_definition->GetFullName(),
|
||||
structure->m_definition->GetFullName())
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
@ -63,44 +67,37 @@ namespace
|
||||
{
|
||||
if (!member->m_member->m_name.empty() && !member->m_member->m_type_declaration->m_has_custom_bit_size)
|
||||
{
|
||||
LINE("REQUIRE(offsetof(" << structure->m_definition->GetFullName() << ", " << member->m_member->m_name
|
||||
<< ") == " << member->m_member->m_offset << ");")
|
||||
LINEF("REQUIRE(offsetof({0}, {1}) == {2});", structure->m_definition->GetFullName(), member->m_member->m_name, member->m_member->m_offset)
|
||||
}
|
||||
}
|
||||
|
||||
LINE("")
|
||||
|
||||
LINE("REQUIRE(" << structure->m_definition->GetSize() << "u == sizeof(" << structure->m_definition->GetFullName() << "));")
|
||||
LINE("REQUIRE(" << structure->m_definition->GetAlignment() << "u == alignof(" << structure->m_definition->GetFullName() << "));")
|
||||
LINEF("REQUIRE({0}u == sizeof({1}));", structure->m_definition->GetSize(), structure->m_definition->GetFullName())
|
||||
LINEF("REQUIRE({0}u == alignof({1}));", structure->m_definition->GetAlignment(), structure->m_definition->GetFullName())
|
||||
m_intendation--;
|
||||
LINE("}")
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
std::vector<CodeTemplateFile> AssetStructTestsTemplate::GetFilesToRender(RenderingContext* context)
|
||||
std::vector<CodeTemplateFile> AssetStructTestsTemplate::GetFilesToRender(const RenderingContext& context)
|
||||
{
|
||||
std::vector<CodeTemplateFile> files;
|
||||
|
||||
auto assetName = context->m_asset->m_definition->m_name;
|
||||
for (auto& c : assetName)
|
||||
c = static_cast<char>(tolower(c));
|
||||
auto assetName = context.m_asset->m_definition->m_name;
|
||||
utils::MakeStringLowerCase(assetName);
|
||||
|
||||
{
|
||||
std::ostringstream str;
|
||||
str << assetName << '/' << assetName << "_struct_test.cpp";
|
||||
files.emplace_back(str.str(), TAG_SOURCE);
|
||||
}
|
||||
files.emplace_back(std::format("{0}/{0}_struct_test.cpp", assetName), TAG_SOURCE);
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
void AssetStructTestsTemplate::RenderFile(std::ostream& stream, const int fileTag, RenderingContext* context)
|
||||
void AssetStructTestsTemplate::RenderFile(std::ostream& stream, const int fileTag, const RenderingContext& context)
|
||||
{
|
||||
Template t(stream, context);
|
||||
|
||||
assert(fileTag == TAG_SOURCE);
|
||||
if (fileTag == TAG_SOURCE)
|
||||
t.Source();
|
||||
else
|
||||
std::cout << "Invalid tag in AssetStructTestsTemplate\n";
|
||||
}
|
||||
|
@ -4,6 +4,6 @@
|
||||
class AssetStructTestsTemplate final : public ICodeTemplate
|
||||
{
|
||||
public:
|
||||
std::vector<CodeTemplateFile> GetFilesToRender(RenderingContext* context) override;
|
||||
void RenderFile(std::ostream& stream, int fileTag, RenderingContext* context) override;
|
||||
std::vector<CodeTemplateFile> GetFilesToRender(const RenderingContext& context) override;
|
||||
void RenderFile(std::ostream& stream, int fileTag, const RenderingContext& context) override;
|
||||
};
|
||||
|
@ -5,9 +5,9 @@
|
||||
|
||||
#include <sstream>
|
||||
|
||||
BaseTemplate::BaseTemplate(std::ostream& stream, RenderingContext* context)
|
||||
BaseTemplate::BaseTemplate(std::ostream& stream, const RenderingContext& context)
|
||||
: m_out(stream),
|
||||
m_env(*context),
|
||||
m_env(context),
|
||||
m_intendation(0u)
|
||||
{
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ class BaseTemplate
|
||||
protected:
|
||||
static constexpr auto INTENDATION = " ";
|
||||
|
||||
BaseTemplate(std::ostream& stream, RenderingContext* context);
|
||||
BaseTemplate(std::ostream& stream, const RenderingContext& context);
|
||||
|
||||
void DoIntendation() const;
|
||||
|
||||
@ -41,7 +41,7 @@ protected:
|
||||
static std::string MakeEvaluation(const IEvaluation* evaluation);
|
||||
|
||||
std::ostream& m_out;
|
||||
RenderingContext& m_env;
|
||||
const RenderingContext& m_env;
|
||||
unsigned m_intendation;
|
||||
|
||||
private:
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include "Utils/StringUtils.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
namespace
|
||||
@ -17,7 +16,7 @@ namespace
|
||||
class Template final : BaseTemplate
|
||||
{
|
||||
public:
|
||||
Template(std::ostream& stream, RenderingContext* context)
|
||||
Template(std::ostream& stream, const RenderingContext& context)
|
||||
: BaseTemplate(stream, context)
|
||||
{
|
||||
}
|
||||
@ -32,12 +31,13 @@ namespace
|
||||
LINE("")
|
||||
LINE("#pragma once")
|
||||
LINE("")
|
||||
LINE("#include \"Loading/AssetLoader.h\"")
|
||||
LINEF("#include \"Game/{0}/{0}.h\"", m_env.m_game)
|
||||
if (m_env.m_has_actions)
|
||||
{
|
||||
LINEF("#include \"Game/{0}/XAssets/{1}/{1}_actions.h\"", m_env.m_game, Lower(m_env.m_asset->m_definition->m_name))
|
||||
}
|
||||
LINE("#include \"Loading/AssetLoader.h\"")
|
||||
LINE("")
|
||||
LINE("#include <string>")
|
||||
LINE("")
|
||||
LINEF("namespace {0}", m_env.m_game)
|
||||
@ -47,32 +47,16 @@ namespace
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
LINEF("XAssetInfo<{0}>* m_asset_info;", m_env.m_asset->m_definition->GetFullName())
|
||||
if (m_env.m_has_actions)
|
||||
{
|
||||
LINEF("Actions_{0} m_actions;", m_env.m_asset->m_definition->m_name)
|
||||
}
|
||||
LINE(VariableDecl(m_env.m_asset->m_definition))
|
||||
LINE(PointerVariableDecl(m_env.m_asset->m_definition))
|
||||
LINE("")
|
||||
|
||||
// Variable Declarations: type varType;
|
||||
for (const auto* type : m_env.m_used_types)
|
||||
{
|
||||
if (type->m_info && !type->m_info->m_definition->m_anonymous && !type->m_info->m_is_leaf && !StructureComputations(type->m_info).IsAsset())
|
||||
{
|
||||
LINE(VariableDecl(type->m_type))
|
||||
}
|
||||
}
|
||||
for (const auto* type : m_env.m_used_types)
|
||||
{
|
||||
if (type->m_pointer_array_reference_exists && !type->m_is_context_asset)
|
||||
{
|
||||
LINE(PointerVariableDecl(type->m_type))
|
||||
}
|
||||
}
|
||||
m_intendation--;
|
||||
LINE("public:")
|
||||
m_intendation++;
|
||||
PrintHeaderConstructor();
|
||||
PrintHeaderMainLoadMethodDeclaration(m_env.m_asset);
|
||||
|
||||
LINE("")
|
||||
m_intendation--;
|
||||
LINE("private:")
|
||||
m_intendation++;
|
||||
|
||||
// Method Declarations
|
||||
for (const auto* type : m_env.m_used_types)
|
||||
@ -100,11 +84,31 @@ namespace
|
||||
PrintHeaderTempPtrLoadMethodDeclaration(m_env.m_asset);
|
||||
PrintHeaderAssetLoadMethodDeclaration(m_env.m_asset);
|
||||
LINE("")
|
||||
m_intendation--;
|
||||
LINE("public:")
|
||||
m_intendation++;
|
||||
PrintHeaderConstructor();
|
||||
PrintHeaderMainLoadMethodDeclaration(m_env.m_asset);
|
||||
|
||||
LINEF("XAssetInfo<{0}>* m_asset_info;", m_env.m_asset->m_definition->GetFullName())
|
||||
if (m_env.m_has_actions)
|
||||
{
|
||||
LINEF("Actions_{0} m_actions;", m_env.m_asset->m_definition->m_name)
|
||||
}
|
||||
LINE(VariableDecl(m_env.m_asset->m_definition))
|
||||
LINE(PointerVariableDecl(m_env.m_asset->m_definition))
|
||||
LINE("")
|
||||
|
||||
// Variable Declarations: type varType;
|
||||
for (const auto* type : m_env.m_used_types)
|
||||
{
|
||||
if (type->m_info && !type->m_info->m_definition->m_anonymous && !type->m_info->m_is_leaf && !StructureComputations(type->m_info).IsAsset())
|
||||
{
|
||||
LINE(VariableDecl(type->m_type))
|
||||
}
|
||||
}
|
||||
for (const auto* type : m_env.m_used_types)
|
||||
{
|
||||
if (type->m_pointer_array_reference_exists && !type->m_is_context_asset)
|
||||
{
|
||||
LINE(PointerVariableDecl(type->m_type))
|
||||
}
|
||||
}
|
||||
|
||||
m_intendation--;
|
||||
LINE("};")
|
||||
@ -121,23 +125,29 @@ namespace
|
||||
LINE("// ====================================================================")
|
||||
LINE("")
|
||||
LINEF("#include \"{0}_load_db.h\"", Lower(m_env.m_asset->m_definition->m_name))
|
||||
LINEF("#include \"{0}_mark_db.h\"", Lower(m_env.m_asset->m_definition->m_name))
|
||||
LINE("#include <cassert>")
|
||||
LINE("#include <cstring>")
|
||||
LINE("")
|
||||
LINEF("#include \"{0}_mark_db.h\"", Lower(m_env.m_asset->m_definition->m_name))
|
||||
|
||||
if (!m_env.m_referenced_assets.empty())
|
||||
{
|
||||
LINE("")
|
||||
LINE("// Referenced Assets:")
|
||||
for (const auto* type : m_env.m_referenced_assets)
|
||||
{
|
||||
LINEF("#include \"../{0}/{0}_load_db.h\"", Lower(type->m_type->m_name))
|
||||
}
|
||||
LINE("")
|
||||
}
|
||||
|
||||
LINE("")
|
||||
LINE("#include <cassert>")
|
||||
LINE("#include <cstring>")
|
||||
|
||||
LINE("")
|
||||
LINEF("using namespace {0};", m_env.m_game)
|
||||
LINE("")
|
||||
PrintConstructorMethod();
|
||||
LINE("")
|
||||
PrintMainLoadMethod();
|
||||
|
||||
for (const auto* type : m_env.m_used_types)
|
||||
{
|
||||
@ -169,8 +179,6 @@ namespace
|
||||
PrintLoadPtrMethod(m_env.m_asset);
|
||||
LINE("")
|
||||
PrintLoadAssetMethod(m_env.m_asset);
|
||||
LINE("")
|
||||
PrintMainLoadMethod();
|
||||
}
|
||||
|
||||
private:
|
||||
@ -236,7 +244,7 @@ namespace
|
||||
|
||||
void PrintHeaderConstructor() const
|
||||
{
|
||||
LINEF("{0}(Zone* zone, IZoneInputStream* stream);", LoaderClassName(m_env.m_asset))
|
||||
LINEF("{0}(Zone& zone, ZoneInputStream& stream);", LoaderClassName(m_env.m_asset))
|
||||
}
|
||||
|
||||
void PrintVariableInitialization(const DataDefinition* def) const
|
||||
@ -251,7 +259,7 @@ namespace
|
||||
|
||||
void PrintConstructorMethod()
|
||||
{
|
||||
LINEF("{0}::{0}(Zone* zone, IZoneInputStream* stream)", LoaderClassName(m_env.m_asset))
|
||||
LINEF("{0}::{0}(Zone& zone, ZoneInputStream& stream)", LoaderClassName(m_env.m_asset))
|
||||
|
||||
m_intendation++;
|
||||
LINE_STARTF(": AssetLoader({0}::EnumEntry, zone, stream)", m_env.m_asset->m_asset_name)
|
||||
@ -304,7 +312,7 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
void PrintLoadPtrArrayMethod_PointerCheck(const DataDefinition* def, StructureInformation* info, const bool reusable)
|
||||
void PrintLoadPtrArrayMethod_PointerCheck(const DataDefinition* def, const StructureInformation* info, const bool reusable)
|
||||
{
|
||||
LINEF("if (*{0})", MakeTypePtrVarName(def))
|
||||
LINE("{")
|
||||
@ -312,7 +320,7 @@ namespace
|
||||
|
||||
if (info && StructureComputations(info).IsAsset())
|
||||
{
|
||||
LINEF("{0} loader(m_zone, m_stream);", LoaderClassName(info))
|
||||
LINEF("{0} loader(m_zone, *m_stream);", LoaderClassName(info))
|
||||
LINEF("loader.Load({0});", MakeTypePtrVarName(def))
|
||||
}
|
||||
else
|
||||
@ -346,7 +354,7 @@ namespace
|
||||
LINE("}")
|
||||
}
|
||||
|
||||
void PrintLoadPtrArrayMethod(const DataDefinition* def, StructureInformation* info, const bool reusable)
|
||||
void PrintLoadPtrArrayMethod(const DataDefinition* def, const StructureInformation* info, const bool reusable)
|
||||
{
|
||||
LINEF("void {0}::LoadPtrArray_{1}(const bool atStreamStart, const size_t count)", LoaderClassName(m_env.m_asset), MakeSafeTypeName(def))
|
||||
LINE("{")
|
||||
@ -362,7 +370,7 @@ namespace
|
||||
|
||||
LINE("")
|
||||
LINEF("{0}** var = {1};", def->GetFullName(), MakeTypePtrVarName(def))
|
||||
LINE("for(size_t index = 0; index < count; index++)")
|
||||
LINE("for (size_t index = 0; index < count; index++)")
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
@ -392,7 +400,7 @@ namespace
|
||||
|
||||
LINE("")
|
||||
LINEF("{0}* var = {1};", def->GetFullName(), MakeTypeVarName(def))
|
||||
LINE("for(size_t index = 0; index < count; index++)")
|
||||
LINE("for (size_t index = 0; index < count; index++)")
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
@ -414,7 +422,7 @@ namespace
|
||||
{
|
||||
if (loadType == MemberLoadType::SINGLE_POINTER)
|
||||
{
|
||||
LINEF("{0} loader(m_zone, m_stream);", LoaderClassName(member->m_type))
|
||||
LINEF("{0} loader(m_zone, *m_stream);", LoaderClassName(member->m_type))
|
||||
LINEF("loader.Load(&{0});", MakeMemberAccess(info, member, modifier))
|
||||
}
|
||||
else if (loadType == MemberLoadType::POINTER_ARRAY)
|
||||
@ -899,7 +907,7 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
void LoadMember_ReferenceArray(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier)
|
||||
void LoadMember_ReferenceArray(const StructureInformation* info, const MemberInformation* member, const DeclarationModifierComputations& modifier)
|
||||
{
|
||||
auto first = true;
|
||||
for (const auto& entry : modifier.GetArrayEntries())
|
||||
@ -917,7 +925,7 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
void LoadMember_Reference(StructureInformation* info, MemberInformation* member, const DeclarationModifierComputations& modifier)
|
||||
void LoadMember_Reference(const StructureInformation* info, const MemberInformation* member, const DeclarationModifierComputations& modifier)
|
||||
{
|
||||
if (modifier.IsDynamicArray())
|
||||
{
|
||||
@ -954,7 +962,7 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
void LoadMember_Condition_Struct(StructureInformation* info, MemberInformation* member)
|
||||
void LoadMember_Condition_Struct(const StructureInformation* info, const MemberInformation* member)
|
||||
{
|
||||
LINE("")
|
||||
if (member->m_condition)
|
||||
@ -974,7 +982,7 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
void LoadMember_Condition_Union(StructureInformation* info, MemberInformation* member)
|
||||
void LoadMember_Condition_Union(const StructureInformation* info, const MemberInformation* member)
|
||||
{
|
||||
const MemberComputations computations(member);
|
||||
|
||||
@ -1042,7 +1050,7 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
void PrintLoadMemberIfNeedsTreatment(StructureInformation* info, MemberInformation* member)
|
||||
void PrintLoadMemberIfNeedsTreatment(const StructureInformation* info, const MemberInformation* member)
|
||||
{
|
||||
const MemberComputations computations(member);
|
||||
if (computations.ShouldIgnore())
|
||||
@ -1058,7 +1066,7 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
void PrintLoadMethod(StructureInformation* info)
|
||||
void PrintLoadMethod(const StructureInformation* info)
|
||||
{
|
||||
const StructureComputations computations(info);
|
||||
LINEF("void {0}::Load_{1}(const bool atStreamStart)", LoaderClassName(m_env.m_asset), info->m_definition->m_name)
|
||||
@ -1122,7 +1130,7 @@ namespace
|
||||
LINE("}")
|
||||
}
|
||||
|
||||
void PrintLoadPtrMethod(StructureInformation* info)
|
||||
void PrintLoadPtrMethod(const StructureInformation* info)
|
||||
{
|
||||
const bool inTemp = info->m_block && info->m_block->m_type == FastFileBlockType::TEMP;
|
||||
LINEF("void {0}::LoadPtr_{1}(const bool atStreamStart)", LoaderClassName(m_env.m_asset), MakeSafeTypeName(info->m_definition))
|
||||
@ -1265,7 +1273,7 @@ namespace
|
||||
LINEF("{0} marker(m_zone);", MarkerClassName(m_env.m_asset))
|
||||
LINE("marker.Mark(*pAsset);")
|
||||
LINE("")
|
||||
LINEF("auto* reallocatedAsset = m_zone->GetMemory()->Alloc<{0}>();", info->m_definition->GetFullName())
|
||||
LINEF("auto* reallocatedAsset = m_zone.Memory().Alloc<{0}>();", info->m_definition->GetFullName())
|
||||
LINEF("std::memcpy(reallocatedAsset, *pAsset, sizeof({0}));", info->m_definition->GetFullName())
|
||||
LINE("")
|
||||
LINEF("m_asset_info = reinterpret_cast<XAssetInfo<{0}>*>(LinkAsset(AssetNameAccessor<{1}>()(**pAsset), reallocatedAsset, marker.GetDependencies(), "
|
||||
@ -1306,11 +1314,11 @@ namespace
|
||||
};
|
||||
} // namespace
|
||||
|
||||
std::vector<CodeTemplateFile> ZoneLoadTemplate::GetFilesToRender(RenderingContext* context)
|
||||
std::vector<CodeTemplateFile> ZoneLoadTemplate::GetFilesToRender(const RenderingContext& context)
|
||||
{
|
||||
std::vector<CodeTemplateFile> files;
|
||||
|
||||
auto assetName = context->m_asset->m_definition->m_name;
|
||||
auto assetName = context.m_asset->m_definition->m_name;
|
||||
utils::MakeStringLowerCase(assetName);
|
||||
|
||||
files.emplace_back(std::format("{0}/{0}_load_db.h", assetName), TAG_HEADER);
|
||||
@ -1319,7 +1327,7 @@ std::vector<CodeTemplateFile> ZoneLoadTemplate::GetFilesToRender(RenderingContex
|
||||
return files;
|
||||
}
|
||||
|
||||
void ZoneLoadTemplate::RenderFile(std::ostream& stream, const int fileTag, RenderingContext* context)
|
||||
void ZoneLoadTemplate::RenderFile(std::ostream& stream, const int fileTag, const RenderingContext& context)
|
||||
{
|
||||
Template t(stream, context);
|
||||
|
||||
|
@ -4,6 +4,6 @@
|
||||
class ZoneLoadTemplate final : public ICodeTemplate
|
||||
{
|
||||
public:
|
||||
std::vector<CodeTemplateFile> GetFilesToRender(RenderingContext* context) override;
|
||||
void RenderFile(std::ostream& stream, int fileTag, RenderingContext* context) override;
|
||||
std::vector<CodeTemplateFile> GetFilesToRender(const RenderingContext& context) override;
|
||||
void RenderFile(std::ostream& stream, int fileTag, const RenderingContext& context) override;
|
||||
};
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include "Utils/StringUtils.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
namespace
|
||||
@ -17,7 +16,7 @@ namespace
|
||||
class Template final : BaseTemplate
|
||||
{
|
||||
public:
|
||||
Template(std::ostream& stream, RenderingContext* context)
|
||||
Template(std::ostream& stream, const RenderingContext& context)
|
||||
: BaseTemplate(stream, context)
|
||||
{
|
||||
}
|
||||
@ -32,8 +31,8 @@ namespace
|
||||
LINE("")
|
||||
LINE("#pragma once")
|
||||
LINE("")
|
||||
LINE("#include \"Loading/AssetMarker.h\"")
|
||||
LINEF("#include \"Game/{0}/{0}.h\"", m_env.m_game)
|
||||
LINE("#include \"Loading/AssetMarker.h\"")
|
||||
LINE("")
|
||||
LINE("#include <string>")
|
||||
LINE("")
|
||||
@ -44,32 +43,18 @@ namespace
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
LINE(VariableDecl(m_env.m_asset->m_definition))
|
||||
LINE(PointerVariableDecl(m_env.m_asset->m_definition))
|
||||
LINE("")
|
||||
|
||||
m_intendation--;
|
||||
LINE("public:")
|
||||
m_intendation++;
|
||||
|
||||
// Variable Declarations: type varType;
|
||||
for (const auto* type : m_env.m_used_types)
|
||||
{
|
||||
if (type->m_info && !type->m_info->m_definition->m_anonymous && !type->m_info->m_is_leaf && !StructureComputations(type->m_info).IsAsset())
|
||||
{
|
||||
LINE(VariableDecl(type->m_type))
|
||||
}
|
||||
}
|
||||
for (const auto* type : m_env.m_used_types)
|
||||
{
|
||||
if (type->m_pointer_array_reference_exists && !type->m_is_context_asset)
|
||||
{
|
||||
LINE(PointerVariableDecl(type->m_type))
|
||||
}
|
||||
}
|
||||
|
||||
PrintHeaderConstructor();
|
||||
PrintHeaderMainMarkMethodDeclaration(m_env.m_asset);
|
||||
PrintHeaderGetAssetInfoMethodDeclaration(m_env.m_asset);
|
||||
LINE("")
|
||||
|
||||
m_intendation--;
|
||||
LINE("private:")
|
||||
m_intendation++;
|
||||
|
||||
// Method Declarations
|
||||
for (const auto* type : m_env.m_used_types)
|
||||
{
|
||||
@ -95,11 +80,28 @@ namespace
|
||||
}
|
||||
}
|
||||
PrintHeaderMarkMethodDeclaration(m_env.m_asset);
|
||||
|
||||
LINE("")
|
||||
PrintHeaderGetAssetInfoMethodDeclaration(m_env.m_asset);
|
||||
|
||||
LINE(VariableDecl(m_env.m_asset->m_definition))
|
||||
LINE(PointerVariableDecl(m_env.m_asset->m_definition))
|
||||
LINE("")
|
||||
PrintHeaderConstructor();
|
||||
PrintHeaderMainMarkMethodDeclaration(m_env.m_asset);
|
||||
|
||||
// Variable Declarations: type varType;
|
||||
for (const auto* type : m_env.m_used_types)
|
||||
{
|
||||
if (type->m_info && !type->m_info->m_definition->m_anonymous && !type->m_info->m_is_leaf && !StructureComputations(type->m_info).IsAsset())
|
||||
{
|
||||
LINE(VariableDecl(type->m_type))
|
||||
}
|
||||
}
|
||||
for (const auto* type : m_env.m_used_types)
|
||||
{
|
||||
if (type->m_pointer_array_reference_exists && !type->m_is_context_asset)
|
||||
{
|
||||
LINE(PointerVariableDecl(type->m_type))
|
||||
}
|
||||
}
|
||||
|
||||
m_intendation--;
|
||||
LINE("};")
|
||||
@ -116,22 +118,26 @@ namespace
|
||||
LINE("// ====================================================================")
|
||||
LINE("")
|
||||
LINEF("#include \"{0}_mark_db.h\"", Lower(m_env.m_asset->m_definition->m_name))
|
||||
LINE("")
|
||||
LINE("#include <cassert>")
|
||||
LINE("")
|
||||
|
||||
if (!m_env.m_referenced_assets.empty())
|
||||
{
|
||||
LINE("")
|
||||
LINE("// Referenced Assets:")
|
||||
for (const auto* type : m_env.m_referenced_assets)
|
||||
{
|
||||
LINEF("#include \"../{0}/{0}_mark_db.h\"", Lower(type->m_type->m_name))
|
||||
}
|
||||
LINE("")
|
||||
}
|
||||
LINE("")
|
||||
LINE("#include <cassert>")
|
||||
LINE("")
|
||||
LINEF("using namespace {0};", m_env.m_game)
|
||||
LINE("")
|
||||
PrintConstructorMethod();
|
||||
LINE("")
|
||||
PrintMainMarkMethod();
|
||||
LINE("")
|
||||
PrintGetAssetInfoMethod();
|
||||
|
||||
for (const auto* type : m_env.m_used_types)
|
||||
{
|
||||
@ -161,10 +167,6 @@ namespace
|
||||
}
|
||||
LINE("")
|
||||
PrintMarkMethod(m_env.m_asset);
|
||||
LINE("")
|
||||
PrintMainMarkMethod();
|
||||
LINE("")
|
||||
PrintGetAssetInfoMethod();
|
||||
}
|
||||
|
||||
private:
|
||||
@ -215,7 +217,7 @@ namespace
|
||||
|
||||
void PrintHeaderConstructor() const
|
||||
{
|
||||
LINEF("{0}(Zone* zone);", MarkerClassName(m_env.m_asset))
|
||||
LINEF("{0}(Zone& zone);", MarkerClassName(m_env.m_asset))
|
||||
}
|
||||
|
||||
void PrintHeaderMainMarkMethodDeclaration(const StructureInformation* info) const
|
||||
@ -235,7 +237,7 @@ namespace
|
||||
|
||||
void PrintConstructorMethod()
|
||||
{
|
||||
LINEF("{0}::{0}(Zone* zone)", MarkerClassName(m_env.m_asset))
|
||||
LINEF("{0}::{0}(Zone& zone)", MarkerClassName(m_env.m_asset))
|
||||
|
||||
m_intendation++;
|
||||
LINEF(": AssetMarker({0}::EnumEntry, zone)", m_env.m_asset->m_asset_name)
|
||||
@ -276,7 +278,7 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
void PrintMarkPtrArrayMethod_PointerCheck(const DataDefinition* def, StructureInformation* info, const bool reusable)
|
||||
void PrintMarkPtrArrayMethod_PointerCheck(const DataDefinition* def, const StructureInformation* info)
|
||||
{
|
||||
LINEF("if (*{0})", MakeTypePtrVarName(def))
|
||||
LINE("{")
|
||||
@ -295,7 +297,7 @@ namespace
|
||||
LINE("}")
|
||||
}
|
||||
|
||||
void PrintMarkPtrArrayMethod(const DataDefinition* def, StructureInformation* info, const bool reusable)
|
||||
void PrintMarkPtrArrayMethod(const DataDefinition* def, const StructureInformation* info, const bool reusable)
|
||||
{
|
||||
LINEF("void {0}::MarkPtrArray_{1}(const size_t count)", MarkerClassName(m_env.m_asset), MakeSafeTypeName(def))
|
||||
LINE("{")
|
||||
@ -310,7 +312,7 @@ namespace
|
||||
m_intendation++;
|
||||
|
||||
LINEF("{0} = var;", MakeTypePtrVarName(def))
|
||||
PrintMarkPtrArrayMethod_PointerCheck(def, info, reusable);
|
||||
PrintMarkPtrArrayMethod_PointerCheck(def, info);
|
||||
LINE("")
|
||||
LINE("var++;")
|
||||
|
||||
@ -531,7 +533,8 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
static bool MarkMember_ShouldMakePointerCheck(const MemberInformation* member, const DeclarationModifierComputations& modifier, MemberLoadType loadType)
|
||||
static bool
|
||||
MarkMember_ShouldMakePointerCheck(const MemberInformation* member, const DeclarationModifierComputations& modifier, const MemberLoadType loadType)
|
||||
{
|
||||
if (loadType != MemberLoadType::ARRAY_POINTER && loadType != MemberLoadType::POINTER_ARRAY && loadType != MemberLoadType::SINGLE_POINTER)
|
||||
{
|
||||
@ -780,11 +783,11 @@ namespace
|
||||
};
|
||||
} // namespace
|
||||
|
||||
std::vector<CodeTemplateFile> ZoneMarkTemplate::GetFilesToRender(RenderingContext* context)
|
||||
std::vector<CodeTemplateFile> ZoneMarkTemplate::GetFilesToRender(const RenderingContext& context)
|
||||
{
|
||||
std::vector<CodeTemplateFile> files;
|
||||
|
||||
auto assetName = context->m_asset->m_definition->m_name;
|
||||
auto assetName = context.m_asset->m_definition->m_name;
|
||||
utils::MakeStringLowerCase(assetName);
|
||||
|
||||
files.emplace_back(std::format("{0}/{0}_mark_db.h", assetName), TAG_HEADER);
|
||||
@ -793,7 +796,7 @@ std::vector<CodeTemplateFile> ZoneMarkTemplate::GetFilesToRender(RenderingContex
|
||||
return files;
|
||||
}
|
||||
|
||||
void ZoneMarkTemplate::RenderFile(std::ostream& stream, const int fileTag, RenderingContext* context)
|
||||
void ZoneMarkTemplate::RenderFile(std::ostream& stream, const int fileTag, const RenderingContext& context)
|
||||
{
|
||||
Template t(stream, context);
|
||||
|
||||
|
@ -4,6 +4,6 @@
|
||||
class ZoneMarkTemplate final : public ICodeTemplate
|
||||
{
|
||||
public:
|
||||
std::vector<CodeTemplateFile> GetFilesToRender(RenderingContext* context) override;
|
||||
void RenderFile(std::ostream& stream, int fileTag, RenderingContext* context) override;
|
||||
std::vector<CodeTemplateFile> GetFilesToRender(const RenderingContext& context) override;
|
||||
void RenderFile(std::ostream& stream, int fileTag, const RenderingContext& context) override;
|
||||
};
|
||||
|
@ -15,7 +15,7 @@ namespace
|
||||
class Template final : BaseTemplate
|
||||
{
|
||||
public:
|
||||
Template(std::ostream& stream, RenderingContext* context)
|
||||
Template(std::ostream& stream, const RenderingContext& context)
|
||||
: BaseTemplate(stream, context)
|
||||
{
|
||||
}
|
||||
@ -30,8 +30,9 @@ namespace
|
||||
LINE("")
|
||||
LINE("#pragma once")
|
||||
LINE("")
|
||||
LINE("#include \"Writing/AssetWriter.h\"")
|
||||
LINEF("#include \"Game/{0}/{0}.h\"", m_env.m_game)
|
||||
LINE("#include \"Writing/AssetWriter.h\"")
|
||||
LINE("")
|
||||
LINE("#include <string>")
|
||||
LINE("")
|
||||
LINEF("namespace {0}", m_env.m_game)
|
||||
@ -41,31 +42,16 @@ namespace
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
LINE(VariableDecl(m_env.m_asset->m_definition))
|
||||
LINE(WrittenVariableDecl(m_env.m_asset->m_definition))
|
||||
LINE(PointerVariableDecl(m_env.m_asset->m_definition))
|
||||
LINE(WrittenPointerVariableDecl(m_env.m_asset->m_definition))
|
||||
LINE("")
|
||||
|
||||
// Variable Declarations: type varType;
|
||||
for (const auto* type : m_env.m_used_types)
|
||||
{
|
||||
if (type->m_info && !type->m_info->m_definition->m_anonymous && !type->m_info->m_is_leaf && !StructureComputations(type->m_info).IsAsset())
|
||||
{
|
||||
LINE(VariableDecl(type->m_type))
|
||||
LINE(WrittenVariableDecl(type->m_type))
|
||||
}
|
||||
}
|
||||
for (const auto* type : m_env.m_used_types)
|
||||
{
|
||||
if (type->m_pointer_array_reference_exists && !type->m_is_context_asset)
|
||||
{
|
||||
LINE(PointerVariableDecl(type->m_type))
|
||||
LINE(WrittenPointerVariableDecl(type->m_type))
|
||||
}
|
||||
}
|
||||
m_intendation--;
|
||||
LINE("public:")
|
||||
m_intendation++;
|
||||
PrintHeaderConstructor();
|
||||
PrintHeaderMainWriteMethodDeclaration(m_env.m_asset);
|
||||
|
||||
LINE("")
|
||||
m_intendation--;
|
||||
LINE("private:")
|
||||
m_intendation++;
|
||||
|
||||
// Method Declarations
|
||||
for (const auto* type : m_env.m_used_types)
|
||||
@ -91,12 +77,32 @@ namespace
|
||||
}
|
||||
PrintHeaderWriteMethodDeclaration(m_env.m_asset);
|
||||
PrintHeaderTempPtrWriteMethodDeclaration(m_env.m_asset);
|
||||
|
||||
LINE("")
|
||||
m_intendation--;
|
||||
LINE("public:")
|
||||
m_intendation++;
|
||||
PrintHeaderConstructor();
|
||||
PrintHeaderMainWriteMethodDeclaration(m_env.m_asset);
|
||||
|
||||
LINE(VariableDecl(m_env.m_asset->m_definition))
|
||||
LINE(WrittenVariableDecl(m_env.m_asset->m_definition))
|
||||
LINE(PointerVariableDecl(m_env.m_asset->m_definition))
|
||||
LINE(WrittenPointerVariableDecl(m_env.m_asset->m_definition))
|
||||
LINE("")
|
||||
|
||||
// Variable Declarations: type varType;
|
||||
for (const auto* type : m_env.m_used_types)
|
||||
{
|
||||
if (type->m_info && !type->m_info->m_definition->m_anonymous && !type->m_info->m_is_leaf && !StructureComputations(type->m_info).IsAsset())
|
||||
{
|
||||
LINE(VariableDecl(type->m_type))
|
||||
LINE(WrittenVariableDecl(type->m_type))
|
||||
}
|
||||
}
|
||||
for (const auto* type : m_env.m_used_types)
|
||||
{
|
||||
if (type->m_pointer_array_reference_exists && !type->m_is_context_asset)
|
||||
{
|
||||
LINE(PointerVariableDecl(type->m_type))
|
||||
LINE(WrittenPointerVariableDecl(type->m_type))
|
||||
}
|
||||
}
|
||||
|
||||
m_intendation--;
|
||||
LINE("};")
|
||||
@ -113,21 +119,25 @@ namespace
|
||||
LINE("// ====================================================================")
|
||||
LINE("")
|
||||
LINEF("#include \"{0}_write_db.h\"", Lower(m_env.m_asset->m_definition->m_name))
|
||||
LINE("#include <cassert>")
|
||||
LINE("")
|
||||
|
||||
if (!m_env.m_referenced_assets.empty())
|
||||
{
|
||||
LINE("")
|
||||
LINE("// Referenced Assets:")
|
||||
for (const auto* type : m_env.m_referenced_assets)
|
||||
{
|
||||
LINEF("#include \"../{0}/{0}_write_db.h\"", Lower(type->m_type->m_name))
|
||||
}
|
||||
LINE("")
|
||||
}
|
||||
|
||||
LINE("")
|
||||
LINE("#include <cassert>")
|
||||
LINE("")
|
||||
LINEF("using namespace {0};", m_env.m_game)
|
||||
LINE("")
|
||||
PrintConstructorMethod();
|
||||
LINE("")
|
||||
PrintMainWriteMethod();
|
||||
|
||||
for (const auto* type : m_env.m_used_types)
|
||||
{
|
||||
@ -157,8 +167,6 @@ namespace
|
||||
PrintWriteMethod(m_env.m_asset);
|
||||
LINE("")
|
||||
PrintWritePtrMethod(m_env.m_asset);
|
||||
LINE("")
|
||||
PrintMainWriteMethod();
|
||||
}
|
||||
|
||||
private:
|
||||
@ -1116,7 +1124,7 @@ namespace
|
||||
LINEF("m_stream->MarkFollowing(*{0});", MakeTypeWrittenPtrVarName(def))
|
||||
}
|
||||
|
||||
void PrintWritePtrArrayMethod_PointerCheck(const DataDefinition* def, StructureInformation* info, const bool reusable)
|
||||
void PrintWritePtrArrayMethod_PointerCheck(const DataDefinition* def, const StructureInformation* info, const bool reusable)
|
||||
{
|
||||
LINEF("if (*{0})", MakeTypePtrVarName(def))
|
||||
LINE("{")
|
||||
@ -1150,7 +1158,7 @@ namespace
|
||||
LINE("}")
|
||||
}
|
||||
|
||||
void PrintWritePtrArrayMethod(const DataDefinition* def, StructureInformation* info, const bool reusable)
|
||||
void PrintWritePtrArrayMethod(const DataDefinition* def, const StructureInformation* info, const bool reusable)
|
||||
{
|
||||
LINEF("void {0}::WritePtrArray_{1}(const bool atStreamStart, const size_t count)", WriterClassName(m_env.m_asset), MakeSafeTypeName(def))
|
||||
LINE("{")
|
||||
@ -1225,11 +1233,11 @@ namespace
|
||||
};
|
||||
} // namespace
|
||||
|
||||
std::vector<CodeTemplateFile> ZoneWriteTemplate::GetFilesToRender(RenderingContext* context)
|
||||
std::vector<CodeTemplateFile> ZoneWriteTemplate::GetFilesToRender(const RenderingContext& context)
|
||||
{
|
||||
std::vector<CodeTemplateFile> files;
|
||||
|
||||
auto assetName = context->m_asset->m_definition->m_name;
|
||||
auto assetName = context.m_asset->m_definition->m_name;
|
||||
for (auto& c : assetName)
|
||||
c = static_cast<char>(tolower(c));
|
||||
|
||||
@ -1239,7 +1247,7 @@ std::vector<CodeTemplateFile> ZoneWriteTemplate::GetFilesToRender(RenderingConte
|
||||
return files;
|
||||
}
|
||||
|
||||
void ZoneWriteTemplate::RenderFile(std::ostream& stream, const int fileTag, RenderingContext* context)
|
||||
void ZoneWriteTemplate::RenderFile(std::ostream& stream, const int fileTag, const RenderingContext& context)
|
||||
{
|
||||
Template t(stream, context);
|
||||
|
||||
|
@ -4,6 +4,6 @@
|
||||
class ZoneWriteTemplate final : public ICodeTemplate
|
||||
{
|
||||
public:
|
||||
std::vector<CodeTemplateFile> GetFilesToRender(RenderingContext* context) override;
|
||||
void RenderFile(std::ostream& stream, int fileTag, RenderingContext* context) override;
|
||||
std::vector<CodeTemplateFile> GetFilesToRender(const RenderingContext& context) override;
|
||||
void RenderFile(std::ostream& stream, int fileTag, const RenderingContext& context) override;
|
||||
};
|
||||
|
@ -1,13 +1,13 @@
|
||||
#include "Zone.h"
|
||||
|
||||
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_name(std::move(name)),
|
||||
m_priority(priority),
|
||||
m_language(GameLanguage::LANGUAGE_NONE),
|
||||
m_game(game),
|
||||
m_pools(ZoneAssetPools::CreateForGame(game->GetId(), this, priority))
|
||||
m_pools(ZoneAssetPools::CreateForGame(game->GetId(), this, priority)),
|
||||
m_memory(std::make_unique<ZoneMemory>()),
|
||||
m_registered(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ void Zone::Register()
|
||||
}
|
||||
}
|
||||
|
||||
ZoneMemory* Zone::GetMemory() const
|
||||
ZoneMemory& Zone::Memory() const
|
||||
{
|
||||
return m_memory.get();
|
||||
return *m_memory;
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
#include "Game/GameLanguage.h"
|
||||
#include "Game/IGame.h"
|
||||
#include "Pool/ZoneAssetPools.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Zone/ZoneTypes.h"
|
||||
#include "ZoneMemory.h"
|
||||
#include "ZoneScriptStrings.h"
|
||||
@ -16,10 +15,6 @@ class ZoneAssetPools;
|
||||
|
||||
class Zone
|
||||
{
|
||||
std::unique_ptr<ZoneMemory> m_memory;
|
||||
|
||||
bool m_registered;
|
||||
|
||||
public:
|
||||
std::string m_name;
|
||||
zone_priority_t m_priority;
|
||||
@ -37,5 +32,10 @@ public:
|
||||
|
||||
void Register();
|
||||
|
||||
_NODISCARD ZoneMemory* GetMemory() const;
|
||||
[[nodiscard]] ZoneMemory& Memory() const;
|
||||
|
||||
private:
|
||||
std::unique_ptr<ZoneMemory> m_memory;
|
||||
|
||||
bool m_registered;
|
||||
};
|
||||
|
@ -32,8 +32,9 @@
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
ContentLoader::ContentLoader()
|
||||
: varXAsset(nullptr),
|
||||
ContentLoader::ContentLoader(Zone& zone)
|
||||
: ContentLoaderBase(zone),
|
||||
varXAsset(nullptr),
|
||||
varScriptStringList(nullptr)
|
||||
{
|
||||
}
|
||||
@ -54,12 +55,12 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
||||
LoadXStringArray(true, varScriptStringList->count);
|
||||
|
||||
if (varScriptStringList->strings && varScriptStringList->count > 0)
|
||||
m_zone->m_script_strings.InitializeForExistingZone(varScriptStringList->strings, static_cast<size_t>(varScriptStringList->count));
|
||||
m_zone.m_script_strings.InitializeForExistingZone(varScriptStringList->strings, static_cast<size_t>(varScriptStringList->count));
|
||||
}
|
||||
|
||||
m_stream->PopBlock();
|
||||
|
||||
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) const
|
||||
@ -67,7 +68,7 @@ void ContentLoader::LoadXAsset(const bool atStreamStart) const
|
||||
#define LOAD_ASSET(type_index, typeName, headerEntry) \
|
||||
case type_index: \
|
||||
{ \
|
||||
Loader_##typeName loader(m_zone, m_stream); \
|
||||
Loader_##typeName loader(m_zone, *m_stream); \
|
||||
loader.Load(&varXAsset->header.headerEntry); \
|
||||
break; \
|
||||
}
|
||||
@ -133,10 +134,9 @@ void ContentLoader::LoadXAssetArray(const bool atStreamStart, const size_t count
|
||||
}
|
||||
}
|
||||
|
||||
void ContentLoader::Load(Zone* zone, IZoneInputStream* stream)
|
||||
void ContentLoader::Load(ZoneInputStream& stream)
|
||||
{
|
||||
m_zone = zone;
|
||||
m_stream = stream;
|
||||
m_stream = &stream;
|
||||
|
||||
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Loading/ContentLoaderBase.h"
|
||||
#include "Loading/IContentLoadingEntryPoint.h"
|
||||
@ -7,17 +8,18 @@ namespace IW3
|
||||
{
|
||||
class ContentLoader final : public ContentLoaderBase, public IContentLoadingEntryPoint
|
||||
{
|
||||
XAsset* varXAsset;
|
||||
ScriptStringList* varScriptStringList;
|
||||
public:
|
||||
explicit ContentLoader(Zone& zone);
|
||||
|
||||
void Load(ZoneInputStream& stream) override;
|
||||
|
||||
private:
|
||||
void LoadScriptStringList(bool atStreamStart);
|
||||
|
||||
void LoadXAsset(bool atStreamStart) const;
|
||||
void LoadXAssetArray(bool atStreamStart, size_t count);
|
||||
|
||||
public:
|
||||
ContentLoader();
|
||||
|
||||
void Load(Zone* zone, IZoneInputStream* stream) override;
|
||||
XAsset* varXAsset;
|
||||
ScriptStringList* varScriptStringList;
|
||||
};
|
||||
} // namespace IW3
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
Actions_GfxImage::Actions_GfxImage(Zone* zone)
|
||||
Actions_GfxImage::Actions_GfxImage(Zone& zone)
|
||||
: AssetLoadingActions(zone)
|
||||
{
|
||||
}
|
||||
@ -19,6 +19,6 @@ void Actions_GfxImage::LoadImageData(GfxImageLoadDef* loadDef, GfxImage* image)
|
||||
{
|
||||
const size_t loadDefSize = offsetof(IW3::GfxImageLoadDef, data) + loadDef->resourceSize;
|
||||
|
||||
image->texture.loadDef = static_cast<GfxImageLoadDef*>(m_zone->GetMemory()->AllocRaw(loadDefSize));
|
||||
image->texture.loadDef = static_cast<GfxImageLoadDef*>(m_zone.Memory().AllocRaw(loadDefSize));
|
||||
memcpy(image->texture.loadDef, loadDef, loadDefSize);
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ namespace IW3
|
||||
class Actions_GfxImage final : public AssetLoadingActions
|
||||
{
|
||||
public:
|
||||
explicit Actions_GfxImage(Zone* zone);
|
||||
explicit Actions_GfxImage(Zone& zone);
|
||||
|
||||
void OnImageLoaded(GfxImage* image) const;
|
||||
void LoadImageData(GfxImageLoadDef* loadDef, GfxImage* image) const;
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
Actions_LoadedSound::Actions_LoadedSound(Zone* zone)
|
||||
Actions_LoadedSound::Actions_LoadedSound(Zone& zone)
|
||||
: AssetLoadingActions(zone)
|
||||
{
|
||||
}
|
||||
@ -14,7 +14,7 @@ void Actions_LoadedSound::SetSoundData(MssSound* sound) const
|
||||
if (sound->info.data_len > 0)
|
||||
{
|
||||
const auto* tempData = sound->data;
|
||||
sound->data = m_zone->GetMemory()->Alloc<char>(sound->info.data_len);
|
||||
sound->data = m_zone.Memory().Alloc<char>(sound->info.data_len);
|
||||
memcpy(sound->data, tempData, sound->info.data_len);
|
||||
}
|
||||
else
|
||||
|
@ -8,7 +8,7 @@ namespace IW3
|
||||
class Actions_LoadedSound final : public AssetLoadingActions
|
||||
{
|
||||
public:
|
||||
explicit Actions_LoadedSound(Zone* zone);
|
||||
explicit Actions_LoadedSound(Zone& zone);
|
||||
|
||||
void SetSoundData(MssSound* sound) const;
|
||||
};
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "Loading/Steps/StepAddProcessor.h"
|
||||
#include "Loading/Steps/StepAllocXBlocks.h"
|
||||
#include "Loading/Steps/StepLoadZoneContent.h"
|
||||
#include "Loading/Steps/StepLoadZoneSizes.h"
|
||||
#include "Loading/Steps/StepSkipBytes.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
|
||||
@ -77,16 +78,15 @@ std::unique_ptr<ZoneLoader> ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader&
|
||||
|
||||
SetupBlock(*zoneLoader);
|
||||
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepAddProcessor>(std::make_unique<ProcessorInflate>(ZoneConstants::AUTHED_CHUNK_SIZE)));
|
||||
zoneLoader->AddLoadingStep(step::CreateStepAddProcessor(processor::CreateProcessorInflate(ZoneConstants::AUTHED_CHUNK_SIZE)));
|
||||
|
||||
// Start of the XFile struct
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(8));
|
||||
// Skip size and externalSize fields since they are not interesting for us
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepAllocXBlocks>());
|
||||
zoneLoader->AddLoadingStep(step::CreateStepLoadZoneSizes());
|
||||
zoneLoader->AddLoadingStep(step::CreateStepAllocXBlocks());
|
||||
|
||||
// Start of the zone content
|
||||
zoneLoader->AddLoadingStep(
|
||||
std::make_unique<StepLoadZoneContent>(std::make_unique<ContentLoader>(), zonePtr, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK));
|
||||
step::CreateStepLoadZoneContent(std::make_unique<ContentLoader>(*zonePtr), ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK));
|
||||
|
||||
return zoneLoader;
|
||||
}
|
||||
|
@ -42,8 +42,9 @@
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
ContentLoader::ContentLoader()
|
||||
: varXAsset(nullptr),
|
||||
ContentLoader::ContentLoader(Zone& zone)
|
||||
: ContentLoaderBase(zone),
|
||||
varXAsset(nullptr),
|
||||
varScriptStringList(nullptr)
|
||||
{
|
||||
}
|
||||
@ -64,12 +65,12 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
||||
LoadXStringArray(true, varScriptStringList->count);
|
||||
|
||||
if (varScriptStringList->strings && varScriptStringList->count > 0)
|
||||
m_zone->m_script_strings.InitializeForExistingZone(varScriptStringList->strings, static_cast<size_t>(varScriptStringList->count));
|
||||
m_zone.m_script_strings.InitializeForExistingZone(varScriptStringList->strings, static_cast<size_t>(varScriptStringList->count));
|
||||
}
|
||||
|
||||
m_stream->PopBlock();
|
||||
|
||||
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) const
|
||||
@ -77,7 +78,7 @@ void ContentLoader::LoadXAsset(const bool atStreamStart) const
|
||||
#define LOAD_ASSET(type_index, typeName, headerEntry) \
|
||||
case type_index: \
|
||||
{ \
|
||||
Loader_##typeName loader(m_zone, m_stream); \
|
||||
Loader_##typeName loader(m_zone, *m_stream); \
|
||||
loader.Load(&varXAsset->header.headerEntry); \
|
||||
break; \
|
||||
}
|
||||
@ -153,10 +154,9 @@ void ContentLoader::LoadXAssetArray(const bool atStreamStart, const size_t count
|
||||
}
|
||||
}
|
||||
|
||||
void ContentLoader::Load(Zone* zone, IZoneInputStream* stream)
|
||||
void ContentLoader::Load(ZoneInputStream& stream)
|
||||
{
|
||||
m_zone = zone;
|
||||
m_stream = stream;
|
||||
m_stream = &stream;
|
||||
|
||||
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
||||
|
||||
|
@ -9,9 +9,9 @@ namespace IW4
|
||||
class ContentLoader final : public ContentLoaderBase, public IContentLoadingEntryPoint
|
||||
{
|
||||
public:
|
||||
ContentLoader();
|
||||
explicit ContentLoader(Zone& zone);
|
||||
|
||||
void Load(Zone* zone, IZoneInputStream* stream) override;
|
||||
void Load(ZoneInputStream& stream) override;
|
||||
|
||||
private:
|
||||
void LoadScriptStringList(bool atStreamStart);
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
Actions_GfxImage::Actions_GfxImage(Zone* zone)
|
||||
Actions_GfxImage::Actions_GfxImage(Zone& zone)
|
||||
: AssetLoadingActions(zone)
|
||||
{
|
||||
}
|
||||
@ -19,6 +19,6 @@ void Actions_GfxImage::LoadImageData(GfxImageLoadDef* loadDef, GfxImage* image)
|
||||
{
|
||||
const size_t loadDefSize = offsetof(IW4::GfxImageLoadDef, data) + loadDef->resourceSize;
|
||||
|
||||
image->texture.loadDef = static_cast<GfxImageLoadDef*>(m_zone->GetMemory()->AllocRaw(loadDefSize));
|
||||
image->texture.loadDef = static_cast<GfxImageLoadDef*>(m_zone.Memory().AllocRaw(loadDefSize));
|
||||
memcpy(image->texture.loadDef, loadDef, loadDefSize);
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ namespace IW4
|
||||
class Actions_GfxImage final : public AssetLoadingActions
|
||||
{
|
||||
public:
|
||||
explicit Actions_GfxImage(Zone* zone);
|
||||
explicit Actions_GfxImage(Zone& zone);
|
||||
|
||||
void OnImageLoaded(GfxImage* image) const;
|
||||
void LoadImageData(GfxImageLoadDef* loadDef, GfxImage* image) const;
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
Actions_LoadedSound::Actions_LoadedSound(Zone* zone)
|
||||
Actions_LoadedSound::Actions_LoadedSound(Zone& zone)
|
||||
: AssetLoadingActions(zone)
|
||||
{
|
||||
}
|
||||
@ -14,7 +14,7 @@ void Actions_LoadedSound::SetSoundData(MssSound* sound) const
|
||||
if (sound->info.data_len > 0)
|
||||
{
|
||||
const auto* tempData = sound->data;
|
||||
sound->data = m_zone->GetMemory()->Alloc<char>(sound->info.data_len);
|
||||
sound->data = m_zone.Memory().Alloc<char>(sound->info.data_len);
|
||||
memcpy(sound->data, tempData, sound->info.data_len);
|
||||
}
|
||||
else
|
||||
|
@ -8,7 +8,7 @@ namespace IW4
|
||||
class Actions_LoadedSound final : public AssetLoadingActions
|
||||
{
|
||||
public:
|
||||
explicit Actions_LoadedSound(Zone* zone);
|
||||
explicit Actions_LoadedSound(Zone& zone);
|
||||
|
||||
void SetSoundData(MssSound* sound) const;
|
||||
};
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
Actions_XModel::Actions_XModel(Zone* zone)
|
||||
Actions_XModel::Actions_XModel(Zone& zone)
|
||||
: AssetLoadingActions(zone)
|
||||
{
|
||||
}
|
||||
@ -13,7 +13,7 @@ void Actions_XModel::SetModelSurfs(XModelLodInfo* lodInfo, XModelSurfs* modelSur
|
||||
{
|
||||
if (modelSurfs)
|
||||
{
|
||||
lodInfo->modelSurfs = m_zone->GetMemory()->Alloc<XModelSurfs>();
|
||||
lodInfo->modelSurfs = m_zone.Memory().Alloc<XModelSurfs>();
|
||||
memcpy(lodInfo->modelSurfs, modelSurfs, sizeof(XModelSurfs));
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ namespace IW4
|
||||
class Actions_XModel final : public AssetLoadingActions
|
||||
{
|
||||
public:
|
||||
explicit Actions_XModel(Zone* zone);
|
||||
explicit Actions_XModel(Zone& zone);
|
||||
|
||||
void SetModelSurfs(XModelLodInfo* lodInfo, XModelSurfs* modelSurfs) const;
|
||||
};
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "Loading/Steps/StepLoadHash.h"
|
||||
#include "Loading/Steps/StepLoadSignature.h"
|
||||
#include "Loading/Steps/StepLoadZoneContent.h"
|
||||
#include "Loading/Steps/StepLoadZoneSizes.h"
|
||||
#include "Loading/Steps/StepRemoveProcessor.h"
|
||||
#include "Loading/Steps/StepSkipBytes.h"
|
||||
#include "Loading/Steps/StepVerifyFileName.h"
|
||||
@ -123,39 +124,39 @@ namespace
|
||||
// If file is signed setup a RSA instance.
|
||||
auto rsa = SetupRsa(isOfficial);
|
||||
|
||||
zoneLoader.AddLoadingStep(std::make_unique<StepVerifyMagic>(ZoneConstants::MAGIC_AUTH_HEADER));
|
||||
zoneLoader.AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved
|
||||
zoneLoader.AddLoadingStep(step::CreateStepVerifyMagic(ZoneConstants::MAGIC_AUTH_HEADER));
|
||||
zoneLoader.AddLoadingStep(step::CreateStepSkipBytes(4)); // Skip reserved
|
||||
|
||||
auto subHeaderHash = std::make_unique<StepLoadHash>(sizeof(DB_AuthHash::bytes), 1);
|
||||
auto subHeaderHash = step::CreateStepLoadHash(sizeof(DB_AuthHash::bytes), 1);
|
||||
auto* subHeaderHashPtr = subHeaderHash.get();
|
||||
zoneLoader.AddLoadingStep(std::move(subHeaderHash));
|
||||
|
||||
auto subHeaderHashSignature = std::make_unique<StepLoadSignature>(sizeof(DB_AuthSignature::bytes));
|
||||
auto subHeaderHashSignature = step::CreateStepLoadSignature(sizeof(DB_AuthSignature::bytes));
|
||||
auto* subHeaderHashSignaturePtr = subHeaderHashSignature.get();
|
||||
zoneLoader.AddLoadingStep(std::move(subHeaderHashSignature));
|
||||
|
||||
zoneLoader.AddLoadingStep(std::make_unique<StepVerifySignature>(std::move(rsa), subHeaderHashSignaturePtr, subHeaderHashPtr));
|
||||
zoneLoader.AddLoadingStep(step::CreateStepVerifySignature(std::move(rsa), subHeaderHashSignaturePtr, subHeaderHashPtr));
|
||||
|
||||
auto subHeaderCapture = std::make_unique<ProcessorCaptureData>(sizeof(DB_AuthSubHeader));
|
||||
auto subHeaderCapture = processor::CreateProcessorCaptureData(sizeof(DB_AuthSubHeader));
|
||||
auto* subHeaderCapturePtr = subHeaderCapture.get();
|
||||
zoneLoader.AddLoadingStep(std::make_unique<StepAddProcessor>(std::move(subHeaderCapture)));
|
||||
zoneLoader.AddLoadingStep(step::CreateStepAddProcessor(std::move(subHeaderCapture)));
|
||||
|
||||
zoneLoader.AddLoadingStep(std::make_unique<StepVerifyFileName>(fileName, sizeof(DB_AuthSubHeader::fastfileName)));
|
||||
zoneLoader.AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved
|
||||
zoneLoader.AddLoadingStep(step::CreateStepVerifyFileName(fileName, sizeof(DB_AuthSubHeader::fastfileName)));
|
||||
zoneLoader.AddLoadingStep(step::CreateStepSkipBytes(4)); // Skip reserved
|
||||
|
||||
auto masterBlockHashes =
|
||||
std::make_unique<StepLoadHash>(sizeof(DB_AuthHash::bytes), static_cast<unsigned>(std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>));
|
||||
step::CreateStepLoadHash(sizeof(DB_AuthHash::bytes), static_cast<unsigned>(std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>));
|
||||
auto* masterBlockHashesPtr = masterBlockHashes.get();
|
||||
zoneLoader.AddLoadingStep(std::move(masterBlockHashes));
|
||||
|
||||
zoneLoader.AddLoadingStep(std::make_unique<StepVerifyHash>(cryptography::CreateSha256(), 0, subHeaderHashPtr, subHeaderCapturePtr));
|
||||
zoneLoader.AddLoadingStep(std::make_unique<StepRemoveProcessor>(subHeaderCapturePtr));
|
||||
zoneLoader.AddLoadingStep(step::CreateStepVerifyHash(cryptography::CreateSha256(), 0, subHeaderHashPtr, subHeaderCapturePtr));
|
||||
zoneLoader.AddLoadingStep(step::CreateStepRemoveProcessor(subHeaderCapturePtr));
|
||||
|
||||
// Skip the rest of the first chunk
|
||||
zoneLoader.AddLoadingStep(std::make_unique<StepSkipBytes>(ZoneConstants::AUTHED_CHUNK_SIZE - sizeof(DB_AuthHeader)));
|
||||
zoneLoader.AddLoadingStep(step::CreateStepSkipBytes(ZoneConstants::AUTHED_CHUNK_SIZE - sizeof(DB_AuthHeader)));
|
||||
|
||||
zoneLoader.AddLoadingStep(std::make_unique<StepAddProcessor>(
|
||||
std::make_unique<ProcessorAuthedBlocks>(ZoneConstants::AUTHED_CHUNK_COUNT_PER_GROUP,
|
||||
zoneLoader.AddLoadingStep(step::CreateStepAddProcessor(
|
||||
processor::CreateProcessorAuthedBlocks(ZoneConstants::AUTHED_CHUNK_COUNT_PER_GROUP,
|
||||
ZoneConstants::AUTHED_CHUNK_SIZE,
|
||||
static_cast<unsigned>(std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>),
|
||||
cryptography::CreateSha256(),
|
||||
@ -185,30 +186,29 @@ std::unique_ptr<ZoneLoader> ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader&
|
||||
SetupBlock(*zoneLoader);
|
||||
|
||||
// Skip unknown 1 byte field that the game ignores as well
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(1));
|
||||
zoneLoader->AddLoadingStep(step::CreateStepSkipBytes(1));
|
||||
|
||||
// Skip timestamp
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(8));
|
||||
zoneLoader->AddLoadingStep(step::CreateStepSkipBytes(8));
|
||||
|
||||
// Add steps for loading the auth header which also contain the signature of the zone if it is signed.
|
||||
AddAuthHeaderSteps(isSecure, isOfficial, *zoneLoader, fileName);
|
||||
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepAddProcessor>(std::make_unique<ProcessorInflate>(ZoneConstants::AUTHED_CHUNK_SIZE)));
|
||||
zoneLoader->AddLoadingStep(step::CreateStepAddProcessor(processor::CreateProcessorInflate(ZoneConstants::AUTHED_CHUNK_SIZE)));
|
||||
|
||||
if (isIw4x) // IW4x has one extra byte of padding here for protection purposes
|
||||
{
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepAddProcessor>(std::make_unique<ProcessorIW4xDecryption>()));
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(1));
|
||||
zoneLoader->AddLoadingStep(step::CreateStepAddProcessor(processor::CreateProcessorIW4xDecryption()));
|
||||
zoneLoader->AddLoadingStep(step::CreateStepSkipBytes(1));
|
||||
}
|
||||
|
||||
// Start of the XFile struct
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(8));
|
||||
// Skip size and externalSize fields since they are not interesting for us
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepAllocXBlocks>());
|
||||
zoneLoader->AddLoadingStep(step::CreateStepLoadZoneSizes());
|
||||
zoneLoader->AddLoadingStep(step::CreateStepAllocXBlocks());
|
||||
|
||||
// Start of the zone content
|
||||
zoneLoader->AddLoadingStep(
|
||||
std::make_unique<StepLoadZoneContent>(std::make_unique<ContentLoader>(), zonePtr, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK));
|
||||
step::CreateStepLoadZoneContent(std::make_unique<ContentLoader>(*zonePtr), ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK));
|
||||
|
||||
return zoneLoader;
|
||||
}
|
||||
|
@ -47,8 +47,9 @@
|
||||
|
||||
using namespace IW5;
|
||||
|
||||
ContentLoader::ContentLoader()
|
||||
: varXAsset(nullptr),
|
||||
ContentLoader::ContentLoader(Zone& zone)
|
||||
: ContentLoaderBase(zone),
|
||||
varXAsset(nullptr),
|
||||
varScriptStringList(nullptr)
|
||||
{
|
||||
}
|
||||
@ -69,12 +70,12 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
||||
LoadXStringArray(true, varScriptStringList->count);
|
||||
|
||||
if (varScriptStringList->strings && varScriptStringList->count > 0)
|
||||
m_zone->m_script_strings.InitializeForExistingZone(varScriptStringList->strings, static_cast<size_t>(varScriptStringList->count));
|
||||
m_zone.m_script_strings.InitializeForExistingZone(varScriptStringList->strings, static_cast<size_t>(varScriptStringList->count));
|
||||
}
|
||||
|
||||
m_stream->PopBlock();
|
||||
|
||||
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) const
|
||||
@ -82,7 +83,7 @@ void ContentLoader::LoadXAsset(const bool atStreamStart) const
|
||||
#define LOAD_ASSET(type_index, typeName, headerEntry) \
|
||||
case type_index: \
|
||||
{ \
|
||||
Loader_##typeName loader(m_zone, m_stream); \
|
||||
Loader_##typeName loader(m_zone, *m_stream); \
|
||||
loader.Load(&varXAsset->header.headerEntry); \
|
||||
break; \
|
||||
}
|
||||
@ -162,10 +163,9 @@ void ContentLoader::LoadXAssetArray(const bool atStreamStart, const size_t count
|
||||
}
|
||||
}
|
||||
|
||||
void ContentLoader::Load(Zone* zone, IZoneInputStream* stream)
|
||||
void ContentLoader::Load(ZoneInputStream& stream)
|
||||
{
|
||||
m_zone = zone;
|
||||
m_stream = stream;
|
||||
m_stream = &stream;
|
||||
|
||||
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "Game/IW5/IW5.h"
|
||||
#include "Loading/ContentLoaderBase.h"
|
||||
#include "Loading/IContentLoadingEntryPoint.h"
|
||||
@ -7,17 +8,18 @@ namespace IW5
|
||||
{
|
||||
class ContentLoader final : public ContentLoaderBase, public IContentLoadingEntryPoint
|
||||
{
|
||||
XAsset* varXAsset;
|
||||
ScriptStringList* varScriptStringList;
|
||||
public:
|
||||
explicit ContentLoader(Zone& zone);
|
||||
|
||||
void Load(ZoneInputStream& stream) override;
|
||||
|
||||
private:
|
||||
void LoadScriptStringList(bool atStreamStart);
|
||||
|
||||
void LoadXAsset(bool atStreamStart) const;
|
||||
void LoadXAssetArray(bool atStreamStart, size_t count);
|
||||
|
||||
public:
|
||||
ContentLoader();
|
||||
|
||||
void Load(Zone* zone, IZoneInputStream* stream) override;
|
||||
XAsset* varXAsset;
|
||||
ScriptStringList* varScriptStringList;
|
||||
};
|
||||
} // namespace IW5
|
||||
|
@ -5,13 +5,13 @@
|
||||
|
||||
using namespace IW5;
|
||||
|
||||
Actions_clipMap_t::Actions_clipMap_t(Zone* zone)
|
||||
Actions_clipMap_t::Actions_clipMap_t(Zone& zone)
|
||||
: AssetLoadingActions(zone)
|
||||
{
|
||||
}
|
||||
|
||||
void Actions_clipMap_t::ReallocClipInfo(const ClipInfo* clipInfo, clipMap_t* clipMap) const
|
||||
{
|
||||
clipMap->pInfo = m_zone->GetMemory()->Alloc<ClipInfo>();
|
||||
clipMap->pInfo = m_zone.Memory().Alloc<ClipInfo>();
|
||||
memcpy(clipMap->pInfo, clipInfo, sizeof(ClipInfo));
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ namespace IW5
|
||||
class Actions_clipMap_t final : public AssetLoadingActions
|
||||
{
|
||||
public:
|
||||
explicit Actions_clipMap_t(Zone* zone);
|
||||
explicit Actions_clipMap_t(Zone& zone);
|
||||
|
||||
void ReallocClipInfo(const ClipInfo* clipInfo, clipMap_t* clipMap) const;
|
||||
};
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
using namespace IW5;
|
||||
|
||||
Actions_GfxImage::Actions_GfxImage(Zone* zone)
|
||||
Actions_GfxImage::Actions_GfxImage(Zone& zone)
|
||||
: AssetLoadingActions(zone)
|
||||
{
|
||||
}
|
||||
@ -19,6 +19,6 @@ void Actions_GfxImage::LoadImageData(GfxImageLoadDef* loadDef, GfxImage* image)
|
||||
{
|
||||
const size_t loadDefSize = offsetof(IW5::GfxImageLoadDef, data) + loadDef->resourceSize;
|
||||
|
||||
image->texture.loadDef = static_cast<GfxImageLoadDef*>(m_zone->GetMemory()->AllocRaw(loadDefSize));
|
||||
image->texture.loadDef = static_cast<GfxImageLoadDef*>(m_zone.Memory().AllocRaw(loadDefSize));
|
||||
memcpy(image->texture.loadDef, loadDef, loadDefSize);
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ namespace IW5
|
||||
class Actions_GfxImage final : public AssetLoadingActions
|
||||
{
|
||||
public:
|
||||
explicit Actions_GfxImage(Zone* zone);
|
||||
explicit Actions_GfxImage(Zone& zone);
|
||||
|
||||
void OnImageLoaded(GfxImage* image) const;
|
||||
void LoadImageData(GfxImageLoadDef* loadDef, GfxImage* image) const;
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
using namespace IW5;
|
||||
|
||||
Actions_LoadedSound::Actions_LoadedSound(Zone* zone)
|
||||
Actions_LoadedSound::Actions_LoadedSound(Zone& zone)
|
||||
: AssetLoadingActions(zone)
|
||||
{
|
||||
}
|
||||
@ -14,7 +14,7 @@ void Actions_LoadedSound::SetSoundData(MssSound* sound) const
|
||||
if (sound->info.data_len > 0)
|
||||
{
|
||||
char* tempData = sound->data;
|
||||
sound->data = m_zone->GetMemory()->Alloc<char>(sound->info.data_len);
|
||||
sound->data = m_zone.Memory().Alloc<char>(sound->info.data_len);
|
||||
memcpy(sound->data, tempData, sound->info.data_len);
|
||||
}
|
||||
else
|
||||
|
@ -8,7 +8,7 @@ namespace IW5
|
||||
class Actions_LoadedSound final : public AssetLoadingActions
|
||||
{
|
||||
public:
|
||||
explicit Actions_LoadedSound(Zone* zone);
|
||||
explicit Actions_LoadedSound(Zone& zone);
|
||||
|
||||
void SetSoundData(MssSound* sound) const;
|
||||
};
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
using namespace IW5;
|
||||
|
||||
Actions_XModel::Actions_XModel(Zone* zone)
|
||||
Actions_XModel::Actions_XModel(Zone& zone)
|
||||
: AssetLoadingActions(zone)
|
||||
{
|
||||
}
|
||||
@ -13,7 +13,7 @@ void Actions_XModel::SetModelSurfs(XModelLodInfo* lodInfo, XModelSurfs* modelSur
|
||||
{
|
||||
if (modelSurfs)
|
||||
{
|
||||
lodInfo->modelSurfs = m_zone->GetMemory()->Alloc<XModelSurfs>();
|
||||
lodInfo->modelSurfs = m_zone.Memory().Alloc<XModelSurfs>();
|
||||
memcpy(lodInfo->modelSurfs, modelSurfs, sizeof(XModelSurfs));
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ namespace IW5
|
||||
class Actions_XModel final : public AssetLoadingActions
|
||||
{
|
||||
public:
|
||||
explicit Actions_XModel(Zone* zone);
|
||||
explicit Actions_XModel(Zone& zone);
|
||||
|
||||
void SetModelSurfs(XModelLodInfo* lodInfo, XModelSurfs* modelSurfs) const;
|
||||
};
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "Loading/Steps/StepLoadHash.h"
|
||||
#include "Loading/Steps/StepLoadSignature.h"
|
||||
#include "Loading/Steps/StepLoadZoneContent.h"
|
||||
#include "Loading/Steps/StepLoadZoneSizes.h"
|
||||
#include "Loading/Steps/StepRemoveProcessor.h"
|
||||
#include "Loading/Steps/StepSkipBytes.h"
|
||||
#include "Loading/Steps/StepVerifyFileName.h"
|
||||
@ -107,39 +108,39 @@ namespace
|
||||
// If file is signed setup a RSA instance.
|
||||
auto rsa = SetupRsa(isOfficial);
|
||||
|
||||
zoneLoader.AddLoadingStep(std::make_unique<StepVerifyMagic>(ZoneConstants::MAGIC_AUTH_HEADER));
|
||||
zoneLoader.AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved
|
||||
zoneLoader.AddLoadingStep(step::CreateStepVerifyMagic(ZoneConstants::MAGIC_AUTH_HEADER));
|
||||
zoneLoader.AddLoadingStep(step::CreateStepSkipBytes(4)); // Skip reserved
|
||||
|
||||
auto subHeaderHash = std::make_unique<StepLoadHash>(sizeof(DB_AuthHash::bytes), 1);
|
||||
auto subHeaderHash = step::CreateStepLoadHash(sizeof(DB_AuthHash::bytes), 1);
|
||||
auto* subHeaderHashPtr = subHeaderHash.get();
|
||||
zoneLoader.AddLoadingStep(std::move(subHeaderHash));
|
||||
|
||||
auto subHeaderHashSignature = std::make_unique<StepLoadSignature>(sizeof(DB_AuthSignature::bytes));
|
||||
auto subHeaderHashSignature = step::CreateStepLoadSignature(sizeof(DB_AuthSignature::bytes));
|
||||
auto* subHeaderHashSignaturePtr = subHeaderHashSignature.get();
|
||||
zoneLoader.AddLoadingStep(std::move(subHeaderHashSignature));
|
||||
|
||||
zoneLoader.AddLoadingStep(std::make_unique<StepVerifySignature>(std::move(rsa), subHeaderHashSignaturePtr, subHeaderHashPtr));
|
||||
zoneLoader.AddLoadingStep(step::CreateStepVerifySignature(std::move(rsa), subHeaderHashSignaturePtr, subHeaderHashPtr));
|
||||
|
||||
auto subHeaderCapture = std::make_unique<ProcessorCaptureData>(sizeof(DB_AuthSubHeader));
|
||||
auto subHeaderCapture = processor::CreateProcessorCaptureData(sizeof(DB_AuthSubHeader));
|
||||
auto* subHeaderCapturePtr = subHeaderCapture.get();
|
||||
zoneLoader.AddLoadingStep(std::make_unique<StepAddProcessor>(std::move(subHeaderCapture)));
|
||||
zoneLoader.AddLoadingStep(step::CreateStepAddProcessor(std::move(subHeaderCapture)));
|
||||
|
||||
zoneLoader.AddLoadingStep(std::make_unique<StepVerifyFileName>(fileName, sizeof(DB_AuthSubHeader::fastfileName)));
|
||||
zoneLoader.AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved
|
||||
zoneLoader.AddLoadingStep(step::CreateStepVerifyFileName(fileName, sizeof(DB_AuthSubHeader::fastfileName)));
|
||||
zoneLoader.AddLoadingStep(step::CreateStepSkipBytes(4)); // Skip reserved
|
||||
|
||||
auto masterBlockHashes =
|
||||
std::make_unique<StepLoadHash>(sizeof(DB_AuthHash::bytes), static_cast<unsigned>(std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>));
|
||||
step::CreateStepLoadHash(sizeof(DB_AuthHash::bytes), static_cast<unsigned>(std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>));
|
||||
auto* masterBlockHashesPtr = masterBlockHashes.get();
|
||||
zoneLoader.AddLoadingStep(std::move(masterBlockHashes));
|
||||
|
||||
zoneLoader.AddLoadingStep(std::make_unique<StepVerifyHash>(cryptography::CreateSha256(), 0, subHeaderHashPtr, subHeaderCapturePtr));
|
||||
zoneLoader.AddLoadingStep(std::make_unique<StepRemoveProcessor>(subHeaderCapturePtr));
|
||||
zoneLoader.AddLoadingStep(step::CreateStepVerifyHash(cryptography::CreateSha256(), 0, subHeaderHashPtr, subHeaderCapturePtr));
|
||||
zoneLoader.AddLoadingStep(step::CreateStepRemoveProcessor(subHeaderCapturePtr));
|
||||
|
||||
// Skip the rest of the first chunk
|
||||
zoneLoader.AddLoadingStep(std::make_unique<StepSkipBytes>(ZoneConstants::AUTHED_CHUNK_SIZE - sizeof(DB_AuthHeader)));
|
||||
zoneLoader.AddLoadingStep(step::CreateStepSkipBytes(ZoneConstants::AUTHED_CHUNK_SIZE - sizeof(DB_AuthHeader)));
|
||||
|
||||
zoneLoader.AddLoadingStep(std::make_unique<StepAddProcessor>(
|
||||
std::make_unique<ProcessorAuthedBlocks>(ZoneConstants::AUTHED_CHUNK_COUNT_PER_GROUP,
|
||||
zoneLoader.AddLoadingStep(step::CreateStepAddProcessor(
|
||||
processor::CreateProcessorAuthedBlocks(ZoneConstants::AUTHED_CHUNK_COUNT_PER_GROUP,
|
||||
ZoneConstants::AUTHED_CHUNK_SIZE,
|
||||
static_cast<unsigned>(std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>),
|
||||
cryptography::CreateSha256(),
|
||||
@ -168,24 +169,23 @@ std::unique_ptr<ZoneLoader> ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader&
|
||||
SetupBlock(*zoneLoader);
|
||||
|
||||
// Skip unknown 1 byte field that the game ignores as well
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(1));
|
||||
zoneLoader->AddLoadingStep(step::CreateStepSkipBytes(1));
|
||||
|
||||
// Skip timestamp
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(8));
|
||||
zoneLoader->AddLoadingStep(step::CreateStepSkipBytes(8));
|
||||
|
||||
// Add steps for loading the auth header which also contain the signature of the zone if it is signed.
|
||||
AddAuthHeaderSteps(isSecure, isOfficial, *zoneLoader, fileName);
|
||||
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepAddProcessor>(std::make_unique<ProcessorInflate>(ZoneConstants::AUTHED_CHUNK_SIZE)));
|
||||
zoneLoader->AddLoadingStep(step::CreateStepAddProcessor(processor::CreateProcessorInflate(ZoneConstants::AUTHED_CHUNK_SIZE)));
|
||||
|
||||
// Start of the XFile struct
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(8));
|
||||
// Skip size and externalSize fields since they are not interesting for us
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepAllocXBlocks>());
|
||||
zoneLoader->AddLoadingStep(step::CreateStepLoadZoneSizes());
|
||||
zoneLoader->AddLoadingStep(step::CreateStepAllocXBlocks());
|
||||
|
||||
// Start of the zone content
|
||||
zoneLoader->AddLoadingStep(
|
||||
std::make_unique<StepLoadZoneContent>(std::make_unique<ContentLoader>(), zonePtr, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK));
|
||||
step::CreateStepLoadZoneContent(std::make_unique<ContentLoader>(*zonePtr), ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK));
|
||||
|
||||
return zoneLoader;
|
||||
}
|
||||
|
@ -39,8 +39,9 @@
|
||||
|
||||
using namespace T5;
|
||||
|
||||
ContentLoader::ContentLoader()
|
||||
: varXAsset(nullptr),
|
||||
ContentLoader::ContentLoader(Zone& zone)
|
||||
: ContentLoaderBase(zone),
|
||||
varXAsset(nullptr),
|
||||
varScriptStringList(nullptr)
|
||||
{
|
||||
}
|
||||
@ -61,12 +62,12 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
||||
LoadXStringArray(true, varScriptStringList->count);
|
||||
|
||||
if (varScriptStringList->strings && varScriptStringList->count > 0)
|
||||
m_zone->m_script_strings.InitializeForExistingZone(varScriptStringList->strings, static_cast<size_t>(varScriptStringList->count));
|
||||
m_zone.m_script_strings.InitializeForExistingZone(varScriptStringList->strings, static_cast<size_t>(varScriptStringList->count));
|
||||
}
|
||||
|
||||
m_stream->PopBlock();
|
||||
|
||||
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) const
|
||||
@ -74,7 +75,7 @@ void ContentLoader::LoadXAsset(const bool atStreamStart) const
|
||||
#define LOAD_ASSET(type_index, typeName, headerEntry) \
|
||||
case type_index: \
|
||||
{ \
|
||||
Loader_##typeName loader(m_zone, m_stream); \
|
||||
Loader_##typeName loader(m_zone, *m_stream); \
|
||||
loader.Load(&varXAsset->header.headerEntry); \
|
||||
break; \
|
||||
}
|
||||
@ -146,10 +147,9 @@ void ContentLoader::LoadXAssetArray(const bool atStreamStart, const size_t count
|
||||
}
|
||||
}
|
||||
|
||||
void ContentLoader::Load(Zone* zone, IZoneInputStream* stream)
|
||||
void ContentLoader::Load(ZoneInputStream& stream)
|
||||
{
|
||||
m_zone = zone;
|
||||
m_stream = stream;
|
||||
m_stream = &stream;
|
||||
|
||||
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "Game/T5/T5.h"
|
||||
#include "Loading/ContentLoaderBase.h"
|
||||
#include "Loading/IContentLoadingEntryPoint.h"
|
||||
@ -7,17 +8,18 @@ namespace T5
|
||||
{
|
||||
class ContentLoader final : public ContentLoaderBase, public IContentLoadingEntryPoint
|
||||
{
|
||||
XAsset* varXAsset;
|
||||
ScriptStringList* varScriptStringList;
|
||||
public:
|
||||
explicit ContentLoader(Zone& zone);
|
||||
|
||||
void Load(ZoneInputStream& stream) override;
|
||||
|
||||
private:
|
||||
void LoadScriptStringList(bool atStreamStart);
|
||||
|
||||
void LoadXAsset(bool atStreamStart) const;
|
||||
void LoadXAssetArray(bool atStreamStart, size_t count);
|
||||
|
||||
public:
|
||||
ContentLoader();
|
||||
|
||||
void Load(Zone* zone, IZoneInputStream* stream) override;
|
||||
XAsset* varXAsset;
|
||||
ScriptStringList* varScriptStringList;
|
||||
};
|
||||
} // namespace T5
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
using namespace T5;
|
||||
|
||||
Actions_GfxImage::Actions_GfxImage(Zone* zone)
|
||||
Actions_GfxImage::Actions_GfxImage(Zone& zone)
|
||||
: AssetLoadingActions(zone)
|
||||
{
|
||||
}
|
||||
@ -19,6 +19,6 @@ void Actions_GfxImage::LoadImageData(GfxImageLoadDef* loadDef, GfxImage* image)
|
||||
{
|
||||
const size_t loadDefSize = offsetof(GfxImageLoadDef, data) + loadDef->resourceSize;
|
||||
|
||||
image->texture.loadDef = static_cast<GfxImageLoadDef*>(m_zone->GetMemory()->AllocRaw(loadDefSize));
|
||||
image->texture.loadDef = static_cast<GfxImageLoadDef*>(m_zone.Memory().AllocRaw(loadDefSize));
|
||||
memcpy(image->texture.loadDef, loadDef, loadDefSize);
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ namespace T5
|
||||
class Actions_GfxImage final : public AssetLoadingActions
|
||||
{
|
||||
public:
|
||||
explicit Actions_GfxImage(Zone* zone);
|
||||
explicit Actions_GfxImage(Zone& zone);
|
||||
|
||||
void OnImageLoaded(GfxImage* image) const;
|
||||
void LoadImageData(GfxImageLoadDef* loadDef, GfxImage* image) const;
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "Loading/Steps/StepAddProcessor.h"
|
||||
#include "Loading/Steps/StepAllocXBlocks.h"
|
||||
#include "Loading/Steps/StepLoadZoneContent.h"
|
||||
#include "Loading/Steps/StepLoadZoneSizes.h"
|
||||
#include "Loading/Steps/StepSkipBytes.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
|
||||
@ -77,16 +78,15 @@ std::unique_ptr<ZoneLoader> ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader&
|
||||
|
||||
SetupBlock(*zoneLoader);
|
||||
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepAddProcessor>(std::make_unique<ProcessorInflate>(ZoneConstants::AUTHED_CHUNK_SIZE)));
|
||||
zoneLoader->AddLoadingStep(step::CreateStepAddProcessor(processor::CreateProcessorInflate(ZoneConstants::AUTHED_CHUNK_SIZE)));
|
||||
|
||||
// Start of the XFile struct
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepSkipBytes>(8));
|
||||
// Skip size and externalSize fields since they are not interesting for us
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepAllocXBlocks>());
|
||||
zoneLoader->AddLoadingStep(step::CreateStepLoadZoneSizes());
|
||||
zoneLoader->AddLoadingStep(step::CreateStepAllocXBlocks());
|
||||
|
||||
// Start of the zone content
|
||||
zoneLoader->AddLoadingStep(
|
||||
std::make_unique<StepLoadZoneContent>(std::make_unique<ContentLoader>(), zonePtr, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK));
|
||||
step::CreateStepLoadZoneContent(std::make_unique<ContentLoader>(*zonePtr), ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK));
|
||||
|
||||
return zoneLoader;
|
||||
}
|
||||
|
@ -55,8 +55,9 @@
|
||||
|
||||
using namespace T6;
|
||||
|
||||
ContentLoader::ContentLoader()
|
||||
: varXAsset(nullptr),
|
||||
ContentLoader::ContentLoader(Zone& zone)
|
||||
: ContentLoaderBase(zone),
|
||||
varXAsset(nullptr),
|
||||
varScriptStringList(nullptr)
|
||||
{
|
||||
}
|
||||
@ -77,12 +78,12 @@ void ContentLoader::LoadScriptStringList(const bool atStreamStart)
|
||||
LoadXStringArray(true, varScriptStringList->count);
|
||||
|
||||
if (varScriptStringList->strings && varScriptStringList->count > 0)
|
||||
m_zone->m_script_strings.InitializeForExistingZone(varScriptStringList->strings, static_cast<size_t>(varScriptStringList->count));
|
||||
m_zone.m_script_strings.InitializeForExistingZone(varScriptStringList->strings, static_cast<size_t>(varScriptStringList->count));
|
||||
}
|
||||
|
||||
m_stream->PopBlock();
|
||||
|
||||
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) const
|
||||
@ -90,7 +91,7 @@ void ContentLoader::LoadXAsset(const bool atStreamStart) const
|
||||
#define LOAD_ASSET(type_index, typeName, headerEntry) \
|
||||
case type_index: \
|
||||
{ \
|
||||
Loader_##typeName loader(m_zone, m_stream); \
|
||||
Loader_##typeName loader(m_zone, *m_stream); \
|
||||
loader.Load(&varXAsset->header.headerEntry); \
|
||||
break; \
|
||||
}
|
||||
@ -175,10 +176,9 @@ void ContentLoader::LoadXAssetArray(const bool atStreamStart, const size_t count
|
||||
}
|
||||
}
|
||||
|
||||
void ContentLoader::Load(Zone* zone, IZoneInputStream* stream)
|
||||
void ContentLoader::Load(ZoneInputStream& stream)
|
||||
{
|
||||
m_zone = zone;
|
||||
m_stream = stream;
|
||||
m_stream = &stream;
|
||||
|
||||
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "Game/T6/T6.h"
|
||||
#include "Loading/ContentLoaderBase.h"
|
||||
#include "Loading/IContentLoadingEntryPoint.h"
|
||||
@ -7,17 +8,18 @@ namespace T6
|
||||
{
|
||||
class ContentLoader final : public ContentLoaderBase, public IContentLoadingEntryPoint
|
||||
{
|
||||
XAsset* varXAsset;
|
||||
ScriptStringList* varScriptStringList;
|
||||
public:
|
||||
explicit ContentLoader(Zone& zone);
|
||||
|
||||
void Load(ZoneInputStream& stream) override;
|
||||
|
||||
private:
|
||||
void LoadScriptStringList(bool atStreamStart);
|
||||
|
||||
void LoadXAsset(bool atStreamStart) const;
|
||||
void LoadXAssetArray(bool atStreamStart, size_t count);
|
||||
|
||||
public:
|
||||
ContentLoader();
|
||||
|
||||
void Load(Zone* zone, IZoneInputStream* stream) override;
|
||||
XAsset* varXAsset;
|
||||
ScriptStringList* varScriptStringList;
|
||||
};
|
||||
} // namespace T6
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
using namespace T6;
|
||||
|
||||
Actions_GfxImage::Actions_GfxImage(Zone* zone)
|
||||
Actions_GfxImage::Actions_GfxImage(Zone& zone)
|
||||
: AssetLoadingActions(zone)
|
||||
{
|
||||
}
|
||||
@ -19,6 +19,6 @@ void Actions_GfxImage::LoadImageData(GfxImageLoadDef* loadDef, GfxImage* image)
|
||||
{
|
||||
const size_t loadDefSize = offsetof(T6::GfxImageLoadDef, data) + loadDef->resourceSize;
|
||||
|
||||
image->texture.loadDef = static_cast<GfxImageLoadDef*>(m_zone->GetMemory()->AllocRaw(loadDefSize));
|
||||
image->texture.loadDef = static_cast<GfxImageLoadDef*>(m_zone.Memory().AllocRaw(loadDefSize));
|
||||
memcpy(image->texture.loadDef, loadDef, loadDefSize);
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ namespace T6
|
||||
class Actions_GfxImage final : public AssetLoadingActions
|
||||
{
|
||||
public:
|
||||
explicit Actions_GfxImage(Zone* zone);
|
||||
explicit Actions_GfxImage(Zone& zone);
|
||||
|
||||
void OnImageLoaded(GfxImage* image) const;
|
||||
void LoadImageData(GfxImageLoadDef* loadDef, GfxImage* image) const;
|
||||
|
@ -35,7 +35,7 @@ namespace
|
||||
|
||||
for (const auto& languagePrefix : languagePrefixes)
|
||||
{
|
||||
if (zoneName.compare(0, languagePrefix.m_prefix.length(), languagePrefix.m_prefix) == 0)
|
||||
if (zoneName.starts_with(languagePrefix.m_prefix))
|
||||
{
|
||||
return languagePrefix.m_language;
|
||||
}
|
||||
@ -128,17 +128,17 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
ISignatureProvider* AddAuthHeaderSteps(const bool isSecure, ZoneLoader& zoneLoader, std::string& fileName)
|
||||
ISignatureProvider* AddAuthHeaderSteps(const bool isSecure, ZoneLoader& zoneLoader, const std::string& fileName)
|
||||
{
|
||||
// Unsigned zones do not have an auth header
|
||||
if (!isSecure)
|
||||
return nullptr;
|
||||
|
||||
zoneLoader.AddLoadingStep(std::make_unique<StepVerifyMagic>(ZoneConstants::MAGIC_AUTH_HEADER));
|
||||
zoneLoader.AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Loading Flags which are always zero
|
||||
zoneLoader.AddLoadingStep(std::make_unique<StepVerifyFileName>(fileName, 32));
|
||||
zoneLoader.AddLoadingStep(step::CreateStepVerifyMagic(ZoneConstants::MAGIC_AUTH_HEADER));
|
||||
zoneLoader.AddLoadingStep(step::CreateStepSkipBytes(4)); // Loading Flags which are always zero
|
||||
zoneLoader.AddLoadingStep(step::CreateStepVerifyFileName(fileName, 32));
|
||||
|
||||
auto signatureLoadStep = std::make_unique<StepLoadSignature>(256);
|
||||
auto signatureLoadStep = step::CreateStepLoadSignature(256);
|
||||
auto* signatureLoadStepPtr = signatureLoadStep.get();
|
||||
zoneLoader.AddLoadingStep(std::move(signatureLoadStep));
|
||||
|
||||
@ -148,7 +148,7 @@ namespace
|
||||
ICapturedDataProvider* AddXChunkProcessor(const bool isEncrypted, ZoneLoader& zoneLoader, std::string& fileName)
|
||||
{
|
||||
ICapturedDataProvider* result = nullptr;
|
||||
auto xChunkProcessor = std::make_unique<ProcessorXChunks>(ZoneConstants::STREAM_COUNT, ZoneConstants::XCHUNK_SIZE, ZoneConstants::VANILLA_BUFFER_SIZE);
|
||||
auto xChunkProcessor = processor::CreateProcessorXChunks(ZoneConstants::STREAM_COUNT, ZoneConstants::XCHUNK_SIZE, ZoneConstants::VANILLA_BUFFER_SIZE);
|
||||
|
||||
if (isEncrypted)
|
||||
{
|
||||
@ -161,7 +161,7 @@ namespace
|
||||
|
||||
// Decompress the chunks using zlib
|
||||
xChunkProcessor->AddChunkProcessor(std::make_unique<XChunkProcessorInflate>());
|
||||
zoneLoader.AddLoadingStep(std::make_unique<StepAddProcessor>(std::move(xChunkProcessor)));
|
||||
zoneLoader.AddLoadingStep(step::CreateStepAddProcessor(std::move(xChunkProcessor)));
|
||||
|
||||
// If there is encryption, the signed data of the zone is the final hash blocks provided by the Salsa20 IV adaption algorithm
|
||||
return result;
|
||||
@ -199,16 +199,16 @@ std::unique_ptr<ZoneLoader> ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader&
|
||||
ICapturedDataProvider* signatureDataProvider = AddXChunkProcessor(isEncrypted, *zoneLoader, fileName);
|
||||
|
||||
// Start of the XFile struct
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepLoadZoneSizes>());
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepAllocXBlocks>());
|
||||
zoneLoader->AddLoadingStep(step::CreateStepLoadZoneSizes());
|
||||
zoneLoader->AddLoadingStep(step::CreateStepAllocXBlocks());
|
||||
|
||||
// Start of the zone content
|
||||
zoneLoader->AddLoadingStep(
|
||||
std::make_unique<StepLoadZoneContent>(std::make_unique<ContentLoader>(), zonePtr, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK));
|
||||
step::CreateStepLoadZoneContent(std::make_unique<ContentLoader>(*zonePtr), ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK));
|
||||
|
||||
if (isSecure)
|
||||
{
|
||||
zoneLoader->AddLoadingStep(std::make_unique<StepVerifySignature>(std::move(rsa), signatureProvider, signatureDataProvider));
|
||||
zoneLoader->AddLoadingStep(step::CreateStepVerifySignature(std::move(rsa), signatureProvider, signatureDataProvider));
|
||||
}
|
||||
|
||||
return zoneLoader;
|
||||
|
@ -3,10 +3,10 @@
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
AssetLoader::AssetLoader(const asset_type_t assetType, Zone* zone, IZoneInputStream* stream)
|
||||
AssetLoader::AssetLoader(const asset_type_t assetType, Zone& zone, ZoneInputStream& stream)
|
||||
: ContentLoaderBase(zone, stream),
|
||||
m_asset_type(assetType),
|
||||
varScriptString(nullptr)
|
||||
varScriptString(nullptr),
|
||||
m_asset_type(assetType)
|
||||
{
|
||||
}
|
||||
|
||||
@ -16,11 +16,11 @@ XAssetInfoGeneric* AssetLoader::LinkAsset(std::string name,
|
||||
std::vector<scr_string_t> scriptStrings,
|
||||
std::vector<IndirectAssetReference> indirectAssetReferences) const
|
||||
{
|
||||
return m_zone->m_pools->AddAsset(
|
||||
return m_zone.m_pools->AddAsset(
|
||||
m_asset_type, std::move(name), asset, std::move(dependencies), std::move(scriptStrings), std::move(indirectAssetReferences));
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* AssetLoader::GetAssetInfo(const std::string& name) const
|
||||
{
|
||||
return m_zone->m_pools->GetAsset(m_asset_type, name);
|
||||
return m_zone.m_pools->GetAsset(m_asset_type, name);
|
||||
}
|
||||
|
@ -4,17 +4,12 @@
|
||||
#include "Pool/XAssetInfo.h"
|
||||
#include "Zone/ZoneTypes.h"
|
||||
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
class AssetLoader : public ContentLoaderBase
|
||||
{
|
||||
asset_type_t m_asset_type;
|
||||
|
||||
protected:
|
||||
scr_string_t* varScriptString;
|
||||
|
||||
AssetLoader(asset_type_t assetType, Zone* zone, IZoneInputStream* stream);
|
||||
AssetLoader(asset_type_t assetType, Zone& zone, ZoneInputStream& stream);
|
||||
|
||||
XAssetInfoGeneric* LinkAsset(std::string name,
|
||||
void* asset,
|
||||
@ -22,5 +17,10 @@ protected:
|
||||
std::vector<scr_string_t> scriptStrings,
|
||||
std::vector<IndirectAssetReference> indirectAssetReferences) const;
|
||||
|
||||
_NODISCARD XAssetInfoGeneric* GetAssetInfo(const std::string& name) const;
|
||||
[[nodiscard]] XAssetInfoGeneric* GetAssetInfo(const std::string& name) const;
|
||||
|
||||
scr_string_t* varScriptString;
|
||||
|
||||
private:
|
||||
asset_type_t m_asset_type;
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "AssetLoadingActions.h"
|
||||
|
||||
AssetLoadingActions::AssetLoadingActions(Zone* zone)
|
||||
AssetLoadingActions::AssetLoadingActions(Zone& zone)
|
||||
: m_zone(zone)
|
||||
{
|
||||
m_zone = zone;
|
||||
}
|
||||
|
@ -4,9 +4,9 @@
|
||||
|
||||
class AssetLoadingActions
|
||||
{
|
||||
protected:
|
||||
Zone* m_zone;
|
||||
|
||||
public:
|
||||
explicit AssetLoadingActions(Zone* zone);
|
||||
explicit AssetLoadingActions(Zone& zone);
|
||||
|
||||
protected:
|
||||
Zone& m_zone;
|
||||
};
|
||||
|
@ -3,9 +3,9 @@
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
AssetMarker::AssetMarker(const asset_type_t assetType, Zone* zone)
|
||||
: m_asset_type(assetType),
|
||||
m_zone(zone)
|
||||
AssetMarker::AssetMarker(const asset_type_t assetType, Zone& zone)
|
||||
: m_zone(zone),
|
||||
m_asset_type(assetType)
|
||||
{
|
||||
}
|
||||
|
||||
@ -23,9 +23,9 @@ void AssetMarker::AddDependency(XAssetInfoGeneric* assetInfo)
|
||||
|
||||
void AssetMarker::Mark_ScriptString(const scr_string_t scrString)
|
||||
{
|
||||
assert(scrString < m_zone->m_script_strings.Count());
|
||||
assert(scrString < m_zone.m_script_strings.Count());
|
||||
|
||||
if (scrString >= m_zone->m_script_strings.Count())
|
||||
if (scrString >= m_zone.m_script_strings.Count())
|
||||
return;
|
||||
|
||||
m_used_script_strings.emplace(scrString);
|
||||
@ -57,7 +57,7 @@ void AssetMarker::MarkArray_IndirectAssetRef(const asset_type_t type, const char
|
||||
|
||||
XAssetInfoGeneric* AssetMarker::GetAssetInfoByName(const std::string& name) const
|
||||
{
|
||||
return m_zone->m_pools->GetAsset(m_asset_type, name);
|
||||
return m_zone.m_pools->GetAsset(m_asset_type, name);
|
||||
}
|
||||
|
||||
std::vector<XAssetInfoGeneric*> AssetMarker::GetDependencies() const
|
||||
|
@ -2,21 +2,19 @@
|
||||
|
||||
#include "ContentLoaderBase.h"
|
||||
#include "Pool/XAssetInfo.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Zone/ZoneTypes.h"
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
class AssetMarker
|
||||
{
|
||||
asset_type_t m_asset_type;
|
||||
|
||||
std::unordered_set<XAssetInfoGeneric*> m_dependencies;
|
||||
std::unordered_set<scr_string_t> m_used_script_strings;
|
||||
std::unordered_set<IndirectAssetReference> m_indirect_asset_references;
|
||||
public:
|
||||
[[nodiscard]] std::vector<XAssetInfoGeneric*> GetDependencies() const;
|
||||
[[nodiscard]] std::vector<scr_string_t> GetUsedScriptStrings() const;
|
||||
[[nodiscard]] std::vector<IndirectAssetReference> GetIndirectAssetReferences() const;
|
||||
|
||||
protected:
|
||||
AssetMarker(asset_type_t assetType, Zone* zone);
|
||||
AssetMarker(asset_type_t assetType, Zone& zone);
|
||||
|
||||
void AddDependency(XAssetInfoGeneric* assetInfo);
|
||||
|
||||
@ -26,12 +24,14 @@ protected:
|
||||
void Mark_IndirectAssetRef(asset_type_t type, const char* assetRefName);
|
||||
void MarkArray_IndirectAssetRef(asset_type_t type, const char** assetRefNames, size_t count);
|
||||
|
||||
_NODISCARD XAssetInfoGeneric* GetAssetInfoByName(const std::string& name) const;
|
||||
[[nodiscard]] XAssetInfoGeneric* GetAssetInfoByName(const std::string& name) const;
|
||||
|
||||
Zone* m_zone;
|
||||
Zone& m_zone;
|
||||
|
||||
public:
|
||||
_NODISCARD std::vector<XAssetInfoGeneric*> GetDependencies() const;
|
||||
_NODISCARD std::vector<scr_string_t> GetUsedScriptStrings() const;
|
||||
_NODISCARD std::vector<IndirectAssetReference> GetIndirectAssetReferences() const;
|
||||
private:
|
||||
asset_type_t m_asset_type;
|
||||
|
||||
std::unordered_set<XAssetInfoGeneric*> m_dependencies;
|
||||
std::unordered_set<scr_string_t> m_used_script_strings;
|
||||
std::unordered_set<IndirectAssetReference> m_indirect_asset_references;
|
||||
};
|
||||
|
@ -5,17 +5,19 @@
|
||||
const void* ContentLoaderBase::PTR_FOLLOWING = reinterpret_cast<void*>(-1);
|
||||
const void* ContentLoaderBase::PTR_INSERT = reinterpret_cast<void*>(-2);
|
||||
|
||||
ContentLoaderBase::ContentLoaderBase()
|
||||
ContentLoaderBase::ContentLoaderBase(Zone& zone)
|
||||
: varXString(nullptr),
|
||||
m_zone(nullptr),
|
||||
m_zone(zone),
|
||||
m_memory(zone.Memory()),
|
||||
m_stream(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
ContentLoaderBase::ContentLoaderBase(Zone* zone, IZoneInputStream* stream)
|
||||
ContentLoaderBase::ContentLoaderBase(Zone& zone, ZoneInputStream& stream)
|
||||
: varXString(nullptr),
|
||||
m_zone(zone),
|
||||
m_stream(stream)
|
||||
m_memory(zone.Memory()),
|
||||
m_stream(&stream)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "Zone/Stream/IZoneInputStream.h"
|
||||
#include "Zone/Stream/ZoneInputStream.h"
|
||||
#include "Zone/Zone.h"
|
||||
|
||||
class ContentLoaderBase
|
||||
@ -9,17 +9,23 @@ protected:
|
||||
static const void* PTR_FOLLOWING;
|
||||
static const void* PTR_INSERT;
|
||||
|
||||
const char** varXString;
|
||||
public:
|
||||
virtual ~ContentLoaderBase() = default;
|
||||
ContentLoaderBase(const ContentLoaderBase& other) = default;
|
||||
ContentLoaderBase(ContentLoaderBase&& other) noexcept = default;
|
||||
ContentLoaderBase& operator=(const ContentLoaderBase& other) = delete;
|
||||
ContentLoaderBase& operator=(ContentLoaderBase&& other) noexcept = delete;
|
||||
|
||||
Zone* m_zone;
|
||||
IZoneInputStream* m_stream;
|
||||
|
||||
ContentLoaderBase();
|
||||
ContentLoaderBase(Zone* zone, IZoneInputStream* stream);
|
||||
protected:
|
||||
explicit ContentLoaderBase(Zone& zone);
|
||||
ContentLoaderBase(Zone& zone, ZoneInputStream& stream);
|
||||
|
||||
void LoadXString(bool atStreamStart) const;
|
||||
void LoadXStringArray(bool atStreamStart, size_t count);
|
||||
|
||||
public:
|
||||
virtual ~ContentLoaderBase() = default;
|
||||
const char** varXString;
|
||||
|
||||
Zone& m_zone;
|
||||
MemoryManager& m_memory;
|
||||
ZoneInputStream* m_stream;
|
||||
};
|
||||
|
@ -1,12 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "Zone/Stream/IZoneInputStream.h"
|
||||
#include "Zone/Zone.h"
|
||||
#include "Zone/Stream/ZoneInputStream.h"
|
||||
|
||||
class IContentLoadingEntryPoint
|
||||
{
|
||||
public:
|
||||
IContentLoadingEntryPoint() = default;
|
||||
virtual ~IContentLoadingEntryPoint() = default;
|
||||
IContentLoadingEntryPoint(const IContentLoadingEntryPoint& other) = default;
|
||||
IContentLoadingEntryPoint(IContentLoadingEntryPoint&& other) noexcept = default;
|
||||
IContentLoadingEntryPoint& operator=(const IContentLoadingEntryPoint& other) = default;
|
||||
IContentLoadingEntryPoint& operator=(IContentLoadingEntryPoint&& other) noexcept = default;
|
||||
|
||||
virtual void Load(Zone* zone, IZoneInputStream* stream) = 0;
|
||||
virtual void Load(ZoneInputStream& stream) = 0;
|
||||
};
|
||||
|
@ -6,5 +6,12 @@
|
||||
class IHashProvider
|
||||
{
|
||||
public:
|
||||
IHashProvider() = default;
|
||||
virtual ~IHashProvider() = default;
|
||||
IHashProvider(const IHashProvider& other) = default;
|
||||
IHashProvider(IHashProvider&& other) noexcept = default;
|
||||
IHashProvider& operator=(const IHashProvider& other) = default;
|
||||
IHashProvider& operator=(IHashProvider&& other) noexcept = default;
|
||||
|
||||
virtual void GetHash(unsigned hashIndex, const uint8_t** pHash, size_t* pSize) = 0;
|
||||
};
|
||||
|
@ -8,7 +8,12 @@ class ZoneLoader;
|
||||
class ILoadingStep
|
||||
{
|
||||
public:
|
||||
ILoadingStep() = default;
|
||||
virtual ~ILoadingStep() = default;
|
||||
ILoadingStep(const ILoadingStep& other) = default;
|
||||
ILoadingStep(ILoadingStep&& other) noexcept = default;
|
||||
ILoadingStep& operator=(const ILoadingStep& other) = default;
|
||||
ILoadingStep& operator=(ILoadingStep&& other) noexcept = default;
|
||||
|
||||
virtual void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) = 0;
|
||||
virtual void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) = 0;
|
||||
};
|
||||
|
@ -4,5 +4,12 @@
|
||||
class ISignatureProvider
|
||||
{
|
||||
public:
|
||||
ISignatureProvider() = default;
|
||||
virtual ~ISignatureProvider() = default;
|
||||
ISignatureProvider(const ISignatureProvider& other) = default;
|
||||
ISignatureProvider(ISignatureProvider&& other) noexcept = default;
|
||||
ISignatureProvider& operator=(const ISignatureProvider& other) = default;
|
||||
ISignatureProvider& operator=(ISignatureProvider&& other) noexcept = default;
|
||||
|
||||
virtual void GetSignature(const uint8_t** pSignature, size_t* pSize) = 0;
|
||||
};
|
||||
|
@ -1,15 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "ILoadingStream.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <istream>
|
||||
|
||||
class LoadingFileStream final : public ILoadingStream
|
||||
{
|
||||
std::istream& m_stream;
|
||||
|
||||
public:
|
||||
explicit LoadingFileStream(std::istream& stream);
|
||||
|
||||
size_t Load(void* buffer, size_t length) override;
|
||||
int64_t Pos() override;
|
||||
|
||||
private:
|
||||
std::istream& m_stream;
|
||||
};
|
||||
|
@ -5,39 +5,20 @@
|
||||
#include "Loading/Exception/TooManyAuthedGroupsException.h"
|
||||
#include "Loading/Exception/UnexpectedEndOfFileException.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
class ProcessorAuthedBlocks::Impl
|
||||
class ProcessorAuthedBlocks final : public StreamProcessor
|
||||
{
|
||||
ProcessorAuthedBlocks* const m_base;
|
||||
|
||||
const unsigned m_authed_chunk_count;
|
||||
const size_t m_chunk_size;
|
||||
const unsigned m_max_master_block_count;
|
||||
|
||||
const std::unique_ptr<cryptography::IHashFunction> m_hash_function;
|
||||
IHashProvider* const m_master_block_hash_provider;
|
||||
const std::unique_ptr<uint8_t[]> m_chunk_hashes_buffer;
|
||||
const std::unique_ptr<uint8_t[]> m_current_chunk_hash_buffer;
|
||||
|
||||
const std::unique_ptr<uint8_t[]> m_chunk_buffer;
|
||||
unsigned m_current_group;
|
||||
unsigned m_current_chunk_in_group;
|
||||
|
||||
size_t m_current_chunk_offset;
|
||||
size_t m_current_chunk_size;
|
||||
|
||||
public:
|
||||
Impl(ProcessorAuthedBlocks* base,
|
||||
const unsigned authedChunkCount,
|
||||
ProcessorAuthedBlocks(const unsigned authedChunkCount,
|
||||
const size_t chunkSize,
|
||||
const unsigned maxMasterBlockCount,
|
||||
std::unique_ptr<cryptography::IHashFunction> hashFunction,
|
||||
IHashProvider* masterBlockHashProvider)
|
||||
: m_base(base),
|
||||
m_authed_chunk_count(authedChunkCount),
|
||||
: m_authed_chunk_count(authedChunkCount),
|
||||
m_chunk_size(chunkSize),
|
||||
m_max_master_block_count(maxMasterBlockCount),
|
||||
m_hash_function(std::move(hashFunction)),
|
||||
@ -53,13 +34,43 @@ public:
|
||||
assert(m_authed_chunk_count * m_hash_function->GetHashSize() <= m_chunk_size);
|
||||
}
|
||||
|
||||
size_t Load(void* buffer, const size_t length) override
|
||||
{
|
||||
size_t loadedSize = 0;
|
||||
|
||||
while (loadedSize < length)
|
||||
{
|
||||
if (m_current_chunk_offset >= m_current_chunk_size)
|
||||
{
|
||||
if (!NextChunk())
|
||||
return loadedSize;
|
||||
}
|
||||
|
||||
auto sizeToWrite = length - loadedSize;
|
||||
sizeToWrite = std::min(sizeToWrite, m_current_chunk_size - m_current_chunk_offset);
|
||||
|
||||
assert(length - loadedSize >= sizeToWrite);
|
||||
std::memcpy(&static_cast<uint8_t*>(buffer)[loadedSize], &m_chunk_buffer[m_current_chunk_offset], sizeToWrite);
|
||||
loadedSize += sizeToWrite;
|
||||
m_current_chunk_offset += sizeToWrite;
|
||||
}
|
||||
|
||||
return loadedSize;
|
||||
}
|
||||
|
||||
int64_t Pos() override
|
||||
{
|
||||
return m_base_stream->Pos() - static_cast<int64_t>(m_current_chunk_size - m_current_chunk_offset);
|
||||
}
|
||||
|
||||
private:
|
||||
bool NextChunk()
|
||||
{
|
||||
m_current_chunk_offset = 0;
|
||||
|
||||
while (true)
|
||||
{
|
||||
m_current_chunk_size = m_base->m_base_stream->Load(m_chunk_buffer.get(), m_chunk_size);
|
||||
m_current_chunk_size = m_base_stream->Load(m_chunk_buffer.get(), m_chunk_size);
|
||||
|
||||
if (m_current_chunk_size == 0)
|
||||
return false;
|
||||
@ -79,7 +90,9 @@ public:
|
||||
|
||||
if (masterBlockHashSize != m_hash_function->GetHashSize()
|
||||
|| std::memcmp(m_current_chunk_hash_buffer.get(), masterBlockHash, m_hash_function->GetHashSize()) != 0)
|
||||
{
|
||||
throw InvalidHashException();
|
||||
}
|
||||
|
||||
memcpy(m_chunk_hashes_buffer.get(), m_chunk_buffer.get(), m_authed_chunk_count * m_hash_function->GetHashSize());
|
||||
|
||||
@ -91,7 +104,9 @@ public:
|
||||
&m_chunk_hashes_buffer[(m_current_chunk_in_group - 1) * m_hash_function->GetHashSize()],
|
||||
m_hash_function->GetHashSize())
|
||||
!= 0)
|
||||
{
|
||||
throw InvalidHashException();
|
||||
}
|
||||
|
||||
if (++m_current_chunk_in_group > m_authed_chunk_count)
|
||||
{
|
||||
@ -107,58 +122,31 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
size_t Load(void* buffer, const size_t length)
|
||||
{
|
||||
size_t loadedSize = 0;
|
||||
const unsigned m_authed_chunk_count;
|
||||
const size_t m_chunk_size;
|
||||
const unsigned m_max_master_block_count;
|
||||
|
||||
while (loadedSize < length)
|
||||
{
|
||||
if (m_current_chunk_offset >= m_current_chunk_size)
|
||||
{
|
||||
if (!NextChunk())
|
||||
return loadedSize;
|
||||
}
|
||||
const std::unique_ptr<cryptography::IHashFunction> m_hash_function;
|
||||
IHashProvider* const m_master_block_hash_provider;
|
||||
const std::unique_ptr<uint8_t[]> m_chunk_hashes_buffer;
|
||||
const std::unique_ptr<uint8_t[]> m_current_chunk_hash_buffer;
|
||||
|
||||
size_t sizeToWrite = length - loadedSize;
|
||||
if (sizeToWrite > m_current_chunk_size - m_current_chunk_offset)
|
||||
sizeToWrite = m_current_chunk_size - m_current_chunk_offset;
|
||||
const std::unique_ptr<uint8_t[]> m_chunk_buffer;
|
||||
unsigned m_current_group;
|
||||
unsigned m_current_chunk_in_group;
|
||||
|
||||
assert(length - loadedSize >= sizeToWrite);
|
||||
memcpy(&static_cast<uint8_t*>(buffer)[loadedSize], &m_chunk_buffer[m_current_chunk_offset], sizeToWrite);
|
||||
loadedSize += sizeToWrite;
|
||||
m_current_chunk_offset += sizeToWrite;
|
||||
}
|
||||
|
||||
return loadedSize;
|
||||
}
|
||||
|
||||
int64_t Pos()
|
||||
{
|
||||
return m_base->m_base_stream->Pos() - (m_current_chunk_size - m_current_chunk_offset);
|
||||
}
|
||||
size_t m_current_chunk_offset;
|
||||
size_t m_current_chunk_size;
|
||||
};
|
||||
|
||||
ProcessorAuthedBlocks::ProcessorAuthedBlocks(const unsigned authedChunkCount,
|
||||
const size_t chunkSize,
|
||||
const unsigned maxMasterBlockCount,
|
||||
namespace processor
|
||||
{
|
||||
std::unique_ptr<StreamProcessor> CreateProcessorAuthedBlocks(unsigned authedChunkCount,
|
||||
size_t chunkSize,
|
||||
unsigned maxMasterBlockCount,
|
||||
std::unique_ptr<cryptography::IHashFunction> hashFunction,
|
||||
IHashProvider* masterBlockHashProvider)
|
||||
: m_impl(new Impl(this, authedChunkCount, chunkSize, maxMasterBlockCount, std::move(hashFunction), masterBlockHashProvider))
|
||||
{
|
||||
}
|
||||
|
||||
ProcessorAuthedBlocks::~ProcessorAuthedBlocks()
|
||||
{
|
||||
delete m_impl;
|
||||
m_impl = nullptr;
|
||||
}
|
||||
|
||||
size_t ProcessorAuthedBlocks::Load(void* buffer, const size_t length)
|
||||
{
|
||||
return m_impl->Load(buffer, length);
|
||||
}
|
||||
|
||||
int64_t ProcessorAuthedBlocks::Pos()
|
||||
{
|
||||
return m_impl->Pos();
|
||||
}
|
||||
{
|
||||
return std::make_unique<ProcessorAuthedBlocks>(authedChunkCount, chunkSize, maxMasterBlockCount, std::move(hashFunction), masterBlockHashProvider);
|
||||
}
|
||||
} // namespace processor
|
||||
|
@ -6,23 +6,11 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
class ProcessorAuthedBlocks final : public StreamProcessor
|
||||
namespace processor
|
||||
{
|
||||
class Impl;
|
||||
Impl* m_impl;
|
||||
|
||||
public:
|
||||
ProcessorAuthedBlocks(unsigned authedChunkCount,
|
||||
std::unique_ptr<StreamProcessor> CreateProcessorAuthedBlocks(unsigned authedChunkCount,
|
||||
size_t chunkSize,
|
||||
unsigned maxMasterBlockCount,
|
||||
std::unique_ptr<cryptography::IHashFunction> hashFunction,
|
||||
IHashProvider* masterBlockHashProvider);
|
||||
~ProcessorAuthedBlocks() override;
|
||||
ProcessorAuthedBlocks(const ProcessorAuthedBlocks& other) = delete;
|
||||
ProcessorAuthedBlocks(ProcessorAuthedBlocks&& other) noexcept = default;
|
||||
ProcessorAuthedBlocks& operator=(const ProcessorAuthedBlocks& other) = delete;
|
||||
ProcessorAuthedBlocks& operator=(ProcessorAuthedBlocks&& other) noexcept = default;
|
||||
|
||||
size_t Load(void* buffer, size_t length) override;
|
||||
int64_t Pos() override;
|
||||
};
|
||||
}
|
||||
|
@ -1,30 +1,32 @@
|
||||
#include "ProcessorCaptureData.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
ProcessorCaptureData::ProcessorCaptureData(const size_t captureSize)
|
||||
namespace
|
||||
{
|
||||
class ProcessorCaptureData final : public processor::IProcessorCaptureData
|
||||
{
|
||||
public:
|
||||
explicit ProcessorCaptureData(const size_t captureSize)
|
||||
: m_data(std::make_unique<uint8_t[]>(captureSize)),
|
||||
m_capture_size(captureSize),
|
||||
m_captured_data_size(0)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
ProcessorCaptureData::~ProcessorCaptureData() = default;
|
||||
|
||||
size_t ProcessorCaptureData::Load(void* buffer, const size_t length)
|
||||
{
|
||||
size_t Load(void* buffer, const size_t length) override
|
||||
{
|
||||
if (m_captured_data_size >= m_capture_size)
|
||||
return m_base_stream->Load(buffer, length);
|
||||
|
||||
size_t dataToCapture = m_capture_size - m_captured_data_size;
|
||||
auto dataToCapture = m_capture_size - m_captured_data_size;
|
||||
dataToCapture = std::min(length, dataToCapture);
|
||||
|
||||
if (length < dataToCapture)
|
||||
dataToCapture = length;
|
||||
|
||||
size_t loadedSize = m_base_stream->Load(&m_data[m_captured_data_size], dataToCapture);
|
||||
auto loadedSize = m_base_stream->Load(&m_data[m_captured_data_size], dataToCapture);
|
||||
assert(length >= loadedSize);
|
||||
memcpy(buffer, &m_data[m_captured_data_size], loadedSize);
|
||||
std::memcpy(buffer, &m_data[m_captured_data_size], loadedSize);
|
||||
|
||||
m_captured_data_size += loadedSize;
|
||||
|
||||
@ -32,15 +34,15 @@ size_t ProcessorCaptureData::Load(void* buffer, const size_t length)
|
||||
loadedSize += m_base_stream->Load(&static_cast<uint8_t*>(buffer)[dataToCapture], length - dataToCapture);
|
||||
|
||||
return loadedSize;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t ProcessorCaptureData::Pos()
|
||||
{
|
||||
int64_t Pos() override
|
||||
{
|
||||
return m_base_stream->Pos();
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessorCaptureData::GetCapturedData(const uint8_t** pCapturedData, size_t* pSize)
|
||||
{
|
||||
void GetCapturedData(const uint8_t** pCapturedData, size_t* pSize) override
|
||||
{
|
||||
assert(pCapturedData != nullptr);
|
||||
assert(pSize != nullptr);
|
||||
|
||||
@ -48,4 +50,19 @@ void ProcessorCaptureData::GetCapturedData(const uint8_t** pCapturedData, size_t
|
||||
|
||||
*pCapturedData = m_data.get();
|
||||
*pSize = m_captured_data_size;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<uint8_t[]> m_data;
|
||||
size_t m_capture_size;
|
||||
size_t m_captured_data_size;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace processor
|
||||
{
|
||||
std::unique_ptr<IProcessorCaptureData> CreateProcessorCaptureData(size_t captureSize)
|
||||
{
|
||||
return std::make_unique<ProcessorCaptureData>(captureSize);
|
||||
}
|
||||
} // namespace processor
|
||||
|
@ -1,20 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "Loading/StreamProcessor.h"
|
||||
#include "Utils/ICapturedDataProvider.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class ProcessorCaptureData final : public StreamProcessor, public ICapturedDataProvider
|
||||
namespace processor
|
||||
{
|
||||
std::unique_ptr<uint8_t[]> m_data;
|
||||
const size_t m_capture_size;
|
||||
size_t m_captured_data_size;
|
||||
class IProcessorCaptureData : public StreamProcessor, public ICapturedDataProvider
|
||||
{
|
||||
};
|
||||
|
||||
public:
|
||||
explicit ProcessorCaptureData(size_t captureSize);
|
||||
~ProcessorCaptureData() override;
|
||||
|
||||
size_t Load(void* buffer, size_t length) override;
|
||||
int64_t Pos() override;
|
||||
void GetCapturedData(const uint8_t** pCapturedData, size_t* pSize) override;
|
||||
};
|
||||
std::unique_ptr<IProcessorCaptureData> CreateProcessorCaptureData(size_t captureSize);
|
||||
} // namespace processor
|
||||
|
@ -2,25 +2,30 @@
|
||||
|
||||
#include <cassert>
|
||||
|
||||
ProcessorIW4xDecryption::ProcessorIW4xDecryption()
|
||||
: m_last_byte(0u)
|
||||
{
|
||||
}
|
||||
|
||||
uint8_t ProcessorIW4xDecryption::RotateLeft(const uint8_t value, const unsigned count)
|
||||
namespace
|
||||
{
|
||||
uint8_t RotateLeft(const uint8_t value, const unsigned count)
|
||||
{
|
||||
assert(count < sizeof(value) * 8);
|
||||
return static_cast<uint8_t>(value << count | (value >> ((sizeof(value) * 8) - count)));
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ProcessorIW4xDecryption::RotateRight(uint8_t value, const unsigned count)
|
||||
{
|
||||
uint8_t RotateRight(const uint8_t value, const unsigned count)
|
||||
{
|
||||
assert(count < sizeof(value) * 8);
|
||||
return static_cast<uint8_t>(value >> count | (value << ((sizeof(value) * 8) - count)));
|
||||
}
|
||||
}
|
||||
|
||||
size_t ProcessorIW4xDecryption::Load(void* buffer, const size_t length)
|
||||
{
|
||||
class ProcessorIW4xDecryption final : public StreamProcessor
|
||||
{
|
||||
public:
|
||||
ProcessorIW4xDecryption()
|
||||
: m_last_byte(0u)
|
||||
{
|
||||
}
|
||||
|
||||
size_t Load(void* buffer, const size_t length) override
|
||||
{
|
||||
const auto readLen = m_base_stream->Load(buffer, length);
|
||||
|
||||
auto* charBuffer = static_cast<uint8_t*>(buffer);
|
||||
@ -37,9 +42,22 @@ size_t ProcessorIW4xDecryption::Load(void* buffer, const size_t length)
|
||||
}
|
||||
|
||||
return readLen;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t ProcessorIW4xDecryption::Pos()
|
||||
{
|
||||
int64_t Pos() override
|
||||
{
|
||||
return m_base_stream->Pos();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
uint8_t m_last_byte;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace processor
|
||||
{
|
||||
std::unique_ptr<StreamProcessor> CreateProcessorIW4xDecryption()
|
||||
{
|
||||
return std::make_unique<ProcessorIW4xDecryption>();
|
||||
}
|
||||
} // namespace processor
|
||||
|
@ -1,16 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "Loading/StreamProcessor.h"
|
||||
|
||||
class ProcessorIW4xDecryption final : public StreamProcessor
|
||||
#include <memory>
|
||||
|
||||
namespace processor
|
||||
{
|
||||
uint8_t m_last_byte;
|
||||
|
||||
static uint8_t RotateLeft(uint8_t value, unsigned count);
|
||||
static uint8_t RotateRight(uint8_t value, unsigned count);
|
||||
|
||||
public:
|
||||
ProcessorIW4xDecryption();
|
||||
|
||||
size_t Load(void* buffer, size_t length) override;
|
||||
int64_t Pos() override;
|
||||
};
|
||||
std::unique_ptr<StreamProcessor> CreateProcessorIW4xDecryption();
|
||||
}
|
||||
|
@ -8,21 +8,17 @@
|
||||
#include <zlib.h>
|
||||
#include <zutil.h>
|
||||
|
||||
class ProcessorInflate::Impl
|
||||
namespace
|
||||
{
|
||||
z_stream m_stream{};
|
||||
ProcessorInflate* m_base;
|
||||
constexpr size_t DEFAULT_BUFFER_SIZE = 0x2000;
|
||||
|
||||
std::unique_ptr<uint8_t[]> m_buffer;
|
||||
size_t m_buffer_size;
|
||||
|
||||
public:
|
||||
Impl(ProcessorInflate* baseClass, const size_t bufferSize)
|
||||
class ProcessorInflate final : public StreamProcessor
|
||||
{
|
||||
public:
|
||||
explicit ProcessorInflate(const size_t bufferSize)
|
||||
: m_buffer(std::make_unique<uint8_t[]>(bufferSize)),
|
||||
m_buffer_size(bufferSize)
|
||||
{
|
||||
m_base = baseClass;
|
||||
|
||||
m_stream.zalloc = Z_NULL;
|
||||
m_stream.zfree = Z_NULL;
|
||||
m_stream.opaque = Z_NULL;
|
||||
@ -32,22 +28,20 @@ public:
|
||||
const int ret = inflateInit(&m_stream);
|
||||
|
||||
if (ret != Z_OK)
|
||||
{
|
||||
throw std::runtime_error("Initializing inflate failed");
|
||||
}
|
||||
}
|
||||
|
||||
~Impl()
|
||||
~ProcessorInflate() override
|
||||
{
|
||||
inflateEnd(&m_stream);
|
||||
}
|
||||
|
||||
Impl(const Impl& other) = delete;
|
||||
Impl(Impl&& other) noexcept = default;
|
||||
Impl& operator=(const Impl& other) = delete;
|
||||
Impl& operator=(Impl&& other) noexcept = default;
|
||||
ProcessorInflate(const ProcessorInflate& other) = delete;
|
||||
ProcessorInflate(ProcessorInflate&& other) noexcept = default;
|
||||
ProcessorInflate& operator=(const ProcessorInflate& other) = delete;
|
||||
ProcessorInflate& operator=(ProcessorInflate&& other) noexcept = default;
|
||||
|
||||
size_t Load(void* buffer, const size_t length)
|
||||
size_t Load(void* buffer, const size_t length) override
|
||||
{
|
||||
m_stream.next_out = static_cast<Bytef*>(buffer);
|
||||
m_stream.avail_out = static_cast<unsigned>(length);
|
||||
@ -56,7 +50,7 @@ public:
|
||||
{
|
||||
if (m_stream.avail_in == 0)
|
||||
{
|
||||
m_stream.avail_in = static_cast<unsigned>(m_base->m_base_stream->Load(m_buffer.get(), m_buffer_size));
|
||||
m_stream.avail_in = static_cast<unsigned>(m_base_stream->Load(m_buffer.get(), m_buffer_size));
|
||||
m_stream.next_in = m_buffer.get();
|
||||
|
||||
if (m_stream.avail_in == 0) // EOF
|
||||
@ -71,30 +65,28 @@ public:
|
||||
|
||||
return length - m_stream.avail_out;
|
||||
}
|
||||
};
|
||||
|
||||
ProcessorInflate::ProcessorInflate()
|
||||
: ProcessorInflate(DEFAULT_BUFFER_SIZE)
|
||||
{
|
||||
}
|
||||
|
||||
ProcessorInflate::ProcessorInflate(const size_t bufferSize)
|
||||
: m_impl(new Impl(this, bufferSize))
|
||||
{
|
||||
}
|
||||
|
||||
ProcessorInflate::~ProcessorInflate()
|
||||
{
|
||||
delete m_impl;
|
||||
m_impl = nullptr;
|
||||
}
|
||||
|
||||
size_t ProcessorInflate::Load(void* buffer, const size_t length)
|
||||
{
|
||||
return m_impl->Load(buffer, length);
|
||||
}
|
||||
|
||||
int64_t ProcessorInflate::Pos()
|
||||
{
|
||||
int64_t Pos() override
|
||||
{
|
||||
return m_base_stream->Pos();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
z_stream m_stream{};
|
||||
std::unique_ptr<uint8_t[]> m_buffer;
|
||||
size_t m_buffer_size;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace processor
|
||||
{
|
||||
std::unique_ptr<StreamProcessor> CreateProcessorInflate()
|
||||
{
|
||||
return std::make_unique<ProcessorInflate>(DEFAULT_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
std::unique_ptr<StreamProcessor> CreateProcessorInflate(size_t bufferSize)
|
||||
{
|
||||
return std::make_unique<ProcessorInflate>(bufferSize);
|
||||
}
|
||||
} // namespace processor
|
||||
|
@ -1,22 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "Loading/StreamProcessor.h"
|
||||
|
||||
class ProcessorInflate final : public StreamProcessor
|
||||
#include <memory>
|
||||
|
||||
namespace processor
|
||||
{
|
||||
class Impl;
|
||||
Impl* m_impl;
|
||||
|
||||
static constexpr size_t DEFAULT_BUFFER_SIZE = 0x2000;
|
||||
|
||||
public:
|
||||
ProcessorInflate();
|
||||
ProcessorInflate(size_t bufferSize);
|
||||
~ProcessorInflate() override;
|
||||
ProcessorInflate(const ProcessorInflate& other) = delete;
|
||||
ProcessorInflate(ProcessorInflate&& other) noexcept = default;
|
||||
ProcessorInflate& operator=(const ProcessorInflate& other) = delete;
|
||||
ProcessorInflate& operator=(ProcessorInflate&& other) noexcept = default;
|
||||
|
||||
size_t Load(void* buffer, size_t length) override;
|
||||
int64_t Pos() override;
|
||||
};
|
||||
std::unique_ptr<StreamProcessor> CreateProcessorInflate();
|
||||
std::unique_ptr<StreamProcessor> CreateProcessorInflate(size_t bufferSize);
|
||||
} // namespace processor
|
||||
|
@ -1,12 +1,17 @@
|
||||
#include "ProcessorStreamCipher.h"
|
||||
|
||||
ProcessorStreamCipher::ProcessorStreamCipher(std::unique_ptr<cryptography::IStreamCipher> cipher)
|
||||
namespace
|
||||
{
|
||||
class ProcessorStreamCipher final : public StreamProcessor
|
||||
{
|
||||
public:
|
||||
explicit ProcessorStreamCipher(std::unique_ptr<cryptography::IStreamCipher> cipher)
|
||||
: m_cipher(std::move(cipher))
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
size_t ProcessorStreamCipher::Load(void* buffer, const size_t length)
|
||||
{
|
||||
size_t Load(void* buffer, const size_t length) override
|
||||
{
|
||||
if (m_base_stream != nullptr)
|
||||
{
|
||||
const size_t readSize = m_base_stream->Load(buffer, length);
|
||||
@ -18,4 +23,22 @@ size_t ProcessorStreamCipher::Load(void* buffer, const size_t length)
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t Pos() override
|
||||
{
|
||||
return m_base_stream->Pos();
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<cryptography::IStreamCipher> m_cipher;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace processor
|
||||
{
|
||||
std::unique_ptr<StreamProcessor> CreateProcessorStreamCipher(std::unique_ptr<cryptography::IStreamCipher> cipher)
|
||||
{
|
||||
return std::make_unique<ProcessorStreamCipher>(std::move(cipher));
|
||||
}
|
||||
} // namespace processor
|
||||
|
@ -5,13 +5,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
class ProcessorStreamCipher final : public StreamProcessor
|
||||
namespace processor
|
||||
{
|
||||
public:
|
||||
explicit ProcessorStreamCipher(std::unique_ptr<cryptography::IStreamCipher> cipher);
|
||||
|
||||
size_t Load(void* buffer, size_t length) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<cryptography::IStreamCipher> m_cipher;
|
||||
};
|
||||
std::unique_ptr<StreamProcessor> CreateProcessorStreamCipher(std::unique_ptr<cryptography::IStreamCipher> cipher);
|
||||
}
|
||||
|
@ -8,33 +8,76 @@
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
class DBLoadStream
|
||||
namespace
|
||||
{
|
||||
int m_index;
|
||||
class DbLoadStream
|
||||
{
|
||||
public:
|
||||
DbLoadStream(const int streamIndex, const size_t chunkSize, std::vector<std::unique_ptr<IXChunkProcessor>>& chunkProcessors)
|
||||
: m_index(streamIndex),
|
||||
m_input_size(0),
|
||||
m_output_size(0),
|
||||
m_chunk_size(chunkSize),
|
||||
m_is_loading(false),
|
||||
m_processors(chunkProcessors)
|
||||
{
|
||||
for (auto& buffer : m_buffers)
|
||||
buffer = std::make_unique<uint8_t[]>(chunkSize);
|
||||
|
||||
std::unique_ptr<uint8_t[]> m_buffers[2];
|
||||
m_input_buffer = m_buffers[0].get();
|
||||
m_output_buffer = m_buffers[1].get();
|
||||
}
|
||||
|
||||
uint8_t* m_input_buffer;
|
||||
size_t m_input_size;
|
||||
[[nodiscard]] uint8_t* GetInputBuffer() const
|
||||
{
|
||||
return m_input_buffer;
|
||||
}
|
||||
|
||||
uint8_t* m_output_buffer;
|
||||
size_t m_output_size;
|
||||
void StartLoading(const size_t inputSize)
|
||||
{
|
||||
if (inputSize > 0)
|
||||
{
|
||||
std::unique_lock lock(m_load_mutex);
|
||||
|
||||
size_t m_chunk_size;
|
||||
if (m_is_loading)
|
||||
{
|
||||
m_loading_finished.wait(lock);
|
||||
}
|
||||
|
||||
bool m_is_loading;
|
||||
std::mutex m_load_mutex;
|
||||
std::condition_variable m_loading_finished;
|
||||
std::thread m_load_thread;
|
||||
m_input_size = inputSize;
|
||||
m_is_loading = true;
|
||||
m_load_thread = std::thread(&DbLoadStream::Load, this);
|
||||
m_load_thread.detach();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_output_size = 0;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<IXChunkProcessor>>& m_processors;
|
||||
void GetOutput(const uint8_t** pBuffer, size_t* pSize)
|
||||
{
|
||||
assert(pBuffer != nullptr);
|
||||
assert(pSize != nullptr);
|
||||
|
||||
std::unique_lock lock(m_load_mutex);
|
||||
if (m_is_loading)
|
||||
{
|
||||
m_loading_finished.wait(lock);
|
||||
}
|
||||
|
||||
*pBuffer = m_output_buffer;
|
||||
*pSize = m_output_size;
|
||||
}
|
||||
|
||||
private:
|
||||
void Load()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_load_mutex);
|
||||
std::lock_guard lock(m_load_mutex);
|
||||
|
||||
bool firstProcessor = true;
|
||||
|
||||
@ -59,208 +102,51 @@ class DBLoadStream
|
||||
m_loading_finished.notify_all();
|
||||
}
|
||||
|
||||
public:
|
||||
DBLoadStream(const int streamIndex, const size_t chunkSize, std::vector<std::unique_ptr<IXChunkProcessor>>& chunkProcessors)
|
||||
: m_processors(chunkProcessors)
|
||||
{
|
||||
m_index = streamIndex;
|
||||
m_chunk_size = chunkSize;
|
||||
int m_index;
|
||||
|
||||
for (auto& buffer : m_buffers)
|
||||
buffer = std::make_unique<uint8_t[]>(chunkSize);
|
||||
std::unique_ptr<uint8_t[]> m_buffers[2];
|
||||
|
||||
m_input_buffer = m_buffers[0].get();
|
||||
m_output_buffer = m_buffers[1].get();
|
||||
uint8_t* m_input_buffer;
|
||||
size_t m_input_size;
|
||||
|
||||
m_input_size = 0;
|
||||
m_output_size = 0;
|
||||
uint8_t* m_output_buffer;
|
||||
size_t m_output_size;
|
||||
|
||||
m_is_loading = false;
|
||||
}
|
||||
|
||||
[[nodiscard]] uint8_t* GetInputBuffer() const
|
||||
{
|
||||
return m_input_buffer;
|
||||
}
|
||||
|
||||
void StartLoading(const size_t inputSize)
|
||||
{
|
||||
if (inputSize > 0)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_load_mutex);
|
||||
|
||||
if (m_is_loading)
|
||||
{
|
||||
m_loading_finished.wait(lock);
|
||||
}
|
||||
|
||||
m_input_size = inputSize;
|
||||
m_is_loading = true;
|
||||
m_load_thread = std::thread(&DBLoadStream::Load, this);
|
||||
m_load_thread.detach();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_output_size = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void GetOutput(const uint8_t** pBuffer, size_t* pSize)
|
||||
{
|
||||
assert(pBuffer != nullptr);
|
||||
assert(pSize != nullptr);
|
||||
|
||||
std::unique_lock<std::mutex> lock(m_load_mutex);
|
||||
if (m_is_loading)
|
||||
{
|
||||
m_loading_finished.wait(lock);
|
||||
}
|
||||
|
||||
*pBuffer = m_output_buffer;
|
||||
*pSize = m_output_size;
|
||||
}
|
||||
};
|
||||
|
||||
class ProcessorXChunks::ProcessorXChunksImpl
|
||||
{
|
||||
ProcessorXChunks* m_base;
|
||||
|
||||
std::vector<std::unique_ptr<DBLoadStream>> m_streams;
|
||||
size_t m_chunk_size;
|
||||
size_t m_vanilla_buffer_size;
|
||||
std::vector<std::unique_ptr<IXChunkProcessor>> m_chunk_processors;
|
||||
|
||||
bool m_initialized_streams;
|
||||
unsigned int m_current_stream;
|
||||
const uint8_t* m_current_chunk;
|
||||
size_t m_current_chunk_size;
|
||||
size_t m_current_chunk_offset;
|
||||
size_t m_vanilla_buffer_offset;
|
||||
bool m_is_loading;
|
||||
std::mutex m_load_mutex;
|
||||
std::condition_variable m_loading_finished;
|
||||
std::thread m_load_thread;
|
||||
|
||||
bool m_eof_reached;
|
||||
unsigned int m_eof_stream;
|
||||
std::vector<std::unique_ptr<IXChunkProcessor>>& m_processors;
|
||||
};
|
||||
|
||||
void AdvanceStream(const unsigned streamNum)
|
||||
class ProcessorXChunks final : public processor::IProcessorXChunks
|
||||
{
|
||||
assert(streamNum < m_streams.size());
|
||||
|
||||
if (m_eof_reached)
|
||||
return;
|
||||
|
||||
xchunk_size_t chunkSize;
|
||||
if (m_vanilla_buffer_size > 0)
|
||||
public:
|
||||
ProcessorXChunks(const int numStreams, const size_t xChunkSize, const std::optional<size_t> vanillaBufferSize)
|
||||
: m_chunk_size(xChunkSize),
|
||||
m_vanilla_buffer_size(vanillaBufferSize),
|
||||
m_initialized_streams(false),
|
||||
m_current_stream(0),
|
||||
m_current_chunk(nullptr),
|
||||
m_current_chunk_size(0),
|
||||
m_current_chunk_offset(0),
|
||||
m_vanilla_buffer_offset(0),
|
||||
m_eof_reached(false),
|
||||
m_eof_stream(0)
|
||||
{
|
||||
if (m_vanilla_buffer_offset + sizeof(chunkSize) > m_vanilla_buffer_size)
|
||||
{
|
||||
m_base->m_base_stream->Load(&chunkSize, m_vanilla_buffer_size - m_vanilla_buffer_offset);
|
||||
m_vanilla_buffer_offset = 0;
|
||||
}
|
||||
|
||||
m_vanilla_buffer_offset = (m_vanilla_buffer_offset + sizeof(chunkSize)) % m_vanilla_buffer_size;
|
||||
}
|
||||
|
||||
const size_t readSize = m_base->m_base_stream->Load(&chunkSize, sizeof(chunkSize));
|
||||
|
||||
if (readSize == 0)
|
||||
{
|
||||
m_eof_reached = true;
|
||||
m_eof_stream = streamNum;
|
||||
return;
|
||||
}
|
||||
|
||||
if (chunkSize > m_chunk_size)
|
||||
{
|
||||
throw InvalidChunkSizeException(chunkSize, m_chunk_size);
|
||||
}
|
||||
|
||||
const auto& stream = m_streams[streamNum];
|
||||
const size_t loadedChunkSize = m_base->m_base_stream->Load(stream->GetInputBuffer(), chunkSize);
|
||||
|
||||
if (loadedChunkSize != chunkSize)
|
||||
{
|
||||
throw InvalidChunkSizeException(chunkSize);
|
||||
}
|
||||
|
||||
if (m_vanilla_buffer_size > 0)
|
||||
{
|
||||
m_vanilla_buffer_offset = (m_vanilla_buffer_offset + loadedChunkSize) % m_vanilla_buffer_size;
|
||||
}
|
||||
|
||||
stream->StartLoading(loadedChunkSize);
|
||||
}
|
||||
|
||||
void NextStream()
|
||||
{
|
||||
AdvanceStream(m_current_stream);
|
||||
|
||||
m_current_stream = (m_current_stream + 1) % m_streams.size();
|
||||
m_current_chunk_offset = 0;
|
||||
m_streams[m_current_stream]->GetOutput(&m_current_chunk, &m_current_chunk_size);
|
||||
}
|
||||
|
||||
void InitStreams()
|
||||
{
|
||||
m_initialized_streams = true;
|
||||
m_vanilla_buffer_offset = static_cast<size_t>(m_base->m_base_stream->Pos());
|
||||
|
||||
const auto streamCount = static_cast<unsigned>(m_streams.size());
|
||||
for (auto streamNum = 0u; streamNum < streamCount; streamNum++)
|
||||
{
|
||||
AdvanceStream(streamNum);
|
||||
}
|
||||
|
||||
m_current_stream = 0;
|
||||
m_current_chunk_offset = 0;
|
||||
m_streams[0]->GetOutput(&m_current_chunk, &m_current_chunk_size);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool EndOfStream() const
|
||||
{
|
||||
return m_eof_reached && m_eof_stream == m_current_stream;
|
||||
}
|
||||
|
||||
public:
|
||||
ProcessorXChunksImpl(ProcessorXChunks* base, const int numStreams, const size_t xChunkSize)
|
||||
{
|
||||
assert(base != nullptr);
|
||||
assert(numStreams > 0);
|
||||
assert(xChunkSize > 0);
|
||||
|
||||
m_base = base;
|
||||
|
||||
for (int streamIndex = 0; streamIndex < numStreams; streamIndex++)
|
||||
{
|
||||
m_streams.emplace_back(std::make_unique<DBLoadStream>(streamIndex, xChunkSize, m_chunk_processors));
|
||||
m_streams.emplace_back(std::make_unique<DbLoadStream>(streamIndex, xChunkSize, m_chunk_processors));
|
||||
}
|
||||
}
|
||||
|
||||
m_chunk_size = xChunkSize;
|
||||
m_vanilla_buffer_size = 0;
|
||||
|
||||
m_initialized_streams = false;
|
||||
m_current_stream = 0;
|
||||
m_current_chunk = nullptr;
|
||||
m_current_chunk_size = 0;
|
||||
m_current_chunk_offset = 0;
|
||||
m_vanilla_buffer_offset = 0;
|
||||
|
||||
m_eof_reached = false;
|
||||
m_eof_stream = 0;
|
||||
}
|
||||
|
||||
ProcessorXChunksImpl(ProcessorXChunks* base, const int numStreams, const size_t xChunkSize, const size_t vanillaBufferSize)
|
||||
: ProcessorXChunksImpl(base, numStreams, xChunkSize)
|
||||
{
|
||||
m_vanilla_buffer_size = vanillaBufferSize;
|
||||
}
|
||||
|
||||
void AddChunkProcessor(std::unique_ptr<IXChunkProcessor> streamProcessor)
|
||||
{
|
||||
assert(streamProcessor != nullptr);
|
||||
|
||||
m_chunk_processors.emplace_back(std::move(streamProcessor));
|
||||
}
|
||||
|
||||
size_t Load(void* buffer, const size_t length)
|
||||
size_t Load(void* buffer, const size_t length) override
|
||||
{
|
||||
assert(buffer != nullptr);
|
||||
|
||||
@ -279,14 +165,14 @@ public:
|
||||
if (sizeToRead > bytesLeftInCurrentChunk)
|
||||
{
|
||||
assert(sizeToRead >= bytesLeftInCurrentChunk);
|
||||
memcpy(bufferPos, &m_current_chunk[m_current_chunk_offset], bytesLeftInCurrentChunk);
|
||||
std::memcpy(bufferPos, &m_current_chunk[m_current_chunk_offset], bytesLeftInCurrentChunk);
|
||||
loadedSize += bytesLeftInCurrentChunk;
|
||||
|
||||
NextStream();
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(bufferPos, &m_current_chunk[m_current_chunk_offset], sizeToRead);
|
||||
std::memcpy(bufferPos, &m_current_chunk[m_current_chunk_offset], sizeToRead);
|
||||
loadedSize += sizeToRead;
|
||||
m_current_chunk_offset += sizeToRead;
|
||||
|
||||
@ -300,39 +186,124 @@ public:
|
||||
return loadedSize;
|
||||
}
|
||||
|
||||
int64_t Pos() const
|
||||
int64_t Pos() override
|
||||
{
|
||||
return m_base->m_base_stream->Pos();
|
||||
return m_base_stream->Pos();
|
||||
}
|
||||
};
|
||||
|
||||
ProcessorXChunks::ProcessorXChunks(const int numStreams, const size_t xChunkSize)
|
||||
{
|
||||
m_impl = new ProcessorXChunksImpl(this, numStreams, xChunkSize);
|
||||
}
|
||||
void AddChunkProcessor(std::unique_ptr<IXChunkProcessor> chunkProcessor) override
|
||||
{
|
||||
assert(chunkProcessor);
|
||||
|
||||
ProcessorXChunks::ProcessorXChunks(const int numStreams, const size_t xChunkSize, const size_t vanillaBufferSize)
|
||||
{
|
||||
m_impl = new ProcessorXChunksImpl(this, numStreams, xChunkSize, vanillaBufferSize);
|
||||
}
|
||||
m_chunk_processors.emplace_back(std::move(chunkProcessor));
|
||||
}
|
||||
|
||||
ProcessorXChunks::~ProcessorXChunks()
|
||||
{
|
||||
delete m_impl;
|
||||
m_impl = nullptr;
|
||||
}
|
||||
private:
|
||||
void AdvanceStream(const unsigned streamNum)
|
||||
{
|
||||
assert(streamNum < m_streams.size());
|
||||
|
||||
void ProcessorXChunks::AddChunkProcessor(std::unique_ptr<IXChunkProcessor> chunkProcessor) const
|
||||
{
|
||||
m_impl->AddChunkProcessor(std::move(chunkProcessor));
|
||||
}
|
||||
if (m_eof_reached)
|
||||
return;
|
||||
|
||||
size_t ProcessorXChunks::Load(void* buffer, const size_t length)
|
||||
{
|
||||
return m_impl->Load(buffer, length);
|
||||
}
|
||||
xchunk_size_t chunkSize;
|
||||
if (m_vanilla_buffer_size.has_value())
|
||||
{
|
||||
if (m_vanilla_buffer_offset + sizeof(chunkSize) > *m_vanilla_buffer_size)
|
||||
{
|
||||
m_base_stream->Load(&chunkSize, *m_vanilla_buffer_size - m_vanilla_buffer_offset);
|
||||
m_vanilla_buffer_offset = 0;
|
||||
}
|
||||
|
||||
int64_t ProcessorXChunks::Pos()
|
||||
m_vanilla_buffer_offset = (m_vanilla_buffer_offset + sizeof(chunkSize)) % *m_vanilla_buffer_size;
|
||||
}
|
||||
|
||||
const size_t readSize = m_base_stream->Load(&chunkSize, sizeof(chunkSize));
|
||||
|
||||
if (readSize == 0)
|
||||
{
|
||||
m_eof_reached = true;
|
||||
m_eof_stream = streamNum;
|
||||
return;
|
||||
}
|
||||
|
||||
if (chunkSize > m_chunk_size)
|
||||
{
|
||||
throw InvalidChunkSizeException(chunkSize, m_chunk_size);
|
||||
}
|
||||
|
||||
const auto& stream = m_streams[streamNum];
|
||||
const size_t loadedChunkSize = m_base_stream->Load(stream->GetInputBuffer(), chunkSize);
|
||||
|
||||
if (loadedChunkSize != chunkSize)
|
||||
{
|
||||
throw InvalidChunkSizeException(chunkSize);
|
||||
}
|
||||
|
||||
if (m_vanilla_buffer_size.has_value())
|
||||
{
|
||||
m_vanilla_buffer_offset = (m_vanilla_buffer_offset + loadedChunkSize) % *m_vanilla_buffer_size;
|
||||
}
|
||||
|
||||
stream->StartLoading(loadedChunkSize);
|
||||
}
|
||||
|
||||
void NextStream()
|
||||
{
|
||||
AdvanceStream(m_current_stream);
|
||||
|
||||
m_current_stream = (m_current_stream + 1) % m_streams.size();
|
||||
m_current_chunk_offset = 0;
|
||||
m_streams[m_current_stream]->GetOutput(&m_current_chunk, &m_current_chunk_size);
|
||||
}
|
||||
|
||||
void InitStreams()
|
||||
{
|
||||
m_initialized_streams = true;
|
||||
m_vanilla_buffer_offset = static_cast<size_t>(m_base_stream->Pos());
|
||||
|
||||
const auto streamCount = static_cast<unsigned>(m_streams.size());
|
||||
for (auto streamNum = 0u; streamNum < streamCount; streamNum++)
|
||||
{
|
||||
AdvanceStream(streamNum);
|
||||
}
|
||||
|
||||
m_current_stream = 0;
|
||||
m_current_chunk_offset = 0;
|
||||
m_streams[0]->GetOutput(&m_current_chunk, &m_current_chunk_size);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool EndOfStream() const
|
||||
{
|
||||
return m_eof_reached && m_eof_stream == m_current_stream;
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<DbLoadStream>> m_streams;
|
||||
size_t m_chunk_size;
|
||||
std::optional<size_t> m_vanilla_buffer_size;
|
||||
std::vector<std::unique_ptr<IXChunkProcessor>> m_chunk_processors;
|
||||
|
||||
bool m_initialized_streams;
|
||||
unsigned int m_current_stream;
|
||||
const uint8_t* m_current_chunk;
|
||||
size_t m_current_chunk_size;
|
||||
size_t m_current_chunk_offset;
|
||||
size_t m_vanilla_buffer_offset;
|
||||
|
||||
bool m_eof_reached;
|
||||
unsigned int m_eof_stream;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace processor
|
||||
{
|
||||
return m_impl->Pos();
|
||||
}
|
||||
std::unique_ptr<IProcessorXChunks> CreateProcessorXChunks(int numStreams, const size_t xChunkSize)
|
||||
{
|
||||
return std::make_unique<ProcessorXChunks>(numStreams, xChunkSize, std::nullopt);
|
||||
}
|
||||
|
||||
std::unique_ptr<IProcessorXChunks> CreateProcessorXChunks(int numStreams, const size_t xChunkSize, const size_t vanillaBufferSize)
|
||||
{
|
||||
return std::make_unique<ProcessorXChunks>(numStreams, xChunkSize, vanillaBufferSize);
|
||||
}
|
||||
} // namespace processor
|
||||
|
@ -4,18 +4,14 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
class ProcessorXChunks : public StreamProcessor
|
||||
namespace processor
|
||||
{
|
||||
class ProcessorXChunksImpl;
|
||||
ProcessorXChunksImpl* m_impl;
|
||||
class IProcessorXChunks : public StreamProcessor
|
||||
{
|
||||
public:
|
||||
virtual void AddChunkProcessor(std::unique_ptr<IXChunkProcessor> chunkProcessor) = 0;
|
||||
};
|
||||
|
||||
public:
|
||||
ProcessorXChunks(int numStreams, size_t xChunkSize);
|
||||
ProcessorXChunks(int numStreams, size_t xChunkSize, size_t vanillaBufferSize);
|
||||
~ProcessorXChunks() override;
|
||||
|
||||
size_t Load(void* buffer, size_t length) override;
|
||||
int64_t Pos() override;
|
||||
|
||||
void AddChunkProcessor(std::unique_ptr<IXChunkProcessor> chunkProcessor) const;
|
||||
};
|
||||
std::unique_ptr<IProcessorXChunks> CreateProcessorXChunks(int numStreams, size_t xChunkSize);
|
||||
std::unique_ptr<IProcessorXChunks> CreateProcessorXChunks(int numStreams, size_t xChunkSize, size_t vanillaBufferSize);
|
||||
} // namespace processor
|
||||
|
@ -2,16 +2,33 @@
|
||||
|
||||
#include <cassert>
|
||||
|
||||
StepAddProcessor::StepAddProcessor(std::unique_ptr<StreamProcessor> streamProcessor)
|
||||
namespace
|
||||
{
|
||||
class StepAddProcessor final : public ILoadingStep
|
||||
{
|
||||
public:
|
||||
explicit StepAddProcessor(std::unique_ptr<StreamProcessor> streamProcessor)
|
||||
: m_stream_processor(std::move(streamProcessor))
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
void StepAddProcessor::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
||||
{
|
||||
assert(zoneLoader != nullptr);
|
||||
void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override
|
||||
{
|
||||
assert(m_stream_processor != nullptr);
|
||||
|
||||
zoneLoader->AddStreamProcessor(std::move(m_stream_processor));
|
||||
zoneLoader.AddStreamProcessor(std::move(m_stream_processor));
|
||||
m_stream_processor = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<StreamProcessor> m_stream_processor;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace step
|
||||
{
|
||||
std::unique_ptr<ILoadingStep> CreateStepAddProcessor(std::unique_ptr<StreamProcessor> streamProcessor)
|
||||
{
|
||||
return std::make_unique<StepAddProcessor>(std::move(streamProcessor));
|
||||
}
|
||||
} // namespace step
|
||||
|
@ -4,12 +4,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
class StepAddProcessor final : public ILoadingStep
|
||||
namespace step
|
||||
{
|
||||
std::unique_ptr<StreamProcessor> m_stream_processor;
|
||||
|
||||
public:
|
||||
explicit StepAddProcessor(std::unique_ptr<StreamProcessor> streamProcessor);
|
||||
|
||||
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
||||
};
|
||||
std::unique_ptr<ILoadingStep> CreateStepAddProcessor(std::unique_ptr<StreamProcessor> streamProcessor);
|
||||
}
|
||||
|
@ -2,14 +2,19 @@
|
||||
|
||||
#include "Loading/Exception/InvalidXBlockSizeException.h"
|
||||
|
||||
const uint64_t StepAllocXBlocks::MAX_XBLOCK_SIZE = 0x3C000000;
|
||||
|
||||
void StepAllocXBlocks::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
||||
namespace
|
||||
{
|
||||
const auto blockCount = static_cast<unsigned>(zoneLoader->m_blocks.size());
|
||||
constexpr uint64_t MAX_XBLOCK_SIZE = 0x3C000000;
|
||||
|
||||
class StepAllocXBlocks final : public ILoadingStep
|
||||
{
|
||||
public:
|
||||
void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override
|
||||
{
|
||||
const auto blockCount = static_cast<unsigned>(zoneLoader.m_blocks.size());
|
||||
|
||||
const auto blockSizes = std::make_unique<xblock_size_t[]>(blockCount);
|
||||
stream->Load(blockSizes.get(), sizeof(xblock_size_t) * blockCount);
|
||||
stream.Load(blockSizes.get(), sizeof(xblock_size_t) * blockCount);
|
||||
|
||||
uint64_t totalMemory = 0;
|
||||
for (unsigned int block = 0; block < blockCount; block++)
|
||||
@ -24,6 +29,16 @@ void StepAllocXBlocks::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* strea
|
||||
|
||||
for (unsigned int block = 0; block < blockCount; block++)
|
||||
{
|
||||
zoneLoader->m_blocks[block]->Alloc(blockSizes[block]);
|
||||
zoneLoader.m_blocks[block]->Alloc(blockSizes[block]);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace step
|
||||
{
|
||||
std::unique_ptr<ILoadingStep> CreateStepAllocXBlocks()
|
||||
{
|
||||
return std::make_unique<StepAllocXBlocks>();
|
||||
}
|
||||
} // namespace step
|
||||
|
@ -2,10 +2,9 @@
|
||||
|
||||
#include "Loading/ILoadingStep.h"
|
||||
|
||||
class StepAllocXBlocks final : public ILoadingStep
|
||||
{
|
||||
static const uint64_t MAX_XBLOCK_SIZE;
|
||||
#include <memory>
|
||||
|
||||
public:
|
||||
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
||||
};
|
||||
namespace step
|
||||
{
|
||||
std::unique_ptr<ILoadingStep> CreateStepAllocXBlocks();
|
||||
}
|
||||
|
@ -2,13 +2,18 @@
|
||||
|
||||
#include <fstream>
|
||||
|
||||
StepDumpData::StepDumpData(const size_t dumpCount)
|
||||
namespace
|
||||
{
|
||||
class StepDumpData final : public ILoadingStep
|
||||
{
|
||||
public:
|
||||
explicit StepDumpData(const size_t dumpCount)
|
||||
: m_dump_count(dumpCount)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
void StepDumpData::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
||||
{
|
||||
void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override
|
||||
{
|
||||
uint8_t tempBuffer[128];
|
||||
auto dumpedBytes = 0uz;
|
||||
|
||||
@ -27,7 +32,7 @@ void StepDumpData::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
||||
toDump = sizeof(tempBuffer);
|
||||
}
|
||||
|
||||
const auto loadedSize = stream->Load(tempBuffer, toDump);
|
||||
const auto loadedSize = stream.Load(tempBuffer, toDump);
|
||||
dumpedBytes += loadedSize;
|
||||
|
||||
if (loadedSize == 0)
|
||||
@ -37,4 +42,17 @@ void StepDumpData::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
||||
}
|
||||
|
||||
tempFile.close();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
size_t m_dump_count;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace step
|
||||
{
|
||||
std::unique_ptr<ILoadingStep> CreateStepDumpData(size_t dumpCount)
|
||||
{
|
||||
return std::make_unique<StepDumpData>(dumpCount);
|
||||
}
|
||||
} // namespace step
|
||||
|
@ -2,13 +2,9 @@
|
||||
|
||||
#include "Loading/ILoadingStep.h"
|
||||
|
||||
class StepDumpData final : public ILoadingStep
|
||||
#include <memory>
|
||||
|
||||
namespace step
|
||||
{
|
||||
public:
|
||||
explicit StepDumpData(size_t dumpCount);
|
||||
|
||||
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
||||
|
||||
private:
|
||||
size_t m_dump_count;
|
||||
};
|
||||
std::unique_ptr<ILoadingStep> CreateStepDumpData(size_t dumpCount);
|
||||
}
|
||||
|
@ -4,40 +4,56 @@
|
||||
|
||||
#include <cassert>
|
||||
|
||||
StepLoadHash::StepLoadHash(const size_t hashSize, const unsigned hashCount)
|
||||
namespace
|
||||
{
|
||||
class StepLoadHash final : public step::IStepLoadHash
|
||||
{
|
||||
public:
|
||||
StepLoadHash(const size_t hashSize, const unsigned hashCount)
|
||||
: m_hash_size(hashSize),
|
||||
m_hash_count(hashCount),
|
||||
m_hashes(std::make_unique<uint8_t[]>(hashSize * hashCount))
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
StepLoadHash::~StepLoadHash() = default;
|
||||
|
||||
void StepLoadHash::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
||||
{
|
||||
assert(stream != nullptr);
|
||||
|
||||
if (stream->Load(m_hashes.get(), m_hash_size * m_hash_count) != m_hash_size * m_hash_count)
|
||||
void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override
|
||||
{
|
||||
if (stream.Load(m_hashes.get(), m_hash_size * m_hash_count) != m_hash_size * m_hash_count)
|
||||
throw UnexpectedEndOfFileException();
|
||||
}
|
||||
}
|
||||
|
||||
void StepLoadHash::GetHash(const unsigned hashIndex, const uint8_t** pHash, size_t* pSize)
|
||||
{
|
||||
void GetHash(const unsigned hashIndex, const uint8_t** pHash, size_t* pSize) override
|
||||
{
|
||||
assert(pHash != nullptr);
|
||||
assert(pSize != nullptr);
|
||||
assert(hashIndex >= 0 && hashIndex < m_hash_count);
|
||||
assert(hashIndex < m_hash_count);
|
||||
|
||||
assert(m_hashes);
|
||||
|
||||
*pHash = &m_hashes[m_hash_size * hashIndex];
|
||||
*pSize = m_hash_size;
|
||||
}
|
||||
}
|
||||
|
||||
void StepLoadHash::GetCapturedData(const uint8_t** pCapturedData, size_t* pSize)
|
||||
{
|
||||
void GetCapturedData(const uint8_t** pCapturedData, size_t* pSize) override
|
||||
{
|
||||
assert(pCapturedData != nullptr);
|
||||
assert(pSize != nullptr);
|
||||
|
||||
*pCapturedData = m_hashes.get();
|
||||
*pSize = m_hash_size * m_hash_count;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
size_t m_hash_size;
|
||||
unsigned m_hash_count;
|
||||
std::unique_ptr<uint8_t[]> m_hashes;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace step
|
||||
{
|
||||
std::unique_ptr<IStepLoadHash> CreateStepLoadHash(const size_t hashSize, const unsigned hashCount)
|
||||
{
|
||||
return std::make_unique<StepLoadHash>(hashSize, hashCount);
|
||||
}
|
||||
} // namespace step
|
||||
|
@ -6,22 +6,11 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
class StepLoadHash final : public ILoadingStep, public IHashProvider, public ICapturedDataProvider
|
||||
namespace step
|
||||
{
|
||||
const size_t m_hash_size;
|
||||
const unsigned m_hash_count;
|
||||
std::unique_ptr<uint8_t[]> m_hashes;
|
||||
class IStepLoadHash : public ILoadingStep, public IHashProvider, public ICapturedDataProvider
|
||||
{
|
||||
};
|
||||
|
||||
public:
|
||||
StepLoadHash(size_t hashSize, unsigned hashCount);
|
||||
~StepLoadHash() override;
|
||||
|
||||
StepLoadHash(const StepLoadHash& other) = delete;
|
||||
StepLoadHash(StepLoadHash&& other) noexcept = default;
|
||||
StepLoadHash& operator=(const StepLoadHash& other) = delete;
|
||||
StepLoadHash& operator=(StepLoadHash&& other) noexcept = delete;
|
||||
|
||||
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
||||
void GetHash(unsigned hashIndex, const uint8_t** pHash, size_t* pSize) override;
|
||||
void GetCapturedData(const uint8_t** pCapturedData, size_t* pSize) override;
|
||||
};
|
||||
std::unique_ptr<IStepLoadHash> CreateStepLoadHash(size_t hashSize, unsigned hashCount);
|
||||
} // namespace step
|
||||
|
@ -4,33 +4,44 @@
|
||||
|
||||
#include <cassert>
|
||||
|
||||
StepLoadSignature::StepLoadSignature(const size_t signatureSize)
|
||||
namespace
|
||||
{
|
||||
m_signature_size = signatureSize;
|
||||
m_signature = new uint8_t[signatureSize];
|
||||
}
|
||||
class StepLoadSignature final : public step::IStepLoadSignature
|
||||
{
|
||||
public:
|
||||
explicit StepLoadSignature(const size_t signatureSize)
|
||||
: m_signature(std::make_unique<uint8_t[]>(signatureSize)),
|
||||
m_signature_size(signatureSize)
|
||||
{
|
||||
}
|
||||
|
||||
StepLoadSignature::~StepLoadSignature()
|
||||
{
|
||||
delete[] m_signature;
|
||||
m_signature = nullptr;
|
||||
}
|
||||
|
||||
void StepLoadSignature::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
||||
{
|
||||
assert(stream != nullptr);
|
||||
|
||||
if (stream->Load(m_signature, m_signature_size) != m_signature_size)
|
||||
void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override
|
||||
{
|
||||
if (stream.Load(m_signature.get(), m_signature_size) != m_signature_size)
|
||||
throw UnexpectedEndOfFileException();
|
||||
}
|
||||
}
|
||||
|
||||
void StepLoadSignature::GetSignature(const uint8_t** pSignature, size_t* pSize)
|
||||
{
|
||||
void GetSignature(const uint8_t** pSignature, size_t* pSize) override
|
||||
{
|
||||
assert(pSignature != nullptr);
|
||||
assert(pSize != nullptr);
|
||||
|
||||
assert(m_signature != nullptr);
|
||||
|
||||
*pSignature = m_signature;
|
||||
*pSignature = m_signature.get();
|
||||
*pSize = m_signature_size;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<uint8_t[]> m_signature;
|
||||
size_t m_signature_size;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace step
|
||||
{
|
||||
std::unique_ptr<IStepLoadSignature> CreateStepLoadSignature(const size_t signatureSize)
|
||||
{
|
||||
return std::make_unique<StepLoadSignature>(signatureSize);
|
||||
}
|
||||
} // namespace step
|
||||
|
@ -3,15 +3,13 @@
|
||||
#include "Loading/ILoadingStep.h"
|
||||
#include "Loading/ISignatureProvider.h"
|
||||
|
||||
class StepLoadSignature final : public ILoadingStep, public ISignatureProvider
|
||||
#include <memory>
|
||||
|
||||
namespace step
|
||||
{
|
||||
uint8_t* m_signature;
|
||||
size_t m_signature_size;
|
||||
class IStepLoadSignature : public ILoadingStep, public ISignatureProvider
|
||||
{
|
||||
};
|
||||
|
||||
public:
|
||||
explicit StepLoadSignature(size_t signatureSize);
|
||||
~StepLoadSignature() override;
|
||||
|
||||
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
||||
void GetSignature(const uint8_t** pSignature, size_t* pSize) override;
|
||||
};
|
||||
std::unique_ptr<IStepLoadSignature> CreateStepLoadSignature(size_t signatureSize);
|
||||
} // namespace step
|
||||
|
@ -1,25 +1,38 @@
|
||||
#include "StepLoadZoneContent.h"
|
||||
|
||||
#include "Zone/Stream/Impl/XBlockInputStream.h"
|
||||
#include "Zone/Stream/ZoneInputStream.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
StepLoadZoneContent::StepLoadZoneContent(std::unique_ptr<IContentLoadingEntryPoint> entryPoint,
|
||||
Zone* zone,
|
||||
const int offsetBlockBitCount,
|
||||
const block_t insertBlock)
|
||||
namespace
|
||||
{
|
||||
class StepLoadZoneContent final : public ILoadingStep
|
||||
{
|
||||
public:
|
||||
StepLoadZoneContent(std::unique_ptr<IContentLoadingEntryPoint> entryPoint, const int offsetBlockBitCount, const block_t insertBlock)
|
||||
: m_content_loader(std::move(entryPoint)),
|
||||
m_zone(zone),
|
||||
m_offset_block_bit_count(offsetBlockBitCount),
|
||||
m_insert_block(insertBlock)
|
||||
{
|
||||
}
|
||||
|
||||
void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override
|
||||
{
|
||||
const auto inputStream = ZoneInputStream::Create(zoneLoader.m_blocks, stream, m_offset_block_bit_count, m_insert_block);
|
||||
|
||||
m_content_loader->Load(*inputStream);
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<IContentLoadingEntryPoint> m_content_loader;
|
||||
int m_offset_block_bit_count;
|
||||
block_t m_insert_block;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace step
|
||||
{
|
||||
}
|
||||
|
||||
void StepLoadZoneContent::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
||||
{
|
||||
auto* inputStream = new XBlockInputStream(zoneLoader->m_blocks, stream, m_offset_block_bit_count, m_insert_block);
|
||||
|
||||
m_content_loader->Load(m_zone, inputStream);
|
||||
|
||||
delete inputStream;
|
||||
}
|
||||
std::unique_ptr<ILoadingStep>
|
||||
CreateStepLoadZoneContent(std::unique_ptr<IContentLoadingEntryPoint> entryPoint, const int offsetBlockBitCount, const block_t insertBlock)
|
||||
{
|
||||
return std::make_unique<StepLoadZoneContent>(std::move(entryPoint), offsetBlockBitCount, insertBlock);
|
||||
}
|
||||
} // namespace step
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user