@@ -12,6 +12,10 @@ Animation::~Animation() {
12
12
if (this ->liveStream != nullptr && this ->isOneTimeLiveStream ) {
13
13
delete this ->liveStream ;
14
14
}
15
+
16
+ if (this ->playedIndexes != nullptr ) {
17
+ delete[] this ->playedIndexes ;
18
+ }
15
19
}
16
20
17
21
bool Animation::hasFinished () {
@@ -36,16 +40,21 @@ void Animation::addScene(Stream &stream, byte fps, int frames) {
36
40
37
41
void Animation::registerScene (Scene *scene) {
38
42
Scene **newScenes = new Scene *[this ->addIndex + 1 ];
43
+ bool *newPlayedIndexes = new bool [this ->addIndex + 1 ];
39
44
40
45
for (int i = 0 ; i < this ->addIndex ; i++) {
41
46
newScenes[i] = this ->scenes [i];
47
+ newPlayedIndexes[i] = this ->playedIndexes [i];
42
48
}
43
49
44
50
newScenes[this ->addIndex ] = scene;
51
+ newPlayedIndexes[this ->addIndex ] = false ;
45
52
46
53
delete[] this ->scenes ;
54
+ delete[] this ->playedIndexes ;
47
55
48
56
this ->scenes = newScenes;
57
+ this ->playedIndexes = newPlayedIndexes;
49
58
this ->addIndex ++;
50
59
}
51
60
@@ -65,9 +74,14 @@ void Animation::setScene(byte index) {
65
74
byte prevIndex = this ->playIndex ;
66
75
67
76
this ->playIndex = index ;
77
+ this ->playedIndexes [index ] = true ;
68
78
this ->scene = this ->scenes [index ];
69
79
this ->scene ->reset ();
70
80
81
+ if (this ->allScenesPlayed ()) {
82
+ this ->resetPlayedScenes ();
83
+ }
84
+
71
85
if (this ->sceneCallback ) {
72
86
this ->sceneCallback (prevIndex, index );
73
87
}
@@ -77,7 +91,9 @@ void Animation::setRandomScene() {
77
91
byte randomIndex = 0 ;
78
92
79
93
if (this ->addIndex > 1 ) {
80
- randomIndex = random (this ->addIndex );
94
+ do {
95
+ randomIndex = random (this ->addIndex );
96
+ } while (this ->playedIndexes [randomIndex]);
81
97
}
82
98
83
99
this ->setScene (randomIndex);
@@ -94,6 +110,12 @@ void Animation::resetScene() {
94
110
}
95
111
}
96
112
113
+ void Animation::resetPlayedScenes () {
114
+ for (int i = 0 ; i < this ->addIndex ; i++) {
115
+ this ->playedIndexes [i] = false ;
116
+ }
117
+ }
118
+
97
119
void Animation::play () {
98
120
if (!this ->hasScenes () || !this ->modeIsIn (2 , MODE_DEFAULT, MODE_PAUSE)) {
99
121
return ;
@@ -190,6 +212,20 @@ byte Animation::getPlayIndex() {
190
212
return this ->playIndex ;
191
213
}
192
214
215
+ bool Animation::scenePlayed (int index) {
216
+ return this ->playedIndexes [index ];
217
+ }
218
+
219
+ bool Animation::allScenesPlayed () {
220
+ for (int i = 0 ; i < this ->addIndex ; i++) {
221
+ if (!this ->playedIndexes [i]) {
222
+ return false ;
223
+ }
224
+ }
225
+
226
+ return true ;
227
+ }
228
+
193
229
void Animation::run (unsigned long currentMicros) {
194
230
switch (this ->mode ) {
195
231
case MODE_PLAY:
0 commit comments