summaryrefslogtreecommitdiffhomepage
path: root/src/wall-atlas.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wall-atlas.cpp')
-rw-r--r--src/wall-atlas.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/wall-atlas.cpp b/src/wall-atlas.cpp
index be4010c7..d73510bb 100644
--- a/src/wall-atlas.cpp
+++ b/src/wall-atlas.cpp
@@ -1,11 +1,32 @@
#include "wall-atlas.hpp"
#include "compat/assert.hpp"
+#include "compat/function2.hpp"
#include <utility>
#include <Magnum/ImageView.h>
#include <Magnum/GL/TextureFormat.h>
namespace floormat {
+namespace {
+
+#define FM_FRAMESET_ITER(Name) do { if (fun( #Name ## _s, const_cast<Self>(frameset.Name), wall_frame_set::type::Name)) return; } while(false)
+#define FM_FRAMESET_ITER2(Str, Name) do { if (fun( Str, const_cast<Self>(frameset.Name), wall_frame_set::type::Name )) return; } while(false)
+
+template<typename Self>
+CORRADE_ALWAYS_INLINE void visit_frameset_impl(const wall_frame_set& frameset, auto&& fun)
+{
+ FM_FRAMESET_ITER(wall);
+ FM_FRAMESET_ITER(overlay);
+ FM_FRAMESET_ITER(side);
+ FM_FRAMESET_ITER(top);
+ FM_FRAMESET_ITER2("corner-L"_s, corner_L);
+ FM_FRAMESET_ITER2("corner-R"_s, corner_R);
+}
+
+#undef FM_FRAMESET_ITER
+
+} // namespace
+
size_t wall_atlas::enum_to_index(enum rotation r)
{
static_assert(rotation_COUNT == rotation{8});
@@ -16,6 +37,17 @@ size_t wall_atlas::enum_to_index(enum rotation r)
return x;
}
+bool wall_frames::is_empty() const noexcept
+{
+ return count == 0;
+}
+
+bool wall_frame_set::is_empty() const noexcept
+{
+ return !wall.is_empty() && !overlay.is_empty() && !side.is_empty() && !top.is_empty() &&
+ !corner_L.is_empty() && !corner_R.is_empty();
+}
+
wall_atlas::wall_atlas(wall_info info, const ImageView2D& image,
Array<wall_frame> frames,
std::unique_ptr<wall_frame_set[]> framesets,
@@ -53,6 +85,16 @@ ArrayView<const wall_frame> wall_atlas::frame_array() const { return _frame_arra
StringView wall_atlas::name() const { return _info.name; }
const wall_frame_set& wall_atlas::frameset(enum rotation r) const { return frameset(enum_to_index(r)); }
+void wall_frame_set::visit(const fu2::function_view<bool(StringView name, const wall_frames& frames, type tag) const>& fun) const&
+{
+ visit_frameset_impl<const wall_frames&>(*this, fun);
+}
+
+void wall_frame_set::visit(const fu2::function_view<bool(StringView name, wall_frames& frames, type tag) const>& fun) &
+{
+ visit_frameset_impl<wall_frames&>(*this, fun);
+}
+
const wall_frame_set& wall_atlas::frameset(size_t i) const
{
fm_assert(i < 4 && _frameset_indexes[i] != (uint8_t)-1);