Merge branch 'itsover32767' into 'master'

Use more appropriate types in terrain storage

See merge request OpenMW/openmw!4125
esm4-texture
psi29a 7 months ago
commit c8567e96fd

@ -42,7 +42,7 @@ namespace CSVRender
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(
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;
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;

@ -11,8 +11,8 @@
namespace MWRender
{
TerrainStorage::TerrainStorage(Resource::ResourceSystem* resourceSystem, const std::string& normalMapPattern,
const std::string& normalHeightMapPattern, bool autoUseNormalMaps, const std::string& specularMapPattern,
TerrainStorage::TerrainStorage(Resource::ResourceSystem* resourceSystem, std::string_view normalMapPattern,
std::string_view normalHeightMapPattern, bool autoUseNormalMaps, std::string_view specularMapPattern,
bool autoUseSpecularMaps)
: ESMTerrain::Storage(resourceSystem->getVFS(), normalMapPattern, normalHeightMapPattern, autoUseNormalMaps,
specularMapPattern, autoUseSpecularMaps)
@ -105,8 +105,9 @@ namespace MWRender
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();
return esmStore.get<ESM::LandTexture>().search(index, plugin);
}

@ -16,13 +16,13 @@ namespace MWRender
class TerrainStorage : public ESMTerrain::Storage
{
public:
TerrainStorage(Resource::ResourceSystem* resourceSystem, const std::string& normalMapPattern = "",
const std::string& normalHeightMapPattern = "", bool autoUseNormalMaps = false,
const std::string& specularMapPattern = "", bool autoUseSpecularMaps = false);
TerrainStorage(Resource::ResourceSystem* resourceSystem, std::string_view normalMapPattern = {},
std::string_view normalHeightMapPattern = {}, bool autoUseNormalMaps = false,
std::string_view specularMapPattern = {}, bool autoUseSpecularMaps = false);
~TerrainStorage();
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;

@ -103,8 +103,8 @@ namespace ESMTerrain
const float defaultHeight = ESM::Land::DEFAULT_HEIGHT;
Storage::Storage(const VFS::Manager* vfs, const std::string& normalMapPattern,
const std::string& normalHeightMapPattern, bool autoUseNormalMaps, const std::string& specularMapPattern,
Storage::Storage(const VFS::Manager* vfs, std::string_view normalMapPattern,
std::string_view normalHeightMapPattern, bool autoUseNormalMaps, std::string_view specularMapPattern,
bool autoUseSpecularMaps)
: mVFS(vfs)
, mNormalMapPattern(normalMapPattern)
@ -368,23 +368,21 @@ namespace ESMTerrain
std::string Storage::getTextureName(UniqueTextureId id)
{
static constexpr char defaultTexture[] = "textures\\_land_default.dds";
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)
std::string_view texture = "_land_default.dds";
if (id.first != 0)
{
Log(Debug::Warning) << "Warning: Unable to find land texture index " << id.first - 1 << " in plugin "
<< id.second << ", using default texture instead";
return defaultTexture;
// NB: All vtex ids are +1 compared to the ltex ids
const ESM::LandTexture* ltex = getLandTexture(id.first - 1, id.second);
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
std::string texture = Misc::ResourceHelpers::correctTexturePath(ltex->mTexture, mVFS);
return texture;
return Misc::ResourceHelpers::correctTexturePath(texture, mVFS);
}
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);
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 x = 0; x < 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())
{
unsigned int layerIndex = layerList.size();
std::size_t layerIndex = layerList.size();
Terrain::LayerInfo info = getLayerInfo(getTextureName(id));
// 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)
{
@ -452,7 +450,7 @@ namespace ESMTerrain
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();
const std::size_t realY = (blendmapSize - y - 1) * imageScaleFactor;
const std::size_t realX = x * imageScaleFactor;

@ -67,13 +67,13 @@ namespace ESMTerrain
class Storage : public Terrain::Storage
{
public:
Storage(const VFS::Manager* vfs, const std::string& normalMapPattern = "",
const std::string& normalHeightMapPattern = "", bool autoUseNormalMaps = false,
const std::string& specularMapPattern = "", bool autoUseSpecularMaps = false);
Storage(const VFS::Manager* vfs, std::string_view normalMapPattern = {},
std::string_view normalHeightMapPattern = {}, bool autoUseNormalMaps = false,
std::string_view specularMapPattern = {}, bool autoUseSpecularMaps = false);
// 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 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
void getBounds(float& minX, float& maxX, float& minY, float& maxY, ESM::RefId worldspace) override = 0;

Loading…
Cancel
Save