OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
loadcell.hpp
Go to the documentation of this file.
1 #ifndef OPENMW_ESM_CELL_H
2 #define OPENMW_ESM_CELL_H
3 
4 #include <string>
5 #include <vector>
6 #include <list>
7 
8 #include "esmcommon.hpp"
9 #include "defs.hpp"
10 #include "cellref.hpp"
11 #include "cellid.hpp"
12 
13 namespace MWWorld
14 {
15  class ESMStore;
16 }
17 
18 namespace ESM
19 {
20 class ESMReader;
21 class ESMWriter;
22 
23 /* Moved cell reference tracking object. This mainly stores the target cell
24  of the reference, so we can easily know where it has been moved when another
25  plugin tries to move it independently.
26  Unfortunately, we need to implement this here.
27  */
29 {
30 public:
32 
33  // Coordinates of target exterior cell
34  int mTarget[2];
35 
36  // The content file format does not support moving objects to an interior cell.
37  // The save game format does support moving to interior cells, but uses a different mechanism
38  // (see the MovedRefTracker implementation in MWWorld::CellStore for more details).
39 };
40 
42 bool operator==(const MovedCellRef& ref, const RefNum& refNum);
43 bool operator==(const CellRef& ref, const RefNum& refNum);
44 
45 typedef std::list<MovedCellRef> MovedCellRefTracker;
46 typedef std::list<std::pair<CellRef, bool> > CellRefTracker;
47 
49 {
51 
52  CellRefTrackerPredicate(const RefNum& refNum) : mRefNum(refNum) {}
53  bool operator() (const std::pair<CellRef, bool>& refdelPair) { return refdelPair.first == mRefNum; }
54 };
55 
56 /* Cells hold data about objects, creatures, statics (rocks, walls,
57  buildings) and landscape (for exterior cells). Cells frequently
58  also has other associated LAND and PGRD records. Combined, all this
59  data can be huge, and we cannot load it all at startup. Instead,
60  the strategy we use is to remember the file position of each cell
61  (using ESMReader::getContext()) and jumping back into place
62  whenever we need to load a given cell.
63  */
64 struct Cell
65 {
66  static unsigned int sRecordId;
68  static std::string getRecordType() { return "Cell"; }
69 
70  enum Flags
71  {
72  Interior = 0x01, // Interior cell
73  HasWater = 0x02, // Does this cell have a water surface
74  NoSleep = 0x04, // Is it allowed to sleep here (without a bed)
75  QuasiEx = 0x80 // Behave like exterior (Tribunal+), with
76  // skybox and weather
77  };
78 
79  struct DATAstruct
80  {
81  int mFlags;
82  int mX, mY;
83  };
84 
85  struct AMBIstruct
86  {
88  float mFogDensity;
89  };
90 
91  Cell() : mName(""),
92  mRegion(""),
93  mWater(0),
94  mWaterInt(false),
95  mMapColor(0),
97  {}
98 
99  // Interior cells are indexed by this (it's the 'id'), for exterior
100  // cells it is optional.
101  std::string mName;
102 
103  // Optional region name for exterior and quasi-exterior cells.
104  std::string mRegion;
105 
106  std::vector<ESM_Context> mContextList; // File position; multiple positions for multiple plugin support
109 
111 
112  float mWater; // Water level
113  bool mWaterInt;
115  // Counter for RefNums. This is only used during content file editing and has no impact on gameplay.
116  // It prevents overwriting previous refNums, even if they were deleted.
117  // as that would collide with refs when a content file is upgraded.
119 
120  // References "leased" from another cell (i.e. a different cell
121  // introduced this ref, and it has been moved here by a plugin)
124 
125  void postLoad(ESMReader &esm);
126 
127  // This method is left in for compatibility with esmtool. Parsing moved references currently requires
128  // passing ESMStore, bit it does not know about this parameter, so we do it this way.
129  void load(ESMReader &esm, bool &isDeleted, bool saveContext = true); // Load everything (except references)
130  void loadNameAndData(ESMReader &esm, bool &isDeleted); // Load NAME and DATAstruct
131  void loadCell(ESMReader &esm, bool saveContext = true); // Load everything, except NAME, DATAstruct and references
132 
133  void save(ESMWriter &esm, bool isDeleted = false) const;
134 
135  bool isExterior() const
136  {
137  return !(mData.mFlags & Interior);
138  }
139 
140  int getGridX() const
141  {
142  return mData.mX;
143  }
144 
145  int getGridY() const
146  {
147  return mData.mY;
148  }
149 
150  bool hasWater() const
151  {
152  return ((mData.mFlags&HasWater) != 0) || isExterior();
153  }
154 
155  // Restore the given reader to the stored position. Will try to open
156  // the file matching the stored file name. If you want to read from
157  // somewhere other than the file system, you need to pre-open the
158  // ESMReader, and the filename must match the stored filename
159  // exactly.
160  void restore(ESMReader &esm, int iCtx) const;
161 
162  std::string getDescription() const;
164 
165  /* Get the next reference in this cell, if any. Returns false when
166  there are no more references in the cell.
167 
168  All fields of the CellRef struct are overwritten. You can safely
169  reuse one memory location without blanking it between calls.
170  */
172  static bool getNextRef(ESMReader &esm,
173  CellRef &ref,
174  bool &isDeleted,
175  bool ignoreMoves = false,
176  MovedCellRef *mref = 0);
177 
178  /* This fetches an MVRF record, which is used to track moved references.
179  * Since they are comparably rare, we use a separate method for this.
180  */
181  static bool getNextMVRF(ESMReader &esm, MovedCellRef &mref);
182 
183  void blank();
185 
186  const CellId& getCellId() const;
187 };
188 }
189 #endif
Color mAmbient
Definition: loadcell.hpp:87
void postLoad(ESMReader &esm)
Definition: loadcell.cpp:155
Definition: loadcell.hpp:28
float mFogDensity
Definition: loadcell.hpp:88
AMBIstruct mAmbi
Definition: loadcell.hpp:110
int mY
Definition: loadcell.hpp:82
Definition: loadcell.hpp:72
bool operator==(const CellId &left, const CellId &right)
Definition: cellid.cpp:29
int mFlags
Definition: loadcell.hpp:81
Definition: esmreader.hpp:21
static bool getNextRef(ESMReader &esm, CellRef &ref, bool &isDeleted, bool ignoreMoves=false, MovedCellRef *mref=0)
Definition: loadcell.cpp:218
Flags
Definition: loadcell.hpp:70
Color mSunlight
Definition: loadcell.hpp:87
Definition: loadcell.hpp:74
Color mFog
Definition: loadcell.hpp:87
CellId mCellId
Definition: loadcell.hpp:108
std::string mName
Definition: loadcell.hpp:101
Definition: loadcell.hpp:75
void save(ESMWriter &esm, bool isDeleted=false) const
Definition: loadcell.cpp:162
static bool getNextMVRF(ESMReader &esm, MovedCellRef &mref)
Definition: loadcell.cpp:255
int getGridX() const
Definition: loadcell.hpp:140
Definition: esmwriter.hpp:17
CellRefTracker mLeasedRefs
Definition: loadcell.hpp:122
std::string getDescription() const
Return a short string describing the cell (mostly used for debugging/logging purpose) ...
Definition: loadcell.cpp:204
Definition: cellref.hpp:14
DATAstruct mData
Definition: loadcell.hpp:107
std::list< std::pair< CellRef, bool > > CellRefTracker
Definition: loadcell.hpp:46
RefNum mRefNum
Definition: loadcell.hpp:50
void load(ESMReader &esm, bool &isDeleted, bool saveContext=true)
Definition: loadcell.cpp:55
bool mWaterInt
Definition: loadcell.hpp:113
Definition: loadcell.hpp:48
RefNum mRefNum
Definition: loadcell.hpp:31
bool hasWater() const
Definition: loadcell.hpp:150
void loadCell(ESMReader &esm, bool saveContext=true)
Definition: loadcell.cpp:111
float mWater
Definition: loadcell.hpp:112
Definition: cellref.hpp:34
Definition: loadcell.hpp:64
Definition: loadcell.hpp:79
void blank()
Set record to default state (does not touch the ID/index).
Definition: loadcell.cpp:265
const CellId & getCellId() const
Definition: loadcell.cpp:284
int mMapColor
Definition: loadcell.hpp:114
int mRefNumCounter
Definition: loadcell.hpp:118
uint32_t Color
Definition: defs.hpp:18
int mTarget[2]
Definition: loadcell.hpp:34
bool isExterior() const
Definition: loadcell.hpp:135
bool operator()(const std::pair< CellRef, bool > &refdelPair)
Definition: loadcell.hpp:53
int getGridY() const
Definition: loadcell.hpp:145
static unsigned int sRecordId
Definition: loadcell.hpp:66
Cell()
Definition: loadcell.hpp:91
Definition: loadcell.hpp:73
CellRefTrackerPredicate(const RefNum &refNum)
Definition: loadcell.hpp:52
std::list< MovedCellRef > MovedCellRefTracker
Definition: loadcell.hpp:45
static std::string getRecordType()
Return a string descriptor for this record type. Currently used for debugging / error logs only...
Definition: loadcell.hpp:68
std::string mRegion
Definition: loadcell.hpp:104
MovedCellRefTracker mMovedRefs
Definition: loadcell.hpp:123
Definition: loadcell.hpp:85
int mX
Definition: loadcell.hpp:82
Definition: cellid.hpp:11
void loadNameAndData(ESMReader &esm, bool &isDeleted)
Definition: loadcell.cpp:61
std::vector< ESM_Context > mContextList
Definition: loadcell.hpp:106
void restore(ESMReader &esm, int iCtx) const
Definition: loadcell.cpp:199