OpenMW
components/esm/loadland.hpp
Go to the documentation of this file.
00001 #ifndef OPENMW_ESM_LAND_H
00002 #define OPENMW_ESM_LAND_H
00003 
00004 #include <libs/platform/stdint.h>
00005 
00006 #include "esmcommon.hpp"
00007 
00008 namespace ESM
00009 {
00010 
00011 class ESMReader;
00012 class ESMWriter;
00013 
00014 /*
00015  * Landscape data.
00016  */
00017 
00018 struct Land
00019 {
00020     static unsigned int sRecordId;
00021 
00022     Land();
00023     ~Land();
00024 
00025     int mFlags; // Only first four bits seem to be used, don't know what
00026     // they mean.
00027     int mX, mY; // Map coordinates.
00028     int mPlugin; // Plugin index, used to reference the correct material palette.
00029 
00030     // File context. This allows the ESM reader to be 'reset' to this
00031     // location later when we are ready to load the full data set.
00032     ESMReader* mEsm;
00033     ESM_Context mContext;
00034 
00035     bool mHasData;
00036     int mDataTypes;
00037     int mDataLoaded;
00038 
00039     enum
00040     {
00041         DATA_VNML = 1,
00042         DATA_VHGT = 2,
00043         DATA_WNAM = 4,
00044         DATA_VCLR = 8,
00045         DATA_VTEX = 16
00046     };
00047 
00048     // number of vertices per side
00049     static const int LAND_SIZE = 65;
00050 
00051     // cell terrain size in world coords
00052     static const int REAL_SIZE = 8192;
00053 
00054     // total number of vertices
00055     static const int LAND_NUM_VERTS = LAND_SIZE * LAND_SIZE;
00056 
00057     static const int HEIGHT_SCALE = 8;
00058 
00059     //number of textures per side of land
00060     static const int LAND_TEXTURE_SIZE = 16;
00061 
00062     //total number of textures per land
00063     static const int LAND_NUM_TEXTURES = LAND_TEXTURE_SIZE * LAND_TEXTURE_SIZE;
00064 
00065 #pragma pack(push,1)
00066     struct VHGT
00067     {
00068         float mHeightOffset;
00069         int8_t mHeightData[LAND_NUM_VERTS];
00070         short mUnk1;
00071         char mUnk2;
00072     };
00073 #pragma pack(pop)
00074 
00075     typedef signed char VNML;
00076 
00077     struct LandData
00078     {
00079         float mHeightOffset;
00080         float mHeights[LAND_NUM_VERTS];
00081         VNML mNormals[LAND_NUM_VERTS * 3];
00082         uint16_t mTextures[LAND_NUM_TEXTURES];
00083 
00084         bool mUsingColours;
00085         char mColours[3 * LAND_NUM_VERTS];
00086         int mDataTypes;
00087 
00088         uint8_t mWnam[81];
00089         short mUnk1;
00090         uint8_t mUnk2;
00091 
00092         void save(ESMWriter &esm);
00093         static void transposeTextureData(uint16_t *in, uint16_t *out);
00094     };
00095 
00096     LandData *mLandData;
00097 
00098     void load(ESMReader &esm);
00099     void save(ESMWriter &esm) const;
00100 
00104     void loadData(int flags);
00105 
00109     void unloadData();
00110 
00113     bool isDataLoaded(int flags) {
00114         return (mDataLoaded & flags) == flags;
00115     }
00116 
00117     private:
00118         Land(const Land& land);
00119         Land& operator=(const Land& land);
00120 
00124         bool condLoad(int flags, int dataFlag, void *ptr, unsigned int size);
00125 };
00126 
00127 }
00128 #endif