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

          Line data    Source code
       1             : /* Copyright (C) 2025 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             : #ifndef INCLUDED_DECAL
      19             : #define INCLUDED_DECAL
      20             : 
      21             : #include "graphics/Material.h"
      22             : #include "graphics/ModelAbstract.h"
      23             : #include "lib/debug.h"
      24             : #include "lib/posix/posix_types.h"
      25             : 
      26             : #include <cstddef>
      27             : 
      28             : class CTerrain;
      29             : 
      30             : /**
      31             :  * Terrain decal definition.
      32             :  * Decals are rectangular textures that are projected vertically downwards
      33             :  * onto the terrain.
      34             :  */
      35           3 : struct SDecal
      36             : {
      37           1 :     SDecal(const CMaterial& material, float sizeX, float sizeZ, float angle,
      38             :             float offsetX, float offsetZ, bool floating)
      39           1 :         : m_Material(material), m_SizeX(sizeX), m_SizeZ(sizeZ), m_Angle(angle),
      40           1 :           m_OffsetX(offsetX), m_OffsetZ(offsetZ), m_Floating(floating)
      41             :     {
      42             :     }
      43             : 
      44             :     CMaterial m_Material;
      45             :     float m_SizeX;
      46             :     float m_SizeZ;
      47             :     float m_Angle;
      48             :     float m_OffsetX;
      49             :     float m_OffsetZ;
      50             :     bool m_Floating;
      51             : };
      52             : 
      53             : class CModelDecal : public CModelAbstract
      54             : {
      55             : public:
      56           2 :     CModelDecal(CTerrain* terrain, const SDecal& decal)
      57           2 :         : m_Terrain(terrain), m_Decal(decal)
      58             :     {
      59           2 :         ENSURE(terrain != NULL);
      60           2 :     }
      61             : 
      62             :     /// Dynamic cast
      63           8 :     CModelDecal* ToCModelDecal() override
      64             :     {
      65           8 :         return this;
      66             :     }
      67             : 
      68             :     std::unique_ptr<CModelAbstract> Clone() const override;
      69             : 
      70             :     void SetTerrainDirty(ssize_t i0, ssize_t j0, ssize_t i1, ssize_t j1) override;
      71             : 
      72             :     void CalcBounds() override;
      73             :     void ValidatePosition() override;
      74             :     void InvalidatePosition() override;
      75             :     void SetTransform(const CMatrix3D& transform) override;
      76             : 
      77             :     // remove shadow receiving
      78             :     void RemoveShadowsReceive();
      79             : 
      80             :     /**
      81             :      * Compute the terrain vertex indexes that bound the decal's
      82             :      * projection onto the terrain.
      83             :      * The returned indexes are clamped to the terrain size.
      84             :      */
      85             :     void CalcVertexExtents(ssize_t& i0, ssize_t& j0, ssize_t& i1, ssize_t& j1);
      86             : 
      87             :     CTerrain* m_Terrain;
      88             :     SDecal m_Decal;
      89             : };
      90             : 
      91             : #endif // INCLUDED_DECAL

Generated by: LCOV version 1.16