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 
21  class Storage : public Terrain::Storage
22  {
23  private:
24 
25  // Not implemented in this class, because we need different Store implementations for game and editor
26  virtual const ESM::Land* getLand (int cellX, int cellY)= 0;
27  virtual const ESM::LandTexture* getLandTexture(int index, short plugin) = 0;
28 
29  public:
30  Storage(const VFS::Manager* vfs, const std::string& normalMapPattern = "", const std::string& normalHeightMapPattern = "", bool autoUseNormalMaps = false, const std::string& specularMapPattern = "", bool autoUseSpecularMaps = false);
31 
35  const ESM::Land::LandData *getLandData (int cellX, int cellY, int flags);
36 
37  // Not implemented in this class, because we need different Store implementations for game and editor
39  virtual void getBounds(float& minX, float& maxX, float& minY, float& maxY) = 0;
40 
49  virtual bool getMinMaxHeights (float size, const osg::Vec2f& center, float& min, float& max);
50 
61  virtual void fillVertexBuffers (int lodLevel, float size, const osg::Vec2f& center,
62  osg::ref_ptr<osg::Vec3Array> positions,
63  osg::ref_ptr<osg::Vec3Array> normals,
64  osg::ref_ptr<osg::Vec4Array> colours);
65 
77  virtual void getBlendmaps (float chunkSize, const osg::Vec2f& chunkCenter, bool pack,
78  ImageVector& blendmaps,
79  std::vector<Terrain::LayerInfo>& layerList);
80 
81  virtual float getHeightAt (const osg::Vec3f& worldPos);
82 
84 
86  virtual float getCellWorldSize();
87 
89  virtual int getCellVertices();
90 
91  private:
93 
94  void fixNormal (osg::Vec3f& normal, int cellX, int cellY, int col, int row);
95  void fixColour (osg::Vec4f& colour, int cellX, int cellY, int col, int row);
96  void averageNormal (osg::Vec3f& normal, int cellX, int cellY, int col, int row);
97 
98  float getVertexHeight (const ESM::Land* land, int x, int y);
99 
100  // Since plugins can define new texture palettes, we need to know the plugin index too
101  // in order to retrieve the correct texture name.
102  // pair <texture id, plugin id>
103  typedef std::pair<short, short> UniqueTextureId;
104 
105  UniqueTextureId getVtexIndexAt(int cellX, int cellY,
106  int x, int y);
107  std::string getTextureName (UniqueTextureId id);
108 
109  std::map<std::string, Terrain::LayerInfo> mLayerInfoMap;
110  OpenThreads::Mutex mLayerInfoMutex;
111 
112  std::string mNormalMapPattern;
115 
116  std::string mSpecularMapPattern;
118 
119  Terrain::LayerInfo getLayerInfo(const std::string& texture);
120  };
121 
122 }
123 
124 #endif
void fixNormal(osg::Vec3f &normal, int cellX, int cellY, int col, int row)
Definition: storage.cpp:79
std::string mNormalHeightMapPattern
Definition: storage.hpp:113
void averageNormal(osg::Vec3f &normal, int cellX, int cellY, int col, int row)
Definition: storage.cpp:113
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:21
std::map< std::string, Terrain::LayerInfo > mLayerInfoMap
Definition: storage.hpp:109
virtual int getCellVertices()
Get the number of vertices on one side for each cell. Should be (power of two)+1. ...
Definition: storage.cpp:568
float getVertexHeight(const ESM::Land *land, int x, int y)
Definition: storage.cpp:499
std::vector< osg::ref_ptr< osg::Image > > ImageVector
Definition: storage.hpp:56
std::string mNormalMapPattern
Definition: storage.hpp:112
const ESM::Land::LandData * getLandData(int cellX, int cellY, int flags)
Definition: storage.cpp:31
bool mAutoUseSpecularMaps
Definition: storage.hpp:117
Definition: loadltex.hpp:28
bool mAutoUseNormalMaps
Definition: storage.hpp:114
Definition: loadland.hpp:20
std::pair< short, short > UniqueTextureId
Definition: storage.hpp:103
virtual void getBlendmaps(float chunkSize, const osg::Vec2f &chunkCenter, bool pack, ImageVector &blendmaps, std::vector< Terrain::LayerInfo > &layerList)
Definition: storage.cpp:332
We keep storage of terrain data abstract here since we need different implementations for game and ed...
Definition: storage.hpp:21
Feeds data from ESM terrain records (ESM::Land, ESM::LandTexture) into the terrain component...
Definition: storage.hpp:21
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:152
virtual float getHeightAt(const osg::Vec3f &worldPos)
Definition: storage.cpp:419
Definition: defs.hpp:17
std::string mSpecularMapPattern
Definition: storage.hpp:116
virtual const ESM::Land * getLand(int cellX, int cellY)=0
UniqueTextureId getVtexIndexAt(int cellX, int cellY, int x, int y)
Definition: storage.cpp:281
const VFS::Manager * mVFS
Definition: storage.hpp:92
OpenThreads::Mutex mLayerInfoMutex
Definition: storage.hpp:110
std::string getTextureName(UniqueTextureId id)
Definition: storage.cpp:312
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:39
Terrain::LayerInfo getLayerInfo(const std::string &texture)
Definition: storage.cpp:506
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:563
Definition: loadland.hpp:81
void fixColour(osg::Vec4f &colour, int cellX, int cellY, int col, int row)
Definition: storage.cpp:124
virtual Terrain::LayerInfo getDefaultLayer()
Definition: storage.cpp:554