1
1
forked from 0ad/0ad

Simulation context cleanup, refs #3991, #3168.

Save the viewed player in the CGame class.
Add the const keyword back to the SimContext to help find mistakes at
compiletime.

This was SVN commit r18201.
This commit is contained in:
elexis 2016-05-19 19:42:07 +00:00
parent 1b3a12ea92
commit 6f744aef88
7 changed files with 34 additions and 24 deletions

View File

@ -237,10 +237,8 @@ void SetPlayerID(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int id)
void SetViewedPlayer(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int id)
{
if (!g_Game)
return;
g_Game->GetSimulation2()->GetSimContext().SetCurrentDisplayedPlayer(id);
if (g_Game)
g_Game->SetViewedPlayerID(id);
}
JS::Value GetEngineInfo(ScriptInterface::CxPrivate* pCxPrivate)

View File

@ -345,10 +345,20 @@ int CGame::GetPlayerID()
void CGame::SetPlayerID(player_id_t playerID)
{
m_PlayerID = playerID;
m_ViewedPlayerID = playerID;
if (m_TurnManager)
m_TurnManager->SetPlayerID(m_PlayerID);
}
m_Simulation2->SetCurrentDisplayedPlayer(g_Game->GetPlayerID());
int CGame::GetViewedPlayerID()
{
return m_ViewedPlayerID;
}
void CGame::SetViewedPlayerID(player_id_t playerID)
{
m_ViewedPlayerID = playerID;
}
void CGame::StartGame(JS::MutableHandleValue attribs, const std::string& savedState)

View File

@ -40,29 +40,43 @@ struct CColor;
class CGame
{
NONCOPYABLE(CGame);
/**
* pointer to the CWorld object representing the game world.
**/
CWorld *m_World;
/**
* pointer to the CSimulation2 object operating on the game world.
**/
CSimulation2 *m_Simulation2;
/**
* pointer to the CGameView object representing the view into the game world.
**/
CGameView *m_GameView;
/**
* the game has been initialized and ready for use if true.
**/
bool m_GameStarted;
/**
* Timescale multiplier for simulation rate.
**/
float m_SimRate;
/**
* Index assigned to the current player.
* 1-8 to control players, 0 for gaia, -1 for observer.
*/
player_id_t m_PlayerID;
/**
* Differs from m_PlayerID if a defeated player or observer views another player.
*/
player_id_t m_ViewedPlayerID;
CNetTurnManager* m_TurnManager;
public:
@ -95,6 +109,9 @@ public:
int GetPlayerID();
void SetPlayerID(player_id_t playerID);
int GetViewedPlayerID();
void SetViewedPlayerID(player_id_t playerID);
/**
* Retrieving player colors from scripts is slow, so this updates an
* internal cache of all players' colors.

View File

@ -607,11 +607,6 @@ void CSimulation2::EnableSerializationTest()
m->m_EnableSerializationTest = true;
}
void CSimulation2::SetCurrentDisplayedPlayer(int playerID)
{
m->m_SimContext.SetCurrentDisplayedPlayer(playerID);
}
entity_id_t CSimulation2::AddEntity(const std::wstring& templateName)
{
return m->m_ComponentManager.AddEntity(templateName, m->m_ComponentManager.AllocateNewEntity());
@ -662,7 +657,7 @@ const CSimulation2::InterfaceListUnordered& CSimulation2::GetEntitiesWithInterfa
return m->m_ComponentManager.GetEntitiesWithInterfaceUnordered(iid);
}
CSimContext& CSimulation2::GetSimContext() const
const CSimContext& CSimulation2::GetSimContext() const
{
return m->m_SimContext;
}

View File

@ -57,8 +57,6 @@ public:
void EnableOOSLog();
void EnableSerializationTest();
void SetCurrentDisplayedPlayer(int playerID);
/**
* Load all scripts in the specified directory (non-recursively),
* so they can register new component types and functions. This
@ -219,7 +217,7 @@ public:
*/
const InterfaceListUnordered& GetEntitiesWithInterfaceUnordered(int iid);
CSimContext& GetSimContext() const;
const CSimContext& GetSimContext() const;
ScriptInterface& GetScriptInterface() const;
bool ComputeStateHash(std::string& outHash, bool quick);

View File

@ -24,7 +24,7 @@
#include "ps/Game.h"
CSimContext::CSimContext() :
m_ComponentManager(NULL), m_UnitManager(NULL), m_Terrain(NULL), m_CurrentDisplayedPlayer(0)
m_ComponentManager(NULL), m_UnitManager(NULL), m_Terrain(NULL)
{
}
@ -67,10 +67,5 @@ ScriptInterface& CSimContext::GetScriptInterface() const
int CSimContext::GetCurrentDisplayedPlayer() const
{
return g_Game ? m_CurrentDisplayedPlayer : -1;
}
void CSimContext::SetCurrentDisplayedPlayer(int player)
{
m_CurrentDisplayedPlayer = player;
return g_Game ? g_Game->GetViewedPlayerID() : -1;
}

View File

@ -53,7 +53,6 @@ public:
* Currently relies on g_Game being initialised (evil globals...)
*/
int GetCurrentDisplayedPlayer() const;
void SetCurrentDisplayedPlayer(int player);
private:
CComponentManager* m_ComponentManager;
@ -62,8 +61,6 @@ private:
CEntityHandle m_SystemEntity;
int m_CurrentDisplayedPlayer;
friend class CSimulation2Impl;
};