-
-
Notifications
You must be signed in to change notification settings - Fork 461
Expand file tree
/
Copy pathSpriteManager.hpp
More file actions
116 lines (97 loc) · 4.04 KB
/
Copy pathSpriteManager.hpp
File metadata and controls
116 lines (97 loc) · 4.04 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#pragma once
#include "UserSprites/Sprite.hpp"
#include <Renderer/RenderContext.hpp>
#include <cstdint>
#include <list>
#include <set>
#include <utility>
#include <vector>
namespace libprojectM {
namespace UserSprites {
class SpriteManager
{
public:
using SpriteIdentifier = uint32_t;
/**
* @brief Spawns a new sprite.
* @param type The type name of the sprite.
* @param spriteData The sprite code/data, depending on the type.
* @return A unique, non-zero identifier if the sprite was successfully spawned, or zero if an error occurred.
*/
auto Spawn(const std::string& type,
const std::string& spriteData,
const Renderer::RenderContext& renderContext) -> SpriteIdentifier;
/**
* @brief Draws all active sprites.
* @param audioData The frame audio data structure.
* @param renderContext The current frame's rendering context.
* @param outputFramebufferObject Framebuffer object the sprite will be rendered to.
* @param presets The active preset, plus eventually the transitioning one. Used for the burn-in effect.
*/
void Draw(const Audio::FrameAudioData& audioData,
const Renderer::RenderContext& renderContext,
uint32_t outputFramebufferObject,
Sprite::PresetList presets);
/**
* @brief Destroys a single active sprite.
*
* If spriteIdentifier is invalid, no action will be taken.
*
* @param spriteIdentifier The identifier of the sprite to destroy.
*/
void Destroy(SpriteIdentifier spriteIdentifier);
/**
* @brief Destroys all active sprites.
*
* Sprites will be removed when drawing the next frame.
*/
void DestroyAll();
/**
* @brief Returns the current number of active sprites.
* @return The current number of active sprites.
*/
auto ActiveSpriteCount() const -> uint32_t;
/**
* @brief Returns a set of identifiers for all active sprites.
* @return A vector with the identifiers of all active sprites.
*/
auto ActiveSpriteIdentifiers() const -> std::vector<SpriteIdentifier>;
/**
* @brief Sets the number of available sprite slots, e.g. the number of concurrently active sprites.
* If there are more active sprites than the newly set limit, the oldest sprites will be destroyed
* in order until the new limit is matched.
* @param slots The maximum number of active sprites. 0 disables user sprites. Default is 16.
*/
void SpriteSlots(uint32_t slots);
/**
* @brief Returns the currently set maximum number of active sprites.
* @return The maximum number of active sprites.
*/
auto SpriteSlots() const -> uint32_t;
/**
* @brief Returns the current value of a variable in a user sprite's expression code.
* @param spriteIdentifier The sprite ID to retrieve the value for.
* @param variableName The variable to retrieve the value for.
* @return The value of the requested variable and sprite.
*/
auto GetSpriteVariableValue(SpriteIdentifier spriteIdentifier, const std::string& variableName) const -> double;
/**
* @brief Set the value of a variable in a user sprite's expression code.
* @param spriteIdentifier The sprite ID to set the value for.
* @param variableName The variable to set the value for.
* @param value The new value.
*/
void SetSpriteVariableValue(SpriteIdentifier spriteIdentifier, const std::string& variableName, double value);
private:
using SpriteIdPair = std::pair<SpriteIdentifier, Sprite::Ptr>;
/**
* Returns the lowest free ID, starting at 1.
* @return The lowest available/unused sprite ID.
*/
SpriteIdentifier GetLowestFreeIdentifier();
uint32_t m_spriteSlots{16}; //!< Max number of active sprites.
std::set<SpriteIdentifier> m_spriteIdentifiers; //!< Set to keep track of ordered sprite IDs.
std::list<SpriteIdPair> m_sprites; //!< Active sprites with their identifier.
};
} // namespace UserSprites
} // namespace libprojectM