ScummVM API documentation
script_tim.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 KYRA_SCRIPT_TIM_H
23 #define KYRA_SCRIPT_TIM_H
24 
25 #include "kyra/kyra_v1.h"
26 
27 #include "common/array.h"
28 #include "common/func.h"
29 #include "common/str.h"
30 
31 namespace Kyra {
32 
33 class WSAMovie_v2;
34 class Screen_v2;
35 class Movie;
36 class LoLEngine;
37 
38 class TimAnimator {
39 public:
40  struct AnimPart {
41  uint16 firstFrame;
42  uint16 lastFrame;
43  uint16 cycles;
44  int16 nextPart;
45  int16 partDelay;
46  uint16 field_A;
47  int16 sfxIndex;
48  uint16 sfxFrame;
49  };
50 
51  struct Animation {
52  Movie *wsa;
53  int16 x, y;
54  uint32 nextFrame;
55  uint8 enable;
56  uint8 field_D;
57  uint8 frameDelay;
58  int8 curPart;
59  uint8 curFrame;
60  uint8 cyclesCompleted;
61  uint16 wsaCopyParams;
62  int8 lastPart;
63  AnimPart *parts;
64  };
65 
66 #ifdef ENABLE_LOL
67  TimAnimator(LoLEngine *engine, Screen_v2 *screen_v2, OSystem *system, bool useParts);
68 #else
69  TimAnimator(KyraEngine_v1 *engine, Screen_v2 *screen_v2, OSystem *system, bool useParts);
70 #endif
71  ~TimAnimator();
72 
73  void init(int animIndex, Movie *wsa, int x, int y, int wsaCopyParams, int frameDelay);
74  void reset(int animIndex, bool clearStruct);
75 
76  void displayFrame(int animIndex, int page, int frame, int flags = -1);
77 
78  const Movie *getWsaCPtr(int animIndex) { return (animIndex >= 0 && animIndex < 6) ? _animations[animIndex].wsa : 0; }
79  int getAnimX(int animIndex) { return (animIndex >= 0 && animIndex < 6) ? _animations[animIndex].x : 0; }
80  int getAnimY(int animIndex) { return (animIndex >= 0 && animIndex < 6) ? _animations[animIndex].y : 0; }
81 
82 #ifdef ENABLE_LOL
83  void setupPart(int animIndex, int part, int firstFrame, int lastFrame, int cycles, int nextPart, int partDelay, int f, int sfxIndex, int sfxFrame);
84  void start(int animIndex, int part);
85  void stop(int animIndex);
86  void update(int animIndex);
87  void playPart(int animIndex, int firstFrame, int lastFrame, int delay);
88  int resetLastPart(int animIndex);
89 #endif
90 
91 private:
92 #ifdef ENABLE_LOL
93  LoLEngine *_vm;
94 #else
95  KyraEngine_v1 *_vm;
96 #endif
97  Screen_v2 *_screen;
98  OSystem *_system;
99 
100  Animation *_animations;
101 
102  const bool _useParts;
103 };
104 
105 struct TIM;
107 
108 struct TIM {
109  char filename[13];
110 
111  uint16 clickedButton;
112  int16 dlgFunc;
113 
114  int16 procFunc;
115  uint16 procParam;
116 
117  enum {
118  kCountFuncs = 10
119  };
120 
121  struct Function {
122  uint16 *ip;
123 
124  uint32 lastTime;
125  uint32 nextTime;
126 
127  uint16 *loopIp;
128 
129  uint16 *avtl;
130  } func[kCountFuncs];
131 
132  enum {
133  kWSASlots = 6,
134  kAnimParts = 10
135  };
136 
137  struct WSASlot {
138  int anim;
139 
140  int16 x, y;
141  uint16 wsaFlags;
142  uint16 offscreen;
143  } wsa[kWSASlots];
144 
145  uint16 *avtl;
146  uint8 *text;
147 
148  const Common::Array<const TIMOpcode *> *opcodes;
149 
150  // TODO: Get rid of this ugly HACK to allow the
151  // Lands of Lore outro to be working properly.
152  bool isLoLOutro;
153  uint8 lolCharacter;
154 };
155 
157 public:
158  TIMInterpreter(KyraEngine_v1 *engine, Screen_v2 *screen_v2, OSystem *system);
159  virtual ~TIMInterpreter();
160 
161  TIM *load(const char *filename, const Common::Array<const TIMOpcode *> *opcodes);
162  void unload(TIM *&tim) const;
163 
164  bool callback(Common::IFFChunk &chunk);
165 
166  virtual int initAnimStruct(int index, const char *filename, int x, int y, int, int offscreenBuffer, uint16 wsaFlags);
167  virtual int freeAnimStruct(int index);
168  TimAnimator *animator() { return _animator; }
169 
170  void setLangData(const char *filename);
171  void clearLangData() { delete[] _langData; _langData = 0; }
172 
173  const char *getCTableEntry(uint idx) const;
174 
175  void resetFinishedFlag() { _finished = false; }
176  bool finished() const { return _finished; }
177 
178  int exec(TIM *tim, bool loop);
179  void stopCurFunc() { if (_currentTim) cmd_stopCurFunc(0); }
180  void stopAllFuncs(TIM *tim);
181 
182  void refreshTimersAfterPause(uint32 elapsedTime);
183 
184  void displayText(uint16 textId, int16 flags);
185  void displayText(uint16 textId, int16 flags, uint8 color);
186  void setupTextPalette(uint index, int fadePalette);
187 
188  virtual void resetDialogueState(TIM *tim) {}
189 
190  int _drawPage2;
191 
192  int _palDelayInc, _palDiff, _palDelayAcc;
193  int _abortFlag;
194 
195 protected:
196  KyraEngine_v1 *_vm;
197  Screen_v2 *_screen;
198  OSystem *_system;
199 
200  TIM *_currentTim;
201  int _currentFunc;
202 
203  TimAnimator *_animator;
204 
205  bool _finished;
206 
207  // used when loading
208  int _avtlChunkSize;
209  const char *_filename;
210  TIM *_tim;
211 
212  Common::String _vocFiles[120];
213 
214  virtual void update() {}
215  virtual void checkSpeechProgress() {}
216 
217  char _audioFilename[32];
218 
219  uint8 *_langData;
220  char *getTableEntry(uint idx);
221  bool _textDisplayed;
222  uint8 *_textAreaBuffer;
223 
224  virtual int execCommand(int cmd, const uint16 *param);
225 
226  typedef int (TIMInterpreter::*CommandProc)(const uint16 *);
227  struct CommandEntry {
228  CommandProc proc;
229  const char *desc;
230  };
231 
232  const CommandEntry *_commands;
233  int _commandsSize;
234 
235  int cmd_initFunc0(const uint16 *param);
236  int cmd_stopCurFunc(const uint16 *param);
237  int cmd_initWSA(const uint16 *param);
238  int cmd_uninitWSA(const uint16 *param);
239  int cmd_initFunc(const uint16 *param);
240  int cmd_stopFunc(const uint16 *param);
241  int cmd_wsaDisplayFrame(const uint16 *param);
242  int cmd_displayText(const uint16 *param);
243  int cmd_loadVocFile(const uint16 *param);
244  int cmd_unloadVocFile(const uint16 *param);
245  int cmd_playVocFile(const uint16 *param);
246  int cmd_loadSoundFile(const uint16 *param);
247  int cmd_playMusicTrack(const uint16 *param);
248  virtual int cmd_setLoopIp(const uint16 *param);
249  virtual int cmd_continueLoop(const uint16 *param);
250  int cmd_resetLoopIp(const uint16 *param);
251  int cmd_resetAllRuntimes(const uint16 *param);
252  int cmd_execOpcode(const uint16 *param);
253  int cmd_initFuncNow(const uint16 *param);
254  int cmd_stopFuncNow(const uint16 *param);
255 #define cmd_return(n, v) \
256  int cmd_return_##n(const uint16 *){ return v; }
257  cmd_return( 1, 1)
258  cmd_return(n1, -1)
259 #undef cmd_return
260 };
261 
262 #ifdef ENABLE_LOL
263 class LoLEngine;
264 class Screen_LoL;
265 class TIMInterpreter_LoL : public TIMInterpreter {
266 public:
267  TIMInterpreter_LoL(LoLEngine *engine, Screen_v2 *screen_v2, OSystem *system);
268 
269  int initAnimStruct(int index, const char *filename, int x, int y, int frameDelay, int, uint16 wsaCopyParams) override;
270  int freeAnimStruct(int index) override;
271 
272  void resetDialogueState(TIM *tim) override;
273 
274 private:
275  void update() override;
276  void checkSpeechProgress() override;
277 
278  const char *getTableString(int id);
279  void advanceToOpcode(int opcode);
280 
281  LoLEngine *_vm;
282  Screen_LoL *_screen;
283 
284  int execCommand(int cmd, const uint16 *param) override;
285 
286  typedef int (TIMInterpreter_LoL::*CommandProc)(const uint16 *);
287  struct CommandEntry {
288  CommandProc proc;
289  const char *desc;
290  };
291 
292  const CommandEntry *_commands;
293  int _commandsSize;
294 
295  int cmd_stopAllFuncs(const uint16 *param);
296  int cmd_setLoopIp(const uint16 *param) override;
297  int cmd_continueLoop(const uint16 *param) override;
298  int cmd_processDialogue(const uint16 *param);
299  int cmd_dialogueBox(const uint16 *param);
300 };
301 #endif // ENABLE_LOL
302 
303 } // End of namespace Kyra
304 
305 #endif
Definition: script_tim.h:51
Definition: str.h:59
Definition: array.h:52
Definition: kyra_v1.h:126
Definition: script_tim.h:121
Definition: script_tim.h:227
Definition: script_tim.h:137
Definition: script_tim.h:156
Definition: wsamovie.h:31
Definition: detection.h:27
Definition: script_tim.h:108
Definition: script_tim.h:38
Definition: script_tim.h:40
Definition: system.h:167
Definition: screen_v2.h:30
Definition: iff_container.h:160
Definition: func.h:473