88
99#include < gf2/core/AnimationData.h>
1010#include < gf2/core/Flags.h>
11+ #include < gf2/core/Id.h>
1112#include < gf2/core/Rect.h>
1213#include < gf2/core/Time.h>
1314
1415#include " Buffer.h"
1516#include " GraphicsApi.h"
1617#include " RenderObject.h"
17-
18- #include " gf2/core/Id.h"
18+ #include " AnimationRuntime.h"
1919
2020namespace gf {
2121 class Texture ;
2222 class RenderManager ;
2323 class ResourceManager ;
2424
25- struct GF_GRAPHICS_API AnimationFrameRuntime {
26- std::size_t texture_index = 0 ;
27- Time duration;
28- std::size_t offset = 0 ;
29- };
30-
31- struct GF_GRAPHICS_API AnimationRuntime {
32- Flags<AnimationProperties> properties = None;
33- std::vector<AnimationFrameRuntime> frames;
34- };
35-
36- class GF_GRAPHICS_API Animation {
25+ class GF_GRAPHICS_API AnimationState {
3726 public:
38- Animation (std::vector<const Texture*> textures, const AnimationData& data, RenderManager* render_manager);
39- Animation (const AnimationResource& resource, RenderManager* render_manager, ResourceManager* resource_manager);
27+ AnimationState (const AnimationData& data);
4028
4129 void update (Time time);
4230 void reset ();
4331 bool finished () const ;
4432
45- RenderGeometry geometry () const ;
33+ std::size_t current_frame () const
34+ {
35+ return m_current_frame;
36+ }
37+
38+ private:
39+ details::AnimationStateRuntime m_animation;
40+ std::size_t m_current_frame = 0 ;
41+ Time m_current_time;
42+ };
43+
44+
45+ class GF_GRAPHICS_API AnimationGraphics {
46+ public:
47+ AnimationGraphics (std::vector<const Texture*> textures, const AnimationData& data, RenderManager* render_manager);
48+ AnimationGraphics (const AnimationResource& resource, RenderManager* render_manager, ResourceManager* resource_manager);
49+
50+ RenderGeometry geometry (std::size_t frame_index) const ;
4651
4752 RectF bounds () const
4853 {
@@ -54,44 +59,44 @@ namespace gf {
5459 Buffer m_vertices;
5560 Buffer m_indices;
5661 RectF m_bounds = RectF::from_size({ 0 .0f , 0 .0f });
57-
58- AnimationRuntime m_animation;
59- std::size_t m_current_frame = 0 ;
60- Time m_current_time;
62+ details::AnimationGraphicsRuntime m_animation;
6163 };
6264
63- class GF_GRAPHICS_API AnimationGroup {
65+ class GF_GRAPHICS_API Animation {
6466 public:
65- AnimationGroup (std::vector<const Texture*> textures, const AnimationGroupData & data, RenderManager* render_manager);
66- AnimationGroup (const AnimationGroupResource & resource, RenderManager* render_manager, ResourceManager* resource_manager);
67+ Animation (std::vector<const Texture*> textures, const AnimationData & data, RenderManager* render_manager);
68+ Animation (const AnimationResource & resource, RenderManager* render_manager, ResourceManager* resource_manager);
6769
68- void select (std::string_view animation_name);
69- void select (Id animation_id);
70+ void update (Time time)
71+ {
72+ m_state.update (time);
73+ }
7074
71- void update (Time time);
72- void reset ();
73- bool finished () const ;
75+ void reset ()
76+ {
77+ m_state.reset ();
78+ }
7479
75- RenderGeometry geometry () const ;
80+ bool finished () const
81+ {
82+ return m_state.finished ();
83+ }
84+
85+ RenderGeometry geometry () const
86+ {
87+ return m_graphics.geometry (m_state.current_frame ());
88+ }
7689
7790 RectF bounds () const
7891 {
79- return m_bounds ;
92+ return m_graphics. bounds () ;
8093 }
8194
8295 private:
83- const AnimationRuntime* current_animation () const ;
84-
85- std::vector<const Texture*> m_textures;
86- Buffer m_vertices;
87- Buffer m_indices;
88- RectF m_bounds = RectF::from_size({ 0 .0f , 0 .0f });
89-
90- std::map<Id, AnimationRuntime> m_animations;
91- Id m_current_animation_id = InvalidId;
92- std::size_t m_current_frame = 0 ;
93- Time m_current_time;
96+ AnimationState m_state;
97+ AnimationGraphics m_graphics;
9498 };
99+
95100}
96101
97102#endif // GF_ANIMATION_H
0 commit comments