Ticket #3991: t3991_const_simcontext_v1.patch
File t3991_const_simcontext_v1.patch, 6.9 KB (added by , 8 years ago) |
---|
-
source/gui/scripting/ScriptFunctions.cpp
void SetPlayerID(ScriptInterface::CxPriv 235 235 g_Game->SetPlayerID(id); 236 236 } 237 237 238 238 void SetViewedPlayer(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int id) 239 239 { 240 if (!g_Game) 241 return; 242 243 g_Game->GetSimulation2()->GetSimContext().SetCurrentDisplayedPlayer(id); 240 if (g_Game) 241 g_Game->SetViewedPlayerID(id); 244 242 } 245 243 246 244 JS::Value GetEngineInfo(ScriptInterface::CxPrivate* pCxPrivate) 247 245 { 248 246 return SavedGames::GetEngineInfo(*(pCxPrivate->pScriptInterface)); -
source/ps/Game.cpp
int CGame::GetPlayerID() 343 343 } 344 344 345 345 void CGame::SetPlayerID(player_id_t playerID) 346 346 { 347 347 m_PlayerID = playerID; 348 m_ViewedPlayerID = playerID; 349 348 350 if (m_TurnManager) 349 351 m_TurnManager->SetPlayerID(m_PlayerID); 352 } 353 354 int CGame::GetViewedPlayerID() 355 { 356 return m_ViewedPlayerID; 357 } 350 358 351 m_Simulation2->SetCurrentDisplayedPlayer(g_Game->GetPlayerID()); 359 void CGame::SetViewedPlayerID(player_id_t playerID) 360 { 361 m_ViewedPlayerID = playerID; 352 362 } 353 363 354 364 void CGame::StartGame(JS::MutableHandleValue attribs, const std::string& savedState) 355 365 { 356 366 if (m_ReplayLogger) -
source/ps/Game.h
struct CColor; 38 38 * maintaining the relations between CPlayer and CWorld, CSimulation and CWorld. 39 39 **/ 40 40 class CGame 41 41 { 42 42 NONCOPYABLE(CGame); 43 43 44 /** 44 45 * pointer to the CWorld object representing the game world. 45 46 **/ 46 47 CWorld *m_World; 48 47 49 /** 48 50 * pointer to the CSimulation2 object operating on the game world. 49 51 **/ 50 52 CSimulation2 *m_Simulation2; 53 51 54 /** 52 55 * pointer to the CGameView object representing the view into the game world. 53 56 **/ 54 57 CGameView *m_GameView; 58 55 59 /** 56 60 * the game has been initialized and ready for use if true. 57 61 **/ 58 62 bool m_GameStarted; 59 63 /** 60 64 * Timescale multiplier for simulation rate. 61 65 **/ 62 66 float m_SimRate; 63 67 68 /** 69 * Index assigned to the current player. 70 * 1-8 to control players, 0 for gaia, -1 for observer. 71 */ 64 72 player_id_t m_PlayerID; 65 73 74 /** 75 * Differs from m_PlayerID if a defeated player or observer views another player. 76 */ 77 player_id_t m_ViewedPlayerID; 78 66 79 CNetTurnManager* m_TurnManager; 67 80 68 81 public: 69 82 CGame(bool disableGraphics = false, bool replayLog = true); 70 83 ~CGame(); … … public: 93 106 void Interpolate(float simFrameLength, float realFrameLength); 94 107 95 108 int GetPlayerID(); 96 109 void SetPlayerID(player_id_t playerID); 97 110 111 int GetViewedPlayerID(); 112 void SetViewedPlayerID(player_id_t playerID); 113 98 114 /** 99 115 * Retrieving player colors from scripts is slow, so this updates an 100 116 * internal cache of all players' colors. 101 117 * Call this just before rendering, so it will always have the latest 102 118 * colors. -
source/simulation2/Simulation2.cpp
void CSimulation2::EnableOOSLog() 605 605 void CSimulation2::EnableSerializationTest() 606 606 { 607 607 m->m_EnableSerializationTest = true; 608 608 } 609 609 610 void CSimulation2::SetCurrentDisplayedPlayer(int playerID)611 {612 m->m_SimContext.SetCurrentDisplayedPlayer(playerID);613 }614 615 610 entity_id_t CSimulation2::AddEntity(const std::wstring& templateName) 616 611 { 617 612 return m->m_ComponentManager.AddEntity(templateName, m->m_ComponentManager.AllocateNewEntity()); 618 613 } 619 614 … … CSimulation2::InterfaceList CSimulation2 660 655 const CSimulation2::InterfaceListUnordered& CSimulation2::GetEntitiesWithInterfaceUnordered(int iid) 661 656 { 662 657 return m->m_ComponentManager.GetEntitiesWithInterfaceUnordered(iid); 663 658 } 664 659 665 CSimContext& CSimulation2::GetSimContext() const660 const CSimContext& CSimulation2::GetSimContext() const 666 661 { 667 662 return m->m_SimContext; 668 663 } 669 664 670 665 ScriptInterface& CSimulation2::GetScriptInterface() const -
source/simulation2/Simulation2.h
public: 55 55 ~CSimulation2(); 56 56 57 57 void EnableOOSLog(); 58 58 void EnableSerializationTest(); 59 59 60 void SetCurrentDisplayedPlayer(int playerID);61 62 60 /** 63 61 * Load all scripts in the specified directory (non-recursively), 64 62 * so they can register new component types and functions. This 65 63 * should be called immediately after constructing the CSimulation2 object. 66 64 * @return false on failure … … public: 217 215 * Returns a list of components implementing the given interface, and their 218 216 * associated entities, as an unordered map. 219 217 */ 220 218 const InterfaceListUnordered& GetEntitiesWithInterfaceUnordered(int iid); 221 219 222 CSimContext& GetSimContext() const;220 const CSimContext& GetSimContext() const; 223 221 ScriptInterface& GetScriptInterface() const; 224 222 225 223 bool ComputeStateHash(std::string& outHash, bool quick); 226 224 bool DumpDebugState(std::ostream& stream); 227 225 bool SerializeState(std::ostream& stream); -
source/simulation2/system/SimContext.cpp
22 22 #include "ComponentManager.h" 23 23 24 24 #include "ps/Game.h" 25 25 26 26 CSimContext::CSimContext() : 27 m_ComponentManager(NULL), m_UnitManager(NULL), m_Terrain(NULL) , m_CurrentDisplayedPlayer(0)27 m_ComponentManager(NULL), m_UnitManager(NULL), m_Terrain(NULL) 28 28 { 29 29 } 30 30 31 31 CSimContext::~CSimContext() 32 32 { … … ScriptInterface& CSimContext::GetScriptI 65 65 return GetComponentManager().GetScriptInterface(); 66 66 } 67 67 68 68 int CSimContext::GetCurrentDisplayedPlayer() const 69 69 { 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; 76 71 } -
source/simulation2/system/SimContext.h
public: 51 51 /** 52 52 * Returns the player ID that the current display is being rendered for. 53 53 * Currently relies on g_Game being initialised (evil globals...) 54 54 */ 55 55 int GetCurrentDisplayedPlayer() const; 56 void SetCurrentDisplayedPlayer(int player);57 56 58 57 private: 59 58 CComponentManager* m_ComponentManager; 60 59 CUnitManager* m_UnitManager; 61 60 CTerrain* m_Terrain; 62 61 63 62 CEntityHandle m_SystemEntity; 64 63 65 int m_CurrentDisplayedPlayer;66 67 64 friend class CSimulation2Impl; 68 65 }; 69 66 70 67 #endif // INCLUDED_SIMCONTEXT