1
0
forked from mirrors/0ad

Split off JSON-related function from ScriptInterface, clean up headers.

Follows 34b1920e7b.

JSON functions and ToString are movec to their own headers.
Also clean out a few PersistentRooted usage to use the 2-phase init to
clean up scriptInterface usage.

With these functions split off, we can finally clean out headers and
remove ScriptInterface.h from most of them, in favour of smaller and
more precise headers.


Take the opportunity to clarify some comments regarding Mutability.

Differential Revision: https://code.wildfiregames.com/D3961
This was SVN commit r25434.
This commit is contained in:
wraitii
2021-05-14 10:18:03 +00:00
parent f368e1a69e
commit 4f972bc623
57 changed files with 396 additions and 280 deletions
+19 -11
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2020 Wildfire Games.
/* Copyright (C) 2021 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,8 @@
#include "NetMessage.h"
#include "lib/utf8.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/JSON.h"
#include "simulation2/serialization/BinarySerializer.h"
#include "simulation2/serialization/StdDeserializer.h"
#include "simulation2/serialization/StdSerializer.h" // for DEBUG_SERIALIZER_ANNOTATE
@@ -110,25 +111,29 @@ public:
};
CSimulationMessage::CSimulationMessage(const ScriptInterface& scriptInterface) :
CNetMessage(NMT_SIMULATION_COMMAND), m_ScriptInterface(scriptInterface), m_Data(scriptInterface.GetGeneralJSContext())
CNetMessage(NMT_SIMULATION_COMMAND), m_ScriptInterface(scriptInterface)
{
ScriptRequest rq(scriptInterface);
m_Data.init(rq.cx);
}
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.GetGeneralJSContext(), data)
m_Client(client), m_Player(player), m_Turn(turn)
{
ScriptRequest rq(scriptInterface);
m_Data.init(rq.cx, data);
}
CSimulationMessage::CSimulationMessage(const CSimulationMessage& orig) :
m_Data(orig.m_ScriptInterface.GetGeneralJSContext()),
m_Client(orig.m_Client),
m_Player(orig.m_Player),
m_ScriptInterface(orig.m_ScriptInterface),
m_Turn(orig.m_Turn),
CNetMessage(orig)
{
m_Data = orig.m_Data;
ScriptRequest rq(m_ScriptInterface);
m_Data.init(rq.cx, orig.m_Data);
}
u8* CSimulationMessage::Serialize(u8* pBuffer) const
@@ -176,7 +181,7 @@ size_t CSimulationMessage::GetSerializedLength() const
CStr CSimulationMessage::ToString() const
{
std::string source = m_ScriptInterface.ToString(const_cast<JS::PersistentRootedValue*>(&m_Data));
std::string source = Script::ToString(ScriptRequest(m_ScriptInterface), const_cast<JS::PersistentRootedValue*>(&m_Data));
std::stringstream stream;
stream << "CSimulationMessage { m_Client: " << m_Client << ", m_Player: " << m_Player << ", m_Turn: " << m_Turn << ", m_Data: " << source << " }";
@@ -185,14 +190,17 @@ CStr CSimulationMessage::ToString() const
CGameSetupMessage::CGameSetupMessage(const ScriptInterface& scriptInterface) :
CNetMessage(NMT_GAME_SETUP), m_ScriptInterface(scriptInterface), m_Data(scriptInterface.GetGeneralJSContext())
CNetMessage(NMT_GAME_SETUP), m_ScriptInterface(scriptInterface)
{
ScriptRequest rq(m_ScriptInterface);
m_Data.init(rq.cx);
}
CGameSetupMessage::CGameSetupMessage(const ScriptInterface& scriptInterface, JS::HandleValue data) :
CNetMessage(NMT_GAME_SETUP), m_ScriptInterface(scriptInterface),
m_Data(scriptInterface.GetGeneralJSContext(), data)
CNetMessage(NMT_GAME_SETUP), m_ScriptInterface(scriptInterface)
{
ScriptRequest rq(m_ScriptInterface);
m_Data.init(rq.cx, data);
}
u8* CGameSetupMessage::Serialize(u8* pBuffer) const
@@ -223,7 +231,7 @@ size_t CGameSetupMessage::GetSerializedLength() const
CStr CGameSetupMessage::ToString() const
{
std::string source = m_ScriptInterface.ToString(const_cast<JS::PersistentRootedValue*>(&m_Data));
std::string source = Script::ToString(ScriptRequest(m_ScriptInterface), const_cast<JS::PersistentRootedValue*>(&m_Data));
std::stringstream stream;
stream << "CGameSetupMessage { m_Data: " << source << " }";