ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ttm.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 DGDS_TTM_H
23 #define DGDS_TTM_H
24 
25 #include "dgds/scripts.h"
26 #include "dgds/font.h"
27 
28 namespace Dgds {
29 
30 class SoundRaw;
31 
32 class GetPutRegion {
33 public:
34  Common::Rect _area;
36 
37  void reset();
38 };
39 
40 class TTMEnviro : public ScriptParserData {
41 public:
42  TTMEnviro() : _totalFrames(330), _enviro(0), _creditScrollMeasure(0),
43  _creditScrollYOffset(0), _xOff(0), _yOff(0), _xScroll(0), _yScroll(0),
44  _lastSelectedSample(0), ScriptParserData() {
45  ARRAYCLEAR(_scriptPals);
46  }
47 
48  Common::Error syncState(Common::Serializer &s);
49 
50  uint16 _enviro;
51  uint16 _totalFrames;
52  Common::Array<int> _frameOffsets;
53  Common::SharedPtr<Image> _scriptShapes[6];
55  int _scriptPals[6];
56  Common::String _strings[10];
58  int16 _creditScrollMeasure;
59  int16 _creditScrollYOffset;
60  // The below are all globals in the original, but never get access from
61  // multiple environments so cleaner to keep here?
62  int16 _xOff;
63  int16 _yOff;
64  Common::SharedPtr<Image> _scrollShape;
65  int16 _xScroll;
66  int16 _yScroll;
68  int16 _lastSelectedSample;
69 };
70 
71 enum TTMRunType {
72  kRunTypeStopped = 0,
73  kRunTypeKeepGoing = 1,
74  kRunTypeMulti = 2,
75  kRunTypeTimeLimited = 3,
76  kRunTypeFinished = 4,
77  kRunTypePaused = 5,
78 };
79 
80 
81 // Note: this object needs to be safely copy-able - ADS opcodes 0x4000 and 0x4010 require it.
82 struct TTMSeq {
83  TTMSeq() : _enviro(0), _seqNum(0), _startFrame(0), _lastFrame(0), _timeCut(0),
84  _currentBmpId(0), _currentGetPutId(0) {
85  // Other members are initialized in the reset function.
86  reset();
87  }
88 
89  void reset();
90  Common::Error syncState(Common::Serializer &s);
91 
92  int16 _enviro;
93  int16 _seqNum;
94  int16 _startFrame; // first frame in this sequence
95  int16 _gotoFrame; // frame to GOTO (or -1 if not currently set)
96  int16 _currentFrame; // currently executing frame
97  int16 _lastFrame; // previous frame processed (-1 if none)
98  bool _selfLoop; // does the script frame loop back on itself
99  bool _executed; // has the current frame already been run
100  uint32 _timeNext; // time the next frame should be run
101  uint32 _timeCut; // time to finish execution
102  Common::Rect _drawWin;
103  // these current ids are called "slot"s in the original
104  int16 _currentFontId; // aka slot 0
105  int16 _currentPalId; // aka slot 1
106  int16 _currentSongId; // aka slot 3
107  int16 _currentBmpId; // aka slot 4
108  int16 _currentGetPutId; // aka slot 5
109  int16 _brushNum;
110  byte _drawColFG;
111  byte _drawColBG;
112  int16 _runPlayed; // number of times the sequence has been started from ADS
113  int16 _runCount; // number of times to play the sequence before stopping
114  int16 _timeInterval; // interval between frames
115  TTMRunType _runFlag;
116  int16 _scriptFlag;
117 };
118 
120 public:
122  virtual ~TTMInterpreter() {};
123 
124  bool load(const Common::String &filename, TTMEnviro &env);
125  void unload();
126  bool run(TTMEnviro &env, TTMSeq &seq);
127  void findAndAddSequences(TTMEnviro &scriptData, Common::Array<Common::SharedPtr<TTMSeq>> &seqArray);
128 
129  static Common::String readTTMStringVal(Common::SeekableReadStream *scr);
130  int32 findGOTOTarget(const TTMEnviro &env, const TTMSeq &seq, int16 frame);
131 
132 protected:
133  virtual void handleOperation(TTMEnviro &env, TTMSeq &seq, uint16 op, byte count, const int16 *ivals, const Common::String &sval, const Common::Array<Common::Point> &pts);
134  void doWipeOp(uint16 code, const TTMEnviro &env, const TTMSeq &seq, const Common::Rect &r);
135  int16 doInitCreditScrollOp(const Image *img);
136  bool doCreditsScrollOp(const Image *img, int16 ygap, int16 ymax, int16 xoff, int16 measuredWidth, const Common::Rect &clipRect);
137  void doDrawDialogForStrings(const TTMEnviro &env, const TTMSeq &seq, int16 x, int16 y, int16 width, int16 height);
138  void doDrawSpriteOp(const TTMEnviro &env, const TTMSeq &seq, uint16 op, byte count, const int16 *ivals);
139  void doFadeOutOp(int16 colorno, int16 ncolors, int16 targetcol, int16 speed);
140  void doFadeInOp(int16 colorno, int16 ncolors, int16 targetcol, int16 speed);
141 
142  static const char *ttmOpName(uint16 op);
143 
144  DgdsEngine *_vm;
145  int _stackDepth;
146 };
147 
148 } // end namespace Dgds
149 
150 #endif // DGDS_TTM_H
void ARRAYCLEAR(T(&array) [N], const T &value=T())
Definition: util.h:103
Definition: str.h:59
Definition: ttm.h:40
Definition: ttm.h:32
Definition: error.h:84
Definition: ads.h:28
Definition: rect.h:144
Definition: stream.h:745
Definition: serializer.h:79
Definition: scripts.h:29
Definition: dgds.h:120
Definition: movie_decoder.h:32
Definition: ttm.h:82
Definition: ttm.h:119