Convert StructuredDataDef for IW4

This commit is contained in:
Jan
2022-01-20 23:38:45 +01:00
parent b894a524e8
commit 96ef7a46fb
9 changed files with 194 additions and 17 deletions

View File

@ -19,12 +19,14 @@ CommonStructuredDataDefStructEntry::CommonStructuredDataDefStructEntry(std::stri
}
CommonStructuredDataDefStruct::CommonStructuredDataDefStruct()
: m_size(0u)
: m_bit_offset(0u),
m_size(0u)
{
}
CommonStructuredDataDefStruct::CommonStructuredDataDefStruct(std::string name)
: m_name(std::move(name)),
m_bit_offset(0u),
m_size(0u)
{
}

View File

@ -19,7 +19,8 @@ struct CommonStructuredDataDefStructEntry
struct CommonStructuredDataDefStruct
{
std::string m_name;
std::vector<CommonStructuredDataDefStructEntry> m_entries;
std::vector<CommonStructuredDataDefStructEntry> m_properties;
size_t m_bit_offset;
size_t m_size;
CommonStructuredDataDefStruct();

View File

@ -43,13 +43,15 @@ bool operator>=(const CommonStructuredDataDefType& lhs, const CommonStructuredDa
}
CommonStructuredDataDefIndexedArray::CommonStructuredDataDefIndexedArray()
: m_array_size(0u)
: m_array_size(0u),
m_element_size(0u)
{
}
CommonStructuredDataDefIndexedArray::CommonStructuredDataDefIndexedArray(const CommonStructuredDataDefType type, const size_t arraySize)
: m_array_type(type),
m_array_size(arraySize)
m_array_size(arraySize),
m_element_size(0u)
{
}
@ -78,13 +80,15 @@ bool operator>=(const CommonStructuredDataDefIndexedArray& lhs, const CommonStru
}
CommonStructuredDataDefEnumedArray::CommonStructuredDataDefEnumedArray()
: m_enum_index(0u)
: m_enum_index(0u),
m_element_size(0u)
{
}
CommonStructuredDataDefEnumedArray::CommonStructuredDataDefEnumedArray(const CommonStructuredDataDefType type, const size_t enumIndex)
: m_array_type(type),
m_enum_index(enumIndex)
m_enum_index(enumIndex),
m_element_size(0u)
{
}

View File

@ -42,6 +42,7 @@ struct CommonStructuredDataDefIndexedArray
{
CommonStructuredDataDefType m_array_type;
size_t m_array_size;
size_t m_element_size;
CommonStructuredDataDefIndexedArray();
CommonStructuredDataDefIndexedArray(CommonStructuredDataDefType type, size_t arraySize);
@ -56,6 +57,7 @@ struct CommonStructuredDataDefEnumedArray
{
CommonStructuredDataDefType m_array_type;
size_t m_enum_index;
size_t m_element_size;
CommonStructuredDataDefEnumedArray();
CommonStructuredDataDefEnumedArray(CommonStructuredDataDefType type, size_t enumIndex);

View File

@ -1,5 +1,7 @@
#include "StructuredDataDefStructScopeSequences.h"
#include <algorithm>
#include "Parsing/Simple/Matcher/SimpleMatcherFactory.h"
namespace sdd::struct_scope_sequences
@ -169,7 +171,7 @@ namespace sdd::struct_scope_sequences
currentType = ProcessArray(state, result, currentType);
// TODO: Calculate offset
state->m_current_struct->m_entries.emplace_back(result.NextCapture(CAPTURE_ENTRY_NAME).IdentifierValue(), currentType, 0);
state->m_current_struct->m_properties.emplace_back(result.NextCapture(CAPTURE_ENTRY_NAME).IdentifierValue(), currentType, 0);
}
};
@ -191,6 +193,11 @@ namespace sdd::struct_scope_sequences
{
assert(state->m_current_struct != nullptr);
std::sort(state->m_current_struct->m_properties.begin(), state->m_current_struct->m_properties.end(),
[](const CommonStructuredDataDefStructEntry& e1, const CommonStructuredDataDefStructEntry& e2)
{
return e1.m_name < e2.m_name;
});
state->m_current_struct = nullptr;
}
};

View File

@ -42,7 +42,7 @@ void StructuredDataDefReader::SetupStreamProxies()
m_stream = m_open_streams.back().get();
}
std::vector<std::unique_ptr<CommonStructuredDataDef>> StructuredDataDefReader::ReadStructureDataDefs()
std::vector<std::unique_ptr<CommonStructuredDataDef>> StructuredDataDefReader::ReadStructureDataDefs(bool& success)
{
SimpleLexer::Config lexerConfig;
lexerConfig.m_emit_new_line_tokens = false;
@ -52,7 +52,8 @@ std::vector<std::unique_ptr<CommonStructuredDataDef>> StructuredDataDefReader::R
const auto parser = std::make_unique<StructuredDataDefParser>(lexer.get());
if (parser->Parse())
success = parser->Parse();
if (success)
return parser->GetDefs();
std::cout << "Parsing structured data def file \"" << m_file_name << "\" failed!" << std::endl;

View File

@ -24,5 +24,5 @@ public:
StructuredDataDefReader(std::istream& stream, std::string fileName);
StructuredDataDefReader(std::istream& stream, std::string fileName, include_callback_t includeCallback);
std::vector<std::unique_ptr<CommonStructuredDataDef>> ReadStructureDataDefs();
std::vector<std::unique_ptr<CommonStructuredDataDef>> ReadStructureDataDefs(bool& success);
};