Optimize getBlendmaps for the general case that most points are within the given cell

0.6.1
scrawl 8 years ago
parent 81c9853fe9
commit 0756fc4ae6

@ -314,7 +314,7 @@ namespace ESMTerrain
} }
Storage::UniqueTextureId Storage::getVtexIndexAt(int cellX, int cellY, Storage::UniqueTextureId Storage::getVtexIndexAt(int cellX, int cellY,
int x, int y) int x, int y, osg::ref_ptr<const LandObject> land)
{ {
// For the first/last row/column, we need to get the texture from the neighbour cell // For the first/last row/column, we need to get the texture from the neighbour cell
// to get consistent blending at the borders // to get consistent blending at the borders
@ -323,22 +323,27 @@ namespace ESMTerrain
{ {
--cellX; --cellX;
x += ESM::Land::LAND_TEXTURE_SIZE; x += ESM::Land::LAND_TEXTURE_SIZE;
land = NULL;
} }
while (x >= ESM::Land::LAND_TEXTURE_SIZE) while (x >= ESM::Land::LAND_TEXTURE_SIZE)
{ {
++cellX; ++cellX;
x -= ESM::Land::LAND_TEXTURE_SIZE; x -= ESM::Land::LAND_TEXTURE_SIZE;
land = NULL;
} }
while (y >= ESM::Land::LAND_TEXTURE_SIZE) // Y appears to be wrapped from the other side because why the hell not? while (y >= ESM::Land::LAND_TEXTURE_SIZE) // Y appears to be wrapped from the other side because why the hell not?
{ {
++cellY; ++cellY;
y -= ESM::Land::LAND_TEXTURE_SIZE; y -= ESM::Land::LAND_TEXTURE_SIZE;
land = NULL;
} }
assert(x<ESM::Land::LAND_TEXTURE_SIZE); assert(x<ESM::Land::LAND_TEXTURE_SIZE);
assert(y<ESM::Land::LAND_TEXTURE_SIZE); assert(y<ESM::Land::LAND_TEXTURE_SIZE);
osg::ref_ptr<const LandObject> land = getLand(cellX, cellY); if (!land)
land = getLand(cellX, cellY);
const ESM::Land::LandData *data = land ? land->getData(ESM::Land::DATA_VTEX) : 0; const ESM::Land::LandData *data = land ? land->getData(ESM::Land::DATA_VTEX) : 0;
if (data) if (data)
{ {
@ -393,10 +398,12 @@ namespace ESMTerrain
// So we're always adding _land_default.dds as the base layer here, even if it's not referenced in this cell. // So we're always adding _land_default.dds as the base layer here, even if it's not referenced in this cell.
textureIndices.insert(std::make_pair(0,0)); textureIndices.insert(std::make_pair(0,0));
osg::ref_ptr<const LandObject> land = getLand(cellX, cellY);
for (int y=colStart; y<colEnd; ++y) for (int y=colStart; y<colEnd; ++y)
for (int x=rowStart; x<rowEnd; ++x) for (int x=rowStart; x<rowEnd; ++x)
{ {
UniqueTextureId id = getVtexIndexAt(cellX, cellY, x, y); UniqueTextureId id = getVtexIndexAt(cellX, cellY, x, y, land);
textureIndices.insert(id); textureIndices.insert(id);
} }
@ -432,7 +439,7 @@ namespace ESMTerrain
{ {
for (int x=0; x<blendmapSize; ++x) for (int x=0; x<blendmapSize; ++x)
{ {
UniqueTextureId id = getVtexIndexAt(cellX, cellY, x+rowStart, y+colStart); UniqueTextureId id = getVtexIndexAt(cellX, cellY, x+rowStart, y+colStart, land);
assert(textureIndicesMap.find(id) != textureIndicesMap.end()); assert(textureIndicesMap.find(id) != textureIndicesMap.end());
int layerIndex = textureIndicesMap.find(id)->second; int layerIndex = textureIndicesMap.find(id)->second;
int blendIndex = (pack ? static_cast<int>(std::floor((layerIndex - 1) / 4.f)) : layerIndex - 1); int blendIndex = (pack ? static_cast<int>(std::floor((layerIndex - 1) / 4.f)) : layerIndex - 1);

@ -117,7 +117,7 @@ namespace ESMTerrain
typedef std::pair<short, short> UniqueTextureId; typedef std::pair<short, short> UniqueTextureId;
UniqueTextureId getVtexIndexAt(int cellX, int cellY, UniqueTextureId getVtexIndexAt(int cellX, int cellY,
int x, int y); int x, int y, osg::ref_ptr<const LandObject> land);
std::string getTextureName (UniqueTextureId id); std::string getTextureName (UniqueTextureId id);
std::map<std::string, Terrain::LayerInfo> mLayerInfoMap; std::map<std::string, Terrain::LayerInfo> mLayerInfoMap;

Loading…
Cancel
Save