File: scene.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 (492 lines) | stat: -rw-r--r-- 11,354 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
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
/* 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 ASYLUM_VIEWS_SCENE_H
#define ASYLUM_VIEWS_SCENE_H

#include "common/array.h"
#include "common/events.h"
#include "common/rational.h"

#include "graphics/surface.h"

#include "asylum/system/screen.h"

#include "asylum/eventhandler.h"
#include "asylum/shared.h"

#define SCENE_FILE_MASK "scn.%03d"
#define MUSIC_FILE_MASK "mus.%03d"

// If defined, will show the scene update times on the debugger output
//#define DEBUG_SCENE_TIMES

namespace Asylum {

class Actor;
class AsylumEngine;
class Puzzle;
class Cursor;
class GraphicResource;
class Polygons;
class Polygon;
class ResourcePack;
class SceneTitle;
class Screen;
class Special;
class Speech;
class Sound;
class Text;
class VideoPlayer;
class WorldStats;

struct ActionArea;
struct AmbientSoundItem;
struct GraphicFrame;
struct ObjectItem;

enum HitType {
	kHitNone       = -1,
	kHitActionArea = 2,
	kHitObject    = 3,
	kHitActor      = 4
};

enum ActionAreaType {
	kActionAreaType1 = 1,
	kActionAreaType2 = 2
};

enum KeyDirection {
	kWalkUp = 1,
	kWalkDown = 2,
	kWalkLeft = 4,
	kWalkRight = 8
};

class Scene : public EventHandler {
public:
	Scene(AsylumEngine *engine);
	virtual ~Scene();

	/**
	 * Load the scene data
	 *
	 * @param packId Package id for the scene.
	 */
	void load(ResourcePackId packId);

	/**
	 * Enter a scene
	 *
	 * @param packId Package id for the scene.
	 */
	void enter(ResourcePackId packId);

	/**
	 * Enter the scene after a loaded game
	 */
	void enterLoad();

	/**
	 * Handle events
	 *
	 * @param ev The event
	 *
	 * @return true if it succeeds, false if it fails.
	 */
	bool handleEvent(const AsylumEvent &ev);

	/**
	 * Gets the current scene pack identifier.
	 *
	 * @return The pack identifier.
	 */
	ResourcePackId  getPackId() { return _packId; }

	/**
	 * Get a reference to an actor object from the
	 * WorldStats actor list. Default parameter just
	 * gets the instance associated with _playerActorIdx
	 */
	Actor *getActor(ActorIndex index = kActorInvalid);

	/**
	 * Change player actor
	 *
	 * @param index new index for the player actor
	 */
	void changePlayer(ActorIndex index);

	/**
	 * Update player position when changing current player
	 *
	 * @param index Zero-based index of the actor
	 */
	void changePlayerUpdate(ActorIndex index);

	/**
	 * Updates the scene coordinates.
	 *
	 * @param targetX 		   Target x coordinate.
	 * @param targetY 		   Target y coordinate.
	 * @param val 			   The value.
	 * @param checkSceneCoords true to check scene coordinates.
	 * @param [in,out] param   If non-null, the parameter.
	 *
	 * @return true if it succeeds, false if it fails.
	 */
	bool updateSceneCoordinates(int32 targetX, int32 targetY, int32 val, bool checkSceneCoords = false, int32 *param = NULL);

	/**
	 * Updates the screen
	 *
	 * @return true if it succeeds, false if it fails.
	 */
	bool updateScreen();

	/**
	 * Updates the ambient sounds.
	 */
	void updateAmbientSounds();

	/**
	 * Rain drawing function for chapter 5.
	 */
	void drawRain();

	/**
	 * 	Determine if the supplied point intersects an action area's active region.
	 *
	 * @param	type	 	The type.
	 * @param	pt		 	The point.
	 * @param	highlight	(optional) whether to highlight the polygons as they are checked.
	 *
	 * @return	The found action area.
	 */
	int32 findActionArea(ActionAreaType type, const Common::Point &pt, bool highlight = false);

	/**
	 * Check if rectangles intersect.
	 *
	 * @param x  The x coordinate.
	 * @param y  The y coordinate.
	 * @param x1 The first x value.
	 * @param y1 The first y value.
	 * @param x2 The second x value.
	 * @param y2 The second y value.
	 * @param x3 The third int32.
	 * @param y3 The third int32.
	 *
	 * @return true if it succeeds, false if it fails.
	 */
	bool rectIntersect(int32 x, int32 y, int32 x1, int32 y1, int32 x2, int32 y2, int32 x3, int32 y3) const;

	Polygons    *polygons()   { return _polygons; }
	WorldStats  *worldstats() { return _ws; }
	uint32 getFrameCounter() { return _frameCounter; }

	const byte *getSavedPalette() { return _savedPalette; }
	const Graphics::Surface &getSavedScreen() { return _savedScreen; }

private:
	AsylumEngine  *_vm;

	ResourcePackId _packId;

	Polygons     *_polygons;
	WorldStats   *_ws;

	struct UpdateItem {
		ActorIndex index;
		int32 priority;
	};

	// Music volume
	int32 _musicVolume;

	Common::Array<UpdateItem> _updateList;
	uint32 _frameCounter;

	Graphics::Surface _savedScreen;
	byte _savedPalette[PALETTE_SIZE];

	bool _debugShowVersion;

	byte _keyState;
	bool _rightButtonDown;

	//////////////////////////////////////////////////////////////////////////
	// Message handling
	void activate();
	bool init();
	bool update();
	bool actionDown(AsylumAction a);
	bool actionUp(AsylumAction a);
	bool key(const AsylumEvent &evt);
	bool clickDown(const AsylumEvent &evt);

	//////////////////////////////////////////////////////////////////////////
	// Scene update
	//////////////////////////////////////////////////////////////////////////

	/**
	 * Loop through the various update blocks (actors, objects, mouse, music, sfx, coordinates), then process the current action script.
	 *
	 * @return true if the script is done executing, false otherwise
	 */
	bool updateScene();

	/**
	 * Updates the mouse.
	 */
	void updateMouse();

	/**
	 * Updates the actors.
	 */
	void updateActors();

	/**
	 * Updates the objects.
	 */
	void updateObjects();

	/**
	 * Updates the music.
	 */
	void updateMusic();

	/**
	 * Updates the screen
	 *
	 *  - update coordinates or allow scrolling if the proper debug option is set
	 */
	void updateAdjustScreen();

	/**
	 * Updates the screen coordinates.
	 */
	void updateCoordinates();

	/**
	 * Update cursor
	 *
	 * @param direction The direction.
	 * @param rect 		The rectangle.
	 */
	void updateCursor(ActorDirection direction, const Common::Rect &rect);

	//////////////////////////////////////////////////////////////////////////
	// Scene drawing
	//////////////////////////////////////////////////////////////////////////

	/**
	 * Draw the loading screen
	 */
	void preload();

	/**
	 * Draw the scene
	 *
	 * @return true if it succeeds, false if it fails.
	 */
	bool drawScene();

	/**
	 * Builds the update list.
	 */
	void buildUpdateList();

	/**
	 * Process the update list.
	 */
	void processUpdateList();

	/**
	 * Compare two items priority on the update list
	 *
	 * @param item1 The first item.
	 * @param item2 The second item.
	 *
	 * @return true item1 priority is superior to item2 priority, false otherwise
	 */
	static bool updateListCompare(const UpdateItem &item1, const UpdateItem &item2);

	/**
	 * Check visible actors priority.
	 */
	void checkVisibleActorsPriority();

	/**
	 * Adjust actor priority.
	 *
	 * @param index Zero-based index of the actor
	 */
	void adjustActorPriority(ActorIndex index);

	int32 _chapter5RainFrameIndex;

	//////////////////////////////////////////////////////////////////////////
	// HitTest
	//////////////////////////////////////////////////////////////////////////

	/**
	 * Run various hit tests and return the index, and a reference to the located type.
	 *
	 * @param [in,out] type The type.
	 *
	 * @return The index
	 */
	int32 hitTest(HitType &type);

	/**
	 * Checks if the supplied coordinates are inside an action area, object or actor, and returns -1 if nothing was found, or the type of hit if
	 * found.
	 *
	 * @param [in,out] type The type.
	 *
	 * @return The Index
	 */
	int32 hitTestScene(HitType &type);

	/**
	 * Check if the mouse cursor is currently intersecting an action area
	 *
	 * @return the index
	 */
	int32 hitTestActionArea();

	/**
	 * Check if the mouse cursor is currently intersecting the currently active actor.
	 *
	 * @return The actor index
	 */
	ActorIndex hitTestActor();

	/**
	 * Check if the mouse cursor is currently intersecting the player.
	 *
	 * @return true if it succeeds, false if it fails.
	 */
	bool hitTestPlayer();

	/**
	 * Check if a object exist at the supplied coordinates. If so, return it's index within the objects array, if not, return -1.
	 *
	 * @return the object index
	 */
	int32 hitTestObject();

	/**
	 * Check if the mouse cursor is currently intersecting a graphic resource at the supplied coordinates.
	 *
	 * @param resourceId Identifier for the resource.
	 * @param frame 	 The frame.
	 * @param x 		 The x coordinate.
	 * @param y 		 The y coordinate.
	 * @param flipped    true to flipped.
	 *
	 * @return true if it succeeds, false if it fails.
	 */
	bool hitTestPixel(ResourceId resourceId, uint32 frame, int16 x, int16 y, bool flipped);

	//////////////////////////////////////////////////////////////////////////
	// Hit actions
	//////////////////////////////////////////////////////////////////////////

	/**
	 * Handle hit
	 *
	 * @param index The index
	 * @param type  The type.
	 */
	void handleHit(int32 index, HitType type);

	void clickInventory();

	void hitAreaChapter2(int32 id);
	bool _isCTRLPressed;
	int32 _hitAreaChapter7Counter;
	void hitAreaChapter7(int32 id);
	void hitAreaChapter11(int32 id);

	void hitActorChapter2(ActorIndex index);
	void hitActorChapter11(ActorIndex index);

	//////////////////////////////////////////////////////////////////////////
	// Helpers
	//////////////////////////////////////////////////////////////////////////

	/**
	 * Play intro speech.
	 */
	void playIntroSpeech();

	/**
	 * Stop speech.
	 */
	void stopSpeech();

	/**
	 * Play specific speech.
	 *
	 * @param code The key code.
	 *
	 * @return true if it succeeds, false if it fails.
	 */
	bool speak(Common::KeyCode code);

	/**
	 * Check if a point lies below the rectangle's top-left to bottom-right diagonal.
	 *
	 * @param point The point.
	 * @param rect  The rectangle.
	 *
	 * @return true if below, false if above.
	 */
	bool pointBelowLine(const Common::Point &point, const Common::Rect &rect) const;

	/**
	 * Adjust coordinates.
	 *
	 * @param point The point.
	 */
	void adjustCoordinates(Common::Point *point);

	//////////////////////////////////////////////////////////////////////////
	// Scene debugging
	//////////////////////////////////////////////////////////////////////////
	void debugShowActors();
	void debugShowObjects();
	void debugShowPolygons();
	void debugShowPolygon(uint32 index, uint32 color = 0xFF);
	void debugHighlightPolygon(uint32 index);
	void debugShowSceneRects();
	void debugScreenScrolling();
	void debugShowWalkRegion(Polygon *poly);

	friend class SceneTitle;
};

} // end of namespace Asylum

#endif // ASYLUM_VIEWS_SCENE_H