diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-18 13:22:31 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-18 13:22:31 +0100 |
commit | 2618f4c486848c5e3b080eb77a0c0c143932240e (patch) | |
tree | 6f4f106f98f3fc73bc7de6ae7a96322079169dff | |
parent | db6e21d50d426d0745d844f3166da296a40435e9 (diff) |
fix few asserts
-rw-r--r-- | serialize/world-reader.cpp | 2 | ||||
-rw-r--r-- | src/character.cpp | 7 | ||||
-rw-r--r-- | src/entity.cpp | 9 |
3 files changed, 14 insertions, 4 deletions
diff --git a/serialize/world-reader.cpp b/serialize/world-reader.cpp index 58cd35ea..84958109 100644 --- a/serialize/world-reader.cpp +++ b/serialize/world-reader.cpp @@ -314,7 +314,7 @@ void reader_state::deserialize_world(ArrayView<const char> buf) read_sceneries(s); read_chunks(s); s.assert_end(); - if (proto >= 8) [[likely]] + if (PROTO >= 8) [[likely]] { fm_assert(_world->entity_counter() == 0); _world->set_entity_counter(entity_counter); diff --git a/src/character.cpp b/src/character.cpp index 9c69e061..94f0b7ac 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -52,11 +52,15 @@ constexpr auto arrows_to_dir(bool L, bool R, bool U, bool D) } // namespace character_proto::character_proto(const character_proto&) = default; -character_proto::character_proto() = default; character_proto::~character_proto() noexcept = default; character_proto& character_proto::operator=(const character_proto&) = default; character::~character() = default; +character_proto::character_proto() +{ + type = entity_type::character; +} + bool character_proto::operator==(const entity_proto& e0) const { if (type != e0.type) @@ -144,6 +148,7 @@ character::character(std::uint64_t id, struct chunk& c, entity_type type, const name = "(Unnamed)"_s; if (!atlas) atlas = loader.anim_atlas("npc-walk", loader.ANIM_PATH); + fm_assert(atlas->check_rotation(r)); entity::set_bbox_(offset, bbox_offset, Vector2ub(iTILE_SIZE2/2), pass); } diff --git a/src/entity.cpp b/src/entity.cpp index 4f0b8807..d06cf52a 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -20,8 +20,11 @@ entity::entity(std::uint64_t id, struct chunk& c, entity_type type, const entity frame{proto.frame}, type{type}, r{proto.r}, pass{proto.pass} { fm_assert(type == proto.type); - fm_assert(atlas->check_rotation(r)); - fm_assert(frame < atlas->info().nframes); + if (atlas) + { + fm_assert(atlas->check_rotation(r)); + fm_assert(frame < atlas->info().nframes); + } } entity::~entity() noexcept @@ -164,6 +167,7 @@ std::size_t entity::move(std::size_t i, Vector2i delta, rotation new_r) auto it_ = std::lower_bound(es.cbegin(), es.cend(), e_, [=](const auto& a, const auto&) { return a->ordinal() < ord; }); e_->coord = coord_; set_bbox_(offset_, bb_offset, bb_size, pass); + const_cast<rotation&>(r) = new_r; auto pos1 = std::distance(es.cbegin(), it_); if ((std::size_t)pos1 > i) pos1--; @@ -189,6 +193,7 @@ std::size_t entity::move(std::size_t i, Vector2i delta, rotation new_r) auto ret = (std::size_t)std::distance(es.cbegin(), it); e_->coord = coord_; set_bbox_(offset_, bb_offset, bb_size, pass); + const_cast<rotation&>(r) = new_r; const_cast<struct chunk*&>(e_->c) = &c2; es.insert(it, std::move(e_)); return ret; |