mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-19 21:23:54 +00:00
Temporary fix for adding new lands, cloned lands will still reference old data though
This commit is contained in:
parent
90c485104a
commit
d3014cf394
3 changed files with 64 additions and 15 deletions
|
@ -1,5 +1,8 @@
|
||||||
#include "terrainstorage.hpp"
|
#include "terrainstorage.hpp"
|
||||||
|
|
||||||
|
#include "../../model/world/land.hpp"
|
||||||
|
#include "../../model/world/landtexture.hpp"
|
||||||
|
|
||||||
namespace CSVRender
|
namespace CSVRender
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -11,12 +14,9 @@ namespace CSVRender
|
||||||
|
|
||||||
osg::ref_ptr<const ESMTerrain::LandObject> TerrainStorage::getLand(int cellX, int cellY)
|
osg::ref_ptr<const ESMTerrain::LandObject> TerrainStorage::getLand(int cellX, int cellY)
|
||||||
{
|
{
|
||||||
std::ostringstream stream;
|
|
||||||
stream << "#" << cellX << " " << cellY;
|
|
||||||
|
|
||||||
// The cell isn't guaranteed to have Land. This is because the terrain implementation
|
// The cell isn't guaranteed to have Land. This is because the terrain implementation
|
||||||
// has to wrap the vertices of the last row and column to the next cell, which may be a nonexisting cell
|
// has to wrap the vertices of the last row and column to the next cell, which may be a nonexisting cell
|
||||||
int index = mData.getLand().searchId(stream.str());
|
int index = mData.getLand().searchId(CSMWorld::Land::createUniqueRecordId(cellX, cellY));
|
||||||
if (index == -1)
|
if (index == -1)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -26,16 +26,11 @@ namespace CSVRender
|
||||||
|
|
||||||
const ESM::LandTexture* TerrainStorage::getLandTexture(int index, short plugin)
|
const ESM::LandTexture* TerrainStorage::getLandTexture(int index, short plugin)
|
||||||
{
|
{
|
||||||
int numRecords = mData.getLandTextures().getSize();
|
int row = mData.getLandTextures().searchId(CSMWorld::LandTexture::createUniqueRecordId(plugin, index));
|
||||||
|
if (row == -1)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
for (int i=0; i<numRecords; ++i)
|
return &mData.getLandTextures().getRecord(row).get();
|
||||||
{
|
|
||||||
const CSMWorld::LandTexture* ltex = &mData.getLandTextures().getRecord(i).get();
|
|
||||||
if (ltex->mIndex == index && ltex->mPluginIndex == plugin)
|
|
||||||
return ltex;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TerrainStorage::getBounds(float &minX, float &maxX, float &minY, float &maxY)
|
void TerrainStorage::getBounds(float &minX, float &maxX, float &minY, float &maxY)
|
||||||
|
|
|
@ -15,6 +15,7 @@ namespace ESM
|
||||||
, mX(0)
|
, mX(0)
|
||||||
, mY(0)
|
, mY(0)
|
||||||
, mPlugin(0)
|
, mPlugin(0)
|
||||||
|
, mNoFile(false)
|
||||||
, mDataTypes(0)
|
, mDataTypes(0)
|
||||||
, mLandData(NULL)
|
, mLandData(NULL)
|
||||||
{
|
{
|
||||||
|
@ -175,6 +176,47 @@ namespace ESM
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Land::blank()
|
||||||
|
{
|
||||||
|
if (mLandData)
|
||||||
|
{
|
||||||
|
delete mLandData;
|
||||||
|
}
|
||||||
|
|
||||||
|
mPlugin = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < LAND_GLOBAL_MAP_LOD_SIZE; ++i)
|
||||||
|
mWnam[0] = 0;
|
||||||
|
|
||||||
|
mLandData = new LandData;
|
||||||
|
mLandData->mHeightOffset = 0;
|
||||||
|
for (int i = 0; i < LAND_NUM_VERTS; ++i)
|
||||||
|
mLandData->mHeights[i] = 0;
|
||||||
|
mLandData->mMinHeight = 0;
|
||||||
|
mLandData->mMaxHeight = 0;
|
||||||
|
for (int i = 0; i < LAND_NUM_VERTS; ++i)
|
||||||
|
{
|
||||||
|
mLandData->mNormals[i*3+0] = 0;
|
||||||
|
mLandData->mNormals[i*3+1] = -1;
|
||||||
|
mLandData->mNormals[i*3+2] = 0;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < LAND_NUM_TEXTURES; ++i)
|
||||||
|
mLandData->mTextures[i] = 0;
|
||||||
|
for (int i = 0; i < LAND_NUM_VERTS; ++i)
|
||||||
|
{
|
||||||
|
mLandData->mColours[i*3+0] = -1;
|
||||||
|
mLandData->mColours[i*3+1] = -1;
|
||||||
|
mLandData->mColours[i*3+2] = -1;
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
|
||||||
|
mNoFile = true;
|
||||||
|
}
|
||||||
|
|
||||||
void Land::loadData(int flags, LandData* target) const
|
void Land::loadData(int flags, LandData* target) const
|
||||||
{
|
{
|
||||||
// Create storage if nothing is loaded
|
// Create storage if nothing is loaded
|
||||||
|
@ -193,6 +235,13 @@ namespace ESM
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy data to target if no file
|
||||||
|
if (mNoFile)
|
||||||
|
{
|
||||||
|
*target = *mLandData;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ESM::ESMReader reader;
|
ESM::ESMReader reader;
|
||||||
reader.restoreContext(mContext);
|
reader.restoreContext(mContext);
|
||||||
|
|
||||||
|
@ -271,7 +320,7 @@ namespace ESM
|
||||||
|
|
||||||
Land::Land (const Land& land)
|
Land::Land (const Land& land)
|
||||||
: mFlags (land.mFlags), mX (land.mX), mY (land.mY), mPlugin (land.mPlugin),
|
: mFlags (land.mFlags), mX (land.mX), mY (land.mY), mPlugin (land.mPlugin),
|
||||||
mContext (land.mContext), mDataTypes (land.mDataTypes),
|
mContext (land.mContext), mNoFile(land.mNoFile), mDataTypes (land.mDataTypes),
|
||||||
mLandData (land.mLandData ? new LandData (*land.mLandData) : 0)
|
mLandData (land.mLandData ? new LandData (*land.mLandData) : 0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
@ -288,6 +337,7 @@ namespace ESM
|
||||||
std::swap (mY, land.mY);
|
std::swap (mY, land.mY);
|
||||||
std::swap (mPlugin, land.mPlugin);
|
std::swap (mPlugin, land.mPlugin);
|
||||||
std::swap (mContext, land.mContext);
|
std::swap (mContext, land.mContext);
|
||||||
|
std::swap (mNoFile, land.mNoFile);
|
||||||
std::swap (mDataTypes, land.mDataTypes);
|
std::swap (mDataTypes, land.mDataTypes);
|
||||||
std::swap (mLandData, land.mLandData);
|
std::swap (mLandData, land.mLandData);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,10 @@ struct Land
|
||||||
// location later when we are ready to load the full data set.
|
// location later when we are ready to load the full data set.
|
||||||
ESM_Context mContext;
|
ESM_Context mContext;
|
||||||
|
|
||||||
|
// In the editor, a new Land is not associated with a file, thus mContext should not be accessed
|
||||||
|
// when land data is being requested. Instead simply copy over the data.
|
||||||
|
bool mNoFile;
|
||||||
|
|
||||||
int mDataTypes;
|
int mDataTypes;
|
||||||
|
|
||||||
enum
|
enum
|
||||||
|
@ -116,7 +120,7 @@ struct Land
|
||||||
void load(ESMReader &esm, bool &isDeleted);
|
void load(ESMReader &esm, bool &isDeleted);
|
||||||
void save(ESMWriter &esm, bool isDeleted = false) const;
|
void save(ESMWriter &esm, bool isDeleted = false) const;
|
||||||
|
|
||||||
void blank() {}
|
void blank();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Actually loads data into target
|
* Actually loads data into target
|
||||||
|
|
Loading…
Reference in a new issue