diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-21 10:53:32 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-21 10:53:49 +0100 |
commit | 15bbfc100a79a975f6024d6e2e6522c4e91f2cb5 (patch) | |
tree | 1fa630728c14b0973a042b50ec712f1303b82eff /src | |
parent | 5dbee173b961792b42596cb792a50624555cc41b (diff) |
src, draw: work on depth and z offsets
Diffstat (limited to 'src')
-rw-r--r-- | src/anim.hpp | 2 | ||||
-rw-r--r-- | src/character.cpp | 2 | ||||
-rw-r--r-- | src/character.hpp | 1 | ||||
-rw-r--r-- | src/chunk-collision.cpp | 2 | ||||
-rw-r--r-- | src/entity.cpp | 2 | ||||
-rw-r--r-- | src/entity.hpp | 3 | ||||
-rw-r--r-- | src/rotation.inl | 11 | ||||
-rw-r--r-- | src/scenery.cpp | 27 | ||||
-rw-r--r-- | src/scenery.hpp | 1 |
9 files changed, 36 insertions, 15 deletions
diff --git a/src/anim.hpp b/src/anim.hpp index 4b7b6bc8..6264a070 100644 --- a/src/anim.hpp +++ b/src/anim.hpp @@ -25,8 +25,8 @@ struct anim_group final String name, mirror_from; std::vector<anim_frame> frames; Vector2ui ground; // for use in anim-crop-tool only + Vector2s z_offset; Vector3b offset; - Vector2b z_offset; }; enum class anim_scale_type : unsigned char { invalid, ratio, fixed, }; diff --git a/src/character.cpp b/src/character.cpp index f43c976b..08de4e99 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -96,6 +96,8 @@ void character::set_keys(bool L, bool R, bool U, bool D) b_D = D; } +Vector2 character::depth_offset() const { return {}; } + Vector2 character::ordinal_offset(Vector2b offset) const { return Vector2(offset); diff --git a/src/character.hpp b/src/character.hpp index f39b14ae..560640b9 100644 --- a/src/character.hpp +++ b/src/character.hpp @@ -29,6 +29,7 @@ struct character final : entity bool update(size_t i, float dt) override; void set_keys(bool L, bool R, bool U, bool D); Vector2 ordinal_offset(Vector2b offset) const override; + Vector2 depth_offset() const override; String name; Vector2s offset_frac; diff --git a/src/chunk-collision.cpp b/src/chunk-collision.cpp index b233a112..5e0c7a94 100644 --- a/src/chunk-collision.cpp +++ b/src/chunk-collision.cpp @@ -44,7 +44,7 @@ constexpr Pair<Vector2, Vector2> wall_west(size_t k) return { min, min + Vector2(2, TILE_SIZE2[1]), }; } -constexpr object_id make_id(collision_type type, pass_mode p, uint64_t id) +constexpr object_id make_id(collision_type type, pass_mode p, object_id id) { return std::bit_cast<object_id>(collision_data { (object_id)type, (object_id)p, id }); } diff --git a/src/entity.cpp b/src/entity.cpp index 1b54117d..ff0f77a9 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -51,7 +51,7 @@ float entity::ordinal() const return ordinal(coord.local(), offset, atlas->group(r).z_offset); } -float entity::ordinal(local_coords xy, Vector2b offset, Vector2b z_offset) const +float entity::ordinal(local_coords xy, Vector2b offset, Vector2s z_offset) const { constexpr auto inv_tile_size = 1.f/TILE_SIZE2; constexpr float width = TILE_MAX_DIM+1; diff --git a/src/entity.hpp b/src/entity.hpp index f2f6c65b..cb5eea3b 100644 --- a/src/entity.hpp +++ b/src/entity.hpp @@ -53,8 +53,9 @@ struct entity virtual ~entity() noexcept; virtual Vector2 ordinal_offset(Vector2b offset) const = 0; + virtual Vector2 depth_offset() const = 0; float ordinal() const; - float ordinal(local_coords xy, Vector2b offset, Vector2b z_offset) const; + float ordinal(local_coords xy, Vector2b offset, Vector2s z_offset) const; struct chunk& chunk() const; size_t index() const; diff --git a/src/rotation.inl b/src/rotation.inl index fb5cefca..4ddf1153 100644 --- a/src/rotation.inl +++ b/src/rotation.inl @@ -23,14 +23,17 @@ constexpr Triple<Vector2b, Vector2ub, Vector2ub> rotation_symmetry(rotation r) return sym; } -constexpr Vector2b rotate_point(Vector2b rect, rotation r_old, rotation r_new) +template<typename T> using Vec2 = Math::Vector2<T>; + +template<typename T> +constexpr Vec2<T> rotate_point(Vec2<T> rect, rotation r_old, rotation r_new) { fm_assert(r_old < rotation_COUNT && r_new < rotation_COUNT); auto [m_offset0, i_offset0, i_size0] = rotation_symmetry(r_old); - auto offset0_ = rect * m_offset0; - auto offset_n = Vector2b(offset0_[i_offset0[0]], offset0_[i_offset0[1]]); + auto offset0_ = rect * Vec2<T>(m_offset0); + auto offset_n = Vec2<T>(offset0_[i_offset0[0]], offset0_[i_offset0[1]]); auto [m_offset1, i_offset1, i_size1] = rotation_symmetry(r_new); - return Vector2b{offset_n[i_offset1[0]], offset_n[i_offset1[1]]}*m_offset1; + return Vec2<T>{offset_n[i_offset1[0]], offset_n[i_offset1[1]]}*Vec2<T>{m_offset1}; } constexpr Vector2ub rotate_size(Vector2ub size0, rotation r_old, rotation r_new) diff --git a/src/scenery.cpp b/src/scenery.cpp index 3253f623..892104c2 100644 --- a/src/scenery.cpp +++ b/src/scenery.cpp @@ -77,15 +77,28 @@ Vector2 scenery::ordinal_offset(Vector2b offset) const { if (sc_type == scenery_type::door) { - constexpr auto vec0 = Vector2b(-iTILE_SIZE2[0], -iTILE_SIZE[1]/2+1); - constexpr auto vec1 = Vector2b(0, -iTILE_SIZE[1]/2+1); - const auto vec0_ = rotate_point(vec0, rotation::N, r); - const auto vec1_ = rotate_point(vec1, rotation::N, r); - const auto vec = frame == 0 ? vec0_ : vec1_; + constexpr auto off_closed_ = Vector2b(0, -iTILE_SIZE[1]/2+2); + constexpr auto off_opened_ = Vector2b(-iTILE_SIZE[0]+2, -iTILE_SIZE[1]/2+2); + const auto off_closed = rotate_point(off_closed_, rotation::N, r); + const auto off_opened = rotate_point(off_opened_, rotation::N, r); + const auto vec = frame == atlas->info().nframes-1 ? off_closed : off_opened; return Vector2(offset) + Vector2(vec); } - else - return Vector2(offset); + return Vector2(offset); +} + +Vector2 scenery::depth_offset() const +{ + constexpr auto inv_tile_size = 1.f/TILE_SIZE2; + Vector2 ret; + if (sc_type == scenery_type::door) + { + constexpr auto door_offset = Vector2b(-iTILE_SIZE[0], 0); + const auto offset = rotate_point(door_offset, rotation::N, r); + ret += Vector2(offset); + } + ret += Vector2(atlas->group(r).z_offset); + return ret * inv_tile_size; } bool scenery::activate(size_t) diff --git a/src/scenery.hpp b/src/scenery.hpp index f7cf3ed7..00ae28f9 100644 --- a/src/scenery.hpp +++ b/src/scenery.hpp @@ -43,6 +43,7 @@ struct scenery final : entity bool update(size_t i, float dt) override; Vector2 ordinal_offset(Vector2b offset) const override; + Vector2 depth_offset() const override; bool can_activate(size_t i) const override; bool activate(size_t i) override; |