CoriEngine
Loading...
Searching...
No Matches
AnimationPack.hpp
Go to the documentation of this file.
1#pragma once
4#include "Animation.hpp"
5#include "AnimationFrame.hpp"
6
7namespace Cori {
8 namespace World {
9 namespace Components {
10 namespace Entity {
11 class QuadAnimator;
12 }
13 }
14 }
15 namespace Graphics {
16 namespace Internal {
18 public:
19 AnimationData(const glm::u16vec2 frameSize, std::vector<AnimationFrame> frames) : m_FrameSize(frameSize), m_Frames(std::move(frames)) {}
20
21 glm::u16vec2 m_FrameSize;
22 std::vector<AnimationFrame> m_Frames;
23 };
24 }
25
82 class AnimationPack : public Profiling::Trackable<AnimationPack>, public std::enable_shared_from_this<AnimationPack>{
83 public:
93
97 class Descriptor {
98 public:
105 constexpr Descriptor(std::string name, std::filesystem::path jsonPath, const ConfigType type) noexcept
106 : m_JsonPath(std::move(jsonPath)),
107 m_ConfigType(type),
108 m_Name(std::move(name)),
109 m_RuntimeID(s_NextRuntimeID.fetch_add(1, std::memory_order_relaxed))
110 { }
111
112 using AssetType = AnimationPack;
113
114 [[nodiscard]] uint32_t GetRuntimeID() const { return m_RuntimeID; }
115
116 constexpr bool operator==(const Descriptor& other) const noexcept {
117 return m_RuntimeID == other.m_RuntimeID;
118 }
119
120 struct Hasher {
121 std::size_t operator()(const Descriptor& descriptor) const noexcept {
122 return std::hash<uint32_t>{}(descriptor.m_RuntimeID);
123 }
124 };
125
126 const std::filesystem::path m_JsonPath;
128 const std::string m_Name;
129
130 private:
131 const uint32_t m_RuntimeID{ 0 };
132 inline static std::atomic<uint32_t> s_NextRuntimeID{ 1 };
133 };
134
142 [[nodiscard]] static std::shared_ptr<AnimationPack> Create(const std::filesystem::path& jsonPath, ConfigType type, const std::string& name);
143
144 [[nodiscard]] Animation GetAnimation(const uint32_t index);
145
146 protected:
147 friend Animation;
149 std::vector<Internal::AnimationData> m_Animations;
150
151 std::variant<std::shared_ptr<SpriteAtlas>, std::shared_ptr<Texture2D>> m_TextureOrAtlas;
152
153 private:
154 friend AssetManager;
155 [[nodiscard]] static std::shared_ptr<AnimationPack> Create(const Descriptor& descriptor);
156 std::string m_Name;
157 protected:
159 private:
160 AnimationPack(std::vector<Internal::AnimationData> animations, const std::shared_ptr<SpriteAtlas>& spriteAtlas, std::string name, const ConfigType type);
161 AnimationPack(std::vector<Internal::AnimationData> animations, const std::shared_ptr<Texture2D>& spriteAtlas, std::string name, const ConfigType type);
162
163 AnimationPack();
164
165 bool m_Valid = false;
166 };
167 }
168}
AnimationPack Descriptor meant to be used with AssetManager only.
constexpr bool operator==(const Descriptor &other) const noexcept
constexpr Descriptor(std::string name, std::filesystem::path jsonPath, const ConfigType type) noexcept
Constructs a descriptor.
std::variant< std::shared_ptr< SpriteAtlas >, std::shared_ptr< Texture2D > > m_TextureOrAtlas
Animation GetAnimation(const uint32_t index)
ConfigType
Available animation pack config types.
std::vector< Internal::AnimationData > m_Animations
static std::shared_ptr< AnimationPack > Create(const std::filesystem::path &jsonPath, ConfigType type, const std::string &name)
Creates an AnimationPack.
AnimationData(const glm::u16vec2 frameSize, std::vector< AnimationFrame > frames)
std::vector< AnimationFrame > m_Frames
For InstanceMetrics to work with a type it should derive from this.
Definition Trackable.hpp:29
Responsible for playing animations when attached to an entity.
Almost everything connected to graphics is in this namespace.
Definition Window.hpp:7
Components designed to be used with entities.
Components that are used with the WorldSystem (ECS).
Anything connected to WorldSystem (ECS) is in this namespace.
Global engine namespace.
std::size_t operator()(const Descriptor &descriptor) const noexcept