More ScriptInterface const.

Reviewed By: elexis; some comments by bb
Differential Revision: https://code.wildfiregames.com/D863
This was SVN commit r20519.
This commit is contained in:
leper
2017-11-25 06:49:58 +00:00
parent 60801158b5
commit f7206dc77d
14 changed files with 27 additions and 35 deletions
+2 -2
View File
@@ -269,7 +269,7 @@ std::string CNetClient::TestReadGuiMessages()
return r;
}
ScriptInterface& CNetClient::GetScriptInterface()
const ScriptInterface& CNetClient::GetScriptInterface()
{
return m_Game->GetSimulation2()->GetScriptInterface();
}
@@ -328,7 +328,7 @@ void CNetClient::HandleDisconnect(u32 reason)
SetCurrState(NCS_UNCONNECTED);
}
void CNetClient::SendGameSetupMessage(JS::MutableHandleValue attrs, ScriptInterface& scriptInterface)
void CNetClient::SendGameSetupMessage(JS::MutableHandleValue attrs, const ScriptInterface& scriptInterface)
{
CGameSetupMessage gameSetup(scriptInterface);
gameSetup.m_Data = attrs;
+2 -2
View File
@@ -159,7 +159,7 @@ public:
* Get the script interface associated with this network client,
* which is equivalent to the one used by the CGame in the constructor.
*/
ScriptInterface& GetScriptInterface();
const ScriptInterface& GetScriptInterface();
/**
* Send a message to the server.
@@ -189,7 +189,7 @@ public:
*/
void LoadFinished();
void SendGameSetupMessage(JS::MutableHandleValue attrs, ScriptInterface& scriptInterface);
void SendGameSetupMessage(JS::MutableHandleValue attrs, const ScriptInterface& scriptInterface);
void SendAssignPlayerMessage(const int playerID, const CStr& guid);
+1 -1
View File
@@ -135,7 +135,7 @@ void CNetClientTurnManager::OnSyncError(u32 turn, const CStr& expectedHash, cons
LOGERROR("Out-Of-Sync on turn %d\nPlayers: %s\nDumping state to %s", turn, playerNamesString.str().c_str(), oosdumpPath.string8());
ScriptInterface& scriptInterface = m_NetClient.GetScriptInterface();
const ScriptInterface& scriptInterface = m_NetClient.GetScriptInterface();
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);
+3 -3
View File
@@ -845,7 +845,7 @@ void CNetServerWorker::SendPlayerAssignments()
Broadcast(&message, { NSS_PREGAME, NSS_JOIN_SYNCING, NSS_INGAME });
}
ScriptInterface& CNetServerWorker::GetScriptInterface()
const ScriptInterface& CNetServerWorker::GetScriptInterface()
{
return *m_ScriptInterface;
}
@@ -1068,7 +1068,7 @@ bool CNetServerWorker::OnInGame(void* context, CFsmEvent* event)
// Ignore messages sent by one player on behalf of another player
// unless cheating is enabled
bool cheatsEnabled = false;
ScriptInterface& scriptInterface = server.GetScriptInterface();
const ScriptInterface& scriptInterface = server.GetScriptInterface();
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);
JS::RootedValue settings(cx);
@@ -1502,7 +1502,7 @@ void CNetServer::StartGame()
m_Worker->m_StartGameQueue.push_back(true);
}
void CNetServer::UpdateGameAttributes(JS::MutableHandleValue attrs, ScriptInterface& scriptInterface)
void CNetServer::UpdateGameAttributes(JS::MutableHandleValue attrs, const ScriptInterface& scriptInterface)
{
// Pass the attributes as JSON, since that's the easiest safe
// cross-thread way of passing script data
+2 -2
View File
@@ -126,7 +126,7 @@ public:
* The changes will be asynchronously propagated to all clients.
* @param attrs game attributes, in the script context of scriptInterface
*/
void UpdateGameAttributes(JS::MutableHandleValue attrs, ScriptInterface& scriptInterface);
void UpdateGameAttributes(JS::MutableHandleValue attrs, const ScriptInterface& scriptInterface);
/**
* Set the turn length to a fixed value.
@@ -221,7 +221,7 @@ private:
/**
* Get the script context used for game attributes.
*/
ScriptInterface& GetScriptInterface();
const ScriptInterface& GetScriptInterface();
/**
* Set the turn length to a fixed value.
+2 -2
View File
@@ -173,7 +173,6 @@ bool CGame::StartVisualReplay(const OsPath& replayPath)
debug_printf("Starting to replay %s\n", replayPath.string8().c_str());
m_IsVisualReplay = true;
ScriptInterface& scriptInterface = m_Simulation2->GetScriptInterface();
SetTurnManager(new CReplayTurnManager(*m_Simulation2, GetReplayLogger()));
@@ -186,6 +185,7 @@ bool CGame::StartVisualReplay(const OsPath& replayPath)
std::string line;
std::getline(*m_ReplayStream, line);
const ScriptInterface& scriptInterface = m_Simulation2->GetScriptInterface();
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);
@@ -203,7 +203,7 @@ bool CGame::StartVisualReplay(const OsPath& replayPath)
**/
void CGame::RegisterInit(const JS::HandleValue attribs, const std::string& savedState)
{
ScriptInterface& scriptInterface = m_Simulation2->GetScriptInterface();
const ScriptInterface& scriptInterface = m_Simulation2->GetScriptInterface();
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);
-1
View File
@@ -19,7 +19,6 @@
#define INCLUDED_TEMPLATELOADER
#include "simulation2/system/ParamNode.h"
#include "scriptinterface/ScriptInterface.h"
enum ETemplatesType
{
+1 -6
View File
@@ -596,17 +596,12 @@ bool ScriptInterface::CallFunction_(JS::HandleValue val, const char* name, JS::H
return ok;
}
JS::Value ScriptInterface::GetGlobalObject()
JS::Value ScriptInterface::GetGlobalObject() const
{
JSAutoRequest rq(m->m_cx);
return JS::ObjectValue(*JS::CurrentGlobalOrNull(m->m_cx));
}
JSClass* ScriptInterface::GetGlobalClass()
{
return &global_class;
}
bool ScriptInterface::SetGlobal_(const char* name, JS::HandleValue value, bool replace)
{
JSAutoRequest rq(m->m_cx);
+1 -3
View File
@@ -134,9 +134,7 @@ public:
JSObject* CreateCustomObject(const std::string & typeName) const;
void DefineCustomObjectType(JSClass *clasp, JSNative constructor, uint minArgs, JSPropertySpec *ps, JSFunctionSpec *fs, JSPropertySpec *static_ps, JSFunctionSpec *static_fs);
JS::Value GetGlobalObject();
JSClass* GetGlobalClass();
JS::Value GetGlobalObject() const;
/**
* Set the named property on the global object.
+2 -2
View File
@@ -359,7 +359,7 @@ void CSimulation2Impl::Update(int turnLength, const std::vector<SimulationComman
const bool serializationTestHash = true; // set true to save and compare hash of state
SerializationTestState primaryStateBefore;
ScriptInterface& scriptInterface = m_ComponentManager.GetScriptInterface();
const ScriptInterface& scriptInterface = m_ComponentManager.GetScriptInterface();
const bool startRejoinTest = (int64_t) m_RejoinTestTurn == m_TurnNumber;
if (startRejoinTest)
@@ -949,7 +949,7 @@ std::string CSimulation2::GetMapSizes()
std::string CSimulation2::GetAIData()
{
ScriptInterface& scriptInterface = GetScriptInterface();
const ScriptInterface& scriptInterface = GetScriptInterface();
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);
JS::RootedValue aiData(cx, ICmpAIManager::GetAIs(scriptInterface));
@@ -1024,7 +1024,7 @@ public:
virtual void TryLoadSharedComponent()
{
ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface();
const ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface();
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);
@@ -1041,7 +1041,7 @@ public:
virtual void RunGamestateInit()
{
ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface();
const ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface();
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);
@@ -1080,7 +1080,7 @@ public:
{
PROFILE("AI setup");
ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface();
const ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface();
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);
@@ -1145,7 +1145,7 @@ public:
if (!cmpCommandQueue)
return;
ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface();
const ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface();
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);
JS::RootedValue clonedCommandVal(cx);
@@ -1197,7 +1197,7 @@ private:
if (!cmpPathfinder)
return;
ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface();
const ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface();
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);
@@ -105,7 +105,7 @@ public:
virtual void FlushTurn(const std::vector<SimulationCommand>& commands)
{
ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface();
const ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface();
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);
+1 -1
View File
@@ -59,7 +59,7 @@ public:
m_ComponentManager.LoadComponentTypes();
}
ScriptInterface& GetScriptInterface()
const ScriptInterface& GetScriptInterface()
{
return m_ComponentManager.GetScriptInterface();
}
@@ -1,4 +1,4 @@
/* Copyright (C) 2016 Wildfire Games.
/* Copyright (C) 2017 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -89,7 +89,7 @@ QUERYHANDLER(GenerateMap)
InitGame();
// Random map
ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface();
const ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface();
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);
@@ -116,7 +116,7 @@ QUERYHANDLER(GenerateMap)
InitGame();
ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface();
const ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface();
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);
@@ -149,7 +149,7 @@ MESSAGEHANDLER(LoadMap)
{
InitGame();
ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface();
const ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface();
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);