From 90367cdc539e65ad287aa8712ff4684fe96af5e1 Mon Sep 17 00:00:00 2001 From: wraitii Date: Thu, 12 Nov 2020 08:24:30 +0000 Subject: [PATCH] Remove DefPersistentRooted and unneeded includes. DefPersistentRooted is essentially a wrapper around unique_ptr and has no real reason to exist. Part of SM52 migration, stage: SM45 compatible. Patch by: Itms Tested by: Freagarach Refs #4893 Differential Revision: https://code.wildfiregames.com/D3086 This was SVN commit r24170. --- source/lobby/XmppClient.h | 3 +- source/lobby/scripting/JSInterface_Lobby.cpp | 1 - source/network/NetClient.h | 3 +- source/network/NetMessages.h | 4 +- source/network/NetSession.h | 3 +- source/ps/Game.h | 2 +- source/ps/scripting/JSInterface_VFS.cpp | 3 +- source/scriptinterface/ScriptVal.h | 85 ------------------- source/simulation2/Simulation2.h | 1 - .../simulation2/serialization/ISerializer.h | 3 +- .../simulation2/system/ComponentManager.cpp | 8 +- source/simulation2/system/ComponentManager.h | 3 +- source/simulation2/system/Message.h | 3 +- 13 files changed, 14 insertions(+), 108 deletions(-) delete mode 100644 source/scriptinterface/ScriptVal.h diff --git a/source/lobby/XmppClient.h b/source/lobby/XmppClient.h index ee66a460c4..f06c5a2d59 100644 --- a/source/lobby/XmppClient.h +++ b/source/lobby/XmppClient.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 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,6 @@ #include #include "glooxwrapper/glooxwrapper.h" -#include "scriptinterface/ScriptVal.h" class ScriptInterface; diff --git a/source/lobby/scripting/JSInterface_Lobby.cpp b/source/lobby/scripting/JSInterface_Lobby.cpp index 498c6fcdd6..1359eb6f56 100644 --- a/source/lobby/scripting/JSInterface_Lobby.cpp +++ b/source/lobby/scripting/JSInterface_Lobby.cpp @@ -27,7 +27,6 @@ #include "ps/CStr.h" #include "ps/Util.h" #include "scriptinterface/ScriptInterface.h" -#include "scriptinterface/ScriptVal.h" #include "third_party/encryption/pkcs5_pbkdf2.h" diff --git a/source/network/NetClient.h b/source/network/NetClient.h index b33e436dfd..cd0bb4fece 100644 --- a/source/network/NetClient.h +++ b/source/network/NetClient.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 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,6 @@ #include "network/fsm.h" #include "network/NetFileTransfer.h" #include "network/NetHost.h" -#include "scriptinterface/ScriptVal.h" #include "scriptinterface/ScriptInterface.h" #include "ps/CStr.h" diff --git a/source/network/NetMessages.h b/source/network/NetMessages.h index 902058935d..a335bfe9a1 100644 --- a/source/network/NetMessages.h +++ b/source/network/NetMessages.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2020 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 @@ #define NETMESSAGES_H #include "ps/CStr.h" -#include "scriptinterface/ScriptVal.h" +#include "scriptinterface/ScriptTypes.h" #define PS_PROTOCOL_MAGIC 0x5073013f // 'P', 's', 0x01, '?' #define PS_PROTOCOL_MAGIC_RESPONSE 0x50630121 // 'P', 'c', 0x01, '!' diff --git a/source/network/NetSession.h b/source/network/NetSession.h index 53bad9ebb4..4730bd2f43 100644 --- a/source/network/NetSession.h +++ b/source/network/NetSession.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 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,6 @@ #include "network/NetFileTransfer.h" #include "network/NetHost.h" #include "ps/CStr.h" -#include "scriptinterface/ScriptVal.h" /** * Report the peer if we didn't receive a packet after this time (milliseconds). diff --git a/source/ps/Game.h b/source/ps/Game.h index c5e04d737a..e888008f87 100644 --- a/source/ps/Game.h +++ b/source/ps/Game.h @@ -22,7 +22,7 @@ #include "ps/Errors.h" #include "ps/Filesystem.h" -#include "scriptinterface/ScriptVal.h" +#include "scriptinterface/ScriptTypes.h" #include "simulation2/helpers/Player.h" class CWorld; diff --git a/source/ps/scripting/JSInterface_VFS.cpp b/source/ps/scripting/JSInterface_VFS.cpp index 6f929e8dc7..e044778c8c 100644 --- a/source/ps/scripting/JSInterface_VFS.cpp +++ b/source/ps/scripting/JSInterface_VFS.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 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,6 @@ #include "ps/CLogger.h" #include "ps/CStr.h" #include "ps/Filesystem.h" -#include "scriptinterface/ScriptVal.h" #include "scriptinterface/ScriptInterface.h" #include diff --git a/source/scriptinterface/ScriptVal.h b/source/scriptinterface/ScriptVal.h deleted file mode 100644 index 42d9cae2c1..0000000000 --- a/source/scriptinterface/ScriptVal.h +++ /dev/null @@ -1,85 +0,0 @@ -/* Copyright (C) 2020 Wildfire Games. - * This file is part of 0 A.D. - * - * 0 A.D. is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * 0 A.D. is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with 0 A.D. If not, see . - */ - -#ifndef INCLUDED_SCRIPTVAL -#define INCLUDED_SCRIPTVAL - -#include "ScriptTypes.h" - -/** - * A default constructible wrapper around JS::PersistentRootedValue - * - * It's a very common case that we need to store JS::Values on the heap as - * class members and only need them conditionally or want to initialize - * them after the constructor because we don't have the runtime available yet. - * Use it in these cases, but prefer to use JS::PersistentRootedValue directly - * if initializing it with a runtime/context in the constructor isn't a problem. - */ - template -class DefPersistentRooted -{ -public: - DefPersistentRooted() - { - } - - DefPersistentRooted(JSRuntime* rt) - { - m_Val.reset(new JS::PersistentRooted(rt)); - } - - DefPersistentRooted(JSRuntime* rt, JS::HandleValue val) - { - m_Val.reset(new JS::PersistentRooted(rt, val)); - } - - DefPersistentRooted(JSContext* cx, JS::Handle val) - { - m_Val.reset(new JS::PersistentRooted(cx, val)); - } - - void clear() - { - m_Val = nullptr; - } - - inline bool uninitialized() - { - return m_Val == nullptr; - } - - inline JS::PersistentRooted& get() const - { - ENSURE(m_Val); - return *m_Val; - } - - inline void set(JSRuntime* rt, T val) - { - m_Val.reset(new JS::PersistentRooted(rt, val)); - } - - inline void set(JSContext* cx, T val) - { - m_Val.reset(new JS::PersistentRooted(cx, val)); - } - -private: - std::unique_ptr > m_Val; -}; - -#endif // INCLUDED_SCRIPTVAL diff --git a/source/simulation2/Simulation2.h b/source/simulation2/Simulation2.h index a781a51954..f57bc7f5d6 100644 --- a/source/simulation2/Simulation2.h +++ b/source/simulation2/Simulation2.h @@ -19,7 +19,6 @@ #define INCLUDED_SIMULATION2 #include "lib/file/vfs/vfs_path.h" -#include "scriptinterface/ScriptVal.h" #include "simulation2/helpers/SimulationCommand.h" #include "simulation2/system/CmpPtr.h" #include "simulation2/system/Components.h" diff --git a/source/simulation2/serialization/ISerializer.h b/source/simulation2/serialization/ISerializer.h index 4ab47bb0b7..1ab19bceab 100644 --- a/source/simulation2/serialization/ISerializer.h +++ b/source/simulation2/serialization/ISerializer.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -20,7 +20,6 @@ #include "maths/Fixed.h" #include "ps/Errors.h" -#include "scriptinterface/ScriptVal.h" ERROR_GROUP(Serialize); ERROR_TYPE(Serialize, OutOfBounds); diff --git a/source/simulation2/system/ComponentManager.cpp b/source/simulation2/system/ComponentManager.cpp index 97d085c647..de10d04a8a 100644 --- a/source/simulation2/system/ComponentManager.cpp +++ b/source/simulation2/system/ComponentManager.cpp @@ -255,7 +255,7 @@ void CComponentManager::Script_RegisterComponentType_Common(ScriptInterface::CxP ctWrapper.dealloc, cname, schema, - DefPersistentRooted(cx, ctor) + std::unique_ptr(new JS::PersistentRootedValue(cx, ctor)) }; componentManager->m_ComponentTypesById[cid] = std::move(ct); @@ -537,7 +537,7 @@ void CComponentManager::SetRNGSeed(u32 seed) void CComponentManager::RegisterComponentType(InterfaceId iid, ComponentTypeId cid, AllocFunc alloc, DeallocFunc dealloc, const char* name, const std::string& schema) { - ComponentType c{ CT_Native, iid, alloc, dealloc, name, schema, DefPersistentRooted() }; + ComponentType c{ CT_Native, iid, alloc, dealloc, name, schema, std::unique_ptr() }; m_ComponentTypesById.insert(std::make_pair(cid, std::move(c))); m_ComponentTypeIdsByName[name] = cid; } @@ -545,7 +545,7 @@ void CComponentManager::RegisterComponentType(InterfaceId iid, ComponentTypeId c void CComponentManager::RegisterComponentTypeScriptWrapper(InterfaceId iid, ComponentTypeId cid, AllocFunc alloc, DeallocFunc dealloc, const char* name, const std::string& schema) { - ComponentType c{ CT_ScriptWrapper, iid, alloc, dealloc, name, schema, DefPersistentRooted() }; + ComponentType c{ CT_ScriptWrapper, iid, alloc, dealloc, name, schema, std::unique_ptr() }; m_ComponentTypesById.insert(std::make_pair(cid, std::move(c))); m_ComponentTypeIdsByName[name] = cid; // TODO: merge with RegisterComponentType @@ -757,7 +757,7 @@ IComponent* CComponentManager::ConstructComponent(CEntityHandle ent, ComponentTy JS::RootedValue obj(cx); if (ct.type == CT_Script) { - m_ScriptInterface.CallConstructor(ct.ctor.get(), JS::HandleValueArray::empty(), &obj); + m_ScriptInterface.CallConstructor(*ct.ctor, JS::HandleValueArray::empty(), &obj); if (obj.isNull()) { LOGERROR("Script component constructor failed"); diff --git a/source/simulation2/system/ComponentManager.h b/source/simulation2/system/ComponentManager.h index bf2bfa7e2a..f1c15e1ff5 100644 --- a/source/simulation2/system/ComponentManager.h +++ b/source/simulation2/system/ComponentManager.h @@ -20,7 +20,6 @@ #include "ps/Filesystem.h" #include "scriptinterface/ScriptInterface.h" -#include "scriptinterface/ScriptVal.h" #include "simulation2/helpers/Player.h" #include "simulation2/system/Components.h" #include "simulation2/system/Entity.h" @@ -71,7 +70,7 @@ private: DeallocFunc dealloc; std::string name; std::string schema; // RelaxNG fragment - DefPersistentRooted ctor; // only valid if type == CT_Script + std::unique_ptr ctor; // only valid if type == CT_Script }; public: diff --git a/source/simulation2/system/Message.h b/source/simulation2/system/Message.h index 8abfa6f67a..05386ab0c1 100644 --- a/source/simulation2/system/Message.h +++ b/source/simulation2/system/Message.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2020 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,6 @@ #define INCLUDED_MESSAGE #include "scriptinterface/ScriptTypes.h" -#include "scriptinterface/ScriptVal.h" class CMessage {