FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
anim_manager.hpp
1/*
2 * Copyright 2024 Guillaume Guillet
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _FGE_ANIM_MANAGER_HPP_INCLUDED
18#define _FGE_ANIM_MANAGER_HPP_INCLUDED
19
20#include "FastEngine/fge_extern.hpp"
21
22#include "FastEngine/C_vector.hpp"
23#include "FastEngine/manager/C_baseManager.hpp"
24#include "FastEngine/textureType.hpp"
25#include <vector>
26
27#define FGE_ANIM_DEFAULT_TICKS 100
28
29#define FGE_ANIM_BAD FGE_MANAGER_BAD
30
31namespace fge::anim
32{
33
44
51{
52 std::shared_ptr<fge::TextureType> _texture;
53 std::filesystem::path _path;
54 fge::Vector2u _texturePosition;
55
56 uint32_t _ticks;
57};
58
65{
66 std::vector<AnimationFrame> _frames;
67 std::string _groupName;
68};
69
76{
77 std::vector<AnimationGroup> _groups;
78
81 std::shared_ptr<TextureType> _tilesetTexture;
82 std::filesystem::path _tilesetPath;
83};
84
85struct DataBlock : manager::BaseDataBlock<AnimationData>
86{};
87
95class FGE_API AnimationManager : public manager::BaseManager<AnimationData, DataBlock>
96{
97public:
98 using BaseManager::BaseManager;
99
100 bool initialize() override;
101 [[nodiscard]] bool isInitialized() override;
102 void uninitialize() override;
103
139 bool loadFromFile(std::string_view name, std::filesystem::path const& path);
140};
141
146FGE_API extern AnimationManager gManager;
147
148} // namespace fge::anim
149
150#endif // _FGE_ANIM_MANAGER_HPP_INCLUDED
Manage animations.
Definition anim_manager.hpp:96
bool loadFromFile(std::string_view name, std::filesystem::path const &path)
Load the animation with the given name from the given file path.
bool initialize() override
Initialize the manager.
Base class for all managers.
Definition C_baseManager.hpp:63
AnimationType
Enum that represent different way of loading an animation.
Definition anim_manager.hpp:40
@ ANIM_TYPE_SEPARATE_FILES
Separate files, every frame is in a different file.
@ ANIM_TYPE_TILESET
Tileset type, you have just one texture with multiple frame in it.
FGE_API AnimationManager gManager
The global animation manager.
Structure that contains the information of an animation.
Definition anim_manager.hpp:76
std::shared_ptr< TextureType > _tilesetTexture
The tileset texture, only useful if the type is ANIM_TYPE_TILESET.
Definition anim_manager.hpp:81
std::vector< AnimationGroup > _groups
The vector of groups of the animation.
Definition anim_manager.hpp:77
Vector2u _tilesetGridSize
The tileset grid size, only useful if the type is ANIM_TYPE_TILESET.
Definition anim_manager.hpp:80
std::filesystem::path _tilesetPath
The tileset texture path, only useful if the type is ANIM_TYPE_TILESET.
Definition anim_manager.hpp:82
AnimationType _type
The type of the animation.
Definition anim_manager.hpp:79
Structure that contains the information of a frame of an animation.
Definition anim_manager.hpp:51
fge::Vector2u _texturePosition
The tileset grid position, only useful if the type is ANIM_TYPE_TILESET.
Definition anim_manager.hpp:54
std::filesystem::path _path
The file path of the texture.
Definition anim_manager.hpp:53
uint32_t _ticks
The number of ticks that the frame will be displayed, by default 1 tick take 100 ms.
Definition anim_manager.hpp:56
std::shared_ptr< fge::TextureType > _texture
The shared pointer texture of the frame.
Definition anim_manager.hpp:52
Structure that contains the information of a group of frames of an animation.
Definition anim_manager.hpp:65
std::vector< AnimationFrame > _frames
The vector of frames of the group.
Definition anim_manager.hpp:66
std::string _groupName
The name of the group.
Definition anim_manager.hpp:67
Definition anim_manager.hpp:86
Definition C_baseManager.hpp:42