diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-29 01:28:12 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-29 01:28:12 +0200 |
commit | b0069421278d6fc3fac0153e2f19c549c7bfce32 (patch) | |
tree | 2104e6dbf45bcd9fbedf1dd144cfdec4f0dbfc1e /serialize/world-writer.cpp | |
parent | b6a42cc53f808c86342d1bcd400ea95e6e7f5762 (diff) |
a
Diffstat (limited to 'serialize/world-writer.cpp')
-rw-r--r-- | serialize/world-writer.cpp | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/serialize/world-writer.cpp b/serialize/world-writer.cpp index e1750fb2..f47e96b1 100644 --- a/serialize/world-writer.cpp +++ b/serialize/world-writer.cpp @@ -7,6 +7,7 @@ #include "src/chunk.hpp"
#include "src/world.hpp"
#include <vector>
+#include <algorithm>
#include <Corrade/Containers/StringView.h>
#include <Corrade/Utility/Path.h>
@@ -90,7 +91,7 @@ void writer_state::serialize_chunk(const chunk& c, chunk_coords coord) fm_debug_assert(s.bytes_written() + tile_size <= chunkbuf_size);
- auto img_g = maybe_intern_atlas(x.ground_image);
+ auto img_g = maybe_intern_atlas(x.ground);
auto img_n = maybe_intern_atlas(x.wall_north);
auto img_w = maybe_intern_atlas(x.wall_north);
@@ -104,8 +105,18 @@ void writer_state::serialize_chunk(const chunk& c, chunk_coords coord) s << flags;
+#ifndef FM_NO_DEBUG
+ constexpr auto check_atlas = [](const tile_image& x) {
+ if (x.atlas)
+ fm_assert(x.variant < x.atlas->num_tiles());
+ };
+ check_atlas(x.ground);
+ check_atlas(x.wall_north);
+ check_atlas(x.wall_west);
+#endif
+
if (img_g != null_atlas)
- s << img_g << x.ground_image.variant;
+ s << img_g << x.ground.variant;
if (img_n != null_atlas)
s << img_n << x.wall_north.variant;
if (img_w != null_atlas)
@@ -131,9 +142,17 @@ void writer_state::serialize_atlases() s << sz;
- for (const auto& [p, t] : tile_images)
+ std::vector<interned_atlas> atlases;
+ atlases.reserve(tile_images.size());
+
+ for (const auto& [_, t] : tile_images)
+ atlases.push_back(t);
+ std::sort(atlases.begin(), atlases.end(), [](const auto& a, const auto& b) {
+ return a.index < b.index;
+ });
+
+ for (const auto& [atlas, _] : atlases)
{
- const auto& [atlas, index] = t;
const auto name = atlas->name();
const auto namesiz = name.size();
fm_debug_assert(s.bytes_written() + namesiz + 1 <= atlasbuf_size);
|