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 NEVERHOOD_SCENE_H
23 #define NEVERHOOD_SCENE_H
24 
25 #include "common/array.h"
26 #include "neverhood/neverhood.h"
27 #include "neverhood/background.h"
28 #include "neverhood/entity.h"
29 #include "neverhood/graphics.h"
30 #include "neverhood/klaymen.h"
31 #include "neverhood/module.h"
32 #include "neverhood/palette.h"
33 #include "neverhood/sprite.h"
34 #include "neverhood/staticdata.h"
35 
36 namespace Neverhood {
37 
38 class Console;
39 class SmackerPlayer;
40 
41 class Scene : public Entity {
42 public:
43  Scene(NeverhoodEngine *vm, Module *parentModule);
44  ~Scene() override;
45  void draw() override;
46  void addEntity(Entity *entity);
47  bool removeEntity(Entity *entity);
48  void addSurface(const Common::SharedPtr<BaseSurface> &surface);
49  bool removeSurface(const Common::SharedPtr<BaseSurface> &surface);
50  void printSurfaces(Console *con);
51  Sprite *addSprite(Sprite *sprite);
52  void removeSprite(Sprite *sprite);
53  void setSurfacePriority(const Common::SharedPtr<BaseSurface> &surface, int priority);
54  void setSpriteSurfacePriority(Sprite *sprite, int priority);
55  void deleteSprite(Sprite **sprite);
56  Background *addBackground(Background *background);
57  void setBackground(uint32 fileHash);
58  void changeBackground(uint32 fileHash);
59  void setBackgroundY(int16 y) { _background->getSurface()->getDrawRect().y = y; }
60  int16 getBackgroundY() { return _background->getSurface()->getDrawRect().y; }
61  void setPalette(uint32 fileHash = 0);
62  void setHitRects(uint32 id);
63  Sprite *insertStaticSprite(uint32 fileHash, int surfacePriority);
64  void insertScreenMouse(uint32 fileHash, const NRect *mouseRect = NULL);
65  void insertPuzzleMouse(uint32 fileHash, int16 x1, int16 x2);
66  void insertNavigationMouse(uint32 fileHash, int type);
67  void showMouse(bool visible);
68  void changeMouseCursor(uint32 fileHash);
69  SmackerPlayer *addSmackerPlayer(SmackerPlayer *smackerPlayer);
70  void update();
71  void leaveScene(uint32 result);
72  HitRect *findHitRectAtPos(int16 x, int16 y);
73  void addCollisionSprite(Sprite *sprite);
74  void removeCollisionSprite(Sprite *sprite);
75  void checkCollision(Sprite *sprite, uint16 flags, int messageNum, uint32 messageParam);
76  // Some crazy templated functions to make the logic code smaller/simpler (imo!)
77  // insertKlaymen
78  template<class T>
79  void insertKlaymen() {
80  _klaymen = (T*)addSprite(new T(_vm, this));
81  }
82  template<class T, class Arg1>
83  void insertKlaymen(Arg1 arg1) {
84  _klaymen = (T*)addSprite(new T(_vm, this, arg1));
85  }
86  template<class T, class Arg1, class Arg2>
87  void insertKlaymen(Arg1 arg1, Arg2 arg2) {
88  _klaymen = (T*)addSprite(new T(_vm, this, arg1, arg2));
89  }
90  template<class T, class Arg1, class Arg2, class Arg3>
91  void insertKlaymen(Arg1 arg1, Arg2 arg2, Arg3 arg3) {
92  _klaymen = (T*)addSprite(new T(_vm, this, arg1, arg2, arg3));
93  }
94  template<class T, class Arg1, class Arg2, class Arg3, class Arg4>
95  void insertKlaymen(Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4) {
96  _klaymen = (T*)addSprite(new T(_vm, this, arg1, arg2, arg3, arg4));
97  }
98  template<class T, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
99  void insertKlaymen(Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5) {
100  _klaymen = (T*)addSprite(new T(_vm, this, arg1, arg2, arg3, arg4, arg5));
101  }
102  template<class T, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6>
103  void insertKlaymen(Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6) {
104  _klaymen = (T*)addSprite(new T(_vm, this, arg1, arg2, arg3, arg4, arg5, arg6));
105  }
106  // insertSprite
107  template<class T>
108  T* insertSprite() {
109  return (T*)addSprite(new T(_vm));
110  }
111  template<class T, class Arg1>
112  T* insertSprite(Arg1 arg1) {
113  return (T*)addSprite(new T(_vm, arg1));
114  }
115  template<class T, class Arg1, class Arg2>
116  T* insertSprite(Arg1 arg1, Arg2 arg2) {
117  return (T*)addSprite(new T(_vm, arg1, arg2));
118  }
119  template<class T, class Arg1, class Arg2, class Arg3>
120  T* insertSprite(Arg1 arg1, Arg2 arg2, Arg3 arg3) {
121  return (T*)addSprite(new T(_vm, arg1, arg2, arg3));
122  }
123  template<class T, class Arg1, class Arg2, class Arg3, class Arg4>
124  T* insertSprite(Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4) {
125  return (T*)addSprite(new T(_vm, arg1, arg2, arg3, arg4));
126  }
127  template<class T, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
128  T* insertSprite(Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5) {
129  return (T*)addSprite(new T(_vm, arg1, arg2, arg3, arg4, arg5));
130  }
131  template<class T, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6>
132  T* insertSprite(Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6) {
133  return (T*)addSprite(new T(_vm, arg1, arg2, arg3, arg4, arg5, arg6));
134  }
135  // createSprite
136  template<class T>
137  T* createSprite() {
138  return new T(_vm);
139  }
140  template<class T, class Arg1>
141  T* createSprite(Arg1 arg1) {
142  return new T(_vm, arg1);
143  }
144  template<class T, class Arg1, class Arg2>
145  T* createSprite(Arg1 arg1, Arg2 arg2) {
146  return new T(_vm, arg1, arg2);
147  }
148  template<class T, class Arg1, class Arg2, class Arg3>
149  T* createSprite(Arg1 arg1, Arg2 arg2, Arg3 arg3) {
150  return new T(_vm, arg1, arg2, arg3);
151  }
152  template<class T, class Arg1, class Arg2, class Arg3, class Arg4>
153  T* createSprite(Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4) {
154  return new T(_vm, arg1, arg2, arg3, arg4);
155  }
156  template<class T, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
157  T* createSprite(Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5) {
158  return new T(_vm, arg1, arg2, arg3, arg4, arg5);
159  }
160  template<class T, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6>
161  T* createSprite(Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6) {
162  return new T(_vm, arg1, arg2, arg3, arg4, arg5, arg6);
163  }
164 
165  uint32 getBackgroundFileHash() const { return _backgroundFileHash; }
166  uint32 getCursorFileHash() const { return _cursorFileHash; }
167 
168 protected:
169  Module *_parentModule;
170  Common::Array<Entity*> _entities;
172 
173  Klaymen *_klaymen;
174  Background *_background;
175  Palette *_palette;
176  SmackerPlayer *_smackerPlayer;
177 
178  MessageList *_messageList;
179  MessageList *_messageList2;
180  int _messageListStatus;
181  uint _messageListCount;
182  uint _messageListIndex;
183  bool _doConvertMessages;
184 
185  bool _canAcceptInput;
186  bool _isKlaymenBusy;
187  bool _isMessageListBusy;
188 
189  Mouse *_mouseCursor;
190  NPoint _mouseClickPos;
191  bool _mouseClicked;
192  bool _mouseCursorWasVisible;
193 
194  int _rectType;
195  RectList *_rectList;
196  DataResource _dataResource;
197 
198  HitRectList _hitRectList;
199 
200  HitRectList *_hitRects;
201  Common::Array<Sprite*> _collisionSprites;
202 
203  // Used for debugging
204  uint32 _backgroundFileHash, _cursorFileHash; // for StaticScene and all Scene* classes
205 
206  int _messageValue;
207  uint32 handleMessage(int messageNum, const MessageParam &param, Entity *sender);
208  bool queryPositionSprite(int16 mouseX, int16 mouseY);
209  bool queryPositionRectList(int16 mouseX, int16 mouseY);
210  void setMessageList(uint32 id, bool canAcceptInput = true, bool doConvertMessages = false);
211  void setMessageList(MessageList *messageList, bool canAcceptInput = true, bool doConvertMessages = false);
212  bool setMessageList2(uint32 id, bool canAcceptInput = true, bool doConvertMessages = false);
213  bool setMessageList2(MessageList *messageList, bool canAcceptInput = true, bool doConvertMessages = false);
214  bool isMessageList2(uint32 id);
215  void processMessageList();
216  void setRectList(uint32 id);
217  void setRectList(RectList *rectList);
218  void clearRectList();
219  void loadHitRectList();
220  void cancelMessageList();
221  void loadDataResource(uint32 fileHash);
222  uint16 convertMessageNum(uint32 messageNum);
223 
224  void setHitRects(HitRectList *hitRects);
225  void clearHitRects();
226  void clearCollisionSprites();
227 
228  void insertMouse(Mouse *mouseCursor);
229 };
230 
231 
232 class StaticScene : public Scene {
233 public:
234  StaticScene(NeverhoodEngine *vm, Module *parentModule, uint32 backgroundFileHash, uint32 cursorFileHash);
235 protected:
236  uint32 handleMessage(int messageNum, const MessageParam &param, Entity *sender);
237 };
238 
239 } // End of namespace Neverhood
240 
241 #endif /* NEVERHOOD_SCENE_H */
Definition: background.h:30
Definition: neverhood.h:60
Definition: array.h:52
Definition: palette.h:30
Definition: graphics.h:42
Definition: entity.h:42
Definition: background.h:32
Definition: scene.h:232
Definition: entity.h:77
Definition: smackerplayer.h:61
Definition: resource.h:162
Definition: scene.h:41
Definition: sprite.h:54
Definition: module.h:45
Definition: staticdata.h:32
Definition: mouse.h:38
Definition: ptr.h:159
Definition: klaymen.h:59
Definition: console.h:31
Definition: graphics.h:32