summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/point.cpp4
-rw-r--r--src/wall-atlas.cpp42
-rw-r--r--src/wall-atlas.hpp9
-rw-r--r--src/world.cpp4
4 files changed, 55 insertions, 4 deletions
diff --git a/src/point.cpp b/src/point.cpp
index a6e27f66..3e970ba3 100644
--- a/src/point.cpp
+++ b/src/point.cpp
@@ -9,10 +9,10 @@ size_t point::hash() const
static_assert(sizeof *this == size);
#ifdef FLOORMAT_64
static_assert(sizeof nullptr > 4);
- return fnvhash_64(this, sizeof *this);
+ return hash_64(this, sizeof *this);
#else
static_assert(sizeof nullptr == 4);
- return fnvhash_32(this, sizeof *this);
+ return hash_32(this, sizeof *this);
#endif
}
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);
diff --git a/src/wall-atlas.hpp b/src/wall-atlas.hpp
index aa18c0bc..544bc5b7 100644
--- a/src/wall-atlas.hpp
+++ b/src/wall-atlas.hpp
@@ -1,5 +1,6 @@
#pragma once
#include "compat/defs.hpp"
+#include "compat/function2.fwd.hpp"
#include "src/rotation.hpp"
#include <array>
#include <memory>
@@ -20,6 +21,7 @@ struct wall_frame
struct wall_frames
{
+ bool is_empty() const noexcept;
ArrayView<const wall_frame> items(const wall_atlas& a) const;
uint32_t index = (uint32_t)-1, count = 0;
@@ -34,6 +36,13 @@ struct wall_frames
struct wall_frame_set
{
+ enum class type : uint8_t { wall = 1, overlay, side, top, corner_L, corner_R, };
+
+ bool is_empty() const noexcept;
+
+ void visit(const fu2::function_view<bool(StringView, const wall_frames&, type) const>& fun) const&;
+ void visit(const fu2::function_view<bool(StringView, wall_frames&, type) const>& fun) &;
+
wall_frames wall, overlay, side, top;
wall_frames corner_L, corner_R;
};
diff --git a/src/world.cpp b/src/world.cpp
index 5f2bb870..7920c205 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -6,7 +6,7 @@
using namespace floormat;
-size_t world::object_id_hasher::operator()(object_id id) const noexcept { return int_hash(id); }
+size_t world::object_id_hasher::operator()(object_id id) const noexcept { return hash_int(id); }
size_t world::chunk_coords_hasher::operator()(const chunk_coords_& coord) const noexcept
{
@@ -14,7 +14,7 @@ size_t world::chunk_coords_hasher::operator()(const chunk_coords_& coord) const
x |= uint64_t((uint16_t)coord.x) << 0;
x |= uint64_t((uint16_t)coord.y) << 16;
x |= uint64_t( (uint8_t)coord.z) << 32;
- return int_hash(x);
+ return hash_int(x);
}
namespace floormat {