diff options
-rw-r--r-- | editor/inspect-types.cpp | 10 | ||||
-rw-r--r-- | serialize/world-impl.hpp | 12 | ||||
-rw-r--r-- | serialize/world-reader.cpp | 10 | ||||
-rw-r--r-- | serialize/world-writer.cpp | 12 | ||||
-rw-r--r-- | src/chunk-bbox.cpp | 8 | ||||
-rw-r--r-- | src/chunk.hpp | 10 | ||||
-rw-r--r-- | src/collision.cpp | 8 | ||||
-rw-r--r-- | src/collision.hpp | 10 | ||||
-rw-r--r-- | src/scenery.cpp | 2 | ||||
-rw-r--r-- | src/scenery.hpp | 10 |
10 files changed, 45 insertions, 47 deletions
diff --git a/editor/inspect-types.cpp b/editor/inspect-types.cpp index 69d40d81..8c50fc18 100644 --- a/editor/inspect-types.cpp +++ b/editor/inspect-types.cpp @@ -48,6 +48,16 @@ struct entity_accessors<scenery_ref> { [](const scenery_ref& x) { return x.frame.passability; }, [](scenery_ref& x, pass_mode value) { x.frame.passability = value; } }, + entity::type<Vector2b>::field{"bbox-offset"_s, + [](const scenery_ref& x) { return x.frame.bbox_offset; }, + [](scenery_ref& x, Vector2b value) { x.frame.bbox_offset = value; }, + [](const scenery_ref& x) { return x.frame.passability == pass_mode::pass ? field_status::readonly : field_status::enabled; }, + }, + entity::type<Vector2b>::field{"bbox-size"_s, + [](const scenery_ref& x) { return x.frame.bbox_size; }, + [](scenery_ref& x, Vector2b value) { x.frame.bbox_size = value; }, + [](const scenery_ref& x) { return x.frame.passability == pass_mode::pass ? field_status::readonly : field_status::enabled; }, + }, entity::type<bool>::field{"interactive"_s, [](const scenery_ref& x) { return x.frame.interactive; }, [](scenery_ref& x, bool value) { x.frame.interactive = value; } diff --git a/serialize/world-impl.hpp b/serialize/world-impl.hpp index 3403631d..5a43654e 100644 --- a/serialize/world-impl.hpp +++ b/serialize/world-impl.hpp @@ -17,14 +17,16 @@ * 3) Serialize scenery. Tile flag (1 << 6) added. * 4) Scenery dt now stored as fixed-point uint16_t. * 5) Serialize scenery pixel offset. + * 6) Serialize scenery bboxes. + * 7) Serialize scenery bbox_size offset. */ namespace floormat::Serialize { -using tilemeta = std::uint8_t; -using atlasid = std::uint16_t; -using chunksiz = std::uint16_t; -using proto_t = std::uint16_t; +using tilemeta = std::uint8_t; +using atlasid = std::uint16_t; +using chunksiz = std::uint16_t; +using proto_t = std::uint16_t; namespace { @@ -35,7 +37,7 @@ template<typename T> constexpr inline T int_max = std::numeric_limits<T>::max(); constexpr inline std::size_t atlas_name_max = 128; constexpr inline auto null_atlas = (atlasid)-1LL; -constexpr inline proto_t proto_version = 5; +constexpr inline proto_t proto_version = 7; constexpr inline proto_t min_proto_version = 1; constexpr inline auto chunk_magic = (std::uint16_t)~0xc0d3; constexpr inline auto scenery_magic = (std::uint16_t)~0xb00b; diff --git a/serialize/world-reader.cpp b/serialize/world-reader.cpp index e108747e..4f31b88b 100644 --- a/serialize/world-reader.cpp +++ b/serialize/world-reader.cpp @@ -177,6 +177,16 @@ void reader_state::read_chunks(reader_t& s) sc.frame.offset[0] << s; sc.frame.offset[1] << s; } + if (PROTO >= 6) [[likely]] + { + sc.frame.bbox_size[0] << s; + sc.frame.bbox_size[1] << s; + } + if (PROTO >= 7) [[likely]] + { + sc.frame.bbox_offset[0] << s; + sc.frame.bbox_offset[1] << s; + } if (sc.frame.active) { if (PROTO >= 4) [[likely]] diff --git a/serialize/world-writer.cpp b/serialize/world-writer.cpp index 2860a118..6d1a0e94 100644 --- a/serialize/world-writer.cpp +++ b/serialize/world-writer.cpp @@ -352,7 +352,11 @@ void writer_state::serialize_chunk(const chunk& c, chunk_coords coord) id |= meta_long_scenery_bit * sc_exact; id |= atlasid(scenery.r) << sizeof(atlasid)*8-1-rotation_BITS; s << id; - if (!sc_exact || !scenery.offset.isZero()) + if (constexpr struct scenery default_scenery; + !sc_exact || + scenery.offset != default_scenery.offset || + scenery.bbox_size != default_scenery.bbox_size || + scenery.bbox_offset != default_scenery.bbox_offset) { fm_assert(scenery.active || scenery.delta == 0); write_scenery_flags(s, scenery); @@ -363,6 +367,12 @@ void writer_state::serialize_chunk(const chunk& c, chunk_coords coord) s << scenery.offset[0]; s << scenery.offset[1]; + s << scenery.bbox_size[0]; + s << scenery.bbox_size[1]; + + s << scenery.bbox_offset[0]; + s << scenery.bbox_offset[1]; + if (scenery.active) s << scenery.delta; } diff --git a/src/chunk-bbox.cpp b/src/chunk-bbox.cpp index b951da10..291056a8 100644 --- a/src/chunk-bbox.cpp +++ b/src/chunk-bbox.cpp @@ -47,10 +47,8 @@ void chunk::ensure_passability() noexcept _lqt_view->Clear(); std::vector<collision_bbox> bboxes; -#ifndef FLOORMAT_64 _bboxes.clear(); bboxes.reserve(TILE_COUNT*4); -#endif constexpr auto whole_tile = [](std::size_t k, pass_mode p) constexpr -> collision_bbox { auto start = tile_start(k); @@ -84,18 +82,12 @@ void chunk::ensure_passability() noexcept bboxes.push_back(wall_west(i, p)); } -#ifndef FLOORMAT_64 _bboxes.reserve(bboxes.size()); -#endif for (const collision_bbox& bbox : bboxes) { -#ifdef FLOORMAT_64 - auto* ptr = std::bit_cast<compact_bb*>(collision_bbox::BB(bbox)); -#else _bboxes.push_back(bbox); auto* ptr = &_bboxes.back(); -#endif switch (bbox.pass_mode) { diff --git a/src/chunk.hpp b/src/chunk.hpp index 78412220..09af9bdb 100644 --- a/src/chunk.hpp +++ b/src/chunk.hpp @@ -23,11 +23,6 @@ template<typename Num, typename BB, typename BBE> struct collision_iterator; template<typename Num, typename BB, typename BBE> struct collision_query; struct collision_bbox; -#ifdef FLOORMAT_64 -struct compact_bb; -struct compact_bb_extractor; -#endif - enum class collision : std::uint8_t { view, shoot, move, }; @@ -93,13 +88,8 @@ struct chunk final void ensure_passability() noexcept; -#ifdef FLOORMAT_64 - using BB = compact_bb; - using BBE = compact_bb_extractor; -#else using BB = loose_quadtree::BoundingBox<std::int16_t>; using BBE = loose_quadtree::TrivialBBExtractor<std::int16_t>; -#endif using lqt = loose_quadtree::LooseQuadtree<std::int16_t, BB, BBE>; using Query = collision_query<std::int16_t, BB, BBE>; diff --git a/src/collision.cpp b/src/collision.cpp index 42ed2344..e2e4974d 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -3,12 +3,4 @@ namespace floormat { -#ifdef FLOORMAT_64 -void compact_bb_extractor::ExtractBoundingBox(compact_bb* object, BB* bbox) -{ - if constexpr(sizeof(void*) >= 8) - *bbox = std::bit_cast<loose_quadtree::BoundingBox<std::int16_t>>((void*)object); -} -#endif - } // namespace floormat diff --git a/src/collision.hpp b/src/collision.hpp index 20ebedb8..086369fb 100644 --- a/src/collision.hpp +++ b/src/collision.hpp @@ -5,16 +5,6 @@ namespace floormat { -#ifdef FLOORMAT_64 -struct compact_bb; - -struct compact_bb_extractor final -{ - using BB = loose_quadtree::BoundingBox<std::int16_t>; - [[maybe_unused]] static void ExtractBoundingBox(compact_bb* object, BB* bbox); -}; -#endif - template<typename Num, typename BB, typename BBE> struct collision_iterator final { diff --git a/src/scenery.cpp b/src/scenery.cpp index 848029da..1a6be03e 100644 --- a/src/scenery.cpp +++ b/src/scenery.cpp @@ -28,8 +28,6 @@ scenery_ref& scenery_ref::operator=(const scenery_proto& proto) noexcept scenery_ref::operator scenery_proto() const noexcept { return { atlas, frame }; } scenery_ref::operator bool() const noexcept { return atlas != nullptr; } -scenery::scenery() noexcept : scenery{none_tag_t{}} {} -scenery::scenery(none_tag_t) noexcept {} scenery::scenery(generic_tag_t, const anim_atlas& atlas, rotation r, frame_t frame, pass_mode pass, bool active, bool interactive) : frame{frame}, r{r}, type{scenery_type::generic}, diff --git a/src/scenery.hpp b/src/scenery.hpp index ca577bc6..9186f9cf 100644 --- a/src/scenery.hpp +++ b/src/scenery.hpp @@ -1,5 +1,6 @@ #pragma once #include "pass-mode.hpp" +#include "tile-defs.hpp" #include <cstdint> #include <memory> #include <type_traits> @@ -36,7 +37,7 @@ struct scenery final std::uint16_t delta = 0; frame_t frame = 0; - Vector2b offset; + Vector2b offset, bbox_size{iTILE_SIZE2/2}, bbox_offset; rotation r : 3 = rotation::N; scenery_type type : 3 = scenery_type::none; pass_mode passability : 2 = pass_mode::shoot_through; @@ -44,8 +45,8 @@ struct scenery final std::uint8_t closing : 1 = false; std::uint8_t interactive : 1 = false; - scenery() noexcept; - scenery(none_tag_t) noexcept; + constexpr scenery() noexcept; + constexpr scenery(none_tag_t) noexcept; scenery(generic_tag_t, const anim_atlas& atlas, rotation r, frame_t frame = 0, pass_mode passability = pass_mode::shoot_through, bool active = false, bool interactive = false); scenery(door_tag_t, const anim_atlas& atlas, rotation r, bool is_open = false); @@ -57,6 +58,9 @@ struct scenery final void update(float dt, const anim_atlas& anim); }; +constexpr scenery::scenery() noexcept : scenery{scenery::none_tag_t{}} {} +constexpr scenery::scenery(none_tag_t) noexcept {} + struct scenery_proto final { std::shared_ptr<anim_atlas> atlas; |