From 35106691a14a4d41e095cb0bc82bd674e87a18d5 Mon Sep 17 00:00:00 2001 From: Hleb Valoshka <375gnu@gmail.com> Date: Fri, 6 Sep 2019 00:36:13 +0300 Subject: [PATCH] Fix virtual texture loading and VT code tiny cleanup --- src/celengine/virtualtex.cpp | 19 ++++++++++--------- src/celengine/virtualtex.h | 4 ++-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/celengine/virtualtex.cpp b/src/celengine/virtualtex.cpp index c3297e33..b7c5907c 100644 --- a/src/celengine/virtualtex.cpp +++ b/src/celengine/virtualtex.cpp @@ -55,14 +55,14 @@ static inline unsigned int lodOffset(unsigned int lod) #endif -VirtualTexture::VirtualTexture(fs::path _tilePath, +VirtualTexture::VirtualTexture(const fs::path& _tilePath, unsigned int _baseSplit, unsigned int _tileSize, - string _tilePrefix, + const string& _tilePrefix, const string& _tileType) : Texture(_tileSize << (_baseSplit + 1), _tileSize << _baseSplit), - tilePath(std::move(_tilePath)), - tilePrefix(std::move(_tilePrefix)), + tilePath(_tilePath), + tilePrefix(_tilePrefix), baseSplit(_baseSplit), tileSize(_tileSize), ticks(0), @@ -71,7 +71,7 @@ VirtualTexture::VirtualTexture(fs::path _tilePath, assert(tileSize != 0 && isPow2(tileSize)); tileTree[0] = new TileQuadtreeNode(); tileTree[1] = new TileQuadtreeNode(); - tileExt = string(".") + _tileType; + tileExt = fmt::sprintf(".%s", _tileType); populateTileTree(); if (DetermineFileType(tileExt) == Content_DXT5NormalMap) @@ -204,8 +204,9 @@ ImageTexture* VirtualTexture::loadTileTexture(unsigned int lod, unsigned int u, lod >>= baseSplit; assert(lod < (unsigned)MaxResolutionLevels); - auto path = fs::path(fmt::sprintf("%slevel%d", tilePath, lod)) / - fmt::sprintf("%s%d_%d%s", tilePrefix, u, v, tileExt); + auto path = tilePath / + fmt::sprintf("level%d", lod) / + fmt::sprintf("%s%d_%d%s", tilePrefix, u, v, tileExt.string()); Image* img = LoadImageFromFile(path); if (img == nullptr) @@ -258,7 +259,7 @@ void VirtualTexture::populateTileTree() for (int i = 0; i < MaxResolutionLevels; i++) { - fs::path path(fmt::sprintf("%slevel%d", tilePath, i)); + fs::path path = tilePath / fmt::sprintf("level%d", i); if (fs::is_directory(path)) { maxLevel = i + baseSplit; @@ -268,7 +269,7 @@ void VirtualTexture::populateTileTree() for (auto& d : fs::directory_iterator(path)) { int u = -1, v = -1; - if (sscanf(d.path().string().c_str(), pattern.c_str(), &u, &v) == 2) + if (sscanf(d.path().filename().string().c_str(), pattern.c_str(), &u, &v) == 2) { if (u >= 0 && v >= 0 && u < uLimit && v < vLimit) { diff --git a/src/celengine/virtualtex.h b/src/celengine/virtualtex.h index db2fd5d7..56297e9b 100644 --- a/src/celengine/virtualtex.h +++ b/src/celengine/virtualtex.h @@ -17,10 +17,10 @@ class VirtualTexture : public Texture { public: - VirtualTexture(fs::path _tilePath, + VirtualTexture(const fs::path& _tilePath, unsigned int _baseSplit, unsigned int _tileSize, - std::string _tilePrefix, + const std::string& _tilePrefix, const std::string& _tileType); ~VirtualTexture() = default;