summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-05-24 11:59:48 +0200
committerStanislaw Halik <sthalik@misaki.pl>2024-05-25 22:59:05 +0200
commit83f60aa9a5a2452158b7774044dcc51c82c43ae4 (patch)
treee7354aa1b76ecb2c8f6ca34bcd40e8059b937b08 /src
parent36972e30f7f2c47e3a5e45b94cda5e0072839484 (diff)
w
Diffstat (limited to 'src')
-rw-r--r--src/hole.cpp45
-rw-r--r--src/hole.hpp33
2 files changed, 78 insertions, 0 deletions
diff --git a/src/hole.cpp b/src/hole.cpp
index f9e6f05c..cdd409d7 100644
--- a/src/hole.cpp
+++ b/src/hole.cpp
@@ -1,7 +1,52 @@
#include "hole.hpp"
+//#include <mg/Functions.h>
namespace floormat {
+using bbox = cut_rectangle_result::bbox;
+
+namespace {
+
+
+} // namespace
+
+cut_rectangle_result cut_rectangle(cut_rectangle_result::bbox input, cut_rectangle_result::bbox hole)
+{
+ const auto ihalf = Vector2i{input.bbox_size/2};
+ const auto istart = input.position - ihalf;
+ const auto iend = input.position + Vector2i{input.bbox_size} - ihalf;
+ const auto hhalf = Vector2i{hole.bbox_size/2};
+ const auto hstart = hole.position - hhalf;
+ const auto hend = hole.position + Vector2i{hole.bbox_size} - hhalf;
+
+ //std::atomic_signal_fence(std::memory_order::relaxed); // compiler-only barrier
+
+ {
+ bool iempty = Vector2ui{input.bbox_size}.product() == 0;
+ bool hempty = Vector2ui{hole.bbox_size}.product() == 0;
+ bool empty_before_x = hend.x() <= istart.x();
+ bool empty_before_y = hend.y() <= istart.y();
+ bool empty_after_x = hstart.x() >= iend.x();
+ bool empty_after_y = hstart.y() >= iend.y();
+ if (iempty | hempty | empty_before_x | empty_before_y | empty_after_x | empty_after_y)
+ return {};
+ }
+
+ const bool sx = hstart.x() <= istart.x();
+ const bool ex = hend.x() >= iend.x();
+ const bool sy = hstart.y() <= istart.y();
+ const bool ey = hend.y() >= iend.y();
+
+ enum : uint8_t { SX, EX, SY, EY };
+ enum : uint8_t { startx = 1 << SX, endx = 1 << EX, starty = 1 << SY, endy = 1 << EY };
+
+ constexpr auto mask = uint8_t(startx | endx | starty | endy);
+ auto val = uint8_t(sx << SX | ex << EX | sy << SY | ey << EY);
+ CORRADE_ASSUME((val & mask) == val);
+ (void)val;
+
+ return {};
+}
} // namespace floormat
diff --git a/src/hole.hpp b/src/hole.hpp
index d97c72f9..bf01ccd2 100644
--- a/src/hole.hpp
+++ b/src/hole.hpp
@@ -1,7 +1,40 @@
#pragma once
+#include "object.hpp"
+#include <array>
namespace floormat {
+struct hole_proto final : object_proto
+{
+ bool affects_render : 1 = true;
+ bool affects_physics : 1 = false;
+};
+struct hole : object
+{
+ bool affects_render : 1 = true;
+ bool affects_physics : 1 = false;
+
+ hole(object_id id, class chunk& c, const hole_proto& proto);
+};
+
+struct cut_rectangle_result
+{
+ struct bbox
+ {
+ Vector2i position;
+ Vector2ub bbox_size;
+ };
+
+ struct rect { Vector2i min, max; };
+
+ uint8_t code = 0;
+ uint8_t size = 0;
+ std::array<rect, 8> ret;
+
+ operator ArrayView<const bbox>() const;
+};
+
+cut_rectangle_result cut_rectangle(cut_rectangle_result::bbox input, cut_rectangle_result::bbox hole);
} // namespace floormat