Ticket #3168: t3168_fog_of_war_v1.patch

File t3168_fog_of_war_v1.patch, 7.8 KB (added by elexis, 8 years ago)

Updates the fog of war if the observer changes the viewed player. This means the SimContext must be non-const since that class holds the globals checked by the components.

  • binaries/data/mods/public/gui/session/session.js

    function init(initData, hotloadData)  
    198198        Engine.EndGame();
    199199        Engine.SwitchGuiPage("page_pregame.xml");
    200200        return;
    201201    }
    202202
     203    Engine.SetViewedPlayer(g_ViewedPlayer);
     204
    203205    if (initData)
    204206    {
    205207        g_IsNetworked = initData.isNetworked;
    206208        g_IsController = initData.isController;
    207209        g_PlayerAssignments = initData.playerAssignments;
    function selectViewPlayer(playerID)  
    296298    if (playerID < -1 || playerID > g_Players.length - 1 ||
    297299            !g_DevSettings.changePerspective && !g_IsObserver)
    298300        return;
    299301
    300302    g_ViewedPlayer = playerID;
     303    Engine.SetViewedPlayer(playerID);
    301304    Engine.SetPlayerID(g_DevSettings.changePerspective ? playerID : -1);
    302305
    303306    updateTopPanel();
    304307    onSimulationUpdate();
    305308
  • source/graphics/LOSTexture.cpp

    void CLOSTexture::RecomputeTexture(int u  
    340340
    341341    CmpPtr<ICmpRangeManager> cmpRangeManager(m_Simulation, SYSTEM_ENTITY);
    342342    if (!cmpRangeManager)
    343343        return;
    344344
    345     ICmpRangeManager::CLosQuerier los(cmpRangeManager->GetLosQuerier(g_Game->GetPlayerID()));
     345    ICmpRangeManager::CLosQuerier los(cmpRangeManager->GetLosQuerier(g_Game->GetSimulation2()->GetSimContext().GetCurrentDisplayedPlayer()));
    346346
    347347    GenerateBitmap(los, &losData[0], m_MapSize, m_MapSize, pitch);
    348348
    349349    if (CRenderer::IsInitialised() && g_Renderer.m_Options.m_SmoothLOS && recreated)
    350350    {
  • source/gui/MiniMap.cpp

     
    1 /* Copyright (C) 2015 Wildfire Games.
     1/* Copyright (C) 2016 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
    55 * it under the terms of the GNU General Public License as published by
    66 * the Free Software Foundation, either version 2 of the License, or
    void CMiniMap::Draw()  
    528528        for (CSimulation2::InterfaceList::const_iterator it = ents.begin(); it != ents.end(); ++it)
    529529        {
    530530            ICmpMinimap* cmpMinimap = static_cast<ICmpMinimap*>(it->second);
    531531            if (cmpMinimap->GetRenderData(v.r, v.g, v.b, posX, posZ))
    532532            {
    533                 ICmpRangeManager::ELosVisibility vis = cmpRangeManager->GetLosVisibility(it->first, g_Game->GetPlayerID());
     533                ICmpRangeManager::ELosVisibility vis = cmpRangeManager->GetLosVisibility(it->first, g_Game->GetSimulation2()->GetSimContext().GetCurrentDisplayedPlayer());
    534534                if (vis != ICmpRangeManager::VIS_HIDDEN)
    535535                {
    536536                    v.a = 255;
    537537                    v.x = posX.ToFloat() * sx;
    538538                    v.y = -posZ.ToFloat() * sy;
  • source/gui/scripting/ScriptFunctions.cpp

    void SetPlayerID(ScriptInterface::CxPriv  
    217217{
    218218    if (g_Game)
    219219        g_Game->SetPlayerID(id);
    220220}
    221221
     222void SetViewedPlayer(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int id)
     223{
     224    if (!g_Game || id < 0)
     225        return;
     226
     227    g_Game->GetSimulation2()->GetSimContext().SetCurrentDisplayedPlayer(id);
     228}
     229
    222230JS::Value GetEngineInfo(ScriptInterface::CxPrivate* pCxPrivate)
    223231{
    224232    return SavedGames::GetEngineInfo(*(pCxPrivate->pScriptInterface));
    225233}
    226234
    void GuiScriptingInit(ScriptInterface& s  
    10211029    // Misc functions
    10221030    scriptInterface.RegisterFunction<std::wstring, std::wstring, &SetCursor>("SetCursor");
    10231031    scriptInterface.RegisterFunction<bool, &IsVisualReplay>("IsVisualReplay");
    10241032    scriptInterface.RegisterFunction<int, &GetPlayerID>("GetPlayerID");
    10251033    scriptInterface.RegisterFunction<void, int, &SetPlayerID>("SetPlayerID");
     1034    scriptInterface.RegisterFunction<void, int, &SetViewedPlayer>("SetViewedPlayer");
    10261035    scriptInterface.RegisterFunction<void, std::string, &OpenURL>("OpenURL");
    10271036    scriptInterface.RegisterFunction<std::wstring, &GetMatchID>("GetMatchID");
    10281037    scriptInterface.RegisterFunction<void, &RestartInAtlas>("RestartInAtlas");
    10291038    scriptInterface.RegisterFunction<bool, &AtlasIsAvailable>("AtlasIsAvailable");
    10301039    scriptInterface.RegisterFunction<bool, &IsAtlasRunning>("IsAtlasRunning");
  • source/simulation2/Simulation2.cpp

    CSimulation2::InterfaceList CSimulation2  
    644644const CSimulation2::InterfaceListUnordered& CSimulation2::GetEntitiesWithInterfaceUnordered(int iid)
    645645{
    646646    return m->m_ComponentManager.GetEntitiesWithInterfaceUnordered(iid);
    647647}
    648648
    649 const CSimContext& CSimulation2::GetSimContext() const
     649CSimContext& CSimulation2::GetSimContext() const
    650650{
    651651    return m->m_SimContext;
    652652}
    653653
    654654ScriptInterface& CSimulation2::GetScriptInterface() const
  • source/simulation2/Simulation2.h

    public:  
    215215     * Returns a list of components implementing the given interface, and their
    216216     * associated entities, as an unordered map.
    217217     */
    218218    const InterfaceListUnordered& GetEntitiesWithInterfaceUnordered(int iid);
    219219
    220     const CSimContext& GetSimContext() const;
     220    CSimContext& GetSimContext() const;
    221221    ScriptInterface& GetScriptInterface() const;
    222222
    223223    bool ComputeStateHash(std::string& outHash, bool quick);
    224224    bool DumpDebugState(std::ostream& stream);
    225225    bool SerializeState(std::ostream& stream);
  • source/simulation2/system/SimContext.cpp

     
    1 /* Copyright (C) 2011 Wildfire Games.
     1/* Copyright (C) 2016 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
    55 * it under the terms of the GNU General Public License as published by
    66 * the Free Software Foundation, either version 2 of the License, or
    ScriptInterface& CSimContext::GetScriptI  
    6565    return GetComponentManager().GetScriptInterface();
    6666}
    6767
    6868int CSimContext::GetCurrentDisplayedPlayer() const
    6969{
    70     if (!g_Game)
    71         return -1;
    72     return g_Game->GetPlayerID();
     70    return g_Game ? currentDisplayedPlayer : -1;
     71}
     72
     73void CSimContext::SetCurrentDisplayedPlayer(int player)
     74{
     75    currentDisplayedPlayer = player;
    7376}
  • source/simulation2/system/SimContext.h

     
    1 /* Copyright (C) 2011 Wildfire Games.
     1/* Copyright (C) 2016 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
    55 * it under the terms of the GNU General Public License as published by
    66 * the Free Software Foundation, either version 2 of the License, or
    public:  
    5151    /**
    5252     * Returns the player ID that the current display is being rendered for.
    5353     * Currently relies on g_Game being initialised (evil globals...)
    5454     */
    5555    int GetCurrentDisplayedPlayer() const;
     56    void SetCurrentDisplayedPlayer(int player);
    5657
    5758private:
    5859    CComponentManager* m_ComponentManager;
    5960    CUnitManager* m_UnitManager;
    6061    CTerrain* m_Terrain;
    6162
    6263    CEntityHandle m_SystemEntity;
    6364
     65    int currentDisplayedPlayer = 0;
     66
    6467    friend class CSimulation2Impl;
    6568};
    6669
    6770#endif // INCLUDED_SIMCONTEXT