From f59f637cbbed70e7e8bbca97ff0284e6a75cca7d Mon Sep 17 00:00:00 2001 From: vladislavbelov Date: Sun, 26 Dec 2021 20:39:13 +0000 Subject: [PATCH] Cleanups TerrainTextureEntry a little, removes commented member from 88ab3f0f5b. This was SVN commit r26118. --- source/graphics/TerrainTextureEntry.cpp | 81 ++++++++++++------------- source/graphics/TerrainTextureEntry.h | 64 +++++++++---------- 2 files changed, 70 insertions(+), 75 deletions(-) diff --git a/source/graphics/TerrainTextureEntry.cpp b/source/graphics/TerrainTextureEntry.cpp index 71c8a5e3b2..3ff5be3cd0 100644 --- a/source/graphics/TerrainTextureEntry.cpp +++ b/source/graphics/TerrainTextureEntry.cpp @@ -19,21 +19,19 @@ #include "TerrainTextureEntry.h" -#include "lib/utf8.h" -#include "lib/ogl.h" +#include "graphics/MaterialManager.h" +#include "graphics/Terrain.h" +#include "graphics/TerrainProperties.h" +#include "graphics/TerrainTextureManager.h" +#include "graphics/Texture.h" #include "lib/allocators/shared_ptr.h" #include "lib/file/io/io.h" +#include "lib/ogl.h" #include "lib/res/graphics/ogl_tex.h" - +#include "lib/utf8.h" #include "ps/CLogger.h" #include "ps/Filesystem.h" #include "ps/XML/Xeromyces.h" - -#include "graphics/MaterialManager.h" -#include "graphics/Terrain.h" -#include "graphics/TerrainTextureManager.h" -#include "graphics/TerrainProperties.h" -#include "graphics/Texture.h" #include "renderer/Renderer.h" #include @@ -202,11 +200,11 @@ const float* CTerrainTextureEntry::GetTextureMatrix() const // LoadAlphaMaps: load the 14 default alpha maps, pack them into one composite texture and // calculate the coordinate of each alphamap within this packed texture -void CTerrainTextureEntry::LoadAlphaMaps(VfsPath &amtype) +void CTerrainTextureEntry::LoadAlphaMaps(const VfsPath& alphaMapType) { - std::wstring key = L"(alpha map composite" + amtype.string() + L")"; + const std::wstring key = L"(alpha map composite" + alphaMapType.string() + L")"; - CTerrainTextureManager::TerrainAlphaMap::iterator it = g_TexMan.m_TerrainAlphas.find(amtype); + CTerrainTextureManager::TerrainAlphaMap::iterator it = g_TexMan.m_TerrainAlphas.find(alphaMapType); if (it != g_TexMan.m_TerrainAlphas.end()) { @@ -214,8 +212,8 @@ void CTerrainTextureEntry::LoadAlphaMaps(VfsPath &amtype) return; } - g_TexMan.m_TerrainAlphas[amtype] = TerrainAlpha(); - it = g_TexMan.m_TerrainAlphas.find(amtype); + g_TexMan.m_TerrainAlphas[alphaMapType] = TerrainAlpha(); + it = g_TexMan.m_TerrainAlphas.find(alphaMapType); TerrainAlpha &result = it->second; @@ -224,9 +222,10 @@ void CTerrainTextureEntry::LoadAlphaMaps(VfsPath &amtype) // Handle textures[NUM_ALPHA_MAPS] = {0}; VfsPath path(L"art/textures/terrain/alphamaps"); - path = path / amtype; + path = path / alphaMapType; - const wchar_t* fnames[NUM_ALPHA_MAPS] = { + const wchar_t* fnames[NUM_ALPHA_MAPS] = + { L"blendcircle.png", L"blendlshape.png", L"blendedge.png", @@ -246,7 +245,7 @@ void CTerrainTextureEntry::LoadAlphaMaps(VfsPath &amtype) // for convenience, we require all alpha maps to be of the same BPP // (avoids another ogl_tex_get_size call, and doesn't hurt) size_t bpp = 0; - for(size_t i=0;i data; - AllocateAligned(data, total_w*total_h, maxSectorSize); + AllocateAligned(data, totalWidth * totalHeight, maxSectorSize); // for each tile on row - for (size_t i = 0; i < NUM_ALPHA_MAPS; i++) + for (size_t i = 0; i < NUM_ALPHA_MAPS; ++i) { // get src of copy u8* src = 0; ignore_result(ogl_tex_get_data(textures[i], &src)); - size_t srcstep = bpp/8; + const size_t srcStep = bpp / 8; // get destination of copy - u8* dst = data.get() + (i*tile_w); + u8* dst = data.get() + (i * tileWidth); // for each row of image - for (size_t j = 0; j < base; j++) + for (size_t j = 0; j < base; ++j) { // duplicate first pixel *dst++ = *src; *dst++ = *src; // copy a row - for (size_t k = 0; k < base; k++) + for (size_t k = 0; k < base; ++k) { *dst++ = *src; - src += srcstep; + src += srcStep; } // duplicate last pixel - *dst++ = *(src-srcstep); - *dst++ = *(src-srcstep); + *dst++ = *(src - srcStep); + *dst++ = *(src - srcStep); // advance write pointer for next row - dst += total_w-tile_w; + dst += totalWidth - tileWidth; } - result.m_AlphaMapCoords[i].u0 = float(i*tile_w+2) / float(total_w); - result.m_AlphaMapCoords[i].u1 = float((i+1)*tile_w-2) / float(total_w); + result.m_AlphaMapCoords[i].u0 = static_cast(i * tileWidth + 2) / totalWidth; + result.m_AlphaMapCoords[i].u1 = static_cast((i + 1) * tileWidth - 2) / totalWidth; result.m_AlphaMapCoords[i].v0 = 0.0f; result.m_AlphaMapCoords[i].v1 = 1.0f; } @@ -334,7 +333,7 @@ void CTerrainTextureEntry::LoadAlphaMaps(VfsPath &amtype) // upload the composite texture Tex t; - ignore_result(t.wrap(total_w, total_h, 8, TEX_GREY, data, 0)); + ignore_result(t.wrap(totalWidth, totalHeight, 8, TEX_GREY, data, 0)); // uncomment the following to save a png of the generated texture // in the public/ directory, for debugging diff --git a/source/graphics/TerrainTextureEntry.h b/source/graphics/TerrainTextureEntry.h index f9949834b8..1623156624 100644 --- a/source/graphics/TerrainTextureEntry.h +++ b/source/graphics/TerrainTextureEntry.h @@ -18,51 +18,23 @@ #ifndef INCLUDED_TERRAINTEXTUREENTRY #define INCLUDED_TERRAINTEXTUREENTRY -#include "TerrainTextureManager.h" -#include "TextureManager.h" -#include "Material.h" - -#include "lib/res/handle.h" +#include "graphics/Material.h" +#include "graphics/TerrainTextureManager.h" +#include "graphics/TextureManager.h" #include "lib/file/vfs/vfs_path.h" +#include "lib/res/handle.h" #include "maths/Matrix3D.h" #include "ps/CStr.h" #include -////////////////////////////////////////////////////////////////////////////////////////////////////////// // CTerrainTextureEntry: class wrapping a terrain texture object; contains various other required // elements - color of minimap, terrain "group" it belongs to, etc class CTerrainTextureEntry { public: - typedef std::vector GroupVector; + using GroupVector = std::vector; -private: - // Tag = file name stripped of path and extension (grass_dark_1) - CStr m_Tag; - - // The property sheet used by this texture - CTerrainPropertiesPtr m_pProperties; - - CMaterial m_Material; - - CMatrix3D m_TextureMatrix; - - // BGRA color of topmost mipmap level, for coloring minimap, or a color - // specified by the terrain properties - u32 m_BaseColor; - // ..Valid is true if the base color has been cached - bool m_BaseColorValid; - - // All terrain type groups we're a member of - GroupVector m_Groups; - - // calculate the root color of the texture, used for coloring minimap - void BuildBaseColor(); - - void LoadAlphaMaps(VfsPath &amtype); - -public: // Most of the texture's data is delay-loaded, so after the constructor has // been called, the texture entry is ready to be used. CTerrainTextureEntry(CTerrainPropertiesPtr props, const VfsPath& path); @@ -88,8 +60,32 @@ public: return m_BaseColor; } - //TerrainAlpha *m_TerrainAlpha; CTerrainTextureManager::TerrainAlphaMap::iterator m_TerrainAlpha; + +private: + // Tag = file name stripped of path and extension (grass_dark_1) + CStr m_Tag; + + // The property sheet used by this texture + CTerrainPropertiesPtr m_pProperties; + + CMaterial m_Material; + + CMatrix3D m_TextureMatrix; + + // BGRA color of topmost mipmap level, for coloring minimap, or a color + // specified by the terrain properties + u32 m_BaseColor; + // ..Valid is true if the base color has been cached + bool m_BaseColorValid; + + // All terrain type groups we're a member of + GroupVector m_Groups; + + // calculate the root color of the texture, used for coloring minimap + void BuildBaseColor(); + + void LoadAlphaMaps(const VfsPath& alphaMapType); }; #endif