This Trac instance is not used for development anymore!

We migrated our development workflow to git and Gitea.
To test the future redirection, replace trac by ariadne in the page URL.

Changeset 9951 for ps


Ignore:
Timestamp:
08/01/11 23:25:12 (13 years ago)
Author:
philip
Message:

# Remove SoD inside territories.
Fix some serialisation issues.

Location:
ps/trunk/source/simulation2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/source/simulation2/MessageTypes.h

    r9019 r9951  
    279279    DEFAULT_MESSAGE_IMPL(TerrainChanged)
    280280
    281     CMessageTerrainChanged(ssize_t i0, ssize_t j0, ssize_t i1, ssize_t j1) :
     281    CMessageTerrainChanged(int32_t i0, int32_t j0, int32_t i1, int32_t j1) :
    282282        i0(i0), j0(j0), i1(i1), j1(j1)
    283283    {
    284284    }
    285285
    286     ssize_t i0, j0, i1, j1; // inclusive lower bound, exclusive upper bound, in tiles
     286    int32_t i0, j0, i1, j1; // inclusive lower bound, exclusive upper bound, in tiles
    287287};
    288288
  • ps/trunk/source/simulation2/components/CCmpRangeManager.cpp

    r9720 r9951  
    2121#include "ICmpRangeManager.h"
    2222
    23 #include "ICmpPosition.h"
    24 #include "ICmpVision.h"
    2523#include "simulation2/MessageTypes.h"
     24#include "simulation2/components/ICmpPosition.h"
     25#include "simulation2/components/ICmpTerritoryManager.h"
     26#include "simulation2/components/ICmpVision.h"
    2627#include "simulation2/helpers/Render.h"
    2728#include "simulation2/helpers/Spatial.h"
     
    189190    bool m_LosCircular;
    190191    i32 m_TerrainVerticesPerSide;
     192    size_t m_TerritoriesDirtyID;
    191193
    192194    // Counts of units seeing vertex, per vertex, per player (starting with player 0).
     
    229231        m_LosCircular = false;
    230232        m_TerrainVerticesPerSide = 0;
     233
     234        m_TerritoriesDirtyID = 0;
    231235    }
    232236
     
    251255        serialize.NumberI32_Unbounded("terrain verts per side", m_TerrainVerticesPerSide);
    252256
    253         // We don't serialize m_Subdivision, m_LosPlayerCounts, m_LosState
    254         // since they can be recomputed from the entity data when deserializing
     257        // We don't serialize m_Subdivision or m_LosPlayerCounts
     258        // since they can be recomputed from the entity data when deserializing;
     259        // m_LosState must be serialized since it depends on the history of exploration
     260
     261        SerializeVector<SerializeU32_Unbounded>()(serialize, "los state", m_LosState);
    255262    }
    256263
     
    267274
    268275        // Reinitialise subdivisions and LOS data
    269         ResetDerivedData();
     276        ResetDerivedData(true);
    270277    }
    271278
     
    396403        {
    397404            m_DebugOverlayDirty = true;
     405            UpdateTerritoriesLos();
    398406            ExecuteActiveQueries();
    399407            break;
     
    416424        m_TerrainVerticesPerSide = vertices;
    417425
    418         ResetDerivedData();
     426        ResetDerivedData(false);
    419427    }
    420428
    421429    // Reinitialise subdivisions and LOS data, based on entity data
    422     void ResetDerivedData()
     430    void ResetDerivedData(bool skipLosState)
    423431    {
    424432        ENSURE(m_WorldX0.IsZero() && m_WorldZ0.IsZero()); // don't bother implementing non-zero offsets yet
     
    427435        m_LosPlayerCounts.clear();
    428436        m_LosPlayerCounts.resize(MAX_LOS_PLAYER_ID+1);
    429         m_LosState.clear();
    430         m_LosState.resize(m_TerrainVerticesPerSide*m_TerrainVerticesPerSide);
     437        if (!skipLosState)
     438        {
     439            m_LosState.clear();
     440            m_LosState.resize(m_TerrainVerticesPerSide*m_TerrainVerticesPerSide);
     441        }
    431442        m_LosStateRevealed.clear();
    432443        m_LosStateRevealed.resize(m_TerrainVerticesPerSide*m_TerrainVerticesPerSide);
     
    801812    }
    802813
     814    // ****************************************************************
    803815
    804816    // LOS implementation:
     
    880892        m_LosCircular = enabled;
    881893
    882         ResetDerivedData();
     894        ResetDerivedData(false);
    883895    }
    884896
     
    886898    {
    887899        return m_LosCircular;
     900    }
     901
     902    void UpdateTerritoriesLos()
     903    {
     904        CmpPtr<ICmpTerritoryManager> cmpTerritoryManager(GetSimContext(), SYSTEM_ENTITY);
     905        if (cmpTerritoryManager.null() || !cmpTerritoryManager->NeedUpdate(&m_TerritoriesDirtyID))
     906            return;
     907
     908        const Grid<u8>& grid = cmpTerritoryManager->GetTerritoryGrid();
     909        ENSURE(grid.m_W == m_TerrainVerticesPerSide-1 && grid.m_H == m_TerrainVerticesPerSide-1);
     910
     911        // For each tile, if it is owned by a valid player then update the LOS
     912        // for every vertex around that tile, to mark them as explored
     913
     914        for (size_t j = 0; j < grid.m_H; ++j)
     915        {
     916            for (size_t i = 0; i < grid.m_W; ++i)
     917            {
     918                u8 p = grid.get(i, j);
     919                if (p > 0 && p <= MAX_LOS_PLAYER_ID)
     920                {
     921                    m_LosState[i + j*m_TerrainVerticesPerSide] |= (LOS_EXPLORED << (2*(p-1)));
     922                    m_LosState[i+1 + j*m_TerrainVerticesPerSide] |= (LOS_EXPLORED << (2*(p-1)));
     923                    m_LosState[i + (j+1)*m_TerrainVerticesPerSide] |= (LOS_EXPLORED << (2*(p-1)));
     924                    m_LosState[i+1 + (j+1)*m_TerrainVerticesPerSide] |= (LOS_EXPLORED << (2*(p-1)));
     925                }
     926            }
     927        }
    888928    }
    889929
  • ps/trunk/source/simulation2/components/CCmpTerritoryManager.cpp

    r9929 r9951  
    183183    virtual bool NeedUpdate(size_t* dirtyID)
    184184    {
    185         ENSURE(*dirtyID <= m_DirtyID);
    186         if (*dirtyID < m_DirtyID)
     185        if (*dirtyID != m_DirtyID)
    187186        {
    188187            *dirtyID = m_DirtyID;
Note: See TracChangeset for help on using the changeset viewer.