1
0
forked from 0ad/0ad

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.
This commit is contained in:
wraitii 2020-11-12 08:24:30 +00:00
parent ace639f96f
commit 90367cdc53
13 changed files with 14 additions and 108 deletions

View File

@ -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 <deque>
#include "glooxwrapper/glooxwrapper.h"
#include "scriptinterface/ScriptVal.h"
class ScriptInterface;

View File

@ -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"

View File

@ -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"

View File

@ -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, '!'

View File

@ -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).

View File

@ -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;

View File

@ -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 <sstream>

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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 <typename T>
class DefPersistentRooted
{
public:
DefPersistentRooted()
{
}
DefPersistentRooted(JSRuntime* rt)
{
m_Val.reset(new JS::PersistentRooted<T>(rt));
}
DefPersistentRooted(JSRuntime* rt, JS::HandleValue val)
{
m_Val.reset(new JS::PersistentRooted<T>(rt, val));
}
DefPersistentRooted(JSContext* cx, JS::Handle<T> val)
{
m_Val.reset(new JS::PersistentRooted<T>(cx, val));
}
void clear()
{
m_Val = nullptr;
}
inline bool uninitialized()
{
return m_Val == nullptr;
}
inline JS::PersistentRooted<T>& get() const
{
ENSURE(m_Val);
return *m_Val;
}
inline void set(JSRuntime* rt, T val)
{
m_Val.reset(new JS::PersistentRooted<T>(rt, val));
}
inline void set(JSContext* cx, T val)
{
m_Val.reset(new JS::PersistentRooted<T>(cx, val));
}
private:
std::unique_ptr<JS::PersistentRooted<T> > m_Val;
};
#endif // INCLUDED_SCRIPTVAL

View File

@ -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"

View File

@ -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);

View File

@ -255,7 +255,7 @@ void CComponentManager::Script_RegisterComponentType_Common(ScriptInterface::CxP
ctWrapper.dealloc,
cname,
schema,
DefPersistentRooted<JS::Value>(cx, ctor)
std::unique_ptr<JS::PersistentRootedValue>(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<JS::Value>() };
ComponentType c{ CT_Native, iid, alloc, dealloc, name, schema, std::unique_ptr<JS::PersistentRootedValue>() };
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<JS::Value>() };
ComponentType c{ CT_ScriptWrapper, iid, alloc, dealloc, name, schema, std::unique_ptr<JS::PersistentRootedValue>() };
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");

View File

@ -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<JS::Value> ctor; // only valid if type == CT_Script
std::unique_ptr<JS::PersistentRootedValue> ctor; // only valid if type == CT_Script
};
public:

View File

@ -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
{