summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-06-10 06:46:49 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-06-10 06:46:49 +0200
commitf7898053802ea38630f93034d0cd1555492fbc56 (patch)
treef81955574f7ecc24ff26ee770c45768a366d0202 /src
parentdc913f11422e002059029cac8da2d6b9a725656a (diff)
wip
Diffstat (limited to 'src')
-rw-r--r--src/chunk-collision.cpp36
-rw-r--r--src/chunk.hpp14
-rw-r--r--src/tile-bbox.hpp46
3 files changed, 54 insertions, 42 deletions
diff --git a/src/chunk-collision.cpp b/src/chunk-collision.cpp
index 49b7bc7d..7cf436a0 100644
--- a/src/chunk-collision.cpp
+++ b/src/chunk-collision.cpp
@@ -3,6 +3,7 @@
#include "entity.hpp"
#include "src/RTree-search.hpp"
#include "src/chunk-scenery.hpp"
+#include "src/tile-bbox.hpp"
#include <bit>
#include <Corrade/Containers/PairStl.h>
@@ -12,41 +13,6 @@ chunk::RTree* chunk::rtree() noexcept { ensure_passability(); return &_rtree; }
namespace {
-constexpr float wall_depth = 8, wall_depth_2 = wall_depth*.5f;
-
-constexpr Vector2 tile_start(size_t k)
-{
- constexpr auto half_tile = Vector2(TILE_SIZE2)/2;
- const local_coords coord{k};
- return TILE_SIZE2 * Vector2(coord) - half_tile;
-}
-
-Pair<Vector2i, Vector2i> scenery_tile(local_coords local, Vector2b offset, Vector2b bbox_offset, Vector2ub bbox_size)
-{
- auto center = iTILE_SIZE2 * Vector2i(local) + Vector2i(offset) + Vector2i(bbox_offset);
- auto min = center - Vector2i(bbox_size/2);
- auto size = Vector2i(bbox_size);
- return { min, min + size, };
-}
-
-constexpr Pair<Vector2, Vector2> whole_tile(size_t k)
-{
- auto min = tile_start(k);
- return { min, min + TILE_SIZE2, };
-}
-
-constexpr Pair<Vector2, Vector2> wall_north(size_t k)
-{
- auto min = tile_start(k) - Vector2(0, wall_depth_2);
- return { min, min + Vector2(TILE_SIZE2[0], wall_depth), };
-}
-
-constexpr Pair<Vector2, Vector2> wall_west(size_t k)
-{
- auto min = tile_start(k) - Vector2(wall_depth_2, 0);
- return { min, min + Vector2(wall_depth, TILE_SIZE2[1]), };
-}
-
constexpr object_id make_id(collision_type type, pass_mode p, object_id id)
{
return std::bit_cast<object_id>(collision_data { (object_id)type, (object_id)p, id });
diff --git a/src/chunk.hpp b/src/chunk.hpp
index 8453bf83..505e335d 100644
--- a/src/chunk.hpp
+++ b/src/chunk.hpp
@@ -128,13 +128,13 @@ private:
RTree _rtree;
- mutable bool _maybe_empty : 1 = true,
- _ground_modified : 1 = true,
- _walls_modified : 1 = true,
- _scenery_modified : 1 = true,
- _pass_modified : 1 = true,
- _teardown : 1 = false,
- _entities_sorted : 1 = true;
+ mutable bool _maybe_empty : 1 = true,
+ _ground_modified : 1 = true,
+ _walls_modified : 1 = true,
+ _scenery_modified : 1 = true,
+ _pass_modified : 1 = true,
+ _teardown : 1 = false,
+ _entities_sorted : 1 = true;
void ensure_scenery_buffers(scenery_scratch_buffers bufs);
static topo_sort_data make_topo_sort_data(entity& e, uint32_t mesh_idx);
diff --git a/src/tile-bbox.hpp b/src/tile-bbox.hpp
new file mode 100644
index 00000000..3275e22a
--- /dev/null
+++ b/src/tile-bbox.hpp
@@ -0,0 +1,46 @@
+#pragma once
+#include "src/tile-defs.hpp"
+#include "src/local-coords.hpp"
+#include <Magnum/Magnum.h>
+#include <Magnum/Math/Vector2.h>
+
+namespace floormat {
+
+namespace {
+constexpr float wall_depth = 8, wall_depth_2 = wall_depth*.5f;
+} // namespace
+
+constexpr Vector2 tile_start(size_t k)
+{
+ constexpr auto half_tile = Vector2(TILE_SIZE2)/2;
+ const local_coords coord{k};
+ return TILE_SIZE2 * Vector2(coord) - half_tile;
+}
+
+constexpr Pair<Vector2i, Vector2i> scenery_tile(local_coords local, Vector2b offset, Vector2b bbox_offset, Vector2ub bbox_size)
+{
+ auto center = iTILE_SIZE2 * Vector2i(local) + Vector2i(offset) + Vector2i(bbox_offset);
+ auto min = center - Vector2i(bbox_size/2);
+ auto size = Vector2i(bbox_size);
+ return { min, min + size, };
+}
+
+constexpr Pair<Vector2, Vector2> whole_tile(size_t k)
+{
+ auto min = tile_start(k);
+ return { min, min + TILE_SIZE2, };
+}
+
+constexpr Pair<Vector2, Vector2> wall_north(size_t k)
+{
+ auto min = tile_start(k) - Vector2(0, wall_depth_2);
+ return { min, min + Vector2(TILE_SIZE2[0], wall_depth), };
+}
+
+constexpr Pair<Vector2, Vector2> wall_west(size_t k)
+{
+ auto min = tile_start(k) - Vector2(wall_depth_2, 0);
+ return { min, min + Vector2(wall_depth, TILE_SIZE2[1]), };
+}
+
+} // namespace floormat