mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-29 13:27:59 +03:00
- integrated Yacobys landscape. First commit.
git-svn-id: https://openmw.svn.sourceforge.net/svnroot/openmw/trunk@112 ea6a568a-9f4f-0410-981a-c910a81bb256
This commit is contained in:
parent
ea486dd770
commit
a46804dae3
32 changed files with 3976 additions and 212 deletions
91
terrain/cpp_index.cpp
Normal file
91
terrain/cpp_index.cpp
Normal file
|
@ -0,0 +1,91 @@
|
|||
/**
|
||||
* @brief holds data about positions of data and general header info
|
||||
*/
|
||||
class Index {
|
||||
public:
|
||||
///saves my fingers :P
|
||||
typedef std::map<long, std::map<long, long> >::iterator OffsetItr;
|
||||
typedef std::map<long, std::map<long, long> >::const_iterator OffsetConstItr;
|
||||
|
||||
/**
|
||||
* @brief sets the root quads side length in gu
|
||||
* @param l the side length
|
||||
*
|
||||
* This is used for working out the locations of quad children.
|
||||
* I am assuming a long is enough...
|
||||
*/
|
||||
inline void setRootSideLength(long l) {
|
||||
mRootSideLength = l;
|
||||
}
|
||||
/**
|
||||
* @return the side length of the root quad.
|
||||
*/
|
||||
inline long getRootSideLength() const {
|
||||
return mRootSideLength;
|
||||
}
|
||||
|
||||
inline void setMaxDepth(int d) {
|
||||
mMaxDepth = d;
|
||||
}
|
||||
inline int getMaxDepth() const {
|
||||
return mMaxDepth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return -1 is returned if there is no offset
|
||||
* @param x, y the position of the quad in gu
|
||||
*
|
||||
* Slightly faster using hasOffset to check if it exists
|
||||
* Shouldn't be noticable diffrence.
|
||||
*/
|
||||
inline long getOffset(long x, long y) const { //inline?
|
||||
OffsetConstItr itr1 = mQuadOffsets.find(x);
|
||||
if ( itr1 == mQuadOffsets.end() ) return -1;
|
||||
std::map<long, long>::const_iterator itr2 = itr1->second.find(y);
|
||||
if ( itr2 == itr1->second.end() ) return -1;
|
||||
return itr2->second;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief checks if a quad for the given position exists
|
||||
* @return true/false
|
||||
* @param x, y the position of the quad in gu
|
||||
*
|
||||
* @todo Would it be worth merging this with getOffset?
|
||||
*/
|
||||
inline bool hasOffset(long x, long y) const {
|
||||
OffsetConstItr itr = mQuadOffsets.find(x);
|
||||
if ( itr == mQuadOffsets.end() ) return false;
|
||||
return (itr->second.find(y) != itr->second.end());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief sets an offset of a quad
|
||||
* @param x, y the position in gu of the quad
|
||||
* @param o the offset within the file of the records for this quad
|
||||
*/
|
||||
inline void setOffset(long x, long y, long o) {
|
||||
mQuadOffsets[x][y] = o;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::map<long, std::map<long, long> > mQuadOffsets;
|
||||
long mRootSideLength; ///length in gu of the root quad
|
||||
int mMaxDepth; ///maximum depth assuming root quad depth = 0
|
||||
|
||||
friend class boost::serialization::access;
|
||||
/**
|
||||
* Saves the data for the max depth, the root side legnth, and the quad offsets
|
||||
*/
|
||||
template<class Archive>
|
||||
inline void serialize(Archive& ar, const unsigned int version){
|
||||
|
||||
ar &mMaxDepth;
|
||||
ar &mRootSideLength;
|
||||
ar &mQuadOffsets;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
BOOST_CLASS_TRACKING(Index, boost::serialization::track_never);
|
Loading…
Add table
Add a link
Reference in a new issue