ScummVM API documentation
animation_events.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef HOLLYWOOD_MONSTERS_SCENES_ANIMATION_EVENTS_H
23#define HOLLYWOOD_MONSTERS_SCENES_ANIMATION_EVENTS_H
24
25#include "common/array.h"
26#include "common/types.h"
27
28namespace Hollywood {
29
37 enum Type {
38 kFramebufferPatch,
39 kResourcePatch,
40 kSound,
41 kLoopingSound,
42 kResidentSound,
43 kStopSound,
44 kSecondarySpeech,
45 kPrimarySpeech,
46 kActorPath,
47 kLayerFrame,
48 kLayerFrameMap,
49 kLayerReset,
50 kLayerVisibility,
51 kStateCommit,
52 kInvalidatePalette,
53 kFadeFromBlack,
54 kCustomHook
55 };
56 // Sound events target the main effect player unless an ambient slot is selected.
57 enum {
58 kMainSoundSlot = 0xff
59 };
60
61 typedef void (*CommitFunction)(void *target, uint32 value);
62
63 AnimationFrameEvent(int newFrame, Type newType) :
64 frame(newFrame),
65 everyFrame(false),
66 type(newType),
67 selector(0),
68 resourceChunk(0),
69 soundId(0),
70 soundVolumePercent(100),
71 soundSlot(kMainSoundSlot),
72 speechRow(0),
73 speechFrame(0),
74 speechId(0),
75 speechCenterX(0),
76 speechTopY(0),
77 speechRed(0),
78 speechGreen(0),
79 speechBlue(0),
80 actorX(0),
81 actorY(0),
82 actorFacing(0),
83 actorCel(0),
84 actorPathFrameMillis(0),
85 layerId(0),
86 layerFrame(0),
87 layerFrameMap(nullptr),
88 layerFrameMapSize(0),
89 layerFrameMapFirstFrame(0),
90 showMappedLayer(false),
91 layerVisible(false),
92 commitTarget(nullptr),
93 commitValue(0),
94 commitFunction(nullptr),
95 hookId(0) {
96 }
97
98 bool matches(uint currentFrame) const {
99 return everyFrame || (frame >= 0 && (uint)frame == currentFrame);
100 }
101
102 int frame;
103 bool everyFrame;
104 Type type;
105 byte selector;
106 uint resourceChunk;
107 uint16 soundId;
108 byte soundVolumePercent;
109 byte soundSlot;
110 uint16 speechRow;
111 byte speechFrame;
112 byte speechId;
113 uint16 speechCenterX;
114 uint16 speechTopY;
115 byte speechRed;
116 byte speechGreen;
117 byte speechBlue;
118 int actorX;
119 int actorY;
120 byte actorFacing;
121 byte actorCel;
122 uint32 actorPathFrameMillis;
123 uint layerId;
124 byte layerFrame;
125 const byte *layerFrameMap;
126 uint layerFrameMapSize;
127 int layerFrameMapFirstFrame;
128 bool showMappedLayer;
129 bool layerVisible;
130 void *commitTarget;
131 uint32 commitValue;
132 CommitFunction commitFunction;
133 byte hookId;
134};
135
139template<class Spec>
141public:
142 Spec &patchAt(int frame, byte selector) {
143 AnimationFrameEvent event(frame, AnimationFrameEvent::kFramebufferPatch);
144 event.selector = selector;
145 _events.push_back(event);
146 return self();
147 }
148
149 Spec &resourcePatchAt(int frame, uint resourceChunkIndex) {
150 AnimationFrameEvent event(frame, AnimationFrameEvent::kResourcePatch);
151 event.resourceChunk = resourceChunkIndex;
152 _events.push_back(event);
153 return self();
154 }
155
156 Spec &soundAt(int frame, uint16 soundId, byte volumePercent = 100,
157 byte slotIndex = AnimationFrameEvent::kMainSoundSlot) {
158 addSound(frame, soundId, volumePercent, false, slotIndex);
159 return self();
160 }
161
162 Spec &loopingSoundAt(int frame, uint16 soundId, byte volumePercent = 100,
163 byte slotIndex = AnimationFrameEvent::kMainSoundSlot) {
164 addSound(frame, soundId, volumePercent, true, slotIndex);
165 return self();
166 }
167
168 Spec &stopSoundAt(int frame) {
169 _events.push_back(AnimationFrameEvent(frame, AnimationFrameEvent::kStopSound));
170 return self();
171 }
172
173 Spec &ambientSoundAt(int frame, uint16 soundId, byte volumePercent = 100,
174 byte slotIndex = 0) {
175 addSound(frame, soundId, volumePercent, false, slotIndex);
176 return self();
177 }
178
179 Spec &loopingAmbientSoundAt(int frame, uint16 soundId, byte volumePercent = 100,
180 byte slotIndex = 0) {
181 addSound(frame, soundId, volumePercent, true, slotIndex);
182 return self();
183 }
184
185 Spec &residentSoundAt(int frame, byte soundId, byte volumePercent = 100) {
186 AnimationFrameEvent event(frame, AnimationFrameEvent::kResidentSound);
187 event.soundId = soundId;
188 event.soundVolumePercent = volumePercent;
189 _events.push_back(event);
190 return self();
191 }
192
193 Spec &secondarySpeechAt(int frame, uint16 rowIndex, byte frameIndex,
194 byte speechId = 0) {
195 AnimationFrameEvent event(frame, AnimationFrameEvent::kSecondarySpeech);
196 event.speechRow = rowIndex;
197 event.speechFrame = frameIndex;
198 event.speechId = speechId;
199 _events.push_back(event);
200 return self();
201 }
202
203 Spec &primarySpeechAt(int frame, uint16 rowIndex, byte frameIndex,
204 uint16 centerX, uint16 topY, byte red, byte green, byte blue) {
205 AnimationFrameEvent event(frame, AnimationFrameEvent::kPrimarySpeech);
206 event.speechRow = rowIndex;
207 event.speechFrame = frameIndex;
208 event.speechCenterX = centerX;
209 event.speechTopY = topY;
210 event.speechRed = red;
211 event.speechGreen = green;
212 event.speechBlue = blue;
213 _events.push_back(event);
214 return self();
215 }
216
217 // Starts a path that advances alongside the blocking animation.
218 Spec &actorPathAt(int frame, int targetX, int targetY, byte finalFacing,
219 byte finalCel, uint32 frameMillis) {
220 AnimationFrameEvent event(frame, AnimationFrameEvent::kActorPath);
221 event.actorX = targetX;
222 event.actorY = targetY;
223 event.actorFacing = finalFacing;
224 event.actorCel = finalCel;
225 event.actorPathFrameMillis = frameMillis;
226 _events.push_back(event);
227 return self();
228 }
229
230 Spec &layerFrameAt(int frame, uint layerId, byte layerFrame) {
231 AnimationFrameEvent event(frame, AnimationFrameEvent::kLayerFrame);
232 event.layerId = layerId;
233 event.layerFrame = layerFrame;
234 _events.push_back(event);
235 return self();
236 }
237
238 Spec &mappedLayerFrames(uint layerId, const byte *mappedFrames,
239 uint mappedFrameCount, int firstPlaybackFrame = 0) {
240 addLayerFrameMap(layerId, mappedFrames, mappedFrameCount, firstPlaybackFrame, false);
241 return self();
242 }
243
244 Spec &visibleMappedLayerFrames(uint layerId, const byte *mappedFrames,
245 uint mappedFrameCount, int firstPlaybackFrame = 0) {
246 addLayerFrameMap(layerId, mappedFrames, mappedFrameCount, firstPlaybackFrame, true);
247 return self();
248 }
249
250 Spec &layerVisibleAt(int frame, uint layerId, bool visible) {
251 AnimationFrameEvent event(frame, AnimationFrameEvent::kLayerVisibility);
252 event.layerId = layerId;
253 event.layerVisible = visible;
254 _events.push_back(event);
255 return self();
256 }
257
258 Spec &layerResetAt(int frame, uint layerId, byte layerFrame) {
259 AnimationFrameEvent event(frame, AnimationFrameEvent::kLayerReset);
260 event.layerId = layerId;
261 event.layerFrame = layerFrame;
262 _events.push_back(event);
263 return self();
264 }
265
266 template<class T, class V>
267 Spec &commitAt(int frame, T &target, const V &value) {
268 AnimationFrameEvent event(frame, AnimationFrameEvent::kStateCommit);
269 event.commitTarget = &target;
270 event.commitValue = static_cast<uint32>(static_cast<T>(value));
271 event.commitFunction = [](void *commitTarget, uint32 commitValue) {
272 *static_cast<T *>(commitTarget) = static_cast<T>(commitValue);
273 };
274 _events.push_back(event);
275 return self();
276 }
277
278 Spec &invalidatePaletteAt(int frame) {
279 _events.push_back(AnimationFrameEvent(frame, AnimationFrameEvent::kInvalidatePalette));
280 return self();
281 }
282
283 Spec &fadeFromBlackAt(int frame) {
284 _events.push_back(AnimationFrameEvent(frame, AnimationFrameEvent::kFadeFromBlack));
285 return self();
286 }
287
288 Spec &hookAt(int frame, byte hookId) {
289 addCustomHook(frame, hookId, false);
290 return self();
291 }
292
293 Spec &hookEveryFrame(byte hookId) {
294 addCustomHook(-1, hookId, true);
295 return self();
296 }
297
299
300private:
301 void addSound(int frame, uint16 soundId, byte volumePercent, bool looping,
302 byte slotIndex) {
303 AnimationFrameEvent event(frame, looping ?
304 AnimationFrameEvent::kLoopingSound : AnimationFrameEvent::kSound);
305 event.soundId = soundId;
306 event.soundVolumePercent = volumePercent;
307 event.soundSlot = slotIndex;
308 _events.push_back(event);
309 }
310
311 void addLayerFrameMap(uint layerId, const byte *mappedFrames, uint mappedFrameCount,
312 int firstPlaybackFrame, bool showLayer) {
313 AnimationFrameEvent event(-1, AnimationFrameEvent::kLayerFrameMap);
314 event.everyFrame = true;
315 event.layerId = layerId;
316 event.layerFrameMap = mappedFrames;
317 event.layerFrameMapSize = mappedFrameCount;
318 event.layerFrameMapFirstFrame = firstPlaybackFrame;
319 event.showMappedLayer = showLayer;
320 _events.push_back(event);
321 }
322
323 void addCustomHook(int frame, byte hookId, bool everyFrame) {
324 if (hookId == 0)
325 return;
326 AnimationFrameEvent event(frame, AnimationFrameEvent::kCustomHook);
327 event.everyFrame = everyFrame;
328 event.hookId = hookId;
329 _events.push_back(event);
330 }
331
332 Spec &self() {
333 return static_cast<Spec &>(*this);
334 }
335};
336
337} // End of namespace Hollywood
338
339#endif // HOLLYWOOD_MONSTERS_SCENES_ANIMATION_EVENTS_H
Definition: array.h:52
void push_back(const T &element)
Definition: array.h:181
Definition: animation_events.h:140
Definition: animation_events.h:36