Ticket #1334: shared-los-2.patch

File shared-los-2.patch, 7.3 KB (added by Deiz, 12 years ago)
  • 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..0bb4955 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        {
     379            std::vector<int> diplomacy = cmpPlayer->GetDiplomacy();
     380            std::vector<int> allies;
     381            for (size_t j = 0; j < diplomacy.size(); ++j)
     382                if (diplomacy[j] == 1)
     383                    allies.push_back(j);
     384
     385            m_PlayerTeamMasks[i] = cmpRangeManager->GetLosVisibilityMask( allies );
     386        }
     387    }
     388}
     389
     390
     391u32 CGame::GetPlayerTeamMask(int player) const
     392{
     393    if (player < 0 || player >= (int)m_PlayerTeamMasks.size())
     394        return 0;
     395
     396    return m_PlayerTeamMasks[player];
     397}
  • 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..19bb65e 100644
    a b public:  
    4343        return m_Script.Call<std::wstring>("GetCiv");
    4444    }
    4545
     46    virtual std::vector<int> GetDiplomacy()
     47    {
     48        return m_Script.Call<std::vector<int> >("GetDiplomacy");
     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..bf62e5b 100644
    a b class ICmpPlayer : public IComponent  
    3333public:
    3434    virtual CColor GetColour() = 0;
    3535    virtual std::wstring GetCiv() = 0;
     36    virtual std::vector<int> GetDiplomacy() = 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.