00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef GRIM_SET_H
00024 #define GRIM_SET_H
00025
00026 #include "engines/grim/pool.h"
00027 #include "engines/grim/object.h"
00028 #include "engines/grim/color.h"
00029 #include "engines/grim/sector.h"
00030 #include "engines/grim/objectstate.h"
00031 #include "math/quat.h"
00032 #include "math/frustum.h"
00033
00034 namespace Common {
00035 class SeekableReadStream;
00036 }
00037 namespace Grim {
00038
00039 class SaveGame;
00040 class CMap;
00041 struct Light;
00042 struct SetShadow;
00043
00044 class Set : public PoolObject<Set> {
00045 public:
00046 Set(const Common::String &name, Common::SeekableReadStream *data);
00047 Set();
00048 ~Set();
00049
00050 static int32 getStaticTag() { return MKTAG('S', 'E', 'T', ' '); }
00051
00052 void loadText(TextSplitter &ts);
00053 void loadBinary(Common::SeekableReadStream *data);
00054 void setupOverworldLights();
00055
00056 void saveState(SaveGame *savedState) const;
00057 bool restoreState(SaveGame *savedState);
00058
00059 int _minVolume;
00060 int _maxVolume;
00061
00062 static Bitmap::Ptr loadBackground(const char *fileName);
00063 void drawBackground() const;
00064 void drawBitmaps(ObjectState::Position stage);
00065 void setupCamera();
00066
00067 void setupLights(const Math::Vector3d &pos, bool inOverworld);
00068
00069 void setSoundPosition(const char *soundName, const Math::Vector3d &pos);
00070 void setSoundPosition(const char *soundName, const Math::Vector3d &pos, int minVol, int maxVol);
00071 void calculateSoundPosition(const Math::Vector3d &pos, int minVol, int maxVol, int &volume, int &balance);
00072 void setSoundParameters(int minVolume, int maxVolume);
00073 void getSoundParameters(int *minVolume, int *maxVolume);
00074
00075 const Common::String &getName() const { return _name; }
00076
00077 void setLightEnableState(bool state) {
00078 _enableLights = state;
00079 }
00080 void setLightIntensity(const char *light, float intensity);
00081 void setLightIntensity(int light, float intensity);
00082 void setLightPosition(const char *light, const Math::Vector3d &pos);
00083 void setLightPosition(int light, const Math::Vector3d &pos);
00084 void setLightEnabled(const char *light, bool enabled);
00085 void setLightEnabled(int light, bool enabled);
00086 void turnOffLights();
00087
00088 void setSetup(int num);
00089 int getSetup() const { return _currSetup - _setups; }
00090 inline int getNumSetups() const { return _numSetups; }
00091
00092
00093 int getSectorCount() { return _numSectors; }
00094
00095 Sector *getSectorBase(int id);
00096 Sector *getSectorByName(const Common::String &name);
00097 Sector *getSectorBySubstring(const Common::String &str);
00098 Sector *getSectorBySubstring(const Common::String &str, const Math::Vector3d &pos);
00099
00100 Sector *findPointSector(const Math::Vector3d &p, Sector::SectorType type);
00101 int findSectorSortOrder(const Math::Vector3d &p, Sector::SectorType type);
00102 void findClosestSector(const Math::Vector3d &p, Sector **sect, Math::Vector3d *closestPt);
00103 void shrinkBoxes(float radius);
00104 void unshrinkBoxes();
00105
00106 void addObjectState(const ObjectState::Ptr &s);
00107 void deleteObjectState(const ObjectState::Ptr &s) {
00108 _states.remove(s);
00109 }
00110
00111 void moveObjectStateToFront(const ObjectState::Ptr &s);
00112 void moveObjectStateToBack(const ObjectState::Ptr &s);
00113
00114 ObjectState *addObjectState(int setupID, ObjectState::Position pos, const char *bitmap, const char *zbitmap, bool transparency);
00115 ObjectState *findState(const Common::String &filename);
00116
00117
00118 struct Setup {
00119 void load(Set *set, int id, TextSplitter &ts);
00120 void loadBinary(Common::SeekableReadStream *data);
00121 void setupCamera() const;
00122 void saveState(SaveGame *savedState) const;
00123 bool restoreState(SaveGame *savedState);
00124
00125 void getRotation(float *x, float *y, float *z);
00126 Math::Matrix4 getRotation() { return _rot; }
00127 void setPitch(Math::Angle p);
00128 void setYaw(Math::Angle y);
00129 void setRoll(Math::Angle r);
00130
00131 Common::String _name;
00132 Bitmap::Ptr _bkgndBm, _bkgndZBm;
00133
00134
00135 Math::Vector3d _pos, _interest;
00136 Math::Matrix4 _rot;
00137 float _roll, _fov, _nclip, _fclip;
00138 };
00139
00140 CMap *getCMap() {
00141 if (!_cmaps || ! _numCmaps)
00142 return NULL;
00143 return _cmaps[0];
00144 };
00145
00146 Setup *getCurrSetup() { return _currSetup; }
00147 const Common::List<Light *> &getLights(bool inOverworld) { return (inOverworld ? _overworldLightsList : _lightsList); }
00148 const Math::Frustum &getFrustum() { return _frustum; }
00149
00150 int getShadowCount() const { return _numShadows; }
00151 SetShadow *getShadow(int i);
00152 SetShadow *getShadowByName(const Common::String &name);
00153
00154 private:
00155 bool _locked;
00156 Common::String _name;
00157 int _numCmaps;
00158 ObjectPtr<CMap> *_cmaps;
00159 int _numSetups, _numLights, _numSectors, _numObjectStates, _numShadows;
00160 bool _enableLights;
00161 Sector **_sectors;
00162 Light *_lights;
00163 Common::List<Light *> _lightsList;
00164 Common::List<Light *> _overworldLightsList;
00165 Setup *_setups;
00166 SetShadow *_shadows;
00167
00168 Setup *_currSetup;
00169 typedef Common::List<ObjectState::Ptr> StateList;
00170 StateList _states;
00171
00172 Math::Frustum _frustum;
00173
00174 friend class GrimEngine;
00175 };
00176
00181 struct Light {
00182 Light();
00183 void load(TextSplitter &ts);
00184 void loadBinary(Common::SeekableReadStream *data);
00185 void saveState(SaveGame *savedState) const;
00186 bool restoreState(SaveGame *savedState);
00187 void setIntensity(float intensity);
00188 void setUmbra(float angle);
00189 void setPenumbra(float angle);
00190
00191 enum LightType {
00192 Omni = 1,
00193 Spot = 2,
00194 Direct = 3,
00195 Ambient = 4
00196 };
00197
00198 Common::String _name;
00199 LightType _type;
00200 Math::Vector3d _pos, _dir;
00201 Color _color;
00202 float _intensity, _umbraangle, _penumbraangle, _falloffNear, _falloffFar;
00203 float _scaledintensity, _cosumbraangle, _cospenumbraangle;
00204 bool _enabled;
00205
00206 int _id;
00207 };
00208
00213 struct SetShadow {
00214 SetShadow();
00215 void loadBinary(Common::SeekableReadStream *data, Set *set);
00216 void saveState(SaveGame *savedState) const;
00217 void restoreState(SaveGame *savedState);
00218
00219 Common::String _name;
00220 Math::Vector3d _shadowPoint;
00221 int _numSectors;
00222 Common::List<Common::String> _sectorNames;
00223 Color _color;
00224 };
00225
00226 }
00227
00228 #endif