Ticket #1334: shared-los.patch

File shared-los.patch, 9.2 KB (added by Deiz, 12 years ago)
  • binaries/data/mods/public/simulation/components/GuiInterface.js

    diff --git a/binaries/data/mods/public/simulation/components/GuiInterface.js b/binaries/data/mods/public/simulation/components/GuiInterface.js
    index 4ce8c71..0129529 100644
    a b GuiInterface.prototype.GetSimulationState = function(player)  
    6565        // store player ally/enemy data as arrays
    6666        var allies = [];
    6767        var enemies = [];
    68         for (var j = 0; j <= n; ++j)
     68        for (var j = 0; j < n; ++j)
    6969        {
    7070            allies[j] = cmpPlayer.IsAlly(j);
    7171            enemies[j] = cmpPlayer.IsEnemy(j);
    7272        }
     73
     74        var diplomacy = [];
     75        for (var k = 0; k < allies.length; ++k)
     76        {
     77            if (allies[k])
     78                diplomacy.push(k);
     79        }
     80        cmpPlayer.SetAllies(diplomacy);
     81
    7382        var playerData = {
    7483            "name": cmpPlayer.GetName(),
    7584            "civ": cmpPlayer.GetCiv(),
  • binaries/data/mods/public/simulation/components/Player.js

    diff --git a/binaries/data/mods/public/simulation/components/Player.js b/binaries/data/mods/public/simulation/components/Player.js
    index cb73201..bbb5a12 100644
    a b Player.prototype.Init = function()  
    2323    this.team = -1; // team number of the player, players on the same team will always have ally diplomatic status - also this is useful for team emblems, scoring, etc.
    2424    this.state = "active"; // game state - one of "active", "defeated", "won"
    2525    this.diplomacy = [];    // array of diplomatic stances for this player with respect to other players (including gaia and self)
     26    this.allies = []; // non-sparse array of a player's allies (including self)
    2627    this.conquestCriticalEntitiesCount = 0; // number of owned units with ConquestCritical class
    2728    this.phase = "village";
    2829    this.formations = [];
    Player.prototype.SetTeam = function(team)  
    213214    this.team = team;
    214215};
    215216
     217Player.prototype.GetAllies = function()
     218{
     219    return this.allies;
     220};
     221
     222Player.prototype.SetAllies = function(allies)
     223{
     224    this.allies = allies;
     225};
     226
    216227Player.prototype.GetDiplomacy = function()
    217228{
    218229    return this.diplomacy;
  • source/graphics/GameView.cpp

    diff --git a/source/graphics/GameView.cpp b/source/graphics/GameView.cpp
    index 86e7c26..ca12aaf 100644
    a b void CGameView::BeginFrame()  
    487487    CheckLightEnv();
    488488
    489489    m->Game->CachePlayerColours();
     490    m->Game->CachePlayerTeamMasks();
    490491}
    491492
    492493void CGameView::Render()
  • source/graphics/LOSTexture.cpp

    diff --git a/source/graphics/LOSTexture.cpp b/source/graphics/LOSTexture.cpp
    index e89c7d7..cb252cf 100644
    a b void CLOSTexture::RecomputeTexture(int unit)  
    178178    if (!cmpRangeManager)
    179179        return;
    180180
    181     ICmpRangeManager::CLosQuerier los (cmpRangeManager->GetLosQuerier(g_Game->GetPlayerID()));
     181    u32 playerMask = g_Game->GetPlayerTeamMask(g_Game->GetPlayerID());
     182    ICmpRangeManager::CLosQuerier los (cmpRangeManager->GetLosQuerier(g_Game->GetPlayerID(), playerMask));
    182183
    183184    GenerateBitmap(los, &losData[0], m_MapSize, m_MapSize);
    184185
  • source/ps/Game.cpp

    diff --git a/source/ps/Game.cpp b/source/ps/Game.cpp
    index 83ec259..d882dfd 100644
    a b CColor CGame::GetPlayerColour(int player) const  
    352352
    353353    return m_PlayerColours[player];
    354354}
     355
     356
     357void CGame::CachePlayerTeamMasks()
     358{
     359    m_PlayerTeamMasks.clear();
     360
     361    CmpPtr<ICmpPlayerManager> cmpPlayerManager(*m_Simulation2, SYSTEM_ENTITY);
     362    if (!cmpPlayerManager)
     363        return;
     364
     365    CmpPtr<ICmpRangeManager> cmpRangeManager(*m_Simulation2, SYSTEM_ENTITY);
     366    if (!cmpRangeManager)
     367        return;
     368
     369    int numPlayers = cmpPlayerManager->GetNumPlayers();
     370    m_PlayerTeamMasks.resize(numPlayers);
     371
     372    for (int i = 0; i < numPlayers; ++i)
     373    {
     374        CmpPtr<ICmpPlayer> cmpPlayer(*m_Simulation2, cmpPlayerManager->GetPlayerByID(i));
     375        if (!cmpPlayer)
     376            m_PlayerTeamMasks[i] = 0;
     377        else
     378            m_PlayerTeamMasks[i] = cmpRangeManager->GetLosVisibilityMask( cmpPlayer->GetAllies() );
     379    }
     380}
     381
     382
     383u32 CGame::GetPlayerTeamMask(int player) const
     384{
     385    if (player < 0 || player >= (int)m_PlayerTeamMasks.size())
     386        return 0;
     387
     388    return m_PlayerTeamMasks[player];
     389}
  • source/ps/Game.h

    diff --git a/source/ps/Game.h b/source/ps/Game.h
    index d6a1d18..70aedb6 100644
    a b public:  
    9797    CColor GetPlayerColour(int player) const;
    9898
    9999    /**
     100     * Retrieves each player's list of allies and generates a mask that
     101     * allows line-of-sight visibility to be checked against a player and
     102     * all allies with one comparison.
     103     */
     104    void CachePlayerTeamMasks();
     105
     106    u32 GetPlayerTeamMask(int player) const;
     107
     108    /**
    100109     * Get m_GameStarted.
    101110     *
    102111     * @return bool the value of m_GameStarted.
    private:  
    158167    IReplayLogger* m_ReplayLogger;
    159168
    160169    std::vector<CColor> m_PlayerColours;
     170    std::vector<u32> m_PlayerTeamMasks;
    161171
    162172    int LoadInitialState();
    163173    std::string m_InitialSavedState; // valid between RegisterInit and LoadInitialState
  • source/simulation2/components/CCmpRangeManager.cpp

    diff --git a/source/simulation2/components/CCmpRangeManager.cpp b/source/simulation2/components/CCmpRangeManager.cpp
    index 44a098d..d7b8e4a 100644
    a b  
    3232#include "lib/timer.h"
    3333#include "maths/FixedVector2D.h"
    3434#include "ps/CLogger.h"
     35#include "ps/Game.h"
    3536#include "ps/Overlay.h"
    3637#include "ps/Profile.h"
    3738#include "renderer/Scene.h"
    public:  
    915916            return CLosQuerier(player, m_LosState, m_TerrainVerticesPerSide);
    916917    }
    917918
     919    virtual CLosQuerier GetLosQuerier(player_id_t player, u32 playerMask)
     920    {
     921        if (GetLosRevealAll(player))
     922            return CLosQuerier(playerMask, m_LosStateRevealed, m_TerrainVerticesPerSide);
     923        else
     924            return CLosQuerier(playerMask, m_LosState, m_TerrainVerticesPerSide);
     925    }
     926
    918927    virtual ELosVisibility GetLosVisibility(entity_id_t ent, player_id_t player, bool forceRetainInFog)
    919928    {
     929        return GetLosVisibility(ent, player, 0, forceRetainInFog);
     930    }
     931
     932    virtual ELosVisibility GetLosVisibility(entity_id_t ent, player_id_t player, u32 playerMask, bool forceRetainInFog)
     933    {
    920934        // (We can't use m_EntityData since this needs to handle LOCAL entities too)
    921935
    922936        // Entities not with positions in the world are never visible
    public:  
    939953        }
    940954
    941955        // Visible if within a visible region
     956        if (!playerMask)
     957            playerMask = g_Game->GetPlayerTeamMask(player);
    942958
    943         CLosQuerier los(player, m_LosState, m_TerrainVerticesPerSide);
     959        CLosQuerier los(playerMask, m_LosState, m_TerrainVerticesPerSide);
    944960
    945961        if (los.IsVisible(i, j))
    946962            return VIS_VISIBLE;
    public:  
    957973        return VIS_HIDDEN;
    958974    }
    959975
     976    virtual u32 GetLosVisibilityMask(std::vector<player_id_t> players)
     977    {
     978        u32 playerMask = 0;
     979        player_id_t player;
     980
     981        for (size_t i = 0; i < players.size(); i++)
     982        {
     983            player = players[i];
     984            if (player > 0 && player <= 16)
     985                playerMask |= LOS_MASK << (2*(player-1));
     986            else
     987                continue;
     988        }
     989
     990        return playerMask;
     991    }
     992
    960993    virtual void SetLosRevealAll(player_id_t player, bool enabled)
    961994    {
    962995        m_LosRevealAll[player] = enabled;
  • source/simulation2/components/ICmpPlayer.cpp

    diff --git a/source/simulation2/components/ICmpPlayer.cpp b/source/simulation2/components/ICmpPlayer.cpp
    index 14b308d..8658ecd 100644
    a b public:  
    4343        return m_Script.Call<std::wstring>("GetCiv");
    4444    }
    4545
     46    virtual std::vector<int> GetAllies()
     47    {
     48        return m_Script.Call<std::vector<int> >("GetAllies");
     49    }
     50
    4651    virtual CFixedVector3D GetStartingCameraPos()
    4752    {
    4853        return m_Script.Call<CFixedVector3D>("GetStartingCameraPos");
  • source/simulation2/components/ICmpPlayer.h

    diff --git a/source/simulation2/components/ICmpPlayer.h b/source/simulation2/components/ICmpPlayer.h
    index fa30df5..fe1b95a 100644
    a b class ICmpPlayer : public IComponent  
    3333public:
    3434    virtual CColor GetColour() = 0;
    3535    virtual std::wstring GetCiv() = 0;
     36    virtual std::vector<int> GetAllies() = 0;
    3637    virtual CFixedVector3D GetStartingCameraPos() = 0;
    3738    virtual CFixedVector3D GetStartingCameraRot() = 0;
    3839
  • source/simulation2/components/ICmpRangeManager.h

    diff --git a/source/simulation2/components/ICmpRangeManager.h b/source/simulation2/components/ICmpRangeManager.h
    index 142936e..2a61d77 100644
    a b public:  
    194194                m_PlayerMask = 0;
    195195        }
    196196
     197        CLosQuerier(u32 playerMask, const std::vector<u32>& data, ssize_t verticesPerSide) :
     198            m_Data(&data[0]), m_VerticesPerSide(verticesPerSide)
     199        {
     200            m_PlayerMask = playerMask;
     201        }
     202
    197203        const CLosQuerier& operator=(const CLosQuerier&); // not implemented
    198204
    199205    public:
    public:  
    269275     * Returns a CLosQuerier for checking whether vertex positions are visible to the given player.
    270276     */
    271277    virtual CLosQuerier GetLosQuerier(player_id_t player) = 0;
     278    virtual CLosQuerier GetLosQuerier(player_id_t player, u32 playerMask) = 0;
    272279
    273280    /**
    274281     * Returns the visibility status of the given entity, with respect to the given player.
    public:  
    279286     *  see http://trac.wildfiregames.com/ticket/958
    280287     */
    281288    virtual ELosVisibility GetLosVisibility(entity_id_t ent, player_id_t player, bool forceRetainInFog = false) = 0;
     289    virtual u32 GetLosVisibilityMask(std::vector<player_id_t> players) = 0;
    282290
    283291    /**
    284292     * GetLosVisibility wrapped for script calls.