File: ttm.h

package info (click to toggle)
scummvm 2.9.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 450,268 kB
  • sloc: cpp: 4,297,604; asm: 28,322; python: 12,901; sh: 11,219; java: 8,477; xml: 7,843; perl: 2,633; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (142 lines) | stat: -rw-r--r-- 4,627 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef DGDS_TTM_H
#define DGDS_TTM_H

#include "dgds/scripts.h"
#include "dgds/font.h"

namespace Dgds {

class SoundRaw;

class GetPutRegion {
public:
	Common::Rect _area;
	Common::SharedPtr<Graphics::ManagedSurface> _surf;

	void reset();
};

class TTMEnviro : public ScriptParserData {
public:
	TTMEnviro() : _totalFrames(330), _enviro(0), _creditScrollMeasure(0),
			_creditScrollYOffset(0), _xOff(0), _yOff(0), _xScroll(0), _yScroll(0),
			ScriptParserData() {
		ARRAYCLEAR(_scriptPals);
	}

	Common::Error syncState(Common::Serializer &s);

	uint16 _enviro;
	uint16 _totalFrames;
	Common::Array<int> _frameOffsets;
	Common::SharedPtr<Image> _scriptShapes[6];
	Common::Array<GetPutRegion> _getPuts;
	int _scriptPals[6];
	Common::String _strings[10];
	Common::Array<FontManager::FontType> _fonts;
	int16 _creditScrollMeasure;
	int16 _creditScrollYOffset;
	// The below are all globals in the original, but never get access from
	// multiple environments so cleaner to keep here?
	int16 _xOff;
	int16 _yOff;
	Common::SharedPtr<Image> _scrollShape;
	int16 _xScroll;
	int16 _yScroll;
	Common::SharedPtr<SoundRaw> _soundRaw;
};

enum TTMRunType {
	kRunTypeStopped = 0,
	kRunType1 = 1,
	kRunTypeMulti = 2,
	kRunTypeTimeLimited = 3,
	kRunTypeFinished = 4,
	kRunTypePaused = 5,
};


// Note: this object needs to be safely copy-able - ADS opcodes 0x4000 and 0x4010 require it.
struct TTMSeq {
	TTMSeq() : _enviro(0), _seqNum(0), _startFrame(0), _lastFrame(0), _timeCut(0) {
		// Other members are initialized in the reset function.
		reset();
	}

	void reset();
	Common::Error syncState(Common::Serializer &s);

	int16 _enviro;
	int16 _seqNum;
	int16 _startFrame;	// first frame in this sequence
	int16 _gotoFrame;   // frame to GOTO (or -1 if not currently set)
	int16 _currentFrame; // currently executing frame
	int16 _lastFrame;	// previous frame processed (-1 if none)
	bool _selfLoop;		// does the script frame loop back on itself
	bool _executed;		// has the current frame already been run
	uint32 _timeNext;	// time the next frame should be run
	uint32 _timeCut;	// time to finish execution
	Common::Rect _drawWin;
	// these current ids are called "slot"s in the original
	int16 _currentFontId; 	// aka slot 0
	int16 _currentPalId;	// aka slot 1
	int16 _currentSongId;	// aka slot 3
	int16 _currentBmpId;	// aka slot 4
	int16 _currentGetPutId;	// aka slot 5
	int16 _brushNum;
	byte _drawColFG;
	byte _drawColBG;
	int16 _runPlayed;		// number of times the sequence has been started from ADS
	int16 _runCount;		// number of times to play the sequence before stopping
	int16 _timeInterval;	// interval between frames
	TTMRunType _runFlag;
	int16 _scriptFlag;
};

class TTMInterpreter {
public:
	TTMInterpreter(DgdsEngine *vm);

	bool load(const Common::String &filename, TTMEnviro &env);
	void unload();
	bool run(TTMEnviro &env, TTMSeq &seq);
	void findAndAddSequences(TTMEnviro &scriptData, Common::Array<Common::SharedPtr<TTMSeq>> &seqArray);

	static Common::String readTTMStringVal(Common::SeekableReadStream *scr);

protected:
	void handleOperation(TTMEnviro &env, TTMSeq &seq, uint16 op, byte count, const int16 *ivals, const Common::String &sval, const Common::Array<Common::Point> &pts);
	int32 findGOTOTarget(const TTMEnviro &env, const TTMSeq &seq, int16 frame);
	void doWipeOp(uint16 code, const TTMEnviro &env, const TTMSeq &seq, const Common::Rect &r);
	int16 doOpInitCreditScroll(const Image *img);
	bool doOpCreditsScroll(const Image *img, int16 ygap, int16 ymax, int16 xoff, int16 measuredWidth, const Common::Rect &clipRect);
	void doDrawDialogForStrings(const TTMEnviro &env, const TTMSeq &seq, int16 x, int16 y, int16 width, int16 height);

	DgdsEngine *_vm;
	int _stackDepth;
};

} // end namespace Dgds

#endif // DGDS_TTM_H