diff --git a/src/ObjWriting/StructuredDataDef/StructuredDataDefDumper.cpp b/src/ObjWriting/StructuredDataDef/StructuredDataDefDumper.cpp index ca566f96..0cbe5fcc 100644 --- a/src/ObjWriting/StructuredDataDef/StructuredDataDefDumper.cpp +++ b/src/ObjWriting/StructuredDataDef/StructuredDataDefDumper.cpp @@ -3,6 +3,8 @@ #include #include +#include "Utils/Alignment.h" + StructuredDataDefDumperNew::StructuredDataDefDumperNew(std::ostream& stream) : AbstractTextDumper(stream), m_flags{} @@ -134,6 +136,16 @@ void StructuredDataDefDumperNew::DumpProperty(const CommonStructuredDataDef& def std::string typeName; std::vector arraySpecifiers; + currentOffsetInBit = utils::Align(currentOffsetInBit, property.m_type.GetAlignmentInBits()); + assert(currentOffsetInBit <= property.m_offset_in_bits); + if (currentOffsetInBit < property.m_offset_in_bits) + { + assert((property.m_offset_in_bits - currentOffsetInBit) % 8 == 0); + Indent(); + m_stream << "pad(" << ((property.m_offset_in_bits - currentOffsetInBit) / 8) << ");\n"; + currentOffsetInBit = property.m_offset_in_bits; + } + DumpType(def, property.m_type, typeName, arraySpecifiers); Indent(); @@ -142,7 +154,6 @@ void StructuredDataDefDumperNew::DumpProperty(const CommonStructuredDataDef& def for (auto ri = arraySpecifiers.begin(); ri != arraySpecifiers.end(); ++ri) m_stream << '[' << *ri << ']'; - #ifdef STRUCTUREDDATADEF_DEBUG m_stream << "; // Offset: " << (property.m_offset_in_bits / 8) << " byte"; if (property.m_offset_in_bits % 8 > 0) @@ -162,8 +173,9 @@ void StructuredDataDefDumperNew::DumpProperty(const CommonStructuredDataDef& def m_stream << '\n'; #else m_stream << ";\n"; - #endif + + currentOffsetInBit += property.m_type.GetSizeInBits(def); } void StructuredDataDefDumperNew::DumpStruct(const CommonStructuredDataDef& def, const CommonStructuredDataStruct& _struct, const size_t structIndex) @@ -188,6 +200,13 @@ void StructuredDataDefDumperNew::DumpStruct(const CommonStructuredDataDef& def, for (const auto& property : _struct.m_properties) DumpProperty(def, property, currentOffsetInBit); + currentOffsetInBit = utils::Align(currentOffsetInBit, 8u); + if ((currentOffsetInBit / 8) < _struct.m_size_in_byte) + { + Indent(); + m_stream << "pad(" << (_struct.m_size_in_byte - (currentOffsetInBit / 8)) << ");\n"; + } + DecIndent(); Indent(); m_stream << "};\n"; // end struct