Antkeeper  0.0.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
timeline.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Christopher J. Howard
3  *
4  * This file is part of Antkeeper source code.
5  *
6  * Antkeeper source code is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Antkeeper source code is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef ANTKEEPER_TIMELINE_HPP
21 #define ANTKEEPER_TIMELINE_HPP
22 
23 #include <functional>
24 #include <set>
25 #include <tuple>
26 
30 class timeline
31 {
32 public:
34  typedef std::tuple<float, std::function<void()>> cue;
35 
37  typedef std::list<cue> sequence;
38 
42  timeline();
43 
49  void advance(float dt);
50 
56  void seek(float t);
57 
63  void add_cue(const cue& c);
64 
70  void remove_cue(const cue& c);
71 
78  void remove_cues(float start, float end);
79 
85  void add_sequence(const sequence& s);
86 
92  void remove_sequence(const sequence& s);
93 
97  void clear();
98 
104  void set_autoremove(bool enabled);
105 
109  float get_position() const;
110 
118  sequence get_cues(float start, float end) const;
119 
120 private:
121  std::multiset<cue, std::function<bool(const cue&, const cue&)>> cues;
122  float position;
123  bool autoremove;
124 };
125 
126 inline float timeline::get_position() const
127 {
128  return position;
129 }
130 
131 #endif // ANTKEEPER_TIMELINE_HPP
132 
Timeline which executes cues (scheduled functions) when advanced over their respective positions in t...
Definition: timeline.hpp:31
void add_cue(const cue &c)
Adds a cue to the timeline.
Definition: timeline.cpp:56
void seek(float t)
Sets the timeline position to t.
Definition: timeline.cpp:51
timeline()
Creates a timeline.
Definition: timeline.cpp:27
void remove_cue(const cue &c)
Removes a cue from the timeline.
Definition: timeline.cpp:61
void remove_sequence(const sequence &s)
Removes a sequence of cues from the timeline.
Definition: timeline.cpp:81
sequence get_cues(float start, float end) const
Returns all the cues on [start, end).
Definition: timeline.cpp:99
void advance(float dt)
Advances the timeline position (t) by dt, triggering any cues scheduled between t and dt.
Definition: timeline.cpp:33
std::list< cue > sequence
List of cues.
Definition: timeline.hpp:37
float get_position() const
Returns the current position in time on the timeline.
Definition: timeline.hpp:126
void set_autoremove(bool enabled)
If enabled, cues will be automatically removed from the timeline when they are triggered.
Definition: timeline.cpp:94
void clear()
Removes all cues from the timeline.
Definition: timeline.cpp:89
void remove_cues(float start, float end)
Removes all cues on [start, end).
Definition: timeline.cpp:66
std::tuple< float, std::function< void()> > cue
Scheduled function consisting of a time and function object.
Definition: timeline.hpp:34
void add_sequence(const sequence &s)
Adds a sequence of cues to the timeline.
Definition: timeline.cpp:73