summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-12-23 11:57:25 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-12-23 11:57:25 +0100
commita737d0cea5ca8bdcd3f9cfc38e29f8a15992ca3e (patch)
treea9eff1385f0b891dc7298477768444a1ce1113fc /src
parent14cf3a6c5acb51a953ca193289e3eb112542e9ac (diff)
a
Diffstat (limited to 'src')
-rw-r--r--src/wall-atlas.cpp55
-rw-r--r--src/wall-atlas.hpp8
2 files changed, 61 insertions, 2 deletions
diff --git a/src/wall-atlas.cpp b/src/wall-atlas.cpp
index 2486eafd..90d5dfe7 100644
--- a/src/wall-atlas.cpp
+++ b/src/wall-atlas.cpp
@@ -7,6 +7,57 @@
#include <Magnum/ImageView.h>
#include <Magnum/GL/TextureFormat.h>
+namespace floormat::Wall {
+
+uint8_t direction_index_from_name(StringView s) noexcept(false)
+{
+ for (uint8_t i = 0; auto [n, _] : wall_atlas::directions)
+ if (n == s)
+ return i;
+ else
+ i++;
+
+ fm_throw("bad rotation name '{}'"_cf, s);
+}
+
+StringView direction_index_to_name(size_t i) noexcept(false)
+{
+ fm_soft_assert(i < arraySize(wall_atlas::directions));
+ return wall_atlas::directions[i].name;
+}
+
+void resolve_wall_rotations(std::vector<Wall::Direction>& array, const std::array<DirArrayIndex, Direction_COUNT>& map) noexcept(false)
+{
+ for (auto [dir_name, dir] : wall_atlas::directions)
+ {
+ auto DAI = map[(size_t)dir];
+ if (!DAI)
+ continue;
+ auto& D = array[DAI.val];
+ for (auto [group_name, ptr, gr] : Direction::groups)
+ {
+ auto& G = D.*ptr;
+ if (!G.is_defined)
+ continue;
+ if (G.from_rotation != (uint8_t)-1)
+ {
+ const auto& DAI2 = map[G.from_rotation];
+ if (!DAI2)
+ fm_throw("from_rotation for '{}/{}' points to nonexistent rotation {}"_cf,
+ dir_name, group_name, direction_index_to_name(G.from_rotation));
+ const auto& D2 = array[DAI2.val];
+ const auto& G2 = D2.*ptr;
+ if (!G2.is_defined)
+ fm_throw("from_rotation for '{}/{}' points to empty group '{}/{}'"_cf,
+ dir_name, group_name, direction_index_to_name(G.from_rotation), group_name);
+ G.from_rotation = DAI2.val;
+ }
+ }
+ }
+}
+
+} // namespace floormat::Wall
+
namespace floormat {
using namespace floormat::Wall;
@@ -74,7 +125,7 @@ wall_atlas::wall_atlas(wall_atlas_def def, String path, const ImageView2D& img)
for (auto [group_name, gmemb, gr] : Direction::groups)
{
const auto& G = D->*gmemb;
- fm_soft_assert(!G.is_defined == !G.count);
+ fm_soft_assert(G.is_defined == !!G.count);
fm_soft_assert(G.is_defined == (G.index != (uint32_t)-1));
if (!G.is_defined)
continue;
@@ -92,6 +143,8 @@ wall_atlas::wall_atlas(wall_atlas_def def, String path, const ImageView2D& img)
fm_throw("wall_atlas '{}' is empty!"_cf, _path);
}
+ resolve_wall_rotations(_dir_array, _direction_map);
+
_texture.setLabel(_path)
.setWrapping(GL::SamplerWrapping::ClampToEdge)
.setMagnificationFilter(GL::SamplerFilter::Nearest)
diff --git a/src/wall-atlas.hpp b/src/wall-atlas.hpp
index fa3006fc..1f18489a 100644
--- a/src/wall-atlas.hpp
+++ b/src/wall-atlas.hpp
@@ -15,6 +15,9 @@ namespace floormat { class wall_atlas; }
namespace floormat::Wall {
+uint8_t direction_index_from_name(StringView s) noexcept(false);
+StringView direction_index_to_name(size_t i) noexcept(false);
+
struct Frame
{
Vector2ui offset = { (unsigned)-1, (unsigned)-1 }, size;
@@ -28,6 +31,7 @@ struct Group
Vector2ui pixel_size;
Color4 tint_mult{1,1,1,1};
Color3 tint_add{};
+ uint8_t from_rotation = (uint8_t)-1;
bool mirrored : 1 = false,
default_tint : 1 = true,
is_defined : 1 = false;
@@ -73,11 +77,13 @@ struct Info
struct DirArrayIndex {
uint8_t val = (uint8_t)-1;
- operator bool() const { return val != (uint8_t)-1; }
+ explicit operator bool() const { return val != (uint8_t)-1; }
bool operator==(const DirArrayIndex&) const noexcept;
};
+void resolve_wall_rotations(std::vector<Wall::Direction>& dirs, const std::array<DirArrayIndex, Direction_COUNT>& map) noexcept(false);
+
} // namespace floormat::Wall
namespace floormat {