11#pragma once
22
3- #include " Sprite.hpp"
3+ #include " UserSprites/Sprite.hpp"
4+
5+ #include < Renderer/RenderContext.hpp>
46
57#include < cstdint>
68#include < list>
9+ #include < set>
10+ #include < utility>
11+ #include < vector>
712
813namespace libprojectM {
914namespace UserSprites {
1015
1116class SpriteManager
1217{
1318public:
14- SpriteManager ();
15-
16- virtual ~SpriteManager ();
19+ using SpriteIdentifier = uint32_t ;
1720
1821 /* *
1922 * @brief Spawns a new sprite.
23+ * @param type The type name of the sprite.
24+ * @param spriteData The sprite code/data, depending on the type.
25+ * @return A unique, non-zero identifier if the sprite was successfully spawned, or zero if an error occurred.
2026 */
21- void Spawn ();
27+ auto Spawn (const std::string& type,
28+ const std::string& spriteData,
29+ const Renderer::RenderContext& renderContext) -> SpriteIdentifier;
2230
2331 /* *
2432 * @brief Draws all active sprites.
33+ * @param audioData The frame audio data structure.
34+ * @param renderContext The current frame's rendering context.
35+ * @param outputFramebufferObject Framebuffer object the sprite will be rendered to.
36+ * @param presets The active preset, plus eventually the transitioning one. Used for the burn-in effect.
2537 */
26- void Draw ();
38+ void Draw (const Audio::FrameAudioData& audioData,
39+ const Renderer::RenderContext& renderContext,
40+ uint32_t outputFramebufferObject,
41+ Sprite::PresetList presets);
2742
2843 /* *
29- * @brief Queues a single active sprite for destruction.
30- *
31- * The index is the 0-based index of the sprite in the list of currently active sprites, with 0 being the
32- * oldest sprite being displayed. Sprites marked for destruction will be removed when drawing the next frame.
44+ * @brief Destroys a single active sprite.
3345 *
34- * If spriteIndex is larger than the maximum index available , no action is taken.
46+ * If spriteIdentifier is invalid , no action will be taken.
3547 *
36- * @param spriteIndex The slot index of the sprite to destroy.
48+ * @param spriteIdentifier The identifier of the sprite to destroy.
3749 */
38- void Destroy (uint32_t spriteIndex );
50+ void Destroy (SpriteIdentifier spriteIdentifier );
3951
4052 /* *
41- * @brief Marks all active sprites for destruction .
53+ * @brief Destroys all active sprites.
4254 *
4355 * Sprites will be removed when drawing the next frame.
4456 */
@@ -48,12 +60,18 @@ class SpriteManager
4860 * @brief Returns the current number of active sprites.
4961 * @return The current number of active sprites.
5062 */
51- auto ActiveSprites () const -> uint32_t;
63+ auto ActiveSpriteCount () const -> uint32_t;
64+
65+ /* *
66+ * @brief Returns a set of identifiers for all active sprites.
67+ * @return A vector with the identifiers of all active sprites.
68+ */
69+ auto ActiveSpriteIdentifiers () const -> std::vector<SpriteIdentifier>;
5270
5371 /* *
54- * @brief Sets the numer of available sprite slots, e.g. the number of concurrently active sprites.
72+ * @brief Sets the number of available sprite slots, e.g. the number of concurrently active sprites.
5573 * If there are more active sprites than the newly set limit, the oldest sprites will be destroyed
56- * when drawing the next frame until the new limit it met .
74+ * in order until the new limit is matched .
5775 * @param slots The maximum number of active sprites. 0 disables user sprites. Default is 16.
5876 */
5977 void SpriteSlots (uint32_t slots);
@@ -65,8 +83,17 @@ class SpriteManager
6583 auto SpriteSlots () const -> uint32_t;
6684
6785private:
68- uint32_t m_spriteSlots{16 }; // !< Max number of active sprites.
69- std::list<Sprite::Ptr> m_sprites; // !< Active sprites.
86+ using SpriteIdPair = std::pair<SpriteIdentifier, Sprite::Ptr>;
87+
88+ /* *
89+ * Returns the lowest free ID, starting at 1.
90+ * @return The lowest available/unused sprite ID.
91+ */
92+ SpriteIdentifier GetLowestFreeIdentifier ();
93+
94+ uint32_t m_spriteSlots{16 }; // !< Max number of active sprites.
95+ std::set<SpriteIdentifier> m_spriteIdentifiers; // !< Set to keep track of ordered sprite IDs.
96+ std::list<SpriteIdPair> m_sprites; // !< Active sprites with their identifier.
7097};
7198
7299} // namespace UserSprites
0 commit comments