diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/hole-cut.cpp | 9 | ||||
-rw-r--r-- | src/hole.cpp | 70 | ||||
-rw-r--r-- | src/hole.hpp | 26 |
3 files changed, 83 insertions, 22 deletions
diff --git a/src/hole-cut.cpp b/src/hole-cut.cpp index f87a6c2f..3983e4fd 100644 --- a/src/hole-cut.cpp +++ b/src/hole-cut.cpp @@ -156,7 +156,10 @@ constexpr cut_rectangle_result cut_rectangleʹ(bbox input, bbox hole) auto h1 = hole.position + Vector2i{hole.bbox_size} - hhalf; if (check_empty(r0, r1, h0, h1, input.bbox_size, hole.bbox_size)) - return {0, {}}; + return { + .size = 1, + .array = {{ rect { r0, r1 }, }}, + }; const bool sx = h0.x() <= r0.x(); const bool ex = h1.x() >= r1.x(); @@ -166,12 +169,12 @@ constexpr cut_rectangle_result cut_rectangleʹ(bbox input, bbox hole) auto val = uint8_t(sx << 0 | ex << 1 | sy << 2 | ey << 3); CORRADE_ASSUME(val < 16); const auto elt = elements[val]; + const auto sz = elt.size; cut_rectangle_result res = { - .size = elt.size, + .size = sz, .array = {}, }; - const auto sz = elt.size; CORRADE_ASSUME(sz <= 8); for (auto i = 0u; i < sz; i++) diff --git a/src/hole.cpp b/src/hole.cpp index 783fa5ee..d013187b 100644 --- a/src/hole.cpp +++ b/src/hole.cpp @@ -2,39 +2,55 @@ #include "chunk.hpp" #include "tile-constants.hpp" #include "shaders/shader.hpp" +#include "compat/non-const.hpp" namespace floormat { namespace { } // namespace +hole_proto::~hole_proto() noexcept = default; +hole_proto::hole_proto() = default; +hole_proto::hole_proto(const hole_proto&) = default; +hole_proto& hole_proto::operator=(const hole_proto&) = default; +hole_proto::hole_proto(hole_proto&&) noexcept = default; +hole_proto& hole_proto::operator=(hole_proto&&) noexcept = default; + +bool hole_proto::flags::operator==(const struct flags&) const = default; +bool hole_proto::operator==(const hole_proto&) const = default; + hole::hole(object_id id, floormat::chunk& c, const hole_proto& proto): - object{id, c, proto} + object{id, c, proto}, height{proto.height}, flags{proto.flags} { + } hole::~hole() noexcept { - c->mark_ground_modified(); - c->mark_walls_modified(); - c->mark_passability_modified(); -} + if (c->is_teardown()) [[unlikely]] + return; -void hole::update(const std::shared_ptr<object>& ptr, size_t& i, const Ns& dt) -{ + mark_chunk_modified(); } +void hole::update(const std::shared_ptr<object>&, size_t&, const Ns&) {} + hole::operator hole_proto() const { hole_proto ret; static_cast<object_proto&>(ret) = object_proto(*this); - ret.max_distance = max_distance; - ret.color = color; - ret.falloff = falloff; - ret.enabled = enabled; + ret.height = height; + ret.flags = flags; return ret; } +void hole::mark_chunk_modified() +{ + c->mark_ground_modified(); // todo conditionalize + c->mark_walls_modified(); // todo conditionalize + c->mark_passability_modified(); +} + float hole::depth_offset() const { constexpr auto ret = 4 / tile_shader::depth_tile_size; @@ -47,8 +63,38 @@ Vector2 hole::ordinal_offset(Vector2b) const return ret; } +void hole::set_height(uint8_t heightʹ) +{ + if (height != heightʹ) + { + const_cast<uint8_t&>(height) = heightʹ; + mark_chunk_modified(); + } +} + +void hole::set_z_offset(uint8_t z) +{ + if (z_offset != z) + { + const_cast<uint8_t&>(z_offset) = z; + mark_chunk_modified(); + } +} + + +void hole::set_enabled(bool on_render, bool on_physics) +{ + non_const(flags).on_render = on_render; + + if (flags.on_physics != on_physics) + { + non_const(flags).on_physics = on_physics; + mark_chunk_modified(); + } +} + object_type hole::type() const noexcept { return object_type::hole; } bool hole::is_virtual() const { return true; } -bool hole::is_dynamic() const { return false; } +bool hole::is_dynamic() const { return true; } } // namespace floormat diff --git a/src/hole.hpp b/src/hole.hpp index 64e53149..49d1e809 100644 --- a/src/hole.hpp +++ b/src/hole.hpp @@ -14,18 +14,23 @@ struct hole_proto final : object_proto hole_proto& operator=(hole_proto&&) noexcept; bool operator==(const hole_proto&) const; + struct flags + { + bool operator==(const flags&) const; + + bool on_render : 1 = true; + bool on_physics : 1 = true; + bool is_wall : 1 = false; + }; + uint8_t height = 0; - bool on_render : 1 = true; - bool on_physics : 1 = true; - bool is_wall : 1 = false; + struct flags flags; }; struct hole final : object { - uint8_t _height = 0; - const bool on_render : 1 = true; - const bool on_physics : 1 = true; - const bool is_wall : 1 = false; + const uint8_t height = 0, z_offset = tile_size_z/2; + const struct hole_proto::flags flags; hole(object_id id, class chunk& c, const hole_proto& proto); ~hole() noexcept override; @@ -37,9 +42,16 @@ struct hole final : object bool is_dynamic() const override; bool is_virtual() const override; + void set_height(uint8_t height); + void set_z_offset(uint8_t z); + void set_enabled(bool on_render, bool on_physics); + explicit operator hole_proto() const; friend class world; + +private: + void mark_chunk_modified(); }; struct cut_rectangle_result |