diff --git a/source/graphics/MapReader.cpp b/source/graphics/MapReader.cpp index 6c2d2bee76..91b9024e05 100644 --- a/source/graphics/MapReader.cpp +++ b/source/graphics/MapReader.cpp @@ -373,7 +373,7 @@ PSRETURN CMapSummaryReader::LoadMap(const VfsPath& pathname) return PSRETURN_OK; } -void CMapSummaryReader::GetMapSettings(ScriptInterface& scriptInterface, JS::MutableHandleValue ret) +void CMapSummaryReader::GetMapSettings(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) { JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); diff --git a/source/graphics/MapReader.h b/source/graphics/MapReader.h index 99ae8ca7ad..43e5041ed8 100644 --- a/source/graphics/MapReader.h +++ b/source/graphics/MapReader.h @@ -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 @@ -176,7 +176,7 @@ public: * } * @endcode */ - void GetMapSettings(ScriptInterface& scriptInterface, JS::MutableHandleValue); + void GetMapSettings(const ScriptInterface& scriptInterface, JS::MutableHandleValue); private: CStr m_ScriptSettings; diff --git a/source/graphics/scripting/JSInterface_GameView.cpp b/source/graphics/scripting/JSInterface_GameView.cpp index 7225a39562..5db7770917 100644 --- a/source/graphics/scripting/JSInterface_GameView.cpp +++ b/source/graphics/scripting/JSInterface_GameView.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2013 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 @@ -57,7 +57,7 @@ IMPLEMENT_BOOLEAN_SCRIPT_SETTING(ConstrainCamera); scriptInterface.RegisterFunction("GameView_Get" #NAME "Enabled"); \ scriptInterface.RegisterFunction("GameView_Set" #NAME "Enabled"); -void JSI_GameView::RegisterScriptFunctions(ScriptInterface& scriptInterface) +void JSI_GameView::RegisterScriptFunctions(const ScriptInterface& scriptInterface) { REGISTER_BOOLEAN_SCRIPT_SETTING(Culling); REGISTER_BOOLEAN_SCRIPT_SETTING(LockCullCamera); diff --git a/source/graphics/scripting/JSInterface_GameView.h b/source/graphics/scripting/JSInterface_GameView.h index 9d2092b56f..cd5449afcb 100644 --- a/source/graphics/scripting/JSInterface_GameView.h +++ b/source/graphics/scripting/JSInterface_GameView.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2013 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 @@ -28,7 +28,7 @@ namespace JSI_GameView { - void RegisterScriptFunctions(ScriptInterface& ScriptInterface); + void RegisterScriptFunctions(const ScriptInterface& ScriptInterface); DECLARE_BOOLEAN_SCRIPT_SETTING(Culling); DECLARE_BOOLEAN_SCRIPT_SETTING(LockCullCamera); diff --git a/source/gui/scripting/ScriptFunctions.cpp b/source/gui/scripting/ScriptFunctions.cpp index 64cfa3365a..f60b7a12e0 100644 --- a/source/gui/scripting/ScriptFunctions.cpp +++ b/source/gui/scripting/ScriptFunctions.cpp @@ -965,7 +965,7 @@ static TimerUnit js_timer_overhead; static TimerClient js_timer_clients[MAX_JS_TIMERS]; static wchar_t js_timer_descriptions_buf[MAX_JS_TIMERS * 12]; // depends on MAX_JS_TIMERS and format string below -static void InitJsTimers(ScriptInterface& scriptInterface) +static void InitJsTimers(const ScriptInterface& scriptInterface) { wchar_t* pos = js_timer_descriptions_buf; for(size_t i = 0; i < MAX_JS_TIMERS; i++) diff --git a/source/i18n/scripting/JSInterface_L10n.cpp b/source/i18n/scripting/JSInterface_L10n.cpp index 6368f5a7a7..2f3f738908 100644 --- a/source/i18n/scripting/JSInterface_L10n.cpp +++ b/source/i18n/scripting/JSInterface_L10n.cpp @@ -157,7 +157,7 @@ void JSI_L10n::ReevaluateCurrentLocaleAndReload(ScriptInterface::CxPrivate* UNUS } -void JSI_L10n::RegisterScriptFunctions(ScriptInterface& scriptInterface) +void JSI_L10n::RegisterScriptFunctions(const ScriptInterface& scriptInterface) { scriptInterface.RegisterFunction("Translate"); scriptInterface.RegisterFunction("TranslateWithContext"); diff --git a/source/i18n/scripting/JSInterface_L10n.h b/source/i18n/scripting/JSInterface_L10n.h index b7f050a947..f3c97ffb09 100644 --- a/source/i18n/scripting/JSInterface_L10n.h +++ b/source/i18n/scripting/JSInterface_L10n.h @@ -42,7 +42,7 @@ namespace JSI_L10n * * @sa GuiScriptingInit() */ - void RegisterScriptFunctions(ScriptInterface& ScriptInterface); + void RegisterScriptFunctions(const ScriptInterface& ScriptInterface); /** * Returns the translation of the specified string to the diff --git a/source/lib/self_test.h b/source/lib/self_test.h index 705c945162..8b7677de7a 100644 --- a/source/lib/self_test.h +++ b/source/lib/self_test.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 Wildfire Games. +/* Copyright (C) 2017 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -129,7 +129,7 @@ std::vector ts_make_vector(T* start, size_t size_bytes) class ScriptInterface; // Script-based testing setup (defined in test_setup.cpp). Defines TS_* functions. -void ScriptTestSetup(ScriptInterface&); +void ScriptTestSetup(const ScriptInterface&); // Default game data directory // (TODO: game-specific functions like this probably shouldn't be inside lib/, but it's useful diff --git a/source/lobby/IXmppClient.h b/source/lobby/IXmppClient.h index a6edc305ac..cf030e097b 100644 --- a/source/lobby/IXmppClient.h +++ b/source/lobby/IXmppClient.h @@ -36,8 +36,8 @@ public: virtual void recv() = 0; virtual void SendIqGetBoardList() = 0; virtual void SendIqGetProfile(const std::string& player) = 0; - virtual void SendIqGameReport(ScriptInterface& scriptInterface, JS::HandleValue data) = 0; - virtual void SendIqRegisterGame(ScriptInterface& scriptInterface, JS::HandleValue data) = 0; + virtual void SendIqGameReport(const ScriptInterface& scriptInterface, JS::HandleValue data) = 0; + virtual void SendIqRegisterGame(const ScriptInterface& scriptInterface, JS::HandleValue data) = 0; virtual void SendIqUnregisterGame() = 0; virtual void SendIqChangeStateGame(const std::string& nbp, const std::string& players) = 0; virtual void SetNick(const std::string& nick) = 0; @@ -48,14 +48,14 @@ public: virtual void GetPresence(const std::string& nickname, std::string& presence) = 0; virtual void GetRole(const std::string& nickname, std::string& role) = 0; virtual void GetSubject(std::string& subject) = 0; - virtual void GUIGetPlayerList(ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0; + virtual void GUIGetPlayerList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0; virtual void ClearPresenceUpdates() = 0; virtual int GetMucMessageCount() = 0; - virtual void GUIGetGameList(ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0; - virtual void GUIGetBoardList(ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0; - virtual void GUIGetProfile(ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0; + virtual void GUIGetGameList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0; + virtual void GUIGetBoardList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0; + virtual void GUIGetProfile(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0; - virtual void GuiPollMessage(ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0; + virtual void GuiPollMessage(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0; virtual void SendMUCMessage(const std::string& message) = 0; virtual void SendStunEndpointToHost(StunClient::StunEndpoint* stunEndpoint, const std::string& hostJID) = 0; diff --git a/source/lobby/XmppClient.cpp b/source/lobby/XmppClient.cpp index d755a2c4bb..92e989b821 100644 --- a/source/lobby/XmppClient.cpp +++ b/source/lobby/XmppClient.cpp @@ -301,7 +301,7 @@ void XmppClient::SendIqGetProfile(const std::string& player) * * @param data A JS array of game statistics */ -void XmppClient::SendIqGameReport(ScriptInterface& scriptInterface, JS::HandleValue data) +void XmppClient::SendIqGameReport(const ScriptInterface& scriptInterface, JS::HandleValue data) { glooxwrapper::JID xpartamuppJid(m_xpartamuppId); @@ -334,7 +334,7 @@ void XmppClient::SendIqGameReport(ScriptInterface& scriptInterface, JS::HandleVa * * @param data A JS array of game attributes */ -void XmppClient::SendIqRegisterGame(ScriptInterface& scriptInterface, JS::HandleValue data) +void XmppClient::SendIqRegisterGame(const ScriptInterface& scriptInterface, JS::HandleValue data) { glooxwrapper::JID xpartamuppJid(m_xpartamuppId); @@ -453,7 +453,7 @@ void XmppClient::handleOOB(const glooxwrapper::JID&, const glooxwrapper::OOB&) * * @return A JS array containing all known players and their presences */ -void XmppClient::GUIGetPlayerList(ScriptInterface& scriptInterface, JS::MutableHandleValue ret) +void XmppClient::GUIGetPlayerList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) { JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); @@ -478,7 +478,7 @@ void XmppClient::GUIGetPlayerList(ScriptInterface& scriptInterface, JS::MutableH * * @return A JS array containing all known games */ -void XmppClient::GUIGetGameList(ScriptInterface& scriptInterface, JS::MutableHandleValue ret) +void XmppClient::GUIGetGameList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) { JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); @@ -502,7 +502,7 @@ void XmppClient::GUIGetGameList(ScriptInterface& scriptInterface, JS::MutableHan * * @return A JS array containing all known leaderboard data */ -void XmppClient::GUIGetBoardList(ScriptInterface& scriptInterface, JS::MutableHandleValue ret) +void XmppClient::GUIGetBoardList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) { JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); @@ -526,7 +526,7 @@ void XmppClient::GUIGetBoardList(ScriptInterface& scriptInterface, JS::MutableHa * * @return A JS array containing the specific user's profile data */ -void XmppClient::GUIGetProfile(ScriptInterface& scriptInterface, JS::MutableHandleValue ret) +void XmppClient::GUIGetProfile(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) { JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); @@ -552,7 +552,7 @@ void XmppClient::GUIGetProfile(ScriptInterface& scriptInterface, JS::MutableHand /** * Send GUI message queue when queried. */ -void XmppClient::GuiPollMessage(ScriptInterface& scriptInterface, JS::MutableHandleValue ret) +void XmppClient::GuiPollMessage(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) { if (m_GuiMessageQueue.empty()) { diff --git a/source/lobby/XmppClient.h b/source/lobby/XmppClient.h index 285ed177dc..3b61c42052 100644 --- a/source/lobby/XmppClient.h +++ b/source/lobby/XmppClient.h @@ -64,8 +64,8 @@ public: void recv(); void SendIqGetBoardList(); void SendIqGetProfile(const std::string& player); - void SendIqGameReport(ScriptInterface& scriptInterface, JS::HandleValue data); - void SendIqRegisterGame(ScriptInterface& scriptInterface, JS::HandleValue data); + void SendIqGameReport(const ScriptInterface& scriptInterface, JS::HandleValue data); + void SendIqRegisterGame(const ScriptInterface& scriptInterface, JS::HandleValue data); void SendIqUnregisterGame(); void SendIqChangeStateGame(const std::string& nbp, const std::string& players); void SetNick(const std::string& nick); @@ -77,16 +77,13 @@ public: void GetRole(const std::string& nickname, std::string& role); void GetSubject(std::string& subject); - void GUIGetPlayerList(ScriptInterface& scriptInterface, JS::MutableHandleValue ret); - void GUIGetGameList(ScriptInterface& scriptInterface, JS::MutableHandleValue ret); - void GUIGetBoardList(ScriptInterface& scriptInterface, JS::MutableHandleValue ret); - void GUIGetProfile(ScriptInterface& scriptInterface, JS::MutableHandleValue ret); + void GUIGetPlayerList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret); + void GUIGetGameList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret); + void GUIGetBoardList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret); + void GUIGetProfile(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret); void SendStunEndpointToHost(StunClient::StunEndpoint* stunEndpoint, const std::string& hostJID); - //Script - ScriptInterface& GetScriptInterface(); - protected: /* Xmpp handlers */ /* MUC handlers */ @@ -146,7 +143,7 @@ public: std::wstring message; std::time_t time; }; - void GuiPollMessage(ScriptInterface& scriptInterface, JS::MutableHandleValue ret); + void GuiPollMessage(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret); void SendMUCMessage(const std::string& message); void ClearPresenceUpdates(); int GetMucMessageCount(); diff --git a/source/lobby/scripting/JSInterface_Lobby.cpp b/source/lobby/scripting/JSInterface_Lobby.cpp index 689261f267..bfa75efbc2 100644 --- a/source/lobby/scripting/JSInterface_Lobby.cpp +++ b/source/lobby/scripting/JSInterface_Lobby.cpp @@ -27,7 +27,7 @@ #include "third_party/encryption/pkcs5_pbkdf2.h" #include "third_party/encryption/sha.h" -void JSI_Lobby::RegisterScriptFunctions(ScriptInterface& scriptInterface) +void JSI_Lobby::RegisterScriptFunctions(const ScriptInterface& scriptInterface) { // Lobby functions scriptInterface.RegisterFunction("HasXmppClient"); diff --git a/source/lobby/scripting/JSInterface_Lobby.h b/source/lobby/scripting/JSInterface_Lobby.h index 8c684ac94a..388492408e 100644 --- a/source/lobby/scripting/JSInterface_Lobby.h +++ b/source/lobby/scripting/JSInterface_Lobby.h @@ -24,7 +24,7 @@ namespace JSI_Lobby { - void RegisterScriptFunctions(ScriptInterface& scriptInterface); + void RegisterScriptFunctions(const ScriptInterface& scriptInterface); bool HasXmppClient(ScriptInterface::CxPrivate* pCxPrivate); bool IsRankedGame(ScriptInterface::CxPrivate* pCxPrivate); diff --git a/source/network/NetMessage.cpp b/source/network/NetMessage.cpp index f61b725eb9..61126d8e1b 100644 --- a/source/network/NetMessage.cpp +++ b/source/network/NetMessage.cpp @@ -93,7 +93,7 @@ CStr CNetMessage::ToString() const CNetMessage* CNetMessageFactory::CreateMessage(const void* pData, size_t dataSize, - ScriptInterface& scriptInterface) + const ScriptInterface& scriptInterface) { CNetMessage* pNewMessage = NULL; CNetMessage header; diff --git a/source/network/NetMessage.h b/source/network/NetMessage.h index c0b760027d..b4b174c760 100644 --- a/source/network/NetMessage.h +++ b/source/network/NetMessage.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 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 @@ -103,7 +103,7 @@ public: * @param scriptInterface Script instance to use when constructing scripted messages * @return The new message created */ - static CNetMessage* CreateMessage(const void* pData, size_t dataSize, ScriptInterface& scriptInterface); + static CNetMessage* CreateMessage(const void* pData, size_t dataSize, const ScriptInterface& scriptInterface); }; /** @@ -113,8 +113,8 @@ public: class CSimulationMessage : public CNetMessage { public: - CSimulationMessage(ScriptInterface& scriptInterface); - CSimulationMessage(ScriptInterface& scriptInterface, u32 client, i32 player, u32 turn, JS::HandleValue data); + CSimulationMessage(const ScriptInterface& scriptInterface); + CSimulationMessage(const ScriptInterface& scriptInterface, u32 client, i32 player, u32 turn, JS::HandleValue data); /** The compiler can't create a copy constructor because of the PersistentRooted member, * so we have to write it manually. @@ -132,7 +132,7 @@ public: u32 m_Turn; JS::PersistentRooted m_Data; private: - ScriptInterface* m_ScriptInterface; + const ScriptInterface& m_ScriptInterface; }; /** @@ -142,8 +142,8 @@ class CGameSetupMessage : public CNetMessage { NONCOPYABLE(CGameSetupMessage); public: - CGameSetupMessage(ScriptInterface& scriptInterface); - CGameSetupMessage(ScriptInterface& scriptInterface, JS::HandleValue data); + CGameSetupMessage(const ScriptInterface& scriptInterface); + CGameSetupMessage(const ScriptInterface& scriptInterface, JS::HandleValue data); virtual u8* Serialize(u8* pBuffer) const; virtual const u8* Deserialize(const u8* pStart, const u8* pEnd); virtual size_t GetSerializedLength() const; @@ -151,7 +151,7 @@ public: JS::PersistentRootedValue m_Data; private: - ScriptInterface& m_ScriptInterface; + const ScriptInterface& m_ScriptInterface; }; // This time, the classes are created diff --git a/source/network/NetMessageSim.cpp b/source/network/NetMessageSim.cpp index 28b0dfeb33..9ea45678c1 100644 --- a/source/network/NetMessageSim.cpp +++ b/source/network/NetMessageSim.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 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 @@ -59,7 +59,7 @@ public: class CBufferBinarySerializer : public CBinarySerializer { public: - CBufferBinarySerializer(ScriptInterface& scriptInterface, u8* buffer) : + CBufferBinarySerializer(const ScriptInterface& scriptInterface, u8* buffer) : CBinarySerializer(scriptInterface, buffer) { } @@ -98,7 +98,7 @@ public: class CLengthBinarySerializer : public CBinarySerializer { public: - CLengthBinarySerializer(ScriptInterface& scriptInterface) : + CLengthBinarySerializer(const ScriptInterface& scriptInterface) : CBinarySerializer(scriptInterface) { } @@ -109,19 +109,19 @@ public: } }; -CSimulationMessage::CSimulationMessage(ScriptInterface& scriptInterface) : - CNetMessage(NMT_SIMULATION_COMMAND), m_ScriptInterface(&scriptInterface), m_Data(scriptInterface.GetJSRuntime()) +CSimulationMessage::CSimulationMessage(const ScriptInterface& scriptInterface) : + CNetMessage(NMT_SIMULATION_COMMAND), m_ScriptInterface(scriptInterface), m_Data(scriptInterface.GetJSRuntime()) { } -CSimulationMessage::CSimulationMessage(ScriptInterface& scriptInterface, u32 client, i32 player, u32 turn, JS::HandleValue data) : - CNetMessage(NMT_SIMULATION_COMMAND), m_ScriptInterface(&scriptInterface), +CSimulationMessage::CSimulationMessage(const ScriptInterface& scriptInterface, u32 client, i32 player, u32 turn, JS::HandleValue data) : + CNetMessage(NMT_SIMULATION_COMMAND), m_ScriptInterface(scriptInterface), m_Client(client), m_Player(player), m_Turn(turn), m_Data(scriptInterface.GetJSRuntime(), data) { } CSimulationMessage::CSimulationMessage(const CSimulationMessage& orig) : - m_Data(orig.m_ScriptInterface->GetJSRuntime()), + m_Data(orig.m_ScriptInterface.GetJSRuntime()), m_Client(orig.m_Client), m_Player(orig.m_Player), m_ScriptInterface(orig.m_ScriptInterface), @@ -136,7 +136,7 @@ u8* CSimulationMessage::Serialize(u8* pBuffer) const // TODO: ought to handle serialization exceptions // TODO: ought to represent common commands more efficiently u8* pos = CNetMessage::Serialize(pBuffer); - CBufferBinarySerializer serializer(*m_ScriptInterface, pos); + CBufferBinarySerializer serializer(m_ScriptInterface, pos); serializer.NumberU32_Unbounded("client", m_Client); serializer.NumberI32_Unbounded("player", m_Player); serializer.NumberU32_Unbounded("turn", m_Turn); @@ -151,7 +151,7 @@ const u8* CSimulationMessage::Deserialize(const u8* pStart, const u8* pEnd) // TODO: ought to represent common commands more efficiently const u8* pos = CNetMessage::Deserialize(pStart, pEnd); std::istringstream stream(std::string(pos, pEnd)); - CStdDeserializer deserializer(*m_ScriptInterface, stream); + CStdDeserializer deserializer(m_ScriptInterface, stream); deserializer.NumberU32_Unbounded("client", m_Client); deserializer.NumberI32_Unbounded("player", m_Player); deserializer.NumberU32_Unbounded("turn", m_Turn); @@ -163,7 +163,7 @@ size_t CSimulationMessage::GetSerializedLength() const { // TODO: serializing twice is stupidly inefficient - we should just // do it once, store the result, and use it here and in Serialize - CLengthBinarySerializer serializer(*m_ScriptInterface); + CLengthBinarySerializer serializer(m_ScriptInterface); serializer.NumberU32_Unbounded("client", m_Client); serializer.NumberI32_Unbounded("player", m_Player); serializer.NumberU32_Unbounded("turn", m_Turn); @@ -176,7 +176,7 @@ size_t CSimulationMessage::GetSerializedLength() const CStr CSimulationMessage::ToString() const { - std::string source = m_ScriptInterface->ToString(const_cast(&m_Data)); + std::string source = m_ScriptInterface.ToString(const_cast(&m_Data)); std::stringstream stream; stream << "CSimulationMessage { m_Client: " << m_Client << ", m_Player: " << m_Player << ", m_Turn: " << m_Turn << ", m_Data: " << source << " }"; @@ -184,12 +184,12 @@ CStr CSimulationMessage::ToString() const } -CGameSetupMessage::CGameSetupMessage(ScriptInterface& scriptInterface) : +CGameSetupMessage::CGameSetupMessage(const ScriptInterface& scriptInterface) : CNetMessage(NMT_GAME_SETUP), m_ScriptInterface(scriptInterface), m_Data(scriptInterface.GetJSRuntime()) { } -CGameSetupMessage::CGameSetupMessage(ScriptInterface& scriptInterface, JS::HandleValue data) : +CGameSetupMessage::CGameSetupMessage(const ScriptInterface& scriptInterface, JS::HandleValue data) : CNetMessage(NMT_GAME_SETUP), m_ScriptInterface(scriptInterface), m_Data(scriptInterface.GetJSRuntime(), data) { diff --git a/source/network/StunClient.cpp b/source/network/StunClient.cpp index 5fed921724..79c5193479 100644 --- a/source/network/StunClient.cpp +++ b/source/network/StunClient.cpp @@ -360,7 +360,7 @@ bool STUNRequestAndResponse(ENetHost* transactionHost) ParseStunResponse(buffer); } -JS::Value StunClient::FindStunEndpointHost(ScriptInterface& scriptInterface, int port) +JS::Value StunClient::FindStunEndpointHost(const ScriptInterface& scriptInterface, int port) { ENetAddress hostAddr{ENET_HOST_ANY, (u16)port}; ENetHost* transactionHost = enet_host_create(&hostAddr, 1, 1, 0, 0); diff --git a/source/network/StunClient.h b/source/network/StunClient.h index c22424b005..4d08c1314f 100644 --- a/source/network/StunClient.h +++ b/source/network/StunClient.h @@ -33,7 +33,7 @@ struct StunEndpoint { void SendStunRequest(ENetHost* transactionHost, u32 targetIp, u16 targetPort); -JS::Value FindStunEndpointHost(ScriptInterface& scriptInterface, int port); +JS::Value FindStunEndpointHost(const ScriptInterface& scriptInterface, int port); StunEndpoint* FindStunEndpointJoin(ENetHost* transactionHost); diff --git a/source/ps/GameSetup/HWDetect.cpp b/source/ps/GameSetup/HWDetect.cpp index 54435d0f85..ccc523bd7b 100644 --- a/source/ps/GameSetup/HWDetect.cpp +++ b/source/ps/GameSetup/HWDetect.cpp @@ -67,10 +67,10 @@ #endif -static void ReportGLLimits(ScriptInterface& scriptInterface, JS::HandleValue settings); +static void ReportGLLimits(const ScriptInterface& scriptInterface, JS::HandleValue settings); #if ARCH_X86_X64 -void ConvertCaches(ScriptInterface& scriptInterface, x86_x64::IdxCache idxCache, JS::MutableHandleValue ret) +void ConvertCaches(const ScriptInterface& scriptInterface, x86_x64::IdxCache idxCache, JS::MutableHandleValue ret) { JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); @@ -93,7 +93,7 @@ void ConvertCaches(ScriptInterface& scriptInterface, x86_x64::IdxCache idxCache, } } -void ConvertTLBs(ScriptInterface& scriptInterface, JS::MutableHandleValue ret) +void ConvertTLBs(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) { JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); @@ -351,7 +351,7 @@ void RunHardwareDetection() scriptInterface.CallFunctionVoid(global, "RunHardwareDetection", settings); } -static void ReportGLLimits(ScriptInterface& scriptInterface, JS::HandleValue settings) +static void ReportGLLimits(const ScriptInterface& scriptInterface, JS::HandleValue settings) { const char* errstr = "(error)"; diff --git a/source/ps/ProfileViewer.cpp b/source/ps/ProfileViewer.cpp index 4f7ece40c7..24e0088708 100644 --- a/source/ps/ProfileViewer.cpp +++ b/source/ps/ProfileViewer.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 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 @@ -484,9 +484,9 @@ namespace struct DumpTable { - ScriptInterface& m_ScriptInterface; + const ScriptInterface& m_ScriptInterface; JS::PersistentRooted m_Root; - DumpTable(ScriptInterface& scriptInterface, JS::HandleValue root) : + DumpTable(const ScriptInterface& scriptInterface, JS::HandleValue root) : m_ScriptInterface(scriptInterface), m_Root(scriptInterface.GetJSRuntime(), root) { } @@ -600,7 +600,7 @@ void CProfileViewer::SaveToFile() m->outputStream.flush(); } -JS::Value CProfileViewer::SaveToJS(ScriptInterface& scriptInterface) +JS::Value CProfileViewer::SaveToJS(const ScriptInterface& scriptInterface) { JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); diff --git a/source/ps/ProfileViewer.h b/source/ps/ProfileViewer.h index 33331229f3..f64d2c0ace 100644 --- a/source/ps/ProfileViewer.h +++ b/source/ps/ProfileViewer.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2009 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 @@ -191,7 +191,7 @@ public: * SaveToJS: Return a script value containing the current profiler data * (for all profile tables). */ - JS::Value SaveToJS(ScriptInterface& scriptInterface); + JS::Value SaveToJS(const ScriptInterface& scriptInterface); /** * ShowTable: Set the named profile table to be the displayed one. If it diff --git a/source/ps/Replay.cpp b/source/ps/Replay.cpp index dfa9a24f64..e00b388c28 100644 --- a/source/ps/Replay.cpp +++ b/source/ps/Replay.cpp @@ -41,7 +41,7 @@ #include #include -CReplayLogger::CReplayLogger(ScriptInterface& scriptInterface) : +CReplayLogger::CReplayLogger(const ScriptInterface& scriptInterface) : m_ScriptInterface(scriptInterface), m_Stream(NULL) { } diff --git a/source/ps/Replay.h b/source/ps/Replay.h index 4174eda563..036d322ddb 100644 --- a/source/ps/Replay.h +++ b/source/ps/Replay.h @@ -73,7 +73,7 @@ class CReplayLogger : public IReplayLogger { NONCOPYABLE(CReplayLogger); public: - CReplayLogger(ScriptInterface& scriptInterface); + CReplayLogger(const ScriptInterface& scriptInterface); ~CReplayLogger(); virtual void StartGame(JS::MutableHandleValue attribs); @@ -82,7 +82,7 @@ public: virtual OsPath GetDirectory() const; private: - ScriptInterface& m_ScriptInterface; + const ScriptInterface& m_ScriptInterface; std::ostream* m_Stream; OsPath m_Directory; }; diff --git a/source/ps/SavedGame.cpp b/source/ps/SavedGame.cpp index b51728aa41..893c4617f3 100644 --- a/source/ps/SavedGame.cpp +++ b/source/ps/SavedGame.cpp @@ -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 @@ -154,7 +154,7 @@ public: * for the metadata because it would be error prone with rooting and the stack-based rooting * types and confusing (a chain of pointers pointing to other pointers). */ - CGameLoader(ScriptInterface& scriptInterface, std::string* savedState) : + CGameLoader(const ScriptInterface& scriptInterface, std::string* savedState) : m_ScriptInterface(scriptInterface), m_Metadata(scriptInterface.GetJSRuntime()), m_SavedState(savedState) @@ -192,12 +192,12 @@ public: private: - ScriptInterface& m_ScriptInterface; + const ScriptInterface& m_ScriptInterface; JS::PersistentRooted m_Metadata; std::string* m_SavedState; }; -Status SavedGames::Load(const std::wstring& name, ScriptInterface& scriptInterface, JS::MutableHandleValue metadata, std::string& savedState) +Status SavedGames::Load(const std::wstring& name, const ScriptInterface& scriptInterface, JS::MutableHandleValue metadata, std::string& savedState) { // Determine the filename to load const VfsPath basename(L"saves/" + name); @@ -221,7 +221,7 @@ Status SavedGames::Load(const std::wstring& name, ScriptInterface& scriptInterfa return INFO::OK; } -JS::Value SavedGames::GetSavedGames(ScriptInterface& scriptInterface) +JS::Value SavedGames::GetSavedGames(const ScriptInterface& scriptInterface) { TIMER(L"GetSavedGames"); JSContext* cx = scriptInterface.GetContext(); @@ -294,7 +294,7 @@ bool SavedGames::DeleteSavedGame(const std::wstring& name) return true; } -JS::Value SavedGames::GetEngineInfo(ScriptInterface& scriptInterface) +JS::Value SavedGames::GetEngineInfo(const ScriptInterface& scriptInterface) { JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); diff --git a/source/ps/SavedGame.h b/source/ps/SavedGame.h index 0e70c89f65..fcca8c2347 100644 --- a/source/ps/SavedGame.h +++ b/source/ps/SavedGame.h @@ -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 @@ -70,7 +70,7 @@ Status SavePrefix(const CStrW& prefix, const CStrW& description, CSimulation2& s * loaded from simulation.dat inside the archive. * @return INFO::OK if successfully loaded, else an error Status */ -Status Load(const std::wstring& name, ScriptInterface& scriptInterface, JS::MutableHandleValue metadata, std::string& savedState); +Status Load(const std::wstring& name, const ScriptInterface& scriptInterface, JS::MutableHandleValue metadata, std::string& savedState); /** * Get list of saved games for GUI script usage @@ -78,7 +78,7 @@ Status Load(const std::wstring& name, ScriptInterface& scriptInterface, JS::Muta * @param scriptInterface the ScriptInterface in which to create the return data. * @return array of objects containing saved game data */ -JS::Value GetSavedGames(ScriptInterface& scriptInterface); +JS::Value GetSavedGames(const ScriptInterface& scriptInterface); /** * Permanently deletes the saved game archive with the given name @@ -94,7 +94,7 @@ bool DeleteSavedGame(const std::wstring& name); * @param scriptInterface the ScriptInterface in which to create the return data. * @return list of objects containing saved game data */ -JS::Value GetEngineInfo(ScriptInterface& scriptInterface); +JS::Value GetEngineInfo(const ScriptInterface& scriptInterface); } diff --git a/source/ps/VisualReplay.cpp b/source/ps/VisualReplay.cpp index 488efc0116..282eaba5d2 100644 --- a/source/ps/VisualReplay.cpp +++ b/source/ps/VisualReplay.cpp @@ -64,7 +64,7 @@ bool VisualReplay::StartVisualReplay(const OsPath& directory) return g_Game->StartVisualReplay(replayFile); } -bool VisualReplay::ReadCacheFile(ScriptInterface& scriptInterface, JS::MutableHandleObject cachedReplaysObject) +bool VisualReplay::ReadCacheFile(const ScriptInterface& scriptInterface, JS::MutableHandleObject cachedReplaysObject) { JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); @@ -89,7 +89,7 @@ bool VisualReplay::ReadCacheFile(ScriptInterface& scriptInterface, JS::MutableHa return false; } -void VisualReplay::StoreCacheFile(ScriptInterface& scriptInterface, JS::HandleObject replays) +void VisualReplay::StoreCacheFile(const ScriptInterface& scriptInterface, JS::HandleObject replays) { JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx); @@ -104,7 +104,7 @@ void VisualReplay::StoreCacheFile(ScriptInterface& scriptInterface, JS::HandleOb LOGERROR("Could not store the replay cache"); } -JS::HandleObject VisualReplay::ReloadReplayCache(ScriptInterface& scriptInterface, bool compareFiles) +JS::HandleObject VisualReplay::ReloadReplayCache(const ScriptInterface& scriptInterface, bool compareFiles) { TIMER(L"ReloadReplayCache"); JSContext* cx = scriptInterface.GetContext(); @@ -217,7 +217,7 @@ JS::HandleObject VisualReplay::ReloadReplayCache(ScriptInterface& scriptInterfac return replays; } -JS::Value VisualReplay::GetReplays(ScriptInterface& scriptInterface, bool compareFiles) +JS::Value VisualReplay::GetReplays(const ScriptInterface& scriptInterface, bool compareFiles) { TIMER(L"GetReplays"); JSContext* cx = scriptInterface.GetContext(); @@ -320,7 +320,7 @@ inline int getReplayDuration(std::istream* replayStream, const OsPath& fileName, return -1; } -JS::Value VisualReplay::LoadReplayData(ScriptInterface& scriptInterface, const OsPath& directory) +JS::Value VisualReplay::LoadReplayData(const ScriptInterface& scriptInterface, const OsPath& directory) { // The directory argument must not be constant, otherwise concatenating will fail const OsPath replayFile = GetDirectoryName() / directory / L"commands.txt"; @@ -434,7 +434,7 @@ JS::Value VisualReplay::GetReplayAttributes(ScriptInterface::CxPrivate* pCxPriva return attribs; } -void VisualReplay::AddReplayToCache(ScriptInterface& scriptInterface, const CStrW& directoryName) +void VisualReplay::AddReplayToCache(const ScriptInterface& scriptInterface, const CStrW& directoryName) { TIMER(L"AddReplayToCache"); JSContext* cx = scriptInterface.GetContext(); diff --git a/source/ps/VisualReplay.h b/source/ps/VisualReplay.h index 0e3f0a039e..f25ff909c2 100644 --- a/source/ps/VisualReplay.h +++ b/source/ps/VisualReplay.h @@ -48,7 +48,7 @@ bool StartVisualReplay(const OsPath& directory); * @param cachedReplaysObject - the cached replays. * @return true on succes */ -bool ReadCacheFile(ScriptInterface& scriptInterface, JS::MutableHandleObject cachedReplaysObject); +bool ReadCacheFile(const ScriptInterface& scriptInterface, JS::MutableHandleObject cachedReplaysObject); /** * Stores the replay list in the replay cache file @@ -56,7 +56,7 @@ bool ReadCacheFile(ScriptInterface& scriptInterface, JS::MutableHandleObject cac * @param scriptInterface - the ScriptInterface in which to create the return data. * @param replays - the replay list to store. */ -void StoreCacheFile(ScriptInterface& scriptInterface, JS::HandleObject replays); +void StoreCacheFile(const ScriptInterface& scriptInterface, JS::HandleObject replays); /** * Load the replay cache and check if there are new/deleted replays. If so, update the cache. @@ -65,7 +65,7 @@ void StoreCacheFile(ScriptInterface& scriptInterface, JS::HandleObject replays); * @param compareFiles - compare the directory name and the FileSize of the replays and the cache. * @return cache entries */ -JS::HandleObject ReloadReplayCache(ScriptInterface& scriptInterface, bool compareFiles); +JS::HandleObject ReloadReplayCache(const ScriptInterface& scriptInterface, bool compareFiles); /** * Get a list of replays to display in the GUI. @@ -75,13 +75,13 @@ JS::HandleObject ReloadReplayCache(ScriptInterface& scriptInterface, bool compar * but nearly ensures, that no changed replay is missed. * @return array of objects containing replay data */ -JS::Value GetReplays(ScriptInterface& scriptInterface, bool compareFiles); +JS::Value GetReplays(const ScriptInterface& scriptInterface, bool compareFiles); /** * Parses a commands.txt file and extracts metadata. * Works similarly to CGame::LoadReplayData(). */ -JS::Value LoadReplayData(ScriptInterface& scriptInterface, const OsPath& directory); +JS::Value LoadReplayData(const ScriptInterface& scriptInterface, const OsPath& directory); /** * Permanently deletes the visual replay (including the parent directory) @@ -114,7 +114,7 @@ void SaveReplayMetadata(ScriptInterface* scriptInterface); /** * Adds a replay to the replayCache. */ -void AddReplayToCache(ScriptInterface& scriptInterface, const CStrW& directoryName); +void AddReplayToCache(const ScriptInterface& scriptInterface, const CStrW& directoryName); } #endif diff --git a/source/ps/scripting/JSInterface_ConfigDB.cpp b/source/ps/scripting/JSInterface_ConfigDB.cpp index 0119358efe..0904caa1fa 100644 --- a/source/ps/scripting/JSInterface_ConfigDB.cpp +++ b/source/ps/scripting/JSInterface_ConfigDB.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2014 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 @@ -133,7 +133,7 @@ bool JSI_ConfigDB::SetFile(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const return true; } -void JSI_ConfigDB::RegisterScriptFunctions(ScriptInterface& scriptInterface) +void JSI_ConfigDB::RegisterScriptFunctions(const ScriptInterface& scriptInterface) { scriptInterface.RegisterFunction("ConfigDB_HasChanges"); scriptInterface.RegisterFunction("ConfigDB_SetChanges"); diff --git a/source/ps/scripting/JSInterface_ConfigDB.h b/source/ps/scripting/JSInterface_ConfigDB.h index 66f21909f0..62926a0fb0 100644 --- a/source/ps/scripting/JSInterface_ConfigDB.h +++ b/source/ps/scripting/JSInterface_ConfigDB.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2013 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 @@ -33,7 +33,7 @@ namespace JSI_ConfigDB bool WriteValueToFile(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& cfgNsString, const std::string& name, const std::string& value, const Path& path); bool Reload(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& cfgNsString); bool SetFile(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& cfgNsString, const Path& path); - void RegisterScriptFunctions(ScriptInterface& scriptInterface); + void RegisterScriptFunctions(const ScriptInterface& scriptInterface); } #endif diff --git a/source/ps/scripting/JSInterface_Console.cpp b/source/ps/scripting/JSInterface_Console.cpp index c2548edbb0..c9992ea65d 100644 --- a/source/ps/scripting/JSInterface_Console.cpp +++ b/source/ps/scripting/JSInterface_Console.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2014 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 @@ -47,7 +47,7 @@ void JSI_Console::SetVisibleEnabled(ScriptInterface::CxPrivate* UNUSED(pCxPrivat g_Console->SetVisible(Enabled); } -void JSI_Console::RegisterScriptFunctions(ScriptInterface& scriptInterface) +void JSI_Console::RegisterScriptFunctions(const ScriptInterface& scriptInterface) { scriptInterface.RegisterFunction("Console_GetVisibleEnabled"); scriptInterface.RegisterFunction("Console_SetVisibleEnabled"); diff --git a/source/ps/scripting/JSInterface_Console.h b/source/ps/scripting/JSInterface_Console.h index f13b3d7209..369484c2e5 100644 --- a/source/ps/scripting/JSInterface_Console.h +++ b/source/ps/scripting/JSInterface_Console.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2014 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 @@ -26,7 +26,7 @@ namespace JSI_Console bool GetVisibleEnabled(ScriptInterface::CxPrivate* pCxPrivate); void SetVisibleEnabled(ScriptInterface::CxPrivate* pCxPrivate, bool Enabled); - void RegisterScriptFunctions(ScriptInterface& scriptInterface); + void RegisterScriptFunctions(const ScriptInterface& scriptInterface); } #endif diff --git a/source/ps/scripting/JSInterface_Mod.cpp b/source/ps/scripting/JSInterface_Mod.cpp index 874b85b6f5..31d28e054e 100644 --- a/source/ps/scripting/JSInterface_Mod.cpp +++ b/source/ps/scripting/JSInterface_Mod.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 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 @@ -123,7 +123,7 @@ void JSI_Mod::SetMods(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std: g_modsLoaded = mods; } -void JSI_Mod::RegisterScriptFunctions(ScriptInterface& scriptInterface) +void JSI_Mod::RegisterScriptFunctions(const ScriptInterface& scriptInterface) { scriptInterface.RegisterFunction("GetAvailableMods"); scriptInterface.RegisterFunction("RestartEngine"); diff --git a/source/ps/scripting/JSInterface_Mod.h b/source/ps/scripting/JSInterface_Mod.h index 51d7bf3cd6..0930070565 100644 --- a/source/ps/scripting/JSInterface_Mod.h +++ b/source/ps/scripting/JSInterface_Mod.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2014 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 @@ -22,7 +22,7 @@ class ScriptInterface; namespace JSI_Mod { - void RegisterScriptFunctions(ScriptInterface& scriptInterface); + void RegisterScriptFunctions(const ScriptInterface& scriptInterface); JS::Value GetAvailableMods(ScriptInterface::CxPrivate* pCxPrivate); void RestartEngine(ScriptInterface::CxPrivate* pCxPrivate); void SetMods(ScriptInterface::CxPrivate* pCxPrivate, const std::vector& mods); diff --git a/source/ps/scripting/JSInterface_VisualReplay.cpp b/source/ps/scripting/JSInterface_VisualReplay.cpp index 2f1554787b..e599beab33 100644 --- a/source/ps/scripting/JSInterface_VisualReplay.cpp +++ b/source/ps/scripting/JSInterface_VisualReplay.cpp @@ -63,7 +63,7 @@ CStrW JSI_VisualReplay::GetReplayDirectoryName(ScriptInterface::CxPrivate* UNUSE return wstring_from_utf8(OsPath(VisualReplay::GetDirectoryName() / directoryName).string8()); } -void JSI_VisualReplay::RegisterScriptFunctions(ScriptInterface& scriptInterface) +void JSI_VisualReplay::RegisterScriptFunctions(const ScriptInterface& scriptInterface) { scriptInterface.RegisterFunction("GetReplays"); scriptInterface.RegisterFunction("DeleteReplay"); diff --git a/source/ps/scripting/JSInterface_VisualReplay.h b/source/ps/scripting/JSInterface_VisualReplay.h index 294e8bcbe6..b90a57fafb 100644 --- a/source/ps/scripting/JSInterface_VisualReplay.h +++ b/source/ps/scripting/JSInterface_VisualReplay.h @@ -30,7 +30,7 @@ namespace JSI_VisualReplay bool HasReplayMetadata(ScriptInterface::CxPrivate* pCxPrivate, const CStrW& directoryName); JS::Value GetReplayMetadata(ScriptInterface::CxPrivate* pCxPrivate, const CStrW& directoryName); void AddReplayToCache(ScriptInterface::CxPrivate* pCxPrivate, const CStrW& directoryName); - void RegisterScriptFunctions(ScriptInterface& scriptInterface); + void RegisterScriptFunctions(const ScriptInterface& scriptInterface); CStrW GetReplayDirectoryName(ScriptInterface::CxPrivate* pCxPrivate, const CStrW& directoryName); } diff --git a/source/renderer/scripting/JSInterface_Renderer.cpp b/source/renderer/scripting/JSInterface_Renderer.cpp index 447b1e7ac1..ff23de4539 100644 --- a/source/renderer/scripting/JSInterface_Renderer.cpp +++ b/source/renderer/scripting/JSInterface_Renderer.cpp @@ -71,7 +71,7 @@ void JSI_Renderer::RecreateShadowMap(ScriptInterface::CxPrivate* UNUSED(pCxPriva scriptInterface.RegisterFunction("Renderer_Get" #NAME "Enabled"); \ scriptInterface.RegisterFunction("Renderer_Set" #NAME "Enabled"); -void JSI_Renderer::RegisterScriptFunctions(ScriptInterface& scriptInterface) +void JSI_Renderer::RegisterScriptFunctions(const ScriptInterface& scriptInterface) { scriptInterface.RegisterFunction("Renderer_GetRenderPath"); scriptInterface.RegisterFunction("Renderer_SetRenderPath"); diff --git a/source/renderer/scripting/JSInterface_Renderer.h b/source/renderer/scripting/JSInterface_Renderer.h index 3c33f90ef2..aac4d79773 100644 --- a/source/renderer/scripting/JSInterface_Renderer.h +++ b/source/renderer/scripting/JSInterface_Renderer.h @@ -47,7 +47,7 @@ namespace JSI_Renderer DECLARE_BOOLEAN_SCRIPT_SETTING(Postproc); DECLARE_BOOLEAN_SCRIPT_SETTING(DisplayFrustum); - void RegisterScriptFunctions(ScriptInterface& scriptInterface); + void RegisterScriptFunctions(const ScriptInterface& scriptInterface); } #undef DECLARE_BOOLEAN_SCRIPT_SETTING diff --git a/source/scriptinterface/NativeWrapperDecls.h b/source/scriptinterface/NativeWrapperDecls.h index f1b1c46b64..4b06eb32a1 100644 --- a/source/scriptinterface/NativeWrapperDecls.h +++ b/source/scriptinterface/NativeWrapperDecls.h @@ -59,7 +59,8 @@ template struct MaybeRef; // Define RegisterFunction #define OVERLOADS(z, i, data) \ template \ - void RegisterFunction(const char* name) { \ + void RegisterFunction(const char* name) const \ + { \ Register(name, call, nargs()); \ } BOOST_PP_REPEAT(SCRIPT_INTERFACE_MAX_ARGS, OVERLOADS, ~) diff --git a/source/scriptinterface/ScriptInterface.cpp b/source/scriptinterface/ScriptInterface.cpp index d835c9efcf..f035701d02 100644 --- a/source/scriptinterface/ScriptInterface.cpp +++ b/source/scriptinterface/ScriptInterface.cpp @@ -56,7 +56,7 @@ struct ScriptInterface_impl { ScriptInterface_impl(const char* nativeScopeName, const shared_ptr& runtime); ~ScriptInterface_impl(); - void Register(const char* name, JSNative fptr, uint nargs); + void Register(const char* name, JSNative fptr, uint nargs) const; // Take care to keep this declaration before heap rooted members. Destructors of heap rooted // members have to be called before the runtime destructor. @@ -393,7 +393,7 @@ ScriptInterface_impl::~ScriptInterface_impl() JS_DestroyContext(m_cx); } -void ScriptInterface_impl::Register(const char* name, JSNative fptr, uint nargs) +void ScriptInterface_impl::Register(const char* name, JSNative fptr, uint nargs) const { JSAutoRequest rq(m_cx); JS::RootedObject nativeScope(m_cx, m_nativeScope); @@ -489,7 +489,7 @@ bool ScriptInterface::ReplaceNondeterministicRNG(boost::rand48& rng) return false; } -void ScriptInterface::Register(const char* name, JSNative fptr, size_t nargs) +void ScriptInterface::Register(const char* name, JSNative fptr, size_t nargs) const { m->Register(name, fptr, (uint)nargs); } @@ -612,7 +612,7 @@ bool ScriptInterface::SetGlobal_(const char* name, JS::HandleValue value, bool r return ok; } -bool ScriptInterface::SetProperty_(JS::HandleValue obj, const char* name, JS::HandleValue value, bool constant, bool enumerate) +bool ScriptInterface::SetProperty_(JS::HandleValue obj, const char* name, JS::HandleValue value, bool constant, bool enumerate) const { JSAutoRequest rq(m->m_cx); uint attrs = 0; @@ -630,7 +630,7 @@ bool ScriptInterface::SetProperty_(JS::HandleValue obj, const char* name, JS::Ha return true; } -bool ScriptInterface::SetProperty_(JS::HandleValue obj, const wchar_t* name, JS::HandleValue value, bool constant, bool enumerate) +bool ScriptInterface::SetProperty_(JS::HandleValue obj, const wchar_t* name, JS::HandleValue value, bool constant, bool enumerate) const { JSAutoRequest rq(m->m_cx); uint attrs = 0; @@ -649,7 +649,7 @@ bool ScriptInterface::SetProperty_(JS::HandleValue obj, const wchar_t* name, JS: return true; } -bool ScriptInterface::SetPropertyInt_(JS::HandleValue obj, int name, JS::HandleValue value, bool constant, bool enumerate) +bool ScriptInterface::SetPropertyInt_(JS::HandleValue obj, int name, JS::HandleValue value, bool constant, bool enumerate) const { JSAutoRequest rq(m->m_cx); uint attrs = 0; @@ -1103,7 +1103,7 @@ void ScriptInterface::ForceGC() JS_GC(this->GetJSRuntime()); } -JS::Value ScriptInterface::CloneValueFromOtherContext(ScriptInterface& otherContext, JS::HandleValue val) +JS::Value ScriptInterface::CloneValueFromOtherContext(const ScriptInterface& otherContext, JS::HandleValue val) const { PROFILE("CloneValueFromOtherContext"); JSAutoRequest rq(m->m_cx); @@ -1124,7 +1124,7 @@ ScriptInterface::StructuredClone::~StructuredClone() JS_ClearStructuredClone(m_Data, m_Size, NULL, NULL); } -shared_ptr ScriptInterface::WriteStructuredClone(JS::HandleValue v) +shared_ptr ScriptInterface::WriteStructuredClone(JS::HandleValue v) const { JSAutoRequest rq(m->m_cx); u64* data = NULL; @@ -1141,7 +1141,7 @@ shared_ptr ScriptInterface::WriteStructuredClo return ret; } -void ScriptInterface::ReadStructuredClone(const shared_ptr& ptr, JS::MutableHandleValue ret) +void ScriptInterface::ReadStructuredClone(const shared_ptr& ptr, JS::MutableHandleValue ret) const { JSAutoRequest rq(m->m_cx); JS_ReadStructuredClone(m->m_cx, ptr->m_Data, ptr->m_Size, JS_STRUCTURED_CLONE_VERSION, ret, NULL, NULL); diff --git a/source/scriptinterface/ScriptInterface.h b/source/scriptinterface/ScriptInterface.h index eeb055c75d..917a31e479 100644 --- a/source/scriptinterface/ScriptInterface.h +++ b/source/scriptinterface/ScriptInterface.h @@ -151,21 +151,21 @@ public: * Optionally makes it {ReadOnly, DontDelete, DontEnum}. */ template - bool SetProperty(JS::HandleValue obj, const char* name, const T& value, bool constant = false, bool enumerate = true); + bool SetProperty(JS::HandleValue obj, const char* name, const T& value, bool constant = false, bool enumerate = true) const; /** * Set the named property on the given object. * Optionally makes it {ReadOnly, DontDelete, DontEnum}. */ template - bool SetProperty(JS::HandleValue obj, const wchar_t* name, const T& value, bool constant = false, bool enumerate = true); + bool SetProperty(JS::HandleValue obj, const wchar_t* name, const T& value, bool constant = false, bool enumerate = true) const; /** * Set the integer-named property on the given object. * Optionally makes it {ReadOnly, DontDelete, DontEnum}. */ template - bool SetPropertyInt(JS::HandleValue obj, int name, const T& value, bool constant = false, bool enumerate = true); + bool SetPropertyInt(JS::HandleValue obj, int name, const T& value, bool constant = false, bool enumerate = true) const; /** * Get the named property on the given object. @@ -266,7 +266,7 @@ public: * Complex values (functions, XML, etc) won't be cloned correctly, but basic * types and cyclic references should be fine. */ - JS::Value CloneValueFromOtherContext(ScriptInterface& otherContext, JS::HandleValue val); + JS::Value CloneValueFromOtherContext(const ScriptInterface& otherContext, JS::HandleValue val) const; /** * Convert a jsval to a C++ type. (This might trigger GC.) @@ -319,8 +319,8 @@ public: size_t m_Size; }; - shared_ptr WriteStructuredClone(JS::HandleValue v); - void ReadStructuredClone(const shared_ptr& ptr, JS::MutableHandleValue ret); + shared_ptr WriteStructuredClone(JS::HandleValue v) const; + void ReadStructuredClone(const shared_ptr& ptr, JS::MutableHandleValue ret) const; /** * Converts |a| if needed and assigns it to |handle|. @@ -360,9 +360,9 @@ private: bool Eval_(const char* code, JS::MutableHandleValue ret) const; bool Eval_(const wchar_t* code, JS::MutableHandleValue ret) const; bool SetGlobal_(const char* name, JS::HandleValue value, bool replace); - bool SetProperty_(JS::HandleValue obj, const char* name, JS::HandleValue value, bool readonly, bool enumerate); - bool SetProperty_(JS::HandleValue obj, const wchar_t* name, JS::HandleValue value, bool readonly, bool enumerate); - bool SetPropertyInt_(JS::HandleValue obj, int name, JS::HandleValue value, bool readonly, bool enumerate); + bool SetProperty_(JS::HandleValue obj, const char* name, JS::HandleValue value, bool readonly, bool enumerate) const; + bool SetProperty_(JS::HandleValue obj, const wchar_t* name, JS::HandleValue value, bool readonly, bool enumerate) const; + bool SetPropertyInt_(JS::HandleValue obj, int name, JS::HandleValue value, bool readonly, bool enumerate) const; bool GetProperty_(JS::HandleValue obj, const char* name, JS::MutableHandleValue out) const; bool GetPropertyInt_(JS::HandleValue obj, int name, JS::MutableHandleValue value) const; static bool IsExceptionPending(JSContext* cx); @@ -394,7 +394,7 @@ private: JSClass* m_Class; JSNative m_Constructor; }; - void Register(const char* name, JSNative fptr, size_t nargs); + void Register(const char* name, JSNative fptr, size_t nargs) const; // Take care to keep this declaration before heap rooted members. Destructors of heap rooted // members have to be called before the runtime destructor. @@ -409,7 +409,7 @@ public: // This declares: // // template - // void RegisterFunction(const char* functionName); + // void RegisterFunction(const char* functionName) const; // // template // static JSNative call; @@ -494,7 +494,7 @@ bool ScriptInterface::SetGlobal(const char* name, const T& value, bool replace) } template -bool ScriptInterface::SetProperty(JS::HandleValue obj, const char* name, const T& value, bool readonly, bool enumerate) +bool ScriptInterface::SetProperty(JS::HandleValue obj, const char* name, const T& value, bool readonly, bool enumerate) const { JSAutoRequest rq(GetContext()); JS::RootedValue val(GetContext()); @@ -503,7 +503,7 @@ bool ScriptInterface::SetProperty(JS::HandleValue obj, const char* name, const T } template -bool ScriptInterface::SetProperty(JS::HandleValue obj, const wchar_t* name, const T& value, bool readonly, bool enumerate) +bool ScriptInterface::SetProperty(JS::HandleValue obj, const wchar_t* name, const T& value, bool readonly, bool enumerate) const { JSAutoRequest rq(GetContext()); JS::RootedValue val(GetContext()); @@ -512,7 +512,7 @@ bool ScriptInterface::SetProperty(JS::HandleValue obj, const wchar_t* name, cons } template -bool ScriptInterface::SetPropertyInt(JS::HandleValue obj, int name, const T& value, bool readonly, bool enumerate) +bool ScriptInterface::SetPropertyInt(JS::HandleValue obj, int name, const T& value, bool readonly, bool enumerate) const { JSAutoRequest rq(GetContext()); JS::RootedValue val(GetContext()); diff --git a/source/scriptinterface/tests/test_ScriptInterface.h b/source/scriptinterface/tests/test_ScriptInterface.h index 72262281a1..cab0c1ed2c 100644 --- a/source/scriptinterface/tests/test_ScriptInterface.h +++ b/source/scriptinterface/tests/test_ScriptInterface.h @@ -188,7 +188,7 @@ public: handle_templates_test(script, val, &out, nbrVal); } - void handle_templates_test(ScriptInterface& script, JS::HandleValue val, JS::MutableHandleValue out, JS::HandleValue nbrVal) + void handle_templates_test(const ScriptInterface& script, JS::HandleValue val, JS::MutableHandleValue out, JS::HandleValue nbrVal) { int nbr = 0; diff --git a/source/simulation2/MessageTypes.h b/source/simulation2/MessageTypes.h index a99d625353..32179116df 100644 --- a/source/simulation2/MessageTypes.h +++ b/source/simulation2/MessageTypes.h @@ -35,8 +35,8 @@ virtual int GetType() const { return MT_##name; } \ virtual const char* GetScriptHandlerName() const { return "On" #name; } \ virtual const char* GetScriptGlobalHandlerName() const { return "OnGlobal" #name; } \ - virtual JS::Value ToJSVal(ScriptInterface& scriptInterface) const; \ - static CMessage* FromJSVal(ScriptInterface&, JS::HandleValue val); + virtual JS::Value ToJSVal(const ScriptInterface& scriptInterface) const; \ + static CMessage* FromJSVal(const ScriptInterface&, JS::HandleValue val); class SceneCollector; class CFrustum; diff --git a/source/simulation2/Simulation2.cpp b/source/simulation2/Simulation2.cpp index a52a4c8ce6..3a24887427 100644 --- a/source/simulation2/Simulation2.cpp +++ b/source/simulation2/Simulation2.cpp @@ -161,7 +161,7 @@ public: SerializationTestState* primaryStateBefore, SerializationTestState* primaryStateAfter, SerializationTestState* secondaryStateBefore, SerializationTestState* secondaryStateAfter); - static std::vector CloneCommandsFromOtherContext(ScriptInterface& oldScript, ScriptInterface& newScript, + static std::vector CloneCommandsFromOtherContext(const ScriptInterface& oldScript, const ScriptInterface& newScript, const std::vector& commands) { JSContext* cxOld = oldScript.GetContext(); diff --git a/source/simulation2/components/ICmpAIManager.cpp b/source/simulation2/components/ICmpAIManager.cpp index 316618f32c..b41f0c310c 100644 --- a/source/simulation2/components/ICmpAIManager.cpp +++ b/source/simulation2/components/ICmpAIManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 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 @@ -38,7 +38,7 @@ struct GetAIsHelper { NONCOPYABLE(GetAIsHelper); public: - GetAIsHelper(ScriptInterface& scriptInterface) : + GetAIsHelper(const ScriptInterface& scriptInterface) : m_ScriptInterface(scriptInterface), m_AIs(scriptInterface.GetJSRuntime()) { @@ -78,10 +78,10 @@ public: } JS::PersistentRootedObject m_AIs; - ScriptInterface& m_ScriptInterface; + const ScriptInterface& m_ScriptInterface; }; -JS::Value ICmpAIManager::GetAIs(ScriptInterface& scriptInterface) +JS::Value ICmpAIManager::GetAIs(const ScriptInterface& scriptInterface) { GetAIsHelper helper(scriptInterface); helper.Run(); diff --git a/source/simulation2/components/ICmpAIManager.h b/source/simulation2/components/ICmpAIManager.h index 97d46f7a9c..3d09cd4872 100644 --- a/source/simulation2/components/ICmpAIManager.h +++ b/source/simulation2/components/ICmpAIManager.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 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 @@ -51,7 +51,7 @@ public: * Returns a vector of {"id":"value-for-AddPlayer", "name":"Human readable name"} * objects, based on all the available AI scripts. */ - static JS::Value GetAIs(ScriptInterface& scriptInterface); + static JS::Value GetAIs(const ScriptInterface& scriptInterface); DECLARE_INTERFACE_TYPE(AIManager) }; diff --git a/source/simulation2/components/tests/test_scripts.h b/source/simulation2/components/tests/test_scripts.h index 5cf8c2a200..319a91b832 100644 --- a/source/simulation2/components/tests/test_scripts.h +++ b/source/simulation2/components/tests/test_scripts.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 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 @@ -36,7 +36,7 @@ public: g_VFS.reset(); } - static void load_script(ScriptInterface& scriptInterface, const VfsPath& pathname) + static void load_script(const ScriptInterface& scriptInterface, const VfsPath& pathname) { CVFSFile file; TS_ASSERT_EQUALS(file.Load(g_VFS, pathname), PSRETURN_OK); diff --git a/source/simulation2/docs/SimulationDocs.h b/source/simulation2/docs/SimulationDocs.h index 870db6c395..b13d294eec 100644 --- a/source/simulation2/docs/SimulationDocs.h +++ b/source/simulation2/docs/SimulationDocs.h @@ -505,7 +505,7 @@ But for now everything is put in there.) Now you have to add C++/JS conversions into MessageTypeConversions.cpp, so scripts can send and receive messages: @code -JS::Value CMessageExample::ToJSVal(ScriptInterface& scriptInterface) const +JS::Value CMessageExample::ToJSVal(const ScriptInterface& scriptInterface) const { TOJSVAL_SETUP(); SET_MSG_PROPERTY(x); @@ -513,7 +513,7 @@ JS::Value CMessageExample::ToJSVal(ScriptInterface& scriptInterface) const return JS::ObjectValue(*obj); } -CMessage* CMessageExample::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val) +CMessage* CMessageExample::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val) { FROMJSVAL_SETUP(); GET_MSG_PROPERTY(int, x); @@ -528,12 +528,12 @@ with a set of scalar fields.) If you don't want to support scripts sending/receiving the message, you can implement stub functions instead: @code -JS::Value CMessageExample::ToJSVal(ScriptInterface& UNUSED(scriptInterface)) const +JS::Value CMessageExample::ToJSVal(const ScriptInterface& UNUSED(scriptInterface)) const { return JS::UndefinedValue(); } -CMessage* CMessageExample::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val)) +CMessage* CMessageExample::FromJSVal(const ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val)) { return NULL; } diff --git a/source/simulation2/scripting/MessageTypeConversions.cpp b/source/simulation2/scripting/MessageTypeConversions.cpp index 74eb7a06d1..095a29e65c 100644 --- a/source/simulation2/scripting/MessageTypeConversions.cpp +++ b/source/simulation2/scripting/MessageTypeConversions.cpp @@ -52,7 +52,7 @@ return NULL; \ } -JS::Value CMessage::ToJSValCached(ScriptInterface& scriptInterface) const +JS::Value CMessage::ToJSValCached(const ScriptInterface& scriptInterface) const { if (!m_Cached) m_Cached.reset(new JS::PersistentRootedValue(scriptInterface.GetJSRuntime(), ToJSVal(scriptInterface))); @@ -62,13 +62,13 @@ JS::Value CMessage::ToJSValCached(ScriptInterface& scriptInterface) const //////////////////////////////// -JS::Value CMessageTurnStart::ToJSVal(ScriptInterface& scriptInterface) const +JS::Value CMessageTurnStart::ToJSVal(const ScriptInterface& scriptInterface) const { TOJSVAL_SETUP(); return JS::ObjectValue(*obj); } -CMessage* CMessageTurnStart::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val)) +CMessage* CMessageTurnStart::FromJSVal(const ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val)) { return new CMessageTurnStart(); } @@ -76,13 +76,13 @@ CMessage* CMessageTurnStart::FromJSVal(ScriptInterface& UNUSED(scriptInterface), //////////////////////////////// #define MESSAGE_1(name, t0, a0) \ - JS::Value CMessage##name::ToJSVal(ScriptInterface& scriptInterface) const \ + JS::Value CMessage##name::ToJSVal(const ScriptInterface& scriptInterface) const \ { \ TOJSVAL_SETUP(); \ SET_MSG_PROPERTY(a0); \ return JS::ObjectValue(*obj); \ } \ - CMessage* CMessage##name::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val) \ + CMessage* CMessage##name::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val) \ { \ FROMJSVAL_SETUP(); \ GET_MSG_PROPERTY(t0, a0); \ @@ -96,7 +96,7 @@ MESSAGE_1(Update_Final, fixed, turnLength) //////////////////////////////// -JS::Value CMessageInterpolate::ToJSVal(ScriptInterface& scriptInterface) const +JS::Value CMessageInterpolate::ToJSVal(const ScriptInterface& scriptInterface) const { TOJSVAL_SETUP(); SET_MSG_PROPERTY(deltaSimTime); @@ -105,7 +105,7 @@ JS::Value CMessageInterpolate::ToJSVal(ScriptInterface& scriptInterface) const return JS::ObjectValue(*obj); } -CMessage* CMessageInterpolate::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val) +CMessage* CMessageInterpolate::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val) { FROMJSVAL_SETUP(); GET_MSG_PROPERTY(float, deltaSimTime); @@ -116,13 +116,13 @@ CMessage* CMessageInterpolate::FromJSVal(ScriptInterface& scriptInterface, JS::H //////////////////////////////// -JS::Value CMessageRenderSubmit::ToJSVal(ScriptInterface& UNUSED(scriptInterface)) const +JS::Value CMessageRenderSubmit::ToJSVal(const ScriptInterface& UNUSED(scriptInterface)) const { LOGWARNING("CMessageRenderSubmit::ToJSVal not implemented"); return JS::UndefinedValue(); } -CMessage* CMessageRenderSubmit::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val)) +CMessage* CMessageRenderSubmit::FromJSVal(const ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val)) { LOGWARNING("CMessageRenderSubmit::FromJSVal not implemented"); return NULL; @@ -130,13 +130,13 @@ CMessage* CMessageRenderSubmit::FromJSVal(ScriptInterface& UNUSED(scriptInterfac //////////////////////////////// -JS::Value CMessageProgressiveLoad::ToJSVal(ScriptInterface& UNUSED(scriptInterface)) const +JS::Value CMessageProgressiveLoad::ToJSVal(const ScriptInterface& UNUSED(scriptInterface)) const { LOGWARNING("CMessageProgressiveLoad::ToJSVal not implemented"); return JS::UndefinedValue(); } -CMessage* CMessageProgressiveLoad::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val)) +CMessage* CMessageProgressiveLoad::FromJSVal(const ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val)) { LOGWARNING("CMessageProgressiveLoad::FromJSVal not implemented"); return NULL; @@ -144,13 +144,13 @@ CMessage* CMessageProgressiveLoad::FromJSVal(ScriptInterface& UNUSED(scriptInter //////////////////////////////// -JS::Value CMessageDeserialized::ToJSVal(ScriptInterface& scriptInterface) const +JS::Value CMessageDeserialized::ToJSVal(const ScriptInterface& scriptInterface) const { TOJSVAL_SETUP(); return JS::ObjectValue(*obj); } -CMessage* CMessageDeserialized::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val) +CMessage* CMessageDeserialized::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val) { FROMJSVAL_SETUP(); return new CMessageDeserialized(); @@ -158,14 +158,14 @@ CMessage* CMessageDeserialized::FromJSVal(ScriptInterface& scriptInterface, JS:: //////////////////////////////// -JS::Value CMessageCreate::ToJSVal(ScriptInterface& scriptInterface) const +JS::Value CMessageCreate::ToJSVal(const ScriptInterface& scriptInterface) const { TOJSVAL_SETUP(); SET_MSG_PROPERTY(entity); return JS::ObjectValue(*obj); } -CMessage* CMessageCreate::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val) +CMessage* CMessageCreate::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val) { FROMJSVAL_SETUP(); GET_MSG_PROPERTY(entity_id_t, entity); @@ -174,14 +174,14 @@ CMessage* CMessageCreate::FromJSVal(ScriptInterface& scriptInterface, JS::Handle //////////////////////////////// -JS::Value CMessageDestroy::ToJSVal(ScriptInterface& scriptInterface) const +JS::Value CMessageDestroy::ToJSVal(const ScriptInterface& scriptInterface) const { TOJSVAL_SETUP(); SET_MSG_PROPERTY(entity); return JS::ObjectValue(*obj); } -CMessage* CMessageDestroy::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val) +CMessage* CMessageDestroy::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val) { FROMJSVAL_SETUP(); GET_MSG_PROPERTY(entity_id_t, entity); @@ -190,7 +190,7 @@ CMessage* CMessageDestroy::FromJSVal(ScriptInterface& scriptInterface, JS::Handl //////////////////////////////// -JS::Value CMessageOwnershipChanged::ToJSVal(ScriptInterface& scriptInterface) const +JS::Value CMessageOwnershipChanged::ToJSVal(const ScriptInterface& scriptInterface) const { TOJSVAL_SETUP(); SET_MSG_PROPERTY(entity); @@ -199,7 +199,7 @@ JS::Value CMessageOwnershipChanged::ToJSVal(ScriptInterface& scriptInterface) co return JS::ObjectValue(*obj); } -CMessage* CMessageOwnershipChanged::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val) +CMessage* CMessageOwnershipChanged::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val) { FROMJSVAL_SETUP(); GET_MSG_PROPERTY(entity_id_t, entity); @@ -210,7 +210,7 @@ CMessage* CMessageOwnershipChanged::FromJSVal(ScriptInterface& scriptInterface, //////////////////////////////// -JS::Value CMessagePositionChanged::ToJSVal(ScriptInterface& scriptInterface) const +JS::Value CMessagePositionChanged::ToJSVal(const ScriptInterface& scriptInterface) const { TOJSVAL_SETUP(); SET_MSG_PROPERTY(entity); @@ -221,7 +221,7 @@ JS::Value CMessagePositionChanged::ToJSVal(ScriptInterface& scriptInterface) con return JS::ObjectValue(*obj); } -CMessage* CMessagePositionChanged::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val) +CMessage* CMessagePositionChanged::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val) { FROMJSVAL_SETUP(); GET_MSG_PROPERTY(entity_id_t, entity); @@ -234,13 +234,13 @@ CMessage* CMessagePositionChanged::FromJSVal(ScriptInterface& scriptInterface, J //////////////////////////////// -JS::Value CMessageInterpolatedPositionChanged::ToJSVal(ScriptInterface& UNUSED(scriptInterface)) const +JS::Value CMessageInterpolatedPositionChanged::ToJSVal(const ScriptInterface& UNUSED(scriptInterface)) const { LOGWARNING("CMessageInterpolatedPositionChanged::ToJSVal not implemented"); return JS::UndefinedValue(); } -CMessage* CMessageInterpolatedPositionChanged::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val)) +CMessage* CMessageInterpolatedPositionChanged::FromJSVal(const ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val)) { LOGWARNING("CMessageInterpolatedPositionChanged::FromJSVal not implemented"); return NULL; @@ -248,7 +248,7 @@ CMessage* CMessageInterpolatedPositionChanged::FromJSVal(ScriptInterface& UNUSED //////////////////////////////// -JS::Value CMessageTerritoryPositionChanged::ToJSVal(ScriptInterface& scriptInterface) const +JS::Value CMessageTerritoryPositionChanged::ToJSVal(const ScriptInterface& scriptInterface) const { TOJSVAL_SETUP(); SET_MSG_PROPERTY(entity); @@ -256,7 +256,7 @@ JS::Value CMessageTerritoryPositionChanged::ToJSVal(ScriptInterface& scriptInter return JS::ObjectValue(*obj); } -CMessage* CMessageTerritoryPositionChanged::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val) +CMessage* CMessageTerritoryPositionChanged::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val) { FROMJSVAL_SETUP(); GET_MSG_PROPERTY(entity_id_t, entity); @@ -266,7 +266,7 @@ CMessage* CMessageTerritoryPositionChanged::FromJSVal(ScriptInterface& scriptInt //////////////////////////////// -JS::Value CMessageMotionChanged::ToJSVal(ScriptInterface& scriptInterface) const +JS::Value CMessageMotionChanged::ToJSVal(const ScriptInterface& scriptInterface) const { TOJSVAL_SETUP(); SET_MSG_PROPERTY(starting); @@ -274,7 +274,7 @@ JS::Value CMessageMotionChanged::ToJSVal(ScriptInterface& scriptInterface) const return JS::ObjectValue(*obj); } -CMessage* CMessageMotionChanged::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val) +CMessage* CMessageMotionChanged::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val) { FROMJSVAL_SETUP(); GET_MSG_PROPERTY(bool, starting); @@ -284,7 +284,7 @@ CMessage* CMessageMotionChanged::FromJSVal(ScriptInterface& scriptInterface, JS: //////////////////////////////// -JS::Value CMessageTerrainChanged::ToJSVal(ScriptInterface& scriptInterface) const +JS::Value CMessageTerrainChanged::ToJSVal(const ScriptInterface& scriptInterface) const { TOJSVAL_SETUP(); SET_MSG_PROPERTY(i0); @@ -294,7 +294,7 @@ JS::Value CMessageTerrainChanged::ToJSVal(ScriptInterface& scriptInterface) cons return OBJECT_TO_JSVAL(obj); } -CMessage* CMessageTerrainChanged::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val) +CMessage* CMessageTerrainChanged::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val) { FROMJSVAL_SETUP(); GET_MSG_PROPERTY(int32_t, i0); @@ -306,7 +306,7 @@ CMessage* CMessageTerrainChanged::FromJSVal(ScriptInterface& scriptInterface, JS //////////////////////////////// -JS::Value CMessageVisibilityChanged::ToJSVal(ScriptInterface& scriptInterface) const +JS::Value CMessageVisibilityChanged::ToJSVal(const ScriptInterface& scriptInterface) const { TOJSVAL_SETUP(); SET_MSG_PROPERTY(player); @@ -316,7 +316,7 @@ JS::Value CMessageVisibilityChanged::ToJSVal(ScriptInterface& scriptInterface) c return JS::ObjectValue(*obj); } -CMessage* CMessageVisibilityChanged::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val) +CMessage* CMessageVisibilityChanged::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val) { FROMJSVAL_SETUP(); GET_MSG_PROPERTY(player_id_t, player); @@ -328,46 +328,46 @@ CMessage* CMessageVisibilityChanged::FromJSVal(ScriptInterface& scriptInterface, //////////////////////////////// -JS::Value CMessageWaterChanged::ToJSVal(ScriptInterface& scriptInterface) const +JS::Value CMessageWaterChanged::ToJSVal(const ScriptInterface& scriptInterface) const { TOJSVAL_SETUP(); return OBJECT_TO_JSVAL(obj); } -CMessage* CMessageWaterChanged::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val)) +CMessage* CMessageWaterChanged::FromJSVal(const ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val)) { return new CMessageWaterChanged(); } //////////////////////////////// -JS::Value CMessageObstructionMapShapeChanged::ToJSVal(ScriptInterface& scriptInterface) const +JS::Value CMessageObstructionMapShapeChanged::ToJSVal(const ScriptInterface& scriptInterface) const { TOJSVAL_SETUP(); return JS::ObjectValue(*obj); } -CMessage* CMessageObstructionMapShapeChanged::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val)) +CMessage* CMessageObstructionMapShapeChanged::FromJSVal(const ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val)) { return new CMessageObstructionMapShapeChanged(); } //////////////////////////////// -JS::Value CMessageTerritoriesChanged::ToJSVal(ScriptInterface& scriptInterface) const +JS::Value CMessageTerritoriesChanged::ToJSVal(const ScriptInterface& scriptInterface) const { TOJSVAL_SETUP(); return JS::ObjectValue(*obj); } -CMessage* CMessageTerritoriesChanged::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val)) +CMessage* CMessageTerritoriesChanged::FromJSVal(const ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val)) { return new CMessageTerritoriesChanged(); } //////////////////////////////// -JS::Value CMessageRangeUpdate::ToJSVal(ScriptInterface& scriptInterface) const +JS::Value CMessageRangeUpdate::ToJSVal(const ScriptInterface& scriptInterface) const { TOJSVAL_SETUP(); SET_MSG_PROPERTY(tag); @@ -376,7 +376,7 @@ JS::Value CMessageRangeUpdate::ToJSVal(ScriptInterface& scriptInterface) const return JS::ObjectValue(*obj); } -CMessage* CMessageRangeUpdate::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val)) +CMessage* CMessageRangeUpdate::FromJSVal(const ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val)) { LOGWARNING("CMessageRangeUpdate::FromJSVal not implemented"); return NULL; @@ -384,13 +384,13 @@ CMessage* CMessageRangeUpdate::FromJSVal(ScriptInterface& UNUSED(scriptInterface //////////////////////////////// -JS::Value CMessagePathResult::ToJSVal(ScriptInterface& UNUSED(scriptInterface)) const +JS::Value CMessagePathResult::ToJSVal(const ScriptInterface& UNUSED(scriptInterface)) const { LOGWARNING("CMessagePathResult::ToJSVal not implemented"); return JS::UndefinedValue(); } -CMessage* CMessagePathResult::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val)) +CMessage* CMessagePathResult::FromJSVal(const ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val)) { LOGWARNING("CMessagePathResult::FromJSVal not implemented"); return NULL; @@ -398,7 +398,7 @@ CMessage* CMessagePathResult::FromJSVal(ScriptInterface& UNUSED(scriptInterface) //////////////////////////////// -JS::Value CMessageValueModification::ToJSVal(ScriptInterface& scriptInterface) const +JS::Value CMessageValueModification::ToJSVal(const ScriptInterface& scriptInterface) const { TOJSVAL_SETUP(); SET_MSG_PROPERTY(entities); @@ -407,7 +407,7 @@ JS::Value CMessageValueModification::ToJSVal(ScriptInterface& scriptInterface) c return JS::ObjectValue(*obj); } -CMessage* CMessageValueModification::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val) +CMessage* CMessageValueModification::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val) { FROMJSVAL_SETUP(); GET_MSG_PROPERTY(std::vector, entities); @@ -418,7 +418,7 @@ CMessage* CMessageValueModification::FromJSVal(ScriptInterface& scriptInterface, //////////////////////////////// -JS::Value CMessageTemplateModification::ToJSVal(ScriptInterface& scriptInterface) const +JS::Value CMessageTemplateModification::ToJSVal(const ScriptInterface& scriptInterface) const { TOJSVAL_SETUP(); SET_MSG_PROPERTY(player); @@ -427,7 +427,7 @@ JS::Value CMessageTemplateModification::ToJSVal(ScriptInterface& scriptInterface return JS::ObjectValue(*obj); } -CMessage* CMessageTemplateModification::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val) +CMessage* CMessageTemplateModification::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val) { FROMJSVAL_SETUP(); GET_MSG_PROPERTY(player_id_t, player); @@ -438,7 +438,7 @@ CMessage* CMessageTemplateModification::FromJSVal(ScriptInterface& scriptInterfa //////////////////////////////// -JS::Value CMessageVisionRangeChanged::ToJSVal(ScriptInterface& scriptInterface) const +JS::Value CMessageVisionRangeChanged::ToJSVal(const ScriptInterface& scriptInterface) const { TOJSVAL_SETUP(); SET_MSG_PROPERTY(entity); @@ -447,7 +447,7 @@ JS::Value CMessageVisionRangeChanged::ToJSVal(ScriptInterface& scriptInterface) return JS::ObjectValue(*obj); } -CMessage* CMessageVisionRangeChanged::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val) +CMessage* CMessageVisionRangeChanged::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val) { FROMJSVAL_SETUP(); GET_MSG_PROPERTY(entity_id_t, entity); @@ -456,7 +456,7 @@ CMessage* CMessageVisionRangeChanged::FromJSVal(ScriptInterface& scriptInterface return new CMessageVisionRangeChanged(entity, oldRange, newRange); } -JS::Value CMessageVisionSharingChanged::ToJSVal(ScriptInterface& scriptInterface) const +JS::Value CMessageVisionSharingChanged::ToJSVal(const ScriptInterface& scriptInterface) const { TOJSVAL_SETUP(); SET_MSG_PROPERTY(entity); @@ -465,7 +465,7 @@ JS::Value CMessageVisionSharingChanged::ToJSVal(ScriptInterface& scriptInterface return JS::ObjectValue(*obj); } -CMessage* CMessageVisionSharingChanged::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val) +CMessage* CMessageVisionSharingChanged::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val) { FROMJSVAL_SETUP(); GET_MSG_PROPERTY(entity_id_t, entity); @@ -476,27 +476,27 @@ CMessage* CMessageVisionSharingChanged::FromJSVal(ScriptInterface& scriptInterfa //////////////////////////////// -JS::Value CMessageMinimapPing::ToJSVal(ScriptInterface& scriptInterface) const +JS::Value CMessageMinimapPing::ToJSVal(const ScriptInterface& scriptInterface) const { TOJSVAL_SETUP(); return JS::ObjectValue(*obj); } -CMessage* CMessageMinimapPing::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val)) +CMessage* CMessageMinimapPing::FromJSVal(const ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val)) { return new CMessageMinimapPing(); } //////////////////////////////// -JS::Value CMessageCinemaPathEnded::ToJSVal(ScriptInterface& scriptInterface) const +JS::Value CMessageCinemaPathEnded::ToJSVal(const ScriptInterface& scriptInterface) const { TOJSVAL_SETUP(); SET_MSG_PROPERTY(name); return JS::ObjectValue(*obj); } -CMessage* CMessageCinemaPathEnded::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val) +CMessage* CMessageCinemaPathEnded::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val) { FROMJSVAL_SETUP(); GET_MSG_PROPERTY(CStrW, name); @@ -505,13 +505,13 @@ CMessage* CMessageCinemaPathEnded::FromJSVal(ScriptInterface& scriptInterface, J //////////////////////////////// -JS::Value CMessageCinemaQueueEnded::ToJSVal(ScriptInterface& scriptInterface) const +JS::Value CMessageCinemaQueueEnded::ToJSVal(const ScriptInterface& scriptInterface) const { TOJSVAL_SETUP(); return JS::ObjectValue(*obj); } -CMessage* CMessageCinemaQueueEnded::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val) +CMessage* CMessageCinemaQueueEnded::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val) { FROMJSVAL_SETUP(); return new CMessageCinemaQueueEnded(); @@ -519,14 +519,14 @@ CMessage* CMessageCinemaQueueEnded::FromJSVal(ScriptInterface& scriptInterface, //////////////////////////////////////////////////////////////// -JS::Value CMessagePlayerColorChanged::ToJSVal(ScriptInterface& scriptInterface) const +JS::Value CMessagePlayerColorChanged::ToJSVal(const ScriptInterface& scriptInterface) const { TOJSVAL_SETUP(); SET_MSG_PROPERTY(player); return JS::ObjectValue(*obj); } -CMessage* CMessagePlayerColorChanged::FromJSVal(ScriptInterface& scriptInterface, JS::HandleValue val) +CMessage* CMessagePlayerColorChanged::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val) { FROMJSVAL_SETUP(); GET_MSG_PROPERTY(player_id_t, player); @@ -535,7 +535,7 @@ CMessage* CMessagePlayerColorChanged::FromJSVal(ScriptInterface& scriptInterface //////////////////////////////////////////////////////////////// -CMessage* CMessageFromJSVal(int mtid, ScriptInterface& scriptingInterface, JS::HandleValue val) +CMessage* CMessageFromJSVal(int mtid, const ScriptInterface& scriptingInterface, JS::HandleValue val) { switch (mtid) { diff --git a/source/simulation2/scripting/ScriptComponent.cpp b/source/simulation2/scripting/ScriptComponent.cpp index 4e96c7bdf5..0443c77b92 100644 --- a/source/simulation2/scripting/ScriptComponent.cpp +++ b/source/simulation2/scripting/ScriptComponent.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 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 @@ -22,7 +22,7 @@ #include "simulation2/serialization/ISerializer.h" #include "simulation2/serialization/IDeserializer.h" -CComponentTypeScript::CComponentTypeScript(ScriptInterface& scriptInterface, JS::HandleValue instance) : +CComponentTypeScript::CComponentTypeScript(const ScriptInterface& scriptInterface, JS::HandleValue instance) : m_ScriptInterface(scriptInterface), m_Instance(scriptInterface.GetJSRuntime(), instance) { // Cache the property detection for efficiency diff --git a/source/simulation2/scripting/ScriptComponent.h b/source/simulation2/scripting/ScriptComponent.h index fcc5432c8d..9efc64f009 100644 --- a/source/simulation2/scripting/ScriptComponent.h +++ b/source/simulation2/scripting/ScriptComponent.h @@ -31,7 +31,7 @@ class CComponentTypeScript { NONCOPYABLE(CComponentTypeScript); public: - CComponentTypeScript(ScriptInterface& scriptInterface, JS::HandleValue instance); + CComponentTypeScript(const ScriptInterface& scriptInterface, JS::HandleValue instance); JS::Value GetInstance() const { return m_Instance.get(); } @@ -68,7 +68,7 @@ public: } private: - ScriptInterface& m_ScriptInterface; + const ScriptInterface& m_ScriptInterface; JS::PersistentRootedValue m_Instance; bool m_HasCustomSerialize; bool m_HasCustomDeserialize; diff --git a/source/simulation2/serialization/BinarySerializer.cpp b/source/simulation2/serialization/BinarySerializer.cpp index ad3376f03d..2f1e737132 100644 --- a/source/simulation2/serialization/BinarySerializer.cpp +++ b/source/simulation2/serialization/BinarySerializer.cpp @@ -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 @@ -54,7 +54,7 @@ static u8 GetArrayType(js::Scalar::Type arrayType) } } -CBinarySerializerScriptImpl::CBinarySerializerScriptImpl(ScriptInterface& scriptInterface, ISerializer& serializer) : +CBinarySerializerScriptImpl::CBinarySerializerScriptImpl(const ScriptInterface& scriptInterface, ISerializer& serializer) : m_ScriptInterface(scriptInterface), m_Serializer(serializer), m_ScriptBackrefs(scriptInterface.GetRuntime()), m_SerializablePrototypes(new ObjectIdCache(scriptInterface.GetRuntime())), m_ScriptBackrefsNext(1) { diff --git a/source/simulation2/serialization/BinarySerializer.h b/source/simulation2/serialization/BinarySerializer.h index 980e825371..235b69a278 100644 --- a/source/simulation2/serialization/BinarySerializer.h +++ b/source/simulation2/serialization/BinarySerializer.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 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 @@ -83,13 +83,13 @@ protected: class CBinarySerializerScriptImpl { public: - CBinarySerializerScriptImpl(ScriptInterface& scriptInterface, ISerializer& serializer); + CBinarySerializerScriptImpl(const ScriptInterface& scriptInterface, ISerializer& serializer); void ScriptString(const char* name, JS::HandleString string); void HandleScriptVal(JS::HandleValue val); void SetSerializablePrototypes(shared_ptr > prototypes); private: - ScriptInterface& m_ScriptInterface; + const ScriptInterface& m_ScriptInterface; ISerializer& m_Serializer; ObjectIdCache m_ScriptBackrefs; @@ -111,7 +111,7 @@ class CBinarySerializer : public ISerializer { NONCOPYABLE(CBinarySerializer); public: - CBinarySerializer(ScriptInterface& scriptInterface) : + CBinarySerializer(const ScriptInterface& scriptInterface) : m_ScriptImpl(new CBinarySerializerScriptImpl(scriptInterface, *this)), m_RawStreamBuf(m_Impl), m_RawStream(&m_RawStreamBuf) @@ -119,7 +119,7 @@ public: } template - CBinarySerializer(ScriptInterface& scriptInterface, A& a) : + CBinarySerializer(const ScriptInterface& scriptInterface, A& a) : m_ScriptImpl(new CBinarySerializerScriptImpl(scriptInterface, *this)), m_Impl(a), m_RawStreamBuf(m_Impl), diff --git a/source/simulation2/serialization/DebugSerializer.cpp b/source/simulation2/serialization/DebugSerializer.cpp index 485431e06e..7f1f49f1ec 100644 --- a/source/simulation2/serialization/DebugSerializer.cpp +++ b/source/simulation2/serialization/DebugSerializer.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 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 @@ -52,7 +52,7 @@ std::string canonfloat(T value, int prec) return r; } -CDebugSerializer::CDebugSerializer(ScriptInterface& scriptInterface, std::ostream& stream, bool includeDebugInfo) : +CDebugSerializer::CDebugSerializer(const ScriptInterface& scriptInterface, std::ostream& stream, bool includeDebugInfo) : m_ScriptInterface(scriptInterface), m_Stream(stream), m_IsDebug(includeDebugInfo), m_Indent(0) { } diff --git a/source/simulation2/serialization/DebugSerializer.h b/source/simulation2/serialization/DebugSerializer.h index 6783f2529f..7ad4871540 100644 --- a/source/simulation2/serialization/DebugSerializer.h +++ b/source/simulation2/serialization/DebugSerializer.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 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 @@ -32,7 +32,7 @@ public: * @param stream Stream to receive UTF-8 encoded output * @param includeDebugInfo If true then additional non-deterministic data will be included in the output */ - CDebugSerializer(ScriptInterface& scriptInterface, std::ostream& stream, bool includeDebugInfo = true); + CDebugSerializer(const ScriptInterface& scriptInterface, std::ostream& stream, bool includeDebugInfo = true); void Comment(const std::string& comment); void TextLine(const std::string& text); @@ -58,7 +58,7 @@ protected: virtual void PutRaw(const char* name, const u8* data, size_t len); private: - ScriptInterface& m_ScriptInterface; + const ScriptInterface& m_ScriptInterface; std::ostream& m_Stream; bool m_IsDebug; int m_Indent; diff --git a/source/simulation2/serialization/HashSerializer.cpp b/source/simulation2/serialization/HashSerializer.cpp index 8084026906..c2957abae5 100644 --- a/source/simulation2/serialization/HashSerializer.cpp +++ b/source/simulation2/serialization/HashSerializer.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2010 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 @@ -19,7 +19,7 @@ #include "HashSerializer.h" -CHashSerializer::CHashSerializer(ScriptInterface& scriptInterface) : +CHashSerializer::CHashSerializer(const ScriptInterface& scriptInterface) : CBinarySerializer(scriptInterface) { } diff --git a/source/simulation2/serialization/HashSerializer.h b/source/simulation2/serialization/HashSerializer.h index c583aa674b..5a5b898dea 100644 --- a/source/simulation2/serialization/HashSerializer.h +++ b/source/simulation2/serialization/HashSerializer.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2010 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 @@ -45,7 +45,7 @@ private: class CHashSerializer : public CBinarySerializer { public: - CHashSerializer(ScriptInterface& scriptInterface); + CHashSerializer(const ScriptInterface& scriptInterface); size_t GetHashLength(); const u8* ComputeHash(); diff --git a/source/simulation2/serialization/StdDeserializer.cpp b/source/simulation2/serialization/StdDeserializer.cpp index 131898ccd9..f805113165 100644 --- a/source/simulation2/serialization/StdDeserializer.cpp +++ b/source/simulation2/serialization/StdDeserializer.cpp @@ -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 @@ -27,7 +27,7 @@ #include "lib/byte_order.h" -CStdDeserializer::CStdDeserializer(ScriptInterface& scriptInterface, std::istream& stream) : +CStdDeserializer::CStdDeserializer(const ScriptInterface& scriptInterface, std::istream& stream) : m_ScriptInterface(scriptInterface), m_Stream(stream), m_dummyObject(scriptInterface.GetJSRuntime()) { diff --git a/source/simulation2/serialization/StdDeserializer.h b/source/simulation2/serialization/StdDeserializer.h index 1d16e56993..763c636855 100644 --- a/source/simulation2/serialization/StdDeserializer.h +++ b/source/simulation2/serialization/StdDeserializer.h @@ -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 @@ -28,7 +28,7 @@ class CStdDeserializer : public IDeserializer { NONCOPYABLE(CStdDeserializer); public: - CStdDeserializer(ScriptInterface& scriptInterface, std::istream& stream); + CStdDeserializer(const ScriptInterface& scriptInterface, std::istream& stream); virtual ~CStdDeserializer(); virtual void ScriptVal(const char* name, JS::MutableHandleValue out); @@ -57,7 +57,7 @@ private: std::vector > m_ScriptBackrefs; JS::PersistentRooted m_dummyObject; - ScriptInterface& m_ScriptInterface; + const ScriptInterface& m_ScriptInterface; std::istream& m_Stream; diff --git a/source/simulation2/serialization/StdSerializer.cpp b/source/simulation2/serialization/StdSerializer.cpp index 50d2adf85a..95667efc4b 100644 --- a/source/simulation2/serialization/StdSerializer.cpp +++ b/source/simulation2/serialization/StdSerializer.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 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 @@ -24,7 +24,7 @@ CStdSerializerImpl::CStdSerializerImpl(std::ostream& stream) : { } -CStdSerializer::CStdSerializer(ScriptInterface& scriptInterface, std::ostream& stream) : +CStdSerializer::CStdSerializer(const ScriptInterface& scriptInterface, std::ostream& stream) : CBinarySerializer(scriptInterface, stream) { } diff --git a/source/simulation2/serialization/StdSerializer.h b/source/simulation2/serialization/StdSerializer.h index 8a2d508f2c..b6445b5972 100644 --- a/source/simulation2/serialization/StdSerializer.h +++ b/source/simulation2/serialization/StdSerializer.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 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 @@ -59,7 +59,7 @@ private: class CStdSerializer : public CBinarySerializer { public: - CStdSerializer(ScriptInterface& scriptInterface, std::ostream& stream); + CStdSerializer(const ScriptInterface& scriptInterface, std::ostream& stream); virtual std::ostream& GetStream(); }; diff --git a/source/simulation2/system/Component.h b/source/simulation2/system/Component.h index 53ed21dcdc..429f4603c9 100644 --- a/source/simulation2/system/Component.h +++ b/source/simulation2/system/Component.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2010 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 @@ -42,7 +42,7 @@ } #define DEFAULT_COMPONENT_ALLOCATOR(cname) \ - static IComponent* Allocate(ScriptInterface&, JS::HandleValue) { return new CCmp##cname(); } \ + static IComponent* Allocate(const ScriptInterface&, JS::HandleValue) { return new CCmp##cname(); } \ static void Deallocate(IComponent* cmp) { delete static_cast (cmp); } \ virtual int GetComponentTypeId() const \ { \ @@ -51,7 +51,7 @@ #define DEFAULT_SCRIPT_WRAPPER(cname) \ static void ClassInit(CComponentManager& UNUSED(componentManager)) { } \ - static IComponent* Allocate(ScriptInterface& scriptInterface, JS::HandleValue instance) \ + static IComponent* Allocate(const ScriptInterface& scriptInterface, JS::HandleValue instance) \ { \ return new CCmp##cname(scriptInterface, instance); \ } \ @@ -59,7 +59,7 @@ { \ delete static_cast (cmp); \ } \ - CCmp##cname(ScriptInterface& scriptInterface, JS::HandleValue instance) : m_Script(scriptInterface, instance) { } \ + CCmp##cname(const ScriptInterface& scriptInterface, JS::HandleValue instance) : m_Script(scriptInterface, instance) { } \ static std::string GetSchema() \ { \ return ""; \ diff --git a/source/simulation2/system/ComponentManager.cpp b/source/simulation2/system/ComponentManager.cpp index d395013e77..77014ab165 100644 --- a/source/simulation2/system/ComponentManager.cpp +++ b/source/simulation2/system/ComponentManager.cpp @@ -40,9 +40,9 @@ public: virtual int GetType() const { return mtid; } virtual const char* GetScriptHandlerName() const { return handlerName.c_str(); } virtual const char* GetScriptGlobalHandlerName() const { return globalHandlerName.c_str(); } - virtual JS::Value ToJSVal(ScriptInterface& UNUSED(scriptInterface)) const { return msg.get(); } + virtual JS::Value ToJSVal(const ScriptInterface& UNUSED(scriptInterface)) const { return msg.get(); } - CMessageScripted(ScriptInterface& scriptInterface, int mtid, const std::string& name, JS::HandleValue msg) : + CMessageScripted(const ScriptInterface& scriptInterface, int mtid, const std::string& name, JS::HandleValue msg) : mtid(mtid), handlerName("On" + name), globalHandlerName("OnGlobal" + name), msg(scriptInterface.GetJSRuntime(), msg) { } diff --git a/source/simulation2/system/ComponentManager.h b/source/simulation2/system/ComponentManager.h index 6c8c283afb..fd3293901c 100644 --- a/source/simulation2/system/ComponentManager.h +++ b/source/simulation2/system/ComponentManager.h @@ -49,7 +49,7 @@ public: private: // Component allocation types - typedef IComponent* (*AllocFunc)(ScriptInterface& scriptInterface, JS::HandleValue ctor); + typedef IComponent* (*AllocFunc)(const ScriptInterface& scriptInterface, JS::HandleValue ctor); typedef void (*DeallocFunc)(IComponent*); // ComponentTypes come in three types: @@ -303,11 +303,11 @@ public: void SetRNGSeed(u32 seed); // Various state serialization functions: - bool ComputeStateHash(std::string& outHash, bool quick); - bool DumpDebugState(std::ostream& stream, bool includeDebugInfo); + bool ComputeStateHash(std::string& outHash, bool quick) const; + bool DumpDebugState(std::ostream& stream, bool includeDebugInfo) const; // FlushDestroyedComponents must be called before SerializeState (since the destruction queue // won't get serialized) - bool SerializeState(std::ostream& stream); + bool SerializeState(std::ostream& stream) const; bool DeserializeState(std::istream& stream); std::string GenerateSchema() const; diff --git a/source/simulation2/system/ComponentManagerSerialization.cpp b/source/simulation2/system/ComponentManagerSerialization.cpp index c9de4b208d..661124cc87 100644 --- a/source/simulation2/system/ComponentManagerSerialization.cpp +++ b/source/simulation2/system/ComponentManagerSerialization.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2013 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 @@ -46,7 +46,7 @@ void DeserializeRNG(const std::string& str, boost::rand48& rng) s >> rng; } -bool CComponentManager::DumpDebugState(std::ostream& stream, bool includeDebugInfo) +bool CComponentManager::DumpDebugState(std::ostream& stream, bool includeDebugInfo) const { CDebugSerializer serializer(m_ScriptInterface, stream, includeDebugInfo); @@ -95,7 +95,7 @@ bool CComponentManager::DumpDebugState(std::ostream& stream, bool includeDebugIn return true; } -bool CComponentManager::ComputeStateHash(std::string& outHash, bool quick) +bool CComponentManager::ComputeStateHash(std::string& outHash, bool quick) const { // Hash serialization: this includes the minimal data necessary to detect // differences in the state, and ignores things like counts and names @@ -177,7 +177,7 @@ bool CComponentManager::ComputeStateHash(std::string& outHash, bool quick) * version), but it doesn't seem worth having a separate codepath for that.) */ -bool CComponentManager::SerializeState(std::ostream& stream) +bool CComponentManager::SerializeState(std::ostream& stream) const { CStdSerializer serializer(m_ScriptInterface, stream); diff --git a/source/simulation2/system/IComponent.cpp b/source/simulation2/system/IComponent.cpp index 993b6b2ba1..f698e8d28f 100644 --- a/source/simulation2/system/IComponent.cpp +++ b/source/simulation2/system/IComponent.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2010 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 @@ -33,7 +33,7 @@ void IComponent::HandleMessage(const CMessage& UNUSED(msg), bool UNUSED(global)) { } -bool IComponent::NewJSObject(ScriptInterface& UNUSED(scriptInterface), JS::MutableHandleObject UNUSED(out)) const +bool IComponent::NewJSObject(const ScriptInterface& UNUSED(scriptInterface), JS::MutableHandleObject UNUSED(out)) const { return false; } diff --git a/source/simulation2/system/IComponent.h b/source/simulation2/system/IComponent.h index e3f1278f1c..9743692c2a 100644 --- a/source/simulation2/system/IComponent.h +++ b/source/simulation2/system/IComponent.h @@ -60,7 +60,7 @@ public: * Returns false by default, indicating that a scripted wrapper of this IComponent is not supported. * Derrived classes should return true if they implement such a wrapper. */ - virtual bool NewJSObject(ScriptInterface& scriptInterface, JS::MutableHandleObject out) const; + virtual bool NewJSObject(const ScriptInterface& scriptInterface, JS::MutableHandleObject out) const; virtual JS::Value GetJSInstance() const; virtual int GetComponentTypeId() const = 0; diff --git a/source/simulation2/system/Interface.h b/source/simulation2/system/Interface.h index 4308b4825e..00180d6c30 100644 --- a/source/simulation2/system/Interface.h +++ b/source/simulation2/system/Interface.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2010 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 @@ -21,7 +21,7 @@ #include "simulation2/system/IComponent.h" #define DECLARE_INTERFACE_TYPE(iname) \ - virtual bool NewJSObject(ScriptInterface& scriptInterface, JS::MutableHandleObject out) const; \ + virtual bool NewJSObject(const ScriptInterface& scriptInterface, JS::MutableHandleObject out) const; \ static void InterfaceInit(ScriptInterface& scriptInterface); \ static int GetInterfaceId() { return IID_##iname; } diff --git a/source/simulation2/system/InterfaceScripted.h b/source/simulation2/system/InterfaceScripted.h index 8efdb732de..81832d79f7 100644 --- a/source/simulation2/system/InterfaceScripted.h +++ b/source/simulation2/system/InterfaceScripted.h @@ -32,7 +32,7 @@ void ICmp##iname::InterfaceInit(ScriptInterface& scriptInterface) { \ scriptInterface.DefineCustomObjectType(&class_ICmp##iname, NULL, 0, NULL, methods_ICmp##iname, NULL, NULL); \ } \ - bool ICmp##iname::NewJSObject(ScriptInterface& scriptInterface, JS::MutableHandleObject out) const\ + bool ICmp##iname::NewJSObject(const ScriptInterface& scriptInterface, JS::MutableHandleObject out) const\ { \ out.set(scriptInterface.CreateCustomObject("ICmp" #iname)); \ return true; \ diff --git a/source/simulation2/system/Message.h b/source/simulation2/system/Message.h index 732dc235fe..8abfa6f67a 100644 --- a/source/simulation2/system/Message.h +++ b/source/simulation2/system/Message.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2010 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 @@ -31,14 +31,14 @@ public: virtual int GetType() const = 0; virtual const char* GetScriptHandlerName() const = 0; virtual const char* GetScriptGlobalHandlerName() const = 0; - virtual JS::Value ToJSVal(ScriptInterface&) const = 0; - JS::Value ToJSValCached(ScriptInterface&) const; + virtual JS::Value ToJSVal(const ScriptInterface&) const = 0; + JS::Value ToJSValCached(const ScriptInterface&) const; private: mutable std::unique_ptr m_Cached; }; // TODO: GetType could be replaced with a plain member variable to avoid some // virtual calls, if that turns out to be worthwhile -CMessage* CMessageFromJSVal(int mtid, ScriptInterface&, JS::HandleValue); +CMessage* CMessageFromJSVal(int mtid, const ScriptInterface&, JS::HandleValue); #endif // INCLUDED_MESSAGE diff --git a/source/soundmanager/scripting/JSInterface_Sound.cpp b/source/soundmanager/scripting/JSInterface_Sound.cpp index a1e3f9d07f..e438e54690 100644 --- a/source/soundmanager/scripting/JSInterface_Sound.cpp +++ b/source/soundmanager/scripting/JSInterface_Sound.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2013 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 @@ -135,7 +135,7 @@ namespace JSI_Sound #endif - void RegisterScriptFunctions(ScriptInterface& scriptInterface) + void RegisterScriptFunctions(const ScriptInterface& scriptInterface) { scriptInterface.RegisterFunction("StartMusic"); scriptInterface.RegisterFunction("StopMusic"); diff --git a/source/soundmanager/scripting/JSInterface_Sound.h b/source/soundmanager/scripting/JSInterface_Sound.h index 43bc4efd63..c0a36f084f 100644 --- a/source/soundmanager/scripting/JSInterface_Sound.h +++ b/source/soundmanager/scripting/JSInterface_Sound.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2012 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 @@ -23,7 +23,7 @@ class ScriptInterface; namespace JSI_Sound { - void RegisterScriptFunctions(ScriptInterface& scriptInterface); + void RegisterScriptFunctions(const ScriptInterface& scriptInterface); } #endif // #ifndef INCLUDED_SOUNDSCRIPTINTERFACE diff --git a/source/test_setup.cpp b/source/test_setup.cpp index b015655ec1..6dfe4ff881 100644 --- a/source/test_setup.cpp +++ b/source/test_setup.cpp @@ -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 @@ -135,9 +135,9 @@ namespace } } -void ScriptTestSetup(ScriptInterface& ifc) +void ScriptTestSetup(const ScriptInterface& scriptinterface) { - ifc.RegisterFunction("TS_FAIL"); + scriptinterface.RegisterFunction("TS_FAIL"); // Load the TS_* function definitions // (We don't use VFS because tests might not have the normal VFS paths loaded) @@ -145,6 +145,6 @@ void ScriptTestSetup(ScriptInterface& ifc) std::ifstream ifs(OsString(path).c_str()); ENSURE(ifs.good()); std::string content((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); - bool ok = ifc.LoadScript(L"test_setup.js", content); + bool ok = scriptinterface.LoadScript(L"test_setup.js", content); ENSURE(ok); }