summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/wall-atlas.cpp8
-rw-r--r--test/wall-atlas.cpp41
2 files changed, 45 insertions, 4 deletions
diff --git a/src/wall-atlas.cpp b/src/wall-atlas.cpp
index c2f05c4f..31b2ad2d 100644
--- a/src/wall-atlas.cpp
+++ b/src/wall-atlas.cpp
@@ -94,13 +94,15 @@ wall_atlas::wall_atlas(Info info, const ImageView2D& img,
auto wall_atlas::get_Direction(Direction_ num) const -> Direction*
{
+ constexpr DirArrayIndex default_DAI;
fm_debug_assert(num < Direction_::COUNT);
if (_dir_array.isEmpty()) [[unlikely]]
return {};
- if (auto idx = _direction_to_Direction_array_index[(uint8_t)num])
- return const_cast<Direction*>(&_dir_array[idx.val]);
- return {};
+ else if (auto DAI = _direction_to_Direction_array_index[(uint8_t)num]; DAI != default_DAI) [[likely]]
+ return const_cast<Direction*>(&_dir_array[DAI.val]);
+ else
+ return {};
}
auto wall_atlas::frames(const Group& group) const -> ArrayView<const Frame>
diff --git a/test/wall-atlas.cpp b/test/wall-atlas.cpp
index 47dc64ac..fd4d6f82 100644
--- a/test/wall-atlas.cpp
+++ b/test/wall-atlas.cpp
@@ -91,10 +91,49 @@ struct wall_atlas_
bool operator==(const wall_atlas_&) const noexcept = default;
Info header;
- Array<Direction> directions;
+ std::array<Direction, 4> directions = {};
Array<Frame> frames;
};
+[[nodiscard]] wall_atlas_ read_from_file(StringView filename, bool do_checks = true)
+{
+ wall_atlas_ atlas;
+
+ const auto jroot = json_helper::from_json_(filename);
+ atlas.header = read_info_header(jroot);
+
+ if (do_checks)
+ {
+ const Info header_defaults;
+ fm_assert(atlas.header.name != header_defaults.name);
+ fm_assert(atlas.header.depth != header_defaults.depth);
+ }
+
+ bool got_any_directions = false;
+ for (const auto& [_, curdir] : wall_atlas::directions)
+ {
+ auto i = (size_t)curdir;
+ atlas.directions[i] = read_direction_metadata(jroot, curdir);
+ got_any_directions = true;
+ }
+ if (do_checks)
+ fm_assert(got_any_directions);
+
+ atlas.frames = read_all_frames(jroot);
+
+ if (do_checks)
+ {
+ constexpr Frame frame_defaults;
+ constexpr Group group_defaults;
+
+ fm_assert(!atlas.frames.isEmpty());
+ fm_assert(atlas.frames[0].offset != frame_defaults.offset);
+ fm_assert(atlas.directions[(size_t)Direction_::W].side.pixel_size != group_defaults.pixel_size);
+ }
+
+ return atlas;
+}
+
void write_to_temp_file()
{
const auto filename = temp_filename();