ScummVM API documentation
animation.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// Background animation management module private header
23
24#ifndef SAGA_ANIMATION_H
25#define SAGA_ANIMATION_H
26
27namespace Saga {
28
29#define MAX_ANIMATIONS 10
30#define DEFAULT_FRAME_TIME 140
31
32#define SAGA_FRAME_START 0xF
33#define SAGA_FRAME_END 0x3F
34#define SAGA_FRAME_NOOP 0x1F
35#define SAGA_FRAME_REPOSITION 0x30
36#define SAGA_FRAME_ROW_END 0x2F
37#define SAGA_FRAME_LONG_COMPRESSED_RUN 0x20
38#define SAGA_FRAME_LONG_UNCOMPRESSED_RUN 0x10
39#define SAGA_FRAME_COMPRESSED_RUN 0x80
40#define SAGA_FRAME_UNCOMPRESSED_RUN 0x40
41#define SAGA_FRAME_EMPTY_RUN 0xC0
42
43#define SAGA_FRAME_AMIGA_OPCODE_REPOSITION 0x00
44#define SAGA_FRAME_AMIGA_OPCODE_LITERAL 0x40
45#define SAGA_FRAME_AMIGA_OPCODE_TRANSPARENT 0xC0
46#define SAGA_FRAME_AMIGA_OPCODE_NEWLINE 0x80
47#define SAGA_FRAME_AMIGA_OPCODE_MASK 0xC0
48#define SAGA_FRAME_AMIGA_PARAM_MASK 0x3F
49#define SAGA_FRAME_AMIGA_END 0x3F
50#define SAGA_FRAME_AMIGA_START 0x3E
51
52enum AnimationState {
53 ANIM_PLAYING = 0x01,
54 ANIM_PAUSE = 0x02,
55 ANIM_STOPPING = 0x03
56};
57
58enum AnimationFlags {
59 ANIM_FLAG_NONE = 0x00,
60 ANIM_FLAG_ENDSCENE = 0x01 // When animation ends, dispatch scene end event
61};
62
63// Cutaway info array member. Cutaways are basically animations with a really
64// bad attitude.
65struct Cutaway {
66 uint16 backgroundResourceId;
67 uint16 animResourceId;
68 int16 cycles;
69 int16 frameRate;
70};
71
72// Animation info array member
74 ByteArray resourceData;
75
76 uint16 magic;
77
78 uint16 screenWidth;
79 uint16 screenHeight;
80
81 byte unknown06;
82 byte unknown07;
83
84 int16 maxFrame;
85 int16 loopFrame;
86
87 int16 currentFrame;
88 Common::Array<size_t> frameOffsets;
89
90 uint16 completed;
91 uint16 cycles;
92
93 int frameTime;
94
95 AnimationState state;
96 int16 linkId;
97 uint16 flags;
98};
99
100class Anim {
101public:
102 Anim(SagaEngine *vm);
103 ~Anim();
104
105 void loadCutawayList(const ByteArray &resourceData);
106 void clearCutawayList();
107 int playCutaway(int cut, bool fade);
108 void endCutaway();
109 void returnFromCutaway();
110 void clearCutaway();
111 void showCutawayBg(int bg);
112
113 void startVideo(int vid, bool fade);
114 void endVideo();
115 void returnFromVideo();
116
117 void load(uint16 animId, const ByteArray &resourceData);
118 void freeId(uint16 animId);
119 void play(uint16 animId, int vectorTime, bool playing = true);
120 void link(int16 animId1, int16 animId2);
121 void setFlag(uint16 animId, uint16 flag);
122 void clearFlag(uint16 animId, uint16 flag);
123 void setFrameTime(uint16 animId, int time);
124 void reset();
125 void animInfo();
126 void cutawayInfo();
127 void setCycles(uint16 animId, int cycles);
128 void stop(uint16 animId);
129 void finish(uint16 animId);
130 void resume(uint16 animId, int cycles);
131 void resumeAll();
132 int16 getCurrentFrame(uint16 animId);
133 int getFrameTime(uint16 animId);
134 int getCycles(uint16 animId);
135 bool isPlaying(uint16 animId);
136
137 bool hasAnimation(uint16 animId) {
138 if (animId >= MAX_ANIMATIONS) {
139 if (animId < MAX_ANIMATIONS + ARRAYSIZE(_cutawayAnimations))
140 return (_cutawayAnimations[animId - MAX_ANIMATIONS] != NULL);
141 return false;
142 }
143 return (_animations[animId] != NULL);
144 }
145
146 bool hasCutaway() { return _cutawayActive; }
147 void setCutAwayMode(int mode) { _cutAwayMode = mode; }
148// int cutawayListLength() { return _cutawayListLength; }
149// int cutawayBgResourceID(int cutaway) { return _cutawayList[cutaway].backgroundResourceId; }
150// int cutawayAnimResourceID(int cutaway) { return _cutawayList[cutaway].animResourceId; }
151
152private:
153 void decodeFrame(AnimationData *anim, size_t frameOffset, byte *buf, size_t bufLength);
154 int fillFrameOffsets(AnimationData *anim, bool reallyFill = true);
155
156 void validateAnimationId(uint16 animId) {
157 if (animId >= MAX_ANIMATIONS) {
158 // Cutaway
159 if (animId >= MAX_ANIMATIONS + ARRAYSIZE(_cutawayAnimations))
160 error("validateAnimationId: animId out of range");
161 if (_cutawayAnimations[animId - MAX_ANIMATIONS] == NULL) {
162 error("validateAnimationId: animId=%i unassigned", animId);
163 }
164 } else {
165 // Animation
166 if (_animations[animId] == NULL) {
167 error("validateAnimationId: animId=%i unassigned.", animId);
168 }
169 }
170 }
171
172 bool isLongData() const {
173 if ((_vm->getGameId() == GID_ITE) && (_vm->getPlatform() != Common::kPlatformMacintosh)) {
174 return false;
175 }
176 return true;
177 }
178
179 AnimationData* getAnimation(uint16 animId) {
180 validateAnimationId(animId);
181 if (animId >= MAX_ANIMATIONS)
182 return _cutawayAnimations[animId - MAX_ANIMATIONS];
183 return _animations[animId];
184 }
185
186 uint16 getAnimationCount() const {
187 uint16 i = 0;
188 for (; i < MAX_ANIMATIONS; i++) {
189 if (_animations[i] == NULL) {
190 break;
191 }
192 }
193 return i;
194 }
195
196 SagaEngine *_vm;
197 AnimationData *_animations[MAX_ANIMATIONS];
198 AnimationData *_cutawayAnimations[2];
199 Common::Array<Cutaway> _cutawayList;
200 PalEntry saved_pal[PAL_ENTRIES];
201 bool _cutawayActive;
202 int _cutAwayMode;
203 bool _cutAwayFade;
204};
205
206} // End of namespace Saga
207
208#endif // ANIMATION_H_
Definition: animation.h:100
Definition: saga.h:464
Definition: saga.h:497
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
#define ARRAYSIZE(x)
Definition: util.h:114
Definition: actor.h:34
Definition: animation.h:73
Definition: animation.h:65
Definition: gfx.h:81