Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
AnimationManager.h
Go to the documentation of this file.
1/*
2Olympe Engine V2 2025
3Animation System - Animation Manager
4
5Purpose:
6- Singleton manager for loading and caching animation banks and graphs
7- Provides centralized access to animation resources
8- Integrates with DataManager for texture loading
9*/
10
11#pragma once
12
13#include "AnimationBank.h"
14#include "AnimationGraph.h"
15#include <string>
16#include <unordered_map>
17#include <memory>
18
19namespace OlympeAnimation
20{
21 // ========================================================================
22 // AnimationManager - Singleton for managing animation resources
23 // ========================================================================
25 {
26 public:
27 // Singleton access
29 {
31 return instance;
32 }
33 static AnimationManager& Get() { return GetInstance(); }
34
35 // Initialize the manager
36 void Init();
37
38 // Load animation banks from a directory
39 void LoadAnimationBanks(const std::string& directoryPath);
40
41 // Load animation graphs from a directory
42 void LoadAnimationGraphs(const std::string& directoryPath);
43
44 // Load a specific animation bank
45 bool LoadAnimationBank(const std::string& filePath);
46
47 // Load a specific animation graph
48 bool LoadAnimationGraph(const std::string& filePath);
49
50 // Get animation bank by name
51 AnimationBank* GetBank(const std::string& bankName);
52 const AnimationBank* GetBank(const std::string& bankName) const;
53
54 // Get animation graph by name
55 AnimationGraph* GetGraph(const std::string& graphName);
56 const AnimationGraph* GetGraph(const std::string& graphName) const;
57
58 /**
59 * @brief Get animation sequence from a bank by name
60 * @param bankId Animation bank identifier
61 * @param animName Animation name within the bank
62 * @return Pointer to AnimationSequence if found, nullptr otherwise
63 *
64 * Helper function to avoid manual bank lookup + animation lookup.
65 *
66 * Example:
67 * @code
68 * auto* seq = AnimationManager::Get().GetAnimationSequence("player", "walk");
69 * if (seq) {
70 * // Use sequence
71 * }
72 * @endcode
73 */
74 const Olympe::AnimationSequence* GetAnimationSequence(const std::string& bankId, const std::string& animName) const;
75
76 /**
77 * @brief Check if animation exists in bank
78 * @param bankId Bank identifier
79 * @param animName Animation name
80 * @return true if animation exists
81 */
82 bool HasAnimation(const std::string& bankId, const std::string& animName) const;
83
84 // Shutdown and cleanup
85 void Shutdown();
86
87 private:
88 AnimationManager() = default;
89 ~AnimationManager() = default;
90
91 // Delete copy constructor and assignment operator (singleton)
94
95 bool m_initialized = false;
96
97 std::unordered_map<std::string, std::unique_ptr<AnimationBank>> m_banks;
98 std::unordered_map<std::string, std::unique_ptr<AnimationGraph>> m_graphs;
99
100 // Helper: Scan directory for JSON files
101 std::vector<std::string> ScanDirectory(const std::string& directoryPath);
102 };
103
104} // namespace OlympeAnimation
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
bool LoadAnimationGraph(const std::string &filePath)
static AnimationManager & Get()
std::vector< std::string > ScanDirectory(const std::string &directoryPath)
AnimationGraph * GetGraph(const std::string &graphName)
AnimationManager & operator=(const AnimationManager &)=delete
void LoadAnimationGraphs(const std::string &directoryPath)
const Olympe::AnimationSequence * GetAnimationSequence(const std::string &bankId, const std::string &animName) const
Get animation sequence from a bank by name.
AnimationBank * GetBank(const std::string &bankName)
bool HasAnimation(const std::string &bankId, const std::string &animName) const
Check if animation exists in bank.
void LoadAnimationBanks(const std::string &directoryPath)
static AnimationManager & GetInstance()
AnimationManager(const AnimationManager &)=delete
std::unordered_map< std::string, std::unique_ptr< AnimationBank > > m_banks
std::unordered_map< std::string, std::unique_ptr< AnimationGraph > > m_graphs
bool LoadAnimationBank(const std::string &filePath)
Defines a complete animation sequence.