diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/anim-atlas.cpp | 24 | ||||
| -rw-r--r-- | src/anim-atlas.hpp | 15 | ||||
| -rw-r--r-- | src/anim.cpp | 0 | ||||
| -rw-r--r-- | src/anim.hpp | 41 |
4 files changed, 60 insertions, 20 deletions
diff --git a/src/anim-atlas.cpp b/src/anim-atlas.cpp index 47490246..c874150e 100644 --- a/src/anim-atlas.cpp +++ b/src/anim-atlas.cpp @@ -9,7 +9,7 @@ namespace floormat { static constexpr const char* name_array[] = { "n", "ne", "e", "se", "s", "sw", "w", "nw", }; -std::uint8_t anim_atlas::rotation_to_index(const anim_info& info, rotation r) noexcept +std::uint8_t anim_atlas::rotation_to_index(const anim_def& info, rotation r) noexcept { StringView str = name_array[std::size_t(r)]; for (std::size_t sz = info.groups.size(), i = 0; i < sz; i++) @@ -21,7 +21,7 @@ std::uint8_t anim_atlas::rotation_to_index(const anim_info& info, rotation r) no return 0xff; } -decltype(anim_atlas::_group_indices) anim_atlas::make_group_indices(const anim_info& a) noexcept +decltype(anim_atlas::_group_indices) anim_atlas::make_group_indices(const anim_def& a) noexcept { std::array<std::uint8_t, (std::size_t)rotation::COUNT> array; for (std::size_t i = 0; i < array.size(); i++) @@ -30,7 +30,7 @@ decltype(anim_atlas::_group_indices) anim_atlas::make_group_indices(const anim_i } anim_atlas::anim_atlas() noexcept = default; -anim_atlas::anim_atlas(StringView name, const ImageView2D& image, anim_info info) noexcept : +anim_atlas::anim_atlas(StringView name, const ImageView2D& image, anim_def info) noexcept : _name{name}, _info{std::move(info)}, _group_indices{make_group_indices(_info)} { @@ -49,7 +49,7 @@ anim_atlas& anim_atlas::operator=(anim_atlas&&) noexcept = default; StringView anim_atlas::name() const noexcept { return _name; } GL::Texture2D& anim_atlas::texture() noexcept { return _tex; } -const Serialize::anim& anim_atlas::info() const noexcept { return _info; } +const anim_def& anim_atlas::info() const noexcept { return _info; } auto anim_atlas::group(rotation r) const noexcept -> const anim_group& { @@ -81,20 +81,22 @@ auto anim_atlas::texcoords_for_frame(rotation r, std::size_t i) const noexcept - auto anim_atlas::frame_quad(const Vector3& center, rotation r, std::size_t i) const noexcept -> quad { + enum : std::size_t { x, y, z }; + const auto g = group(r); const auto f = frame(r, i); const auto size = Vector2d(f.size); - const auto gx = (float)f.ground[0]*.5f, gy = (float)f.ground[1]*.5f; - const auto sx = (float)size[0]*.5f, sy = (float)size[1]*.5f; + const auto gx = (float)f.ground[x]*.5f, gy = (float)f.ground[y]*.5f; + const auto sx = (float)size[x]*.5f, sy = (float)size[y]*.5f; const auto bottom_right = tile_shader::unproject({ sx - gx, sy - gy }), top_right = tile_shader::unproject({ sx - gx, - gy }), bottom_left = tile_shader::unproject({ - gx, sy - gy }), top_left = tile_shader::unproject({ - gx, - gy }); - const auto cx = center[0], cy = center[1], cz = center[2]; + const auto cx = center[x] + g.offset[x], cy = center[y] + g.offset[y], cz = center[z]; return {{ - { cx + bottom_right[0], cy + bottom_right[1], cz }, - { cx + top_right[0], cy + top_right[1], cz }, - { cx + bottom_left[0], cy + bottom_left[1], cz }, - { cx + top_left[0], cy + top_left[1], cz }, + { cx + bottom_right[x], cy + bottom_right[y], cz }, + { cx + top_right[x], cy + top_right[y], cz }, + { cx + bottom_left[x], cy + bottom_left[y], cz }, + { cx + top_left[x], cy + top_left[y], cz }, }}; } diff --git a/src/anim-atlas.hpp b/src/anim-atlas.hpp index d05bbe77..36939f68 100644 --- a/src/anim-atlas.hpp +++ b/src/anim-atlas.hpp @@ -1,7 +1,7 @@ #pragma once #include "compat/defs.hpp" #include "scenery.hpp" -#include "serialize/anim.hpp" +#include "anim.hpp" #include <array> #include <Corrade/Containers/String.h> #include <Magnum/Math/Vector2.h> @@ -12,14 +12,11 @@ namespace floormat { struct anim_atlas final { - using anim_info = Serialize::anim; - using anim_group = Serialize::anim_group; - using anim_frame = Serialize::anim_frame; using texcoords = std::array<Vector2, 4>; using quad = std::array<Vector3, 4>; anim_atlas() noexcept; - anim_atlas(StringView name, const ImageView2D& tex, anim_info info) noexcept; + anim_atlas(StringView name, const ImageView2D& tex, anim_def info) noexcept; ~anim_atlas() noexcept; anim_atlas(anim_atlas&&) noexcept; @@ -27,7 +24,7 @@ struct anim_atlas final StringView name() const noexcept; GL::Texture2D& texture() noexcept; - const anim_info& info() const noexcept; + const anim_def& info() const noexcept; const anim_group& group(rotation r) const noexcept; const anim_frame& frame(rotation r, std::size_t frame) const noexcept; @@ -39,13 +36,13 @@ struct anim_atlas final private: GL::Texture2D _tex; String _name; - anim_info _info; + anim_def _info; std::array<std::uint8_t, (std::size_t)rotation::COUNT> _group_indices = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }; - static decltype(_group_indices) make_group_indices(const Serialize::anim& anim) noexcept; - static std::uint8_t rotation_to_index(const anim_info& a, rotation r) noexcept; + static decltype(_group_indices) make_group_indices(const anim_def& anim) noexcept; + static std::uint8_t rotation_to_index(const anim_def& a, rotation r) noexcept; }; } // namespace floormat diff --git a/src/anim.cpp b/src/anim.cpp new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/src/anim.cpp diff --git a/src/anim.hpp b/src/anim.hpp new file mode 100644 index 00000000..771df5d7 --- /dev/null +++ b/src/anim.hpp @@ -0,0 +1,41 @@ +#pragma once + +#include "compat/integer-types.hpp" +#include <vector> +#include <Corrade/Containers/String.h> +#include <Magnum/Magnum.h> +#include <Magnum/Math/Vector2.h> + +namespace floormat { + +struct anim_frame final +{ + Vector2i ground; + Vector2ui offset, size; +}; + +enum class anim_direction : unsigned char +{ + N, NE, E, SE, S, SW, W, NW, + COUNT, +}; + +struct anim_group final +{ + String name; + std::vector<anim_frame> frames; + Vector2ui ground; + Vector2b offset; +}; + +struct anim_def final +{ + static constexpr int default_fps = 24; + + String object_name, anim_name; + std::vector<anim_group> groups; + Vector2ui pixel_size; + std::size_t nframes = 0, width = 0, height = 0, fps = default_fps, actionframe = 0; +}; + +} // namespace floormat |
