mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 16:29:55 +00:00
Use more appropriate types in terrain storage
This commit is contained in:
parent
d15be7a685
commit
6a10311ae5
6 changed files with 33 additions and 34 deletions
|
@ -42,7 +42,7 @@ namespace CSVRender
|
||||||
land, ESM::Land::DATA_VHGT | ESM::Land::DATA_VNML | ESM::Land::DATA_VCLR | ESM::Land::DATA_VTEX);
|
land, ESM::Land::DATA_VHGT | ESM::Land::DATA_VNML | ESM::Land::DATA_VCLR | ESM::Land::DATA_VTEX);
|
||||||
}
|
}
|
||||||
|
|
||||||
const ESM::LandTexture* TerrainStorage::getLandTexture(int index, short plugin)
|
const ESM::LandTexture* TerrainStorage::getLandTexture(std::uint16_t index, int plugin)
|
||||||
{
|
{
|
||||||
const int row = mData.getLandTextures().searchId(
|
const int row = mData.getLandTextures().searchId(
|
||||||
ESM::RefId::stringRefId(CSMWorld::LandTexture::createUniqueRecordId(plugin, index)));
|
ESM::RefId::stringRefId(CSMWorld::LandTexture::createUniqueRecordId(plugin, index)));
|
||||||
|
|
|
@ -38,7 +38,7 @@ namespace CSVRender
|
||||||
std::array<float, ESM::Land::LAND_SIZE * ESM::Land::LAND_SIZE> mAlteredHeight;
|
std::array<float, ESM::Land::LAND_SIZE * ESM::Land::LAND_SIZE> mAlteredHeight;
|
||||||
|
|
||||||
osg::ref_ptr<const ESMTerrain::LandObject> getLand(ESM::ExteriorCellLocation cellLocation) override;
|
osg::ref_ptr<const ESMTerrain::LandObject> getLand(ESM::ExteriorCellLocation cellLocation) override;
|
||||||
const ESM::LandTexture* getLandTexture(int index, short plugin) override;
|
const ESM::LandTexture* getLandTexture(std::uint16_t index, int plugin) override;
|
||||||
|
|
||||||
void getBounds(float& minX, float& maxX, float& minY, float& maxY, ESM::RefId worldspace) override;
|
void getBounds(float& minX, float& maxX, float& minY, float& maxY, ESM::RefId worldspace) override;
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
namespace MWRender
|
namespace MWRender
|
||||||
{
|
{
|
||||||
|
|
||||||
TerrainStorage::TerrainStorage(Resource::ResourceSystem* resourceSystem, const std::string& normalMapPattern,
|
TerrainStorage::TerrainStorage(Resource::ResourceSystem* resourceSystem, std::string_view normalMapPattern,
|
||||||
const std::string& normalHeightMapPattern, bool autoUseNormalMaps, const std::string& specularMapPattern,
|
std::string_view normalHeightMapPattern, bool autoUseNormalMaps, std::string_view specularMapPattern,
|
||||||
bool autoUseSpecularMaps)
|
bool autoUseSpecularMaps)
|
||||||
: ESMTerrain::Storage(resourceSystem->getVFS(), normalMapPattern, normalHeightMapPattern, autoUseNormalMaps,
|
: ESMTerrain::Storage(resourceSystem->getVFS(), normalMapPattern, normalHeightMapPattern, autoUseNormalMaps,
|
||||||
specularMapPattern, autoUseSpecularMaps)
|
specularMapPattern, autoUseSpecularMaps)
|
||||||
|
@ -105,8 +105,9 @@ namespace MWRender
|
||||||
return mLandManager->getLand(cellLocation);
|
return mLandManager->getLand(cellLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
const ESM::LandTexture* TerrainStorage::getLandTexture(int index, short plugin)
|
const ESM::LandTexture* TerrainStorage::getLandTexture(std::uint16_t index, int plugin)
|
||||||
{
|
{
|
||||||
|
assert(plugin >= 0); // Saves don't contain textures
|
||||||
const MWWorld::ESMStore& esmStore = *MWBase::Environment::get().getESMStore();
|
const MWWorld::ESMStore& esmStore = *MWBase::Environment::get().getESMStore();
|
||||||
return esmStore.get<ESM::LandTexture>().search(index, plugin);
|
return esmStore.get<ESM::LandTexture>().search(index, plugin);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,13 +16,13 @@ namespace MWRender
|
||||||
class TerrainStorage : public ESMTerrain::Storage
|
class TerrainStorage : public ESMTerrain::Storage
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TerrainStorage(Resource::ResourceSystem* resourceSystem, const std::string& normalMapPattern = "",
|
TerrainStorage(Resource::ResourceSystem* resourceSystem, std::string_view normalMapPattern = {},
|
||||||
const std::string& normalHeightMapPattern = "", bool autoUseNormalMaps = false,
|
std::string_view normalHeightMapPattern = {}, bool autoUseNormalMaps = false,
|
||||||
const std::string& specularMapPattern = "", bool autoUseSpecularMaps = false);
|
std::string_view specularMapPattern = {}, bool autoUseSpecularMaps = false);
|
||||||
~TerrainStorage();
|
~TerrainStorage();
|
||||||
|
|
||||||
osg::ref_ptr<const ESMTerrain::LandObject> getLand(ESM::ExteriorCellLocation cellLocation) override;
|
osg::ref_ptr<const ESMTerrain::LandObject> getLand(ESM::ExteriorCellLocation cellLocation) override;
|
||||||
const ESM::LandTexture* getLandTexture(int index, short plugin) override;
|
const ESM::LandTexture* getLandTexture(std::uint16_t index, int plugin) override;
|
||||||
|
|
||||||
bool hasData(ESM::ExteriorCellLocation cellLocation) override;
|
bool hasData(ESM::ExteriorCellLocation cellLocation) override;
|
||||||
|
|
||||||
|
|
|
@ -103,8 +103,8 @@ namespace ESMTerrain
|
||||||
|
|
||||||
const float defaultHeight = ESM::Land::DEFAULT_HEIGHT;
|
const float defaultHeight = ESM::Land::DEFAULT_HEIGHT;
|
||||||
|
|
||||||
Storage::Storage(const VFS::Manager* vfs, const std::string& normalMapPattern,
|
Storage::Storage(const VFS::Manager* vfs, std::string_view normalMapPattern,
|
||||||
const std::string& normalHeightMapPattern, bool autoUseNormalMaps, const std::string& specularMapPattern,
|
std::string_view normalHeightMapPattern, bool autoUseNormalMaps, std::string_view specularMapPattern,
|
||||||
bool autoUseSpecularMaps)
|
bool autoUseSpecularMaps)
|
||||||
: mVFS(vfs)
|
: mVFS(vfs)
|
||||||
, mNormalMapPattern(normalMapPattern)
|
, mNormalMapPattern(normalMapPattern)
|
||||||
|
@ -368,23 +368,21 @@ namespace ESMTerrain
|
||||||
|
|
||||||
std::string Storage::getTextureName(UniqueTextureId id)
|
std::string Storage::getTextureName(UniqueTextureId id)
|
||||||
{
|
{
|
||||||
static constexpr char defaultTexture[] = "textures\\_land_default.dds";
|
std::string_view texture = "_land_default.dds";
|
||||||
if (id.first == 0)
|
if (id.first != 0)
|
||||||
return defaultTexture; // Not sure if the default texture really is hardcoded?
|
|
||||||
|
|
||||||
// NB: All vtex ids are +1 compared to the ltex ids
|
|
||||||
const ESM::LandTexture* ltex = getLandTexture(id.first - 1, id.second);
|
|
||||||
if (!ltex)
|
|
||||||
{
|
{
|
||||||
Log(Debug::Warning) << "Warning: Unable to find land texture index " << id.first - 1 << " in plugin "
|
// NB: All vtex ids are +1 compared to the ltex ids
|
||||||
<< id.second << ", using default texture instead";
|
const ESM::LandTexture* ltex = getLandTexture(id.first - 1, id.second);
|
||||||
return defaultTexture;
|
if (ltex)
|
||||||
|
texture = ltex->mTexture;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log(Debug::Warning) << "Warning: Unable to find land texture index " << id.first - 1 << " in plugin "
|
||||||
|
<< id.second << ", using default texture instead";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is needed due to MWs messed up texture handling
|
// this is needed due to MWs messed up texture handling
|
||||||
std::string texture = Misc::ResourceHelpers::correctTexturePath(ltex->mTexture, mVFS);
|
return Misc::ResourceHelpers::correctTexturePath(texture, mVFS);
|
||||||
|
|
||||||
return texture;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Storage::getBlendmaps(float chunkSize, const osg::Vec2f& chunkCenter, ImageVector& blendmaps,
|
void Storage::getBlendmaps(float chunkSize, const osg::Vec2f& chunkCenter, ImageVector& blendmaps,
|
||||||
|
@ -417,21 +415,21 @@ namespace ESMTerrain
|
||||||
|
|
||||||
sampleBlendmaps(chunkSize, origin.x(), origin.y(), ESM::Land::LAND_TEXTURE_SIZE, handleSample);
|
sampleBlendmaps(chunkSize, origin.x(), origin.y(), ESM::Land::LAND_TEXTURE_SIZE, handleSample);
|
||||||
|
|
||||||
std::map<UniqueTextureId, unsigned int> textureIndicesMap;
|
std::map<UniqueTextureId, std::size_t> textureIndicesMap;
|
||||||
|
|
||||||
for (std::size_t y = 0; y < blendmapSize; ++y)
|
for (std::size_t y = 0; y < blendmapSize; ++y)
|
||||||
{
|
{
|
||||||
for (std::size_t x = 0; x < blendmapSize; ++x)
|
for (std::size_t x = 0; x < blendmapSize; ++x)
|
||||||
{
|
{
|
||||||
const UniqueTextureId id = textureIds[y * blendmapSize + x];
|
const UniqueTextureId id = textureIds[y * blendmapSize + x];
|
||||||
std::map<UniqueTextureId, unsigned int>::iterator found = textureIndicesMap.find(id);
|
auto found = textureIndicesMap.find(id);
|
||||||
if (found == textureIndicesMap.end())
|
if (found == textureIndicesMap.end())
|
||||||
{
|
{
|
||||||
unsigned int layerIndex = layerList.size();
|
std::size_t layerIndex = layerList.size();
|
||||||
Terrain::LayerInfo info = getLayerInfo(getTextureName(id));
|
Terrain::LayerInfo info = getLayerInfo(getTextureName(id));
|
||||||
|
|
||||||
// look for existing diffuse map, which may be present when several plugins use the same texture
|
// look for existing diffuse map, which may be present when several plugins use the same texture
|
||||||
for (unsigned int i = 0; i < layerList.size(); ++i)
|
for (std::size_t i = 0; i < layerList.size(); ++i)
|
||||||
{
|
{
|
||||||
if (layerList[i].mDiffuseMap == info.mDiffuseMap)
|
if (layerList[i].mDiffuseMap == info.mDiffuseMap)
|
||||||
{
|
{
|
||||||
|
@ -452,7 +450,7 @@ namespace ESMTerrain
|
||||||
layerList.push_back(std::move(info));
|
layerList.push_back(std::move(info));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const unsigned int layerIndex = found->second;
|
const std::size_t layerIndex = found->second;
|
||||||
unsigned char* const data = blendmaps[layerIndex]->data();
|
unsigned char* const data = blendmaps[layerIndex]->data();
|
||||||
const std::size_t realY = (blendmapSize - y - 1) * imageScaleFactor;
|
const std::size_t realY = (blendmapSize - y - 1) * imageScaleFactor;
|
||||||
const std::size_t realX = x * imageScaleFactor;
|
const std::size_t realX = x * imageScaleFactor;
|
||||||
|
|
|
@ -67,13 +67,13 @@ namespace ESMTerrain
|
||||||
class Storage : public Terrain::Storage
|
class Storage : public Terrain::Storage
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Storage(const VFS::Manager* vfs, const std::string& normalMapPattern = "",
|
Storage(const VFS::Manager* vfs, std::string_view normalMapPattern = {},
|
||||||
const std::string& normalHeightMapPattern = "", bool autoUseNormalMaps = false,
|
std::string_view normalHeightMapPattern = {}, bool autoUseNormalMaps = false,
|
||||||
const std::string& specularMapPattern = "", bool autoUseSpecularMaps = false);
|
std::string_view specularMapPattern = {}, bool autoUseSpecularMaps = false);
|
||||||
|
|
||||||
// Not implemented in this class, because we need different Store implementations for game and editor
|
// Not implemented in this class, because we need different Store implementations for game and editor
|
||||||
virtual osg::ref_ptr<const LandObject> getLand(ESM::ExteriorCellLocation cellLocation) = 0;
|
virtual osg::ref_ptr<const LandObject> getLand(ESM::ExteriorCellLocation cellLocation) = 0;
|
||||||
virtual const ESM::LandTexture* getLandTexture(int index, short plugin) = 0;
|
virtual const ESM::LandTexture* getLandTexture(std::uint16_t index, int plugin) = 0;
|
||||||
/// Get bounds of the whole terrain in cell units
|
/// Get bounds of the whole terrain in cell units
|
||||||
void getBounds(float& minX, float& maxX, float& minY, float& maxY, ESM::RefId worldspace) override = 0;
|
void getBounds(float& minX, float& maxX, float& minY, float& maxY, ESM::RefId worldspace) override = 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue