2009-05-15 07:04:50 +00:00
|
|
|
/**
|
|
|
|
* @brief the class that deals with loading quads from the disk @todo a
|
|
|
|
* major improvment would be to store the data as a quad tree. It might
|
|
|
|
* improve lookup times. Then again. Might not
|
|
|
|
*/
|
2009-05-16 17:58:08 +00:00
|
|
|
class MWHeightmap
|
2009-05-15 07:04:50 +00:00
|
|
|
{
|
|
|
|
public:
|
2009-05-16 17:58:08 +00:00
|
|
|
/**
|
|
|
|
* loads the quad data from the disk
|
|
|
|
*/
|
|
|
|
QuadData* getData(long x, long y)
|
2009-05-15 07:04:50 +00:00
|
|
|
{
|
2009-05-16 17:58:08 +00:00
|
|
|
long offset = mIndex.getOffset(x,y);
|
|
|
|
if ( offset == -1 ) //check we have xy
|
2009-05-15 07:04:50 +00:00
|
|
|
assert(0);
|
|
|
|
|
2009-05-16 17:58:08 +00:00
|
|
|
mDataIFS.seekg(offset);
|
2009-05-15 07:04:50 +00:00
|
|
|
|
2009-05-16 17:58:08 +00:00
|
|
|
//load the quad from the file
|
|
|
|
QuadData* q = new QuadData();
|
|
|
|
boost::archive::binary_iarchive oa(mDataIFS);
|
|
|
|
oa >> *q;
|
|
|
|
return q;
|
2009-05-15 07:04:50 +00:00
|
|
|
}
|
|
|
|
|
2009-05-16 17:58:08 +00:00
|
|
|
inline bool hasData(long x, long y)
|
|
|
|
{ return (mIndex.getOffset(x,y) != -1 ); }
|
|
|
|
|
2009-05-15 07:04:50 +00:00
|
|
|
inline long getRootSideLength() {
|
|
|
|
return mIndex.getRootSideLength();
|
|
|
|
}
|
|
|
|
inline int getMaxDepth() {
|
|
|
|
return mIndex.getMaxDepth();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads the index and palette
|
|
|
|
*/
|
|
|
|
bool load(const std::string& fn)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::ifstream ifs(std::string(fn + ".index").c_str(), std::ios::binary);
|
|
|
|
boost::archive::binary_iarchive oa(ifs);
|
|
|
|
oa >> mIndex;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
std::ifstream ifs(std::string(fn + ".palette").c_str(), std::ios::binary);
|
|
|
|
boost::archive::binary_iarchive oa(ifs);
|
|
|
|
oa >> mPalette;
|
|
|
|
}
|
2009-05-16 17:58:08 +00:00
|
|
|
g_materialGen->setTexturePaths(mPalette.getPalette());
|
2009-05-15 07:04:50 +00:00
|
|
|
|
|
|
|
mDataIFS.open(std::string(fn + ".data").c_str(), std::ios::binary);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
///ifs for the data file. Opned on load
|
|
|
|
std::ifstream mDataIFS;
|
|
|
|
///holds the offsets of the quads
|
|
|
|
Index mIndex;
|
|
|
|
TexturePalette mPalette;
|
2009-05-16 17:58:08 +00:00
|
|
|
|
2009-05-15 07:04:50 +00:00
|
|
|
};
|