mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-19 15:52:53 +00:00
refactor: use OutputPathFilesystem for writing fastfiles
This commit is contained in:
parent
a364e63258
commit
cc67f6e730
@ -4,6 +4,7 @@
|
|||||||
#include "LinkerPaths.h"
|
#include "LinkerPaths.h"
|
||||||
#include "ObjContainer/SoundBank/SoundBankWriter.h"
|
#include "ObjContainer/SoundBank/SoundBankWriter.h"
|
||||||
#include "ObjWriting.h"
|
#include "ObjWriting.h"
|
||||||
|
#include "SearchPath/OutputPathFilesystem.h"
|
||||||
#include "SearchPath/SearchPaths.h"
|
#include "SearchPath/SearchPaths.h"
|
||||||
#include "Utils/ObjFileStream.h"
|
#include "Utils/ObjFileStream.h"
|
||||||
#include "Zone/AssetList/AssetList.h"
|
#include "Zone/AssetList/AssetList.h"
|
||||||
@ -268,42 +269,41 @@ class LinkerImpl final : public Linker
|
|||||||
return zone_creator::CreateZoneForDefinition(zoneDefinition.m_game, context);
|
return zone_creator::CreateZoneForDefinition(zoneDefinition.m_game, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WriteZoneToFile(const LinkerPathManager& paths, const fs::path& outDir, const std::string& projectName, Zone* zone) const
|
static bool WriteZoneToFile(IOutputPath& outPath, const Zone& zone)
|
||||||
{
|
{
|
||||||
auto zoneFilePath(outDir);
|
const auto stream = outPath.Open(std::format("{}.ff", zone.m_name));
|
||||||
zoneFilePath.append(std::format("{}.ff", zone->m_name));
|
if (!stream)
|
||||||
|
|
||||||
fs::create_directories(outDir);
|
|
||||||
|
|
||||||
std::ofstream stream(zoneFilePath, std::fstream::out | std::fstream::binary);
|
|
||||||
if (!stream.is_open())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
std::cout << std::format("Building zone \"{}\"\n", zoneFilePath.string());
|
|
||||||
|
|
||||||
if (!ZoneWriting::WriteZone(stream, zone))
|
|
||||||
{
|
{
|
||||||
std::cerr << "Writing zone failed.\n";
|
std::cerr << std::format("Failed to open file for zone: {}\n", zone.m_name);
|
||||||
stream.close();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << std::format("Created zone \"{}\"\n", zoneFilePath.string());
|
std::cout << std::format("Building zone \"{}\"\n", zone.m_name);
|
||||||
|
|
||||||
|
if (!ZoneWriting::WriteZone(*stream, zone))
|
||||||
|
{
|
||||||
|
std::cerr << "Writing zone failed.\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << std::format("Created zone \"{}\"\n", zone.m_name);
|
||||||
|
|
||||||
stream.close();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BuildFastFile(LinkerPathManager& paths, const std::string& projectName, const std::string& targetName, ZoneDefinition& zoneDefinition) const
|
bool BuildFastFile(LinkerPathManager& paths, const std::string& projectName, const std::string& targetName, ZoneDefinition& zoneDefinition) const
|
||||||
{
|
{
|
||||||
const fs::path outDir(paths.m_linker_paths->BuildOutputFolderPath(projectName, zoneDefinition.m_game));
|
const fs::path outDir(paths.m_linker_paths->BuildOutputFolderPath(projectName, zoneDefinition.m_game));
|
||||||
|
|
||||||
|
OutputPathFilesystem outputPath(outDir);
|
||||||
|
|
||||||
const fs::path cacheDir(paths.m_linker_paths->BuildCacheFolderPath(projectName, zoneDefinition.m_game));
|
const fs::path cacheDir(paths.m_linker_paths->BuildCacheFolderPath(projectName, zoneDefinition.m_game));
|
||||||
SoundBankWriter::OutputPath = outDir;
|
SoundBankWriter::OutputPath = outDir;
|
||||||
|
|
||||||
const auto zone = CreateZoneForDefinition(paths, outDir, cacheDir, targetName, zoneDefinition);
|
const auto zone = CreateZoneForDefinition(paths, outDir, cacheDir, targetName, zoneDefinition);
|
||||||
auto result = zone != nullptr;
|
auto result = zone != nullptr;
|
||||||
if (zone)
|
if (zone)
|
||||||
result = WriteZoneToFile(paths, outDir, projectName, zone.get());
|
result = WriteZoneToFile(outputPath, *zone);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,13 @@
|
|||||||
#include "Internal/BaseTemplate.h"
|
#include "Internal/BaseTemplate.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <cstdint>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
class ZoneWriteTemplate::Internal final : BaseTemplate
|
class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||||
{
|
{
|
||||||
enum class MemberWriteType
|
enum class MemberWriteType : std::uint8_t
|
||||||
{
|
{
|
||||||
ARRAY_POINTER,
|
ARRAY_POINTER,
|
||||||
DYNAMIC_ARRAY,
|
DYNAMIC_ARRAY,
|
||||||
@ -86,7 +87,7 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
|||||||
|
|
||||||
void PrintHeaderConstructor() const
|
void PrintHeaderConstructor() const
|
||||||
{
|
{
|
||||||
LINE(WriterClassName(m_env.m_asset) << "(" << m_env.m_asset->m_definition->GetFullName() << "* asset, Zone* zone, IZoneOutputStream* stream);")
|
LINE(WriterClassName(m_env.m_asset) << "(" << m_env.m_asset->m_definition->GetFullName() << "* asset, const Zone& zone, IZoneOutputStream& stream);")
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintVariableInitialization(const DataDefinition* def) const
|
void PrintVariableInitialization(const DataDefinition* def) const
|
||||||
@ -112,10 +113,10 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
|||||||
void PrintConstructorMethod()
|
void PrintConstructorMethod()
|
||||||
{
|
{
|
||||||
LINE(WriterClassName(m_env.m_asset) << "::" << WriterClassName(m_env.m_asset) << "(" << m_env.m_asset->m_definition->GetFullName()
|
LINE(WriterClassName(m_env.m_asset) << "::" << WriterClassName(m_env.m_asset) << "(" << m_env.m_asset->m_definition->GetFullName()
|
||||||
<< "* asset, Zone* zone, IZoneOutputStream* stream)")
|
<< "* asset, const Zone& zone, IZoneOutputStream& stream)")
|
||||||
|
|
||||||
m_intendation++;
|
m_intendation++;
|
||||||
LINE_START(": AssetWriter(zone->m_pools->GetAssetOrAssetReference(" << m_env.m_asset->m_asset_enum_entry->m_name << ", GetAssetName(asset))"
|
LINE_START(": AssetWriter(zone.m_pools->GetAssetOrAssetReference(" << m_env.m_asset->m_asset_enum_entry->m_name << ", GetAssetName(asset))"
|
||||||
<< ", zone, stream)")
|
<< ", zone, stream)")
|
||||||
LINE_END("")
|
LINE_END("")
|
||||||
m_intendation--;
|
m_intendation--;
|
||||||
@ -184,7 +185,7 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
|||||||
{
|
{
|
||||||
if (writeType == MemberWriteType::SINGLE_POINTER)
|
if (writeType == MemberWriteType::SINGLE_POINTER)
|
||||||
{
|
{
|
||||||
LINE(WriterClassName(member->m_type) << " writer(" << MakeMemberAccess(info, member, modifier) << ", m_zone, m_stream);")
|
LINE(WriterClassName(member->m_type) << " writer(" << MakeMemberAccess(info, member, modifier) << ", m_zone, *m_stream);")
|
||||||
LINE("writer.Write(&" << MakeWrittenMemberAccess(info, member, modifier) << ");")
|
LINE("writer.Write(&" << MakeWrittenMemberAccess(info, member, modifier) << ");")
|
||||||
}
|
}
|
||||||
else if (writeType == MemberWriteType::POINTER_ARRAY)
|
else if (writeType == MemberWriteType::POINTER_ARRAY)
|
||||||
@ -1005,7 +1006,7 @@ class ZoneWriteTemplate::Internal final : BaseTemplate
|
|||||||
|
|
||||||
if (info && StructureComputations(info).IsAsset())
|
if (info && StructureComputations(info).IsAsset())
|
||||||
{
|
{
|
||||||
LINE(WriterClassName(info) << " writer(*" << MakeTypePtrVarName(def) << ", m_zone, m_stream);")
|
LINE(WriterClassName(info) << " writer(*" << MakeTypePtrVarName(def) << ", m_zone, *m_stream);")
|
||||||
LINE("writer.Write(" << MakeTypeWrittenPtrVarName(def) << ");")
|
LINE("writer.Write(" << MakeTypeWrittenPtrVarName(def) << ");")
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -28,12 +28,13 @@
|
|||||||
#include "Writing/WritingException.h"
|
#include "Writing/WritingException.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <sstream>
|
#include <format>
|
||||||
|
|
||||||
using namespace IW3;
|
using namespace IW3;
|
||||||
|
|
||||||
ContentWriter::ContentWriter()
|
ContentWriter::ContentWriter(const Zone& zone)
|
||||||
: varXAssetList(nullptr),
|
: ContentWriterBase(zone),
|
||||||
|
varXAssetList(nullptr),
|
||||||
varXAsset(nullptr),
|
varXAsset(nullptr),
|
||||||
varScriptStringList(nullptr)
|
varScriptStringList(nullptr)
|
||||||
{
|
{
|
||||||
@ -41,14 +42,14 @@ ContentWriter::ContentWriter()
|
|||||||
|
|
||||||
void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memory) const
|
void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memory) const
|
||||||
{
|
{
|
||||||
if (!m_zone->m_script_strings.Empty())
|
if (!m_zone.m_script_strings.Empty())
|
||||||
{
|
{
|
||||||
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
assert(m_zone.m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
||||||
xAssetList.stringList.count = static_cast<int>(m_zone->m_script_strings.Count());
|
xAssetList.stringList.count = static_cast<int>(m_zone.m_script_strings.Count());
|
||||||
xAssetList.stringList.strings = memory.Alloc<const char*>(m_zone->m_script_strings.Count());
|
xAssetList.stringList.strings = memory.Alloc<const char*>(m_zone.m_script_strings.Count());
|
||||||
|
|
||||||
for (auto i = 0u; i < m_zone->m_script_strings.Count(); i++)
|
for (auto i = 0u; i < m_zone.m_script_strings.Count(); i++)
|
||||||
xAssetList.stringList.strings[i] = m_zone->m_script_strings.CValue(i);
|
xAssetList.stringList.strings[i] = m_zone.m_script_strings.CValue(i);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -56,15 +57,15 @@ void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memo
|
|||||||
xAssetList.stringList.strings = nullptr;
|
xAssetList.stringList.strings = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto assetCount = m_zone->m_pools->GetTotalAssetCount();
|
const auto assetCount = m_zone.m_pools->GetTotalAssetCount();
|
||||||
if (assetCount > 0)
|
if (assetCount > 0)
|
||||||
{
|
{
|
||||||
xAssetList.assetCount = static_cast<int>(assetCount);
|
xAssetList.assetCount = static_cast<int>(assetCount);
|
||||||
xAssetList.assets = memory.Alloc<XAsset>(assetCount);
|
xAssetList.assets = memory.Alloc<XAsset>(assetCount);
|
||||||
|
|
||||||
const auto end = m_zone->m_pools->end();
|
const auto end = m_zone.m_pools->end();
|
||||||
auto index = 0u;
|
auto index = 0u;
|
||||||
for (auto i = m_zone->m_pools->begin(); i != end; ++i)
|
for (auto i = m_zone.m_pools->begin(); i != end; ++i)
|
||||||
{
|
{
|
||||||
auto& asset = xAssetList.assets[index++];
|
auto& asset = xAssetList.assets[index++];
|
||||||
asset.type = static_cast<XAssetType>((*i)->m_type);
|
asset.type = static_cast<XAssetType>((*i)->m_type);
|
||||||
@ -102,7 +103,7 @@ void ContentWriter::WriteXAsset(const bool atStreamStart)
|
|||||||
#define WRITE_ASSET(type_index, typeName, headerEntry) \
|
#define WRITE_ASSET(type_index, typeName, headerEntry) \
|
||||||
case type_index: \
|
case type_index: \
|
||||||
{ \
|
{ \
|
||||||
Writer_##typeName writer(varXAsset->header.headerEntry, m_zone, m_stream); \
|
Writer_##typeName writer(varXAsset->header.headerEntry, m_zone, *m_stream); \
|
||||||
writer.Write(&varXAsset->header.headerEntry); \
|
writer.Write(&varXAsset->header.headerEntry); \
|
||||||
break; \
|
break; \
|
||||||
}
|
}
|
||||||
@ -147,9 +148,7 @@ void ContentWriter::WriteXAsset(const bool atStreamStart)
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
std::ostringstream str;
|
throw WritingException(std::format("Unsupported asset type: {}.", static_cast<unsigned>(varXAsset->type)));
|
||||||
str << "Unsupported asset type: " << varXAsset->type << ".";
|
|
||||||
throw WritingException(str.str());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,10 +170,9 @@ void ContentWriter::WriteXAssetArray(const bool atStreamStart, const size_t coun
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentWriter::WriteContent(Zone* zone, IZoneOutputStream* stream)
|
void ContentWriter::WriteContent(IZoneOutputStream& stream)
|
||||||
{
|
{
|
||||||
m_zone = zone;
|
m_stream = &stream;
|
||||||
m_stream = stream;
|
|
||||||
|
|
||||||
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
||||||
|
|
||||||
|
@ -7,10 +7,12 @@ namespace IW3
|
|||||||
{
|
{
|
||||||
class ContentWriter final : public ContentWriterBase, public IContentWritingEntryPoint
|
class ContentWriter final : public ContentWriterBase, public IContentWritingEntryPoint
|
||||||
{
|
{
|
||||||
XAssetList* varXAssetList;
|
public:
|
||||||
XAsset* varXAsset;
|
explicit ContentWriter(const Zone& zone);
|
||||||
ScriptStringList* varScriptStringList;
|
|
||||||
|
|
||||||
|
void WriteContent(IZoneOutputStream& stream) override;
|
||||||
|
|
||||||
|
private:
|
||||||
void CreateXAssetList(XAssetList& xAssetList, MemoryManager& memory) const;
|
void CreateXAssetList(XAssetList& xAssetList, MemoryManager& memory) const;
|
||||||
|
|
||||||
void WriteScriptStringList(bool atStreamStart);
|
void WriteScriptStringList(bool atStreamStart);
|
||||||
@ -18,9 +20,8 @@ namespace IW3
|
|||||||
void WriteXAsset(bool atStreamStart);
|
void WriteXAsset(bool atStreamStart);
|
||||||
void WriteXAssetArray(bool atStreamStart, size_t count);
|
void WriteXAssetArray(bool atStreamStart, size_t count);
|
||||||
|
|
||||||
public:
|
XAssetList* varXAssetList;
|
||||||
ContentWriter();
|
XAsset* varXAsset;
|
||||||
|
ScriptStringList* varScriptStringList;
|
||||||
void WriteContent(Zone* zone, IZoneOutputStream* stream) override;
|
|
||||||
};
|
};
|
||||||
} // namespace IW3
|
} // namespace IW3
|
||||||
|
@ -45,14 +45,14 @@ namespace
|
|||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
std::unique_ptr<ZoneWriter> ZoneWriterFactory::CreateWriter(Zone* zone) const
|
std::unique_ptr<ZoneWriter> ZoneWriterFactory::CreateWriter(const Zone& zone) const
|
||||||
{
|
{
|
||||||
auto writer = std::make_unique<ZoneWriter>();
|
auto writer = std::make_unique<ZoneWriter>();
|
||||||
|
|
||||||
SetupBlocks(*writer);
|
SetupBlocks(*writer);
|
||||||
|
|
||||||
auto contentInMemory = std::make_unique<StepWriteZoneContentToMemory>(
|
auto contentInMemory = std::make_unique<StepWriteZoneContentToMemory>(
|
||||||
std::make_unique<ContentWriter>(), zone, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK);
|
std::make_unique<ContentWriter>(zone), zone, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK);
|
||||||
auto* contentInMemoryPtr = contentInMemory.get();
|
auto* contentInMemoryPtr = contentInMemory.get();
|
||||||
writer->AddWritingStep(std::move(contentInMemory));
|
writer->AddWritingStep(std::move(contentInMemory));
|
||||||
|
|
||||||
|
@ -9,6 +9,6 @@ namespace IW3
|
|||||||
class ZoneWriterFactory final : public IZoneWriterFactory
|
class ZoneWriterFactory final : public IZoneWriterFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
_NODISCARD std::unique_ptr<ZoneWriter> CreateWriter(Zone* zone) const override;
|
[[nodiscard]] std::unique_ptr<ZoneWriter> CreateWriter(const Zone& zone) const override;
|
||||||
};
|
};
|
||||||
} // namespace IW3
|
} // namespace IW3
|
||||||
|
@ -38,12 +38,13 @@
|
|||||||
#include "Writing/WritingException.h"
|
#include "Writing/WritingException.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <sstream>
|
#include <format>
|
||||||
|
|
||||||
using namespace IW4;
|
using namespace IW4;
|
||||||
|
|
||||||
ContentWriter::ContentWriter()
|
ContentWriter::ContentWriter(const Zone& zone)
|
||||||
: varXAssetList(nullptr),
|
: ContentWriterBase(zone),
|
||||||
|
varXAssetList(nullptr),
|
||||||
varXAsset(nullptr),
|
varXAsset(nullptr),
|
||||||
varScriptStringList(nullptr)
|
varScriptStringList(nullptr)
|
||||||
{
|
{
|
||||||
@ -51,14 +52,14 @@ ContentWriter::ContentWriter()
|
|||||||
|
|
||||||
void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memory) const
|
void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memory) const
|
||||||
{
|
{
|
||||||
if (!m_zone->m_script_strings.Empty())
|
if (!m_zone.m_script_strings.Empty())
|
||||||
{
|
{
|
||||||
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
assert(m_zone.m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
||||||
xAssetList.stringList.count = static_cast<int>(m_zone->m_script_strings.Count());
|
xAssetList.stringList.count = static_cast<int>(m_zone.m_script_strings.Count());
|
||||||
xAssetList.stringList.strings = memory.Alloc<const char*>(m_zone->m_script_strings.Count());
|
xAssetList.stringList.strings = memory.Alloc<const char*>(m_zone.m_script_strings.Count());
|
||||||
|
|
||||||
for (auto i = 0u; i < m_zone->m_script_strings.Count(); i++)
|
for (auto i = 0u; i < m_zone.m_script_strings.Count(); i++)
|
||||||
xAssetList.stringList.strings[i] = m_zone->m_script_strings.CValue(i);
|
xAssetList.stringList.strings[i] = m_zone.m_script_strings.CValue(i);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -66,15 +67,15 @@ void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memo
|
|||||||
xAssetList.stringList.strings = nullptr;
|
xAssetList.stringList.strings = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto assetCount = m_zone->m_pools->GetTotalAssetCount();
|
const auto assetCount = m_zone.m_pools->GetTotalAssetCount();
|
||||||
if (assetCount > 0)
|
if (assetCount > 0)
|
||||||
{
|
{
|
||||||
xAssetList.assetCount = static_cast<int>(assetCount);
|
xAssetList.assetCount = static_cast<int>(assetCount);
|
||||||
xAssetList.assets = memory.Alloc<XAsset>(assetCount);
|
xAssetList.assets = memory.Alloc<XAsset>(assetCount);
|
||||||
|
|
||||||
const auto end = m_zone->m_pools->end();
|
const auto end = m_zone.m_pools->end();
|
||||||
auto index = 0u;
|
auto index = 0u;
|
||||||
for (auto i = m_zone->m_pools->begin(); i != end; ++i)
|
for (auto i = m_zone.m_pools->begin(); i != end; ++i)
|
||||||
{
|
{
|
||||||
auto& asset = xAssetList.assets[index++];
|
auto& asset = xAssetList.assets[index++];
|
||||||
asset.type = static_cast<XAssetType>((*i)->m_type);
|
asset.type = static_cast<XAssetType>((*i)->m_type);
|
||||||
@ -112,7 +113,7 @@ void ContentWriter::WriteXAsset(const bool atStreamStart)
|
|||||||
#define WRITE_ASSET(type_index, typeName, headerEntry) \
|
#define WRITE_ASSET(type_index, typeName, headerEntry) \
|
||||||
case type_index: \
|
case type_index: \
|
||||||
{ \
|
{ \
|
||||||
Writer_##typeName writer(varXAsset->header.headerEntry, m_zone, m_stream); \
|
Writer_##typeName writer(varXAsset->header.headerEntry, m_zone, *m_stream); \
|
||||||
writer.Write(&varXAsset->header.headerEntry); \
|
writer.Write(&varXAsset->header.headerEntry); \
|
||||||
break; \
|
break; \
|
||||||
}
|
}
|
||||||
@ -167,9 +168,7 @@ void ContentWriter::WriteXAsset(const bool atStreamStart)
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
std::ostringstream str;
|
throw WritingException(std::format("Unsupported asset type: {}.", static_cast<unsigned>(varXAsset->type)));
|
||||||
str << "Unsupported asset type: " << varXAsset->type << ".";
|
|
||||||
throw WritingException(str.str());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,10 +190,9 @@ void ContentWriter::WriteXAssetArray(const bool atStreamStart, const size_t coun
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentWriter::WriteContent(Zone* zone, IZoneOutputStream* stream)
|
void ContentWriter::WriteContent(IZoneOutputStream& stream)
|
||||||
{
|
{
|
||||||
m_zone = zone;
|
m_stream = &stream;
|
||||||
m_stream = stream;
|
|
||||||
|
|
||||||
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
||||||
|
|
||||||
|
@ -7,10 +7,12 @@ namespace IW4
|
|||||||
{
|
{
|
||||||
class ContentWriter final : public ContentWriterBase, public IContentWritingEntryPoint
|
class ContentWriter final : public ContentWriterBase, public IContentWritingEntryPoint
|
||||||
{
|
{
|
||||||
XAssetList* varXAssetList;
|
public:
|
||||||
XAsset* varXAsset;
|
explicit ContentWriter(const Zone& zone);
|
||||||
ScriptStringList* varScriptStringList;
|
|
||||||
|
|
||||||
|
void WriteContent(IZoneOutputStream& stream) override;
|
||||||
|
|
||||||
|
private:
|
||||||
void CreateXAssetList(XAssetList& xAssetList, MemoryManager& memory) const;
|
void CreateXAssetList(XAssetList& xAssetList, MemoryManager& memory) const;
|
||||||
|
|
||||||
void WriteScriptStringList(bool atStreamStart);
|
void WriteScriptStringList(bool atStreamStart);
|
||||||
@ -18,9 +20,8 @@ namespace IW4
|
|||||||
void WriteXAsset(bool atStreamStart);
|
void WriteXAsset(bool atStreamStart);
|
||||||
void WriteXAssetArray(bool atStreamStart, size_t count);
|
void WriteXAssetArray(bool atStreamStart, size_t count);
|
||||||
|
|
||||||
public:
|
XAssetList* varXAssetList;
|
||||||
ContentWriter();
|
XAsset* varXAsset;
|
||||||
|
ScriptStringList* varScriptStringList;
|
||||||
void WriteContent(Zone* zone, IZoneOutputStream* stream) override;
|
|
||||||
};
|
};
|
||||||
} // namespace IW4
|
} // namespace IW4
|
||||||
|
@ -57,7 +57,7 @@ namespace
|
|||||||
}
|
}
|
||||||
}; // namespace
|
}; // namespace
|
||||||
|
|
||||||
std::unique_ptr<ZoneWriter> ZoneWriterFactory::CreateWriter(Zone* zone) const
|
std::unique_ptr<ZoneWriter> ZoneWriterFactory::CreateWriter(const Zone& zone) const
|
||||||
{
|
{
|
||||||
auto writer = std::make_unique<ZoneWriter>();
|
auto writer = std::make_unique<ZoneWriter>();
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ std::unique_ptr<ZoneWriter> ZoneWriterFactory::CreateWriter(Zone* zone) const
|
|||||||
SetupBlocks(*writer);
|
SetupBlocks(*writer);
|
||||||
|
|
||||||
auto contentInMemory = std::make_unique<StepWriteZoneContentToMemory>(
|
auto contentInMemory = std::make_unique<StepWriteZoneContentToMemory>(
|
||||||
std::make_unique<ContentWriter>(), zone, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK);
|
std::make_unique<ContentWriter>(zone), zone, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK);
|
||||||
auto* contentInMemoryPtr = contentInMemory.get();
|
auto* contentInMemoryPtr = contentInMemory.get();
|
||||||
writer->AddWritingStep(std::move(contentInMemory));
|
writer->AddWritingStep(std::move(contentInMemory));
|
||||||
|
|
||||||
|
@ -9,6 +9,6 @@ namespace IW4
|
|||||||
class ZoneWriterFactory final : public IZoneWriterFactory
|
class ZoneWriterFactory final : public IZoneWriterFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
_NODISCARD std::unique_ptr<ZoneWriter> CreateWriter(Zone* zone) const override;
|
[[nodiscard]] std::unique_ptr<ZoneWriter> CreateWriter(const Zone& zone) const override;
|
||||||
};
|
};
|
||||||
} // namespace IW4
|
} // namespace IW4
|
||||||
|
@ -43,12 +43,13 @@
|
|||||||
#include "Writing/WritingException.h"
|
#include "Writing/WritingException.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <sstream>
|
#include <format>
|
||||||
|
|
||||||
using namespace IW5;
|
using namespace IW5;
|
||||||
|
|
||||||
ContentWriter::ContentWriter()
|
ContentWriter::ContentWriter(const Zone& zone)
|
||||||
: varXAssetList(nullptr),
|
: ContentWriterBase(zone),
|
||||||
|
varXAssetList(nullptr),
|
||||||
varXAsset(nullptr),
|
varXAsset(nullptr),
|
||||||
varScriptStringList(nullptr)
|
varScriptStringList(nullptr)
|
||||||
{
|
{
|
||||||
@ -56,14 +57,14 @@ ContentWriter::ContentWriter()
|
|||||||
|
|
||||||
void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memory) const
|
void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memory) const
|
||||||
{
|
{
|
||||||
if (!m_zone->m_script_strings.Empty())
|
if (!m_zone.m_script_strings.Empty())
|
||||||
{
|
{
|
||||||
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
assert(m_zone.m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
||||||
xAssetList.stringList.count = static_cast<int>(m_zone->m_script_strings.Count());
|
xAssetList.stringList.count = static_cast<int>(m_zone.m_script_strings.Count());
|
||||||
xAssetList.stringList.strings = memory.Alloc<const char*>(m_zone->m_script_strings.Count());
|
xAssetList.stringList.strings = memory.Alloc<const char*>(m_zone.m_script_strings.Count());
|
||||||
|
|
||||||
for (auto i = 0u; i < m_zone->m_script_strings.Count(); i++)
|
for (auto i = 0u; i < m_zone.m_script_strings.Count(); i++)
|
||||||
xAssetList.stringList.strings[i] = m_zone->m_script_strings.CValue(i);
|
xAssetList.stringList.strings[i] = m_zone.m_script_strings.CValue(i);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -71,15 +72,15 @@ void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memo
|
|||||||
xAssetList.stringList.strings = nullptr;
|
xAssetList.stringList.strings = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto assetCount = m_zone->m_pools->GetTotalAssetCount();
|
const auto assetCount = m_zone.m_pools->GetTotalAssetCount();
|
||||||
if (assetCount > 0)
|
if (assetCount > 0)
|
||||||
{
|
{
|
||||||
xAssetList.assetCount = static_cast<int>(assetCount);
|
xAssetList.assetCount = static_cast<int>(assetCount);
|
||||||
xAssetList.assets = memory.Alloc<XAsset>(assetCount);
|
xAssetList.assets = memory.Alloc<XAsset>(assetCount);
|
||||||
|
|
||||||
const auto end = m_zone->m_pools->end();
|
const auto end = m_zone.m_pools->end();
|
||||||
auto index = 0u;
|
auto index = 0u;
|
||||||
for (auto i = m_zone->m_pools->begin(); i != end; ++i)
|
for (auto i = m_zone.m_pools->begin(); i != end; ++i)
|
||||||
{
|
{
|
||||||
auto& asset = xAssetList.assets[index++];
|
auto& asset = xAssetList.assets[index++];
|
||||||
asset.type = static_cast<XAssetType>((*i)->m_type);
|
asset.type = static_cast<XAssetType>((*i)->m_type);
|
||||||
@ -117,7 +118,7 @@ void ContentWriter::WriteXAsset(const bool atStreamStart)
|
|||||||
#define WRITE_ASSET(type_index, typeName, headerEntry) \
|
#define WRITE_ASSET(type_index, typeName, headerEntry) \
|
||||||
case type_index: \
|
case type_index: \
|
||||||
{ \
|
{ \
|
||||||
Writer_##typeName writer(varXAsset->header.headerEntry, m_zone, m_stream); \
|
Writer_##typeName writer(varXAsset->header.headerEntry, m_zone, *m_stream); \
|
||||||
writer.Write(&varXAsset->header.headerEntry); \
|
writer.Write(&varXAsset->header.headerEntry); \
|
||||||
break; \
|
break; \
|
||||||
}
|
}
|
||||||
@ -175,9 +176,7 @@ void ContentWriter::WriteXAsset(const bool atStreamStart)
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
std::ostringstream str;
|
throw WritingException(std::format("Unsupported asset type: {}.", static_cast<unsigned>(varXAsset->type)));
|
||||||
str << "Unsupported asset type: " << varXAsset->type << ".";
|
|
||||||
throw WritingException(str.str());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,10 +198,9 @@ void ContentWriter::WriteXAssetArray(const bool atStreamStart, const size_t coun
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentWriter::WriteContent(Zone* zone, IZoneOutputStream* stream)
|
void ContentWriter::WriteContent(IZoneOutputStream& stream)
|
||||||
{
|
{
|
||||||
m_zone = zone;
|
m_stream = &stream;
|
||||||
m_stream = stream;
|
|
||||||
|
|
||||||
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
||||||
|
|
||||||
|
@ -7,10 +7,12 @@ namespace IW5
|
|||||||
{
|
{
|
||||||
class ContentWriter final : public ContentWriterBase, public IContentWritingEntryPoint
|
class ContentWriter final : public ContentWriterBase, public IContentWritingEntryPoint
|
||||||
{
|
{
|
||||||
XAssetList* varXAssetList;
|
public:
|
||||||
XAsset* varXAsset;
|
explicit ContentWriter(const Zone& zone);
|
||||||
ScriptStringList* varScriptStringList;
|
|
||||||
|
|
||||||
|
void WriteContent(IZoneOutputStream& stream) override;
|
||||||
|
|
||||||
|
private:
|
||||||
void CreateXAssetList(XAssetList& xAssetList, MemoryManager& memory) const;
|
void CreateXAssetList(XAssetList& xAssetList, MemoryManager& memory) const;
|
||||||
|
|
||||||
void WriteScriptStringList(bool atStreamStart);
|
void WriteScriptStringList(bool atStreamStart);
|
||||||
@ -18,9 +20,8 @@ namespace IW5
|
|||||||
void WriteXAsset(bool atStreamStart);
|
void WriteXAsset(bool atStreamStart);
|
||||||
void WriteXAssetArray(bool atStreamStart, size_t count);
|
void WriteXAssetArray(bool atStreamStart, size_t count);
|
||||||
|
|
||||||
public:
|
XAssetList* varXAssetList;
|
||||||
ContentWriter();
|
XAsset* varXAsset;
|
||||||
|
ScriptStringList* varScriptStringList;
|
||||||
void WriteContent(Zone* zone, IZoneOutputStream* stream) override;
|
|
||||||
};
|
};
|
||||||
} // namespace IW5
|
} // namespace IW5
|
||||||
|
@ -58,7 +58,7 @@ namespace
|
|||||||
}
|
}
|
||||||
}; // namespace
|
}; // namespace
|
||||||
|
|
||||||
std::unique_ptr<ZoneWriter> ZoneWriterFactory::CreateWriter(Zone* zone) const
|
std::unique_ptr<ZoneWriter> ZoneWriterFactory::CreateWriter(const Zone& zone) const
|
||||||
{
|
{
|
||||||
auto writer = std::make_unique<ZoneWriter>();
|
auto writer = std::make_unique<ZoneWriter>();
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ std::unique_ptr<ZoneWriter> ZoneWriterFactory::CreateWriter(Zone* zone) const
|
|||||||
SetupBlocks(*writer);
|
SetupBlocks(*writer);
|
||||||
|
|
||||||
auto contentInMemory = std::make_unique<StepWriteZoneContentToMemory>(
|
auto contentInMemory = std::make_unique<StepWriteZoneContentToMemory>(
|
||||||
std::make_unique<ContentWriter>(), zone, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK);
|
std::make_unique<ContentWriter>(zone), zone, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK);
|
||||||
auto* contentInMemoryPtr = contentInMemory.get();
|
auto* contentInMemoryPtr = contentInMemory.get();
|
||||||
writer->AddWritingStep(std::move(contentInMemory));
|
writer->AddWritingStep(std::move(contentInMemory));
|
||||||
|
|
||||||
|
@ -9,6 +9,6 @@ namespace IW5
|
|||||||
class ZoneWriterFactory final : public IZoneWriterFactory
|
class ZoneWriterFactory final : public IZoneWriterFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
_NODISCARD std::unique_ptr<ZoneWriter> CreateWriter(Zone* zone) const override;
|
[[nodiscard]] std::unique_ptr<ZoneWriter> CreateWriter(const Zone& zone) const override;
|
||||||
};
|
};
|
||||||
} // namespace IW5
|
} // namespace IW5
|
||||||
|
@ -35,12 +35,13 @@
|
|||||||
#include "Writing/WritingException.h"
|
#include "Writing/WritingException.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <sstream>
|
#include <format>
|
||||||
|
|
||||||
using namespace T5;
|
using namespace T5;
|
||||||
|
|
||||||
ContentWriter::ContentWriter()
|
ContentWriter::ContentWriter(const Zone& zone)
|
||||||
: varXAssetList(nullptr),
|
: ContentWriterBase(zone),
|
||||||
|
varXAssetList(nullptr),
|
||||||
varXAsset(nullptr),
|
varXAsset(nullptr),
|
||||||
varScriptStringList(nullptr)
|
varScriptStringList(nullptr)
|
||||||
{
|
{
|
||||||
@ -48,14 +49,14 @@ ContentWriter::ContentWriter()
|
|||||||
|
|
||||||
void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memory) const
|
void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memory) const
|
||||||
{
|
{
|
||||||
if (!m_zone->m_script_strings.Empty())
|
if (!m_zone.m_script_strings.Empty())
|
||||||
{
|
{
|
||||||
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
assert(m_zone.m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
||||||
xAssetList.stringList.count = static_cast<int>(m_zone->m_script_strings.Count());
|
xAssetList.stringList.count = static_cast<int>(m_zone.m_script_strings.Count());
|
||||||
xAssetList.stringList.strings = memory.Alloc<const char*>(m_zone->m_script_strings.Count());
|
xAssetList.stringList.strings = memory.Alloc<const char*>(m_zone.m_script_strings.Count());
|
||||||
|
|
||||||
for (auto i = 0u; i < m_zone->m_script_strings.Count(); i++)
|
for (auto i = 0u; i < m_zone.m_script_strings.Count(); i++)
|
||||||
xAssetList.stringList.strings[i] = m_zone->m_script_strings.CValue(i);
|
xAssetList.stringList.strings[i] = m_zone.m_script_strings.CValue(i);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -63,15 +64,15 @@ void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memo
|
|||||||
xAssetList.stringList.strings = nullptr;
|
xAssetList.stringList.strings = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto assetCount = m_zone->m_pools->GetTotalAssetCount();
|
const auto assetCount = m_zone.m_pools->GetTotalAssetCount();
|
||||||
if (assetCount > 0)
|
if (assetCount > 0)
|
||||||
{
|
{
|
||||||
xAssetList.assetCount = static_cast<int>(assetCount);
|
xAssetList.assetCount = static_cast<int>(assetCount);
|
||||||
xAssetList.assets = memory.Alloc<XAsset>(assetCount);
|
xAssetList.assets = memory.Alloc<XAsset>(assetCount);
|
||||||
|
|
||||||
const auto end = m_zone->m_pools->end();
|
const auto end = m_zone.m_pools->end();
|
||||||
auto index = 0u;
|
auto index = 0u;
|
||||||
for (auto i = m_zone->m_pools->begin(); i != end; ++i)
|
for (auto i = m_zone.m_pools->begin(); i != end; ++i)
|
||||||
{
|
{
|
||||||
auto& asset = xAssetList.assets[index++];
|
auto& asset = xAssetList.assets[index++];
|
||||||
asset.type = static_cast<XAssetType>((*i)->m_type);
|
asset.type = static_cast<XAssetType>((*i)->m_type);
|
||||||
@ -109,7 +110,7 @@ void ContentWriter::WriteXAsset(const bool atStreamStart)
|
|||||||
#define WRITE_ASSET(type_index, typeName, headerEntry) \
|
#define WRITE_ASSET(type_index, typeName, headerEntry) \
|
||||||
case type_index: \
|
case type_index: \
|
||||||
{ \
|
{ \
|
||||||
Writer_##typeName writer(varXAsset->header.headerEntry, m_zone, m_stream); \
|
Writer_##typeName writer(varXAsset->header.headerEntry, m_zone, *m_stream); \
|
||||||
writer.Write(&varXAsset->header.headerEntry); \
|
writer.Write(&varXAsset->header.headerEntry); \
|
||||||
break; \
|
break; \
|
||||||
}
|
}
|
||||||
@ -160,9 +161,7 @@ void ContentWriter::WriteXAsset(const bool atStreamStart)
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
std::ostringstream str;
|
throw WritingException(std::format("Unsupported asset type: {}.", static_cast<unsigned>(varXAsset->type)));
|
||||||
str << "Unsupported asset type: " << varXAsset->type << ".";
|
|
||||||
throw WritingException(str.str());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,10 +183,9 @@ void ContentWriter::WriteXAssetArray(const bool atStreamStart, const size_t coun
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentWriter::WriteContent(Zone* zone, IZoneOutputStream* stream)
|
void ContentWriter::WriteContent(IZoneOutputStream& stream)
|
||||||
{
|
{
|
||||||
m_zone = zone;
|
m_stream = &stream;
|
||||||
m_stream = stream;
|
|
||||||
|
|
||||||
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
||||||
|
|
||||||
|
@ -7,10 +7,12 @@ namespace T5
|
|||||||
{
|
{
|
||||||
class ContentWriter final : public ContentWriterBase, public IContentWritingEntryPoint
|
class ContentWriter final : public ContentWriterBase, public IContentWritingEntryPoint
|
||||||
{
|
{
|
||||||
XAssetList* varXAssetList;
|
public:
|
||||||
XAsset* varXAsset;
|
ContentWriter(const Zone& zone);
|
||||||
ScriptStringList* varScriptStringList;
|
|
||||||
|
|
||||||
|
void WriteContent(IZoneOutputStream& stream) override;
|
||||||
|
|
||||||
|
private:
|
||||||
void CreateXAssetList(XAssetList& xAssetList, MemoryManager& memory) const;
|
void CreateXAssetList(XAssetList& xAssetList, MemoryManager& memory) const;
|
||||||
|
|
||||||
void WriteScriptStringList(bool atStreamStart);
|
void WriteScriptStringList(bool atStreamStart);
|
||||||
@ -18,9 +20,8 @@ namespace T5
|
|||||||
void WriteXAsset(bool atStreamStart);
|
void WriteXAsset(bool atStreamStart);
|
||||||
void WriteXAssetArray(bool atStreamStart, size_t count);
|
void WriteXAssetArray(bool atStreamStart, size_t count);
|
||||||
|
|
||||||
public:
|
XAssetList* varXAssetList;
|
||||||
ContentWriter();
|
XAsset* varXAsset;
|
||||||
|
ScriptStringList* varScriptStringList;
|
||||||
void WriteContent(Zone* zone, IZoneOutputStream* stream) override;
|
|
||||||
};
|
};
|
||||||
} // namespace T5
|
} // namespace T5
|
||||||
|
@ -43,14 +43,14 @@ namespace
|
|||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
std::unique_ptr<ZoneWriter> ZoneWriterFactory::CreateWriter(Zone* zone) const
|
std::unique_ptr<ZoneWriter> ZoneWriterFactory::CreateWriter(const Zone& zone) const
|
||||||
{
|
{
|
||||||
auto writer = std::make_unique<ZoneWriter>();
|
auto writer = std::make_unique<ZoneWriter>();
|
||||||
|
|
||||||
SetupBlocks(*writer);
|
SetupBlocks(*writer);
|
||||||
|
|
||||||
auto contentInMemory = std::make_unique<StepWriteZoneContentToMemory>(
|
auto contentInMemory = std::make_unique<StepWriteZoneContentToMemory>(
|
||||||
std::make_unique<ContentWriter>(), zone, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK);
|
std::make_unique<ContentWriter>(zone), zone, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK);
|
||||||
auto* contentInMemoryPtr = contentInMemory.get();
|
auto* contentInMemoryPtr = contentInMemory.get();
|
||||||
writer->AddWritingStep(std::move(contentInMemory));
|
writer->AddWritingStep(std::move(contentInMemory));
|
||||||
|
|
||||||
|
@ -8,9 +8,7 @@ namespace T5
|
|||||||
{
|
{
|
||||||
class ZoneWriterFactory final : public IZoneWriterFactory
|
class ZoneWriterFactory final : public IZoneWriterFactory
|
||||||
{
|
{
|
||||||
class Impl;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
_NODISCARD std::unique_ptr<ZoneWriter> CreateWriter(Zone* zone) const override;
|
[[nodiscard]] std::unique_ptr<ZoneWriter> CreateWriter(const Zone& zone) const override;
|
||||||
};
|
};
|
||||||
} // namespace T5
|
} // namespace T5
|
||||||
|
@ -51,12 +51,13 @@
|
|||||||
#include "Writing/WritingException.h"
|
#include "Writing/WritingException.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <sstream>
|
#include <format>
|
||||||
|
|
||||||
using namespace T6;
|
using namespace T6;
|
||||||
|
|
||||||
ContentWriter::ContentWriter()
|
ContentWriter::ContentWriter(const Zone& zone)
|
||||||
: varXAssetList(nullptr),
|
: ContentWriterBase(zone),
|
||||||
|
varXAssetList(nullptr),
|
||||||
varXAsset(nullptr),
|
varXAsset(nullptr),
|
||||||
varScriptStringList(nullptr)
|
varScriptStringList(nullptr)
|
||||||
{
|
{
|
||||||
@ -64,14 +65,14 @@ ContentWriter::ContentWriter()
|
|||||||
|
|
||||||
void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memory) const
|
void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memory) const
|
||||||
{
|
{
|
||||||
if (!m_zone->m_script_strings.Empty())
|
if (!m_zone.m_script_strings.Empty())
|
||||||
{
|
{
|
||||||
assert(m_zone->m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
assert(m_zone.m_script_strings.Count() <= SCR_STRING_MAX + 1);
|
||||||
xAssetList.stringList.count = static_cast<int>(m_zone->m_script_strings.Count());
|
xAssetList.stringList.count = static_cast<int>(m_zone.m_script_strings.Count());
|
||||||
xAssetList.stringList.strings = memory.Alloc<const char*>(m_zone->m_script_strings.Count());
|
xAssetList.stringList.strings = memory.Alloc<const char*>(m_zone.m_script_strings.Count());
|
||||||
|
|
||||||
for (auto i = 0u; i < m_zone->m_script_strings.Count(); i++)
|
for (auto i = 0u; i < m_zone.m_script_strings.Count(); i++)
|
||||||
xAssetList.stringList.strings[i] = m_zone->m_script_strings.CValue(i);
|
xAssetList.stringList.strings[i] = m_zone.m_script_strings.CValue(i);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -82,15 +83,15 @@ void ContentWriter::CreateXAssetList(XAssetList& xAssetList, MemoryManager& memo
|
|||||||
xAssetList.dependCount = 0;
|
xAssetList.dependCount = 0;
|
||||||
xAssetList.depends = nullptr;
|
xAssetList.depends = nullptr;
|
||||||
|
|
||||||
const auto assetCount = m_zone->m_pools->GetTotalAssetCount();
|
const auto assetCount = m_zone.m_pools->GetTotalAssetCount();
|
||||||
if (assetCount > 0)
|
if (assetCount > 0)
|
||||||
{
|
{
|
||||||
xAssetList.assetCount = static_cast<int>(assetCount);
|
xAssetList.assetCount = static_cast<int>(assetCount);
|
||||||
xAssetList.assets = memory.Alloc<XAsset>(assetCount);
|
xAssetList.assets = memory.Alloc<XAsset>(assetCount);
|
||||||
|
|
||||||
const auto end = m_zone->m_pools->end();
|
const auto end = m_zone.m_pools->end();
|
||||||
auto index = 0u;
|
auto index = 0u;
|
||||||
for (auto i = m_zone->m_pools->begin(); i != end; ++i)
|
for (auto i = m_zone.m_pools->begin(); i != end; ++i)
|
||||||
{
|
{
|
||||||
auto& asset = xAssetList.assets[index++];
|
auto& asset = xAssetList.assets[index++];
|
||||||
asset.type = static_cast<XAssetType>((*i)->m_type);
|
asset.type = static_cast<XAssetType>((*i)->m_type);
|
||||||
@ -128,7 +129,7 @@ void ContentWriter::WriteXAsset(const bool atStreamStart)
|
|||||||
#define WRITE_ASSET(type_index, typeName, headerEntry) \
|
#define WRITE_ASSET(type_index, typeName, headerEntry) \
|
||||||
case type_index: \
|
case type_index: \
|
||||||
{ \
|
{ \
|
||||||
Writer_##typeName writer(varXAsset->header.headerEntry, m_zone, m_stream); \
|
Writer_##typeName writer(varXAsset->header.headerEntry, m_zone, *m_stream); \
|
||||||
writer.Write(&varXAsset->header.headerEntry); \
|
writer.Write(&varXAsset->header.headerEntry); \
|
||||||
break; \
|
break; \
|
||||||
}
|
}
|
||||||
@ -192,9 +193,7 @@ void ContentWriter::WriteXAsset(const bool atStreamStart)
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
std::ostringstream str;
|
throw WritingException(std::format("Unsupported asset type: {}.", static_cast<unsigned>(varXAsset->type)));
|
||||||
str << "Unsupported asset type: " << varXAsset->type << ".";
|
|
||||||
throw WritingException(str.str());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,10 +214,9 @@ void ContentWriter::WriteXAssetArray(const bool atStreamStart, const size_t coun
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentWriter::WriteContent(Zone* zone, IZoneOutputStream* stream)
|
void ContentWriter::WriteContent(IZoneOutputStream& stream)
|
||||||
{
|
{
|
||||||
m_zone = zone;
|
m_stream = &stream;
|
||||||
m_stream = stream;
|
|
||||||
|
|
||||||
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
m_stream->PushBlock(XFILE_BLOCK_VIRTUAL);
|
||||||
|
|
||||||
|
@ -7,10 +7,12 @@ namespace T6
|
|||||||
{
|
{
|
||||||
class ContentWriter final : public ContentWriterBase, public IContentWritingEntryPoint
|
class ContentWriter final : public ContentWriterBase, public IContentWritingEntryPoint
|
||||||
{
|
{
|
||||||
XAssetList* varXAssetList;
|
public:
|
||||||
XAsset* varXAsset;
|
explicit ContentWriter(const Zone& zone);
|
||||||
ScriptStringList* varScriptStringList;
|
|
||||||
|
|
||||||
|
void WriteContent(IZoneOutputStream& stream) override;
|
||||||
|
|
||||||
|
private:
|
||||||
void CreateXAssetList(XAssetList& xAssetList, MemoryManager& memory) const;
|
void CreateXAssetList(XAssetList& xAssetList, MemoryManager& memory) const;
|
||||||
|
|
||||||
void WriteScriptStringList(bool atStreamStart);
|
void WriteScriptStringList(bool atStreamStart);
|
||||||
@ -18,9 +20,8 @@ namespace T6
|
|||||||
void WriteXAsset(bool atStreamStart);
|
void WriteXAsset(bool atStreamStart);
|
||||||
void WriteXAssetArray(bool atStreamStart, size_t count);
|
void WriteXAssetArray(bool atStreamStart, size_t count);
|
||||||
|
|
||||||
public:
|
XAssetList* varXAssetList;
|
||||||
ContentWriter();
|
XAsset* varXAsset;
|
||||||
|
ScriptStringList* varScriptStringList;
|
||||||
void WriteContent(Zone* zone, IZoneOutputStream* stream) override;
|
|
||||||
};
|
};
|
||||||
} // namespace T6
|
} // namespace T6
|
||||||
|
@ -95,7 +95,7 @@ namespace
|
|||||||
}
|
}
|
||||||
}; // namespace
|
}; // namespace
|
||||||
|
|
||||||
std::unique_ptr<ZoneWriter> ZoneWriterFactory::CreateWriter(Zone* zone) const
|
std::unique_ptr<ZoneWriter> ZoneWriterFactory::CreateWriter(const Zone& zone) const
|
||||||
{
|
{
|
||||||
auto writer = std::make_unique<ZoneWriter>();
|
auto writer = std::make_unique<ZoneWriter>();
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ std::unique_ptr<ZoneWriter> ZoneWriterFactory::CreateWriter(Zone* zone) const
|
|||||||
SetupBlocks(*writer);
|
SetupBlocks(*writer);
|
||||||
|
|
||||||
auto contentInMemory = std::make_unique<StepWriteZoneContentToMemory>(
|
auto contentInMemory = std::make_unique<StepWriteZoneContentToMemory>(
|
||||||
std::make_unique<ContentWriter>(), zone, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK);
|
std::make_unique<ContentWriter>(zone), zone, ZoneConstants::OFFSET_BLOCK_BIT_COUNT, ZoneConstants::INSERT_BLOCK);
|
||||||
auto* contentInMemoryPtr = contentInMemory.get();
|
auto* contentInMemoryPtr = contentInMemory.get();
|
||||||
writer->AddWritingStep(std::move(contentInMemory));
|
writer->AddWritingStep(std::move(contentInMemory));
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ std::unique_ptr<ZoneWriter> ZoneWriterFactory::CreateWriter(Zone* zone) const
|
|||||||
// Setup loading XChunks from the zone from this point on.
|
// Setup loading XChunks from the zone from this point on.
|
||||||
ICapturedDataProvider* dataToSignProvider;
|
ICapturedDataProvider* dataToSignProvider;
|
||||||
OutputProcessorXChunks* xChunksProcessor;
|
OutputProcessorXChunks* xChunksProcessor;
|
||||||
AddXChunkProcessor(*writer, *zone, isEncrypted, &dataToSignProvider, &xChunksProcessor);
|
AddXChunkProcessor(*writer, zone, isEncrypted, &dataToSignProvider, &xChunksProcessor);
|
||||||
|
|
||||||
// Start of the XFile struct
|
// Start of the XFile struct
|
||||||
// m_writer->AddWritingStep(std::make_unique<StepSkipBytes>(8)); // Skip size and externalSize fields since they are not interesting for us
|
// m_writer->AddWritingStep(std::make_unique<StepSkipBytes>(8)); // Skip size and externalSize fields since they are not interesting for us
|
||||||
|
@ -8,9 +8,7 @@ namespace T6
|
|||||||
{
|
{
|
||||||
class ZoneWriterFactory final : public IZoneWriterFactory
|
class ZoneWriterFactory final : public IZoneWriterFactory
|
||||||
{
|
{
|
||||||
class Impl;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
_NODISCARD std::unique_ptr<ZoneWriter> CreateWriter(Zone* zone) const override;
|
[[nodiscard]] std::unique_ptr<ZoneWriter> CreateWriter(const Zone& zone) const override;
|
||||||
};
|
};
|
||||||
} // namespace T6
|
} // namespace T6
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
AssetWriter::AssetWriter(XAssetInfoGeneric* asset, Zone* zone, IZoneOutputStream* stream)
|
AssetWriter::AssetWriter(XAssetInfoGeneric* asset, const Zone& zone, IZoneOutputStream& stream)
|
||||||
: ContentWriterBase(zone, stream),
|
: ContentWriterBase(zone, stream),
|
||||||
m_asset(asset),
|
m_asset(asset),
|
||||||
varScriptString(nullptr),
|
varScriptString(nullptr),
|
||||||
@ -14,11 +14,11 @@ scr_string_t AssetWriter::UseScriptString(const scr_string_t scrString) const
|
|||||||
{
|
{
|
||||||
assert(scrString < m_asset->m_zone->m_script_strings.Count());
|
assert(scrString < m_asset->m_zone->m_script_strings.Count());
|
||||||
|
|
||||||
if (m_asset->m_zone == m_zone)
|
if (m_asset->m_zone == &m_zone)
|
||||||
return scrString;
|
return scrString;
|
||||||
|
|
||||||
const auto strValue = m_asset->m_zone->m_script_strings.CValue(scrString);
|
const auto strValue = m_asset->m_zone->m_script_strings.CValue(scrString);
|
||||||
return m_zone->m_script_strings.GetScriptString(strValue);
|
return m_zone.m_script_strings.GetScriptString(strValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssetWriter::WriteScriptStringArray(const bool atStreamStart, const size_t count)
|
void AssetWriter::WriteScriptStringArray(const bool atStreamStart, const size_t count)
|
||||||
|
@ -9,13 +9,13 @@
|
|||||||
class AssetWriter : public ContentWriterBase
|
class AssetWriter : public ContentWriterBase
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
AssetWriter(XAssetInfoGeneric* asset, const Zone& zone, IZoneOutputStream& stream);
|
||||||
|
|
||||||
|
_NODISCARD scr_string_t UseScriptString(scr_string_t scrString) const;
|
||||||
|
void WriteScriptStringArray(bool atStreamStart, size_t count);
|
||||||
|
|
||||||
XAssetInfoGeneric* m_asset;
|
XAssetInfoGeneric* m_asset;
|
||||||
|
|
||||||
scr_string_t* varScriptString;
|
scr_string_t* varScriptString;
|
||||||
scr_string_t* varScriptStringWritten;
|
scr_string_t* varScriptStringWritten;
|
||||||
|
|
||||||
AssetWriter(XAssetInfoGeneric* asset, Zone* zone, IZoneOutputStream* stream);
|
|
||||||
|
|
||||||
_NODISCARD scr_string_t UseScriptString(scr_string_t scrString) const;
|
|
||||||
void WriteScriptStringArray(bool atStreamStart, size_t count);
|
|
||||||
};
|
};
|
||||||
|
@ -2,19 +2,19 @@
|
|||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
ContentWriterBase::ContentWriterBase()
|
ContentWriterBase::ContentWriterBase(const Zone& zone)
|
||||||
: varXString(nullptr),
|
: m_zone(zone),
|
||||||
varXStringWritten(nullptr),
|
m_stream(nullptr),
|
||||||
m_zone(nullptr),
|
varXString(nullptr),
|
||||||
m_stream(nullptr)
|
varXStringWritten(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentWriterBase::ContentWriterBase(Zone* zone, IZoneOutputStream* stream)
|
ContentWriterBase::ContentWriterBase(const Zone& zone, IZoneOutputStream& stream)
|
||||||
: varXString(nullptr),
|
: m_zone(zone),
|
||||||
varXStringWritten(nullptr),
|
m_stream(&stream),
|
||||||
m_zone(zone),
|
varXString(nullptr),
|
||||||
m_stream(stream)
|
varXStringWritten(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,17 +6,8 @@
|
|||||||
class ContentWriterBase
|
class ContentWriterBase
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
const char** varXString;
|
explicit ContentWriterBase(const Zone& zone);
|
||||||
const char** varXStringWritten;
|
ContentWriterBase(const Zone& zone, IZoneOutputStream& stream);
|
||||||
|
|
||||||
Zone* m_zone;
|
|
||||||
IZoneOutputStream* m_stream;
|
|
||||||
|
|
||||||
ContentWriterBase();
|
|
||||||
ContentWriterBase(Zone* zone, IZoneOutputStream* stream);
|
|
||||||
|
|
||||||
void WriteXString(bool atStreamStart);
|
|
||||||
void WriteXStringArray(bool atStreamStart, size_t count);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~ContentWriterBase() = default;
|
virtual ~ContentWriterBase() = default;
|
||||||
@ -24,4 +15,14 @@ public:
|
|||||||
ContentWriterBase(ContentWriterBase&& other) noexcept = default;
|
ContentWriterBase(ContentWriterBase&& other) noexcept = default;
|
||||||
ContentWriterBase& operator=(const ContentWriterBase& other) = default;
|
ContentWriterBase& operator=(const ContentWriterBase& other) = default;
|
||||||
ContentWriterBase& operator=(ContentWriterBase&& other) noexcept = default;
|
ContentWriterBase& operator=(ContentWriterBase&& other) noexcept = default;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void WriteXString(bool atStreamStart);
|
||||||
|
void WriteXStringArray(bool atStreamStart, size_t count);
|
||||||
|
|
||||||
|
const Zone& m_zone;
|
||||||
|
IZoneOutputStream* m_stream;
|
||||||
|
|
||||||
|
const char** varXString;
|
||||||
|
const char** varXStringWritten;
|
||||||
};
|
};
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Zone/Stream/IZoneOutputStream.h"
|
#include "Zone/Stream/IZoneOutputStream.h"
|
||||||
#include "Zone/Zone.h"
|
|
||||||
|
|
||||||
class IContentWritingEntryPoint
|
class IContentWritingEntryPoint
|
||||||
{
|
{
|
||||||
@ -13,5 +12,5 @@ public:
|
|||||||
IContentWritingEntryPoint& operator=(const IContentWritingEntryPoint& other) = default;
|
IContentWritingEntryPoint& operator=(const IContentWritingEntryPoint& other) = default;
|
||||||
IContentWritingEntryPoint& operator=(IContentWritingEntryPoint&& other) noexcept = default;
|
IContentWritingEntryPoint& operator=(IContentWritingEntryPoint&& other) noexcept = default;
|
||||||
|
|
||||||
virtual void WriteContent(Zone* zone, IZoneOutputStream* stream) = 0;
|
virtual void WriteContent(IZoneOutputStream& stream) = 0;
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Utils/ClassUtils.h"
|
|
||||||
#include "Zone/Zone.h"
|
#include "Zone/Zone.h"
|
||||||
#include "ZoneWriter.h"
|
#include "ZoneWriter.h"
|
||||||
|
|
||||||
@ -14,7 +13,7 @@ public:
|
|||||||
IZoneWriterFactory& operator=(const IZoneWriterFactory& other) = default;
|
IZoneWriterFactory& operator=(const IZoneWriterFactory& other) = default;
|
||||||
IZoneWriterFactory& operator=(IZoneWriterFactory&& other) noexcept = default;
|
IZoneWriterFactory& operator=(IZoneWriterFactory&& other) noexcept = default;
|
||||||
|
|
||||||
_NODISCARD virtual std::unique_ptr<ZoneWriter> CreateWriter(Zone* zone) const = 0;
|
[[nodiscard]] virtual std::unique_ptr<ZoneWriter> CreateWriter(const Zone& zone) const = 0;
|
||||||
|
|
||||||
static const IZoneWriterFactory* GetZoneWriterFactoryForGame(GameId game);
|
static const IZoneWriterFactory* GetZoneWriterFactoryForGame(GameId game);
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "StepWriteXBlockSizes.h"
|
#include "StepWriteXBlockSizes.h"
|
||||||
|
|
||||||
StepWriteXBlockSizes::StepWriteXBlockSizes(Zone* zone)
|
StepWriteXBlockSizes::StepWriteXBlockSizes(const Zone& zone)
|
||||||
: m_zone(zone)
|
: m_zone(zone)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,11 @@
|
|||||||
|
|
||||||
class StepWriteXBlockSizes final : public IWritingStep
|
class StepWriteXBlockSizes final : public IWritingStep
|
||||||
{
|
{
|
||||||
Zone* m_zone;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit StepWriteXBlockSizes(Zone* zone);
|
explicit StepWriteXBlockSizes(const Zone& zone);
|
||||||
|
|
||||||
void PerformStep(ZoneWriter* zoneWriter, IWritingStream* stream) override;
|
void PerformStep(ZoneWriter* zoneWriter, IWritingStream* stream) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const Zone& m_zone;
|
||||||
};
|
};
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
#include "Zone/Stream/Impl/InMemoryZoneOutputStream.h"
|
#include "Zone/Stream/Impl/InMemoryZoneOutputStream.h"
|
||||||
|
|
||||||
StepWriteZoneContentToMemory::StepWriteZoneContentToMemory(std::unique_ptr<IContentWritingEntryPoint> entryPoint,
|
StepWriteZoneContentToMemory::StepWriteZoneContentToMemory(std::unique_ptr<IContentWritingEntryPoint> entryPoint,
|
||||||
Zone* zone,
|
const Zone& zone,
|
||||||
int offsetBlockBitCount,
|
const int offsetBlockBitCount,
|
||||||
block_t insertBlock)
|
const block_t insertBlock)
|
||||||
: m_content_loader(std::move(entryPoint)),
|
: m_content_loader(std::move(entryPoint)),
|
||||||
m_zone_data(std::make_unique<InMemoryZoneData>()),
|
m_zone_data(std::make_unique<InMemoryZoneData>()),
|
||||||
m_zone(zone),
|
m_zone(zone),
|
||||||
@ -17,11 +17,12 @@ StepWriteZoneContentToMemory::StepWriteZoneContentToMemory(std::unique_ptr<ICont
|
|||||||
void StepWriteZoneContentToMemory::PerformStep(ZoneWriter* zoneWriter, IWritingStream* stream)
|
void StepWriteZoneContentToMemory::PerformStep(ZoneWriter* zoneWriter, IWritingStream* stream)
|
||||||
{
|
{
|
||||||
std::vector<XBlock*> blocks;
|
std::vector<XBlock*> blocks;
|
||||||
|
blocks.reserve(zoneWriter->m_blocks.size());
|
||||||
for (const auto& block : zoneWriter->m_blocks)
|
for (const auto& block : zoneWriter->m_blocks)
|
||||||
blocks.push_back(block.get());
|
blocks.emplace_back(block.get());
|
||||||
|
|
||||||
const auto zoneOutputStream = std::make_unique<InMemoryZoneOutputStream>(m_zone_data.get(), std::move(blocks), m_offset_block_bit_count, m_insert_block);
|
const auto zoneOutputStream = std::make_unique<InMemoryZoneOutputStream>(m_zone_data.get(), std::move(blocks), m_offset_block_bit_count, m_insert_block);
|
||||||
m_content_loader->WriteContent(m_zone, zoneOutputStream.get());
|
m_content_loader->WriteContent(*zoneOutputStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
InMemoryZoneData* StepWriteZoneContentToMemory::GetData() const
|
InMemoryZoneData* StepWriteZoneContentToMemory::GetData() const
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Utils/ClassUtils.h"
|
|
||||||
#include "Writing/IContentWritingEntryPoint.h"
|
#include "Writing/IContentWritingEntryPoint.h"
|
||||||
#include "Writing/IWritingStep.h"
|
#include "Writing/IWritingStep.h"
|
||||||
#include "Writing/InMemoryZoneData.h"
|
#include "Writing/InMemoryZoneData.h"
|
||||||
@ -9,15 +8,16 @@
|
|||||||
|
|
||||||
class StepWriteZoneContentToMemory final : public IWritingStep
|
class StepWriteZoneContentToMemory final : public IWritingStep
|
||||||
{
|
{
|
||||||
std::unique_ptr<IContentWritingEntryPoint> m_content_loader;
|
|
||||||
std::unique_ptr<InMemoryZoneData> m_zone_data;
|
|
||||||
Zone* m_zone;
|
|
||||||
int m_offset_block_bit_count;
|
|
||||||
block_t m_insert_block;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
StepWriteZoneContentToMemory(std::unique_ptr<IContentWritingEntryPoint> entryPoint, Zone* zone, int offsetBlockBitCount, block_t insertBlock);
|
StepWriteZoneContentToMemory(std::unique_ptr<IContentWritingEntryPoint> entryPoint, const Zone& zone, int offsetBlockBitCount, block_t insertBlock);
|
||||||
|
|
||||||
void PerformStep(ZoneWriter* zoneWriter, IWritingStream* stream) override;
|
void PerformStep(ZoneWriter* zoneWriter, IWritingStream* stream) override;
|
||||||
_NODISCARD InMemoryZoneData* GetData() const;
|
[[nodiscard]] InMemoryZoneData* GetData() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr<IContentWritingEntryPoint> m_content_loader;
|
||||||
|
std::unique_ptr<InMemoryZoneData> m_zone_data;
|
||||||
|
const Zone& m_zone;
|
||||||
|
int m_offset_block_bit_count;
|
||||||
|
block_t m_insert_block;
|
||||||
};
|
};
|
||||||
|
@ -6,16 +6,16 @@
|
|||||||
#include <format>
|
#include <format>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
bool ZoneWriting::WriteZone(std::ostream& stream, Zone* zone)
|
bool ZoneWriting::WriteZone(std::ostream& stream, const Zone& zone)
|
||||||
{
|
{
|
||||||
const auto start = std::chrono::high_resolution_clock::now();
|
const auto start = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
const auto factory = IZoneWriterFactory::GetZoneWriterFactoryForGame(zone->m_game->GetId());
|
const auto factory = IZoneWriterFactory::GetZoneWriterFactoryForGame(zone.m_game->GetId());
|
||||||
|
|
||||||
const auto zoneWriter = factory->CreateWriter(zone);
|
const auto zoneWriter = factory->CreateWriter(zone);
|
||||||
if (zoneWriter == nullptr)
|
if (zoneWriter == nullptr)
|
||||||
{
|
{
|
||||||
std::cerr << std::format("Could not create ZoneWriter for zone \"{}\".\n", zone->m_name);
|
std::cerr << std::format("Could not create ZoneWriter for zone \"{}\".\n", zone.m_name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ bool ZoneWriting::WriteZone(std::ostream& stream, Zone* zone)
|
|||||||
|
|
||||||
const auto end = std::chrono::high_resolution_clock::now();
|
const auto end = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
std::cout << std::format("Writing zone \"{}\" took {} ms.\n", zone->m_name, std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count());
|
std::cout << std::format("Writing zone \"{}\" took {} ms.\n", zone.m_name, std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count());
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Zone/Zone.h"
|
#include "Zone/Zone.h"
|
||||||
|
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
class ZoneWriting
|
class ZoneWriting
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static bool WriteZone(std::ostream& stream, Zone* zone);
|
static bool WriteZone(std::ostream& stream, const Zone& zone);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user