summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--editor/wall-editor.cpp11
-rw-r--r--src/chunk-walls.cpp25
-rw-r--r--src/global-coords.hpp4
3 files changed, 17 insertions, 23 deletions
diff --git a/editor/wall-editor.cpp b/editor/wall-editor.cpp
index faa7a260..eba9dc66 100644
--- a/editor/wall-editor.cpp
+++ b/editor/wall-editor.cpp
@@ -1,6 +1,7 @@
#include "wall-editor.hpp"
#include "src/wall-defs.hpp"
#include "src/wall-atlas.hpp"
+#include "src/world.hpp"
#include "loader/loader.hpp"
#include "loader/wall-info.hpp"
#include <Corrade/Containers/ArrayView.h>
@@ -69,4 +70,14 @@ void wall_editor::clear_selection() { _selected_atlas = nullptr; }
bool wall_editor::is_atlas_selected(const std::shared_ptr<wall_atlas>& atlas) const { return _selected_atlas == atlas; }
bool wall_editor::is_anything_selected() const { return _selected_atlas != nullptr; }
+void wall_editor::place_tile(world& w, global_coords coords, const std::shared_ptr<wall_atlas>& atlas)
+{
+ auto [c, t] = w[coords];
+ switch (_r)
+ {
+ case rotation::N: t.wall_north() = { atlas, (uint8_t)-1 }; break;
+ case rotation::W: t.wall_west() = { atlas, (uint8_t)-1 }; break;
+ }
+}
+
} // namespace floormat
diff --git a/src/chunk-walls.cpp b/src/chunk-walls.cpp
index 24049094..6021aa3a 100644
--- a/src/chunk-walls.cpp
+++ b/src/chunk-walls.cpp
@@ -185,6 +185,7 @@ GL::Mesh chunk::make_wall_mesh()
const auto pos = local_coords{k / 2u};
const auto center = Vector3(pos) * TILE_SIZE;
const auto& dir = atlas->calc_direction(D);
+ const auto vpos = (uint8_t)Vector2ui(global_coords{_coord, pos}.raw()).sum();
for (auto [_, member, G] : Wall::Direction::groups)
{
@@ -216,7 +217,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 variant = (variant_ != (uint8_t)-1 ? variant_ : vpos) % 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);
@@ -226,11 +227,8 @@ GL::Mesh chunk::make_wall_mesh()
}
}
- 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);
+ ranges::sort(ranges::zip_view(vertexes, _walls->mesh_indexes),
+ [&A = _walls->atlases](const auto& a, const auto& b) { return A[a.second] < A[b.second]; });
auto vertex_view = std::as_const(vertexes).prefix(N);
auto index_view = make_indexes(N);
@@ -253,21 +251,6 @@ auto chunk::ensure_wall_mesh() noexcept -> wall_mesh_tuple
return { wall_mesh, _walls->mesh_indexes, size_t(wall_mesh.count()/6) };
_walls_modified = false;
-#if 0
- size_t count = 0;
- for (auto i = 0uz; i < TILE_COUNT*2; i++)
- if (_walls->atlases[i])
- _walls->mesh_indexes[count++] = uint16_t(i);
-
- if (count == 0)
- return {wall_mesh, {}, 0};
-
- std::sort(_walls->mesh_indexes.data(), _walls->mesh_indexes.data() + (ptrdiff_t)count,
- [this](uint16_t a, uint16_t b) {
- return _walls->atlases[a] < _walls->atlases[b];
- });
-#endif
-
wall_mesh = make_wall_mesh();
return { wall_mesh, _walls->mesh_indexes, (size_t)wall_mesh.count()/6u };
}
diff --git a/src/global-coords.hpp b/src/global-coords.hpp
index 8e0cf5a8..1f6c2def 100644
--- a/src/global-coords.hpp
+++ b/src/global-coords.hpp
@@ -80,8 +80,8 @@ constexpr inline int8_t chunk_z_min = -1, chunk_z_max = 14;
struct global_coords final
{
- struct raw_coords final { uint32_t &x, &y; }; // NOLINT
- struct raw_coords_ final { uint32_t x, y; };
+ struct raw_coords { uint32_t &x, &y; operator Vector2ui() const { return {x, y}; } }; // NOLINT
+ struct raw_coords_ { uint32_t x, y; operator Vector2ui() const { return {x, y}; } };
private:
using u0 = std::integral_constant<uint32_t, (1<<15)>;