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 class Scene : public EventHandler {
79 public:
80  Scene(AsylumEngine *engine);
81  virtual ~Scene();
82 
88  void load(ResourcePackId packId);
89 
95  void enter(ResourcePackId packId);
96 
100  void enterLoad();
101 
109  bool handleEvent(const AsylumEvent &ev);
110 
116  ResourcePackId getPackId() { return _packId; }
117 
123  Actor *getActor(ActorIndex index = kActorInvalid);
124 
130  void changePlayer(ActorIndex index);
131 
137  void changePlayerUpdate(ActorIndex index);
138 
150  bool updateSceneCoordinates(int32 targetX, int32 targetY, int32 val, bool checkSceneCoords = false, int32 *param = NULL);
151 
157  bool updateScreen();
158 
162  void updateAmbientSounds();
163 
167  void drawRain();
168 
178  int32 findActionArea(ActionAreaType type, const Common::Point &pt, bool highlight = false);
179 
194  bool rectIntersect(int32 x, int32 y, int32 x1, int32 y1, int32 x2, int32 y2, int32 x3, int32 y3) const;
195 
196  Polygons *polygons() { return _polygons; }
197  WorldStats *worldstats() { return _ws; }
198  uint32 getFrameCounter() { return _frameCounter; }
199 
200  const byte *getSavedPalette() { return _savedPalette; }
201  const Graphics::Surface &getSavedScreen() { return _savedScreen; }
202 
203 private:
204  AsylumEngine *_vm;
205 
206  ResourcePackId _packId;
207 
208  Polygons *_polygons;
209  WorldStats *_ws;
210 
211  struct UpdateItem {
212  ActorIndex index;
213  int32 priority;
214  };
215 
216  // Music volume
217  int32 _musicVolume;
218 
219  Common::Array<UpdateItem> _updateList;
220  uint32 _frameCounter;
221 
222  Graphics::Surface _savedScreen;
223  byte _savedPalette[PALETTE_SIZE];
224 
225  bool _debugShowVersion;
226 
228  // Message handling
229  void activate();
230  bool init();
231  bool update();
232  bool action(AsylumAction a);
233  bool key(const AsylumEvent &evt);
234  bool clickDown(const AsylumEvent &evt);
235 
237  // Scene update
239 
245  bool updateScene();
246 
250  void updateMouse();
251 
255  void updateActors();
256 
260  void updateObjects();
261 
265  void updateMusic();
266 
272  void updateAdjustScreen();
273 
277  void updateCoordinates();
278 
285  void updateCursor(ActorDirection direction, const Common::Rect &rect);
286 
288  // Scene drawing
290 
294  void preload();
295 
301  bool drawScene();
302 
306  void buildUpdateList();
307 
311  void processUpdateList();
312 
321  static bool updateListCompare(const UpdateItem &item1, const UpdateItem &item2);
322 
326  void checkVisibleActorsPriority();
327 
333  void adjustActorPriority(ActorIndex index);
334 
335  int32 _chapter5RainFrameIndex;
336 
338  // HitTest
340 
348  int32 hitTest(HitType &type);
349 
358  int32 hitTestScene(HitType &type);
359 
365  int32 hitTestActionArea();
366 
372  ActorIndex hitTestActor();
373 
379  bool hitTestPlayer();
380 
386  int32 hitTestObject();
387 
399  bool hitTestPixel(ResourceId resourceId, uint32 frame, int16 x, int16 y, bool flipped);
400 
402  // Hit actions
404 
411  void handleHit(int32 index, HitType type);
412 
413  void clickInventory();
414 
415  void hitAreaChapter2(int32 id);
416  bool _isCTRLPressed;
417  int32 _hitAreaChapter7Counter;
418  void hitAreaChapter7(int32 id);
419  void hitAreaChapter11(int32 id);
420 
421  void hitActorChapter2(ActorIndex index);
422  void hitActorChapter11(ActorIndex index);
423 
425  // Helpers
427 
431  void playIntroSpeech();
432 
436  void stopSpeech();
437 
445  bool speak(Common::KeyCode code);
446 
455  bool pointBelowLine(const Common::Point &point, const Common::Rect &rect) const;
456 
462  void adjustCoordinates(Common::Point *point);
463 
465  // Scene debugging
467  void debugShowActors();
468  void debugShowObjects();
469  void debugShowPolygons();
470  void debugShowPolygon(uint32 index, uint32 color = 0xFF);
471  void debugHighlightPolygon(uint32 index);
472  void debugShowSceneRects();
473  void debugScreenScrolling();
474  void debugShowWalkRegion(Polygon *poly);
475 
476  friend class SceneTitle;
477 };
478 
479 } // end of namespace Asylum
480 
481 #endif // ASYLUM_VIEWS_SCENE_H
bool updateSceneCoordinates(int32 targetX, int32 targetY, int32 val, bool checkSceneCoords=false, int32 *param=NULL)
void enterLoad()
Definition: surface.h:66
Actor * getActor(ActorIndex index=kActorInvalid)
Definition: actor.h:86
Definition: asylum.h:53
Definition: default_display_client.h:78
bool handleEvent(const AsylumEvent &ev)
Definition: rect.h:144
Definition: polygons.h:33
void updateAmbientSounds()
Definition: scenetitle.h:32
Definition: polygons.h:50
ResourcePackId getPackId()
Definition: scene.h:116
Definition: worldstats.h:64
void changePlayer(ActorIndex index)
Definition: eventhandler.h:43
bool updateScreen()
void load(ResourcePackId packId)
Definition: eventhandler.h:61
Definition: scene.h:78
Definition: rect.h:45
Definition: asylum.h:70
Definition: cursor.h:27
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