|
|
|
@ -122,15 +122,7 @@ ElementType ImageElement::elementType() const { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::size_t ImageElement::serializeTo(std::span<std::byte> target) const { |
|
|
|
std::size_t ImageElement::serializeTo(std::span<std::byte> target) const { |
|
|
|
std::size_t pos = 0; |
|
|
|
// FIXME: serialize
|
|
|
|
pos = writeU16LE(target, pos, static_cast<std::uint16_t>(ElementType::Image)); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_x); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_y); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_width); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_height); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, 0); |
|
|
|
|
|
|
|
pos = writeBuffer(target, pos, m_buffer); |
|
|
|
|
|
|
|
return alignNextWrite(target, pos, 4); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ImageElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) { |
|
|
|
void ImageElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) { |
|
|
|
@ -217,17 +209,7 @@ ElementType AnimationElement::elementType() const { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::size_t AnimationElement::serializeTo(std::span<std::byte> target) const { |
|
|
|
std::size_t AnimationElement::serializeTo(std::span<std::byte> target) const { |
|
|
|
std::size_t pos = 0; |
|
|
|
// FIXME: implement this
|
|
|
|
pos = writeU16LE(target, pos, static_cast<std::uint16_t>(ElementType::Animation)); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_x); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_y); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_width); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_height); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_numberOfFrames); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_updateInterval); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, 0); |
|
|
|
|
|
|
|
pos = writeBuffer(target, pos, m_buffer); |
|
|
|
|
|
|
|
return alignNextWrite(target, pos, 4); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void AnimationElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) { |
|
|
|
void AnimationElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) { |
|
|
|
@ -303,18 +285,7 @@ ElementType HScrollImageElement::elementType() const { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::size_t HScrollImageElement::serializeTo(std::span<std::byte> target) const { |
|
|
|
std::size_t HScrollImageElement::serializeTo(std::span<std::byte> target) const { |
|
|
|
std::size_t pos = 0; |
|
|
|
// FIXME Serialize
|
|
|
|
pos = writeU16LE(target, pos, static_cast<std::uint16_t>(ElementType::HScrollImage)); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_x); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_y); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_width); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_height); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_contentWidth); |
|
|
|
|
|
|
|
pos = writeU8LE(target, pos, m_flags); |
|
|
|
|
|
|
|
pos = writeU8LE(target, pos, m_scrollSpeed); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, 0); |
|
|
|
|
|
|
|
pos = writeBuffer(target, pos, m_buffer); |
|
|
|
|
|
|
|
return alignNextWrite(target, pos, 4); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void HScrollImageElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) { |
|
|
|
void HScrollImageElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) { |
|
|
|
@ -390,18 +361,7 @@ ElementType VScrollImageElement::elementType() const { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::size_t VScrollImageElement::serializeTo(std::span<std::byte> target) const { |
|
|
|
std::size_t VScrollImageElement::serializeTo(std::span<std::byte> target) const { |
|
|
|
std::size_t pos = 0; |
|
|
|
// FIXME Serialize
|
|
|
|
pos = writeU16LE(target, pos, static_cast<std::uint16_t>(ElementType::VScrollImage)); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_x); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_y); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_width); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_height); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_contentHeight); |
|
|
|
|
|
|
|
pos = writeU8LE(target, pos, m_flags); |
|
|
|
|
|
|
|
pos = writeU8LE(target, pos, m_scrollSpeed); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, 0); |
|
|
|
|
|
|
|
pos = writeBuffer(target, pos, m_buffer); |
|
|
|
|
|
|
|
return alignNextWrite(target, pos, 4); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void VScrollImageElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) { |
|
|
|
void VScrollImageElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) { |
|
|
|
@ -455,15 +415,7 @@ ElementType LineElement::elementType() const { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::size_t LineElement::serializeTo(std::span<std::byte> target) const { |
|
|
|
std::size_t LineElement::serializeTo(std::span<std::byte> target) const { |
|
|
|
std::size_t pos = 0; |
|
|
|
// FIXME: serialize
|
|
|
|
pos = writeU16LE(target, pos, static_cast<std::uint16_t>(ElementType::Line)); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_originX); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_originY); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_targetX); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_targetY); |
|
|
|
|
|
|
|
pos = writeU8LE(target, pos, static_cast<std::uint8_t>(m_lineStyle)); |
|
|
|
|
|
|
|
pos = writeU8LE(target, pos, m_flags); |
|
|
|
|
|
|
|
return alignNextWrite(target, pos, 4); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void LineElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) { |
|
|
|
void LineElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) { |
|
|
|
@ -516,16 +468,7 @@ ElementType ClippedTextElement::elementType() const { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::size_t ClippedTextElement::serializeTo(std::span<std::byte> target) const { |
|
|
|
std::size_t ClippedTextElement::serializeTo(std::span<std::byte> target) const { |
|
|
|
std::size_t pos = 0; |
|
|
|
// FIXME: serialize
|
|
|
|
pos = writeU16LE(target, pos, static_cast<std::uint16_t>(ElementType::HScrollImage)); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_x); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_y); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_width); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_height); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_fontIndex); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_text.size()); |
|
|
|
|
|
|
|
pos = writeBuffer(target, pos, std::as_bytes(std::span{m_text})); |
|
|
|
|
|
|
|
return alignNextWrite(target, pos, 4); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ClippedTextElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) { |
|
|
|
void ClippedTextElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) { |
|
|
|
@ -588,18 +531,7 @@ ElementType HScrollTextElement::elementType() const { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::size_t HScrollTextElement::serializeTo(std::span<std::byte> target) const { |
|
|
|
std::size_t HScrollTextElement::serializeTo(std::span<std::byte> target) const { |
|
|
|
std::size_t pos = 0; |
|
|
|
// FIXME serialize
|
|
|
|
pos = writeU16LE(target, pos, static_cast<std::uint16_t>(ElementType::HScrollImage)); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_x); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_y); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_width); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_height); |
|
|
|
|
|
|
|
pos = writeU8LE(target, pos, m_flags); |
|
|
|
|
|
|
|
pos = writeU8LE(target, pos, m_scrollSpeed); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_fontIndex); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_text.size()); |
|
|
|
|
|
|
|
pos = writeBuffer(target, pos, std::as_bytes(std::span{m_text})); |
|
|
|
|
|
|
|
return alignNextWrite(target, pos, 4); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void HScrollTextElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) { |
|
|
|
void HScrollTextElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) { |
|
|
|
@ -657,16 +589,7 @@ ElementType CurrentTimeElement::elementType() const { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::size_t CurrentTimeElement::serializeTo(std::span<std::byte> target) const { |
|
|
|
std::size_t CurrentTimeElement::serializeTo(std::span<std::byte> target) const { |
|
|
|
std::size_t pos = 0; |
|
|
|
// FIXME: serialize
|
|
|
|
pos = writeU16LE(target, pos, static_cast<std::uint16_t>(ElementType::HScrollImage)); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_x); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_y); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_width); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_height); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_fontIndex); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_utcOffset); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_flags); |
|
|
|
|
|
|
|
return alignNextWrite(target, pos, 4); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void CurrentTimeElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) { |
|
|
|
void CurrentTimeElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) { |
|
|
|
@ -751,32 +674,7 @@ SectionType AlwaysDrawnSection::sectionType() const { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::size_t AlwaysDrawnSection::serializeTo(std::span<std::byte> target) const { |
|
|
|
std::size_t AlwaysDrawnSection::serializeTo(std::span<std::byte> target) const { |
|
|
|
std::size_t pos = 0; |
|
|
|
// FIXME: serialize
|
|
|
|
pos = writeU8LE(target, pos, static_cast<std::uint16_t>(SectionType::AlwaysDrawn)); |
|
|
|
|
|
|
|
// Will be replaced later
|
|
|
|
|
|
|
|
pos = writeU24LE(target, pos, 0); |
|
|
|
|
|
|
|
std::uint16_t flags = 0; |
|
|
|
|
|
|
|
if (m_drawOnFront) { |
|
|
|
|
|
|
|
flags |= std::uint16_t{1}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (m_drawOnBack) { |
|
|
|
|
|
|
|
flags |= std::uint16_t{2}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (m_clearBeforeDrawing) { |
|
|
|
|
|
|
|
flags |= std::uint16_t{4}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, flags); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_elements.size()); |
|
|
|
|
|
|
|
for (auto const& element : m_elements) { |
|
|
|
|
|
|
|
if (pos < target.size()) { |
|
|
|
|
|
|
|
pos += element->serializeTo(target.subspan(pos)); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
pos += element->serializeTo({}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
pos = alignNextWrite(target, pos, 4); |
|
|
|
|
|
|
|
std::ignore = writeU24LE(target, 1, pos); |
|
|
|
|
|
|
|
return pos; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::expected<std::unique_ptr<AlwaysDrawnSection>, ParseError> AlwaysDrawnSection::parse(std::span<std::byte const>& buffer) { |
|
|
|
std::expected<std::unique_ptr<AlwaysDrawnSection>, ParseError> AlwaysDrawnSection::parse(std::span<std::byte const>& buffer) { |
|
|
|
@ -873,34 +771,7 @@ SectionType TimeBasedDrawnSection::sectionType() const { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::size_t TimeBasedDrawnSection::serializeTo(std::span<std::byte> target) const { |
|
|
|
std::size_t TimeBasedDrawnSection::serializeTo(std::span<std::byte> target) const { |
|
|
|
std::size_t pos = 0; |
|
|
|
// FIXME: serialize
|
|
|
|
pos = writeU8LE(target, pos, static_cast<std::uint16_t>(SectionType::AlwaysDrawn)); |
|
|
|
|
|
|
|
// Will be replaced later
|
|
|
|
|
|
|
|
pos = writeU24LE(target, pos, 0); |
|
|
|
|
|
|
|
std::uint16_t flags = 0; |
|
|
|
|
|
|
|
if (m_drawOnFront) { |
|
|
|
|
|
|
|
flags |= std::uint16_t{1}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (m_drawOnBack) { |
|
|
|
|
|
|
|
flags |= std::uint16_t{2}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (m_clearBeforeDrawing) { |
|
|
|
|
|
|
|
flags |= std::uint16_t{4}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, flags); |
|
|
|
|
|
|
|
pos = writeU16LE(target, pos, m_elements.size()); |
|
|
|
|
|
|
|
pos = writeU64LE(target, pos, std::bit_cast<std::uint64_t>(m_startTimestamp)); |
|
|
|
|
|
|
|
pos = writeU64LE(target, pos, std::bit_cast<std::uint64_t>(m_endTimestamp)); |
|
|
|
|
|
|
|
for (auto const& element : m_elements) { |
|
|
|
|
|
|
|
if (pos < target.size()) { |
|
|
|
|
|
|
|
pos += element->serializeTo(target.subspan(pos)); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
pos += element->serializeTo({}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
pos = alignNextWrite(target, pos, 4); |
|
|
|
|
|
|
|
std::ignore = writeU24LE(target, 1, pos); |
|
|
|
|
|
|
|
return pos; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::expected<std::unique_ptr<TimeBasedDrawnSection>, ParseError> TimeBasedDrawnSection::parse(std::span<std::byte const>& buffer) { |
|
|
|
std::expected<std::unique_ptr<TimeBasedDrawnSection>, ParseError> TimeBasedDrawnSection::parse(std::span<std::byte const>& buffer) { |
|
|
|
@ -924,16 +795,7 @@ SectionType CustomFontSection::sectionType() const { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::size_t CustomFontSection::serializeTo(std::span<std::byte> target) const { |
|
|
|
std::size_t CustomFontSection::serializeTo(std::span<std::byte> target) const { |
|
|
|
std::size_t pos = 0; |
|
|
|
// FIXME: serailize
|
|
|
|
pos = writeU8LE(target, pos, static_cast<std::uint16_t>(SectionType::AlwaysDrawn)); |
|
|
|
|
|
|
|
// Will be replaced later
|
|
|
|
|
|
|
|
pos = writeU24LE(target, pos, 0); |
|
|
|
|
|
|
|
pos = writeU24LE(target, pos, m_fontData.size()); |
|
|
|
|
|
|
|
pos = writeU8LE(target, pos, 0); |
|
|
|
|
|
|
|
pos = writeBuffer(target, pos, m_fontData); |
|
|
|
|
|
|
|
pos = alignNextWrite(target, pos, 4); |
|
|
|
|
|
|
|
std::ignore = writeU24LE(target, 1, pos); |
|
|
|
|
|
|
|
return pos; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::expected<std::unique_ptr<CustomFontSection>, ParseError> CustomFontSection::parse(std::span<std::byte const>& buffer) { |
|
|
|
std::expected<std::unique_ptr<CustomFontSection>, ParseError> CustomFontSection::parse(std::span<std::byte const>& buffer) { |
|
|
|
@ -941,23 +803,7 @@ std::expected<std::unique_ptr<CustomFontSection>, ParseError> CustomFontSection: |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::size_t serializeFile(std::span<std::byte>& buffer, File const& file) { |
|
|
|
std::size_t serializeFile(std::span<std::byte>& buffer, File const& file) { |
|
|
|
std::size_t pos = 0; |
|
|
|
// FIXME: serialize
|
|
|
|
pos = writeU8LE(buffer, pos, 0xAF); |
|
|
|
|
|
|
|
pos = writeU8LE(buffer, pos, 0x7E); |
|
|
|
|
|
|
|
pos = writeU8LE(buffer, pos, 0x2B); |
|
|
|
|
|
|
|
pos = writeU8LE(buffer, pos, 0x64); |
|
|
|
|
|
|
|
pos = writeU32LE(buffer, pos, 1); |
|
|
|
|
|
|
|
pos = writeU16LE(buffer, pos, file.sections.size()); |
|
|
|
|
|
|
|
pos = writeU16LE(buffer, pos, 0); |
|
|
|
|
|
|
|
pos = alignNextWrite(buffer, pos, 4); |
|
|
|
|
|
|
|
for (auto const& section : file.sections) { |
|
|
|
|
|
|
|
if (pos < buffer.size()) { |
|
|
|
|
|
|
|
pos += section->serializeTo(buffer.subspan(pos)); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
pos += section->serializeTo({}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return pos; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::expected<File, ParseError> parseFile(std::span<std::byte const> data) { |
|
|
|
std::expected<File, ParseError> parseFile(std::span<std::byte const> data) { |
|
|
|
|