aboutsummaryrefslogtreecommitdiff
path: root/engines/composer/composer.h
blob: 2025a2ebf3c40ffc3060ff7a316133f884a84cfd (plain)
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/* 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 2
 * 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * $URL$
 * $Id$
 *
 */

#ifndef COMPOSER_H
#define COMPOSER_H

#include "common/config-file.h"
#include "common/random.h"
#include "common/system.h"
#include "common/debug.h"
#include "common/debug-channels.h"
#include "common/textconsole.h"
#include "common/rect.h"

#include "engines/engine.h"
#include "engines/util.h"

#include "graphics/surface.h"

#include "audio/mixer.h"

#include "composer/resource.h"

namespace Audio {
	class QueuingAudioStream;
}

namespace Composer {

struct ComposerGameDescription;

enum GameType {
	GType_ComposerV1,
	GType_ComposerV2
};

class Archive;
class ComposerEngine;

struct Sprite {
	uint16 _id;
	uint16 _animId;
	uint16 _zorder;
	Common::Point _pos;
	Graphics::Surface _surface;

	bool contains(const Common::Point &pos) const;
};

struct AnimationEntry {
	uint32 dword0;
	uint16 op;
	uint16 word6;
	uint16 counter;
	uint16 word10;
};

struct Animation {
	Animation(Common::SeekableReadStream *stream, uint16 id, Common::Point basePos, uint32 eventParam);
	~Animation();

	void seekToCurrPos();

	uint16 _id;
	Common::Point _basePos;
	uint32 _eventParam;
	
	uint32 _state;

	Common::Array<AnimationEntry> _entries;

	uint32 _offset;
	Common::SeekableReadStream *_stream;
};

struct PipeResourceEntry {
	uint32 size;
	uint32 offset;
};

struct PipeResource {
	Common::Array<PipeResourceEntry> entries;
};

class Pipe {
public:
	Pipe(Common::SeekableReadStream *stream);
	void nextFrame();

	Animation *_anim;

        bool hasResource(uint32 tag, uint16 id) const;
	Common::SeekableReadStream *getResource(uint32 tag, uint16 id, bool buffering);

protected:
	Common::SeekableReadStream *_stream;

	typedef Common::HashMap<uint16, PipeResource> ResourceMap;
	typedef Common::HashMap<uint32, ResourceMap> TypeMap;
	TypeMap _types;

	uint32 _offset;
};

enum {
	kButtonRect = 0,
	kButtonEllipse = 1,
	kButtonSprites = 4
};

class Button {
public:
	Button() { }
	Button(Common::SeekableReadStream *stream, uint16 id);

	bool contains(const Common::Point &pos) const;

	uint16 _id;
	uint16 _type;
	uint16 _zorder;
	uint16 _scriptId;
	uint16 _scriptIdRollOn;
	uint16 _scriptIdRollOff;
	bool _active;

	Common::Rect _rect;
	Common::Array<uint16> _spriteIds;
};

struct Library {
	uint _id;
	Archive *_archive;
};

struct QueuedScript {
	uint32 _baseTime;
	uint32 _duration;
	uint32 _count;
	uint16 _scriptId;
};

struct PendingPageChange {
	PendingPageChange() { }
	PendingPageChange(uint16 id, bool remove) : _pageId(id), _remove(remove) { }

	uint16 _pageId;
	bool _remove;
};

class ComposerEngine : public Engine {
protected:
	Common::Error run();

public:
	ComposerEngine(OSystem *syst, const ComposerGameDescription *gameDesc);
	virtual ~ComposerEngine();

	virtual bool hasFeature(EngineFeature f) const;

	int getGameType() const;
	const char *getGameId() const;
	uint32 getFeatures() const;
	Common::Language getLanguage() const;

	const ComposerGameDescription *_gameDescription;

private:
	Common::RandomSource *_rnd;

	Audio::SoundHandle _soundHandle;
	Audio::QueuingAudioStream *_audioStream;

	bool _needsUpdate;
	Graphics::Surface _surface;
	Common::List<Button> _buttons;
	Common::List<Sprite> _sprites;

	uint _directoriesToStrip;
	Common::ConfigFile _bookIni;
	Common::List<Library> _libraries;
	Common::Array<PendingPageChange> _pendingPageChanges;

	Common::Array<uint16> _stack;
	Common::Array<uint16> _vars;

	Common::Array<QueuedScript> _queuedScripts;
	Common::List<Animation *> _anims;
	Common::List<Pipe *> _pipes;

	void onMouseDown(const Common::Point &pos);
	void onMouseMove(const Common::Point &pos);
	void onKeyDown(uint16 keyCode);
	void setCursor(uint16 id, const Common::Point &offset);
	void setCursorVisible(bool visible);

	bool _mouseEnabled;
	bool _mouseVisible;
	Common::Point _lastMousePos;
	const Button *_lastButton;
	uint16 _mouseSpriteId;
	Common::Point _mouseOffset;

	Common::String getStringFromConfig(const Common::String &section, const Common::String &key);
	Common::String getFilename(const Common::String &section, uint id);
	void loadLibrary(uint id);
	void unloadLibrary(uint id);

	bool hasResource(uint32 tag, uint16 id);
	Common::SeekableReadStream *getResource(uint32 tag, uint16 id);

	void runEvent(uint16 id, int16 param1, int16 param2, int16 param3);
	int16 runScript(uint16 id, int16 param1, int16 param2, int16 param3);

	int16 getArg(uint16 arg, uint16 type);
	void setArg(uint16 arg, uint16 type, uint16 val);
	void runScript(uint16 id);
	int16 scriptFuncCall(uint16 id, int16 param1, int16 param2, int16 param3);

	void playAnimation(uint16 animId, int16 param1, int16 param2, int16 param3);
	void stopAnimation(Animation *anim, bool localOnly = false, bool pipesOnly = false);
	void playWaveForAnim(uint16 id, bool bufferingOnly);
	void processAnimFrame();

	bool spriteVisible(uint16 id, uint16 animId);
	void addSprite(uint16 id, uint16 animId, uint16 zorder, const Common::Point &pos);
	void removeSprite(uint16 id, uint16 animId);
	const Sprite *getSpriteAtPos(const Common::Point &pos);
	const Button *getButtonFor(const Sprite *sprite, const Common::Point &pos);

	void redraw();
	void loadCTBL(uint id, uint fadePercent);
	void decompressBitmap(uint16 type, Common::SeekableReadStream *stream, byte *buffer, uint32 size, uint width, uint height);
	bool initSprite(Sprite &sprite);
	Common::SeekableReadStream *getStreamForSprite(uint16 id);
	void drawSprite(const Sprite &sprite);
};

} // End of namespace Composer

#endif