OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
loadland.hpp
Go to the documentation of this file.
1 #ifndef OPENMW_ESM_LAND_H
2 #define OPENMW_ESM_LAND_H
3 
4 #include <stdint.h>
5 
6 #include <OpenThreads/Mutex>
7 
8 #include "esmcommon.hpp"
9 
10 namespace ESM
11 {
12 
13 class ESMReader;
14 class ESMWriter;
15 
16 /*
17  * Landscape data.
18  */
19 
20 struct Land
21 {
22  static unsigned int sRecordId;
24  static std::string getRecordType() { return "Land"; }
25 
26  Land();
27  ~Land();
28 
29  int mFlags; // Only first four bits seem to be used, don't know what
30  // they mean.
31  int mX, mY; // Map coordinates.
32  int mPlugin; // Plugin index, used to reference the correct material palette.
33 
34  // File context. This allows the ESM reader to be 'reset' to this
35  // location later when we are ready to load the full data set.
37 
39 
40  enum
41  {
42  DATA_VNML = 1,
43  DATA_VHGT = 2,
44  DATA_WNAM = 4,
45  DATA_VCLR = 8,
46  DATA_VTEX = 16
47  };
48 
49  // default height to use in case there is no Land record
50  static const int DEFAULT_HEIGHT = -2048;
51 
52  // number of vertices per side
53  static const int LAND_SIZE = 65;
54 
55  // cell terrain size in world coords
56  static const int REAL_SIZE = 8192;
57 
58  // total number of vertices
59  static const int LAND_NUM_VERTS = LAND_SIZE * LAND_SIZE;
60 
61  static const int HEIGHT_SCALE = 8;
62 
63  //number of textures per side of land
64  static const int LAND_TEXTURE_SIZE = 16;
65 
66  //total number of textures per land
68 
69 #pragma pack(push,1)
70  struct VHGT
71  {
74  short mUnk1;
75  char mUnk2;
76  };
77 #pragma pack(pop)
78 
79  typedef signed char VNML;
80 
81  struct LandData
82  {
83  // Initial reference height for the first vertex, only needed for filling mHeights
85  // Height in world space for each vertex
87 
88  // 24-bit normals, these aren't always correct though. Edge and corner normals may be garbage.
90 
91  // 2D array of texture indices. An index can be used to look up an ESM::LandTexture,
92  // but to do so you must subtract 1 from the index first!
93  // An index of 0 indicates the default texture.
95 
96  // 24-bit RGB color for each vertex
97  unsigned char mColours[3 * LAND_NUM_VERTS];
98 
99  // DataTypes available in this LandData, accessing data that is not available is an undefined operation
101 
102  // low-LOD heightmap (used for rendering the global map)
103  signed char mWnam[81];
104 
105  // ???
106  short mUnk1;
107  uint8_t mUnk2;
108 
109  void save(ESMWriter &esm) const;
110  static void transposeTextureData(const uint16_t *in, uint16_t *out);
111  };
112 
113  void load(ESMReader &esm, bool &isDeleted);
114  void save(ESMWriter &esm, bool isDeleted = false) const;
115 
116  void blank() {}
117 
121  void loadData(int flags) const;
122 
126  void unloadData();
127 
130  bool isDataLoaded(int flags) const;
131 
132  Land (const Land& land);
133 
134  Land& operator= (Land land);
135 
136  void swap (Land& land);
137 
141  const LandData *getLandData (int flags) const;
142 
144  const LandData *getLandData() const;
145 
147  LandData *getLandData();
148 
152  void add (int flags);
153 
155  void remove (int flags);
156 
157  private:
158 
162  bool condLoad(ESM::ESMReader& reader, int flags, int dataFlag, void *ptr, unsigned int size) const;
163 
164  mutable OpenThreads::Mutex mMutex;
165 
166  mutable int mDataLoaded;
167 
168  mutable LandData *mLandData;
169 };
170 
171 }
172 #endif
Definition: loadland.hpp:44
void save(ESMWriter &esm) const
Definition: loadland.cpp:15
static const int LAND_NUM_TEXTURES
Definition: loadland.hpp:67
static const int LAND_NUM_VERTS
Definition: loadland.hpp:59
static unsigned int sRecordId
Definition: loadland.hpp:22
Definition: esmreader.hpp:21
LandData * mLandData
Definition: loadland.hpp:168
void unloadData()
Definition: loadland.cpp:237
short mUnk1
Definition: loadland.hpp:74
Land & operator=(Land land)
Definition: loadland.cpp:271
void save(ESMWriter &esm, bool isDeleted=false) const
Definition: loadland.cpp:160
Definition: loadland.hpp:20
static std::string getRecordType()
Return a string descriptor for this record type. Currently used for debugging / error logs only...
Definition: loadland.hpp:24
int mFlags
Definition: loadland.hpp:29
static const int HEIGHT_SCALE
Definition: loadland.hpp:61
Definition: esmwriter.hpp:17
int mX
Definition: loadland.hpp:31
void swap(Land &land)
Definition: loadland.cpp:277
void loadData(int flags) const
Definition: loadland.cpp:181
int mY
Definition: loadland.hpp:31
static const int LAND_TEXTURE_SIZE
Definition: loadland.hpp:64
Definition: loadland.hpp:43
Land()
Definition: loadland.cpp:60
ESM_Context mContext
Definition: loadland.hpp:36
int mDataLoaded
Definition: loadland.hpp:166
int mDataTypes
Definition: loadland.hpp:100
Definition: loadland.hpp:70
uint16_t mTextures[LAND_NUM_TEXTURES]
Definition: loadland.hpp:94
Definition: esmcommon.hpp:116
char mUnk2
Definition: loadland.hpp:75
Definition: loadland.hpp:45
static const int LAND_SIZE
Definition: loadland.hpp:53
bool condLoad(ESM::ESMReader &reader, int flags, int dataFlag, void *ptr, unsigned int size) const
Definition: loadland.cpp:247
OpenThreads::Mutex mMutex
Definition: loadland.hpp:164
signed char mWnam[81]
Definition: loadland.hpp:103
short mUnk1
Definition: loadland.hpp:106
bool isDataLoaded(int flags) const
Definition: loadland.cpp:258
float mHeightOffset
Definition: loadland.hpp:84
static const int DEFAULT_HEIGHT
Definition: loadland.hpp:50
void load(ESMReader &esm, bool &isDeleted)
Definition: loadland.cpp:86
Definition: loadland.hpp:42
static const int REAL_SIZE
Definition: loadland.hpp:56
uint8_t mUnk2
Definition: loadland.hpp:107
VNML mNormals[LAND_NUM_VERTS *3]
Definition: loadland.hpp:89
float mHeights[LAND_NUM_VERTS]
Definition: loadland.hpp:86
int mDataTypes
Definition: loadland.hpp:38
void blank()
Definition: loadland.hpp:116
signed char VNML
Definition: loadland.hpp:79
static void transposeTextureData(const uint16_t *in, uint16_t *out)
Definition: loadland.cpp:71
void add(int flags)
Definition: loadland.cpp:308
int8_t mHeightData[LAND_NUM_VERTS]
Definition: loadland.hpp:73
unsigned char mColours[3 *LAND_NUM_VERTS]
Definition: loadland.hpp:97
const LandData * getLandData() const
Return land data without loading first anything. Can return a 0-pointer.
Definition: loadland.cpp:298
Definition: loadland.hpp:81
int mPlugin
Definition: loadland.hpp:32
float mHeightOffset
Definition: loadland.hpp:72
Definition: loadland.hpp:46
~Land()
Definition: loadland.cpp:81