-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimationSystem.cpp
More file actions
79 lines (68 loc) · 2.13 KB
/
AnimationSystem.cpp
File metadata and controls
79 lines (68 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "AnimationSystem.h"
#include "DekiLogSystem.h"
#include <algorithm>
AnimationSystem* AnimationSystem::instance = nullptr;
AnimationSystem::AnimationSystem()
{
DEKI_LOG_INTERNAL("AnimationSystem initialized");
}
AnimationSystem::~AnimationSystem()
{
animation_components.clear();
DEKI_LOG_INTERNAL("AnimationSystem destroyed");
}
void AnimationSystem::RegisterAnimationComponent(AnimationComponent* animation_component)
{
if (!animation_component)
{
DEKI_LOG_ERROR("AnimationSystem::RegisterAnimationComponent - null component");
return;
}
// Check if already registered
auto it = std::find(animation_components.begin(), animation_components.end(), animation_component);
if (it != animation_components.end())
{
DEKI_LOG_INTERNAL("AnimationSystem::RegisterAnimationComponent - component already registered");
return;
}
animation_components.push_back(animation_component);
DEKI_LOG_INTERNAL("AnimationSystem::RegisterAnimationComponent - registered component (total: %d)",
static_cast<int>(animation_components.size()));
}
void AnimationSystem::UnregisterAnimationComponent(AnimationComponent* animation_component)
{
if (!animation_component)
{
return;
}
auto it = std::find(animation_components.begin(), animation_components.end(), animation_component);
if (it != animation_components.end())
{
animation_components.erase(it);
DEKI_LOG_INTERNAL("AnimationSystem::UnregisterAnimationComponent - unregistered component (total: %d)",
static_cast<int>(animation_components.size()));
}
}
void AnimationSystem::ClearAll()
{
animation_components.clear();
}
void AnimationSystem::UpdateAnimations(uint32_t current_time)
{
// Update all animation components
for (auto* component : animation_components)
{
if (component && component->is_playing)
{
component->UpdateAnimation(current_time);
}
}
}
AnimationSystem& AnimationSystem::GetInstance()
{
if (!instance)
{
instance = new AnimationSystem();
}
return *instance;
}