ScummVM API documentation
scene.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 ASYLUM_VIEWS_SCENE_H
23 #define ASYLUM_VIEWS_SCENE_H
24 
25 #include "common/array.h"
26 #include "common/events.h"
27 #include "common/rational.h"
28 
29 #include "graphics/surface.h"
30 
31 #include "asylum/system/screen.h"
32 
33 #include "asylum/eventhandler.h"
34 #include "asylum/shared.h"
35 
36 #define SCENE_FILE_MASK "scn.%03d"
37 #define MUSIC_FILE_MASK "mus.%03d"
38 
39 // If defined, will show the scene update times on the debugger output
40 //#define DEBUG_SCENE_TIMES
41 
42 namespace Asylum {
43 
44 class Actor;
45 class AsylumEngine;
46 class Puzzle;
47 class Cursor;
48 class GraphicResource;
49 class Polygons;
50 class Polygon;
51 class ResourcePack;
52 class SceneTitle;
53 class Screen;
54 class Special;
55 class Speech;
56 class Sound;
57 class Text;
58 class VideoPlayer;
59 class WorldStats;
60 
61 struct ActionArea;
62 struct AmbientSoundItem;
63 struct GraphicFrame;
64 struct ObjectItem;
65 
66 enum HitType {
67  kHitNone = -1,
68  kHitActionArea = 2,
69  kHitObject = 3,
70  kHitActor = 4
71 };
72 
73 enum ActionAreaType {
74  kActionAreaType1 = 1,
75  kActionAreaType2 = 2
76 };
77 
78 enum KeyDirection {
79  kWalkUp = 1,
80  kWalkDown = 2,
81  kWalkLeft = 4,
82  kWalkRight = 8
83 };
84 
85 class Scene : public EventHandler {
86 public:
87  Scene(AsylumEngine *engine);
88  virtual ~Scene();
89 
95  void load(ResourcePackId packId);
96 
102  void enter(ResourcePackId packId);
103 
107  void enterLoad();
108 
116  bool handleEvent(const AsylumEvent &ev);
117 
123  ResourcePackId getPackId() { return _packId; }
124 
130  Actor *getActor(ActorIndex index = kActorInvalid);
131 
137  void changePlayer(ActorIndex index);
138 
144  void changePlayerUpdate(ActorIndex index);
145 
157  bool updateSceneCoordinates(int32 targetX, int32 targetY, int32 val, bool checkSceneCoords = false, int32 *param = NULL);
158 
164  bool updateScreen();
165 
169  void updateAmbientSounds();
170 
174  void drawRain();
175 
185  int32 findActionArea(ActionAreaType type, const Common::Point &pt, bool highlight = false);
186 
201  bool rectIntersect(int32 x, int32 y, int32 x1, int32 y1, int32 x2, int32 y2, int32 x3, int32 y3) const;
202 
203  Polygons *polygons() { return _polygons; }
204  WorldStats *worldstats() { return _ws; }
205  uint32 getFrameCounter() { return _frameCounter; }
206 
207  const byte *getSavedPalette() { return _savedPalette; }
208  const Graphics::Surface &getSavedScreen() { return _savedScreen; }
209 
210 private:
211  AsylumEngine *_vm;
212 
213  ResourcePackId _packId;
214 
215  Polygons *_polygons;
216  WorldStats *_ws;
217 
218  struct UpdateItem {
219  ActorIndex index;
220  int32 priority;
221  };
222 
223  // Music volume
224  int32 _musicVolume;
225 
226  Common::Array<UpdateItem> _updateList;
227  uint32 _frameCounter;
228 
229  Graphics::Surface _savedScreen;
230  byte _savedPalette[PALETTE_SIZE];
231 
232  bool _debugShowVersion;
233 
234  byte _keyState;
235  bool _rightButtonDown;
236 
238  // Message handling
239  void activate();
240  bool init();
241  bool update();
242  bool actionDown(AsylumAction a);
243  bool actionUp(AsylumAction a);
244  bool key(const AsylumEvent &evt);
245  bool clickDown(const AsylumEvent &evt);
246 
248  // Scene update
250 
256  bool updateScene();
257 
261  void updateMouse();
262 
266  void updateActors();
267 
271  void updateObjects();
272 
276  void updateMusic();
277 
283  void updateAdjustScreen();
284 
288  void updateCoordinates();
289 
296  void updateCursor(ActorDirection direction, const Common::Rect &rect);
297 
299  // Scene drawing
301 
305  void preload();
306 
312  bool drawScene();
313 
317  void buildUpdateList();
318 
322  void processUpdateList();
323 
332  static bool updateListCompare(const UpdateItem &item1, const UpdateItem &item2);
333 
337  void checkVisibleActorsPriority();
338 
344  void adjustActorPriority(ActorIndex index);
345 
346  int32 _chapter5RainFrameIndex;
347 
349  // HitTest
351 
359  int32 hitTest(HitType &type);
360 
369  int32 hitTestScene(HitType &type);
370 
376  int32 hitTestActionArea();
377 
383  ActorIndex hitTestActor();
384 
390  bool hitTestPlayer();
391 
397  int32 hitTestObject();
398 
410  bool hitTestPixel(ResourceId resourceId, uint32 frame, int16 x, int16 y, bool flipped);
411 
413  // Hit actions
415 
422  void handleHit(int32 index, HitType type);
423 
424  void clickInventory();
425 
426  void hitAreaChapter2(int32 id);
427  bool _isCTRLPressed;
428  int32 _hitAreaChapter7Counter;
429  void hitAreaChapter7(int32 id);
430  void hitAreaChapter11(int32 id);
431 
432  void hitActorChapter2(ActorIndex index);
433  void hitActorChapter11(ActorIndex index);
434 
436  // Helpers
438 
442  void playIntroSpeech();
443 
447  void stopSpeech();
448 
456  bool speak(Common::KeyCode code);
457 
466  bool pointBelowLine(const Common::Point &point, const Common::Rect &rect) const;
467 
473  void adjustCoordinates(Common::Point *point);
474 
476  // Scene debugging
478  void debugShowActors();
479  void debugShowObjects();
480  void debugShowPolygons();
481  void debugShowPolygon(uint32 index, uint32 color = 0xFF);
482  void debugHighlightPolygon(uint32 index);
483  void debugShowSceneRects();
484  void debugScreenScrolling();
485  void debugShowWalkRegion(Polygon *poly);
486 
487  friend class SceneTitle;
488 };
489 
490 } // end of namespace Asylum
491 
492 #endif // ASYLUM_VIEWS_SCENE_H
bool updateSceneCoordinates(int32 targetX, int32 targetY, int32 val, bool checkSceneCoords=false, int32 *param=NULL)
void enterLoad()
Definition: surface.h:67
Actor * getActor(ActorIndex index=kActorInvalid)
Definition: actor.h:86
Definition: asylum.h:53
bool handleEvent(const AsylumEvent &ev)
Definition: rect.h:144
Definition: atari-screen.h:60
Definition: polygons.h:33
void updateAmbientSounds()
Definition: scenetitle.h:32
Definition: polygons.h:50
ResourcePackId getPackId()
Definition: scene.h:123
Definition: worldstats.h:64
void changePlayer(ActorIndex index)
Definition: eventhandler.h:43
bool updateScreen()
void load(ResourcePackId packId)
Definition: atari-cursor.h:38
Definition: eventhandler.h:61
Definition: scene.h:85
Definition: rect.h:45
Definition: asylum.h:73
void changePlayerUpdate(ActorIndex index)
int32 findActionArea(ActionAreaType type, const Common::Point &pt, bool highlight=false)
void enter(ResourcePackId packId)
bool rectIntersect(int32 x, int32 y, int32 x1, int32 y1, int32 x2, int32 y2, int32 x3, int32 y3) const