FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
fge::anim::AnimationManager Class Reference

Manage animations. More...

#include <anim_manager.hpp>

Inheritance diagram for fge::anim::AnimationManager:
fge::manager::BaseManager< AnimationData, DataBlock >

Public Types

using DataType
 
using DataBlockType
 
using DataBlockPointer
 
using Map
 

Public Member Functions

bool initialize () override
 Initialize the manager.
 
bool isInitialized () override
 
void uninitialize () override
 
bool loadFromFile (std::string_view name, std::filesystem::path const &path)
 Load the animation with the given name from the given file path.
 
std::size_t size () const
 Get the number of elements in the manager.
 
AccessLock< std::mutex > acquireLock () const
 Acquire a AccessLock, with the manager mutex.
 
Map::const_iterator begin (AccessLock< std::mutex > const &lock) const
 Get the "begin" iterator of the manager.
 
Map::const_iterator end (AccessLock< std::mutex > const &lock) const
 Get the "end" iterator of the manager.
 
DataBlockPointer const & getBadElement () const
 Get the "bad" element.
 
DataBlockPointer getElement (std::string_view name) const
 Get the resource with the given name.
 
bool contains (std::string_view name) const
 
bool unload (std::string_view name)
 
void unloadAll ()
 
bool push (std::string_view name, DataBlockPointer block)
 Add a user handled resource.
 

Protected Attributes

DataBlockPointer _g_badElement
 

Detailed Description

Manage animations.

See also
TextureManager

Member Function Documentation

◆ acquireLock()

AccessLock< std::mutex > fge::manager::BaseManager< AnimationData, DataBlock >::acquireLock ( ) const
nodiscardinherited

Acquire a AccessLock, with the manager mutex.

In order to use iterators, you have to acquire a unique lock from this function. The lock is not differed and will lock the mutex.

Returns
A AccessLock bound to this mutex

◆ begin()

BaseManager< AnimationData, DataBlock >::Map::const_iterator fge::manager::BaseManager< AnimationData, DataBlock >::begin ( AccessLock< std::mutex > const & lock) const
nodiscardinherited

Get the "begin" iterator of the manager.

You have to provide a valid reference to a AccessLock acquired with the function AcquireLock(). This function will throw if one of this is not respected :

  • The mutex pointer of the lock does not correspond to this mutex.
Parameters
lockA AccessLock bound to this mutex
Returns
The "begin" iterator of the texture manager

◆ end()

BaseManager< AnimationData, DataBlock >::Map::const_iterator fge::manager::BaseManager< AnimationData, DataBlock >::end ( AccessLock< std::mutex > const & lock) const
nodiscardinherited

Get the "end" iterator of the manager.

See also
begin()
Parameters
lockA AccessLock bound to this mutex
Returns
The "end" iterator of the manager

◆ getBadElement()

BaseManager< AnimationData, DataBlock >::DataBlockPointer const & fge::manager::BaseManager< AnimationData, DataBlock >::getBadElement ( ) const
nodiscardinherited

Get the "bad" element.

A bad element is a "valid" default resource that is returned when the requested resource is not found. return The "bad" element

◆ getElement()

BaseManager< AnimationData, DataBlock >::DataBlockPointer fge::manager::BaseManager< AnimationData, DataBlock >::getElement ( std::string_view name) const
nodiscardinherited

Get the resource with the given name.

Parameters
nameThe name of the resource to get
Returns
The resource with the given name or the bad resource if not found

◆ initialize()

bool fge::anim::AnimationManager::initialize ( )
overridevirtual

Initialize the manager.

The philosophy with this class is to always return a "valid" element even if the element is not found. When this method is called, a "bad" element is created and stored in the manager.

Warning
Note that there is no verification about the above statement, and you can always create your own manager without a "bad" element.

return true if the manager is initialized, false otherwise

Implements fge::manager::BaseManager< AnimationData, DataBlock >.

◆ isInitialized()

bool fge::anim::AnimationManager::isInitialized ( )
nodiscardoverridevirtual

◆ loadFromFile()

bool fge::anim::AnimationManager::loadFromFile ( std::string_view name,
std::filesystem::path const & path )

Load the animation with the given name from the given file path.

The specified file must be a valid json file that contains the information of the animation and its groups.

Here is an example of a valid json file:

{
"type": "tileset" or "separate",
"gridSize": {"x": 32, "y": 32}, (not necessary if the type is separate)
"tileset": "test/tileset_test.png", (not necessary if the type is separate)
"animationGroup1": [
{
"path": "path/to/the/texture1", (not necessary if the type is tileset)
"ticks": 10,
"position": {"x": 0, "y": 0} (not necessary if the type is separate)
},
{
"path": "path/to/the/texture2", (not necessary if the type is tileset)
"ticks": 10,
"position": {"x": 1, "y": 0} (not necessary if the type is separate)
}
],
"animationGroup2": [
...
]
}
Parameters
nameThe name of the animation to load
pathThe file path of the animation to load
Returns
true if the animation is loaded, false otherwise

◆ push()

bool fge::manager::BaseManager< AnimationData, DataBlock >::push ( std::string_view name,
DataBlockPointer block )
inherited

Add a user handled resource.

Parameters
nameThe name of the texture to add
blockThe block data to add
Returns
true if the resource was added, false otherwise

◆ size()

std::size_t fge::manager::BaseManager< AnimationData, DataBlock >::size ( ) const
nodiscardinherited

Get the number of elements in the manager.

return The number of elements in the manager without the "bad" element

◆ uninitialize()

void fge::anim::AnimationManager::uninitialize ( )
overridevirtual

The documentation for this class was generated from the following file: