ScummVM API documentation
set.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 GRIM_SET_H
23 #define GRIM_SET_H
24 
25 #include "engines/grim/pool.h"
26 #include "engines/grim/object.h"
27 #include "engines/grim/color.h"
28 #include "engines/grim/sector.h"
29 #include "engines/grim/objectstate.h"
30 
31 #include "math/quat.h"
32 #include "math/frustum.h"
33 
34 namespace Common {
35  class SeekableReadStream;
36 }
37 namespace Grim {
38 
39 class SaveGame;
40 class CMap;
41 struct Light;
42 struct SetShadow;
43 
44 class Set : public PoolObject<Set> {
45 public:
46  Set(const Common::String &name, Common::SeekableReadStream *data);
47  Set();
48  ~Set();
49 
50  struct Setup;
51 
52  static int32 getStaticTag() { return MKTAG('S', 'E', 'T', ' '); }
53 
54  void loadText(TextSplitter &ts);
55  void loadBinary(Common::SeekableReadStream *data);
56  void setupOverworldLights();
57 
58  void saveState(SaveGame *savedState) const;
59  bool restoreState(SaveGame *savedState);
60 
61  int _minVolume;
62  int _maxVolume;
63 
64  static Bitmap::Ptr loadBackground(const char *fileName);
65  void drawBackground() const;
66  void drawBitmaps(ObjectState::Position stage);
67  void setupCamera();
68 
69  void setupLights(const Math::Vector3d &pos, bool inOverworld);
70 
71  void setSoundPosition(const char *soundName, const Math::Vector3d &pos);
72  void setSoundPosition(const char *soundName, const Math::Vector3d &pos, int minVol, int maxVol);
73  void calculateSoundPosition(const Math::Vector3d &pos, int minVol, int maxVol, int &volume, int &balance);
74  void setSoundParameters(int minVolume, int maxVolume);
75  void getSoundParameters(int *minVolume, int *maxVolume);
76 
77  const Common::String &getName() const { return _name; }
78 
79  void setLightEnableState(bool state) {
80  _enableLights = state;
81  }
82  void setLightIntensity(const char *light, float intensity);
83  void setLightIntensity(int light, float intensity);
84  void setLightPosition(const char *light, const Math::Vector3d &pos);
85  void setLightPosition(int light, const Math::Vector3d &pos);
86  void setLightEnabled(const char *light, bool enabled);
87  void setLightEnabled(int light, bool enabled);
88  void turnOffLights();
89 
90  void setSetup(int num);
91  int getSetup() const { return _currSetup - _setups; }
92  inline int getNumSetups() const { return _numSetups; }
93 
94  // Sector access functions
95  int getSectorCount() { return _numSectors; }
96 
97  Sector *getSectorBase(int id);
98  Sector *getSectorByName(const Common::String &name);
99  Sector *getSectorBySubstring(const Common::String &str);
100  Sector *getSectorBySubstring(const Common::String &str, const Math::Vector3d &pos);
101 
102  Sector *findPointSector(const Math::Vector3d &p, Sector::SectorType type);
103  int findSectorSortOrder(const Math::Vector3d &p, Sector::SectorType type);
104  void findClosestSector(const Math::Vector3d &p, Sector **sect, Math::Vector3d *closestPt);
105  void shrinkBoxes(float radius);
106  void unshrinkBoxes();
107 
108  void addObjectState(const ObjectState::Ptr &s);
109  void deleteObjectState(const ObjectState::Ptr &s) {
110  _states.remove(s);
111  }
112 
113  void moveObjectStateToFront(const ObjectState::Ptr &s);
114  void moveObjectStateToBack(const ObjectState::Ptr &s);
115 
116  ObjectState *addObjectState(int setupID, ObjectState::Position pos, const char *bitmap, const char *zbitmap, bool transparency);
117  ObjectState *findState(const Common::String &filename);
118 
119  // Setups contain the camera information and background for all views in a Set
120  struct Setup { // Camera setup data
121  void load(Set *set, int id, TextSplitter &ts);
122  void loadBinary(Common::SeekableReadStream *data);
123  void setupCamera() const;
124  void saveState(SaveGame *savedState) const;
125  bool restoreState(SaveGame *savedState);
126 
127  void getRotation(float *x, float *y, float *z);
128  Math::Matrix4 getRotation() { return _rot; }
129  void setPitch(Math::Angle p);
130  void setYaw(Math::Angle y);
131  void setRoll(Math::Angle r);
132 
133  Common::String _name;
134  Bitmap::Ptr _bkgndBm, _bkgndZBm;
135 
136  // Camera settings
137  Math::Vector3d _pos, _interest;
138  Math::Matrix4 _rot;
139  float _roll, _fov, _nclip, _fclip;
140  };
141 
142  CMap *getCMap() {
143  if (!_cmaps || ! _numCmaps)
144  return NULL;
145  return _cmaps[0];
146  };
147 
148  Setup *getCurrSetup() { return _currSetup; }
149  Setup *getSetup(int num) const { return _setups + num; }
150  const Common::List<Light *> &getLights(bool inOverworld) { return (inOverworld ? _overworldLightsList : _lightsList); }
151  const Math::Frustum &getFrustum() { return _frustum; }
152 
153  int getShadowCount() const { return _numShadows; }
154  SetShadow *getShadow(int i);
155  SetShadow *getShadowByName(const Common::String &name);
156 
157 private:
158  bool _locked;
159  Common::String _name;
160  int _numCmaps;
161  ObjectPtr<CMap> *_cmaps;
162  int _numSetups, _numLights, _numSectors, _numObjectStates, _numShadows;
163  bool _enableLights;
164  Sector **_sectors;
165  Light *_lights;
166  Common::List<Light *> _lightsList;
167  Common::List<Light *> _overworldLightsList;
168  Setup *_setups;
169  SetShadow *_shadows;
170 
171  Setup *_currSetup;
173  StateList _states;
174 
175  Math::Frustum _frustum;
176 
177  friend class GrimEngine;
178 };
179 
184 struct Light {
185  Light();
186  void load(TextSplitter &ts);
187  void loadBinary(Common::SeekableReadStream *data);
188  void saveState(SaveGame *savedState) const;
189  bool restoreState(SaveGame *savedState);
190  void setIntensity(float intensity);
191  void setUmbra(float angle);
192  void setPenumbra(float angle);
193 
194  enum LightType {
195  Omni = 1,
196  Spot = 2,
197  Direct = 3,
198  Ambient = 4
199  };
200 
201  Common::String _name;
202  LightType _type;
203  Math::Vector3d _pos, _dir;
204  Color _color;
205  float _intensity, _umbraangle, _penumbraangle, _falloffNear, _falloffFar;
206  float _scaledintensity, _cosumbraangle, _cospenumbraangle;
207  bool _enabled;
208  // there may be more lights with the same position, so this is used to make the sort stable
209  int _id;
210 };
211 
216 struct SetShadow {
217  SetShadow();
218  void loadBinary(Common::SeekableReadStream *data, Set *set);
219  void saveState(SaveGame *savedState) const;
220  void restoreState(SaveGame *savedState);
221 
222  Common::String _name;
223  Math::Vector3d _shadowPoint;
224  int _numSectors;
225  Common::List<Common::String> _sectorNames;
226  Color _color;
227 };
228 
229 } // end of namespace Grim
230 
231 #endif
Definition: set.h:184
Definition: grim.h:58
Definition: str.h:59
Definition: list.h:44
Definition: objectstate.h:34
Definition: savegame.h:33
Definition: stream.h:745
Definition: actor.h:33
Definition: set.h:216
Definition: set.h:120
Definition: algorithm.h:29
Definition: colormap.h:35
Definition: textsplit.h:35
#define MKTAG(a0, a1, a2, a3)
Definition: endian.h:188
Definition: object.h:69
Definition: pool.h:42
Definition: color.h:29
Definition: sector.h:40
Definition: set.h:44