Loading...
Searching...
No Matches
AnimationManager.h
Go to the documentation of this file.
1// Copyright (c) 2025 Dave R. Smith.
2// Malena Framework — Licensed under PolyForm Noncommercial 1.0.0; commercial use requires a paid license. See LICENSE.
3
4//
5// AnimationManager.h — the single per-frame driver for all active animations.
6//
7// AppManager::run() calls advance(dt) once per frame. Each animation registers a
8// type-erased step tagged with an owner pointer; when the owner is destroyed the
9// framework cancels its steps so no dangling setter is ever called.
10//
11
12#ifndef MALENA_ANIMATIONMANAGER_H
13#define MALENA_ANIMATIONMANAGER_H
14
15#pragma once
16
18#include <cstddef>
19#include <functional>
20#include <vector>
21
22namespace ml
23{
25 {
26 public:
28 using Step = std::function<bool(float)>;
29
31 static void add(const void* owner, Step step);
32
34 static void advance(float dt);
35
37 static void cancel(const void* owner);
38
40 static bool hasActive(const void* owner);
41
43 static std::size_t activeCount();
44
45 private:
46 struct Track
47 {
48 const void* owner = nullptr;
49 Step step;
50 bool dead = false;
51 };
52
53 static std::vector<Track>& tracks();
54 static std::vector<Track>& pending();
55 static bool& advancing();
56 };
57
58} // namespace ml
59
60#endif // MALENA_ANIMATIONMANAGER_H
static void cancel(const void *owner)
Remove every animation belonging to owner (called on owner destruction).
std::function< bool(float)> Step
A per-frame step. Receives dt (seconds); returns true when finished.
static void advance(float dt)
Advance every active animation by dt seconds (called once per frame).
static bool hasActive(const void *owner)
True if owner has any live animation.
static void add(const void *owner, Step step)
Register an animation step owned by owner (used for cancellation).
static std::size_t activeCount()
Total number of live animations (test/introspection helper).
#define MALENA_API
Definition Animate.h:25