diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-16 09:07:00 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-17 23:23:11 +0100 |
commit | a1df7c84a5c49adb3b8e8cd3796fd53a02684dd5 (patch) | |
tree | 0e29449992a851fdb4c16628db8f1ea81c078308 | |
parent | fd9298ef43136fa89dab034096690a08027ebf44 (diff) |
a
-rw-r--r-- | src/entity.cpp | 25 | ||||
-rw-r--r-- | src/entity.hpp | 3 |
2 files changed, 22 insertions, 6 deletions
diff --git a/src/entity.cpp b/src/entity.cpp index 09d4dfe2..e7d2398b 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -43,20 +43,35 @@ entity::~entity() noexcept w.do_kill_entity(id); } +Vector2b entity::ordinal_offset_for_type(entity_type type, Vector2b offset) +{ + switch (type) + { + case entity_type::scenery: + return offset; + default: + fm_warn_once("unknown entity type '%zu'", std::size_t(type)); + [[fallthrough]]; + case entity_type::character: + return {}; + } +} + std::int32_t entity_proto::ordinal(local_coords local) const { - return entity::ordinal(local, offset); + return entity::ordinal(local, offset, type); } std::int32_t entity::ordinal() const { - return ordinal(coord.local(), offset); + return ordinal(coord.local(), offset, type); } -std::int32_t entity::ordinal(local_coords xy, Vector2b offset) +std::int32_t entity::ordinal(local_coords xy, Vector2b offset, entity_type type) { + offset = ordinal_offset_for_type(type, offset); constexpr auto x_size = (std::int32_t)TILE_MAX_DIM * (std::int32_t)iTILE_SIZE[0]; - auto vec = Vector2i(xy) * Vector2i(iTILE_SIZE2) + Vector2i(offset); + auto vec = Vector2i(xy) * Vector2i(iTILE_SIZE2); return vec[1] * x_size + vec[0]; } @@ -157,7 +172,7 @@ void entity::move(It it, Vector2i delta) chunk::bbox bb0, bb1; bool b0 = c._bbox_for_scenery(e, bb0), b1 = c._bbox_for_scenery(e, coord_.local(), offset_, bb1); - const auto ord = e.ordinal(coord_.local(), offset_); + const auto ord = e.ordinal(coord_.local(), offset_, e.type); if (coord_.chunk() == coord.chunk()) { diff --git a/src/entity.hpp b/src/entity.hpp index a0a6ed53..522ef8b6 100644 --- a/src/entity.hpp +++ b/src/entity.hpp @@ -51,8 +51,9 @@ struct entity virtual ~entity() noexcept; + static Vector2b ordinal_offset_for_type(entity_type type, Vector2b offset); std::int32_t ordinal() const; - static std::int32_t ordinal(local_coords xy, Vector2b offset); + static std::int32_t ordinal(local_coords xy, Vector2b offset, entity_type type); struct chunk& chunk() const; It iter() const; |