1
0
forked from 0ad/0ad

Fixes Atlas previews after e4455a8e8f.

Differential Revision: https://code.wildfiregames.com/D4919
This was SVN commit r27521.
This commit is contained in:
Vladislav Belov 2023-02-01 21:56:35 +00:00
parent 4c4e978627
commit 0fce64ed5a
3 changed files with 31 additions and 4 deletions

View File

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

View File

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

View File

@ -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<u8> 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 &&