Changeset 24980

Timestamp:
Mar 2, 2021, 5:44:40 PM (3 years ago)
Author:
wraitii
Message:

Decouple LOS resolution from terrain resolution

Introduce a LOS_TILE_SIZE, to replace usage of TERRITORY_TILE_SIZE in the LOS code.
This makes it possible to change the resolution of LOS/Terrain without affecting the other component.

Additional refactoring:

  • LosTile has been renamed LosRegion (it's more comparable to the hierarchical pathfinder regions/spatial subdivisions)
  • LosState explicitly refers to "los vertices" instead of terrain vertices.

Refs #5566

Differential Revision: https://code.wildfiregames.com/D3076

Location:
ps/trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/binaries/data/mods/public/simulation/helpers/InitGame.js

    r24142 r24980  
    3939        let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
    4040        for (let i = 1; i < settings.PlayerData.length; ++i)
    41             cmpRangeManager.ExploreAllTiles(i);
     41            cmpRangeManager.Explore(i);
    4242    }
    4343
  • ps/trunk/source/graphics/LOSTexture.cpp

    r23774 r24980  
    2121
    2222#include "graphics/ShaderManager.h"
    23 #include "graphics/Terrain.h"
    2423#include "lib/bits.h"
    2524#include "lib/config2.h"
     
    3231#include "simulation2/Simulation2.h"
    3332#include "simulation2/components/ICmpRangeManager.h"
    34 #include "simulation2/components/ICmpTerrain.h"
    3533#include "simulation2/helpers/Los.h"
    3634
    3735/*
    3836
    39 The LOS bitmap is computed with one value per map vertex, based on
     37The LOS bitmap is computed with one value per vertex, based on
    4038CCmpRangeManager's visibility information.
    4139
     
    244242void CLOSTexture::ConstructTexture(int unit)
    245243{
    246     CmpPtr<ICmpTerrain> cmpTerrain(m_Simulation, SYSTEM_ENTITY);
    247     if (!cmpTerrain)
     244    CmpPtr<ICmp(m_Simulation, SYSTEM_ENTITY);
     245    if (!cmp)
    248246        return;
    249247
    250     m_MapSize = cmpTerrain->GetVerticesPerSide();
     248    m_MapSize = cmp->GetVerticesPerSide();
    251249
    252250    m_TextureSize = (GLsizei)round_up_to_pow2(round_up((size_t)m_MapSize + g_BlurSize - 1, g_SubTextureAlignment));
     
    295293        //     onto texcoord ((mapsize-0.5) / texsize, (mapsize-0.5) / texsize)  (i.e. middle of last texel)
    296294
    297         float s = (m_MapSize-1) / (float)(m_TextureSize * (m_MapSize-1) * TERRAIN_TILE_SIZE);
     295        float s = (m_MapSize-1) / (float)(m_TextureSize * (m_MapSize-1) * _TILE_SIZE);
    298296        float t = 0.5f / m_TextureSize;
    299297        m_TextureMatrix.SetZero();
     
    321319    if (m_Texture)
    322320    {
    323         CmpPtr<ICmpTerrain> cmpTerrain(m_Simulation, SYSTEM_ENTITY);
    324         if (cmpTerrain && m_MapSize != (ssize_t)cmpTerrain->GetVerticesPerSide())
     321        CmpPtr<ICmp(m_Simulation, SYSTEM_ENTITY);
     322        if (->GetVerticesPerSide())
    325323            DeleteTexture();
    326324    }
  • ps/trunk/source/graphics/LOSTexture.h

    r24227 r24980  
    100100    CShaderTechniquePtr m_smoothShader;
    101101
    102     ssize_t m_MapSize; // vertexes per side
     102    size_t m_MapSize; // vertexes per side
    103103    GLsizei m_TextureSize; // texels per side
    104104
  • ps/trunk/source/simulation2/components/CCmpProjectileManager.cpp

    r23774 r24980  
    363363{
    364364    // Don't display objects outside the visible area
    365     ssize_t posi = (ssize_t)(0.5f + position.X / TERRAIN_TILE_SIZE);
    366     ssize_t posj = (ssize_t)(0.5f + position.Z / TERRAIN_TILE_SIZE);
     365    ssize_t posi = (ssize_t)(0.5f + position.X / _TILE_SIZE);
     366    ssize_t posj = (ssize_t)(0.5f + position.Z / _TILE_SIZE);
    367367    if (!losRevealAll && !los.IsVisible(posi, posj))
    368368        return;
  • ps/trunk/source/simulation2/components/CCmpRallyPointRenderer.cpp

    r24144 r24980  
    817817    // a new one at the next point.
    818818
    819     const float terrainSize = static_cast<float>(TERRAIN_TILE_SIZE);
     819    const float _TILE_SIZE);
    820820    bool lastVisible = losQuerier.IsExplored(
    821         (fixed::FromFloat(m_Path[index][0].X / terrainSize)).ToInt_RoundToNearest(),
    822         (fixed::FromFloat(m_Path[index][0].Y / terrainSize)).ToInt_RoundToNearest()
     821        (fixed::FromFloat(m_Path[index][0].X / Size)).ToInt_RoundToNearest(),
     822        (fixed::FromFloat(m_Path[index][0].Y / Size)).ToInt_RoundToNearest()
    823823    );
    824824    // Starting node index of the current segment
     
    828828    {
    829829        // Grab tile indices for this coord
    830         int i = (fixed::FromFloat(m_Path[index][k].X / terrainSize)).ToInt_RoundToNearest();
    831         int j = (fixed::FromFloat(m_Path[index][k].Y / terrainSize)).ToInt_RoundToNearest();
     830        int i = (fixed::FromFloat(m_Path[index][k].X / Size)).ToInt_RoundToNearest();
     831        int j = (fixed::FromFloat(m_Path[index][k].Y / Size)).ToInt_RoundToNearest();
    832832
    833833        bool nodeVisible = losQuerier.IsExplored(i, j);
  • ps/trunk/source/simulation2/components/CCmpRangeManager.cpp

    r24776 r24980  
    4646#include "renderer/Scene.h"
    4747
    48 #define LOS_TILES_RATIO 8
    4948#define DEBUG_RANGE_MANAGER_BOUNDS 0
    5049
     50
    5151
    5252/**
     
    114114
    115115/**
    116  * Test whether the visibility is dirty for a given LoS tile and a given player
     116 * Test whether the visibility is dirty for a given LoS and a given player
    117117 */
    118118static inline bool IsVisibilityDirty(u16 dirty, player_id_t player)
     
    382382    static const player_id_t MAX_LOS_PLAYER_ID = 16;
    383383
    384     using LosTile = std::pair<u16, u16>;
     384    using Los = std::pair<u16, u16>;
    385385
    386386    std::array<bool, MAX_LOS_PLAYER_ID+2> m_LosRevealAll;
    387387    bool m_LosCircular;
    388     i32 m_TerrainVerticesPerSide;
     388    i32 m_VerticesPerSide;
    389389
    390390    // Cache for visibility tracking
    391     i32 m_LosTilesPerSide;
     391    i32 m_LossPerSide;
    392392    bool m_GlobalVisibilityUpdate;
    393393    std::array<bool, MAX_LOS_PLAYER_ID> m_GlobalPlayerVisibilityUpdate;
    394394    Grid<u16> m_DirtyVisibility;
    395     Grid<std::set<entity_id_t>> m_LosTiles;
     395    Grid<std::set<entity_id_t>> m_Loss;
    396396    // List of entities that must be updated, regardless of the status of their tile
    397397    std::vector<entity_id_t> m_ModifiedEntities;
     
    448448
    449449        m_LosCircular = false;
    450         m_TerrainVerticesPerSide = 0;
     450        m_VerticesPerSide = 0;
    451451    }
    452452
     
    469469        Serializer(serialize, "los reveal all", m_LosRevealAll);
    470470        serialize.Bool("los circular", m_LosCircular);
    471         serialize.NumberI32_Unbounded("terrain verts per side", m_TerrainVerticesPerSide);
     471        serialize.NumberI32_Unbounded("VerticesPerSide);
    472472
    473473        serialize.Bool("global visibility update", m_GlobalVisibilityUpdate);
     
    476476        Serializer(serialize, "modified entities", m_ModifiedEntities);
    477477
    478         // We don't serialize m_Subdivision, m_LosPlayerCounts or m_LosTiles
     478        // We don't serialize m_Subdivision, m_LosPlayerCounts or m_Loss
    479479        // since they can be recomputed from the entity data when deserializing;
    480480        // m_LosState must be serialized since it depends on the history of exploration
     
    571571                    else
    572572                        LosMove(it->second.owner, it->second.visionRange, from, to);
    573                     LosTile oldLosTile = PosToLosTilesHelper(it->second.x, it->second.z);
    574                     LosTile newLosTile = PosToLosTilesHelper(msgData.x, msgData.z);
    575                     if (oldLosTile != newLosTile)
     573                    LossHelper(it->second.x, it->second.z);
     574                    LossHelper(msgData.x, msgData.z);
     575                    if (oldLos)
    576576                    {
    577                         RemoveFromTile(oldLosTile, ent);
    578           ��             AddToTile(newLosTile, ent);
     577                        RemoveFrom, ent);
     578                        AddTo, ent);
    579579                    }
    580580                }
     
    587587                    else
    588588                        LosAdd(it->second.owner, it->second.visionRange, to);
    589                     AddToTile(PosToLosTilesHelper(msgData.x, msgData.z), ent);
     589                    AddTosHelper(msgData.x, msgData.z), ent);
    590590                }
    591591
     
    604604                    else
    605605                        LosRemove(it->second.owner, it->second.visionRange, from);
    606                     RemoveFromTile(PosToLosTilesHelper(it->second.x, it->second.z), ent);
     606                    RemoveFromsHelper(it->second.x, it->second.z), ent);
    607607                }
    608608
     
    664664            {
    665665                m_Subdivision.Remove(ent, CFixedVector2D(it->second.x, it->second.z), it->second.size);
    666                 RemoveFromTile(PosToLosTilesHelper(it->second.x, it->second.z), ent);
     666                RemoveFromsHelper(it->second.x, it->second.z), ent);
    667667            }
    668668
     
    770770    }
    771771
    772     virtual void SetBounds(entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, ssize_t vertices)
    773     {
     772    virtual void SetBounds(entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1)
     773    {
     774        // Don't support rectangular looking maps.
     775        ENSURE(x1-x0 == z1-z0);
    774776        m_WorldX0 = x0;
    775777        m_WorldZ0 = z0;
    776778        m_WorldX1 = x1;
    777779        m_WorldZ1 = z1;
    778         m_TerrainVerticesPerSide = (i32)vertices;
     780        m_;
    779781
    780782        ResetDerivedData();
     
    793795        Grid<u32> oldStateRevealed = m_LosStateRevealed;
    794796        FastSpatialSubdivision oldSubdivision = m_Subdivision;
    795         Grid<std::set<entity_id_t> > oldLosTiles = m_LosTiles;
     797        Grid<std::set<entity_id_t> > oldLoss;
    796798
    797799        m_Deserializing = true;
     
    827829        if (oldSubdivision != m_Subdivision)
    828830            debug_warn(L"inconsistent subdivs");
    829         if (oldLosTiles != m_LosTiles)
    830             debug_warn(L"inconsistent los tiles");
     831        if (oldLoss)
     832            debug_warn(L"inconsistent los s");
    831833    }
    832834
     
    842844        ResetSubdivisions(m_WorldX1, m_WorldZ1);
    843845
    844         m_LosTilesPerSide = (m_TerrainVerticesPerSide - 1)/LOS_TILES_RATIO;
     846        m_Los_RATIO;
    845847
    846848        for (size_t player_id = 0; player_id < m_LosPlayerCounts.size(); ++player_id)
     
    853855        {
    854856            // recalc current exploration stats.
    855             for (i32 j = 0; j < m_TerrainVerticesPerSide; j++)
    856                 for (i32 i = 0; i < m_TerrainVerticesPerSide; i++)
     857            for (i32 j = 0; j < m_VerticesPerSide; j++)
     858                for (i32 i = 0; i < m_VerticesPerSide; i++)
    857859                    if (!LosIsOffWorld(i, j))
    858860                        for (u8 k = 1; k < MAX_LOS_PLAYER_ID+1; ++k)
    859861                            m_ExploredVertices.at(k) += ((m_LosState.get(i, j) & ((u32)LosState::EXPLORED << (2*(k-1)))) > 0);
    860862        } else
    861             m_LosState.resize(m_TerrainVerticesPerSide, m_TerrainVerticesPerSide);
    862 
    863         m_LosStateRevealed.resize(m_TerrainVerticesPerSide, m_TerrainVerticesPerSide);
     863            m_LosState.resize(m_VerticesPerSide);
     864
     865        m_LosStateRevealed.resize(m_VerticesPerSide);
    864866
    865867        if (!m_Deserializing)
    866868        {
    867             m_DirtyVisibility.resize(m_LosTilesPerSide, m_LosTilesPerSide);
    868         }
    869         ENSURE(m_DirtyVisibility.width() == m_LosTilesPerSide);
    870         ENSURE(m_DirtyVisibility.height() == m_LosTilesPerSide);
    871 
    872         m_LosTiles.resize(m_LosTilesPerSide, m_LosTilesPerSide);
     869            m_DirtyVisibility.resize(m_LossPerSide);
     870        }
     871        ENSURE(m_DirtyVisibility.width() == m_LossPerSide);
     872        ENSURE(m_DirtyVisibility.height() == m_LossPerSide);
     873
     874        m_LossPerSide);
    873875
    874876        for (EntityMap<EntityData>::const_iterator it = m_EntityData.begin(); it != m_EntityData.end(); ++it)
     
    879881                else
    880882                    LosAdd(it->second.owner, it->second.visionRange, CFixedVector2D(it->second.x, it->second.z));
    881                 AddToTile(PosToLosTilesHelper(it->second.x, it->second.z), it->first);
     883                AddTosHelper(it->second.x, it->second.z), it->first);
    882884
    883885                if (it->second.HasFlag<FlagMasks::RevealShore>())
     
    886888
    887889        m_TotalInworldVertices = 0;
    888         for (ssize_t j = 0; j < m_TerrainVerticesPerSide; ++j)
    889             for (ssize_t i = 0; i < m_TerrainVerticesPerSide; ++i)
     890        for (VerticesPerSide; ++j)
     891            for (VerticesPerSide; ++i)
    890892            {
    891893                if (LosIsOffWorld(i,j))
     
    16011603    {
    16021604        if (GetLosRevealAll(player))
    1603             return CLosQuerier(0xFFFFFFFFu, m_LosStateRevealed, m_TerrainVerticesPerSide);
     1605            return CLosQuerier(0xFFFFFFFFu, m_LosStateRevealed, m_VerticesPerSide);
    16041606        else
    1605             return CLosQuerier(GetSharedLosMask(player), m_LosState, m_TerrainVerticesPerSide);
     1607            return CLosQuerier(GetSharedLosMask(player), m_LosState, m_VerticesPerSide);
    16061608    }
    16071609
     
    16281630
    16291631        CFixedVector2D pos = cmpPosition->GetPosition2D();
    1630         int i = (pos.X / (int)TERRAIN_TILE_SIZE).ToInt_RoundToNearest();
    1631         int j = (pos.Y / (int)TERRAIN_TILE_SIZE).ToInt_RoundToNearest();
     1632        int i = (pos.X / _TILE_SIZE).ToInt_RoundToNearest();
     1633        int j = (pos.Y / _TILE_SIZE).ToInt_RoundToNearest();
    16321634
    16331635        // Reveal flag makes all positioned entities visible and all mirages useless
     
    16401642
    16411643        // Get visible regions
    1642         CLosQuerier los(GetSharedLosMask(player), m_LosState, m_TerrainVerticesPerSide);
     1644        CLosQuerier los(GetSharedLosMask(player), m_LosState, m_VerticesPerSide);
    16431645
    16441646        CmpPtr<ICmpVisibility> cmpVisibility(ent);
     
    17341736        CFixedVector2D pos = cmpPosition->GetPosition2D();
    17351737
    1736         if (IsVisibilityDirty(m_DirtyVisibility[PosToLosTilesHelper(pos.X, pos.Y)], player))
     1738        if (IsVisibilityDirty(m_DirtyVisibility[PosToLossHelper(pos.X, pos.Y)], player))
    17371739            return ComputeLosVisibility(ent, player);
    17381740
     
    17551757    virtual LosVisibility GetLosVisibilityPosition(entity_pos_t x, entity_pos_t z, player_id_t player) const
    17561758    {
    1757         int i = (x / (int)TERRAIN_TILE_SIZE).ToInt_RoundToNearest();
    1758         int j = (z / (int)TERRAIN_TILE_SIZE).ToInt_RoundToNearest();
     1759        int i = (x / _TILE_SIZE).ToInt_RoundToNearest();
     1760        int j = (z / _TILE_SIZE).ToInt_RoundToNearest();
    17591761
    17601762        // Reveal flag makes all positioned entities visible and all mirages useless
     
    17681770
    17691771        // Get visible regions
    1770         CLosQuerier los(GetSharedLosMask(player), m_LosState, m_TerrainVerticesPerSide);
     1772        CLosQuerier los(GetSharedLosMask(player), m_LosState, m_VerticesPerSide);
    17711773
    17721774        if (los.IsVisible(i,j))
     
    17771779    }
    17781780
    1779     LosTile PosToLosTilesHelper(u16 x, u16 z) const
    1780     {
    1781         return LosTile{ Clamp(x/LOS_TILES_RATIO, 0, m_LosTilesPerSide - 1), Clamp(z/LOS_TILES_RATIO, 0, m_LosTilesPerSide - 1) };
    1782     }
    1783 
    1784     LosTile PosToLosTilesHelper(entity_pos_t x, entity_pos_t z) const
    1785     {
    1786         i32 i = Clamp(
    1787             (x/(entity_pos_t::FromInt(TERRAIN_TILE_SIZE * LOS_TILES_RATIO))).ToInt_RoundToZero(),
     1781    size_t GetVerticesPerSide() const
     1782    {
     1783        return m_LosVerticesPerSide;
     1784    }
     1785
     1786    LosRegion LosVertexToLosRegionsHelper(u16 x, u16 z) const
     1787    {
     1788        return LosRegion {
     1789            Clamp(x/LOS_REGION_RATIO, 0, m_LosRegionsPerSide - 1),
     1790            Clamp(z/LOS_REGION_RATIO, 0, m_LosRegionsPerSide - 1)
     1791        };
     1792    }
     1793
     1794    LosRegion PosToLosRegionsHelper(entity_pos_t x, entity_pos_t z) const
     1795    {
     1796        u16 i = Clamp(
     1797            ((x/LOS_TILE_SIZE)/LOS_REGION_RATIO).ToInt_RoundToZero(),
    17881798            0,
    1789             m_LosTilesPerSide - 1);
    1790         i32 j = Clamp(
    1791             (z/(entity_pos_t::FromInt(TERRAIN_TILE_SIZE * LOS_TILES_RATIO))).ToInt_RoundToZero(),
     1799            m_LossPerSide - 1);
     1800        j = Clamp(
     1801            ().ToInt_RoundToZero(),
    17921802            0,
    1793             m_LosTilesPerSide - 1);
     1803            m_LossPerSide - 1);
    17941804        return std::make_pair(i, j);
    17951805    }
    17961806
    1797     void AddToTile(LosTile tile, entity_id_t ent)
    1798     {
    1799         m_LosTiles[tile].insert(ent);
    1800     }
    1801 
    1802     void RemoveFromTile(LosTile tile, entity_id_t ent)
    1803     {
    1804         std::set<entity_id_t>::const_iterator tileIt = m_LosTiles[tile].find(ent);
    1805         if (tileIt != m_LosTiles[tile].end())
    1806             m_LosTiles[tile].erase(tileIt);
     1807    void AddTo, entity_id_t ent)
     1808    {
     1809        m_Los].insert(ent);
     1810    }
     1811
     1812    void RemoveFrom, entity_id_t ent)
     1813    {
     1814        std::set<entity_id_t>::const_iterator ].find(ent);
     1815        if (].end())
     1816            m_LosIt);
    18071817    }
    18081818
     
    18111821        PROFILE("UpdateVisibilityData");
    18121822
    1813         for (u16 i = 0; i < m_LosTilesPerSide; ++i)
    1814             for (u16 j = 0; j < m_LosTilesPerSide; ++j)
    1815             {
    1816                 LosTile pos{i, j};
     1823        for (u16 i = 0; i < m_LossPerSide; ++i)
     1824            for (u16 j = 0; j < m_LossPerSide; ++j)
     1825            {
     1826                Los pos{i, j};
    18171827                for (player_id_t player = 1; player < MAX_LOS_PLAYER_ID + 1; ++player)
    18181828                    if (IsVisibilityDirty(m_DirtyVisibility[pos], player) || m_GlobalPlayerVisibilityUpdate[player-1] == 1 || m_GlobalVisibilityUpdate)
    1819                         for (const entity_id_t& ent : m_LosTiles[pos])
     1829                        for (const entity_id_t& ent : m_Loss[pos])
    18201830                            UpdateVisibility(ent, player);
    18211831
     
    19371947    }
    19381948
    1939     void ExploreAllTiles(player_id_t p)
    1940     {
    1941         for (u16 j = 0; j < m_TerrainVerticesPerSide; ++j)
    1942             for (u16 i = 0; i < m_TerrainVerticesPerSide; ++i)
     1949    void Explore(player_id_t p)
     1950    {
     1951        for (VerticesPerSide; ++j)
     1952            for (VerticesPerSide; ++i)
    19431953            {
    19441954                if (LosIsOffWorld(i,j))
     
    19601970
    19611971        // Territory data is stored per territory-tile (typically a multiple of terrain-tiles).
    1962         // LOS data is stored per terrain-tile vertex.
     1972        // LOS data is stored per los vertex (in reality tiles too, but it's the center that matters).
     1973        // This scales from LOS coordinates to Territory coordinates.
     1974        auto scale = [](i32 coord) -> i32 {
     1975            return (coord * LOS_TILE_SIZE + LOS_TILE_SIZE / 2) / (ICmpTerritoryManager::NAVCELLS_PER_TERRITORY_TILE * Pathfinding::NAVCELL_SIZE_INT);
     1976        };
    19631977
    19641978        // For each territory-tile, if it is owned by a valid player then update the LOS
    19651979        // for every vertex inside/around that tile, to mark them as explored.
    1966 
    1967         // Currently this code doesn't support territory-tiles smaller than terrain-tiles
    1968         // (it will get scale==0 and break), or a non-integer multiple, so check that first
    1969         cassert(ICmpTerritoryManager::NAVCELLS_PER_TERRITORY_TILE >= Pathfinding::NAVCELLS_PER_TILE);
    1970         cassert(ICmpTerritoryManager::NAVCELLS_PER_TERRITORY_TILE % Pathfinding::NAVCELLS_PER_TILE == 0);
    1971 
    1972         int scale = ICmpTerritoryManager::NAVCELLS_PER_TERRITORY_TILE / Pathfinding::NAVCELLS_PER_TILE;
    1973 
    1974         ENSURE(grid.m_W*scale == m_TerrainVerticesPerSide-1 && grid.m_H*scale == m_TerrainVerticesPerSide-1);
    1975 
    1976         for (u16 j = 0; j < grid.m_H; ++j)
    1977             for (u16 i = 0; i < grid.m_W; ++i)
    1978             {
    1979                 u8 p = grid.get(i, j) & ICmpTerritoryManager::TERRITORY_PLAYER_MASK;
     1980        for (i32 j = 0; j < m_LosVerticesPerSide; ++j)
     1981            for (i32 i = 0; i < m_LosVerticesPerSide; ++i)
     1982            {
     1983                // TODO: This fetches data redundantly if the los grid is smaller than the territory grid
     1984                // (but it's unlikely to matter much).
     1985                u8 p = grid.get(scale(i), scale(j)) & ICmpTerritoryManager::TERRITORY_PLAYER_MASK;
    19801986                if (p > 0 && p <= MAX_LOS_PLAYER_ID)
    19811987                {
    19821988                    u32& explored = m_ExploredVertices.at(p);
    1983                     for (int tj = j * scale; tj <= (j+1) * scale; ++tj)
    1984                         for (int ti = i * scale; ti <= (i+1) * scale; ++ti)
    1985                         {
    1986                             if (LosIsOffWorld(ti, tj))
    1987                                 continue;
    1988 
    1989                             u32& losState = m_LosState.get(ti, tj);
    1990                             if (!(losState & ((u32)LosState::EXPLORED << (2*(p-1)))))
    1991                             {
    1992                                 ++explored;
    1993                                 losState |= ((u32)LosState::EXPLORED << (2*(p-1)));
    1994                             }
    1995                         }
     1989
     1990                    if (LosIsOffWorld(i, j))
     1991                        continue;
     1992
     1993                    u32& losState = m_LosState.get(i, j);
     1994                    if (!(losState & ((u32)LosState::EXPLORED << (2*(p-1)))))
     1995                    {
     1996                        ++explored;
     1997                        losState |= ((u32)LosState::EXPLORED << (2*(p-1)));
     1998                    }
    19961999                }
    19972000            }
     
    20222025
    20232026            CFixedVector2D pos = cmpPosition->GetPosition2D();
    2024             int i = (pos.X / (int)TERRAIN_TILE_SIZE).ToInt_RoundToNearest();
    2025             int j = (pos.Y / (int)TERRAIN_TILE_SIZE).ToInt_RoundToNearest();
    2026 
    2027             CLosQuerier los(GetSharedLosMask(p), m_LosState, m_TerrainVerticesPerSide);
     2027            int i = (pos.X / _TILE_SIZE).ToInt_RoundToNearest();
     2028            int j = (pos.Y / _TILE_SIZE).ToInt_RoundToNearest();
     2029
     2030            CLosQuerier los(GetSharedLosMask(p), m_LosState, m_VerticesPerSide);
    20282031            if (!los.IsExplored(i,j) || los.IsVisible(i,j))
    20292032                continue;
     
    20522055        CmpPtr<ICmpPathfinder> cmpPathfinder(GetSystemEntity());
    20532056        const Grid<u16>& shoreGrid = cmpPathfinder->ComputeShoreGrid(true);
    2054         ENSURE(shoreGrid.m_W == m_TerrainVerticesPerSide-1 && shoreGrid.m_H == m_TerrainVerticesPerSide-1);
     2057        ENSURE(shoreGrid.m_W == m_VerticesPerSide-1);
    20552058
    20562059        Grid<u16>& counts = m_LosPlayerCounts.at(p);
     
    20822085            // With a circular map, vertex is off-world if hypot(i - size/2, j - size/2) >= size/2:
    20832086
    2084             ssize_t dist2 = (i - m_TerrainVerticesPerSide/2)*(i - m_TerrainVerticesPerSide/2)
    2085                     + (j - m_TerrainVerticesPerSide/2)*(j - m_TerrainVerticesPerSide/2);
    2086 
    2087             ssize_t r = m_TerrainVerticesPerSide / 2 - MAP_EDGE_TILES + 1;
     2087            ssize_t dist2 = (i - m_VerticesPerSide/2)
     2088                    + (j - m_VerticesPerSide/2);
     2089
     2090            ssize_t r = m_VerticesPerSide / 2 - MAP_EDGE_TILES + 1;
    20882091                // subtract a bit from the radius to ensure nice
    20892092                // SoD blurring around the edges of the map
     
    20962099            // so the SoD texture blends out nicely
    20972100            return i < MAP_EDGE_TILES || j < MAP_EDGE_TILES ||
    2098                 i >= m_TerrainVerticesPerSide - MAP_EDGE_TILES ||
    2099                 j >= m_TerrainVerticesPerSide - MAP_EDGE_TILES;
     2101                i >= m_VerticesPerSide - MAP_EDGE_TILES ||
     2102                j >= m_VerticesPerSide - MAP_EDGE_TILES;
    21002103        }
    21012104    }
     
    21592162            return;
    21602163
    2161         // Mark the LoS tiles around the updated vertex
     2164        // Mark the LoS s around the updated vertex
    21622165        // 1: left-up, 2: right-up, 3: left-down, 4: right-down
    2163         LosTile n1 = PosToLosTilesHelper(i-1, j-1);
    2164         LosTile n2 = PosToLosTilesHelper(i-1, j);
    2165         LosTile n3 = PosToLosTilesHelper(i, j-1);
    2166         LosTile n4 = PosToLosTilesHelper(i, j);
     2166        LossHelper(i-1, j-1);
     2167        LossHelper(i-1, j);
     2168        LossHelper(i, j-1);
     2169        LossHelper(i, j);
    21672170
    21682171        u16 sharedDirtyVisibilityMask = m_SharedDirtyVisibilityMasks[owner];
     
    21702173        if (j > 0 && i > 0)
    21712174            m_DirtyVisibility[n1] |= sharedDirtyVisibilityMask;
    2172         if (n2 != n1 && j > 0 && i < m_TerrainVerticesPerSide)
     2175        if (n2 != n1 && j > 0 && i < m_VerticesPerSide)
    21732176            m_DirtyVisibility[n2] |= sharedDirtyVisibilityMask;
    2174         if (n3 != n1 && j < m_TerrainVerticesPerSide && i > 0)
     2177        if (n3 != n1 && j < m_VerticesPerSide && i > 0)
    21752178            m_DirtyVisibility[n3] |= sharedDirtyVisibilityMask;
    2176         if (n4 != n1 && j < m_TerrainVerticesPerSide && i < m_TerrainVerticesPerSide)
     2179        if (n4 != n1 && j < m_VerticesPerSide)
    21772180            m_DirtyVisibility[n4] |= sharedDirtyVisibilityMask;
    21782181    }
     
    21862189    void LosUpdateHelper(u8 owner, entity_pos_t visionRange, CFixedVector2D pos)
    21872190    {
    2188         if (m_TerrainVerticesPerSide == 0) // do nothing if not initialised yet
     2191        if (m_VerticesPerSide == 0) // do nothing if not initialised yet
    21892192            return;
    21902193
     
    21952198        // Lazy initialisation of counts:
    21962199        if (counts.blank())
    2197             counts.resize(m_TerrainVerticesPerSide, m_TerrainVerticesPerSide);
     2200            counts.resize(m_VerticesPerSide);
    21982201
    21992202        // Compute the circular region as a series of strips.
     
    22082211        // Compute top/bottom coordinates, and clamp to exclude the 1-tile border around the map
    22092212        // (so that we never render the sharp edge of the map)
    2210         i32 j0 = ((pos.Y - visionRange)/(int)TERRAIN_TILE_SIZE).ToInt_RoundToInfinity();
    2211         i32 j1 = ((pos.Y + visionRange)/(int)TERRAIN_TILE_SIZE).ToInt_RoundToNegInfinity();
     2213        i32 j0 = ((pos.Y - visionRange)/_TILE_SIZE).ToInt_RoundToInfinity();
     2214        i32 j1 = ((pos.Y + visionRange)/_TILE_SIZE).ToInt_RoundToNegInfinity();
    22122215        i32 j0clamp = std::max(j0, 1);
    2213         i32 j1clamp = std::min(j1, m_TerrainVerticesPerSide-2);
     2216        i32 j1clamp = std::min(j1, m_VerticesPerSide-2);
    22142217
    22152218        // Translate world coordinates into fractional tile-space coordinates
    2216         entity_pos_t x = pos.X / (int)TERRAIN_TILE_SIZE;
    2217         entity_pos_t y = pos.Y / (int)TERRAIN_TILE_SIZE;
    2218         entity_pos_t r = visionRange / (int)TERRAIN_TILE_SIZE;
     2219        entity_pos_t x = pos.X / _TILE_SIZE;
     2220        entity_pos_t y = pos.Y / _TILE_SIZE;
     2221        entity_pos_t r = visionRange / _TILE_SIZE;
    22192222        entity_pos_t r2 = r.Square();
    22202223
     
    22582261            // then add or remove the strip as requested
    22592262            i32 i0clamp = std::max(i0, 1);
    2260             i32 i1clamp = std::min(i1, m_TerrainVerticesPerSide-2);
     2263            i32 i1clamp = std::min(i1, m_VerticesPerSide-2);
    22612264            if (adding)
    22622265                LosAddStripHelper(owner, i0clamp, i1clamp, j, counts);
     
    22732276    void LosUpdateHelperIncremental(u8 owner, entity_pos_t visionRange, CFixedVector2D from, CFixedVector2D to)
    22742277    {
    2275         if (m_TerrainVerticesPerSide == 0) // do nothing if not initialised yet
     2278        if (m_VerticesPerSide == 0) // do nothing if not initialised yet
    22762279            return;
    22772280
     
    22822285        // Lazy initialisation of counts:
    22832286        if (counts.blank())
    2284             counts.resize(m_TerrainVerticesPerSide, m_TerrainVerticesPerSide);
     2287            counts.resize(m_VerticesPerSide);
    22852288
    22862289        // See comments in LosUpdateHelper.
     
    22912294        // and only have to touch tiles that have a net change.)
    22922295
    2293         i32 j0_from = ((from.Y - visionRange)/(int)TERRAIN_TILE_SIZE).ToInt_RoundToInfinity();
    2294         i32 j1_from = ((from.Y + visionRange)/(int)TERRAIN_TILE_SIZE).ToInt_RoundToNegInfinity();
    2295         i32 j0_to = ((to.Y - visionRange)/(int)TERRAIN_TILE_SIZE).ToInt_RoundToInfinity();
    2296         i32 j1_to = ((to.Y + visionRange)/(int)TERRAIN_TILE_SIZE).ToInt_RoundToNegInfinity();
     2296        i32 j0_from = ((from.Y - visionRange)/_TILE_SIZE).ToInt_RoundToInfinity();
     2297        i32 j1_from = ((from.Y + visionRange)/_TILE_SIZE).ToInt_RoundToNegInfinity();
     2298        i32 j0_to = ((to.Y - visionRange)/_TILE_SIZE).ToInt_RoundToInfinity();
     2299        i32 j1_to = ((to.Y + visionRange)/_TILE_SIZE).ToInt_RoundToNegInfinity();
    22972300        i32 j0clamp = std::max(std::min(j0_from, j0_to), 1);
    2298         i32 j1clamp = std::min(std::max(j1_from, j1_to), m_TerrainVerticesPerSide-2);
    2299 
    2300         entity_pos_t x_from = from.X / (int)TERRAIN_TILE_SIZE;
    2301         entity_pos_t y_from = from.Y / (int)TERRAIN_TILE_SIZE;
    2302         entity_pos_t x_to = to.X / (int)TERRAIN_TILE_SIZE;
    2303         entity_pos_t y_to = to.Y / (int)TERRAIN_TILE_SIZE;
    2304         entity_pos_t r = visionRange / (int)TERRAIN_TILE_SIZE;
     2301        i32 j1clamp = std::min(std::max(j1_from, j1_to), m_VerticesPerSide-2);
     2302
     2303        entity_pos_t x_from = from.X / _TILE_SIZE;
     2304        entity_pos_t y_from = from.Y / _TILE_SIZE;
     2305        entity_pos_t x_to = to.X / _TILE_SIZE;
     2306        entity_pos_t y_to = to.Y / _TILE_SIZE;
     2307        entity_pos_t r = visionRange / _TILE_SIZE;
    23052308        entity_pos_t r2 = r.Square();
    23062309
     
    23602363            {
    23612364                i32 i0clamp_from = std::max(i0_from, 1);
    2362                 i32 i1clamp_from = std::min(i1_from, m_TerrainVerticesPerSide-2);
     2365                i32 i1clamp_from = std::min(i1_from, m_VerticesPerSide-2);
    23632366                i32 i0clamp_to = std::max(i0_to, 1);
    2364                 i32 i1clamp_to = std::min(i1_to, m_TerrainVerticesPerSide-2);
     2367                i32 i1clamp_to = std::min(i1_to, m_VerticesPerSide-2);
    23652368
    23662369                // Check whether one strip is negative width,
     
    24662469        std::vector<player_id_t>::const_iterator playerIt;
    24672470
    2468         for (i32 j = 0; j < m_TerrainVerticesPerSide; j++)
    2469             for (i32 i = 0; i < m_TerrainVerticesPerSide; i++)
     2471        for (i32 j = 0; j < m_VerticesPerSide; j++)
     2472            for (i32 i = 0; i < m_VerticesPerSide; i++)
    24702473            {
    24712474                if (LosIsOffWorld(i, j))
     
    24852488
    24862489REGISTER_COMPONENT_TYPE(RangeManager)
    2487 
    2488 #undef LOS_TILES_RATIO
    2489 #undef DEBUG_RANGE_MANAGER_BOUNDS
  • ps/trunk/source/simulation2/components/CCmpTerrain.cpp

    r19862 r24980  
    140140            cmpRangeManager->SetBounds(entity_pos_t::Zero(), entity_pos_t::Zero(),
    141141                    entity_pos_t::FromInt(tiles*(int)TERRAIN_TILE_SIZE),
    142                     entity_pos_t::FromInt(tiles*(int)TERRAIN_TILE_SIZE),
    143                     vertices);
     142                    entity_pos_t::FromInt(tiles*(int)TERRAIN_TILE_SIZE));
    144143        }
    145144
  • ps/trunk/source/simulation2/components/ICmpRangeManager.cpp

    r24776 r24980  
    6161DEFINE_INTERFACE_METHOD_CONST_0("GetGaiaAndNonGaiaEntities", std::vector<entity_id_t>, ICmpRangeManager, GetGaiaAndNonGaiaEntities)
    6262DEFINE_INTERFACE_METHOD_1("SetDebugOverlay", void, ICmpRangeManager, SetDebugOverlay, bool)
    63 DEFINE_INTERFACE_METHOD_1("ExploreAllTiles", void, ICmpRangeManager, ExploreAllTiles, player_id_t)
     63DEFINE_INTERFACE_METHOD_1("Explore, player_id_t)
    6464DEFINE_INTERFACE_METHOD_0("ExploreTerritories", void, ICmpRangeManager, ExploreTerritories)
    6565DEFINE_INTERFACE_METHOD_2("SetLosRevealAll", void, ICmpRangeManager, SetLosRevealAll, player_id_t, bool)
  • ps/trunk/source/simulation2/components/ICmpRangeManager.h

    r24776 r24980  
    107107     * Entities should not be outside the bounds (else efficiency will suffer).
    108108     * @param x0,z0,x1,z1 Coordinates of the corners of the world
    109      * @param vertices Number of terrain vertices per side
    110      */
    111     virtual void SetBounds(entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, ssize_t vertices) = 0;
     109     */
     110    virtual void SetBounds(entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1) = 0;
    112111
    113112    /**
     
    298297
    299298    /**
    300      * Explore all tiles (but leave them in the FoW) for player p
    301      */
    302     virtual void ExploreAllTiles(player_id_t p) = 0;
     299     * Explore in the FoW) for player p
     300     */
     301    virtual void Explore(player_id_t p) = 0;
    303302
    304303    /**
     
    358357    virtual u8 GetUnionPercentMapExplored(const std::vector<player_id_t>& players) const = 0;
    359358
     359
     360
     361
     362
    360363
    361364    /**
  • ps/trunk/source/simulation2/components/tests/test_RangeManager.h

    r24776 r24980  
    144144        // in various edge cases
    145145
    146         cmp->SetBounds(entity_pos_t::FromInt(0), entity_pos_t::FromInt(0), entity_pos_t::FromInt(512), entity_pos_t::FromInt(512), 512/TERRAIN_TILE_SIZE + 1);
     146        cmp->SetBounds(entity_pos_t::FromInt(0), entity_pos_t::FromInt(0), entity_pos_t::FromInt(512), entity_pos_t::FromInt(512));
    147147        cmp->Verify();
    148148        { CMessageCreate msg(100); cmp->HandleMessage(msg, false); }
     
    215215        test.AddMock(101, IID_Obstruction, obs2);
    216216
    217         cmp->SetBounds(entity_pos_t::FromInt(0), entity_pos_t::FromInt(0), entity_pos_t::FromInt(512), entity_pos_t::FromInt(512), 512/TERRAIN_TILE_SIZE + 1);
     217        cmp->SetBounds(entity_pos_t::FromInt(0), entity_pos_t::FromInt(0), entity_pos_t::FromInt(512), entity_pos_t::FromInt(512));
    218218        cmp->Verify();
    219219        { CMessageCreate msg(100); cmp->HandleMessage(msg, false); }
  • ps/trunk/source/simulation2/helpers/Los.h

    r23827 r24980  
    2222// since files must include "Los.h" explicitly, and that's only done in .cpp files.
    2323#include "Grid.h"
     24
     25
     26
     27
     28
     29
     30
    2431
    2532enum class LosState : u8
Note: See TracChangeset for help on using the changeset viewer.