Ticket #3991: t3991_const_simcontext_v1.patch

File t3991_const_simcontext_v1.patch, 6.9 KB (added by elexis, 8 years ago)
  • source/gui/scripting/ScriptFunctions.cpp

    void SetPlayerID(ScriptInterface::CxPriv  
    235235        g_Game->SetPlayerID(id);
    236236}
    237237
    238238void SetViewedPlayer(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int id)
    239239{
    240     if (!g_Game)
    241         return;
    242 
    243     g_Game->GetSimulation2()->GetSimContext().SetCurrentDisplayedPlayer(id);
     240    if (g_Game)
     241        g_Game->SetViewedPlayerID(id);
    244242}
    245243
    246244JS::Value GetEngineInfo(ScriptInterface::CxPrivate* pCxPrivate)
    247245{
    248246    return SavedGames::GetEngineInfo(*(pCxPrivate->pScriptInterface));
  • source/ps/Game.cpp

    int CGame::GetPlayerID()  
    343343}
    344344
    345345void CGame::SetPlayerID(player_id_t playerID)
    346346{
    347347    m_PlayerID = playerID;
     348    m_ViewedPlayerID = playerID;
     349
    348350    if (m_TurnManager)
    349351        m_TurnManager->SetPlayerID(m_PlayerID);
     352}
     353
     354int CGame::GetViewedPlayerID()
     355{
     356    return m_ViewedPlayerID;
     357}
    350358
    351     m_Simulation2->SetCurrentDisplayedPlayer(g_Game->GetPlayerID());
     359void CGame::SetViewedPlayerID(player_id_t playerID)
     360{
     361    m_ViewedPlayerID = playerID;
    352362}
    353363
    354364void CGame::StartGame(JS::MutableHandleValue attribs, const std::string& savedState)
    355365{
    356366    if (m_ReplayLogger)
  • source/ps/Game.h

    struct CColor;  
    3838 * maintaining the relations between CPlayer and CWorld, CSimulation and CWorld.
    3939 **/
    4040class CGame
    4141{
    4242    NONCOPYABLE(CGame);
     43
    4344    /**
    4445     * pointer to the CWorld object representing the game world.
    4546     **/
    4647    CWorld *m_World;
     48
    4749    /**
    4850     * pointer to the CSimulation2 object operating on the game world.
    4951     **/
    5052    CSimulation2 *m_Simulation2;
     53
    5154    /**
    5255     * pointer to the CGameView object representing the view into the game world.
    5356     **/
    5457    CGameView *m_GameView;
     58
    5559    /**
    5660     * the game has been initialized and ready for use if true.
    5761     **/
    5862    bool m_GameStarted;
    5963    /**
    6064     * Timescale multiplier for simulation rate.
    6165     **/
    6266    float m_SimRate;
    6367
     68    /**
     69     * Index assigned to the current player.
     70     * 1-8 to control players, 0 for gaia, -1 for observer.
     71     */
    6472    player_id_t m_PlayerID;
    6573
     74    /**
     75     * Differs from m_PlayerID if a defeated player or observer views another player.
     76     */
     77    player_id_t m_ViewedPlayerID;
     78
    6679    CNetTurnManager* m_TurnManager;
    6780
    6881public:
    6982    CGame(bool disableGraphics = false, bool replayLog = true);
    7083    ~CGame();
    public:  
    93106    void Interpolate(float simFrameLength, float realFrameLength);
    94107
    95108    int GetPlayerID();
    96109    void SetPlayerID(player_id_t playerID);
    97110
     111    int GetViewedPlayerID();
     112    void SetViewedPlayerID(player_id_t playerID);
     113
    98114    /**
    99115     * Retrieving player colors from scripts is slow, so this updates an
    100116     * internal cache of all players' colors.
    101117     * Call this just before rendering, so it will always have the latest
    102118     * colors.
  • source/simulation2/Simulation2.cpp

    void CSimulation2::EnableOOSLog()  
    605605void CSimulation2::EnableSerializationTest()
    606606{
    607607    m->m_EnableSerializationTest = true;
    608608}
    609609
    610 void CSimulation2::SetCurrentDisplayedPlayer(int playerID)
    611 {
    612     m->m_SimContext.SetCurrentDisplayedPlayer(playerID);
    613 }
    614 
    615610entity_id_t CSimulation2::AddEntity(const std::wstring& templateName)
    616611{
    617612    return m->m_ComponentManager.AddEntity(templateName, m->m_ComponentManager.AllocateNewEntity());
    618613}
    619614
    CSimulation2::InterfaceList CSimulation2  
    660655const CSimulation2::InterfaceListUnordered& CSimulation2::GetEntitiesWithInterfaceUnordered(int iid)
    661656{
    662657    return m->m_ComponentManager.GetEntitiesWithInterfaceUnordered(iid);
    663658}
    664659
    665 CSimContext& CSimulation2::GetSimContext() const
     660const CSimContext& CSimulation2::GetSimContext() const
    666661{
    667662    return m->m_SimContext;
    668663}
    669664
    670665ScriptInterface& CSimulation2::GetScriptInterface() const
  • source/simulation2/Simulation2.h

    public:  
    5555    ~CSimulation2();
    5656
    5757    void EnableOOSLog();
    5858    void EnableSerializationTest();
    5959
    60     void SetCurrentDisplayedPlayer(int playerID);
    61 
    6260    /**
    6361     * Load all scripts in the specified directory (non-recursively),
    6462     * so they can register new component types and functions. This
    6563     * should be called immediately after constructing the CSimulation2 object.
    6664     * @return false on failure
    public:  
    217215     * Returns a list of components implementing the given interface, and their
    218216     * associated entities, as an unordered map.
    219217     */
    220218    const InterfaceListUnordered& GetEntitiesWithInterfaceUnordered(int iid);
    221219
    222     CSimContext& GetSimContext() const;
     220    const CSimContext& GetSimContext() const;
    223221    ScriptInterface& GetScriptInterface() const;
    224222
    225223    bool ComputeStateHash(std::string& outHash, bool quick);
    226224    bool DumpDebugState(std::ostream& stream);
    227225    bool SerializeState(std::ostream& stream);
  • source/simulation2/system/SimContext.cpp

     
    2222#include "ComponentManager.h"
    2323
    2424#include "ps/Game.h"
    2525
    2626CSimContext::CSimContext() :
    27     m_ComponentManager(NULL), m_UnitManager(NULL), m_Terrain(NULL), m_CurrentDisplayedPlayer(0)
     27    m_ComponentManager(NULL), m_UnitManager(NULL), m_Terrain(NULL)
    2828{
    2929}
    3030
    3131CSimContext::~CSimContext()
    3232{
    ScriptInterface& CSimContext::GetScriptI  
    6565    return GetComponentManager().GetScriptInterface();
    6666}
    6767
    6868int CSimContext::GetCurrentDisplayedPlayer() const
    6969{
    70     return g_Game ? m_CurrentDisplayedPlayer : -1;
    71 }
    72 
    73 void CSimContext::SetCurrentDisplayedPlayer(int player)
    74 {
    75     m_CurrentDisplayedPlayer = player;
     70    return g_Game ? g_Game->GetViewedPlayerID() : -1;
    7671}
  • source/simulation2/system/SimContext.h

    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);
    5756
    5857private:
    5958    CComponentManager* m_ComponentManager;
    6059    CUnitManager* m_UnitManager;
    6160    CTerrain* m_Terrain;
    6261
    6362    CEntityHandle m_SystemEntity;
    6463
    65     int m_CurrentDisplayedPlayer;
    66 
    6764    friend class CSimulation2Impl;
    6865};
    6966
    7067#endif // INCLUDED_SIMCONTEXT