- started code cleanup/rewrite

git-svn-id: https://openmw.svn.sourceforge.net/svnroot/openmw/trunk@113 ea6a568a-9f4f-0410-981a-c910a81bb256
This commit is contained in:
nkorslund 2009-05-16 17:58:08 +00:00
parent a46804dae3
commit 2ac9503854
20 changed files with 1211 additions and 1616 deletions

View file

@ -1,90 +1,90 @@
/**
* @brief holds data about positions of data and general header info
*/
class Index {
* Holds index and other data describing the landscape.data file.
*/
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;
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;
}
/**
* @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;
}
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;
}
/**
* @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 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;
}
/**
* @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
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){
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;
}
}
};