From f09125fc931ecd5b948bc99c6ff586cec241194a Mon Sep 17 00:00:00 2001 From: bzzt Date: Wed, 20 Nov 2019 13:37:00 +0000 Subject: [PATCH] perf regression fix --- apps/opencs/view/render/terrainstorage.hpp | 2 ++ components/esmterrain/storage.cpp | 11 +++++++---- components/esmterrain/storage.hpp | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/apps/opencs/view/render/terrainstorage.hpp b/apps/opencs/view/render/terrainstorage.hpp index 032261ad4..74c30ce5c 100644 --- a/apps/opencs/view/render/terrainstorage.hpp +++ b/apps/opencs/view/render/terrainstorage.hpp @@ -18,6 +18,8 @@ namespace CSVRender TerrainStorage(const CSMWorld::Data& data); void setAlteredHeight(int inCellX, int inCellY, float heightMap); void resetHeights(); + + virtual bool useAlteration() const { return true; } float getSumOfAlteredAndTrueHeight(int cellX, int cellY, int inCellX, int inCellY); float* getAlteredHeight(int inCellX, int inCellY); diff --git a/components/esmterrain/storage.cpp b/components/esmterrain/storage.cpp index 52af530f5..021ae32e9 100644 --- a/components/esmterrain/storage.cpp +++ b/components/esmterrain/storage.cpp @@ -201,6 +201,8 @@ namespace ESMTerrain LandCache cache; + bool alteration = useAlteration(); + float vertY_ = 0; // of current cell corner for (int cellY = startCellY; cellY < startCellY + std::ceil(size); ++cellY) { @@ -251,11 +253,12 @@ namespace ESMTerrain float height = defaultHeight; if (heightData) height = heightData->mHeights[col*ESM::Land::LAND_SIZE + row]; - + if (alteration) + height += getAlteredHeight(col, row); (*positions)[static_cast(vertX*numVerts + vertY)] = osg::Vec3f((vertX / float(numVerts - 1) - 0.5f) * size * Constants::CellSizeInUnits, (vertY / float(numVerts - 1) - 0.5f) * size * Constants::CellSizeInUnits, - height + getAlteredHeight(col, row)); + height); if (normalData) { @@ -290,8 +293,8 @@ namespace ESMTerrain color.g() = 255; color.b() = 255; } - - adjustColor(col, row, heightData, color); //Does nothing by default, override in OpenMW-CS + if (alteration) + adjustColor(col, row, heightData, color); //Does nothing by default, override in OpenMW-CS // Unlike normals, colors mostly connect seamlessly between cells, but not always... if (col == ESM::Land::LAND_SIZE-1 || row == ESM::Land::LAND_SIZE-1) diff --git a/components/esmterrain/storage.hpp b/components/esmterrain/storage.hpp index 65e531e5c..a5f62ba48 100644 --- a/components/esmterrain/storage.hpp +++ b/components/esmterrain/storage.hpp @@ -125,6 +125,7 @@ namespace ESMTerrain inline const LandObject* getLand(int cellX, int cellY, LandCache& cache); + virtual bool useAlteration() const { return false; } virtual void adjustColor(int col, int row, const ESM::Land::LandData *heightData, osg::Vec4ub& color) const; virtual float getAlteredHeight(int col, int row) const;