OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
storage.hpp
Go to the documentation of this file.
1 #ifndef COMPONENTS_ESM_TERRAIN_STORAGE_H
2 #define COMPONENTS_ESM_TERRAIN_STORAGE_H
3 
4 #include <OpenThreads/Mutex>
5 
7 
10 
11 namespace VFS
12 {
13  class Manager;
14 }
15 
16 namespace ESMTerrain
17 {
18 
19  class LandCache;
20 
22  class LandObject : public osg::Object
23  {
24  public:
25  LandObject();
26  LandObject(const ESM::Land* land, int loadFlags);
27  LandObject(const LandObject& copy, const osg::CopyOp& copyop);
28  virtual ~LandObject();
29 
30  META_Object(ESMTerrain, LandObject)
31 
32  const ESM::Land::LandData* getData(int flags) const;
33  int getPlugin() const;
34 
35  private:
36  const ESM::Land* mLand;
38 
40  };
41 
44  class Storage : public Terrain::Storage
45  {
46  public:
47  Storage(const VFS::Manager* vfs, const std::string& normalMapPattern = "", const std::string& normalHeightMapPattern = "", bool autoUseNormalMaps = false, const std::string& specularMapPattern = "", bool autoUseSpecularMaps = false);
48 
49  // Not implemented in this class, because we need different Store implementations for game and editor
50  virtual osg::ref_ptr<const LandObject> getLand (int cellX, int cellY)= 0;
51  virtual const ESM::LandTexture* getLandTexture(int index, short plugin) = 0;
53  virtual void getBounds(float& minX, float& maxX, float& minY, float& maxY) = 0;
54 
63  virtual bool getMinMaxHeights (float size, const osg::Vec2f& center, float& min, float& max);
64 
75  virtual void fillVertexBuffers (int lodLevel, float size, const osg::Vec2f& center,
76  osg::ref_ptr<osg::Vec3Array> positions,
77  osg::ref_ptr<osg::Vec3Array> normals,
78  osg::ref_ptr<osg::Vec4Array> colours);
79 
91  virtual void getBlendmaps (float chunkSize, const osg::Vec2f& chunkCenter, bool pack,
92  ImageVector& blendmaps,
93  std::vector<Terrain::LayerInfo>& layerList);
94 
95  virtual float getHeightAt (const osg::Vec3f& worldPos);
96 
98  virtual float getCellWorldSize();
99 
101  virtual int getCellVertices();
102 
103  virtual int getBlendmapScale(float chunkSize);
104 
105  private:
107 
108  void fixNormal (osg::Vec3f& normal, int cellX, int cellY, int col, int row, LandCache& cache);
109  void fixColour (osg::Vec4f& colour, int cellX, int cellY, int col, int row, LandCache& cache);
110  void averageNormal (osg::Vec3f& normal, int cellX, int cellY, int col, int row, LandCache& cache);
111 
112  float getVertexHeight (const ESM::Land::LandData* data, int x, int y);
113 
114  const LandObject* getLand(int cellX, int cellY, LandCache& cache);
115 
116  // Since plugins can define new texture palettes, we need to know the plugin index too
117  // in order to retrieve the correct texture name.
118  // pair <texture id, plugin id>
119  typedef std::pair<short, short> UniqueTextureId;
120 
121  UniqueTextureId getVtexIndexAt(int cellX, int cellY,
122  int x, int y, LandCache&);
123  std::string getTextureName (UniqueTextureId id);
124 
125  std::map<std::string, Terrain::LayerInfo> mLayerInfoMap;
126  OpenThreads::Mutex mLayerInfoMutex;
127 
128  std::string mNormalMapPattern;
131 
132  std::string mSpecularMapPattern;
134 
135  Terrain::LayerInfo getLayerInfo(const std::string& texture);
136  };
137 
138 }
139 
140 #endif
virtual osg::ref_ptr< const LandObject > getLand(int cellX, int cellY)=0
void fixNormal(osg::Vec3f &normal, int cellX, int cellY, int col, int row, LandCache &cache)
Definition: storage.cpp:115
UniqueTextureId getVtexIndexAt(int cellX, int cellY, int x, int y, LandCache &)
Definition: storage.cpp:329
std::string mNormalHeightMapPattern
Definition: storage.hpp:129
void copy(const btTransform &src, Nif::Transformation &dst)
Definition: testbulletnifloader.cpp:269
Storage(const VFS::Manager *vfs, const std::string &normalMapPattern="", const std::string &normalHeightMapPattern="", bool autoUseNormalMaps=false, const std::string &specularMapPattern="", bool autoUseSpecularMaps=false)
Definition: storage.cpp:65
std::map< std::string, Terrain::LayerInfo > mLayerInfoMap
Definition: storage.hpp:125
virtual int getCellVertices()
Get the number of vertices on one side for each cell. Should be (power of two)+1. ...
Definition: storage.cpp:634
const ESM::Land * mLand
Definition: storage.hpp:36
std::vector< osg::ref_ptr< osg::Image > > ImageVector
Definition: storage.hpp:57
std::string mNormalMapPattern
Definition: storage.hpp:128
bool mAutoUseSpecularMaps
Definition: storage.hpp:133
virtual int getBlendmapScale(float chunkSize)
Definition: storage.cpp:639
Definition: loadltex.hpp:28
bool mAutoUseNormalMaps
Definition: storage.hpp:130
T & getData(Data &data)
Definition: types.hpp:25
Definition: loadland.hpp:20
int mLoadFlags
Definition: storage.hpp:37
std::pair< short, short > UniqueTextureId
Definition: storage.hpp:119
virtual void getBlendmaps(float chunkSize, const osg::Vec2f &chunkCenter, bool pack, ImageVector &blendmaps, std::vector< Terrain::LayerInfo > &layerList)
Definition: storage.cpp:392
virtual ~LandObject()
Definition: storage.cpp:46
Wrapper around Land Data with reference counting. The wrapper needs to be held as long as the data is...
Definition: storage.hpp:22
Definition: storage.hpp:22
void averageNormal(osg::Vec3f &normal, int cellX, int cellY, int col, int row, LandCache &cache)
Definition: storage.cpp:151
Feeds data from ESM terrain records (ESM::Land, ESM::LandTexture) into the terrain component...
Definition: storage.hpp:44
virtual void getBounds(float &minX, float &maxX, float &minY, float &maxY)=0
Get bounds of the whole terrain in cell units.
virtual void fillVertexBuffers(int lodLevel, float size, const osg::Vec2f &center, osg::ref_ptr< osg::Vec3Array > positions, osg::ref_ptr< osg::Vec3Array > normals, osg::ref_ptr< osg::Vec4Array > colours)
Definition: storage.cpp:191
virtual float getHeightAt(const osg::Vec3f &worldPos)
Definition: storage.cpp:478
float getVertexHeight(const ESM::Land::LandData *data, int x, int y)
Definition: storage.cpp:562
Definition: defs.hpp:17
std::string mSpecularMapPattern
Definition: storage.hpp:132
const VFS::Manager * mVFS
Definition: storage.hpp:106
void fixColour(osg::Vec4f &colour, int cellX, int cellY, int col, int row, LandCache &cache)
Definition: storage.cpp:162
OpenThreads::Mutex mLayerInfoMutex
Definition: storage.hpp:126
LandObject()
Definition: storage.cpp:27
std::string getTextureName(UniqueTextureId id)
Definition: storage.cpp:367
The main class responsible for loading files from a virtual file system.
Definition: manager.hpp:20
virtual bool getMinMaxHeights(float size, const osg::Vec2f &center, float &min, float &max)
Definition: storage.cpp:75
Terrain::LayerInfo getLayerInfo(const std::string &texture)
Definition: storage.cpp:581
ESM::Land::LandData mData
Definition: storage.hpp:39
META_Object(ESMTerrain, LandObject) const ESM int getPlugin() const
Definition: storage.cpp:57
virtual const ESM::LandTexture * getLandTexture(int index, short plugin)=0
virtual float getCellWorldSize()
Get the transformation factor for mapping cell units to world units.
Definition: storage.cpp:629
Definition: loadland.hpp:85
Definition: storage.cpp:20