Fix virtual texture loading and VT code tiny cleanup

pull/3/head
Hleb Valoshka 2019-09-06 00:36:13 +03:00
parent 31cc7363da
commit 35106691a1
2 changed files with 12 additions and 11 deletions

View File

@ -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)
{

View File

@ -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;