summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/chunk-walls.cpp7
-rw-r--r--src/wall-atlas.cpp23
-rw-r--r--src/wall-atlas.hpp2
3 files changed, 25 insertions, 7 deletions
diff --git a/src/chunk-walls.cpp b/src/chunk-walls.cpp
index 6e9fd51b..24049094 100644
--- a/src/chunk-walls.cpp
+++ b/src/chunk-walls.cpp
@@ -181,7 +181,7 @@ GL::Mesh chunk::make_wall_mesh()
const auto D = k & 1 ? Wall::Direction_::W : Wall::Direction_::N;
const auto& atlas = _walls->atlases[k];
fm_assert(atlas != nullptr);
- const auto variant = _walls->variants[k];
+ const auto variant_ = _walls->variants[k];
const auto pos = local_coords{k / 2u};
const auto center = Vector3(pos) * TILE_SIZE;
const auto& dir = atlas->calc_direction(D);
@@ -216,6 +216,7 @@ GL::Mesh chunk::make_wall_mesh()
fm_debug_assert(i < max_wall_quad_count);
_walls->mesh_indexes[i] = (uint16_t)k;
const auto frames = atlas->frames(group);
+ const auto variant = variant_ % frames.size();
const auto& frame = frames[variant];
const auto texcoords = Quads::texcoords_at(frame.offset, frame.size, atlas->image_size());
const auto depth = tile_shader::depth_value(pos, depth_offset);
@@ -225,8 +226,8 @@ GL::Mesh chunk::make_wall_mesh()
}
}
- const auto comp = [&atlases = _walls->atlases](const auto& a, const auto& b) {
- return atlases[a.second] < atlases[b.second];
+ const auto comp = [&A = _walls->atlases](const auto& a, const auto& b) {
+ return A[a.second] < A[b.second];
};
ranges::sort(ranges::zip_view(vertexes, _walls->mesh_indexes), comp);
diff --git a/src/wall-atlas.cpp b/src/wall-atlas.cpp
index 3ee14f1e..995be1e9 100644
--- a/src/wall-atlas.cpp
+++ b/src/wall-atlas.cpp
@@ -61,6 +61,7 @@ wall_atlas::wall_atlas(wall_atlas_def def, String path, const ImageView2D& img)
fm_soft_assert(!_frame_array.empty());
{
+ const auto frame_count = _frame_array.size();
bool found = false;
for (auto [dir_name, dir] : wall_atlas::directions)
{
@@ -71,12 +72,15 @@ 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.index != (uint32_t)-1));
if (!G.is_defined)
continue;
found = true;
if (G.count == 0) [[unlikely]]
fm_throw("wall_atlas '{}' defined group {}/{} has no frames!"_cf,
_path, dir_name, group_name);
+ fm_soft_assert(G.index < frame_count && G.index + G.count <= frame_count);
}
}
if (!found) [[unlikely]]
@@ -113,6 +117,17 @@ auto wall_atlas::frames(const Group& group) const -> ArrayView<const Frame>
return { &_frame_array[index], count };
}
+auto wall_atlas::frames(Direction_ dir, Group_ gr) const -> ArrayView<const Frame>
+{
+ const auto* D = get_Direction(dir);
+ if (!D) [[unlikely]]
+ fm_throw("no such direction: {}"_cf, (int)dir);
+ const auto* G = group(*D, gr);
+ if (!G) [[unlikely]]
+ fm_throw("no such group {} for direction {}"_cf, (int)gr, (int)dir);
+ return { _frame_array.data() + G->index, G->count };
+}
+
auto wall_atlas::group(Direction_ dir, Group_ gr) const -> const Group* { return group((size_t)dir, (size_t)gr); }
auto wall_atlas::group(size_t dir, Group_ gr) const -> const Group* { return group(dir, (size_t)gr); }
@@ -138,6 +153,8 @@ auto wall_atlas::group(const Direction& dir, Group_ tag) const -> const Group*
fm_assert(tag < Group_::COUNT);
const auto memfn = dir.groups[(size_t)tag].member;
const Group& ret = dir.*memfn;
+ if (!ret.is_defined)
+ return {};
#if 0
if (ret.is_empty())
return {};
@@ -145,10 +162,8 @@ auto wall_atlas::group(const Direction& dir, Group_ tag) const -> const Group*
return &ret;
}
-auto wall_atlas::direction(size_t dir) const -> const Direction*
-{
- return get_Direction(Direction_(dir));
-}
+auto wall_atlas::direction(size_t dir) const -> const Direction* { return get_Direction(Direction_(dir)); }
+auto wall_atlas::direction(Direction_ dir) const -> const Direction* { return get_Direction(dir); }
auto wall_atlas::calc_direction(Direction_ dir) const -> const Direction&
{
diff --git a/src/wall-atlas.hpp b/src/wall-atlas.hpp
index 0e2a6e1e..fa3006fc 100644
--- a/src/wall-atlas.hpp
+++ b/src/wall-atlas.hpp
@@ -131,9 +131,11 @@ public:
const Group* group(size_t dir, Group_ tag) const;
const Group* group(const Direction& dir, Group_ group) const;
const Direction* direction(size_t dir) const;
+ const Direction* direction(Direction_ dir) const;
const Direction& calc_direction(Direction_ dir) const;
uint8_t direction_count() const;
ArrayView<const Frame> frames(const Group& a) const;
+ ArrayView<const Frame> frames(Direction_ dir, Group_ g) const noexcept(false);
ArrayView<const Frame> raw_frame_array() const;
const Info& info() const { return _info; }