From 0fce64ed5a73e7eae2821bc592051206f5b7c0fb Mon Sep 17 00:00:00 2001 From: vladislavbelov Date: Wed, 1 Feb 2023 21:56:35 +0000 Subject: [PATCH] Fixes Atlas previews after e4455a8e8f. Differential Revision: https://code.wildfiregames.com/D4919 This was SVN commit r27521. --- source/graphics/TextureManager.cpp | 10 ++++++++++ source/graphics/TextureManager.h | 7 ++++++- .../GameInterface/Handlers/TerrainHandlers.cpp | 18 +++++++++++++++--- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/source/graphics/TextureManager.cpp b/source/graphics/TextureManager.cpp index bec878d686..ec68b15989 100644 --- a/source/graphics/TextureManager.cpp +++ b/source/graphics/TextureManager.cpp @@ -685,6 +685,11 @@ public: } } + VfsPath GetCachedPath(const VfsPath& path) const + { + return m_CacheLoader.ArchiveCachePath(path); + } + bool MakeProgress() { // Process any completed conversion tasks @@ -1105,6 +1110,11 @@ bool CTextureManager::GenerateCachedTexture(const VfsPath& path, VfsPath& output return m->GenerateCachedTexture(path, outputPath); } +VfsPath CTextureManager::GetCachedPath(const VfsPath& path) const +{ + return m->GetCachedPath(path); +} + size_t CTextureManager::GetBytesUploaded() const { return m->GetBytesUploaded(); diff --git a/source/graphics/TextureManager.h b/source/graphics/TextureManager.h index 7580a56ac7..1ceaec15c4 100644 --- a/source/graphics/TextureManager.h +++ b/source/graphics/TextureManager.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2022 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -143,6 +143,11 @@ public: */ bool GenerateCachedTexture(const VfsPath& path, VfsPath& outputPath); + /** + * @return a cached version of the path + */ + VfsPath GetCachedPath(const VfsPath& path) const; + /** * Returns true if the given texture exists. * This tests both for the original and converted filename. diff --git a/source/tools/atlas/GameInterface/Handlers/TerrainHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/TerrainHandlers.cpp index a909ae9df9..8246007581 100644 --- a/source/tools/atlas/GameInterface/Handlers/TerrainHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/TerrainHandlers.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2022 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -30,6 +30,7 @@ #include "ps/World.h" #include "lib/tex/tex.h" #include "ps/Filesystem.h" +#include "renderer/Renderer.h" #include "simulation2/Simulation2.h" #include "simulation2/components/ICmpPathfinder.h" #include "simulation2/components/ICmpTerrain.h" @@ -76,12 +77,23 @@ sTerrainTexturePreview GetPreview(CTerrainTextureEntry* tex, size_t width, size_ // interesting; so just go down one mipmap level, then crop a chunk // out of the middle. + VfsPath texturePath; + if (!tex->GetDiffuseTexturePath().empty()) + { + const VfsPath cachedTexturePath = g_Renderer.GetTextureManager().GetCachedPath( + tex->GetDiffuseTexturePath()); + if (g_VFS->GetFileInfo(cachedTexturePath, nullptr) == INFO::OK) + texturePath = cachedTexturePath; + else + texturePath = tex->GetDiffuseTexturePath(); + } + std::shared_ptr fileData; size_t fileSize; Tex texture; const bool canUsePreview = - !tex->GetDiffuseTexturePath().empty() && - g_VFS->LoadFile(tex->GetDiffuseTexturePath(), fileData, fileSize) == INFO::OK && + !texturePath.empty() && + g_VFS->LoadFile(texturePath, fileData, fileSize) == INFO::OK && texture.decode(fileData, fileSize) == INFO::OK && // Check that we can fit the texture into the preview size before any transform. texture.m_Width >= width && texture.m_Height >= height &&