From 2618f4c486848c5e3b080eb77a0c0c143932240e Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 18 Mar 2023 13:22:31 +0100 Subject: fix few asserts --- src/character.cpp | 7 ++++++- src/entity.cpp | 9 +++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'src') 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(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(r) = new_r; const_cast(e_->c) = &c2; es.insert(it, std::move(e_)); return ret; -- cgit v1.2.3