summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/wall-atlas.cpp44
-rw-r--r--src/wall-atlas.hpp49
2 files changed, 62 insertions, 31 deletions
diff --git a/src/wall-atlas.cpp b/src/wall-atlas.cpp
index a8fe168f..a4bf9aa9 100644
--- a/src/wall-atlas.cpp
+++ b/src/wall-atlas.cpp
@@ -2,6 +2,7 @@
#include "compat/exception.hpp"
#include "src/tile-defs.hpp"
#include <utility>
+#include <Corrade/Containers/ArrayViewStl.h>
#include <Corrade/Containers/StridedArrayView.h>
#include <Magnum/ImageView.h>
#include <Magnum/GL/TextureFormat.h>
@@ -11,8 +12,11 @@ namespace floormat {
wall_atlas::wall_atlas() noexcept = default;
wall_atlas::~wall_atlas() noexcept = default;
+#if 0
void wall_atlas::validate(const wall_atlas& a, const ImageView2D& img) noexcept(false)
{
+ // todo
+
const auto pixels = img.pixels();
const auto size = pixels.size();
const auto width = size[1], height = size[0];
@@ -48,13 +52,17 @@ void wall_atlas::validate(const wall_atlas& a, const ImageView2D& img) noexcept(
}
fm_soft_assert(got_group);
}
+#endif
-Vector2i wall_atlas::expected_size(int depth, Tag group)
+Vector2i wall_atlas::expected_size(unsigned depth, Group_ group)
{
static_assert(iTILE_SIZE2.x() == iTILE_SIZE2.y());
constexpr int half_tile = iTILE_SIZE2.x()/2;
- CORRADE_ASSUME(group < Tag::COUNT);
- using enum Tag;
+
+ fm_assert(depth > 0 && depth < 1<<16);
+ CORRADE_ASSUME(group < Group_::COUNT);
+
+ using enum Group_;
switch (group)
{
case overlay:
@@ -62,7 +70,7 @@ Vector2i wall_atlas::expected_size(int depth, Tag group)
return { iTILE_SIZE.x(), iTILE_SIZE.z() };
case top:
case side:
- return { depth, iTILE_SIZE.z() };
+ return { (int)depth, iTILE_SIZE.z() };
case corner_L:
return { half_tile, iTILE_SIZE.z() };
case corner_R:
@@ -93,7 +101,7 @@ auto wall_atlas::get_Direction(Direction_ num) const -> Direction*
constexpr DirArrayIndex default_DAI;
fm_debug_assert(num < Direction_::COUNT);
- if (_dir_array.isEmpty()) [[unlikely]]
+ if (_dir_array.empty()) [[unlikely]]
return {};
else if (auto DAI = _direction_map[(uint8_t)num]; DAI != default_DAI) [[likely]]
return const_cast<Direction*>(&_dir_array[DAI.val]);
@@ -103,7 +111,7 @@ auto wall_atlas::get_Direction(Direction_ num) const -> Direction*
auto wall_atlas::frames(const Group& group) const -> ArrayView<const Frame>
{
- if (_frame_array.isEmpty()) [[unlikely]]
+ if (_frame_array.empty()) [[unlikely]]
return {};
const auto size = _frame_array.size(); (void)size;
const auto index = group.index, count = group.count;
@@ -111,9 +119,12 @@ auto wall_atlas::frames(const Group& group) const -> ArrayView<const Frame>
return { &_frame_array[index], count };
}
-auto wall_atlas::group(size_t dir, Tag tag) const -> const Group*
+auto wall_atlas::group(Direction_ d, Group_ tag) const -> const Group* { return group((size_t)d, tag); }
+auto wall_atlas::group(size_t d, size_t tag) const -> const Group* { return group(d, (Group_)tag); }
+
+auto wall_atlas::group(size_t dir, Group_ tag) const -> const Group*
{
- fm_assert(tag < Tag::COUNT);
+ fm_assert(tag < Group_::COUNT);
const auto* const set_ = direction(dir);
if (!set_)
return {};
@@ -126,9 +137,9 @@ auto wall_atlas::group(size_t dir, Tag tag) const -> const Group*
return &ret;
}
-auto wall_atlas::group(const Direction& dir, Tag tag) const -> const Group*
+auto wall_atlas::group(const Direction& dir, Group_ tag) const -> const Group*
{
- fm_assert(tag < Tag::COUNT);
+ fm_assert(tag < Group_::COUNT);
const auto memfn = dir.groups[(size_t)tag].member;
const Group& ret = dir.*memfn;
if (ret.is_empty())
@@ -136,7 +147,7 @@ auto wall_atlas::group(const Direction& dir, Tag tag) const -> const Group*
return &ret;
}
-auto wall_atlas::group(const Direction* dir, Tag tag) const -> const Group*
+auto wall_atlas::group(const Direction* dir, Group_ tag) const -> const Group*
{
fm_debug_assert(dir != nullptr);
return group(*dir, tag);
@@ -173,6 +184,17 @@ bool Direction::is_empty() const noexcept
return true;
}
+const Group& Direction::group(Group_ i) const { return const_cast<Direction&>(*this).group((size_t)i); }
+const Group& Direction::group(size_t i) const { return const_cast<Direction&>(*this).group(i); }
+Group& Direction::group(Group_ i) { return group((size_t)i); }
+
+Group& Direction::group(size_t i)
+{
+ fm_assert(i < (size_t)Group_::COUNT);
+ auto ptr = groups[i].member;
+ return this->*ptr;
+}
+
bool Frame::operator==(const Frame&) const noexcept = default;
bool Direction::operator==(const Direction&) const noexcept = default;
bool Info::operator==(const floormat::Wall::Info&) const noexcept = default;
diff --git a/src/wall-atlas.hpp b/src/wall-atlas.hpp
index 1c0a920d..fcad0a8b 100644
--- a/src/wall-atlas.hpp
+++ b/src/wall-atlas.hpp
@@ -3,7 +3,8 @@
#include "src/rotation.hpp"
#include "src/pass-mode.hpp"
#include <array>
-#include <Corrade/Containers/Array.h>
+#include <bitset>
+#include <vector>
#include <Corrade/Containers/String.h>
#include <Magnum/Math/Vector2.h>
#include <Magnum/Math/Color.h>
@@ -36,14 +37,14 @@ struct Group
bool operator==(const Group&) const noexcept;
};
-enum class Tag : uint8_t { wall, overlay, side, top, corner_L, corner_R, COUNT };
+enum class Group_ : uint8_t { wall, overlay, side, top, corner_L, corner_R, COUNT };
enum class Direction_ : uint8_t { N, E, S, W, COUNT };
struct Direction
{
using memfn_ptr = Group Direction::*;
- struct member_tuple { StringView str; memfn_ptr member; Tag tag; };
+ struct member_tuple { StringView str; memfn_ptr member; Group_ tag; };
explicit operator bool() const noexcept { return !is_empty(); }
bool is_empty() const noexcept;
@@ -52,15 +53,20 @@ struct Direction
Group corner_L, corner_R;
pass_mode passability = pass_mode::blocked;
+ const Group& group(Group_ i) const;
+ const Group& group(size_t i) const;
+ Group& group(Group_ i);
+ Group& group(size_t i);
+
static constexpr inline member_tuple groups[] = {
- { "wall"_s, &Direction::wall, Tag::wall },
- { "overlay"_s, &Direction::overlay, Tag::overlay },
- { "side"_s, &Direction::side, Tag::side },
- { "top"_s, &Direction::top, Tag::top },
- { "corner-L"_s, &Direction::corner_L, Tag::corner_L, },
- { "corner-R"_s, &Direction::corner_R, Tag::corner_R, },
+ { "wall"_s, &Direction::wall, Group_::wall },
+ { "overlay"_s, &Direction::overlay, Group_::overlay },
+ { "side"_s, &Direction::side, Group_::side },
+ { "top"_s, &Direction::top, Group_::top },
+ { "corner-L"_s, &Direction::corner_L, Group_::corner_L, },
+ { "corner-R"_s, &Direction::corner_R, Group_::corner_R, },
};
- static_assert(arraySize(groups) == (size_t)Tag::COUNT);
+ static_assert(std::size(groups) == (size_t)Group_::COUNT);
bool operator==(const Direction&) const noexcept;
};
@@ -96,9 +102,10 @@ public:
bool operator==(const wall_atlas_def&) const noexcept;
Info header;
- Array<Frame> frames;
- Array<Direction> direction_array;
+ std::vector<Frame> frames;
+ std::vector<Direction> direction_array;
std::array<DirArrayIndex, 4> direction_map;
+ std::bitset<(size_t)Wall::Direction_::COUNT> direction_mask{0};
static wall_atlas_def deserialize(StringView filename);
void serialize(StringView filename) const;
@@ -113,11 +120,11 @@ class wall_atlas final
using Direction_ = Wall::Direction_;
using Direction = Wall::Direction;
using Info = Wall::Info;
- using Tag = Wall::Tag;
+ using Group_ = Wall::Group_;
using DirArrayIndex = Wall::DirArrayIndex;
- Array<Direction> _dir_array;
- Array<Frame> _frame_array;
+ std::vector<Direction> _dir_array;
+ std::vector<Frame> _frame_array;
Info _info;
String _path;
GL::Texture2D _texture{NoCreate};
@@ -132,9 +139,11 @@ public:
wall_atlas(wall_atlas_def def, String path, const ImageView2D& img);
void serialize(StringView filename) const;
- const Group* group(size_t dir, Tag tag) const;
- const Group* group(const Direction& dir, Tag tag) const;
- const Group* group(const Direction* dir, Tag tag) const;
+ const Group* group(Direction_ d, Group_ tag) const;
+ const Group* group(size_t dir, size_t group) const;
+ const Group* group(size_t dir, Group_ tag) const;
+ const Group* group(const Direction& dir, Group_ tag) const;
+ const Group* group(const Direction* dir, Group_ tag) const;
const Direction* direction(size_t dir) const;
uint8_t direction_count() const;
ArrayView<const Frame> frames(const Group& a) const;
@@ -147,8 +156,8 @@ public:
GL::Texture2D& texture();
static size_t enum_to_index(enum rotation x);
- static void validate(const wall_atlas& a, const ImageView2D& img) noexcept(false);
- static Vector2i expected_size(int depth, Tag group);
+ //static void validate(const wall_atlas& a, const ImageView2D& img) noexcept(false);
+ static Vector2i expected_size(unsigned depth, Group_ group);
struct dir_tuple
{