PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/engines/kyra/script_tim.h

http://github.com/scummvm/scummvm
C Header | 306 lines | 214 code | 68 blank | 24 comment | 4 complexity | 72dd9167308646087abb8abd20006e8d MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1, GPL-2.0
  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
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (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, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  20. *
  21. */
  22. #ifndef KYRA_SCRIPT_TIM_H
  23. #define KYRA_SCRIPT_TIM_H
  24. #include "kyra/kyra_v1.h"
  25. #include "common/array.h"
  26. #include "common/func.h"
  27. #include "common/str.h"
  28. namespace Kyra {
  29. class WSAMovie_v2;
  30. class Screen_v2;
  31. class Movie;
  32. class LoLEngine;
  33. class TimAnimator {
  34. public:
  35. struct AnimPart {
  36. uint16 firstFrame;
  37. uint16 lastFrame;
  38. uint16 cycles;
  39. int16 nextPart;
  40. int16 partDelay;
  41. uint16 field_A;
  42. int16 sfxIndex;
  43. uint16 sfxFrame;
  44. };
  45. struct Animation {
  46. Movie *wsa;
  47. int16 x, y;
  48. uint32 nextFrame;
  49. uint8 enable;
  50. uint8 field_D;
  51. uint8 frameDelay;
  52. int8 curPart;
  53. uint8 curFrame;
  54. uint8 cyclesCompleted;
  55. uint16 wsaCopyParams;
  56. int8 lastPart;
  57. AnimPart *parts;
  58. };
  59. #ifdef ENABLE_LOL
  60. TimAnimator(LoLEngine *engine, Screen_v2 *screen_v2, OSystem *system, bool useParts);
  61. #else
  62. TimAnimator(KyraEngine_v1 *engine, Screen_v2 *screen_v2, OSystem *system, bool useParts);
  63. #endif
  64. ~TimAnimator();
  65. void init(int animIndex, Movie *wsa, int x, int y, int wsaCopyParams, int frameDelay);
  66. void reset(int animIndex, bool clearStruct);
  67. void displayFrame(int animIndex, int page, int frame, int flags = -1);
  68. const Movie *getWsaCPtr(int animIndex) { return (animIndex >= 0 && animIndex < 6) ? _animations[animIndex].wsa : 0; }
  69. int getAnimX(int animIndex) { return (animIndex >= 0 && animIndex < 6) ? _animations[animIndex].x : 0; }
  70. int getAnimY(int animIndex) { return (animIndex >= 0 && animIndex < 6) ? _animations[animIndex].y : 0; }
  71. #ifdef ENABLE_LOL
  72. void setupPart(int animIndex, int part, int firstFrame, int lastFrame, int cycles, int nextPart, int partDelay, int f, int sfxIndex, int sfxFrame);
  73. void start(int animIndex, int part);
  74. void stop(int animIndex);
  75. void update(int animIndex);
  76. void playPart(int animIndex, int firstFrame, int lastFrame, int delay);
  77. int resetLastPart(int animIndex);
  78. #endif
  79. private:
  80. #ifdef ENABLE_LOL
  81. LoLEngine *_vm;
  82. #else
  83. KyraEngine_v1 *_vm;
  84. #endif
  85. Screen_v2 *_screen;
  86. OSystem *_system;
  87. Animation *_animations;
  88. const bool _useParts;
  89. };
  90. struct TIM;
  91. typedef Common::Functor2<const TIM *, const uint16 *, int> TIMOpcode;
  92. struct TIM {
  93. char filename[13];
  94. uint16 clickedButton;
  95. int16 dlgFunc;
  96. int16 procFunc;
  97. uint16 procParam;
  98. enum {
  99. kCountFuncs = 10
  100. };
  101. struct Function {
  102. uint16 *ip;
  103. uint32 lastTime;
  104. uint32 nextTime;
  105. uint16 *loopIp;
  106. uint16 *avtl;
  107. } func[kCountFuncs];
  108. enum {
  109. kWSASlots = 6,
  110. kAnimParts = 10
  111. };
  112. struct WSASlot {
  113. int anim;
  114. int16 x, y;
  115. uint16 wsaFlags;
  116. uint16 offscreen;
  117. } wsa[kWSASlots];
  118. uint16 *avtl;
  119. uint8 *text;
  120. const Common::Array<const TIMOpcode *> *opcodes;
  121. // TODO: Get rid of this ugly HACK to allow the
  122. // Lands of Lore outro to be working properly.
  123. bool isLoLOutro;
  124. uint8 lolCharacter;
  125. };
  126. class TIMInterpreter {
  127. public:
  128. TIMInterpreter(KyraEngine_v1 *engine, Screen_v2 *screen_v2, OSystem *system);
  129. virtual ~TIMInterpreter();
  130. TIM *load(const char *filename, const Common::Array<const TIMOpcode *> *opcodes);
  131. void unload(TIM *&tim) const;
  132. bool callback(Common::IFFChunk &chunk);
  133. virtual int initAnimStruct(int index, const char *filename, int x, int y, int, int offscreenBuffer, uint16 wsaFlags);
  134. virtual int freeAnimStruct(int index);
  135. TimAnimator *animator() { return _animator; }
  136. void setLangData(const char *filename);
  137. void clearLangData() { delete[] _langData; _langData = 0; }
  138. const char *getCTableEntry(uint idx) const;
  139. void resetFinishedFlag() { _finished = false; }
  140. bool finished() const { return _finished; }
  141. int exec(TIM *tim, bool loop);
  142. void stopCurFunc() { if (_currentTim) cmd_stopCurFunc(0); }
  143. void stopAllFuncs(TIM *tim);
  144. void refreshTimersAfterPause(uint32 elapsedTime);
  145. void displayText(uint16 textId, int16 flags);
  146. void displayText(uint16 textId, int16 flags, uint8 color);
  147. void setupTextPalette(uint index, int fadePalette);
  148. virtual void resetDialogueState(TIM *tim) {}
  149. int _drawPage2;
  150. int _palDelayInc, _palDiff, _palDelayAcc;
  151. int _abortFlag;
  152. protected:
  153. KyraEngine_v1 *_vm;
  154. Screen_v2 *_screen;
  155. OSystem *_system;
  156. TIM *_currentTim;
  157. int _currentFunc;
  158. TimAnimator *_animator;
  159. bool _finished;
  160. // used when loading
  161. int _avtlChunkSize;
  162. const char *_filename;
  163. TIM *_tim;
  164. Common::String _vocFiles[120];
  165. virtual void update() {}
  166. virtual void checkSpeechProgress() {}
  167. char _audioFilename[32];
  168. uint8 *_langData;
  169. char *getTableEntry(uint idx);
  170. bool _textDisplayed;
  171. uint8 *_textAreaBuffer;
  172. virtual int execCommand(int cmd, const uint16 *param);
  173. typedef int (TIMInterpreter::*CommandProc)(const uint16 *);
  174. struct CommandEntry {
  175. CommandProc proc;
  176. const char *desc;
  177. };
  178. const CommandEntry *_commands;
  179. int _commandsSize;
  180. int cmd_initFunc0(const uint16 *param);
  181. int cmd_stopCurFunc(const uint16 *param);
  182. int cmd_initWSA(const uint16 *param);
  183. int cmd_uninitWSA(const uint16 *param);
  184. int cmd_initFunc(const uint16 *param);
  185. int cmd_stopFunc(const uint16 *param);
  186. int cmd_wsaDisplayFrame(const uint16 *param);
  187. int cmd_displayText(const uint16 *param);
  188. int cmd_loadVocFile(const uint16 *param);
  189. int cmd_unloadVocFile(const uint16 *param);
  190. int cmd_playVocFile(const uint16 *param);
  191. int cmd_loadSoundFile(const uint16 *param);
  192. int cmd_playMusicTrack(const uint16 *param);
  193. virtual int cmd_setLoopIp(const uint16 *param);
  194. virtual int cmd_continueLoop(const uint16 *param);
  195. int cmd_resetLoopIp(const uint16 *param);
  196. int cmd_resetAllRuntimes(const uint16 *param);
  197. int cmd_execOpcode(const uint16 *param);
  198. int cmd_initFuncNow(const uint16 *param);
  199. int cmd_stopFuncNow(const uint16 *param);
  200. #define cmd_return(n, v) \
  201. int cmd_return_##n(const uint16 *){ return v; }
  202. cmd_return( 1, 1)
  203. cmd_return(n1, -1)
  204. #undef cmd_return
  205. };
  206. #ifdef ENABLE_LOL
  207. class LoLEngine;
  208. class Screen_LoL;
  209. class TIMInterpreter_LoL : public TIMInterpreter {
  210. public:
  211. TIMInterpreter_LoL(LoLEngine *engine, Screen_v2 *screen_v2, OSystem *system);
  212. int initAnimStruct(int index, const char *filename, int x, int y, int frameDelay, int, uint16 wsaCopyParams);
  213. int freeAnimStruct(int index);
  214. void resetDialogueState(TIM *tim);
  215. private:
  216. void update();
  217. void checkSpeechProgress();
  218. char *getTableString(int id);
  219. void advanceToOpcode(int opcode);
  220. LoLEngine *_vm;
  221. Screen_LoL *_screen;
  222. virtual int execCommand(int cmd, const uint16 *param);
  223. typedef int (TIMInterpreter_LoL::*CommandProc)(const uint16 *);
  224. struct CommandEntry {
  225. CommandProc proc;
  226. const char *desc;
  227. };
  228. const CommandEntry *_commands;
  229. int _commandsSize;
  230. int cmd_stopAllFuncs(const uint16 *param);
  231. int cmd_setLoopIp(const uint16 *param);
  232. int cmd_continueLoop(const uint16 *param);
  233. int cmd_processDialogue(const uint16 *param);
  234. int cmd_dialogueBox(const uint16 *param);
  235. };
  236. #endif // ENABLE_LOL
  237. } // End of namespace Kyra
  238. #endif