LCOV - code coverage report
Current view: top level - source/graphics - HeightMipmap.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 1 1 100.0 %
Date: 2026-12-03 01:19:39 Functions: 0 0 -

          Line data    Source code
       1             : /* Copyright (C) 2026 Wildfire Games.
       2             :  * This file is part of 0 A.D.
       3             :  *
       4             :  * 0 A.D. is free software: you can redistribute it and/or modify
       5             :  * it under the terms of the GNU General Public License as published by
       6             :  * the Free Software Foundation, either version 2 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * 0 A.D. is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  * GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License
      15             :  * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : 
      19             : /*
      20             :  * Describes ground using heightmap mipmaps
      21             :  * Used for camera movement
      22             :  */
      23             : 
      24             : #ifndef INCLUDED_HEIGHTMIPMAP
      25             : #define INCLUDED_HEIGHTMIPMAP
      26             : 
      27             : #include "lib/code_annotation.h"
      28             : 
      29             : #include <cstddef>
      30             : #include <vector>
      31             : 
      32             : class Path;
      33             : using VfsPath = Path;
      34             : 
      35             : struct SMipmap
      36             : {
      37             :     SMipmap() : m_MapSize(0), m_Heightmap(0) { }
      38         184 :     SMipmap(size_t MapSize, std::uint16_t* Heightmap) : m_MapSize(MapSize), m_Heightmap(Heightmap) { }
      39             : 
      40             :     size_t m_MapSize;
      41             :     std::uint16_t* m_Heightmap;
      42             : };
      43             : 
      44             : class CHeightMipmap
      45             : {
      46             :     NONCOPYABLE(CHeightMipmap);
      47             : public:
      48             : 
      49             :     CHeightMipmap();
      50             :     ~CHeightMipmap();
      51             : 
      52             :     void Initialize(size_t mapSize, const std::uint16_t* ptr);
      53             :     void ReleaseData();
      54             : 
      55             :     // update the heightmap mipmaps
      56             :     void Update(const std::uint16_t* ptr);
      57             : 
      58             :     // update a section of the heightmap mipmaps
      59             :     // (coordinates are heightmap cells, inclusive of lower bounds,
      60             :     // exclusive of upper bounds)
      61             :     void Update(const std::uint16_t* ptr, size_t left, size_t bottom, size_t right, size_t top);
      62             : 
      63             :     float GetTrilinearGroundLevel(float x, float z, float radius) const;
      64             : 
      65             :     void DumpToDisk(const VfsPath& path) const;
      66             : 
      67             : private:
      68             : 
      69             :     // get bilinear filtered height from mipmap
      70             :     float BilinearFilter(const SMipmap &mipmap, float x, float z) const;
      71             : 
      72             :     // update rectangle of the output mipmap by bilinear interpolating an input mipmap of exactly twice its size
      73             :     void HalfResizeUpdate(SMipmap &out_mipmap, size_t mapSize, const std::uint16_t* ptr, size_t left, size_t bottom, size_t right, size_t top);
      74             : 
      75             :     // update rectangle of the output mipmap by bilinear interpolating the input mipmap
      76             :     void BilinearUpdate(SMipmap &out_mipmap, size_t mapSize, const std::uint16_t* ptr, size_t left, size_t bottom, size_t right, size_t top);
      77             : 
      78             :     // size of this map in each direction
      79             :     size_t m_MapSize;
      80             : 
      81             :     // mipmap list
      82             :     std::vector<SMipmap> m_Mipmap;
      83             : };
      84             : 
      85             : #endif

Generated by: LCOV version 1.16