diff options
-rw-r--r-- | editor/inspect-types.cpp | 23 | ||||
-rw-r--r-- | src/object.cpp | 2 |
2 files changed, 12 insertions, 13 deletions
diff --git a/editor/inspect-types.cpp b/editor/inspect-types.cpp index 2a4fd05d..eac5140c 100644 --- a/editor/inspect-types.cpp +++ b/editor/inspect-types.cpp @@ -1,6 +1,6 @@ #include "entity/metadata.hpp" #include "entity/accessor.hpp" -#include "compat/overloaded.hpp" +#include "compat/limits.hpp" #include "src/scenery.hpp" #include "src/anim-atlas.hpp" #include "src/tile-defs.hpp" @@ -51,17 +51,16 @@ struct entity_accessors<object, inspect_intent_t> { }, E::type<Vector3i>::field{"chunk"_s, [](const object& x) { return Vector3i(x.chunk().coord()); }, - [](object& x, Vector3i tile) { - if (tile.z() != x.coord.z()) // todo - { - fm_warn_once("object tried to move to different Z level (from %d to %d)", (int)tile.z(), (int)x.coord.z()); - return; - } - auto foo1 = Vector2i{tile.x(), tile.y()}; - auto foo2 = Vector2i{x.coord.chunk()}; - constexpr auto chunk_size = Vector2i{tile_size_xy} * TILE_MAX_DIM; - - x.move_to((foo1 - foo2) * chunk_size); + [](object& x, Vector3i cʹ) { + constexpr auto cmin = Vector3i(limits<int16_t>::min, limits<int16_t>::min, chunk_z_min); + constexpr auto cmax = Vector3i(limits<int16_t>::max, limits<int16_t>::max, chunk_z_max); + auto i = x.index(); + auto c = Math::clamp(cʹ, cmin, cmax); + auto ch = chunk_coords_{(int16_t)c.x(), (int16_t)c.y(), (int8_t)c.z()}; + auto g0 = x.coord; + auto g = global_coords{ch, x.coord.local()}; + if (g0 != g) + x.teleport_to(i, g, x.offset, x.r); }, }, E::type<Vector2i>::field{"tile"_s, diff --git a/src/object.cpp b/src/object.cpp index 428db9ab..3c1dae9a 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -236,7 +236,7 @@ void object::teleport_to(size_t& i, global_coords coord_, Vector2b offset_, rota bool b0 = c->_bbox_for_scenery(*this, bb0), b1 = c->_bbox_for_scenery(*this, coord_.local(), offset_, bb_offset, bb_size, bb1); - if (coord_.chunk() == coord.chunk()) + if (coord_.chunk3() == coord.chunk3()) { c->_replace_bbox_(bb0, bb1, b0, b1, upd, dynamic); non_const(coord) = coord_; |