Changeset 24980
- Timestamp:
- Mar 2, 2021, 5:44:40 PM (3 years ago)
- Location:
- ps/trunk
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
ps/trunk/binaries/data/mods/public/simulation/helpers/InitGame.js
r24142 r24980 39 39 let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); 40 40 for (let i = 1; i < settings.PlayerData.length; ++i) 41 cmpRangeManager.Explore AllTiles(i);41 cmpRangeManager.Explore(i); 42 42 } 43 43 -
ps/trunk/source/graphics/LOSTexture.cpp
r23774 r24980 21 21 22 22 #include "graphics/ShaderManager.h" 23 #include "graphics/Terrain.h"24 23 #include "lib/bits.h" 25 24 #include "lib/config2.h" … … 32 31 #include "simulation2/Simulation2.h" 33 32 #include "simulation2/components/ICmpRangeManager.h" 34 #include "simulation2/components/ICmpTerrain.h"35 33 #include "simulation2/helpers/Los.h" 36 34 37 35 /* 38 36 39 The LOS bitmap is computed with one value per mapvertex, based on37 The LOS bitmap is computed with one value per vertex, based on 40 38 CCmpRangeManager's visibility information. 41 39 … … 244 242 void CLOSTexture::ConstructTexture(int unit) 245 243 { 246 CmpPtr<ICmp Terrain> cmpTerrain(m_Simulation, SYSTEM_ENTITY);247 if (!cmp Terrain)244 CmpPtr<ICmp(m_Simulation, SYSTEM_ENTITY); 245 if (!cmp) 248 246 return; 249 247 250 m_MapSize = cmp Terrain->GetVerticesPerSide();248 m_MapSize = cmp->GetVerticesPerSide(); 251 249 252 250 m_TextureSize = (GLsizei)round_up_to_pow2(round_up((size_t)m_MapSize + g_BlurSize - 1, g_SubTextureAlignment)); … … 295 293 // onto texcoord ((mapsize-0.5) / texsize, (mapsize-0.5) / texsize) (i.e. middle of last texel) 296 294 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); 298 296 float t = 0.5f / m_TextureSize; 299 297 m_TextureMatrix.SetZero(); … … 321 319 if (m_Texture) 322 320 { 323 CmpPtr<ICmp Terrain> cmpTerrain(m_Simulation, SYSTEM_ENTITY);324 if ( cmpTerrain && m_MapSize != (ssize_t)cmpTerrain->GetVerticesPerSide())321 CmpPtr<ICmp(m_Simulation, SYSTEM_ENTITY); 322 if (->GetVerticesPerSide()) 325 323 DeleteTexture(); 326 324 } -
ps/trunk/source/graphics/LOSTexture.h
r24227 r24980 100 100 CShaderTechniquePtr m_smoothShader; 101 101 102 s size_t m_MapSize; // vertexes per side102 size_t m_MapSize; // vertexes per side 103 103 GLsizei m_TextureSize; // texels per side 104 104 -
ps/trunk/source/simulation2/components/CCmpProjectileManager.cpp
r23774 r24980 363 363 { 364 364 // 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); 367 367 if (!losRevealAll && !los.IsVisible(posi, posj)) 368 368 return; -
ps/trunk/source/simulation2/components/CCmpRallyPointRenderer.cpp
r24144 r24980 817 817 // a new one at the next point. 818 818 819 const float terrainSize = static_cast<float>(TERRAIN_TILE_SIZE);819 const float _TILE_SIZE); 820 820 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() 823 823 ); 824 824 // Starting node index of the current segment … … 828 828 { 829 829 // 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(); 832 832 833 833 bool nodeVisible = losQuerier.IsExplored(i, j); -
ps/trunk/source/simulation2/components/CCmpRangeManager.cpp
r24776 r24980 46 46 #include "renderer/Scene.h" 47 47 48 #define LOS_TILES_RATIO 849 48 #define DEBUG_RANGE_MANAGER_BOUNDS 0 50 49 50 51 51 52 52 /** … … 114 114 115 115 /** 116 * Test whether the visibility is dirty for a given LoS tileand a given player116 * Test whether the visibility is dirty for a given LoS and a given player 117 117 */ 118 118 static inline bool IsVisibilityDirty(u16 dirty, player_id_t player) … … 382 382 static const player_id_t MAX_LOS_PLAYER_ID = 16; 383 383 384 using Los Tile= std::pair<u16, u16>;384 using Los = std::pair<u16, u16>; 385 385 386 386 std::array<bool, MAX_LOS_PLAYER_ID+2> m_LosRevealAll; 387 387 bool m_LosCircular; 388 i32 m_ TerrainVerticesPerSide;388 i32 m_VerticesPerSide; 389 389 390 390 // Cache for visibility tracking 391 i32 m_Los TilesPerSide;391 i32 m_LossPerSide; 392 392 bool m_GlobalVisibilityUpdate; 393 393 std::array<bool, MAX_LOS_PLAYER_ID> m_GlobalPlayerVisibilityUpdate; 394 394 Grid<u16> m_DirtyVisibility; 395 Grid<std::set<entity_id_t>> m_Los Tiles;395 Grid<std::set<entity_id_t>> m_Loss; 396 396 // List of entities that must be updated, regardless of the status of their tile 397 397 std::vector<entity_id_t> m_ModifiedEntities; … … 448 448 449 449 m_LosCircular = false; 450 m_ TerrainVerticesPerSide = 0;450 m_VerticesPerSide = 0; 451 451 } 452 452 … … 469 469 Serializer(serialize, "los reveal all", m_LosRevealAll); 470 470 serialize.Bool("los circular", m_LosCircular); 471 serialize.NumberI32_Unbounded(" terrain verts per side", m_TerrainVerticesPerSide);471 serialize.NumberI32_Unbounded("VerticesPerSide); 472 472 473 473 serialize.Bool("global visibility update", m_GlobalVisibilityUpdate); … … 476 476 Serializer(serialize, "modified entities", m_ModifiedEntities); 477 477 478 // We don't serialize m_Subdivision, m_LosPlayerCounts or m_Los Tiles478 // We don't serialize m_Subdivision, m_LosPlayerCounts or m_Loss 479 479 // since they can be recomputed from the entity data when deserializing; 480 480 // m_LosState must be serialized since it depends on the history of exploration … … 571 571 else 572 572 LosMove(it->second.owner, it->second.visionRange, from, to); 573 Los Tile oldLosTile = PosToLosTilesHelper(it->second.x, it->second.z);574 Los Tile newLosTile = PosToLosTilesHelper(msgData.x, msgData.z);575 if (oldLos Tile != newLosTile)573 LossHelper(it->second.x, it->second.z); 574 LossHelper(msgData.x, msgData.z); 575 if (oldLos) 576 576 { 577 RemoveFrom Tile(oldLosTile, ent);578 �� AddTo Tile(newLosTile, ent);577 RemoveFrom, ent); 578 AddTo, ent); 579 579 } 580 580 } … … 587 587 else 588 588 LosAdd(it->second.owner, it->second.visionRange, to); 589 AddTo Tile(PosToLosTilesHelper(msgData.x, msgData.z), ent);589 AddTosHelper(msgData.x, msgData.z), ent); 590 590 } 591 591 … … 604 604 else 605 605 LosRemove(it->second.owner, it->second.visionRange, from); 606 RemoveFrom Tile(PosToLosTilesHelper(it->second.x, it->second.z), ent);606 RemoveFromsHelper(it->second.x, it->second.z), ent); 607 607 } 608 608 … … 664 664 { 665 665 m_Subdivision.Remove(ent, CFixedVector2D(it->second.x, it->second.z), it->second.size); 666 RemoveFrom Tile(PosToLosTilesHelper(it->second.x, it->second.z), ent);666 RemoveFromsHelper(it->second.x, it->second.z), ent); 667 667 } 668 668 … … 770 770 } 771 771 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); 774 776 m_WorldX0 = x0; 775 777 m_WorldZ0 = z0; 776 778 m_WorldX1 = x1; 777 779 m_WorldZ1 = z1; 778 m_ TerrainVerticesPerSide = (i32)vertices;780 m_; 779 781 780 782 ResetDerivedData(); … … 793 795 Grid<u32> oldStateRevealed = m_LosStateRevealed; 794 796 FastSpatialSubdivision oldSubdivision = m_Subdivision; 795 Grid<std::set<entity_id_t> > oldLos Tiles = m_LosTiles;797 Grid<std::set<entity_id_t> > oldLoss; 796 798 797 799 m_Deserializing = true; … … 827 829 if (oldSubdivision != m_Subdivision) 828 830 debug_warn(L"inconsistent subdivs"); 829 if (oldLos Tiles != m_LosTiles)830 debug_warn(L"inconsistent los tiles");831 if (oldLoss) 832 debug_warn(L"inconsistent los s"); 831 833 } 832 834 … … 842 844 ResetSubdivisions(m_WorldX1, m_WorldZ1); 843 845 844 m_Los TilesPerSide = (m_TerrainVerticesPerSide - 1)/LOS_TILES_RATIO;846 m_Los_RATIO; 845 847 846 848 for (size_t player_id = 0; player_id < m_LosPlayerCounts.size(); ++player_id) … … 853 855 { 854 856 // 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++) 857 859 if (!LosIsOffWorld(i, j)) 858 860 for (u8 k = 1; k < MAX_LOS_PLAYER_ID+1; ++k) 859 861 m_ExploredVertices.at(k) += ((m_LosState.get(i, j) & ((u32)LosState::EXPLORED << (2*(k-1)))) > 0); 860 862 } 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); 864 866 865 867 if (!m_Deserializing) 866 868 { 867 m_DirtyVisibility.resize(m_Los TilesPerSide, m_LosTilesPerSide);868 } 869 ENSURE(m_DirtyVisibility.width() == m_Los TilesPerSide);870 ENSURE(m_DirtyVisibility.height() == m_Los TilesPerSide);871 872 m_Los Tiles.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); 873 875 874 876 for (EntityMap<EntityData>::const_iterator it = m_EntityData.begin(); it != m_EntityData.end(); ++it) … … 879 881 else 880 882 LosAdd(it->second.owner, it->second.visionRange, CFixedVector2D(it->second.x, it->second.z)); 881 AddTo Tile(PosToLosTilesHelper(it->second.x, it->second.z), it->first);883 AddTosHelper(it->second.x, it->second.z), it->first); 882 884 883 885 if (it->second.HasFlag<FlagMasks::RevealShore>()) … … 886 888 887 889 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) 890 892 { 891 893 if (LosIsOffWorld(i,j)) … … 1601 1603 { 1602 1604 if (GetLosRevealAll(player)) 1603 return CLosQuerier(0xFFFFFFFFu, m_LosStateRevealed, m_ TerrainVerticesPerSide);1605 return CLosQuerier(0xFFFFFFFFu, m_LosStateRevealed, m_VerticesPerSide); 1604 1606 else 1605 return CLosQuerier(GetSharedLosMask(player), m_LosState, m_ TerrainVerticesPerSide);1607 return CLosQuerier(GetSharedLosMask(player), m_LosState, m_VerticesPerSide); 1606 1608 } 1607 1609 … … 1628 1630 1629 1631 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(); 1632 1634 1633 1635 // Reveal flag makes all positioned entities visible and all mirages useless … … 1640 1642 1641 1643 // Get visible regions 1642 CLosQuerier los(GetSharedLosMask(player), m_LosState, m_ TerrainVerticesPerSide);1644 CLosQuerier los(GetSharedLosMask(player), m_LosState, m_VerticesPerSide); 1643 1645 1644 1646 CmpPtr<ICmpVisibility> cmpVisibility(ent); … … 1734 1736 CFixedVector2D pos = cmpPosition->GetPosition2D(); 1735 1737 1736 if (IsVisibilityDirty(m_DirtyVisibility[PosToLos TilesHelper(pos.X, pos.Y)], player))1738 if (IsVisibilityDirty(m_DirtyVisibility[PosToLossHelper(pos.X, pos.Y)], player)) 1737 1739 return ComputeLosVisibility(ent, player); 1738 1740 … … 1755 1757 virtual LosVisibility GetLosVisibilityPosition(entity_pos_t x, entity_pos_t z, player_id_t player) const 1756 1758 { 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(); 1759 1761 1760 1762 // Reveal flag makes all positioned entities visible and all mirages useless … … 1768 1770 1769 1771 // Get visible regions 1770 CLosQuerier los(GetSharedLosMask(player), m_LosState, m_ TerrainVerticesPerSide);1772 CLosQuerier los(GetSharedLosMask(player), m_LosState, m_VerticesPerSide); 1771 1773 1772 1774 if (los.IsVisible(i,j)) … … 1777 1779 } 1778 1780 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(), 1788 1798 0, 1789 m_Los TilesPerSide - 1);1790 i32j = 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(), 1792 1802 0, 1793 m_Los TilesPerSide - 1);1803 m_LossPerSide - 1); 1794 1804 return std::make_pair(i, j); 1795 1805 } 1796 1806 1797 void AddTo Tile(LosTile tile, entity_id_t ent)1798 { 1799 m_Los Tiles[tile].insert(ent);1800 } 1801 1802 void RemoveFrom Tile(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_Los Tiles[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); 1807 1817 } 1808 1818 … … 1811 1821 PROFILE("UpdateVisibilityData"); 1812 1822 1813 for (u16 i = 0; i < m_Los TilesPerSide; ++i)1814 for (u16 j = 0; j < m_Los TilesPerSide; ++j)1815 { 1816 Los Tilepos{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}; 1817 1827 for (player_id_t player = 1; player < MAX_LOS_PLAYER_ID + 1; ++player) 1818 1828 if (IsVisibilityDirty(m_DirtyVisibility[pos], player) || m_GlobalPlayerVisibilityUpdate[player-1] == 1 || m_GlobalVisibilityUpdate) 1819 for (const entity_id_t& ent : m_Los Tiles[pos])1829 for (const entity_id_t& ent : m_Loss[pos]) 1820 1830 UpdateVisibility(ent, player); 1821 1831 … … 1937 1947 } 1938 1948 1939 void Explore AllTiles(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) 1943 1953 { 1944 1954 if (LosIsOffWorld(i,j)) … … 1960 1970 1961 1971 // 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 }; 1963 1977 1964 1978 // For each territory-tile, if it is owned by a valid player then update the LOS 1965 1979 // 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; 1980 1986 if (p > 0 && p <= MAX_LOS_PLAYER_ID) 1981 1987 { 1982 1988 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 } 1996 1999 } 1997 2000 } … … 2022 2025 2023 2026 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); 2028 2031 if (!los.IsExplored(i,j) || los.IsVisible(i,j)) 2029 2032 continue; … … 2052 2055 CmpPtr<ICmpPathfinder> cmpPathfinder(GetSystemEntity()); 2053 2056 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); 2055 2058 2056 2059 Grid<u16>& counts = m_LosPlayerCounts.at(p); … … 2082 2085 // With a circular map, vertex is off-world if hypot(i - size/2, j - size/2) >= size/2: 2083 2086 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; 2088 2091 // subtract a bit from the radius to ensure nice 2089 2092 // SoD blurring around the edges of the map … … 2096 2099 // so the SoD texture blends out nicely 2097 2100 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; 2100 2103 } 2101 2104 } … … 2159 2162 return; 2160 2163 2161 // Mark the LoS tiles around the updated vertex2164 // Mark the LoS s around the updated vertex 2162 2165 // 1: left-up, 2: right-up, 3: left-down, 4: right-down 2163 Los Tile n1 = PosToLosTilesHelper(i-1, j-1);2164 Los Tile n2 = PosToLosTilesHelper(i-1, j);2165 Los Tile n3 = PosToLosTilesHelper(i, j-1);2166 Los Tile n4 = PosToLosTilesHelper(i, j);2166 LossHelper(i-1, j-1); 2167 LossHelper(i-1, j); 2168 LossHelper(i, j-1); 2169 LossHelper(i, j); 2167 2170 2168 2171 u16 sharedDirtyVisibilityMask = m_SharedDirtyVisibilityMasks[owner]; … … 2170 2173 if (j > 0 && i > 0) 2171 2174 m_DirtyVisibility[n1] |= sharedDirtyVisibilityMask; 2172 if (n2 != n1 && j > 0 && i < m_ TerrainVerticesPerSide)2175 if (n2 != n1 && j > 0 && i < m_VerticesPerSide) 2173 2176 m_DirtyVisibility[n2] |= sharedDirtyVisibilityMask; 2174 if (n3 != n1 && j < m_ TerrainVerticesPerSide && i > 0)2177 if (n3 != n1 && j < m_VerticesPerSide && i > 0) 2175 2178 m_DirtyVisibility[n3] |= sharedDirtyVisibilityMask; 2176 if (n4 != n1 && j < m_ TerrainVerticesPerSide && i < m_TerrainVerticesPerSide)2179 if (n4 != n1 && j < m_VerticesPerSide) 2177 2180 m_DirtyVisibility[n4] |= sharedDirtyVisibilityMask; 2178 2181 } … … 2186 2189 void LosUpdateHelper(u8 owner, entity_pos_t visionRange, CFixedVector2D pos) 2187 2190 { 2188 if (m_ TerrainVerticesPerSide == 0) // do nothing if not initialised yet2191 if (m_VerticesPerSide == 0) // do nothing if not initialised yet 2189 2192 return; 2190 2193 … … 2195 2198 // Lazy initialisation of counts: 2196 2199 if (counts.blank()) 2197 counts.resize(m_ TerrainVerticesPerSide, m_TerrainVerticesPerSide);2200 counts.resize(m_VerticesPerSide); 2198 2201 2199 2202 // Compute the circular region as a series of strips. … … 2208 2211 // Compute top/bottom coordinates, and clamp to exclude the 1-tile border around the map 2209 2212 // (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(); 2212 2215 i32 j0clamp = std::max(j0, 1); 2213 i32 j1clamp = std::min(j1, m_ TerrainVerticesPerSide-2);2216 i32 j1clamp = std::min(j1, m_VerticesPerSide-2); 2214 2217 2215 2218 // 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; 2219 2222 entity_pos_t r2 = r.Square(); 2220 2223 … … 2258 2261 // then add or remove the strip as requested 2259 2262 i32 i0clamp = std::max(i0, 1); 2260 i32 i1clamp = std::min(i1, m_ TerrainVerticesPerSide-2);2263 i32 i1clamp = std::min(i1, m_VerticesPerSide-2); 2261 2264 if (adding) 2262 2265 LosAddStripHelper(owner, i0clamp, i1clamp, j, counts); … … 2273 2276 void LosUpdateHelperIncremental(u8 owner, entity_pos_t visionRange, CFixedVector2D from, CFixedVector2D to) 2274 2277 { 2275 if (m_ TerrainVerticesPerSide == 0) // do nothing if not initialised yet2278 if (m_VerticesPerSide == 0) // do nothing if not initialised yet 2276 2279 return; 2277 2280 … … 2282 2285 // Lazy initialisation of counts: 2283 2286 if (counts.blank()) 2284 counts.resize(m_ TerrainVerticesPerSide, m_TerrainVerticesPerSide);2287 counts.resize(m_VerticesPerSide); 2285 2288 2286 2289 // See comments in LosUpdateHelper. … … 2291 2294 // and only have to touch tiles that have a net change.) 2292 2295 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(); 2297 2300 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; 2305 2308 entity_pos_t r2 = r.Square(); 2306 2309 … … 2360 2363 { 2361 2364 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); 2363 2366 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); 2365 2368 2366 2369 // Check whether one strip is negative width, … … 2466 2469 std::vector<player_id_t>::const_iterator playerIt; 2467 2470 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++) 2470 2473 { 2471 2474 if (LosIsOffWorld(i, j)) … … 2485 2488 2486 2489 REGISTER_COMPONENT_TYPE(RangeManager) 2487 2488 #undef LOS_TILES_RATIO2489 #undef DEBUG_RANGE_MANAGER_BOUNDS -
ps/trunk/source/simulation2/components/CCmpTerrain.cpp
r19862 r24980 140 140 cmpRangeManager->SetBounds(entity_pos_t::Zero(), entity_pos_t::Zero(), 141 141 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)); 144 143 } 145 144 -
ps/trunk/source/simulation2/components/ICmpRangeManager.cpp
r24776 r24980 61 61 DEFINE_INTERFACE_METHOD_CONST_0("GetGaiaAndNonGaiaEntities", std::vector<entity_id_t>, ICmpRangeManager, GetGaiaAndNonGaiaEntities) 62 62 DEFINE_INTERFACE_METHOD_1("SetDebugOverlay", void, ICmpRangeManager, SetDebugOverlay, bool) 63 DEFINE_INTERFACE_METHOD_1("Explore AllTiles", void, ICmpRangeManager, ExploreAllTiles, player_id_t)63 DEFINE_INTERFACE_METHOD_1("Explore, player_id_t) 64 64 DEFINE_INTERFACE_METHOD_0("ExploreTerritories", void, ICmpRangeManager, ExploreTerritories) 65 65 DEFINE_INTERFACE_METHOD_2("SetLosRevealAll", void, ICmpRangeManager, SetLosRevealAll, player_id_t, bool) -
ps/trunk/source/simulation2/components/ICmpRangeManager.h
r24776 r24980 107 107 * Entities should not be outside the bounds (else efficiency will suffer). 108 108 * @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; 112 111 113 112 /** … … 298 297 299 298 /** 300 * Explore all tiles (but leave themin the FoW) for player p301 */ 302 virtual void Explore AllTiles(player_id_t p) = 0;299 * Explore in the FoW) for player p 300 */ 301 virtual void Explore(player_id_t p) = 0; 303 302 304 303 /** … … 358 357 virtual u8 GetUnionPercentMapExplored(const std::vector<player_id_t>& players) const = 0; 359 358 359 360 361 362 360 363 361 364 /** -
ps/trunk/source/simulation2/components/tests/test_RangeManager.h
r24776 r24980 144 144 // in various edge cases 145 145 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)); 147 147 cmp->Verify(); 148 148 { CMessageCreate msg(100); cmp->HandleMessage(msg, false); } … … 215 215 test.AddMock(101, IID_Obstruction, obs2); 216 216 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)); 218 218 cmp->Verify(); 219 219 { CMessageCreate msg(100); cmp->HandleMessage(msg, false); } -
ps/trunk/source/simulation2/helpers/Los.h
r23827 r24980 22 22 // since files must include "Los.h" explicitly, and that's only done in .cpp files. 23 23 #include "Grid.h" 24 25 26 27 28 29 30 24 31 25 32 enum class LosState : u8
Note:
See TracChangeset
for help on using the changeset viewer.