LCOV - code coverage report
Current view: top level - source/graphics - TerritoryBoundary.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             : #ifndef INCLUDED_TERRITORYBOUNDARY
      19             : #define INCLUDED_TERRITORYBOUNDARY
      20             : 
      21             : #include "maths/Vector2D.h"
      22             : #include "simulation2/helpers/Player.h"
      23             : 
      24             : #include <vector>
      25             : 
      26             : template<typename T> class Grid;
      27             : 
      28             : /**
      29             :  * Describes an outline of a territory, where the latter are understood to mean the largest sets of mutually connected tiles
      30             :  * ('connected' as in the mathematical sense from graph theory) that are either all reachable or all unreachable from a root
      31             :  * influence entity.
      32             :  *
      33             :  * Note that the latter property is also called the 'connected' flag in the territory manager terminology, because for tiles
      34             :  * to be reachable from a root influence entity they must in fact be mathematically connected. Hence, you should not confuse
      35             :  * the 'connected' flag with the pure mathematical concept of connectedness, because in the former it is implicitly
      36             :  * understood that the connection is to a root influence entity.
      37             :  */
      38          50 : struct STerritoryBoundary
      39             : {
      40             :     /// Set if this boundary should blink
      41             :     bool blinking;
      42             :     player_id_t owner;
      43             :     /// The boundary points, in clockwise order for inner boundaries and counter-clockwise order for outer boundaries.
      44             :     /// Note: if you need a way to explicitly find out which winding order these are in, you can have
      45             :     /// CTerritoryBoundCalculator::ComputeBoundaries set it during computation -- see its implementation for details.
      46             :     std::vector<CVector2D> points;
      47             : };
      48             : 
      49             : /**
      50             :  * Responsible for calculating territory boundaries, given an input territory map. Factored out for testing.
      51             :  */
      52             : class CTerritoryBoundaryCalculator
      53             : {
      54             : private:
      55             :     CTerritoryBoundaryCalculator(){} // private ctor
      56             : 
      57             : public:
      58             :     /**
      59             :      * Computes and returns all territory boundaries on the provided territory map (see STerritoryBoundary for a definition).
      60             :      * The result includes both inner and outer territory boundaries. Outer boundaries have their points in CCW order, inner
      61             :      * boundaries have them in CW order (because this matches the winding orders needed by the renderer to offset them
      62             :      * inwards/outwards appropriately).
      63             :      */
      64             :     static std::vector<STerritoryBoundary> ComputeBoundaries(const Grid<std::uint8_t>* territories);
      65             : };
      66             : 
      67             : #endif // INCLUDED_TERRITORYBOUNDARY

Generated by: LCOV version 1.16