2011-04-06 16:11:08 +00:00
|
|
|
#include "loadland.hpp"
|
|
|
|
|
2019-01-07 13:05:45 +00:00
|
|
|
#include <limits>
|
2015-08-31 09:06:32 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2012-09-23 18:41:41 +00:00
|
|
|
#include "esmreader.hpp"
|
|
|
|
#include "esmwriter.hpp"
|
2013-09-24 11:17:28 +00:00
|
|
|
#include "defs.hpp"
|
2012-09-17 07:37:50 +00:00
|
|
|
|
2011-04-06 16:11:08 +00:00
|
|
|
namespace ESM
|
|
|
|
{
|
2013-09-24 11:17:28 +00:00
|
|
|
unsigned int Land::sRecordId = REC_LAND;
|
2012-04-01 19:29:49 +00:00
|
|
|
|
2015-07-16 19:17:49 +00:00
|
|
|
Land::Land()
|
|
|
|
: mFlags(0)
|
|
|
|
, mX(0)
|
|
|
|
, mY(0)
|
|
|
|
, mPlugin(0)
|
|
|
|
, mDataTypes(0)
|
2018-10-09 06:21:12 +00:00
|
|
|
, mLandData(nullptr)
|
2012-01-21 16:59:08 +00:00
|
|
|
{
|
2012-09-20 16:33:30 +00:00
|
|
|
}
|
2015-07-16 19:17:49 +00:00
|
|
|
|
2017-02-14 01:30:21 +00:00
|
|
|
void transposeTextureData(const uint16_t *in, uint16_t *out)
|
2015-11-13 00:34:36 +00:00
|
|
|
{
|
|
|
|
int readPos = 0; //bit ugly, but it works
|
|
|
|
for ( int y1 = 0; y1 < 4; y1++ )
|
|
|
|
for ( int x1 = 0; x1 < 4; x1++ )
|
|
|
|
for ( int y2 = 0; y2 < 4; y2++)
|
|
|
|
for ( int x2 = 0; x2 < 4; x2++ )
|
|
|
|
out[(y1*4+y2)*16+(x1*4+x2)] = in[readPos++];
|
2012-09-21 05:36:18 +00:00
|
|
|
}
|
2015-11-13 00:34:36 +00:00
|
|
|
|
2015-07-16 19:17:49 +00:00
|
|
|
Land::~Land()
|
2012-01-21 16:59:08 +00:00
|
|
|
{
|
2015-07-16 19:17:49 +00:00
|
|
|
delete mLandData;
|
2012-09-20 16:33:30 +00:00
|
|
|
}
|
2012-04-06 19:04:30 +00:00
|
|
|
|
2015-07-20 14:23:14 +00:00
|
|
|
void Land::load(ESMReader &esm, bool &isDeleted)
|
2012-01-21 16:59:08 +00:00
|
|
|
{
|
2015-07-20 14:23:14 +00:00
|
|
|
isDeleted = false;
|
2012-04-01 19:29:49 +00:00
|
|
|
|
2016-02-09 19:14:16 +00:00
|
|
|
mPlugin = esm.getIndex();
|
2012-04-04 19:05:19 +00:00
|
|
|
|
2015-07-20 14:23:14 +00:00
|
|
|
bool hasLocation = false;
|
|
|
|
bool isLoaded = false;
|
|
|
|
while (!isLoaded && esm.hasMoreSubs())
|
2015-07-16 19:17:49 +00:00
|
|
|
{
|
2015-07-20 14:23:14 +00:00
|
|
|
esm.getSubName();
|
2016-05-07 17:32:51 +00:00
|
|
|
switch (esm.retSubName().intval)
|
2015-07-20 14:23:14 +00:00
|
|
|
{
|
|
|
|
case ESM::FourCC<'I','N','T','V'>::value:
|
|
|
|
esm.getSubHeaderIs(8);
|
|
|
|
esm.getT<int>(mX);
|
|
|
|
esm.getT<int>(mY);
|
|
|
|
hasLocation = true;
|
|
|
|
break;
|
|
|
|
case ESM::FourCC<'D','A','T','A'>::value:
|
|
|
|
esm.getHT(mFlags);
|
|
|
|
break;
|
2015-11-13 17:07:18 +00:00
|
|
|
case ESM::SREC_DELE:
|
2015-07-20 14:23:14 +00:00
|
|
|
esm.skipHSub();
|
|
|
|
isDeleted = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
esm.cacheSubName();
|
|
|
|
isLoaded = true;
|
|
|
|
break;
|
|
|
|
}
|
2015-07-16 19:17:49 +00:00
|
|
|
}
|
2012-03-27 08:20:22 +00:00
|
|
|
|
2015-07-20 14:23:14 +00:00
|
|
|
if (!hasLocation)
|
|
|
|
esm.fail("Missing INTV subrecord");
|
2011-04-06 16:11:08 +00:00
|
|
|
|
2015-07-16 19:17:49 +00:00
|
|
|
mContext = esm.getContext();
|
2011-04-06 16:11:08 +00:00
|
|
|
|
2018-10-09 06:21:12 +00:00
|
|
|
mLandData = nullptr;
|
2020-04-04 14:53:36 +00:00
|
|
|
std::fill(std::begin(mWnam), std::end(mWnam), 0);
|
2017-02-14 01:40:41 +00:00
|
|
|
|
2015-07-20 14:23:14 +00:00
|
|
|
// Skip the land data here. Load it when the cell is loaded.
|
|
|
|
while (esm.hasMoreSubs())
|
2015-07-16 19:17:49 +00:00
|
|
|
{
|
2015-07-20 14:23:14 +00:00
|
|
|
esm.getSubName();
|
2016-05-07 17:32:51 +00:00
|
|
|
switch (esm.retSubName().intval)
|
2015-07-20 14:23:14 +00:00
|
|
|
{
|
|
|
|
case ESM::FourCC<'V','N','M','L'>::value:
|
|
|
|
esm.skipHSub();
|
|
|
|
mDataTypes |= DATA_VNML;
|
|
|
|
break;
|
|
|
|
case ESM::FourCC<'V','H','G','T'>::value:
|
|
|
|
esm.skipHSub();
|
|
|
|
mDataTypes |= DATA_VHGT;
|
|
|
|
break;
|
|
|
|
case ESM::FourCC<'W','N','A','M'>::value:
|
2017-02-14 01:40:41 +00:00
|
|
|
esm.getHExact(mWnam, sizeof(mWnam));
|
2015-07-20 14:23:14 +00:00
|
|
|
mDataTypes |= DATA_WNAM;
|
|
|
|
break;
|
|
|
|
case ESM::FourCC<'V','C','L','R'>::value:
|
|
|
|
esm.skipHSub();
|
|
|
|
mDataTypes |= DATA_VCLR;
|
|
|
|
break;
|
|
|
|
case ESM::FourCC<'V','T','E','X'>::value:
|
|
|
|
esm.skipHSub();
|
|
|
|
mDataTypes |= DATA_VTEX;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
esm.fail("Unknown subrecord");
|
|
|
|
break;
|
|
|
|
}
|
2015-07-16 19:17:49 +00:00
|
|
|
}
|
2012-01-21 16:59:08 +00:00
|
|
|
}
|
2011-04-06 16:11:08 +00:00
|
|
|
|
2015-07-20 14:23:14 +00:00
|
|
|
void Land::save(ESMWriter &esm, bool isDeleted) const
|
2015-07-16 19:17:49 +00:00
|
|
|
{
|
|
|
|
esm.startSubRecord("INTV");
|
|
|
|
esm.writeT(mX);
|
|
|
|
esm.writeT(mY);
|
|
|
|
esm.endRecord("INTV");
|
2012-01-21 16:59:08 +00:00
|
|
|
|
2015-07-16 19:17:49 +00:00
|
|
|
esm.writeHNT("DATA", mFlags);
|
2012-04-06 19:04:30 +00:00
|
|
|
|
2015-07-20 14:23:14 +00:00
|
|
|
if (isDeleted)
|
2015-07-16 19:17:49 +00:00
|
|
|
{
|
|
|
|
esm.writeHNCString("DELE", "");
|
2015-07-28 12:04:22 +00:00
|
|
|
return;
|
2015-07-16 19:17:49 +00:00
|
|
|
}
|
2012-04-04 19:05:19 +00:00
|
|
|
|
2015-07-20 14:23:14 +00:00
|
|
|
if (mLandData)
|
2015-07-16 19:17:49 +00:00
|
|
|
{
|
2017-02-14 01:30:21 +00:00
|
|
|
if (mDataTypes & Land::DATA_VNML) {
|
2019-10-06 11:19:55 +00:00
|
|
|
esm.writeHNT("VNML", mLandData->mNormals);
|
2017-02-14 01:30:21 +00:00
|
|
|
}
|
|
|
|
if (mDataTypes & Land::DATA_VHGT) {
|
|
|
|
VHGT offsets;
|
|
|
|
offsets.mHeightOffset = mLandData->mHeights[0] / HEIGHT_SCALE;
|
|
|
|
offsets.mUnk1 = mLandData->mUnk1;
|
|
|
|
offsets.mUnk2 = mLandData->mUnk2;
|
|
|
|
|
|
|
|
float prevY = mLandData->mHeights[0];
|
|
|
|
int number = 0; // avoid multiplication
|
|
|
|
for (int i = 0; i < LAND_SIZE; ++i) {
|
|
|
|
float diff = (mLandData->mHeights[number] - prevY) / HEIGHT_SCALE;
|
|
|
|
offsets.mHeightData[number] =
|
|
|
|
(diff >= 0) ? (int8_t) (diff + 0.5) : (int8_t) (diff - 0.5);
|
|
|
|
|
|
|
|
float prevX = prevY = mLandData->mHeights[number];
|
|
|
|
++number;
|
|
|
|
|
|
|
|
for (int j = 1; j < LAND_SIZE; ++j) {
|
|
|
|
diff = (mLandData->mHeights[number] - prevX) / HEIGHT_SCALE;
|
|
|
|
offsets.mHeightData[number] =
|
|
|
|
(diff >= 0) ? (int8_t) (diff + 0.5) : (int8_t) (diff - 0.5);
|
|
|
|
|
|
|
|
prevX = mLandData->mHeights[number];
|
|
|
|
++number;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
esm.writeHNT("VHGT", offsets, sizeof(VHGT));
|
|
|
|
}
|
2020-04-04 13:39:32 +00:00
|
|
|
if (mDataTypes & Land::DATA_WNAM)
|
2020-01-10 12:49:57 +00:00
|
|
|
{
|
2020-04-04 13:39:32 +00:00
|
|
|
// Generate WNAM record
|
|
|
|
signed char wnam[LAND_GLOBAL_MAP_LOD_SIZE];
|
2021-05-04 21:03:14 +00:00
|
|
|
constexpr float max = std::numeric_limits<signed char>::max();
|
|
|
|
constexpr float min = std::numeric_limits<signed char>::min();
|
|
|
|
constexpr float vertMult = static_cast<float>(ESM::Land::LAND_SIZE - 1) / LAND_GLOBAL_MAP_LOD_SIZE_SQRT;
|
2020-04-04 13:39:32 +00:00
|
|
|
for (int row = 0; row < LAND_GLOBAL_MAP_LOD_SIZE_SQRT; ++row)
|
2020-01-10 12:49:57 +00:00
|
|
|
{
|
2020-04-04 13:39:32 +00:00
|
|
|
for (int col = 0; col < LAND_GLOBAL_MAP_LOD_SIZE_SQRT; ++col)
|
|
|
|
{
|
|
|
|
float height = mLandData->mHeights[int(row * vertMult) * ESM::Land::LAND_SIZE + int(col * vertMult)];
|
|
|
|
height /= height > 0 ? 128.f : 16.f;
|
|
|
|
height = std::min(max, std::max(min, height));
|
|
|
|
wnam[row * LAND_GLOBAL_MAP_LOD_SIZE_SQRT + col] = static_cast<signed char>(height);
|
|
|
|
}
|
2020-01-10 12:49:57 +00:00
|
|
|
}
|
2020-04-04 13:39:32 +00:00
|
|
|
esm.writeHNT("WNAM", wnam);
|
2020-01-10 12:49:57 +00:00
|
|
|
}
|
2017-02-14 01:30:21 +00:00
|
|
|
if (mDataTypes & Land::DATA_VCLR) {
|
2019-10-06 11:19:55 +00:00
|
|
|
esm.writeHNT("VCLR", mLandData->mColours);
|
2017-02-14 01:30:21 +00:00
|
|
|
}
|
|
|
|
if (mDataTypes & Land::DATA_VTEX) {
|
|
|
|
uint16_t vtex[LAND_NUM_TEXTURES];
|
|
|
|
transposeTextureData(mLandData->mTextures, vtex);
|
2019-10-06 11:19:55 +00:00
|
|
|
esm.writeHNT("VTEX", vtex);
|
2017-02-14 01:30:21 +00:00
|
|
|
}
|
2015-07-16 19:17:49 +00:00
|
|
|
}
|
2017-02-14 01:30:21 +00:00
|
|
|
|
2012-09-21 08:12:16 +00:00
|
|
|
}
|
2012-01-21 16:59:08 +00:00
|
|
|
|
2017-09-04 19:13:45 +00:00
|
|
|
void Land::blank()
|
|
|
|
{
|
|
|
|
mPlugin = 0;
|
|
|
|
|
2020-04-04 14:53:36 +00:00
|
|
|
std::fill(std::begin(mWnam), std::end(mWnam), 0);
|
2017-09-04 19:13:45 +00:00
|
|
|
|
2017-09-18 00:29:51 +00:00
|
|
|
if (!mLandData)
|
|
|
|
mLandData = new LandData;
|
|
|
|
|
2017-09-04 19:13:45 +00:00
|
|
|
mLandData->mHeightOffset = 0;
|
2020-04-04 14:53:36 +00:00
|
|
|
std::fill(std::begin(mLandData->mHeights), std::end(mLandData->mHeights), 0);
|
2017-09-04 19:13:45 +00:00
|
|
|
mLandData->mMinHeight = 0;
|
|
|
|
mLandData->mMaxHeight = 0;
|
|
|
|
for (int i = 0; i < LAND_NUM_VERTS; ++i)
|
|
|
|
{
|
|
|
|
mLandData->mNormals[i*3+0] = 0;
|
2017-09-09 01:03:52 +00:00
|
|
|
mLandData->mNormals[i*3+1] = 0;
|
|
|
|
mLandData->mNormals[i*3+2] = 127;
|
2017-09-04 19:13:45 +00:00
|
|
|
}
|
2020-04-04 14:53:36 +00:00
|
|
|
std::fill(std::begin(mLandData->mTextures), std::end(mLandData->mTextures), 0);
|
|
|
|
std::fill(std::begin(mLandData->mColours), std::end(mLandData->mColours), 255);
|
2017-09-04 19:13:45 +00:00
|
|
|
mLandData->mUnk1 = 0;
|
|
|
|
mLandData->mUnk2 = 0;
|
|
|
|
mLandData->mDataLoaded = Land::DATA_VNML | Land::DATA_VHGT | Land::DATA_WNAM |
|
|
|
|
Land::DATA_VCLR | Land::DATA_VTEX;
|
|
|
|
mDataTypes = mLandData->mDataLoaded;
|
|
|
|
|
2017-09-08 04:51:46 +00:00
|
|
|
// No file associated with the land now
|
|
|
|
mContext.filename.clear();
|
2017-09-04 19:13:45 +00:00
|
|
|
}
|
|
|
|
|
2017-03-06 23:25:04 +00:00
|
|
|
void Land::loadData(int flags, LandData* target) const
|
2015-07-16 19:17:49 +00:00
|
|
|
{
|
2017-03-06 23:25:04 +00:00
|
|
|
// Create storage if nothing is loaded
|
|
|
|
if (!target && !mLandData)
|
|
|
|
{
|
|
|
|
mLandData = new LandData;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!target)
|
|
|
|
target = mLandData;
|
2016-02-09 19:14:16 +00:00
|
|
|
|
2015-07-16 19:17:49 +00:00
|
|
|
// Try to load only available data
|
|
|
|
flags = flags & mDataTypes;
|
|
|
|
// Return if all required data is loaded
|
2017-03-06 23:25:04 +00:00
|
|
|
if ((target->mDataLoaded & flags) == flags) {
|
2015-07-16 19:17:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-04 19:13:45 +00:00
|
|
|
// Copy data to target if no file
|
2017-09-08 04:51:46 +00:00
|
|
|
if (mContext.filename.empty())
|
2017-09-04 19:13:45 +00:00
|
|
|
{
|
2017-09-10 03:18:09 +00:00
|
|
|
// Make sure there is data, and that it doesn't point to the same object.
|
|
|
|
if (mLandData && mLandData != target)
|
2017-09-09 15:48:13 +00:00
|
|
|
*target = *mLandData;
|
|
|
|
|
2017-09-04 19:13:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-09 19:14:16 +00:00
|
|
|
ESM::ESMReader reader;
|
|
|
|
reader.restoreContext(mContext);
|
|
|
|
|
|
|
|
if (reader.isNextSub("VNML")) {
|
2017-03-06 23:25:04 +00:00
|
|
|
condLoad(reader, flags, target->mDataLoaded, DATA_VNML, target->mNormals, sizeof(target->mNormals));
|
2015-07-16 19:17:49 +00:00
|
|
|
}
|
2012-01-21 16:59:08 +00:00
|
|
|
|
2016-02-09 19:14:16 +00:00
|
|
|
if (reader.isNextSub("VHGT")) {
|
2017-02-08 23:53:48 +00:00
|
|
|
VHGT vhgt;
|
2017-03-06 23:25:04 +00:00
|
|
|
if (condLoad(reader, flags, target->mDataLoaded, DATA_VHGT, &vhgt, sizeof(vhgt))) {
|
2019-01-07 13:05:45 +00:00
|
|
|
target->mMinHeight = std::numeric_limits<float>::max();
|
|
|
|
target->mMaxHeight = -std::numeric_limits<float>::max();
|
2015-07-16 19:17:49 +00:00
|
|
|
float rowOffset = vhgt.mHeightOffset;
|
|
|
|
for (int y = 0; y < LAND_SIZE; y++) {
|
|
|
|
rowOffset += vhgt.mHeightData[y * LAND_SIZE];
|
2012-01-21 16:59:08 +00:00
|
|
|
|
2017-03-06 23:25:04 +00:00
|
|
|
target->mHeights[y * LAND_SIZE] = rowOffset * HEIGHT_SCALE;
|
2017-03-07 14:00:16 +00:00
|
|
|
if (rowOffset * HEIGHT_SCALE > target->mMaxHeight)
|
|
|
|
target->mMaxHeight = rowOffset * HEIGHT_SCALE;
|
|
|
|
if (rowOffset * HEIGHT_SCALE < target->mMinHeight)
|
|
|
|
target->mMinHeight = rowOffset * HEIGHT_SCALE;
|
2012-01-21 17:59:12 +00:00
|
|
|
|
2015-07-16 19:17:49 +00:00
|
|
|
float colOffset = rowOffset;
|
|
|
|
for (int x = 1; x < LAND_SIZE; x++) {
|
|
|
|
colOffset += vhgt.mHeightData[y * LAND_SIZE + x];
|
2017-03-06 23:25:04 +00:00
|
|
|
target->mHeights[x + y * LAND_SIZE] = colOffset * HEIGHT_SCALE;
|
2017-03-07 14:00:16 +00:00
|
|
|
|
|
|
|
if (colOffset * HEIGHT_SCALE > target->mMaxHeight)
|
|
|
|
target->mMaxHeight = colOffset * HEIGHT_SCALE;
|
|
|
|
if (colOffset * HEIGHT_SCALE < target->mMinHeight)
|
|
|
|
target->mMinHeight = colOffset * HEIGHT_SCALE;
|
2015-07-16 19:17:49 +00:00
|
|
|
}
|
2012-09-21 05:36:18 +00:00
|
|
|
}
|
2017-03-06 23:25:04 +00:00
|
|
|
target->mUnk1 = vhgt.mUnk1;
|
|
|
|
target->mUnk2 = vhgt.mUnk2;
|
2012-01-21 16:59:08 +00:00
|
|
|
}
|
2012-01-21 17:59:12 +00:00
|
|
|
}
|
2012-01-21 16:59:08 +00:00
|
|
|
|
2017-02-14 01:40:41 +00:00
|
|
|
if (reader.isNextSub("WNAM"))
|
|
|
|
reader.skipHSub();
|
|
|
|
|
2016-02-09 19:14:16 +00:00
|
|
|
if (reader.isNextSub("VCLR"))
|
2017-03-06 23:25:04 +00:00
|
|
|
condLoad(reader, flags, target->mDataLoaded, DATA_VCLR, target->mColours, 3 * LAND_NUM_VERTS);
|
2016-02-09 19:14:16 +00:00
|
|
|
if (reader.isNextSub("VTEX")) {
|
2017-02-08 23:53:48 +00:00
|
|
|
uint16_t vtex[LAND_NUM_TEXTURES];
|
2017-03-06 23:25:04 +00:00
|
|
|
if (condLoad(reader, flags, target->mDataLoaded, DATA_VTEX, vtex, sizeof(vtex))) {
|
|
|
|
transposeTextureData(vtex, target->mTextures);
|
2015-07-16 19:17:49 +00:00
|
|
|
}
|
2012-01-21 16:59:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-13 00:29:22 +00:00
|
|
|
void Land::unloadData() const
|
2012-04-04 19:05:19 +00:00
|
|
|
{
|
2017-03-06 23:11:01 +00:00
|
|
|
if (mLandData)
|
2015-07-16 19:17:49 +00:00
|
|
|
{
|
|
|
|
delete mLandData;
|
2018-10-09 06:21:12 +00:00
|
|
|
mLandData = nullptr;
|
2015-07-16 19:17:49 +00:00
|
|
|
}
|
2012-09-21 08:12:16 +00:00
|
|
|
}
|
|
|
|
|
2017-03-06 23:25:04 +00:00
|
|
|
bool Land::condLoad(ESM::ESMReader& reader, int flags, int& targetFlags, int dataFlag, void *ptr, unsigned int size) const
|
2015-07-16 19:17:49 +00:00
|
|
|
{
|
2017-03-06 23:25:04 +00:00
|
|
|
if ((targetFlags & dataFlag) == 0 && (flags & dataFlag) != 0) {
|
2016-02-09 19:14:16 +00:00
|
|
|
reader.getHExact(ptr, size);
|
2017-03-06 23:25:04 +00:00
|
|
|
targetFlags |= dataFlag;
|
2015-07-16 19:17:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-02-09 19:14:16 +00:00
|
|
|
reader.skipHSubSize(size);
|
2015-07-16 19:17:49 +00:00
|
|
|
return false;
|
2012-04-04 19:05:19 +00:00
|
|
|
}
|
|
|
|
|
2015-07-16 19:17:49 +00:00
|
|
|
bool Land::isDataLoaded(int flags) const
|
|
|
|
{
|
2017-10-14 19:09:12 +00:00
|
|
|
return mLandData && (mLandData->mDataLoaded & flags) == flags;
|
2017-09-09 19:37:52 +00:00
|
|
|
}
|
|
|
|
|
2015-08-31 09:06:32 +00:00
|
|
|
Land::Land (const Land& land)
|
|
|
|
: mFlags (land.mFlags), mX (land.mX), mY (land.mY), mPlugin (land.mPlugin),
|
2017-09-08 04:51:46 +00:00
|
|
|
mContext (land.mContext), mDataTypes (land.mDataTypes),
|
2020-04-04 13:39:32 +00:00
|
|
|
mLandData (land.mLandData ? new LandData (*land.mLandData) : nullptr)
|
2019-10-06 10:23:49 +00:00
|
|
|
{
|
2019-10-06 18:57:10 +00:00
|
|
|
std::copy(land.mWnam, land.mWnam + LAND_GLOBAL_MAP_LOD_SIZE, mWnam);
|
2019-10-06 10:23:49 +00:00
|
|
|
}
|
2015-08-31 09:06:32 +00:00
|
|
|
|
2020-10-28 14:02:31 +00:00
|
|
|
Land& Land::operator= (const Land& land)
|
2015-08-31 09:06:32 +00:00
|
|
|
{
|
2020-10-28 14:02:31 +00:00
|
|
|
Land tmp(land);
|
|
|
|
swap(tmp);
|
2015-08-31 09:06:32 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Land::swap (Land& land)
|
|
|
|
{
|
|
|
|
std::swap (mFlags, land.mFlags);
|
|
|
|
std::swap (mX, land.mX);
|
|
|
|
std::swap (mY, land.mY);
|
|
|
|
std::swap (mPlugin, land.mPlugin);
|
|
|
|
std::swap (mContext, land.mContext);
|
|
|
|
std::swap (mDataTypes, land.mDataTypes);
|
|
|
|
std::swap (mLandData, land.mLandData);
|
2019-10-06 20:50:16 +00:00
|
|
|
std::swap (mWnam, land.mWnam);
|
2015-08-31 09:06:32 +00:00
|
|
|
}
|
2015-08-31 14:13:26 +00:00
|
|
|
|
|
|
|
const Land::LandData *Land::getLandData (int flags) const
|
|
|
|
{
|
|
|
|
if (!(flags & mDataTypes))
|
2020-04-04 13:39:32 +00:00
|
|
|
return nullptr;
|
2015-08-31 14:13:26 +00:00
|
|
|
|
|
|
|
loadData (flags);
|
|
|
|
return mLandData;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Land::LandData *Land::getLandData() const
|
|
|
|
{
|
|
|
|
return mLandData;
|
|
|
|
}
|
2015-09-03 14:15:00 +00:00
|
|
|
|
|
|
|
Land::LandData *Land::getLandData()
|
|
|
|
{
|
|
|
|
return mLandData;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Land::add (int flags)
|
|
|
|
{
|
|
|
|
if (!mLandData)
|
|
|
|
mLandData = new LandData;
|
|
|
|
|
|
|
|
mDataTypes |= flags;
|
2017-03-06 23:11:01 +00:00
|
|
|
mLandData->mDataLoaded |= flags;
|
2015-09-03 14:15:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Land::remove (int flags)
|
|
|
|
{
|
|
|
|
mDataTypes &= ~flags;
|
|
|
|
|
2017-03-06 23:11:01 +00:00
|
|
|
if (mLandData)
|
2015-09-03 14:15:00 +00:00
|
|
|
{
|
2017-03-06 23:11:01 +00:00
|
|
|
mLandData->mDataLoaded &= ~flags;
|
|
|
|
|
|
|
|
if (!mLandData->mDataLoaded)
|
|
|
|
{
|
|
|
|
delete mLandData;
|
2020-04-04 13:39:32 +00:00
|
|
|
mLandData = nullptr;
|
2017-03-06 23:11:01 +00:00
|
|
|
}
|
2015-09-03 14:15:00 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-06 16:11:08 +00:00
|
|
|
}
|