Move Script* classes to Script namespace

- Rename ScriptEngine, ScriptContext, ScriptInterface, ScriptRequest to
  Script::Engine, Script::Context, Script::Interface, Script::Request
- Remove 'Script' prefix from filenames:
  ScriptContext.* → Context.*
  ScriptInterface.* → Interface.*
  ScriptRequest.* → Request.*
  ScriptEngine.* → Engine.*
  ScriptConversions.* → Conversions.*
  ScriptExceptions.* → Exceptions.*
  ScriptForward.* → ForwardDeclarations.*
  ScriptStats.* → Stats.*
- Update all includes, forward declarations, and friend classes
- Use namespace Script { ... } in .cpp definitions to avoid repetitive
  Script:: prefix (keeping global callbacks outside)
- Rename internal implementation structs:
  ScriptInterface_impl → Interface_impl
  ScriptFunction → Function
- Update copyright year to 2026 in all touched files
- Suppress pre-existing cppcheck warnings (uninitvar, nullPointer, unknown
  macro) by adding them to suppressions-list.txt (these are not caused
  by this refactor)

Fixes #7516
This commit is contained in:
vyordan
2026-06-02 15:06:50 -06:00
committed by phosit
parent 310c4bf028
commit ec8b420abc
220 changed files with 2224 additions and 2153 deletions
+18 -18
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -25,14 +25,14 @@
#include "lib/sysdep/os.h"
#include "ps/CLogger.h"
#include "ps/Filesystem.h"
#include "scriptinterface/Context.h"
#include "scriptinterface/Exceptions.h"
#include "scriptinterface/FunctionWrapper.h"
#include "scriptinterface/Interface.h"
#include "scriptinterface/JSON.h"
#include "scriptinterface/ModuleLoader.h"
#include "scriptinterface/Object.h"
#include "scriptinterface/ScriptContext.h"
#include "scriptinterface/ScriptExceptions.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Request.h"
#include <cstddef>
#include <fmt/format.h>
@@ -286,7 +286,7 @@ namespace DAP
bool m_Running{true};
};
Interface::Interface(const std::string serverAddress, int port, ScriptContext& scriptContext)
Interface::Interface(const std::string serverAddress, int port, Script::Context& scriptContext)
: m_SocketImpl{std::make_unique<SocketHandler>(this)},
m_ModuleValue{scriptContext.GetGeneralJSContext()}
{
@@ -299,22 +299,22 @@ namespace DAP
if (!VfsFileExists(fntPath))
throw DapInterfaceNoJSDebuggerException{ fmt::format("DAP entry script not found at {}", fntPath.string8().c_str())};
m_ScriptInterface = std::make_unique<ScriptInterface>("Engine", "Debugger", scriptContext, [](const VfsPath& path) {
m_ScriptInterface = std::make_unique<Script::Interface>("Engine", "Debugger", scriptContext, [](const VfsPath& path) {
return path.string8().find("tools/dap/") == 0;
});
m_ScriptInterface->SetCallbackData(this);
ScriptRequest rq(m_ScriptInterface.get());
Script::Request rq(m_ScriptInterface.get());
if (!JS_DefineDebuggerObject(rq.cx, rq.glob))
{
ScriptException::CatchPending(rq);
Script::Exception::CatchPending(rq);
throw DapInterfaceNoJSDebuggerException{"Failed to define debugger object"};
}
// Register methods.
constexpr ScriptFunction::ObjectGetter<DAP::Interface> Getter{&ScriptInterface::ObjectFromCBData<DAP::Interface>};
ScriptFunction::Register<&DAP::Interface::WaitForMessage, Getter>(rq, "WaitForMessage");
ScriptFunction::Register<&DAP::Interface::EndWaitingForMessage, Getter>(rq, "EndWaitingForMessage");
constexpr Script::Function::ObjectGetter<DAP::Interface> Getter{&Script::Interface::ObjectFromCBData<DAP::Interface>};
Script::Function::Register<&DAP::Interface::WaitForMessage, Getter>(rq, "WaitForMessage");
Script::Function::Register<&DAP::Interface::EndWaitingForMessage, Getter>(rq, "EndWaitingForMessage");
auto result{m_ScriptInterface->GetModuleLoader().LoadModule(rq, fntPath)};
@@ -336,12 +336,12 @@ namespace DAP
bool Interface::isJSHandlerDefined()
{
ScriptRequest rq{m_ScriptInterface.get()};
Script::Request rq{m_ScriptInterface.get()};
JS::RootedValue handler{rq.cx};
if (!Script::GetProperty(rq, m_ModuleValue, "handleMessage", &handler))
{
ScriptException::CatchPending(rq);
Script::Exception::CatchPending(rq);
return false;
}
@@ -365,7 +365,7 @@ namespace DAP
std::string Interface::OnMessage(const std::string& message)
{
ScriptRequest rq{m_ScriptInterface.get()};
Script::Request rq{m_ScriptInterface.get()};
JS::RootedValue msg{rq.cx};
if (!Script::ParseJSON(rq, message, &msg))
@@ -375,7 +375,7 @@ namespace DAP
}
JS::RootedValue rval{rq.cx};
if (!ScriptFunction::Call(rq, m_ModuleValue, "handleMessage", &rval, msg))
if (!Script::Function::Call(rq, m_ModuleValue, "handleMessage", &rval, msg))
{
LOGERROR("Failed to call message handler");
return "";
@@ -386,13 +386,13 @@ namespace DAP
void Interface::SendEventToClient()
{
ScriptRequest rq{m_ScriptInterface.get()};
Script::Request rq{m_ScriptInterface.get()};
JS::RootedValue global{rq.cx, rq.globalValue()};
JS::RootedValue rval{rq.cx};
while (true)
{
if (!ScriptFunction::Call(rq, m_ModuleValue, "sendEventToClient", &rval))
if (!Script::Function::Call(rq, m_ModuleValue, "sendEventToClient", &rval))
{
LOGERROR("Failed to call sendEventToClient");
return;
+5 -5
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -29,8 +29,8 @@
#include <stdexcept>
#include <string>
class ScriptContext;
class ScriptInterface;
namespace Script { class Context; }
namespace Script { class Interface; }
namespace DAP
{
@@ -52,7 +52,7 @@ namespace DAP
class Interface
{
public:
Interface(const std::string server_address, int port, ScriptContext& scriptContext);
Interface(const std::string server_address, int port, Script::Context& scriptContext);
~Interface();
NONCOPYABLE(Interface);
@@ -70,7 +70,7 @@ namespace DAP
void SendEventToClient();
std::unique_ptr<SocketHandler> m_SocketImpl;
std::unique_ptr<ScriptInterface> m_ScriptInterface;
std::unique_ptr<Script::Interface> m_ScriptInterface;
std::string m_DapRequest;
std::string m_DapResponse;
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 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 "lib/path.h"
#include "ps/CLogger.h"
#include "ps/Filesystem.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/Interface.h"
#include <fmt/format.h>
#include <memory>
+18 -18
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -41,10 +41,10 @@
#include "scriptinterface/JSON.h"
#include "scriptinterface/ModuleLoader.h"
#include "scriptinterface/Object.h"
#include "scriptinterface/ScriptContext.h"
#include "scriptinterface/ScriptConversions.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Context.h"
#include "scriptinterface/Conversions.h"
#include "scriptinterface/Interface.h"
#include "scriptinterface/Request.h"
#include "simulation2/helpers/MapEdgeTiles.h"
#include "simulation2/system/Component.h"
@@ -78,7 +78,7 @@ class CMapGenerationCallbacks
public:
// Only the constructor and the destructor are called by C++.
CMapGenerationCallbacks(const StopToken stopToken, ScriptInterface& scriptInterface,
CMapGenerationCallbacks(const StopToken stopToken, Script::Interface& scriptInterface,
const u16 flags) :
m_StopToken{stopToken},
m_ScriptInterface{scriptInterface}
@@ -92,8 +92,8 @@ public:
// Set initial seed, callback data.
// Expose functions, globals and classes relevant to the map scripts.
#define REGISTER_MAPGEN_FUNC(func) \
ScriptFunction::Register<&CMapGenerationCallbacks::func, \
ScriptInterface::ObjectFromCBData<CMapGenerationCallbacks>>(rq, #func, flags);
Script::Function::Register<&CMapGenerationCallbacks::func, \
Script::Interface::ObjectFromCBData<CMapGenerationCallbacks>>(rq, #func, flags);
// VFS
JSI_VFS::RegisterScriptFunctions_ReadOnlySimulationMaps(m_ScriptInterface, flags);
@@ -102,7 +102,7 @@ public:
m_ScriptInterface.LoadGlobalScripts();
// File loading
ScriptRequest rq(m_ScriptInterface);
Script::Request rq(m_ScriptInterface);
REGISTER_MAPGEN_FUNC(LoadLibrary);
REGISTER_MAPGEN_FUNC(LoadHeightmapImage);
REGISTER_MAPGEN_FUNC(LoadMapTerrain);
@@ -200,7 +200,7 @@ private:
return JS::UndefinedValue();
}
ScriptRequest rq(m_ScriptInterface);
Script::Request rq(m_ScriptInterface);
JS::RootedValue returnValue(rq.cx);
Script::ToJSVal(rq, &returnValue, heightmap);
return returnValue;
@@ -213,7 +213,7 @@ private:
*/
JS::Value LoadMapTerrain(const VfsPath& filename)
{
ScriptRequest rq(m_ScriptInterface);
Script::Request rq(m_ScriptInterface);
if (!VfsFileExists(filename))
{
@@ -332,7 +332,7 @@ private:
/**
* Provides the script context.
*/
ScriptInterface& m_ScriptInterface;
Script::Interface& m_ScriptInterface;
/**
* Currently loaded script librarynames.
@@ -347,15 +347,15 @@ private:
bool MapGenerationInterruptCallback(JSContext* cx)
{
return !ScriptInterface::ObjectFromCBData<CMapGenerationCallbacks>(
ScriptInterface::CmptPrivate::GetScriptInterface(cx))->m_StopToken.IsStopRequested();
return !Script::Interface::ObjectFromCBData<CMapGenerationCallbacks>(
Script::Interface::CmptPrivate::GetScriptInterface(cx))->m_StopToken.IsStopRequested();
}
} // anonymous namespace
Script::StructuredClone RunMapGenerationScript(const StopToken stopToken, std::atomic<int>& progress,
ScriptInterface& scriptInterface, const VfsPath& script, const std::string& settings, const u16 flags)
Script::Interface& scriptInterface, const VfsPath& script, const std::string& settings, const u16 flags)
{
ScriptRequest rq(scriptInterface);
Script::Request rq(scriptInterface);
// Parse settings
JS::RootedValue settingsVal(rq.cx);
@@ -421,7 +421,7 @@ Script::StructuredClone RunMapGenerationScript(const StopToken stopToken, std::a
LOGMESSAGE("Run RMS generator");
JS::RootedValue ns{rq.cx, JS::ObjectValue(*nsAsObject)};
JS::RootedValue map{rq.cx, ScriptFunction::RunGenerator(rq, ns, GENERATOR_NAME, settingsVal,
JS::RootedValue map{rq.cx, Script::Function::RunGenerator(rq, ns, GENERATOR_NAME, settingsVal,
[&](const JS::HandleValue value)
{
// When the task is started, `progress` is only mutated by this thread.
@@ -440,6 +440,6 @@ Script::StructuredClone RunMapGenerationScript(const StopToken stopToken, std::a
})};
JS::RootedValue exportedMap{rq.cx};
const bool exportSuccess{ScriptFunction::Call(rq, map, "MakeExportable", &exportedMap)};
const bool exportSuccess{Script::Function::Call(rq, map, "MakeExportable", &exportedMap)};
return Script::WriteStructuredClone(rq, exportSuccess ? exportedMap : map);
}
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -27,8 +27,8 @@
#include <string>
#include <string_view>
class ScriptInterface;
class StopToken;
namespace Script { class Interface; }
constexpr std::wstring_view RANDOM_MAP_PREFIX{L"maps/random/"};
@@ -48,7 +48,7 @@ constexpr std::wstring_view RANDOM_MAP_PREFIX{L"maps/random/"};
* https://gitea.wildfiregames.com/0ad/0ad/wiki/Random_Map_Generator_Internals#Dataformat
*/
Script::StructuredClone RunMapGenerationScript(const StopToken stopToken, std::atomic<int>& progress,
ScriptInterface& scriptInterface, const VfsPath& script, const std::string& settings,
Script::Interface& scriptInterface, const VfsPath& script, const std::string& settings,
const u16 flags = JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
#endif //INCLUDED_MAPGENERATOR
+16 -16
View File
@@ -55,9 +55,9 @@
#include "renderer/WaterManager.h"
#include "scriptinterface/JSON.h"
#include "scriptinterface/Object.h"
#include "scriptinterface/ScriptContext.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Context.h"
#include "scriptinterface/Interface.h"
#include "scriptinterface/Request.h"
#include "scriptinterface/StructuredClone.h"
#include "simulation2/Simulation2.h"
#include "simulation2/components/ICmpCinemaManager.h"
@@ -98,7 +98,7 @@ constexpr int MAP_GENERATION_CONTEXT_SIZE{96 * MiB};
CMapReader::CMapReader() = default;
// LoadMap: try to load the map from given file; reinitialise the scene to new data if successful
void CMapReader::LoadMap(const VfsPath& pathname, const ScriptContext& cx, JS::HandleValue settings, CTerrain *pTerrain_,
void CMapReader::LoadMap(const VfsPath& pathname, const Script::Context& cx, JS::HandleValue settings, CTerrain *pTerrain_,
WaterManager* pWaterMan_, SkyManager* pSkyMan_,
CLightEnv *pLightEnv_, CGameView *pGameView_, CCinemaManager* pCinema_, CTriggerManager* pTrigMan_, CPostprocManager* pPostproc_,
CSimulation2 *pSimulation2_, const CSimContext* pSimContext_, int playerID_, bool skipEntities)
@@ -207,7 +207,7 @@ void CMapReader::LoadMap(const VfsPath& pathname, const ScriptContext& cx, JS::
}
// LoadRandomMap: try to load the map data; reinitialise the scene to new data if successful
void CMapReader::LoadRandomMap(const CStrW& scriptFile, const ScriptContext& cx, JS::HandleValue settings, CTerrain *pTerrain_,
void CMapReader::LoadRandomMap(const CStrW& scriptFile, const Script::Context& cx, JS::HandleValue settings, CTerrain *pTerrain_,
WaterManager* pWaterMan_, SkyManager* pSkyMan_,
CLightEnv *pLightEnv_, CGameView *pGameView_, CCinemaManager* pCinema_, CTriggerManager* pTrigMan_, CPostprocManager* pPostproc_,
CSimulation2 *pSimulation2_, int playerID_)
@@ -449,9 +449,9 @@ PSRETURN CMapSummaryReader::LoadMap(const VfsPath& pathname)
return PSRETURN_OK;
}
void CMapSummaryReader::GetMapSettings(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret)
void CMapSummaryReader::GetMapSettings(const Script::Interface& scriptInterface, JS::MutableHandleValue ret)
{
ScriptRequest rq(scriptInterface);
Script::Request rq(scriptInterface);
Script::CreateObject(rq, ret);
@@ -1312,7 +1312,7 @@ PS::Loader::Task CMapReader::RunMapGeneration(const CStrW& scriptFile)
// The settings are stringified to pass them to the task.
Future<Script::StructuredClone> task = {g_TaskManager,
[&progress, scriptFile, settings = Script::StringifyJSON(ScriptRequest{
[&progress, scriptFile, settings = Script::StringifyJSON(Script::Request{
pSimulation2->GetScriptInterface()}, &m_ScriptSettings)](const StopToken stopToken)
{
PROFILE2("Map Generation");
@@ -1320,8 +1320,8 @@ PS::Loader::Task CMapReader::RunMapGeneration(const CStrW& scriptFile)
const VfsPath scriptPath{scriptFile.empty() ? L"" :
static_cast<std::wstring>(RANDOM_MAP_PREFIX) + scriptFile};
ScriptContext mapgenContext{MAP_GENERATION_CONTEXT_SIZE};
ScriptInterface mapgenInterface{"Engine", "MapGenerator", mapgenContext,
Script::Context mapgenContext{MAP_GENERATION_CONTEXT_SIZE};
Script::Interface mapgenInterface{"Engine", "MapGenerator", mapgenContext,
[](const VfsPath& path){
// Only allow to load modules inside the maps folder.
return path.string().find(RANDOM_MAP_PREFIX) == 0;
@@ -1347,7 +1347,7 @@ PS::Loader::Task CMapReader::RunMapGeneration(const CStrW& scriptFile)
ThrowMapGenerationError();
// Parse data into simulation context
ScriptRequest rq(pSimulation2->GetScriptInterface());
Script::Request rq(pSimulation2->GetScriptInterface());
JS::RootedValue data{rq.cx};
Script::ReadStructuredClone(rq, results, &data);
@@ -1363,7 +1363,7 @@ PS::Loader::Task CMapReader::RunMapGeneration(const CStrW& scriptFile)
int CMapReader::ParseTerrain()
{
PROFILE2("ParseTerrain");
ScriptRequest rq(pSimulation2->GetScriptInterface());
Script::Request rq(pSimulation2->GetScriptInterface());
// parse terrain from map data
// an error here should stop the loading process
@@ -1436,7 +1436,7 @@ int CMapReader::ParseTerrain()
struct ParseEntitiesState
{
ScriptRequest rq;
Script::Request rq;
CmpPtr<ICmpPlayerManager> cmpPlayerManager;
std::vector<Entity> entities;
size_t currentEntityIndex{0};
@@ -1450,7 +1450,7 @@ PS::Loader::Task CMapReader::ParseEntities()
PROFILE2("ParseEntities");
CSimulation2& sim{*pSimulation2};
ScriptRequest rq{sim.GetScriptInterface()};
Script::Request rq{sim.GetScriptInterface()};
CmpPtr<ICmpPlayerManager> cmpPlayerManager{sim, SYSTEM_ENTITY};
std::vector<Entity> entities;
@@ -1509,7 +1509,7 @@ PS::Loader::Task CMapReader::ParseEntities()
int CMapReader::ParseEnvironment()
{
// parse environment settings from map data
ScriptRequest rq(pSimulation2->GetScriptInterface());
Script::Request rq(pSimulation2->GetScriptInterface());
const auto getEnvironmentProperty = [&](JS::HandleValue val, const char* prop, auto&& out)
{
@@ -1603,7 +1603,7 @@ int CMapReader::ParseEnvironment()
int CMapReader::ParseCamera()
{
ScriptRequest rq(pSimulation2->GetScriptInterface());
Script::Request rq(pSimulation2->GetScriptInterface());
// parse camera settings from map data
// defaults if we don't find player starting camera
+6 -6
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -47,10 +47,10 @@ class CTerrain;
class CTerrainTextureEntry;
class CTriggerManager;
class CXMLReader;
class ScriptContext;
class ScriptInterface;
class SkyManager;
class WaterManager;
namespace Script { class Context; }
namespace Script { class Interface; }
class CMapReader : public CMapIO
{
@@ -66,11 +66,11 @@ public:
~CMapReader();
// LoadMap: try to load the map from given file; reinitialise the scene to new data if successful
void LoadMap(const VfsPath& pathname, const ScriptContext& cx, JS::HandleValue settings, CTerrain*, WaterManager*, SkyManager*, CLightEnv*, CGameView*,
void LoadMap(const VfsPath& pathname, const Script::Context& cx, JS::HandleValue settings, CTerrain*, WaterManager*, SkyManager*, CLightEnv*, CGameView*,
CCinemaManager*, CTriggerManager*, CPostprocManager* pPostproc, CSimulation2*, const CSimContext*,
int playerID, bool skipEntities);
void LoadRandomMap(const CStrW& scriptFile, const ScriptContext& cx, JS::HandleValue settings, CTerrain*, WaterManager*, SkyManager*, CLightEnv*, CGameView*, CCinemaManager*, CTriggerManager*, CPostprocManager* pPostproc_, CSimulation2*, int playerID);
void LoadRandomMap(const CStrW& scriptFile, const Script::Context& cx, JS::HandleValue settings, CTerrain*, WaterManager*, SkyManager*, CLightEnv*, CGameView*, CCinemaManager*, CTriggerManager*, CPostprocManager* pPostproc_, CSimulation2*, int playerID);
private:
// Load script settings for use by scripts
@@ -176,7 +176,7 @@ public:
* }
* @endcode
*/
void GetMapSettings(const ScriptInterface& scriptInterface, JS::MutableHandleValue);
void GetMapSettings(const Script::Interface& scriptInterface, JS::MutableHandleValue);
private:
CStr m_ScriptSettings;
+1 -1
View File
@@ -44,7 +44,7 @@
#include "renderer/PostprocManager.h"
#include "renderer/SkyManager.h"
#include "renderer/WaterManager.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/Interface.h"
#include "simulation2/Simulation2.h"
#include "simulation2/components/ICmpCinemaManager.h"
#include "simulation2/components/ICmpGarrisonHolder.h"
+2 -2
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -29,7 +29,7 @@
#include "ps/Filesystem.h"
#include "ps/Profiler2.h"
#include "ps/XML/Xeromyces.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/Interface.h"
#include "simulation2/Simulation2.h"
#include "simulation2/components/ICmpTerrain.h"
#include "simulation2/components/ICmpVisual.h"
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -30,7 +30,7 @@
#include "ps/World.h"
#include "scriptinterface/FunctionWrapper.h"
#include "scriptinterface/Object.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Request.h"
#include "simulation2/helpers/Position.h"
#include "simulation2/system/Entity.h"
@@ -69,10 +69,10 @@ IMPLEMENT_BOOLEAN_SCRIPT_SETTING(ConstrainCamera);
#define REGISTER_BOOLEAN_SCRIPT_SETTING(NAME) \
ScriptFunction::Register<&Get##NAME##Enabled>(rq, "GameView_Get" #NAME "Enabled"); \
ScriptFunction::Register<&Set##NAME##Enabled>(rq, "GameView_Set" #NAME "Enabled");
Script::Function::Register<&Get##NAME##Enabled>(rq, "GameView_Get" #NAME "Enabled"); \
Script::Function::Register<&Set##NAME##Enabled>(rq, "GameView_Set" #NAME "Enabled");
void RegisterScriptFunctions_Settings(const ScriptRequest& rq)
void RegisterScriptFunctions_Settings(const Script::Request& rq)
{
REGISTER_BOOLEAN_SCRIPT_SETTING(Culling);
REGISTER_BOOLEAN_SCRIPT_SETTING(LockCullCamera);
@@ -81,7 +81,7 @@ void RegisterScriptFunctions_Settings(const ScriptRequest& rq)
#undef REGISTER_BOOLEAN_SCRIPT_SETTING
JS::Value GetCameraRotation(const ScriptRequest& rq)
JS::Value GetCameraRotation(const Script::Request& rq)
{
if (!g_Game || !g_Game->GetView())
return JS::UndefinedValue();
@@ -99,7 +99,7 @@ JS::Value GetCameraZoom()
return JS::NumberValue(g_Game->GetView()->GetCameraZoom());
}
JS::Value GetCameraPivot(const ScriptRequest& rq)
JS::Value GetCameraPivot(const Script::Request& rq)
{
if (!g_Game || !g_Game->GetView())
return JS::UndefinedValue();
@@ -110,7 +110,7 @@ JS::Value GetCameraPivot(const ScriptRequest& rq)
return pivotValue;
}
JS::Value GetCameraPosition(const ScriptRequest& rq)
JS::Value GetCameraPosition(const Script::Request& rq)
{
if (!g_Game || !g_Game->GetView())
return JS::UndefinedValue();
@@ -200,20 +200,20 @@ CFixedVector3D GetTerrainAtScreenPoint(int x, int y)
return CFixedVector3D(fixed::FromFloat(pos.X), fixed::FromFloat(pos.Y), fixed::FromFloat(pos.Z));
}
void RegisterScriptFunctions(const ScriptRequest& rq)
void RegisterScriptFunctions(const Script::Request& rq)
{
RegisterScriptFunctions_Settings(rq);
ScriptFunction::Register<&GetCameraRotation>(rq, "GetCameraRotation");
ScriptFunction::Register<&GetCameraZoom>(rq, "GetCameraZoom");
ScriptFunction::Register<&GetCameraPivot>(rq, "GetCameraPivot");
ScriptFunction::Register<&GetCameraPosition>(rq, "GetCameraPosition");
ScriptFunction::Register<&CameraMoveTo>(rq, "CameraMoveTo");
ScriptFunction::Register<&SetCameraTarget>(rq, "SetCameraTarget");
ScriptFunction::Register<&SetCameraData>(rq, "SetCameraData");
ScriptFunction::Register<&CameraFollow>(rq, "CameraFollow");
ScriptFunction::Register<&CameraFollowFPS>(rq, "CameraFollowFPS");
ScriptFunction::Register<&GetFollowedEntity>(rq, "GetFollowedEntity");
ScriptFunction::Register<&GetTerrainAtScreenPoint>(rq, "GetTerrainAtScreenPoint");
Script::Function::Register<&GetCameraRotation>(rq, "GetCameraRotation");
Script::Function::Register<&GetCameraZoom>(rq, "GetCameraZoom");
Script::Function::Register<&GetCameraPivot>(rq, "GetCameraPivot");
Script::Function::Register<&GetCameraPosition>(rq, "GetCameraPosition");
Script::Function::Register<&CameraMoveTo>(rq, "CameraMoveTo");
Script::Function::Register<&SetCameraTarget>(rq, "SetCameraTarget");
Script::Function::Register<&SetCameraData>(rq, "SetCameraData");
Script::Function::Register<&CameraFollow>(rq, "CameraFollow");
Script::Function::Register<&CameraFollowFPS>(rq, "CameraFollowFPS");
Script::Function::Register<&GetFollowedEntity>(rq, "GetFollowedEntity");
Script::Function::Register<&GetTerrainAtScreenPoint>(rq, "GetTerrainAtScreenPoint");
}
}
@@ -1,4 +1,4 @@
/* Copyright (C) 2019 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -18,11 +18,11 @@
#ifndef INCLUDED_JSINTERFACE_GAMEVIEW
#define INCLUDED_JSINTERFACE_GAMEVIEW
class ScriptRequest;
namespace Script { class Request; }
namespace JSI_GameView
{
void RegisterScriptFunctions(const ScriptRequest& rq);
void RegisterScriptFunctions(const Script::Request& rq);
}
#endif // INCLUDED_JSINTERFACE_GAMEVIEW
+1 -1
View File
@@ -22,7 +22,7 @@
#include "lib/posix/posix_types.h"
#include "lib/timer.h"
#include "lib/types.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/Interface.h"
#include "simulation2/Simulation2.h"
#include "simulation2/helpers/Grid.h"
#include "simulation2/helpers/Los.h"
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 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 "ps/Filesystem.h"
#include "ps/Future.h"
#include "ps/XML/Xeromyces.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/Interface.h"
#include "scriptinterface/StructuredClone.h"
#include <atomic>
@@ -66,7 +66,7 @@ public:
for (const VfsPath& path : paths)
{
TestLogger logger;
ScriptInterface scriptInterface{"Engine", "MapGenerator", g_ScriptContext,
Script::Interface scriptInterface{"Engine", "MapGenerator", g_ScriptContext,
[](const VfsPath& path){
return path.string().find(RANDOM_MAP_PREFIX) == 0;
}};
+1 -1
View File
@@ -50,7 +50,7 @@
#include "ps/VideoMode.h"
#include "ps/XML/Xeromyces.h"
#include "renderer/Renderer.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/Interface.h"
#include "simulation2/Simulation2.h"
#include "simulation2/system/Entity.h"
+15 -15
View File
@@ -52,9 +52,9 @@
#include "renderer/backend/Sampler.h"
#include "scriptinterface/FunctionWrapper.h"
#include "scriptinterface/Object.h"
#include "scriptinterface/ScriptExceptions.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Exceptions.h"
#include "scriptinterface/Interface.h"
#include "scriptinterface/Request.h"
#include <algorithm>
#include <js/CallAndConstruct.h>
@@ -88,13 +88,13 @@ const CStr CGUI::EventNameMouseLeftRelease = "MouseLeftRelease";
const CStr CGUI::EventNameMouseRightDoubleClick = "MouseRightDoubleClick";
const CStr CGUI::EventNameMouseRightRelease = "MouseRightRelease";
CGUI::CGUI(ScriptContext& context)
CGUI::CGUI(Script::Context& context)
: m_BaseObject(std::make_unique<CGUIDummyObject>(*this)),
m_FocusedObject(nullptr),
m_InternalNameNumber(0),
m_MouseButtons(0)
{
m_ScriptInterface = std::make_shared<ScriptInterface>("Engine", "GUIPage", context,
m_ScriptInterface = std::make_shared<Script::Interface>("Engine", "GUIPage", context,
[](const VfsPath& path){
return path.string8().find("gui/") == 0;
});
@@ -124,11 +124,11 @@ Input::Reaction CGUI::HandleEvent(const SDL_Event& ev)
{
ret = Input::Reaction::HANDLED;
ScriptRequest rq(m_ScriptInterface);
Script::Request rq(m_ScriptInterface);
JS::RootedObject globalObj(rq.cx, rq.glob);
JS::RootedValue result(rq.cx);
if (!JS_CallFunctionValue(rq.cx, globalObj, m_GlobalHotkeys[hotkey][eventName], JS::HandleValueArray::empty(), &result))
ScriptException::CatchPending(rq);
Script::Exception::CatchPending(rq);
}
std::map<CStr, std::vector<IGUIObject*> >::iterator it = m_HotkeyObjects.find(hotkey);
@@ -297,16 +297,16 @@ Input::Reaction CGUI::HandleEvent(const SDL_Event& ev)
return ret;
}
JS::Value CGUI::GetHotloadData(const ScriptRequest& rq)
JS::Value CGUI::GetHotloadData(const Script::Request& rq)
{
JS::RootedValue oldNamespace{rq.cx, m_LoadModuleResult.has_value() ?
JS::ObjectValue(*m_LoadModuleResult->moduleNamespace) : rq.globalValue()};
JS::RootedValue hotloadDataVal(rq.cx);
ScriptFunction::Call(rq, oldNamespace, "getHotloadData", &hotloadDataVal);
Script::Function::Call(rq, oldNamespace, "getHotloadData", &hotloadDataVal);
return hotloadDataVal;
}
JSObject* CGUI::CallPageInit(const ScriptRequest& rq, Script::StructuredClone initData,
JSObject* CGUI::CallPageInit(const Script::Request& rq, Script::StructuredClone initData,
JS::HandleValue hotloadDataVal, const std::string_view scriptName)
{
JS::RootedValue initDataVal{rq.cx};
@@ -319,7 +319,7 @@ JSObject* CGUI::CallPageInit(const ScriptRequest& rq, Script::StructuredClone in
return nullptr;
JS::RootedValue returnValue{rq.cx};
if (!ScriptFunction::Call(rq, newNamespace, "init", &returnValue, initDataVal, hotloadDataVal))
if (!Script::Function::Call(rq, newNamespace, "init", &returnValue, initDataVal, hotloadDataVal))
{
LOGERROR("GUI page '%s': Failed to call init() function", scriptName);
return nullptr;
@@ -335,7 +335,7 @@ JSObject* CGUI::CallPageInit(const ScriptRequest& rq, Script::StructuredClone in
return returnObject;
}
JSObject* CGUI::TickObjects(const ScriptRequest& rq, Script::StructuredClone initData,
JSObject* CGUI::TickObjects(const Script::Request& rq, Script::StructuredClone initData,
const std::string_view scriptName)
{
JS::RootedObject sendingPromise{rq.cx};
@@ -522,7 +522,7 @@ void CGUI::UnsetObjectHotkey(IGUIObject& object, const CStr& hotkeyTag)
void CGUI::SetGlobalHotkey(const CStr& hotkeyTag, const CStr& eventName, JS::HandleValue function)
{
ScriptRequest rq(*m_ScriptInterface);
Script::Request rq(*m_ScriptInterface);
if (hotkeyTag.empty())
throw std::invalid_argument{"Cannot assign a function to an empty hotkey identifier!"};
@@ -991,7 +991,7 @@ void CGUI::Xeromyces_ReadScript(const XMBData& xmb, XMBElement element, std::uno
if (m_LoadModuleResult.has_value())
throw std::logic_error{"There can only be one root module per page."};
const ScriptRequest rq{m_ScriptInterface};
const Script::Request rq{m_ScriptInterface};
m_LoadModuleResult.emplace(rq, moduleAttribute);
}
@@ -1367,7 +1367,7 @@ void CGUI::Xeromyces_ReadColor(const XMBData& xmb, XMBElement element)
LOGERROR("GUI: Unable to create custom color '%s'. Invalid color syntax.", name.c_str());
}
CGUI::ModuleArtifact::ModuleArtifact(const ScriptRequest& rq, VfsPath filename):
CGUI::ModuleArtifact::ModuleArtifact(const Script::Request& rq, VfsPath filename):
result{rq, std::move(filename)},
moduleNamespace{rq.cx}
{}
+10 -10
View File
@@ -59,14 +59,14 @@ class CSize2D;
class GUIProxyProps;
class IGUIObject;
class JSObject;
class ScriptContext;
class ScriptInterface;
class ScriptRequest;
class XMBData;
class XMBElement;
namespace JS { class HandleValueArray; }
namespace JS { class Value; }
namespace js { class BaseProxyHandler; }
namespace Script { class Context; }
namespace Script { class Interface; }
namespace Script { class Request; }
struct SGUIImageEffects;
union SDL_Event;
@@ -86,7 +86,7 @@ private:
using ConstructObjectFunction = std::unique_ptr<IGUIObject> (*)(CGUI&);
public:
CGUI(ScriptContext& context);
CGUI(Script::Context& context);
~CGUI();
/**
@@ -94,16 +94,16 @@ public:
*/
void AddObjectTypes();
JS::Value GetHotloadData(const ScriptRequest& rq);
JS::Value GetHotloadData(const Script::Request& rq);
JSObject* CallPageInit(const ScriptRequest& rq, Script::StructuredClone initDataVal,
JSObject* CallPageInit(const Script::Request& rq, Script::StructuredClone initDataVal,
JS::HandleValue hotloadDataVal, const std::string_view scriptName);
/**
* Performs processing that should happen every frame
* (including sending the "Tick" event to scripts)
*/
JSObject* TickObjects(const ScriptRequest& rq, Script::StructuredClone initData,
JSObject* TickObjects(const Script::Request& rq, Script::StructuredClone initData,
const std::string_view scriptName);
/**
@@ -286,7 +286,7 @@ public:
GUIProxyProps* GetProxyData(const js::BaseProxyHandler* ptr) { return m_ProxyData.at(ptr).get(); }
std::shared_ptr<ScriptInterface> GetScriptInterface() { return m_ScriptInterface; };
std::shared_ptr<Script::Interface> GetScriptInterface() { return m_ScriptInterface; };
private:
/**
@@ -596,7 +596,7 @@ private:
//--------------------------------------------------------
//@{
std::shared_ptr<ScriptInterface> m_ScriptInterface;
std::shared_ptr<Script::Interface> m_ScriptInterface;
/**
* don't want to pass this around with the
@@ -728,7 +728,7 @@ private:
public:
struct ModuleArtifact
{
ModuleArtifact(const ScriptRequest& rq, VfsPath filename);
ModuleArtifact(const Script::Request& rq, VfsPath filename);
Script::ModuleLoader::Result result;
Script::ModuleLoader::Result::iterator iterator{result.begin()};
+7 -7
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -30,7 +30,7 @@
#include "maths/Vector2D.h"
#include "ps/CLogger.h"
#include "ps/CStr.h"
#include "scriptinterface/ScriptConversions.h"
#include "scriptinterface/Conversions.h"
#include <js/RootingAPI.h>
@@ -59,9 +59,9 @@ bool IGUISetting::FromString(const CStrW& value, const bool sendMessage)
}
/**
* Parses the given JS::Value using ScriptInterface::FromJSVal and assigns it to the setting data.
* Parses the given JS::Value using Script::Interface::FromJSVal and assigns it to the setting data.
*/
bool IGUISetting::FromJSVal(const ScriptRequest& rq, JS::HandleValue value, const bool sendMessage)
bool IGUISetting::FromJSVal(const Script::Request& rq, JS::HandleValue value, const bool sendMessage)
{
if (!DoFromJSVal(rq, value))
return false;
@@ -82,7 +82,7 @@ bool CGUISimpleSetting<T>::DoFromString(const CStrW& value)
};
template<>
bool CGUISimpleSetting<CGUIColor>::DoFromJSVal(const ScriptRequest& rq, JS::HandleValue value)
bool CGUISimpleSetting<CGUIColor>::DoFromJSVal(const Script::Request& rq, JS::HandleValue value)
{
if (value.isString())
{
@@ -101,13 +101,13 @@ bool CGUISimpleSetting<CGUIColor>::DoFromJSVal(const ScriptRequest& rq, JS::Hand
};
template<typename T>
bool CGUISimpleSetting<T>::DoFromJSVal(const ScriptRequest& rq, JS::HandleValue value)
bool CGUISimpleSetting<T>::DoFromJSVal(const Script::Request& rq, JS::HandleValue value)
{
return Script::FromJSVal<T>(rq, value, m_Setting);
};
template<typename T>
void CGUISimpleSetting<T>::ToJSVal(const ScriptRequest& rq, JS::MutableHandleValue value)
void CGUISimpleSetting<T>::ToJSVal(const Script::Request& rq, JS::MutableHandleValue value)
{
Script::ToJSVal<T>(rq, value, m_Setting);
};
+6 -6
View File
@@ -26,7 +26,7 @@
#include <utility>
class IGUIObject;
class ScriptRequest;
namespace Script { class Request; }
/**
* This setting interface allows GUI objects to call setting function functions without having to know the setting type.
@@ -47,12 +47,12 @@ public:
/**
* Parses the given JS::Value using Script::FromJSVal and assigns it to the setting data.
*/
bool FromJSVal(const ScriptRequest& rq, JS::HandleValue value, const bool sendMessage);
bool FromJSVal(const Script::Request& rq, JS::HandleValue value, const bool sendMessage);
/**
* Converts the setting data to a JS::Value using Script::ToJSVal.
*/
virtual void ToJSVal(const ScriptRequest& rq, JS::MutableHandleValue value) = 0;
virtual void ToJSVal(const Script::Request& rq, JS::MutableHandleValue value) = 0;
protected:
IGUISetting(IGUISetting&& other);
@@ -61,7 +61,7 @@ protected:
virtual ~IGUISetting() = default;
virtual bool DoFromString(const CStrW& value) = 0;
virtual bool DoFromJSVal(const ScriptRequest& rq, JS::HandleValue value) = 0;
virtual bool DoFromJSVal(const Script::Request& rq, JS::HandleValue value) = 0;
/**
* Triggers the IGUIObject logic when a setting changes.
@@ -124,8 +124,8 @@ public:
protected:
bool DoFromString(const CStrW& value) override;
bool DoFromJSVal(const ScriptRequest& rq, JS::HandleValue value) override;
void ToJSVal(const ScriptRequest& rq, JS::MutableHandleValue value) override;
bool DoFromJSVal(const Script::Request& rq, JS::HandleValue value) override;
void ToJSVal(const Script::Request& rq, JS::MutableHandleValue value) override;
T m_Setting;
};
+22 -22
View File
@@ -37,10 +37,10 @@
#include "ps/containers/StaticVector.h"
#include "scriptinterface/FunctionWrapper.h"
#include "scriptinterface/Object.h"
#include "scriptinterface/ScriptContext.h"
#include "scriptinterface/ScriptConversions.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Context.h"
#include "scriptinterface/Conversions.h"
#include "scriptinterface/Interface.h"
#include "scriptinterface/Request.h"
#include "scriptinterface/StructuredClone.h"
#include "simulation2/system/Component.h"
@@ -90,7 +90,7 @@ static Status ReloadChangedFileCB(void* param, const VfsPath& path)
return static_cast<CGUIManager*>(param)->ReloadChangedFile(path);
}
CGUIManager::CGUIManager(ScriptContext& scriptContext, ScriptInterface& scriptInterface) :
CGUIManager::CGUIManager(Script::Context& scriptContext, Script::Interface& scriptInterface) :
m_ScriptContext{scriptContext},
m_ScriptInterface{scriptInterface},
m_InputHandler{g_VideoMode.m_InputManager, Input::Slot::GUI, {*this}}
@@ -116,7 +116,7 @@ size_t CGUIManager::GetPageCount() const
return m_PageStack.size();
}
void CGUIManager::SwitchPage(const CStrW& pageName, const ScriptInterface* srcScriptInterface, JS::HandleValue initData)
void CGUIManager::SwitchPage(const CStrW& pageName, const Script::Interface* srcScriptInterface, JS::HandleValue initData)
{
// The page stack is cleared (including the script context where initData came from),
// therefore we have to clone initData.
@@ -124,7 +124,7 @@ void CGUIManager::SwitchPage(const CStrW& pageName, const ScriptInterface* srcSc
Script::StructuredClone initDataClone;
if (!initData.isUndefined())
{
ScriptRequest rq(srcScriptInterface);
Script::Request rq(srcScriptInterface);
initDataClone = Script::WriteStructuredClone(rq, initData);
}
@@ -165,14 +165,14 @@ CGUIManager::SGUIPage::SGUIPage(const CStrW& pageName, const Script::StructuredC
{
}
void CGUIManager::SGUIPage::LoadPage(ScriptContext& scriptContext)
void CGUIManager::SGUIPage::LoadPage(Script::Context& scriptContext)
{
// If we're hotloading then try to grab some data from the previous page
Script::StructuredClone hotloadData;
if (gui)
{
std::shared_ptr<ScriptInterface> scriptInterface = gui->GetScriptInterface();
ScriptRequest rq(scriptInterface);
std::shared_ptr<Script::Interface> scriptInterface = gui->GetScriptInterface();
Script::Request rq(scriptInterface);
JS::RootedValue hotloadDataVal(rq.cx, gui->GetHotloadData(rq));
hotloadData = Script::WriteStructuredClone(rq, hotloadDataVal);
}
@@ -180,7 +180,7 @@ void CGUIManager::SGUIPage::LoadPage(ScriptContext& scriptContext)
g_VideoMode.ResetCursor();
inputs.clear();
gui.reset(new CGUI(scriptContext));
const ScriptRequest rq{gui->GetScriptInterface()};
const Script::Request rq{gui->GetScriptInterface()};
for (const char* name : {START_ATLAS, OPEN_REQUEST})
{
@@ -267,7 +267,7 @@ void CGUIManager::SGUIPage::LoadPage(ScriptContext& scriptContext)
JS::Value CGUIManager::SGUIPage::GetPromise()
{
const ScriptRequest rq{gui->GetScriptInterface()};
const Script::Request rq{gui->GetScriptInterface()};
if (receivingPromise == nullptr)
{
receivingPromise = std::make_shared<JS::PersistentRootedObject>(rq.cx,
@@ -285,7 +285,7 @@ std::optional<CGUIManager::SGUIPage::CloseResult> CGUIManager::SGUIPage::MaybeCl
// Make sure we unfocus anything on the current page.
gui->SendFocusMessage(GUIM_LOST_FOCUS);
const ScriptRequest rq{gui->GetScriptInterface()};
const Script::Request rq{gui->GetScriptInterface()};
JS::RootedValue arg{rq.cx, JS::GetPromiseResult(*sendingPromise)};
const bool rejected{JS::GetPromiseState(*sendingPromise) == JS::PromiseState::Rejected};
@@ -327,8 +327,8 @@ void CGUIManager::SGUIPage::Refocus(const Close& result)
{
ENSURE(receivingPromise);
std::shared_ptr<ScriptInterface> scriptInterface = gui->GetScriptInterface();
ScriptRequest rq(scriptInterface);
std::shared_ptr<Script::Interface> scriptInterface = gui->GetScriptInterface();
Script::Request rq(scriptInterface);
JS::RootedObject globalObj(rq.cx, rq.glob);
@@ -379,10 +379,10 @@ Input::Reaction CGUIManager::HandleEvent(const SDL_Event& ev)
{
PROFILE("handleInputBeforeGui");
ScriptRequest rq(*top()->GetScriptInterface());
Script::Request rq(*top()->GetScriptInterface());
JS::RootedValue global(rq.cx, rq.globalValue());
if (ScriptFunction::Call(rq, global, "handleInputBeforeGui", handled, ev, top()->FindObjectUnderMouse()))
if (Script::Function::Call(rq, global, "handleInputBeforeGui", handled, ev, top()->FindObjectUnderMouse()))
if (handled)
return Input::Reaction::HANDLED;
}
@@ -396,11 +396,11 @@ Input::Reaction CGUIManager::HandleEvent(const SDL_Event& ev)
{
// We can't take the following lines out of this scope because top() may be another gui page than it was when calling handleInputBeforeGui!
ScriptRequest rq(*top()->GetScriptInterface());
Script::Request rq(*top()->GetScriptInterface());
JS::RootedValue global(rq.cx, rq.globalValue());
PROFILE("handleInputAfterGui");
if (ScriptFunction::Call(rq, global, "handleInputAfterGui", handled, ev))
if (Script::Function::Call(rq, global, "handleInputAfterGui", handled, ev))
if (handled)
return Input::Reaction::HANDLED;
}
@@ -435,7 +435,7 @@ std::optional<bool> CGUIManager::TickObjects()
for (const SGUIPage& p : pageStack)
{
const ScriptRequest rq{p.gui->GetScriptInterface()};
const Script::Request rq{p.gui->GetScriptInterface()};
JS::RootedObject newSendingPromise{rq.cx, p.gui->TickObjects(rq, p.initData,
utf8_from_wstring(p.m_Name))};
if (newSendingPromise)
@@ -503,8 +503,8 @@ const CParamNode& CGUIManager::GetTemplate(const std::string& templateName)
void CGUIManager::DisplayLoadProgress(int percent, const wchar_t* pending_task)
{
const ScriptInterface& scriptInterface = *(GetActiveGUI()->GetScriptInterface());
ScriptRequest rq(scriptInterface);
const Script::Interface& scriptInterface = *(GetActiveGUI()->GetScriptInterface());
Script::Request rq(scriptInterface);
JS::RootedValueVector paramData(rq.cx);
+10 -10
View File
@@ -24,7 +24,7 @@
#include "ps/CStr.h"
#include "ps/Input.h"
#include "ps/TemplateLoader.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/Interface.h"
#include "scriptinterface/StructuredClone.h"
#include <cstddef>
@@ -39,7 +39,7 @@
class CCanvas2D;
class CGUI;
class CParamNode;
class ScriptContext;
namespace Script { class Context; }
namespace JS { class HandleValueArray; }
namespace JS { class Value; }
namespace PS { template <typename T, size_t N> class StaticVector; }
@@ -57,14 +57,14 @@ class CGUIManager
{
NONCOPYABLE(CGUIManager);
public:
CGUIManager(ScriptContext& scriptContext, ScriptInterface& scriptInterface);
CGUIManager(Script::Context& scriptContext, Script::Interface& scriptInterface);
~CGUIManager();
ScriptInterface& GetScriptInterface()
Script::Interface& GetScriptInterface()
{
return m_ScriptInterface;
}
ScriptContext& GetContext() { return m_ScriptContext; }
Script::Context& GetContext() { return m_ScriptContext; }
std::shared_ptr<CGUI> GetActiveGUI() { return top(); }
/**
@@ -75,7 +75,7 @@ public:
/**
* Load a new GUI page and make it active. All current pages will be destroyed.
*/
void SwitchPage(const CStrW& name, const ScriptInterface* srcScriptInterface, JS::HandleValue initData);
void SwitchPage(const CStrW& name, const Script::Interface* srcScriptInterface, JS::HandleValue initData);
/**
* Load a new GUI page and make it active. All current pages will be retained,
@@ -150,9 +150,9 @@ private:
SGUIPage(const CStrW& pageName, const Script::StructuredClone initData);
/**
* Create the CGUI with it's own ScriptInterface. Deletes the previous CGUI if it existed.
* Create the CGUI with it's own Script::Interface. Deletes the previous CGUI if it existed.
*/
void LoadPage(ScriptContext& context);
void LoadPage(Script::Context& context);
/**
* A reference to the promise is returned. The promise will settle when the page is closed.
@@ -206,8 +206,8 @@ private:
std::shared_ptr<CGUI> top() const;
ScriptContext& m_ScriptContext;
ScriptInterface& m_ScriptInterface;
Script::Context& m_ScriptContext;
Script::Interface& m_ScriptInterface;
/**
* The page stack must not move pointers on push/pop, or pushing a page in a page's init method
+6 -6
View File
@@ -31,7 +31,7 @@
#include "ps/CLogger.h"
#include "ps/Profiler2.h"
#include "scriptinterface/Object.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/Interface.h"
#include "soundmanager/ISoundManager.h"
#include <algorithm>
@@ -321,7 +321,7 @@ float IGUIObject::GetBufferedZ() const
void IGUIObject::RegisterScriptHandler(const CStr& eventName, const CStr& Code, CGUI& pGUI)
{
ScriptRequest rq(pGUI.GetScriptInterface());
Script::Request rq(pGUI.GetScriptInterface());
const int paramCount = 1;
const char* paramNames[paramCount] = { "mouse" };
@@ -334,7 +334,7 @@ void IGUIObject::RegisterScriptHandler(const CStr& eventName, const CStr& Code,
char buf[64];
sprintf_s(buf, ARRAY_SIZE(buf), "__eventhandler%d (%s)", x++, eventName.c_str());
// TODO: this is essentially the same code as ScriptInterface::LoadScript (with a tweak for the argument).
// TODO: this is essentially the same code as Script::Interface::LoadScript (with a tweak for the argument).
JS::CompileOptions options(rq.cx);
options.setFileAndLine(CodeName.c_str(), 0);
options.setIsRunOnce(false);
@@ -413,7 +413,7 @@ Input::Reaction IGUIObject::SendMouseEvent(EGUIMessageType type, const CStr& eve
msg.Skip();
HandleMessage(msg);
ScriptRequest rq(m_pGUI.GetScriptInterface());
Script::Request rq(m_pGUI.GetScriptInterface());
// Set up the 'mouse' parameter
JS::RootedValue mouse(rq.cx);
@@ -457,7 +457,7 @@ bool IGUIObject::ScriptEvent(const CStr& eventName,
if (it == m_ScriptHandlers.end())
return false;
ScriptRequest rq(m_pGUI.GetScriptInterface());
Script::Request rq(m_pGUI.GetScriptInterface());
JS::RootedObject obj(rq.cx, GetJSObject());
JS::RootedValue handlerVal(rq.cx, JS::ObjectValue(*it->second));
JS::RootedValue result(rq.cx);
@@ -465,7 +465,7 @@ bool IGUIObject::ScriptEvent(const CStr& eventName,
if (!JS_CallFunctionValue(rq.cx, obj, handlerVal, paramData, &result))
{
LOGERROR("Errors executing script event \"%s\"", eventName.c_str());
ScriptException::CatchPending(rq);
Script::Exception::CatchPending(rq);
return false;
}
return JS::ToBoolean(result);
+5 -5
View File
@@ -26,8 +26,8 @@
#include "lib/timer.h"
#include "ps/CLogger.h"
#include "ps/KeyName.h"
#include "scriptinterface/ScriptConversions.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Conversions.h"
#include "scriptinterface/Request.h"
#include <SDL_events.h>
#include <SDL_mouse.h>
@@ -43,13 +43,13 @@ const CStr CHotkeyPicker::EventNameCombination = "Combination";
const CStr CHotkeyPicker::EventNameKeyChange = "KeyChange";
// Don't send the scancode, JS doesn't care.
template<> void Script::ToJSVal(const ScriptRequest& rq, JS::MutableHandleValue ret, const CHotkeyPicker::Key& val)
template<> void Script::ToJSVal(const Script::Request& rq, JS::MutableHandleValue ret, const CHotkeyPicker::Key& val)
{
Script::ToJSVal(rq, ret, val.scancodeName);
}
// Unused, but JSVAL_VECTOR requires it.
template<> bool Script::FromJSVal(const ScriptRequest&, const JS::HandleValue, CHotkeyPicker::Key&)
template<> bool Script::FromJSVal(const Script::Request&, const JS::HandleValue, CHotkeyPicker::Key&)
{
LOGWARNING("FromJSVal<CHotkeyPicker>: Not implemented");
return false;
@@ -65,7 +65,7 @@ CHotkeyPicker::CHotkeyPicker(CGUI& pGUI) : IGUIObject(pGUI), m_TimeToCombination
void CHotkeyPicker::FireEvent(const CStr& event)
{
ScriptRequest rq(*m_pGUI.GetScriptInterface());
Script::Request rq(*m_pGUI.GetScriptInterface());
JS::RootedValueArray<1> args(rq.cx);
JS::RootedValue keys(rq.cx);
+3 -3
View File
@@ -44,8 +44,8 @@
#include "renderer/SceneRenderer.h"
#include "renderer/WaterManager.h"
#include "scriptinterface/Object.h"
#include "scriptinterface/ScriptConversions.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Conversions.h"
#include "scriptinterface/Request.h"
#include "simulation2/components/ICmpRangeManager.h"
#include "simulation2/system/Component.h"
#include "simulation2/system/Entity.h"
@@ -262,7 +262,7 @@ CVector2D CMiniMap::WorldSpaceToMiniMapSpace(const CVector3D& worldPosition) con
bool CMiniMap::FireWorldClickEvent(int button, int /*clicks*/)
{
ScriptRequest rq(g_GUI->GetActiveGUI()->GetScriptInterface());
Script::Request rq(g_GUI->GetActiveGUI()->GetScriptInterface());
float x, z;
GetMouseWorldCoordinates(x, z);
+32 -32
View File
@@ -17,7 +17,7 @@
#include "precompiled.h"
#include "scriptinterface/ScriptConversions.h"
#include "scriptinterface/Conversions.h"
#include "gui/CGUISprite.h"
#include "gui/ObjectBases/IGUIObject.h"
@@ -36,8 +36,8 @@
#include "ps/CLogger.h"
#include "ps/Hotkey.h"
#include "scriptinterface/Object.h"
#include "scriptinterface/ScriptExceptions.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Exceptions.h"
#include "scriptinterface/Request.h"
#include <js/CallArgs.h>
#include <js/PropertyAndElement.h>
@@ -55,7 +55,7 @@ struct CColor;
// ignore JS_SetProperty return value, because errors should be impossible
// and we can't do anything useful in the case of errors anyway
template<> void Script::ToJSVal<SDL_Event>(const ScriptRequest& rq, JS::MutableHandleValue ret, SDL_Event const& ev)
template<> void Script::ToJSVal<SDL_Event>(const Script::Request& rq, JS::MutableHandleValue ret, SDL_Event const& ev)
{
const char* typeName;
@@ -148,7 +148,7 @@ template<> void Script::ToJSVal<SDL_Event>(const ScriptRequest& rq, JS::MutableH
ret.setObject(*obj);
}
template<> void Script::ToJSVal<IGUIObject*>(const ScriptRequest&, JS::MutableHandleValue ret,
template<> void Script::ToJSVal<IGUIObject*>(const Script::Request&, JS::MutableHandleValue ret,
IGUIObject* const& val)
{
if (val == nullptr)
@@ -157,28 +157,28 @@ template<> void Script::ToJSVal<IGUIObject*>(const ScriptRequest&, JS::MutableHa
ret.setObject(*val->GetJSObject());
}
template<> bool Script::FromJSVal<IGUIObject*>(const ScriptRequest& rq, JS::HandleValue v, IGUIObject*& out)
template<> bool Script::FromJSVal<IGUIObject*>(const Script::Request& rq, JS::HandleValue v, IGUIObject*& out)
{
if (!v.isObject())
{
ScriptException::Raise(rq, "Value is not an IGUIObject.");
Script::Exception::Raise(rq, "Value is not an IGUIObject.");
return false;
}
out = IGUIProxyObject::FromPrivateSlot<IGUIObject>(v.toObjectOrNull());
if (!out)
{
ScriptException::Raise(rq, "Value is not an IGUIObject.");
Script::Exception::Raise(rq, "Value is not an IGUIObject.");
return false;
}
return true;
}
template<> void Script::ToJSVal<CGUIString>(const ScriptRequest& rq, JS::MutableHandleValue ret, const CGUIString& val)
template<> void Script::ToJSVal<CGUIString>(const Script::Request& rq, JS::MutableHandleValue ret, const CGUIString& val)
{
Script::ToJSVal(rq, ret, val.GetOriginalString());
}
template<> bool Script::FromJSVal<CGUIString>(const ScriptRequest& rq, JS::HandleValue v, CGUIString& out)
template<> bool Script::FromJSVal<CGUIString>(const Script::Request& rq, JS::HandleValue v, CGUIString& out)
{
std::wstring val;
if (!FromJSVal(rq, v, val))
@@ -191,7 +191,7 @@ JSVAL_VECTOR(CVector2D)
JSVAL_VECTOR(std::vector<CVector2D>)
JSVAL_VECTOR(CGUIString)
template<> void Script::ToJSVal<CGUIColor>(const ScriptRequest& rq, JS::MutableHandleValue ret, const CGUIColor& val)
template<> void Script::ToJSVal<CGUIColor>(const Script::Request& rq, JS::MutableHandleValue ret, const CGUIColor& val)
{
ToJSVal<CColor>(rq, ret, val);
}
@@ -199,9 +199,9 @@ template<> void Script::ToJSVal<CGUIColor>(const ScriptRequest& rq, JS::MutableH
/**
* The color depends on the predefined color database stored in the current GUI page.
*/
template<> bool Script::FromJSVal<CGUIColor>(const ScriptRequest& rq, JS::HandleValue v, CGUIColor& out) = delete;
template<> bool Script::FromJSVal<CGUIColor>(const Script::Request& rq, JS::HandleValue v, CGUIColor& out) = delete;
template<> void Script::ToJSVal<CRect>(const ScriptRequest& rq, JS::MutableHandleValue ret, const CRect& val)
template<> void Script::ToJSVal<CRect>(const Script::Request& rq, JS::MutableHandleValue ret, const CRect& val)
{
Script::CreateObject(
rq,
@@ -212,27 +212,27 @@ template<> void Script::ToJSVal<CRect>(const ScriptRequest& rq, JS::MutableHandl
"bottom", val.bottom);
}
template<> void Script::ToJSVal<CGUIList>(const ScriptRequest& rq, JS::MutableHandleValue ret, const CGUIList& val)
template<> void Script::ToJSVal<CGUIList>(const Script::Request& rq, JS::MutableHandleValue ret, const CGUIList& val)
{
ToJSVal(rq, ret, val.m_Items);
}
template<> bool Script::FromJSVal<CGUIList>(const ScriptRequest& rq, JS::HandleValue v, CGUIList& out)
template<> bool Script::FromJSVal<CGUIList>(const Script::Request& rq, JS::HandleValue v, CGUIList& out)
{
return FromJSVal(rq, v, out.m_Items);
}
template<> void Script::ToJSVal<CGUISeries>(const ScriptRequest& rq, JS::MutableHandleValue ret, const CGUISeries& val)
template<> void Script::ToJSVal<CGUISeries>(const Script::Request& rq, JS::MutableHandleValue ret, const CGUISeries& val)
{
ToJSVal(rq, ret, val.m_Series);
}
template<> bool Script::FromJSVal<CGUISeries>(const ScriptRequest& rq, JS::HandleValue v, CGUISeries& out)
template<> bool Script::FromJSVal<CGUISeries>(const Script::Request& rq, JS::HandleValue v, CGUISeries& out)
{
return FromJSVal(rq, v, out.m_Series);
}
template<> void Script::ToJSVal<EVAlign>(const ScriptRequest& rq, JS::MutableHandleValue ret, const EVAlign& val)
template<> void Script::ToJSVal<EVAlign>(const Script::Request& rq, JS::MutableHandleValue ret, const EVAlign& val)
{
std::string word;
switch (val)
@@ -251,13 +251,13 @@ template<> void Script::ToJSVal<EVAlign>(const ScriptRequest& rq, JS::MutableHan
default:
word = "error";
ScriptException::Raise(rq, "Invalid EVAlign");
Script::Exception::Raise(rq, "Invalid EVAlign");
break;
}
ToJSVal(rq, ret, word);
}
template<> bool Script::FromJSVal<EVAlign>(const ScriptRequest& rq, JS::HandleValue v, EVAlign& out)
template<> bool Script::FromJSVal<EVAlign>(const Script::Request& rq, JS::HandleValue v, EVAlign& out)
{
std::string word;
FromJSVal(rq, v, word);
@@ -277,7 +277,7 @@ template<> bool Script::FromJSVal<EVAlign>(const ScriptRequest& rq, JS::HandleVa
return true;
}
template<> void Script::ToJSVal<EAlign>(const ScriptRequest& rq, JS::MutableHandleValue ret, const EAlign& val)
template<> void Script::ToJSVal<EAlign>(const Script::Request& rq, JS::MutableHandleValue ret, const EAlign& val)
{
std::string word;
switch (val)
@@ -293,13 +293,13 @@ template<> void Script::ToJSVal<EAlign>(const ScriptRequest& rq, JS::MutableHand
break;
default:
word = "error";
ScriptException::Raise(rq, "Invalid alignment (should be 'left', 'right' or 'center')");
Script::Exception::Raise(rq, "Invalid alignment (should be 'left', 'right' or 'center')");
break;
}
ToJSVal(rq, ret, word);
}
template<> bool Script::FromJSVal<EAlign>(const ScriptRequest& rq, JS::HandleValue v, EAlign& out)
template<> bool Script::FromJSVal<EAlign>(const Script::Request& rq, JS::HandleValue v, EAlign& out)
{
std::string word;
FromJSVal(rq, v, word);
@@ -319,7 +319,7 @@ template<> bool Script::FromJSVal<EAlign>(const ScriptRequest& rq, JS::HandleVal
return true;
}
template<> void Script::ToJSVal<EScrollOrientation>(const ScriptRequest& rq, JS::MutableHandleValue ret, const EScrollOrientation& val)
template<> void Script::ToJSVal<EScrollOrientation>(const Script::Request& rq, JS::MutableHandleValue ret, const EScrollOrientation& val)
{
std::string word;
switch (val)
@@ -335,13 +335,13 @@ template<> void Script::ToJSVal<EScrollOrientation>(const ScriptRequest& rq, JS:
break;
default:
word = "error";
ScriptException::Raise(rq, "Invalid scroll orientation (should be 'vertical', 'horizontal' or 'both')");
Script::Exception::Raise(rq, "Invalid scroll orientation (should be 'vertical', 'horizontal' or 'both')");
break;
}
ToJSVal(rq, ret, word);
}
template <> bool Script::FromJSVal<EScrollOrientation>(const ScriptRequest& rq, JS::HandleValue v, EScrollOrientation& out)
template <> bool Script::FromJSVal<EScrollOrientation>(const Script::Request& rq, JS::HandleValue v, EScrollOrientation& out)
{
std::string word;
FromJSVal(rq, v, word);
@@ -362,12 +362,12 @@ template <> bool Script::FromJSVal<EScrollOrientation>(const ScriptRequest& rq,
return true;
}
template<> void Script::ToJSVal<CGUISpriteInstance>(const ScriptRequest& rq, JS::MutableHandleValue ret, const CGUISpriteInstance& val)
template<> void Script::ToJSVal<CGUISpriteInstance>(const Script::Request& rq, JS::MutableHandleValue ret, const CGUISpriteInstance& val)
{
ToJSVal(rq, ret, val.GetName());
}
template<> bool Script::FromJSVal<CGUISpriteInstance>(const ScriptRequest& rq, JS::HandleValue v, CGUISpriteInstance& out)
template<> bool Script::FromJSVal<CGUISpriteInstance>(const Script::Request& rq, JS::HandleValue v, CGUISpriteInstance& out)
{
std::string name;
if (!FromJSVal(rq, v, name))
@@ -377,12 +377,12 @@ template<> bool Script::FromJSVal<CGUISpriteInstance>(const ScriptRequest& rq, J
return true;
}
template<> void Script::ToJSVal<CSize2D>(const ScriptRequest& rq, JS::MutableHandleValue ret, const CSize2D& val)
template<> void Script::ToJSVal<CSize2D>(const Script::Request& rq, JS::MutableHandleValue ret, const CSize2D& val)
{
Script::CreateObject(rq, ret, "width", val.Width, "height", val.Height);
}
template<> bool Script::FromJSVal<CSize2D>(const ScriptRequest& rq, JS::HandleValue v, CSize2D& out)
template<> bool Script::FromJSVal<CSize2D>(const Script::Request& rq, JS::HandleValue v, CSize2D& out)
{
if (!v.isObject())
{
@@ -405,12 +405,12 @@ template<> bool Script::FromJSVal<CSize2D>(const ScriptRequest& rq, JS::HandleVa
return true;
}
template<> void Script::ToJSVal<CVector2D>(const ScriptRequest& rq, JS::MutableHandleValue ret, const CVector2D& val)
template<> void Script::ToJSVal<CVector2D>(const Script::Request& rq, JS::MutableHandleValue ret, const CVector2D& val)
{
Script::CreateObject(rq, ret, "x", val.X, "y", val.Y);
}
template<> bool Script::FromJSVal<CVector2D>(const ScriptRequest& rq, JS::HandleValue v, CVector2D& out)
template<> bool Script::FromJSVal<CVector2D>(const Script::Request& rq, JS::HandleValue v, CVector2D& out)
{
if (!v.isObject())
{
+13 -13
View File
@@ -30,9 +30,9 @@
#include "ps/CLogger.h"
#include "ps/CStr.h"
#include "scriptinterface/Object.h"
#include "scriptinterface/ScriptConversions.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Conversions.h"
#include "scriptinterface/Interface.h"
#include "scriptinterface/Request.h"
#include <fmt/format.h>
#include <js/CallArgs.h>
@@ -55,7 +55,7 @@ bool GetCRectField(JSContext* cx, unsigned argc, JS::Value* vp)
{
JS::CallArgs args{JS::CallArgsFromVp(argc, vp)};
JS::RootedObject obj{cx, &args.thisv().toObject()};
CGUISimpleSetting<CGUISize>* wrapper{JS::GetMaybePtrFromReservedSlot<CGUISimpleSetting<CGUISize>>(obj, ScriptInterface::JSObjectReservedSlots::PRIVATE)};
CGUISimpleSetting<CGUISize>* wrapper{JS::GetMaybePtrFromReservedSlot<CGUISimpleSetting<CGUISize>>(obj, Script::Interface::JSObjectReservedSlots::PRIVATE)};
args.rval().setDouble(wrapper->GetMutable().*RectMember.*Member);
return true;
@@ -66,7 +66,7 @@ bool SetCRectField(JSContext* cx, unsigned argc, JS::Value* vp)
{
JS::CallArgs args{JS::CallArgsFromVp(argc, vp)};
JS::RootedObject obj{cx, &args.thisv().toObject()};
CGUISimpleSetting<CGUISize>* wrapper{JS::GetMaybePtrFromReservedSlot<CGUISimpleSetting<CGUISize>>(obj, ScriptInterface::JSObjectReservedSlots::PRIVATE)};
CGUISimpleSetting<CGUISize>* wrapper{JS::GetMaybePtrFromReservedSlot<CGUISimpleSetting<CGUISize>>(obj, Script::Interface::JSObjectReservedSlots::PRIVATE)};
double val;
if (!JS::ToNumber(cx, args.get(0), &val))
@@ -96,7 +96,7 @@ bool toString(JSContext* cx, uint argc, JS::Value* vp)
{
JS::CallArgs args{JS::CallArgsFromVp(argc, vp)};
JS::RootedObject obj{cx, &args.thisv().toObject()};
CGUISimpleSetting<CGUISize>* wrapper{JS::GetMaybePtrFromReservedSlot<CGUISimpleSetting<CGUISize>>(obj, ScriptInterface::JSObjectReservedSlots::PRIVATE)};
CGUISimpleSetting<CGUISize>* wrapper{JS::GetMaybePtrFromReservedSlot<CGUISimpleSetting<CGUISize>>(obj, Script::Interface::JSObjectReservedSlots::PRIVATE)};
CStr buffer;
buffer += ToPercentString(wrapper->GetMutable().pixel.left, wrapper->GetMutable().percent.left) + " ";
@@ -104,7 +104,7 @@ bool toString(JSContext* cx, uint argc, JS::Value* vp)
buffer += ToPercentString(wrapper->GetMutable().pixel.right, wrapper->GetMutable().percent.right) + " ";
buffer += ToPercentString(wrapper->GetMutable().pixel.bottom, wrapper->GetMutable().percent.bottom);
ScriptRequest rq{cx};
Script::Request rq{cx};
Script::ToJSVal(rq, args.rval(), buffer);
return true;
}
@@ -137,19 +137,19 @@ JSPropertySpec JSI_props[] =
void JSI_CGUISize::RegisterScriptClass(ScriptInterface& scriptInterface)
void JSI_CGUISize::RegisterScriptClass(Script::Interface& scriptInterface)
{
scriptInterface.DefineCustomObjectType(&JSI_class, nullptr, 0, JSI_props, JSI_methods, nullptr, nullptr);
}
template class CGUISimpleSetting<CGUISize>;
template<>
void CGUISimpleSetting<CGUISize>::ToJSVal(const ScriptRequest& rq, JS::MutableHandleValue ret)
void CGUISimpleSetting<CGUISize>::ToJSVal(const Script::Request& rq, JS::MutableHandleValue ret)
{
const ScriptInterface& scriptInterface = rq.GetScriptInterface();
const Script::Interface& scriptInterface = rq.GetScriptInterface();
JS::RootedObject obj{rq.cx, scriptInterface.CreateCustomObject("CGUISize")};
JS::SetReservedSlot(obj, ScriptInterface::JSObjectReservedSlots::PRIVATE, JS::PrivateValue(this));
JS::SetReservedSlot(obj, Script::Interface::JSObjectReservedSlots::PRIVATE, JS::PrivateValue(this));
ret.setObject(*obj);
};
@@ -160,7 +160,7 @@ bool CGUISimpleSetting<CGUISize>::DoFromString(const CStrW& value)
};
template<>
bool CGUISimpleSetting<CGUISize>::DoFromJSVal(const ScriptRequest& rq, JS::HandleValue value)
bool CGUISimpleSetting<CGUISize>::DoFromJSVal(const Script::Request& rq, JS::HandleValue value)
{
if (value.isString())
{
@@ -189,7 +189,7 @@ bool CGUISimpleSetting<CGUISize>::DoFromJSVal(const ScriptRequest& rq, JS::Handl
JS::RootedObject obj{rq.cx, &value.toObject()};
if (JS_InstanceOf(rq.cx, obj, &JSI_class, nullptr))
{
CGUISimpleSetting<CGUISize>* wrapper = JS::GetMaybePtrFromReservedSlot<CGUISimpleSetting<CGUISize>>(obj, ScriptInterface::JSObjectReservedSlots::PRIVATE);
CGUISimpleSetting<CGUISize>* wrapper = JS::GetMaybePtrFromReservedSlot<CGUISimpleSetting<CGUISize>>(obj, Script::Interface::JSObjectReservedSlots::PRIVATE);
if (this != wrapper)
this->Set(wrapper->m_Setting, false);
return true;
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -18,10 +18,10 @@
#ifndef INCLUDED_JSI_CGUISIZE
#define INCLUDED_JSI_CGUISIZE
class ScriptInterface;
namespace Script { class Interface; }
namespace JSI_CGUISize
{
void RegisterScriptClass(ScriptInterface& scriptInterface);
void RegisterScriptClass(Script::Interface& scriptInterface);
}
#endif // INCLUDED_JSI_GUISIZE
+12 -12
View File
@@ -24,7 +24,7 @@
#include "ps/CStr.h"
#include "ps/VideoMode.h"
#include "scriptinterface/FunctionWrapper.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/Interface.h"
#include "scriptinterface/StructuredClone.h"
#include "simulation2/system/Component.h"
@@ -38,7 +38,7 @@ namespace JSI_GUIManager
// Note that the initData argument may only contain clonable data.
// Functions aren't supported for example!
// It returns a promise.
JS::Value OpenChildPage(const ScriptRequest& rq, const std::wstring& name, JS::HandleValue initData)
JS::Value OpenChildPage(const Script::Request& rq, const std::wstring& name, JS::HandleValue initData)
{
return g_GUI->OpenChildPage(name, Script::WriteStructuredClone(rq, initData));
}
@@ -64,17 +64,17 @@ CParamNode GetTemplate(const std::string& templateName)
}
void RegisterScriptFunctions(const ScriptRequest& rq)
void RegisterScriptFunctions(const Script::Request& rq)
{
ScriptFunction::Register<&OpenChildPage>(rq, "OpenChildPage");
ScriptFunction::Register<&SetCursor>(rq, "SetCursor");
ScriptFunction::Register<&ResetCursor>(rq, "ResetCursor");
ScriptFunction::Register<&TemplateExists>(rq, "TemplateExists");
ScriptFunction::Register<&GetTemplate>(rq, "GetTemplate");
Script::Function::Register<&OpenChildPage>(rq, "OpenChildPage");
Script::Function::Register<&SetCursor>(rq, "SetCursor");
Script::Function::Register<&ResetCursor>(rq, "ResetCursor");
Script::Function::Register<&TemplateExists>(rq, "TemplateExists");
Script::Function::Register<&GetTemplate>(rq, "GetTemplate");
ScriptFunction::Register<&CGUI::TryFindObjectByName, &ScriptInterface::ObjectFromCBData<CGUI>>(rq, "TryGetGUIObjectByName");
ScriptFunction::Register<&CGUI::FindObjectByName, &ScriptInterface::ObjectFromCBData<CGUI>>(rq, "GetGUIObjectByName");
ScriptFunction::Register<&CGUI::SetGlobalHotkey, &ScriptInterface::ObjectFromCBData<CGUI>>(rq, "SetGlobalHotkey");
ScriptFunction::Register<&CGUI::UnsetGlobalHotkey, &ScriptInterface::ObjectFromCBData<CGUI>>(rq, "UnsetGlobalHotkey");
Script::Function::Register<&CGUI::TryFindObjectByName, &Script::Interface::ObjectFromCBData<CGUI>>(rq, "TryGetGUIObjectByName");
Script::Function::Register<&CGUI::FindObjectByName, &Script::Interface::ObjectFromCBData<CGUI>>(rq, "GetGUIObjectByName");
Script::Function::Register<&CGUI::SetGlobalHotkey, &Script::Interface::ObjectFromCBData<CGUI>>(rq, "SetGlobalHotkey");
Script::Function::Register<&CGUI::UnsetGlobalHotkey, &Script::Interface::ObjectFromCBData<CGUI>>(rq, "UnsetGlobalHotkey");
}
}
@@ -1,4 +1,4 @@
/* Copyright (C) 2020 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -18,11 +18,11 @@
#ifndef INCLUDED_JSI_GUIMANAGER
#define INCLUDED_JSI_GUIMANAGER
class ScriptRequest;
namespace Script { class Request; }
namespace JSI_GUIManager
{
void RegisterScriptFunctions(const ScriptRequest& rq);
void RegisterScriptFunctions(const Script::Request& rq);
}
#endif // INCLUDED_JSI_GUIMANAGER
@@ -31,11 +31,11 @@
#include <string>
class CGUIString;
class ScriptRequest;
namespace Script { class Request; }
// Called for every specialization - adds the common interface.
template<>
void JSI_GUIProxy<IGUIObject>::CreateFunctions(const ScriptRequest& rq, GUIProxyProps* cache)
void JSI_GUIProxy<IGUIObject>::CreateFunctions(const Script::Request& rq, GUIProxyProps* cache)
{
CreateFunction<&IGUIObject::GetName>(rq, cache, "toString");
CreateFunction<&IGUIObject::GetName>(rq, cache, "toSource");
@@ -48,7 +48,7 @@ DECLARE_GUIPROXY(IGUIObject);
// Implement derived types below.
// CButton
template<> void JSI_GUIProxy<CButton>::CreateFunctions(const ScriptRequest& rq, GUIProxyProps* cache)
template<> void JSI_GUIProxy<CButton>::CreateFunctions(const Script::Request& rq, GUIProxyProps* cache)
{
CreateFunction<&CButton::GetTextSize>(rq, cache, "getTextSize");
CreateFunction<&CButton::GetPreferredTextSize>(rq, cache, "getPreferredTextSize");
@@ -56,7 +56,7 @@ template<> void JSI_GUIProxy<CButton>::CreateFunctions(const ScriptRequest& rq,
DECLARE_GUIPROXY(CButton);
// CText
template<> void JSI_GUIProxy<CText>::CreateFunctions(const ScriptRequest& rq, GUIProxyProps* cache)
template<> void JSI_GUIProxy<CText>::CreateFunctions(const Script::Request& rq, GUIProxyProps* cache)
{
CreateFunction<&CText::GetTextSize>(rq, cache, "getTextSize");
CreateFunction<&CText::GetPreferredTextSize>(rq, cache, "getPreferredTextSize");
@@ -64,28 +64,28 @@ template<> void JSI_GUIProxy<CText>::CreateFunctions(const ScriptRequest& rq, GU
DECLARE_GUIPROXY(CText);
// CList
template<> void JSI_GUIProxy<CList>::CreateFunctions(const ScriptRequest& rq, GUIProxyProps* cache)
template<> void JSI_GUIProxy<CList>::CreateFunctions(const Script::Request& rq, GUIProxyProps* cache)
{
CreateFunction<static_cast<void(CList::*)(const CGUIString&)>(&CList::AddItem)>(rq, cache, "addItem");
}
DECLARE_GUIPROXY(CList);
// CDropDown
template<> void JSI_GUIProxy<CDropDown>::CreateFunctions(const ScriptRequest& rq, GUIProxyProps* cache)
template<> void JSI_GUIProxy<CDropDown>::CreateFunctions(const Script::Request& rq, GUIProxyProps* cache)
{
CreateFunction<&CDropDown::GetPreferredHeaderTextSize>(rq, cache, "getPreferredHeaderTextSize");
}
DECLARE_GUIPROXY(CDropDown);
// CMiniMap
template<> void JSI_GUIProxy<CMiniMap>::CreateFunctions(const ScriptRequest& rq, GUIProxyProps* cache)
template<> void JSI_GUIProxy<CMiniMap>::CreateFunctions(const Script::Request& rq, GUIProxyProps* cache)
{
CreateFunction<&CMiniMap::Flare>(rq, cache, "flare");
}
DECLARE_GUIPROXY(CMiniMap);
// CScrollPanel
template<> void JSI_GUIProxy<CScrollPanel>::CreateFunctions(const ScriptRequest& rq, GUIProxyProps* cache)
template<> void JSI_GUIProxy<CScrollPanel>::CreateFunctions(const Script::Request& rq, GUIProxyProps* cache)
{
CreateFunction<&CScrollPanel::ResetScrollPosition>(rq, cache, "resetScrollPosition");
}
+8 -8
View File
@@ -36,9 +36,9 @@
class JSFunction;
class JSObject;
class ScriptInterface;
class ScriptRequest;
namespace JS { class CallArgs; }
namespace Script { class Interface; }
namespace Script { class Request; }
// See JSI_GuiProxy below
#if GCC_VERSION
@@ -101,7 +101,7 @@ public:
virtual bool has(const std::string& name) const = 0;
// @return the JSFunction matching @param name. Must call has() first as it can assume existence.
virtual JSObject* get(const std::string& name) const = 0;
virtual bool setFunction(const ScriptRequest& rq, const std::string& name, JSFunction* function) = 0;
virtual bool setFunction(const Script::Request& rq, const std::string& name, JSFunction* function) = 0;
virtual std::vector<std::string_view> getPropsNames() const = 0;
};
@@ -138,10 +138,10 @@ public:
static JSI_GUIProxy& Singleton();
// Call this in CGUI::AddObjectTypes.
static std::pair<const js::BaseProxyHandler*, GUIProxyProps*> CreateData(ScriptInterface& scriptInterface);
static std::pair<const js::BaseProxyHandler*, GUIProxyProps*> CreateData(Script::Interface& scriptInterface);
// Create the JS object, the proxy, the data and wrap it in a convenient unique_ptr.
static std::unique_ptr<IGUIProxyObject> CreateJSObject(const ScriptRequest& rq, GUIObjectType* ptr, GUIProxyProps* data);
static std::unique_ptr<IGUIProxyObject> CreateJSObject(const Script::Request& rq, GUIObjectType* ptr, GUIProxyProps* data);
protected:
// @param family can't be nullptr because that's used for some DOM object and it crashes.
JSI_GUIProxy() : BaseProxyHandler(this, false, false) {};
@@ -150,18 +150,18 @@ protected:
// This also enforces making proxy handlers dataless static variables.
~JSI_GUIProxy() {};
static GUIObjectType* FromPrivateSlot(const ScriptRequest&, JS::CallArgs& args);
static GUIObjectType* FromPrivateSlot(const Script::Request&, JS::CallArgs& args);
// The default implementations need to know the type of the GUIProxyProps for this proxy type.
// This is done by specializing this struct's alias type.
struct PropCache;
// Specialize this to define the custom properties of this type.
static void CreateFunctions(const ScriptRequest& rq, GUIProxyProps* cache);
static void CreateFunctions(const Script::Request& rq, GUIProxyProps* cache);
// Convenience helper for the above.
template<auto callable>
static void CreateFunction(const ScriptRequest& rq, GUIProxyProps* cache, const std::string& name);
static void CreateFunction(const Script::Request& rq, GUIProxyProps* cache, const std::string& name);
// This handles returning custom properties. Specialize this if needed.
bool PropGetter(JS::HandleObject proxy, const std::string& propName, JS::MutableHandleValue vp) const;
@@ -25,8 +25,8 @@
#include "ps/CStr.h"
#include "scriptinterface/FunctionWrapper.h"
#include "scriptinterface/Object.h"
#include "scriptinterface/ScriptConversions.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Conversions.h"
#include "scriptinterface/Request.h"
#include <js/CallAndConstruct.h>
#include <js/CallArgs.h>
@@ -49,7 +49,7 @@
#include <utility>
class JSObject;
class ScriptInterface;
namespace Script { class Interface; }
#ifndef INCLUDED_JSI_GUIPROXY_IMP
#define INCLUDED_JSI_GUIPROXY_IMP
@@ -65,7 +65,7 @@ JSI_GUIProxy<T>& JSI_GUIProxy<T>::Singleton()
#define DECLARE_GUIPROXY(Type) \
void Type::CreateJSObject() \
{ \
ScriptRequest rq(m_pGUI.GetScriptInterface()); \
Script::Request rq(m_pGUI.GetScriptInterface()); \
using ProxyHandler = JSI_GUIProxy<std::remove_pointer_t<decltype(this)>>; \
m_JSObject = ProxyHandler::CreateJSObject(rq, this, GetGUI().GetProxyData(&ProxyHandler::Singleton())); \
} \
@@ -97,7 +97,7 @@ public:
return m_Functions.at(name).get();
}
bool setFunction(const ScriptRequest& rq, const std::string& name, JSFunction* function) override
bool setFunction(const Script::Request& rq, const std::string& name, JSFunction* function) override
{
m_Functions[name].init(rq.cx, JS_GetFunctionObject(function));
return true;
@@ -137,7 +137,7 @@ struct JSI_GUIProxy<T>::PropCache
};
template <typename T>
T* JSI_GUIProxy<T>::FromPrivateSlot(const ScriptRequest&, JS::CallArgs& args)
T* JSI_GUIProxy<T>::FromPrivateSlot(const Script::Request&, JS::CallArgs& args)
{
// Call the unsafe version - this is only ever called from actual proxy objects.
return IGUIProxyObject::UnsafeFromPrivateSlot<T>(args.thisv().toObjectOrNull());
@@ -158,11 +158,11 @@ bool JSI_GUIProxy<T>::PropGetter(JS::HandleObject proxy, const std::string& prop
}
template <typename T>
std::pair<const js::BaseProxyHandler*, GUIProxyProps*> JSI_GUIProxy<T>::CreateData(ScriptInterface& scriptInterface)
std::pair<const js::BaseProxyHandler*, GUIProxyProps*> JSI_GUIProxy<T>::CreateData(Script::Interface& scriptInterface)
{
using PropertyCache = typename PropCache::type;
PropertyCache* data = new PropertyCache();
ScriptRequest rq(scriptInterface);
Script::Request rq(scriptInterface);
// Functions common to all children of IGUIObject.
JSI_GUIProxy<IGUIObject>::CreateFunctions(rq, data);
@@ -175,13 +175,13 @@ std::pair<const js::BaseProxyHandler*, GUIProxyProps*> JSI_GUIProxy<T>::CreateDa
template<typename T>
template<auto callable>
void JSI_GUIProxy<T>::CreateFunction(const ScriptRequest& rq, GUIProxyProps* cache, const std::string& name)
void JSI_GUIProxy<T>::CreateFunction(const Script::Request& rq, GUIProxyProps* cache, const std::string& name)
{
cache->setFunction(rq, name, ScriptFunction::Create<callable, FromPrivateSlot>(rq, name.c_str()));
cache->setFunction(rq, name, Script::Function::Create<callable, FromPrivateSlot>(rq, name.c_str()));
}
template<typename T>
std::unique_ptr<IGUIProxyObject> JSI_GUIProxy<T>::CreateJSObject(const ScriptRequest& rq, T* ptr, GUIProxyProps* dataPtr)
std::unique_ptr<IGUIProxyObject> JSI_GUIProxy<T>::CreateJSObject(const Script::Request& rq, T* ptr, GUIProxyProps* dataPtr)
{
js::ProxyOptions options;
options.setClass(&JSInterface_GUIProxy::ClassDefinition());
@@ -201,7 +201,7 @@ template <typename T>
bool JSI_GUIProxy<T>::get(JSContext* cx, JS::HandleObject proxy, JS::HandleValue /*receiver*/,
JS::HandleId id, JS::MutableHandleValue vp) const
{
ScriptRequest rq(cx);
Script::Request rq(cx);
T* e = IGUIProxyObject::FromPrivateSlot<T>(proxy.get());
if (!e)
@@ -283,7 +283,7 @@ bool JSI_GUIProxy<T>::set(JSContext* cx, JS::HandleObject proxy, JS::HandleId id
return result.fail(JSMSG_OBJECT_REQUIRED);
}
ScriptRequest rq(cx);
Script::Request rq(cx);
JS::RootedValue idval(rq.cx);
if (!JS_IdToValue(rq.cx, id, &idval))
@@ -338,7 +338,7 @@ bool JSI_GUIProxy<T>::delete_(JSContext* cx, JS::HandleObject proxy, JS::HandleI
return result.fail(JSMSG_OBJECT_REQUIRED);
}
ScriptRequest rq(cx);
Script::Request rq(cx);
JS::RootedValue idval(rq.cx);
if (!JS_IdToValue(rq.cx, id, &idval))
@@ -363,7 +363,7 @@ bool JSI_GUIProxy<T>::delete_(JSContext* cx, JS::HandleObject proxy, JS::HandleI
template<typename T>
bool JSI_GUIProxy<T>::ownPropertyKeys(JSContext* cx, JS::HandleObject proxy, JS::MutableHandleIdVector props) const
{
ScriptRequest rq(cx);
Script::Request rq(cx);
T* e = IGUIProxyObject::FromPrivateSlot<T>(proxy.get());
if (!e)
+8 -8
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -21,9 +21,9 @@
#include "ps/CStr.h"
#include "scriptinterface/Object.h"
#include "scriptinterface/ScriptConversions.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Conversions.h"
#include "scriptinterface/Interface.h"
#include "scriptinterface/Request.h"
#include <js/CallArgs.h>
#include <js/Class.h>
@@ -52,7 +52,7 @@ JSFunctionSpec JSI_GUISize::JSI_methods[] =
JS_FS_END
};
void JSI_GUISize::RegisterScriptClass(ScriptInterface& scriptInterface)
void JSI_GUISize::RegisterScriptClass(Script::Interface& scriptInterface)
{
scriptInterface.DefineCustomObjectType(&JSI_GUISize::JSI_class, JSI_GUISize::construct, 0, nullptr, JSI_GUISize::JSI_methods, nullptr, nullptr);
}
@@ -60,8 +60,8 @@ void JSI_GUISize::RegisterScriptClass(ScriptInterface& scriptInterface)
bool JSI_GUISize::construct(JSContext* cx, uint argc, JS::Value* vp)
{
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
ScriptRequest rq(cx);
const ScriptInterface& scriptInterface = rq.GetScriptInterface();
Script::Request rq(cx);
const Script::Interface& scriptInterface = rq.GetScriptInterface();
JS::RootedObject obj(rq.cx, scriptInterface.CreateCustomObject("GUISize"));
@@ -119,7 +119,7 @@ bool JSI_GUISize::toString(JSContext* cx, uint argc, JS::Value* vp)
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
CStr buffer;
ScriptRequest rq(cx);
Script::Request rq(cx);
double val, valr;
#define SIDE(side) \
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -23,8 +23,8 @@
#include "lib/types.h"
#include "ps/CStr.h"
class ScriptInterface;
namespace JS { class Value; }
namespace Script { class Interface; }
struct JSClass;
struct JSClassOps;
struct JSContext;
@@ -38,7 +38,7 @@ namespace JSI_GUISize
extern JSPropertySpec JSI_props[];
extern JSFunctionSpec JSI_methods[];
void RegisterScriptClass(ScriptInterface& scriptInterface);
void RegisterScriptClass(Script::Interface& scriptInterface);
bool construct(JSContext* cx, uint argc, JS::Value* vp);
bool toString(JSContext* cx, uint argc, JS::Value* vp);
+4 -4
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -39,7 +39,7 @@
#include "ps/scripting/JSInterface_VFS.h"
#include "ps/scripting/JSInterface_VisualReplay.h"
#include "renderer/scripting/JSInterface_Renderer.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Request.h"
#include "simulation2/scripting/JSInterface_Simulation.h"
#include "soundmanager/scripting/JSInterface_Sound.h"
@@ -49,9 +49,9 @@
* Functions are exposed to scripts within the global object 'Engine', so
* scripts should call "Engine.FunctionName(...)" etc.
*/
void GuiScriptingInit(ScriptInterface& scriptInterface)
void GuiScriptingInit(Script::Interface& scriptInterface)
{
ScriptRequest rq(scriptInterface);
Script::Request rq(scriptInterface);
JSI_GUISize::RegisterScriptClass(scriptInterface);
JSI_CGUISize::RegisterScriptClass(scriptInterface);
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2010 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -18,8 +18,8 @@
#ifndef INCLUDED_GUI_SCRIPTFUNCTIONS
#define INCLUDED_GUI_SCRIPTFUNCTIONS
class ScriptInterface;
namespace Script { class Interface; }
void GuiScriptingInit(ScriptInterface& scriptInterface);
void GuiScriptingInit(Script::Interface& scriptInterface);
#endif // INCLUDED_GUI_SCRIPTFUNCTIONS
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 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 "gui/CGUI.h"
#include "gui/ObjectBases/IGUIObject.h"
#include "scriptinterface/ScriptConversions.h"
#include "scriptinterface/Conversions.h"
#include <js/RootingAPI.h>
@@ -33,7 +33,7 @@ bool CGUIHotkey::DoFromString(const CStrW& value)
return true;
}
bool CGUIHotkey::DoFromJSVal(const ScriptRequest& rq, JS::HandleValue value)
bool CGUIHotkey::DoFromJSVal(const Script::Request& rq, JS::HandleValue value)
{
m_Object.GetGUI().UnsetObjectHotkey(m_Object, m_Setting);
if (!Script::FromJSVal(rq, value, m_Setting))
+2 -2
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -39,7 +39,7 @@ public:
CGUIHotkey& operator=(CGUIHotkey&&) = delete;
bool DoFromString(const CStrW& value) override;
bool DoFromJSVal(const ScriptRequest& rq, JS::HandleValue value) override;
bool DoFromJSVal(const Script::Request& rq, JS::HandleValue value) override;
void OnSettingChange(const CStr& setting, bool sendMessage) override;
};
+3 -3
View File
@@ -32,7 +32,7 @@
#include "ps/CStr.h"
#include "ps/CacheLoader.h"
#include "ps/Filesystem.h"
#include "scriptinterface/ScriptConversions.h"
#include "scriptinterface/Conversions.h"
#include <cmath>
#include <cstddef>
@@ -63,12 +63,12 @@ CGUIMouseEventMask::~CGUIMouseEventMask()
{
}
void CGUIMouseEventMask::ToJSVal(const ScriptRequest& rq, JS::MutableHandleValue Value)
void CGUIMouseEventMask::ToJSVal(const Script::Request& rq, JS::MutableHandleValue Value)
{
Script::ToJSVal(rq, Value, m_Spec);
}
bool CGUIMouseEventMask::DoFromJSVal(const ScriptRequest& rq, JS::HandleValue value)
bool CGUIMouseEventMask::DoFromJSVal(const Script::Request& rq, JS::HandleValue value)
{
CStrW spec;
if (!Script::FromJSVal(rq, value, spec))
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -58,12 +58,12 @@ public:
*/
bool IsMouseOver(const CVector2D& mousePos, const CRect& objectSize) const;
void ToJSVal(const ScriptRequest& rq, JS::MutableHandleValue value) override;
void ToJSVal(const Script::Request& rq, JS::MutableHandleValue value) override;
class Impl;
protected:
bool DoFromString(const CStrW& value) override;
bool DoFromJSVal(const ScriptRequest& rq, JS::HandleValue value) override;
bool DoFromJSVal(const Script::Request& rq, JS::HandleValue value) override;
std::string m_Spec;
std::unique_ptr<Impl> m_Impl;
+2 -2
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -37,7 +37,7 @@
#include "ps/VideoMode.h"
#include "ps/XML/Xeromyces.h"
#include "renderer/Renderer.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/Interface.h"
#include <algorithm>
#include <array>
+3 -3
View File
@@ -34,8 +34,8 @@
#include "ps/VideoMode.h"
#include "ps/XML/Xeromyces.h"
#include "renderer/Renderer.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Interface.h"
#include "scriptinterface/Request.h"
#include <js/PropertyAndElement.h>
#include <js/PropertyDescriptor.h>
@@ -140,7 +140,7 @@ public:
CGUISimpleSetting<CGUISize>* setting{object.GetSizeSetting()};
object.SetSettingFromString("size", L"2 2 20 20", false);
ScriptRequest rq{gui.GetScriptInterface()};
Script::Request rq{gui.GetScriptInterface()};
JS::RootedValue val(rq.cx);
val.setObject(*object.GetJSObject());
JS::RootedObject global(rq.cx, rq.glob);
+21 -21
View File
@@ -35,9 +35,9 @@
#include "ps/VideoMode.h"
#include "scriptinterface/FunctionWrapper.h"
#include "scriptinterface/Object.h"
#include "scriptinterface/ScriptConversions.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Conversions.h"
#include "scriptinterface/Interface.h"
#include "scriptinterface/Request.h"
#include "scriptinterface/StructuredClone.h"
#include <SDL_events.h>
@@ -60,7 +60,7 @@ class TestGuiManager : public CxxTest::TestSuite
{
std::unique_ptr<CConfigDB> configDB;
std::optional<CXeromycesEngine> xeromycesEngine;
std::optional<ScriptInterface> scriptInterface;
std::optional<Script::Interface> scriptInterface;
public:
void setUp()
@@ -90,15 +90,15 @@ public:
void test_EventObject()
{
// Load up a test page.
ScriptRequest rq{g_GUI->GetScriptInterface()};
Script::Request rq{g_GUI->GetScriptInterface()};
JS::RootedValue val(rq.cx);
Script::CreateObject(rq, &val);
Script::StructuredClone data = Script::WriteStructuredClone(rq, JS::NullHandleValue);
g_GUI->OpenChildPage(L"event/page_event.xml", data);
const ScriptInterface& pageScriptInterface = *(g_GUI->GetActiveGUI()->GetScriptInterface());
ScriptRequest prq(pageScriptInterface);
const Script::Interface& pageScriptInterface = *(g_GUI->GetActiveGUI()->GetScriptInterface());
Script::Request prq(pageScriptInterface);
JS::RootedValue global(prq.cx, prq.globalValue());
int called_value = 0;
@@ -153,7 +153,7 @@ public:
LoadHotkeys(*configDB);
// Load up a test page.
ScriptRequest rq{g_GUI->GetScriptInterface()};
Script::Request rq{g_GUI->GetScriptInterface()};
JS::RootedValue val(rq.cx);
Script::CreateObject(rq, &val);
@@ -172,8 +172,8 @@ public:
for (SDL_Event& ev : g_VideoMode.m_InputManager.PollEvents())
g_VideoMode.m_InputManager.DispatchEvent(ev);
const ScriptInterface& pageScriptInterface = *(g_GUI->GetActiveGUI()->GetScriptInterface());
ScriptRequest prq(pageScriptInterface);
const Script::Interface& pageScriptInterface = *(g_GUI->GetActiveGUI()->GetScriptInterface());
Script::Request prq(pageScriptInterface);
JS::RootedValue global(prq.cx, prq.globalValue());
// Ensure that our hotkey state was synchronised with the event itself.
@@ -225,16 +225,16 @@ public:
static void CloseTopmostPage()
{
ScriptRequest rq{g_GUI->GetActiveGUI()->GetScriptInterface()};
Script::Request rq{g_GUI->GetActiveGUI()->GetScriptInterface()};
JS::RootedValue global{rq.cx, rq.globalValue()};
TS_ASSERT(ScriptFunction::CallVoid(rq, global, "closePageCallback"));
TS_ASSERT(Script::Function::CallVoid(rq, global, "closePageCallback"));
// Check whether promises are settled in the page stack and flush the stack.
g_GUI->TickObjects();
}
void test_PageRegainedFocusEvent()
{
ScriptRequest rq{g_GUI->GetScriptInterface()};
Script::Request rq{g_GUI->GetScriptInterface()};
const Script::StructuredClone undefined{
Script::WriteStructuredClone(rq, JS::UndefinedHandleValue)};
@@ -261,7 +261,7 @@ public:
{false, JS::PromiseState::Fulfilled},
{true, JS::PromiseState::Rejected}}};
const ScriptRequest rq{g_GUI->GetScriptInterface()};
const Script::Request rq{g_GUI->GetScriptInterface()};
const Script::StructuredClone undefined{
Script::WriteStructuredClone(rq, JS::UndefinedHandleValue)};
@@ -285,7 +285,7 @@ public:
void test_Sequential()
{
const ScriptRequest rq{g_GUI->GetScriptInterface()};
const Script::Request rq{g_GUI->GetScriptInterface()};
const Script::StructuredClone undefined{
Script::WriteStructuredClone(rq, JS::UndefinedHandleValue)};
g_GUI->OpenChildPage(L"sequential/page_sequential.xml", undefined);
@@ -298,7 +298,7 @@ public:
void test_Result()
{
const ScriptRequest rq{g_GUI->GetScriptInterface()};
const Script::Request rq{g_GUI->GetScriptInterface()};
g_GUI->OpenChildPage(L"Result/page_Result.xml",
Script::WriteStructuredClone(rq, JS::FalseHandleValue));
TS_ASSERT(!g_GUI->TickObjects().value());
@@ -310,7 +310,7 @@ public:
void test_MultipleRootModules()
{
ScriptRequest rq{g_GUI->GetScriptInterface()};
Script::Request rq{g_GUI->GetScriptInterface()};
TS_ASSERT_THROWS_EQUALS(g_GUI->OpenChildPage(
L"multiple_root-modules/page.xml",
@@ -320,7 +320,7 @@ public:
void test_Await()
{
ScriptRequest rq{g_GUI->GetScriptInterface()};
Script::Request rq{g_GUI->GetScriptInterface()};
TS_ASSERT_THROWS(g_GUI->OpenChildPage(L"await/page.xml",
Script::WriteStructuredClone(rq, JS::NullHandleValue)), const std::bad_variant_access&);
@@ -328,17 +328,17 @@ public:
void test_OpenRequest()
{
const ScriptRequest rq{g_GUI->GetScriptInterface()};
const Script::Request rq{g_GUI->GetScriptInterface()};
g_GUI->OpenChildPage(L"OpenRequest/Root/Page.xml",
Script::WriteStructuredClone(rq, JS::UndefinedHandleValue));
TS_ASSERT_EQUALS(g_GUI->GetPageCount(), 2);
g_GUI->TickObjects();
const ScriptRequest pageRq{g_GUI->GetActiveGUI()->GetScriptInterface()};
const Script::Request pageRq{g_GUI->GetActiveGUI()->GetScriptInterface()};
JS::RootedValue global{pageRq.cx, pageRq.globalValue()};
std::string result;
TS_ASSERT(ScriptFunction::Call(pageRq, global, "closePageCallback", result));
TS_ASSERT(Script::Function::Call(pageRq, global, "closePageCallback", result));
TS_ASSERT_STR_EQUALS(result, "Entry Continuation");
}
+2 -2
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@@ -36,7 +36,7 @@
#include "ps/Errors.h"
#include "ps/Filesystem.h"
#include "ps/GameSetup/GameSetup.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/Interface.h"
#include <algorithm>
#include <cstdint>
+8 -8
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -31,7 +31,7 @@ namespace JS { class CallArgs; }
namespace JSI_L10n
{
L10n* L10nGetter(const ScriptRequest&, JS::CallArgs&)
L10n* L10nGetter(const Script::Request&, JS::CallArgs&)
{
if (!g_L10n.IsInitialised())
{
@@ -63,21 +63,21 @@ std::string FormatMillisecondsIntoDateStringGMT(UDate milliseconds, const std::s
return g_L10n.FormatMillisecondsIntoDateString(milliseconds, formatString, false);
}
void RegisterScriptFunctions(const ScriptRequest& rq)
void RegisterScriptFunctions(const Script::Request& rq)
{
#define REGISTER_L10N(name) \
ScriptFunction::Register<&L10n::name, &L10nGetter>(rq, #name);
Script::Function::Register<&L10n::name, &L10nGetter>(rq, #name);
#define REGISTER_L10N_FUNC(func, name) \
ScriptFunction::Register<func, &L10nGetter>(rq, name);
Script::Function::Register<func, &L10nGetter>(rq, name);
REGISTER_L10N(Translate)
REGISTER_L10N(TranslateWithContext)
REGISTER_L10N(TranslatePlural)
REGISTER_L10N(TranslatePluralWithContext)
REGISTER_L10N(TranslateLines)
ScriptFunction::Register<&TranslateArray>(rq, "TranslateArray");
ScriptFunction::Register<&FormatMillisecondsIntoDateStringLocal>(rq, "FormatMillisecondsIntoDateStringLocal");
ScriptFunction::Register<&FormatMillisecondsIntoDateStringGMT>(rq, "FormatMillisecondsIntoDateStringGMT");
Script::Function::Register<&TranslateArray>(rq, "TranslateArray");
Script::Function::Register<&FormatMillisecondsIntoDateStringLocal>(rq, "FormatMillisecondsIntoDateStringLocal");
Script::Function::Register<&FormatMillisecondsIntoDateStringGMT>(rq, "FormatMillisecondsIntoDateStringGMT");
REGISTER_L10N(FormatDecimalNumberIntoString)
REGISTER_L10N(GetSupportedLocaleBaseNames)
+4 -4
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2021 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -18,7 +18,7 @@
#ifndef INCLUDED_JSINTERFACE_L10N
#define INCLUDED_JSINTERFACE_L10N
class ScriptRequest;
namespace Script { class Request; }
/**
* Namespace for the functions of the JavaScript interface for
@@ -36,12 +36,12 @@ namespace JSI_L10n
* internationalization and localization into the specified JavaScript
* context.
*
* @param ScriptRequest Script Request where RegisterScriptFunctions()
* @param Script::Request Script Request where RegisterScriptFunctions()
* registers the functions.
*
* @sa GuiScriptingInit()
*/
void RegisterScriptFunctions(const ScriptRequest& rq);
void RegisterScriptFunctions(const Script::Request& rq);
}
#endif // INCLUDED_JSINTERFACE_L10N
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@@ -160,9 +160,9 @@ std::vector<T> ts_make_vector(T* start, size_t size_bytes)
for (int j = 0; j < size; ++j) \
TS_ASSERT(!feq(m1._data[j], m2._data[j], epsilon));
class ScriptInterface;
namespace Script { class Interface; }
// Script-based testing setup (defined in test_setup.cpp). Defines TS_* functions.
void ScriptTestSetup(const ScriptInterface&);
void ScriptTestSetup(const Script::Interface&);
// Default game data directory
// (TODO: game-specific functions like this probably shouldn't be inside lib/, but it's useful
+22 -22
View File
@@ -35,9 +35,9 @@
#include "ps/GUID.h"
#include "ps/Pyrogenesis.h"
#include "scriptinterface/Object.h"
#include "scriptinterface/ScriptConversions.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Conversions.h"
#include "scriptinterface/Interface.h"
#include "scriptinterface/Request.h"
#include "scriptinterface/StructuredClone.h"
#include <ctime>
@@ -133,7 +133,7 @@ class XmppClient::Impl : public gloox::ConnectionListener, public gloox::MUCRoom
{
public:
// Basic
Impl(const ScriptInterface* scriptInterface, const std::string& sUsername,
Impl(const Script::Interface* scriptInterface, const std::string& sUsername,
const std::string& sPassword, const std::string& sRoom, const std::string& sNick,
const int historyRequestSize, const bool regOpt);
@@ -246,8 +246,8 @@ public:
std::vector<std::unique_ptr<const gloox::Tag>> m_BoardList;
/// Profile data
std::vector<std::unique_ptr<const gloox::Tag>> m_Profile;
/// ScriptInterface to root the values
const ScriptInterface* m_ScriptInterface;
/// Script::Interface to root the values
const Script::Interface* m_ScriptInterface;
/// Queue of messages for the GUI
JS::PersistentRootedVector<JS::Value> m_GuiMessageQueue;
/// Cache of all GUI messages received since the login
@@ -260,7 +260,7 @@ public:
/**
* Construct the XMPP client.
*
* @param scriptInterface - ScriptInterface to be used for storing GUI messages.
* @param scriptInterface - Script::Interface to be used for storing GUI messages.
* Can be left blank for non-visual applications.
* @param sUsername Username to login with of register.
* @param sPassword Password to login with or register.
@@ -269,14 +269,14 @@ public:
* @param historyRequestSize Number of stanzas of room history to request.
* @param regOpt If we are just registering or not.
*/
XmppClient::XmppClient(const ScriptInterface* scriptInterface, const std::string& username,
XmppClient::XmppClient(const Script::Interface* scriptInterface, const std::string& username,
const std::string& password, const std::string& room, const std::string& nick,
const int historyRequestSize, bool regOpt) :
m_Impl{std::make_unique<Impl>(scriptInterface, username, password, room, nick, historyRequestSize,
regOpt)}
{}
XmppClient::Impl::Impl(const ScriptInterface* scriptInterface, const std::string& sUsername,
XmppClient::Impl::Impl(const Script::Interface* scriptInterface, const std::string& sUsername,
const std::string& sPassword, const std::string& sRoom, const std::string& sNick,
const int historyRequestSize, bool regOpt)
: m_server{g_ConfigDB.Get("lobby.server", std::string{})},
@@ -527,7 +527,7 @@ void XmppClient::SendIqGetConnectionData(const std::string& jid, const std::stri
*
* @param data A JS array of game statistics
*/
void XmppClient::SendIqGameReport(const ScriptRequest& rq, JS::HandleValue data)
void XmppClient::SendIqGameReport(const Script::Request& rq, JS::HandleValue data)
{
gloox::JID echelonJid(m_Impl->m_echelonId);
@@ -570,7 +570,7 @@ void XmppClient::SendIqGameReport(const ScriptRequest& rq, JS::HandleValue data)
*
* @param data A JS array of game attributes
*/
void XmppClient::SendIqRegisterGame(const ScriptRequest& rq, JS::HandleValue data)
void XmppClient::SendIqRegisterGame(const Script::Request& rq, JS::HandleValue data)
{
gloox::JID xpartamuppJid(m_Impl->m_xpartamuppId);
@@ -720,7 +720,7 @@ void XmppClient::Impl::handleOOB(const gloox::JID&, const gloox::OOB&)
*
* @return A JS array containing all known players and their presences
*/
JS::Value XmppClient::GUIGetPlayerList(const ScriptRequest& rq)
JS::Value XmppClient::GUIGetPlayerList(const Script::Request& rq)
{
JS::RootedValueVector players{rq.cx};
@@ -747,7 +747,7 @@ JS::Value XmppClient::GUIGetPlayerList(const ScriptRequest& rq)
*
* @return A JS array containing all known games
*/
JS::Value XmppClient::GUIGetGameList(const ScriptRequest& rq)
JS::Value XmppClient::GUIGetGameList(const Script::Request& rq)
{
JS::RootedValueVector games{rq.cx};
@@ -774,7 +774,7 @@ JS::Value XmppClient::GUIGetGameList(const ScriptRequest& rq)
*
* @return A JS array containing all known leaderboard data
*/
JS::Value XmppClient::GUIGetBoardList(const ScriptRequest& rq)
JS::Value XmppClient::GUIGetBoardList(const Script::Request& rq)
{
JS::RootedValueVector boardList{rq.cx};
@@ -799,7 +799,7 @@ JS::Value XmppClient::GUIGetBoardList(const ScriptRequest& rq)
*
* @return A JS array containing the specific user's profile data
*/
JS::Value XmppClient::GUIGetProfile(const ScriptRequest& rq)
JS::Value XmppClient::GUIGetProfile(const Script::Request& rq)
{
JS::RootedValueVector profileData{rq.cx};
@@ -823,12 +823,12 @@ JS::Value XmppClient::GUIGetProfile(const ScriptRequest& rq)
* Message interfaces *
*****************************************************/
void SetGUIMessageProperty(const ScriptRequest&, JS::HandleObject /*messageObj*/)
void SetGUIMessageProperty(const Script::Request&, JS::HandleObject /*messageObj*/)
{
}
template<typename T, typename... Args>
void SetGUIMessageProperty(const ScriptRequest& rq, JS::HandleObject messageObj, const std::string& propertyName, const T& propertyValue, Args const&... args)
void SetGUIMessageProperty(const Script::Request& rq, JS::HandleObject messageObj, const std::string& propertyName, const T& propertyValue, Args const&... args)
{
JS::RootedValue scriptPropertyValue(rq.cx);
Script::ToJSVal(rq, &scriptPropertyValue, propertyValue);
@@ -845,7 +845,7 @@ void XmppClient::Impl::CreateGUIMessage(
{
if (!m_ScriptInterface)
return;
ScriptRequest rq(m_ScriptInterface);
Script::Request rq(m_ScriptInterface);
JS::RootedValue message(rq.cx);
Script::CreateObject(
rq,
@@ -872,12 +872,12 @@ bool XmppClient::GuiPollHasPlayerListUpdate()
return std::exchange(m_Impl->m_PlayerMapUpdate, false);
}
JS::Value XmppClient::GuiPollNewMessages(const ScriptInterface& guiInterface)
JS::Value XmppClient::GuiPollNewMessages(const Script::Interface& guiInterface)
{
if ((isConnected() && !m_Impl->m_initialLoadComplete) || m_Impl->m_GuiMessageQueue.empty())
return JS::UndefinedValue();
ScriptRequest rq(m_Impl->m_ScriptInterface);
Script::Request rq(m_Impl->m_ScriptInterface);
// Optimize for batch message processing that is more
// performance demanding than processing a lone message.
@@ -919,12 +919,12 @@ JS::Value XmppClient::GuiPollNewMessages(const ScriptInterface& guiInterface)
JS::RootedValue{rq.cx, JS::ObjectValue(*JS::NewArrayObject(rq.cx, messages))});
}
JS::Value XmppClient::GuiPollHistoricMessages(const ScriptInterface& guiInterface)
JS::Value XmppClient::GuiPollHistoricMessages(const Script::Interface& guiInterface)
{
if (m_Impl->m_HistoricGuiMessages.empty())
return JS::UndefinedValue();
ScriptRequest rq(m_Impl->m_ScriptInterface);
Script::Request rq(m_Impl->m_ScriptInterface);
JS::RootedValueVector messages{rq.cx};
+11 -11
View File
@@ -23,13 +23,13 @@
#include <js/Value.h>
#include <memory>
class ScriptInterface;
class ScriptRequest;
namespace Script { class Interface; }
namespace Script { class Request; }
class XmppClient
{
public:
XmppClient(const ScriptInterface* scriptInterface, const std::string& username,
XmppClient(const Script::Interface* scriptInterface, const std::string& username,
const std::string& password, const std::string& room, const std::string& nick,
const int historyRequestSize = 0, bool regOpt = false);
~XmppClient();
@@ -40,8 +40,8 @@ public:
void recv();
void SendIqGetBoardList();
void SendIqGetProfile(const std::string& player);
void SendIqGameReport(const ScriptRequest& rq, JS::HandleValue data);
void SendIqRegisterGame(const ScriptRequest& rq, JS::HandleValue data);
void SendIqGameReport(const Script::Request& rq, JS::HandleValue data);
void SendIqRegisterGame(const Script::Request& rq, JS::HandleValue data);
void SendIqGetConnectionData(const std::string& jid, const std::string& password,
const std::string& clientSalt, bool localIP);
void SendIqUnregisterGame();
@@ -59,13 +59,13 @@ public:
const char* GetRole(const std::string& nickname);
std::wstring GetRating(const std::string& nickname);
const std::wstring& GetSubject();
JS::Value GUIGetPlayerList(const ScriptRequest& rq);
JS::Value GUIGetGameList(const ScriptRequest& rq);
JS::Value GUIGetBoardList(const ScriptRequest& rq);
JS::Value GUIGetProfile(const ScriptRequest& rq);
JS::Value GUIGetPlayerList(const Script::Request& rq);
JS::Value GUIGetGameList(const Script::Request& rq);
JS::Value GUIGetBoardList(const Script::Request& rq);
JS::Value GUIGetProfile(const Script::Request& rq);
JS::Value GuiPollNewMessages(const ScriptInterface& guiInterface);
JS::Value GuiPollHistoricMessages(const ScriptInterface& guiInterface);
JS::Value GuiPollNewMessages(const Script::Interface& guiInterface);
JS::Value GuiPollHistoricMessages(const Script::Interface& guiInterface);
bool GuiPollHasPlayerListUpdate();
void SendMUCMessage(const std::string& message);
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -22,40 +22,40 @@
#include "lib/external_libraries/gloox.h"
#include "lib/utf8.h"
#include "lobby/GlooxConversion.h"
#include "scriptinterface/ScriptConversions.h"
#include "scriptinterface/Conversions.h"
#include <js/RootingAPI.h>
#include <js/TypeDecls.h>
#include <string>
class ScriptRequest;
namespace Script { class Request; }
template<> void Script::ToJSVal<gloox::Presence::PresenceType>(const ScriptRequest& rq, JS::MutableHandleValue ret, const gloox::Presence::PresenceType& val)
template<> void Script::ToJSVal<gloox::Presence::PresenceType>(const Script::Request& rq, JS::MutableHandleValue ret, const gloox::Presence::PresenceType& val)
{
ToJSVal(rq, ret, GetPresenceString(val));
}
template<> void Script::ToJSVal<gloox::MUCRoomRole>(const ScriptRequest& rq, JS::MutableHandleValue ret, const gloox::MUCRoomRole& val)
template<> void Script::ToJSVal<gloox::MUCRoomRole>(const Script::Request& rq, JS::MutableHandleValue ret, const gloox::MUCRoomRole& val)
{
ToJSVal(rq, ret, GetRoleString(val));
}
template<> void Script::ToJSVal<gloox::StanzaError>(const ScriptRequest& rq, JS::MutableHandleValue ret, const gloox::StanzaError& val)
template<> void Script::ToJSVal<gloox::StanzaError>(const Script::Request& rq, JS::MutableHandleValue ret, const gloox::StanzaError& val)
{
ToJSVal(rq, ret, wstring_from_utf8(StanzaErrorToString(val)));
}
template<> void Script::ToJSVal<gloox::ConnectionError>(const ScriptRequest& rq, JS::MutableHandleValue ret, const gloox::ConnectionError& val)
template<> void Script::ToJSVal<gloox::ConnectionError>(const Script::Request& rq, JS::MutableHandleValue ret, const gloox::ConnectionError& val)
{
ToJSVal(rq, ret, wstring_from_utf8(ConnectionErrorToString(val)));
}
template<> void Script::ToJSVal<gloox::RegistrationResult>(const ScriptRequest& rq, JS::MutableHandleValue ret, const gloox::RegistrationResult& val)
template<> void Script::ToJSVal<gloox::RegistrationResult>(const Script::Request& rq, JS::MutableHandleValue ret, const gloox::RegistrationResult& val)
{
ToJSVal(rq, ret, wstring_from_utf8(RegistrationResultToString(val)));
}
template<> void Script::ToJSVal<gloox::CertStatus>(const ScriptRequest& rq, JS::MutableHandleValue ret, const gloox::CertStatus& val)
template<> void Script::ToJSVal<gloox::CertStatus>(const Script::Request& rq, JS::MutableHandleValue ret, const gloox::CertStatus& val)
{
ToJSVal(rq, ret, wstring_from_utf8(CertificateErrorToString(val)));
}
+15 -15
View File
@@ -31,7 +31,7 @@
#include "ps/CStr.h"
#include "ps/Util.h"
#include "scriptinterface/FunctionWrapper.h"
#include "scriptinterface/ScriptExceptions.h"
#include "scriptinterface/Exceptions.h"
#include "third_party/encryption/pkcs5_pbkdf2.h"
#include <js/RootingAPI.h>
@@ -41,8 +41,8 @@
#include <stdexcept>
#include <string>
class ScriptInterface;
namespace JS { class CallArgs; }
namespace Script { class Interface; }
namespace JSI_Lobby
{
@@ -107,7 +107,7 @@ void StopXmppClient()
////////////////////////////////////////////////
////////////////////////////////////////////////
XmppClient* XmppGetter(const ScriptRequest&, JS::CallArgs&)
XmppClient* XmppGetter(const Script::Request&, JS::CallArgs&)
{
if (!g_XmppClient)
{
@@ -117,7 +117,7 @@ XmppClient* XmppGetter(const ScriptRequest&, JS::CallArgs&)
return g_XmppClient;
}
void SendRegisterGame(const ScriptInterface& scriptInterface, JS::HandleValue data)
void SendRegisterGame(const Script::Interface& scriptInterface, JS::HandleValue data)
{
if (!g_XmppClient)
throw std::logic_error{"Cannot call SendRegisterGame without an initialized XmppClient!"};
@@ -133,7 +133,7 @@ void SendRegisterGame(const ScriptInterface& scriptInterface, JS::HandleValue da
}
// Unlike other functions, this one just returns Undefined if XmppClient isn't initialised.
JS::Value GuiPollNewMessages(const ScriptInterface& scriptInterface)
JS::Value GuiPollNewMessages(const Script::Interface& scriptInterface)
{
if (!g_XmppClient)
return JS::UndefinedValue();
@@ -186,18 +186,18 @@ std::string EncryptPassword(const std::string& password, const std::string& user
#endif
void RegisterScriptFunctions(const ScriptRequest& rq)
void RegisterScriptFunctions(const Script::Request& rq)
{
// Lobby functions
ScriptFunction::Register<&HasXmppClient>(rq, "HasXmppClient");
ScriptFunction::Register<&SetRankedGame>(rq, "SetRankedGame");
Script::Function::Register<&HasXmppClient>(rq, "HasXmppClient");
Script::Function::Register<&SetRankedGame>(rq, "SetRankedGame");
#if CONFIG2_LOBBY // Allow the lobby to be disabled
ScriptFunction::Register<&StartXmppClient>(rq, "StartXmppClient");
ScriptFunction::Register<&StartRegisterXmppClient>(rq, "StartRegisterXmppClient");
ScriptFunction::Register<&StopXmppClient>(rq, "StopXmppClient");
Script::Function::Register<&StartXmppClient>(rq, "StartXmppClient");
Script::Function::Register<&StartRegisterXmppClient>(rq, "StartRegisterXmppClient");
Script::Function::Register<&StopXmppClient>(rq, "StopXmppClient");
#define REGISTER_XMPP(func, name) \
ScriptFunction::Register<&XmppClient::func, &XmppGetter>(rq, name)
Script::Function::Register<&XmppClient::func, &XmppGetter>(rq, name)
REGISTER_XMPP(connect, "ConnectXmppClient");
REGISTER_XMPP(disconnect, "DisconnectXmppClient");
@@ -205,7 +205,7 @@ void RegisterScriptFunctions(const ScriptRequest& rq)
REGISTER_XMPP(SendIqGetBoardList, "SendGetBoardList");
REGISTER_XMPP(SendIqGetProfile, "SendGetProfile");
REGISTER_XMPP(SendIqGameReport, "SendGameReport");
ScriptFunction::Register<&SendRegisterGame>(rq, "SendRegisterGame");
Script::Function::Register<&SendRegisterGame>(rq, "SendRegisterGame");
REGISTER_XMPP(SendIqUnregisterGame, "SendUnregisterGame");
REGISTER_XMPP(SendIqChangeStateGame, "SendChangeStateGame");
REGISTER_XMPP(GUIGetPlayerList, "GetPlayerList");
@@ -213,7 +213,7 @@ void RegisterScriptFunctions(const ScriptRequest& rq)
REGISTER_XMPP(GUIGetBoardList, "GetBoardList");
REGISTER_XMPP(GUIGetProfile, "GetProfile");
ScriptFunction::Register<&GuiPollNewMessages>(rq, "LobbyGuiPollNewMessages");
Script::Function::Register<&GuiPollNewMessages>(rq, "LobbyGuiPollNewMessages");
REGISTER_XMPP(GuiPollHistoricMessages, "LobbyGuiPollHistoricMessages");
REGISTER_XMPP(GuiPollHasPlayerListUpdate, "LobbyGuiPollHasPlayerListUpdate");
REGISTER_XMPP(SendMUCMessage, "LobbySendMessage");
@@ -231,7 +231,7 @@ void RegisterScriptFunctions(const ScriptRequest& rq)
REGISTER_XMPP(GetSubject, "LobbyGetRoomSubject");
#undef REGISTER_XMPP
ScriptFunction::Register<&EncryptPassword>(rq, "EncryptPassword");
Script::Function::Register<&EncryptPassword>(rq, "EncryptPassword");
#endif // CONFIG2_LOBBY
}
}
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2019 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -18,11 +18,11 @@
#ifndef INCLUDED_JSI_LOBBY
#define INCLUDED_JSI_LOBBY
class ScriptRequest;
namespace Script { class Request; }
namespace JSI_Lobby
{
void RegisterScriptFunctions(const ScriptRequest& rq);
void RegisterScriptFunctions(const Script::Request& rq);
}
#endif // INCLUDED_JSI_LOBBY
+10 -10
View File
@@ -81,11 +81,11 @@ that of Atlas depending on commandline parameters.
#include "renderer/Renderer.h"
#include "rlinterface/RLInterface.h"
#include "scriptinterface/JSON.h"
#include "scriptinterface/ScriptContext.h"
#include "scriptinterface/ScriptConversions.h"
#include "scriptinterface/ScriptEngine.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Context.h"
#include "scriptinterface/Conversions.h"
#include "scriptinterface/Engine.h"
#include "scriptinterface/Interface.h"
#include "scriptinterface/Request.h"
#include "simulation2/system/TurnManager.h"
#include "soundmanager/ISoundManager.h"
@@ -208,7 +208,7 @@ static Input::Reaction MainInputHandler(const SDL_Event& ev)
else
{
LOGMESSAGE("Installed mod %s", installer.GetInstalledMods().front());
ScriptInterface modInterface("Engine", "Mod", g_ScriptContext);
Script::Interface modInterface("Engine", "Mod", g_ScriptContext);
g_Mods.UpdateAvailableMods(modInterface);
RestartEngine();
}
@@ -242,7 +242,7 @@ static Input::Reaction MainInputHandler(const SDL_Event& ev)
// dispatch all pending events to the various receivers.
static void PumpEvents()
{
ScriptRequest rq(g_GUI->GetScriptInterface());
Script::Request rq(g_GUI->GetScriptInterface());
PROFILE3("dispatch events");
@@ -586,7 +586,7 @@ static void RunGameOrAtlas(const std::span<const char* const> argv)
// We need to initialize SpiderMonkey and libxml2 in the main thread before
// any thread uses them. So initialize them here before we might run Atlas.
ScriptEngine scriptEngine;
Script::Engine scriptEngine;
CXeromycesEngine xeromycesEngine;
// Initialise the global task manager at this point (JS & Profiler2 are set up).
@@ -689,7 +689,7 @@ static void RunGameOrAtlas(const std::span<const char* const> argv)
installedMods = installer.GetInstalledMods();
ScriptInterface modInterface("Engine", "Mod", g_ScriptContext);
Script::Interface modInterface("Engine", "Mod", g_ScriptContext);
g_Mods.UpdateAvailableMods(modInterface);
}
@@ -714,7 +714,7 @@ static void RunGameOrAtlas(const std::span<const char* const> argv)
~VisualData() = default;
private:
ScriptInterface scriptInterface{"Engine", "gui", *g_ScriptContext};
Script::Interface scriptInterface{"Engine", "gui", *g_ScriptContext};
std::unique_ptr<InputHandlers> inputHandlers;
Input::Handler<Input::Reaction(&)(const SDL_Event&)> mainInputHandler{
g_VideoMode.m_InputManager, Input::Slot::PRIMARY, MainInputHandler};
+17 -17
View File
@@ -39,8 +39,8 @@
#include "ps/Profile.h"
#include "ps/Threading.h"
#include "scriptinterface/JSON.h"
#include "scriptinterface/ScriptContext.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/Context.h"
#include "scriptinterface/Interface.h"
#include "simulation2/Simulation2.h"
#include "simulation2/system/TurnManager.h"
@@ -364,17 +364,17 @@ void CNetClient::CheckServerConnection()
}
}
JSObject* CNetClient::GetNextGUIMessage(const ScriptInterface& guiInterface)
JSObject* CNetClient::GetNextGUIMessage(const Script::Interface& guiInterface)
{
Unregister(nullptr);
const ScriptRequest rq{guiInterface};
const Script::Request rq{guiInterface};
m_GuiMessagePoll.emplace(GuiPollData{guiInterface, {rq.cx, JS::NewPromiseObject(rq.cx, nullptr)}});
FetchMessage();
return m_GuiMessagePoll.value().promise;
}
void CNetClient::Unregister(const ScriptInterface* guiInterface)
void CNetClient::Unregister(const Script::Interface* guiInterface)
{
if (!m_GuiMessagePoll.has_value() ||
(guiInterface && &m_GuiMessagePoll.value().interface != guiInterface))
@@ -382,7 +382,7 @@ void CNetClient::Unregister(const ScriptInterface* guiInterface)
return;
}
auto& [interface, promise] = m_GuiMessagePoll.value();
const ScriptRequest oldRq{interface};
const Script::Request oldRq{interface};
JS::ResolvePromise(oldRq.cx, promise, JS::UndefinedHandleValue);
m_GuiMessagePoll.reset();
}
@@ -395,7 +395,7 @@ void CNetClient::FetchMessage()
return;
}
const ScriptRequest rq{m_GuiMessagePoll.value().interface};
const Script::Request rq{m_GuiMessagePoll.value().interface};
JS::RootedValue message{rq.cx};
Script::ReadStructuredClone(rq, std::move(m_GuiMessageQueue.front()), &message);
m_GuiMessageQueue.pop_front();
@@ -405,7 +405,7 @@ void CNetClient::FetchMessage()
std::string CNetClient::TestReadGuiMessages()
{
ScriptRequest rq(GetScriptInterface());
Script::Request rq(GetScriptInterface());
std::string r;
while (true)
@@ -422,14 +422,14 @@ std::string CNetClient::TestReadGuiMessages()
return r;
}
const ScriptInterface& CNetClient::GetScriptInterface()
const Script::Interface& CNetClient::GetScriptInterface()
{
return m_Game->GetSimulation2()->GetScriptInterface();
}
void CNetClient::PostPlayerAssignmentsToScript()
{
ScriptRequest rq(GetScriptInterface());
Script::Request rq(GetScriptInterface());
JS::RootedValue newAssignments(rq.cx);
Script::CreateObject(rq, &newAssignments);
@@ -491,7 +491,7 @@ void CNetClient::HandleDisconnect(u32 reason)
SetCurrState(NCS_UNCONNECTED);
}
void CNetClient::SendGameSetupMessage(JS::MutableHandleValue attrs, const ScriptInterface& scriptInterface)
void CNetClient::SendGameSetupMessage(JS::MutableHandleValue attrs, const Script::Interface& scriptInterface)
{
CGameSetupMessage gameSetup(scriptInterface);
gameSetup.m_Data = attrs;
@@ -836,8 +836,8 @@ bool CNetClient::OnGameStart(CNetClient* client, CFsmEvent<CNetMessage*>* event)
CGameStartMessage* message = static_cast<CGameStartMessage*>(event->GetParamRef());
const ScriptInterface& scriptInterface{client->m_Game->GetSimulation2()->GetScriptInterface()};
ScriptRequest rq{scriptInterface};
const Script::Interface& scriptInterface{client->m_Game->GetSimulation2()->GetScriptInterface()};
Script::Request rq{scriptInterface};
JS::RootedValue initAttribs{rq.cx};
Script::ParseJSON(rq, message->m_InitAttributes, &initAttribs);
@@ -851,8 +851,8 @@ bool CNetClient::OnSavedGameStart(CNetClient* client, CFsmEvent<CNetMessage*>* e
ENSURE(event->GetType() == static_cast<uint>(NMT_SAVED_GAME_START));
CGameSavedStartMessage* message{static_cast<CGameSavedStartMessage*>(event->GetParamRef())};
const ScriptInterface& scriptInterface{client->m_Game->GetSimulation2()->GetScriptInterface()};
ScriptRequest rq{scriptInterface};
const Script::Interface& scriptInterface{client->m_Game->GetSimulation2()->GetScriptInterface()};
Script::Request rq{scriptInterface};
const std::shared_ptr<JS::RootedValue> initAttribs{std::make_shared<JS::RootedValue>(rq.cx)};
Script::ParseJSON(rq, message->m_InitAttributes, &*initAttribs);
@@ -1058,8 +1058,8 @@ bool CNetClient::OnFlare(CNetClient* client, CFsmEvent<CNetMessage*>* event)
CFlareMessage* message = static_cast<CFlareMessage*>(event->GetParamRef());
const ScriptInterface& scriptInterface = client->m_Game->GetSimulation2()->GetScriptInterface();
ScriptRequest rq(scriptInterface);
const Script::Interface& scriptInterface = client->m_Game->GetSimulation2()->GetScriptInterface();
Script::Request rq(scriptInterface);
JS::RootedValue position(rq.cx);
Script::CreateObject(
rq, &position,
+11 -10
View File
@@ -26,7 +26,7 @@
#include "network/NetMessage.h"
#include "ps/CStr.h"
#include "scriptinterface/Object.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Request.h"
#include "scriptinterface/StructuredClone.h"
#include <ctime>
@@ -43,9 +43,10 @@ class CGame;
class CNetClientSession;
class CNetClientTurnManager;
class JSTracer;
class ScriptInterface;
class XmppClient;
namespace Script { class Interface; }
typedef struct _ENetHost ENetHost;
// NetClient session FSM states
@@ -130,7 +131,7 @@ public:
/**
* Retrieves the next queued GUI message, and removes it from the queue.
* The returned value is in the JS context of the provided
* @c ScriptInterface.
* @c Script::Interface.
*
* This is the only mechanism for the networking code to send messages to
* the GUI.
@@ -141,13 +142,13 @@ public:
*
* @return a promise resolving to the next message.
*/
JSObject* GetNextGUIMessage(const ScriptInterface& guiInterface);
JSObject* GetNextGUIMessage(const Script::Interface& guiInterface);
/**
* Has to be called bevore the @c ScriptInterface gets destroied so that
* Has to be called bevore the @c Script::Interface gets destroied so that
* no future messages are sent to it.
*/
void Unregister(const ScriptInterface* guiInterface);
void Unregister(const Script::Interface* guiInterface);
/**
* Add a message to the queue, to be read by GuiPoll.
@@ -156,7 +157,7 @@ public:
template<typename... Args>
void PushGuiMessage(Args const&... args)
{
ScriptRequest rq(GetScriptInterface());
Script::Request rq(GetScriptInterface());
JS::RootedValue message(rq.cx);
Script::CreateObject(rq, &message, args...);
@@ -173,7 +174,7 @@ public:
* Get the script interface associated with this network client,
* which is equivalent to the one used by the CGame in the constructor.
*/
const ScriptInterface& GetScriptInterface();
const Script::Interface& GetScriptInterface();
/**
* Send a message to the server.
@@ -203,7 +204,7 @@ public:
*/
void LoadFinished();
void SendGameSetupMessage(JS::MutableHandleValue attrs, const ScriptInterface& scriptInterface);
void SendGameSetupMessage(JS::MutableHandleValue attrs, const Script::Interface& scriptInterface);
void SendAssignPlayerMessage(const int playerID, const CStr& guid);
@@ -351,7 +352,7 @@ private:
struct GuiPollData
{
const ScriptInterface& interface;
const Script::Interface& interface;
/**
* In the context of interface.
* When the promise is pending @see Poll should fill it with a message.
+2 -2
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -93,7 +93,7 @@ CStr CNetMessage::ToString() const
CNetMessage* CNetMessageFactory::CreateMessage(const void* pData,
size_t dataSize,
const ScriptInterface& scriptInterface)
const Script::Interface& scriptInterface)
{
CNetMessage* pNewMessage = NULL;
CNetMessage header;
+9 -9
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 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 @@
#include <js/TypeDecls.h>
#include <js/Value.h>
class ScriptInterface;
namespace Script { class Interface; }
// We need the enum from NetMessages.h, but we can't create any classes in
// NetMessages.h, since they in turn require CNetMessage to be defined
@@ -113,7 +113,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, const ScriptInterface& scriptInterface);
static CNetMessage* CreateMessage(const void* pData, size_t dataSize, const Script::Interface& scriptInterface);
};
/**
@@ -123,8 +123,8 @@ public:
class CSimulationMessage : public CNetMessage
{
public:
CSimulationMessage(const ScriptInterface& scriptInterface);
CSimulationMessage(const ScriptInterface& scriptInterface, u32 client, i32 player, u32 turn, JS::HandleValue data);
CSimulationMessage(const Script::Interface& scriptInterface);
CSimulationMessage(const Script::Interface& 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.
@@ -142,7 +142,7 @@ public:
u32 m_Turn;
JS::PersistentRooted<JS::Value> m_Data;
private:
const ScriptInterface& m_ScriptInterface;
const Script::Interface& m_ScriptInterface;
};
/**
@@ -152,8 +152,8 @@ class CGameSetupMessage : public CNetMessage
{
NONCOPYABLE(CGameSetupMessage);
public:
CGameSetupMessage(const ScriptInterface& scriptInterface);
CGameSetupMessage(const ScriptInterface& scriptInterface, JS::HandleValue data);
CGameSetupMessage(const Script::Interface& scriptInterface);
CGameSetupMessage(const Script::Interface& 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;
@@ -161,7 +161,7 @@ public:
JS::PersistentRootedValue m_Data;
private:
const ScriptInterface& m_ScriptInterface;
const Script::Interface& m_ScriptInterface;
};
// This time, the classes are created
+16 -16
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 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 @@
#include "network/NetMessage.h"
#include "ps/CStr.h"
#include "scriptinterface/JSON.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Request.h"
#include "simulation2/serialization/BinarySerializer.h"
#include "simulation2/serialization/StdDeserializer.h"
#include "simulation2/serialization/StdSerializer.h"
@@ -36,7 +36,7 @@
#include <sstream>
#include <string>
class ScriptInterface;
namespace Script { class Interface; }
class CBufferBinarySerializerImpl
{
@@ -68,7 +68,7 @@ public:
class CBufferBinarySerializer : public CBinarySerializer<CBufferBinarySerializerImpl>
{
public:
CBufferBinarySerializer(const ScriptInterface& scriptInterface, u8* buffer) :
CBufferBinarySerializer(const Script::Interface& scriptInterface, u8* buffer) :
CBinarySerializer<CBufferBinarySerializerImpl>(scriptInterface, buffer)
{
}
@@ -105,7 +105,7 @@ public:
class CLengthBinarySerializer : public CBinarySerializer<CLengthBinarySerializerImpl>
{
public:
CLengthBinarySerializer(const ScriptInterface& scriptInterface) :
CLengthBinarySerializer(const Script::Interface& scriptInterface) :
CBinarySerializer<CLengthBinarySerializerImpl>(scriptInterface)
{
}
@@ -116,18 +116,18 @@ public:
}
};
CSimulationMessage::CSimulationMessage(const ScriptInterface& scriptInterface) :
CSimulationMessage::CSimulationMessage(const Script::Interface& scriptInterface) :
CNetMessage(NMT_SIMULATION_COMMAND), m_ScriptInterface(scriptInterface)
{
ScriptRequest rq(scriptInterface);
Script::Request rq(scriptInterface);
m_Data.init(rq.cx);
}
CSimulationMessage::CSimulationMessage(const ScriptInterface& scriptInterface, u32 client, i32 player, u32 turn, JS::HandleValue data) :
CSimulationMessage::CSimulationMessage(const Script::Interface& 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)
{
ScriptRequest rq(scriptInterface);
Script::Request rq(scriptInterface);
m_Data.init(rq.cx, data);
}
@@ -138,7 +138,7 @@ CSimulationMessage::CSimulationMessage(const CSimulationMessage& orig) :
m_Turn(orig.m_Turn),
CNetMessage(orig)
{
ScriptRequest rq(m_ScriptInterface);
Script::Request rq(m_ScriptInterface);
m_Data.init(rq.cx, orig.m_Data);
}
@@ -187,7 +187,7 @@ size_t CSimulationMessage::GetSerializedLength() const
CStr CSimulationMessage::ToString() const
{
std::string source = Script::ToString(ScriptRequest(m_ScriptInterface), const_cast<JS::PersistentRootedValue*>(&m_Data));
std::string source = Script::ToString(Script::Request(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 << " }";
@@ -195,17 +195,17 @@ CStr CSimulationMessage::ToString() const
}
CGameSetupMessage::CGameSetupMessage(const ScriptInterface& scriptInterface) :
CGameSetupMessage::CGameSetupMessage(const Script::Interface& scriptInterface) :
CNetMessage(NMT_GAME_SETUP), m_ScriptInterface(scriptInterface)
{
ScriptRequest rq(m_ScriptInterface);
Script::Request rq(m_ScriptInterface);
m_Data.init(rq.cx);
}
CGameSetupMessage::CGameSetupMessage(const ScriptInterface& scriptInterface, JS::HandleValue data) :
CGameSetupMessage::CGameSetupMessage(const Script::Interface& scriptInterface, JS::HandleValue data) :
CNetMessage(NMT_GAME_SETUP), m_ScriptInterface(scriptInterface)
{
ScriptRequest rq(m_ScriptInterface);
Script::Request rq(m_ScriptInterface);
m_Data.init(rq.cx, data);
}
@@ -237,7 +237,7 @@ size_t CGameSetupMessage::GetSerializedLength() const
CStr CGameSetupMessage::ToString() const
{
std::string source = Script::ToString(ScriptRequest(m_ScriptInterface), const_cast<JS::PersistentRootedValue*>(&m_Data));
std::string source = Script::ToString(Script::Request(m_ScriptInterface), const_cast<JS::PersistentRootedValue*>(&m_Data));
std::stringstream stream;
stream << "CGameSetupMessage { m_Data: " << source << " }";
+13 -13
View File
@@ -46,9 +46,9 @@
#include "ps/algorithm.h"
#include "scriptinterface/JSON.h"
#include "scriptinterface/Object.h"
#include "scriptinterface/ScriptContext.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Context.h"
#include "scriptinterface/Interface.h"
#include "scriptinterface/Request.h"
#include "simulation2/system/TurnManager.h"
#include <algorithm>
@@ -373,14 +373,14 @@ void CNetServerWorker::Run(const std::string& initAttributes)
// The script context uses the profiler and therefore the thread must be registered before the context is created
g_Profiler2.RegisterCurrentThread("Net server");
// We create a new ScriptContext for this network thread, with a single ScriptInterface.
ScriptContext netServerContext;
m_ScriptInterface = new ScriptInterface("Engine", "Net server", netServerContext);
// We create a new Script::Context for this network thread, with a single Script::Interface.
Script::Context netServerContext;
m_ScriptInterface = new Script::Interface("Engine", "Net server", netServerContext);
m_InitAttributes.init(m_ScriptInterface->GetGeneralJSContext(), JS::UndefinedValue());
if (!initAttributes.empty())
{
ScriptRequest rq(m_ScriptInterface);
Script::Request rq(m_ScriptInterface);
JS::RootedValue gameAttributesVal(rq.cx);
Script::ParseJSON(rq, std::move(initAttributes), &gameAttributesVal);
m_InitAttributes = gameAttributesVal;
@@ -409,7 +409,7 @@ bool CNetServerWorker::RunStep()
m_ScriptInterface->GetContext().MaybeIncrementalGC();
ScriptRequest rq(m_ScriptInterface);
Script::Request rq(m_ScriptInterface);
std::vector<bool> newStartGame;
std::vector<std::pair<CStr, CStr>> newLobbyAuths;
@@ -845,7 +845,7 @@ void CNetServerWorker::SendPlayerAssignments()
Multicast(&message, { NSS_PREGAME, NSS_JOIN_SYNCING, NSS_INGAME });
}
const ScriptInterface& CNetServerWorker::GetScriptInterface()
const Script::Interface& CNetServerWorker::GetScriptInterface()
{
return *m_ScriptInterface;
}
@@ -1135,7 +1135,7 @@ bool CNetServerWorker::OnAuthenticate(CNetServerSession* session, CFsmEvent<CNet
// started.
CJoinSyncStartMessage message;
message.m_InitAttributes = Script::StringifyJSON(
ScriptRequest{server.GetScriptInterface()}, &server.m_InitAttributes);
Script::Request{server.GetScriptInterface()}, &server.m_InitAttributes);
(*sessionIt)->SendMessage(&message);
});
@@ -1154,8 +1154,8 @@ bool CNetServerWorker::OnSimulationCommand(CNetServerSession* session, CFsmEvent
// Ignore messages sent by one player on behalf of another player
// unless cheating is enabled
bool cheatsEnabled = false;
const ScriptInterface& scriptInterface = server.GetScriptInterface();
ScriptRequest rq(scriptInterface);
const Script::Interface& scriptInterface = server.GetScriptInterface();
Script::Request rq(scriptInterface);
JS::RootedValue settings(rq.cx);
Script::GetProperty(rq, server.m_InitAttributes, "settings", &settings);
if (Script::HasProperty(rq, settings, "CheatsEnabled"))
@@ -1576,7 +1576,7 @@ void CNetServerWorker::PreStartGame(const CStr& initAttribs)
SendPlayerAssignments();
// Update init attributes. They should no longer change.
Script::ParseJSON(ScriptRequest(m_ScriptInterface), initAttribs, &m_InitAttributes);
Script::ParseJSON(Script::Request(m_ScriptInterface), initAttribs, &m_InitAttributes);
}
void CNetServerWorker::StartGame(const CStr& initAttribs)
+4 -4
View File
@@ -42,8 +42,8 @@ class CNetServerTurnManager;
class CNetStatsTable;
class CPlayerAssignmentMessage;
class CSimulationMessage;
class ScriptInterface;
class ScriptRequest;
namespace Script { class Interface; }
namespace Script { class Request; }
template <typename MessageType> class CFsmEvent;
enum NetServerState
@@ -176,7 +176,7 @@ private:
/**
* Get the script context used for init attributes.
*/
const ScriptInterface& GetScriptInterface();
const Script::Interface& GetScriptInterface();
/**
* Set the turn length to a fixed value.
@@ -242,7 +242,7 @@ private:
* (TODO: we shouldn't bother deserializing (except for debug printing of messages),
* we should just forward messages blindly and efficiently.)
*/
ScriptInterface* m_ScriptInterface{nullptr};
Script::Interface* m_ScriptInterface{nullptr};
PlayerAssignmentMap m_PlayerAssignments;
@@ -36,8 +36,8 @@
#include "ps/SavedGame.h"
#include "scriptinterface/FunctionWrapper.h"
#include "scriptinterface/JSON.h"
#include "scriptinterface/ScriptConversions.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Conversions.h"
#include "scriptinterface/Request.h"
#include "scriptinterface/StructuredClone.h"
#include <fmt/format.h>
@@ -51,7 +51,7 @@
#include <utility>
#include <vector>
class ScriptInterface;
namespace Script { class Interface; }
namespace JSI_Network
{
@@ -159,7 +159,7 @@ CStr GetPlayerGUID()
return g_NetClient->GetGUID();
}
JS::Value PollNetworkClient(const ScriptInterface& guiInterface)
JS::Value PollNetworkClient(const Script::Interface& guiInterface)
{
if (!g_NetClient)
throw std::logic_error{"Network client not present"};
@@ -167,12 +167,12 @@ JS::Value PollNetworkClient(const ScriptInterface& guiInterface)
return JS::ObjectValue(*g_NetClient->GetNextGUIMessage(guiInterface));
}
void SendGameSetupMessage(const ScriptInterface& scriptInterface, JS::HandleValue attribs1)
void SendGameSetupMessage(const Script::Interface& scriptInterface, JS::HandleValue attribs1)
{
ENSURE(g_NetClient);
// TODO: This is a workaround because we need to pass a MutableHandle to a JSAPI functions somewhere (with no obvious reason).
ScriptRequest rq(scriptInterface);
Script::Request rq(scriptInterface);
JS::RootedValue attribs(rq.cx, attribs1);
g_NetClient->SendGameSetupMessage(&attribs, scriptInterface);
@@ -192,7 +192,7 @@ void KickPlayer(const CStrW& playerName, bool ban)
g_NetClient->SendKickPlayerMessage(playerName, ban);
}
void SendNetworkChat(const ScriptRequest& rq, const CStrW& message, JS::HandleValue handle)
void SendNetworkChat(const Script::Request& rq, const CStrW& message, JS::HandleValue handle)
{
ENSURE(g_NetClient);
@@ -227,11 +227,11 @@ void ClearAllPlayerReady ()
g_NetClient->SendClearAllReadyMessage();
}
void StartNetworkGame(const ScriptInterface& scriptInterface, JS::HandleValue savegame, JS::HandleValue attribs1)
void StartNetworkGame(const Script::Interface& scriptInterface, JS::HandleValue savegame, JS::HandleValue attribs1)
{
ENSURE(g_NetClient);
ScriptRequest rq(scriptInterface);
Script::Request rq(scriptInterface);
JS::RootedValue attribs(rq.cx, attribs1);
std::string attributesAsString{Script::StringifyJSON(rq, &attribs)};
@@ -267,7 +267,7 @@ void SendNetworkFlare(JS::HandleValue position)
{
ENSURE(g_NetClient);
ScriptRequest rq(g_NetClient->GetScriptInterface());
Script::Request rq(g_NetClient->GetScriptInterface());
ENSURE(position.isObject());
JS::RootedObject positionObj(rq.cx, &position.toObject());
JS::RootedValue positionX(rq.cx);
@@ -286,26 +286,26 @@ void SendNetworkFlare(JS::HandleValue position)
);
}
void RegisterScriptFunctions(const ScriptRequest& rq)
void RegisterScriptFunctions(const Script::Request& rq)
{
ScriptFunction::Register<&GetDefaultPort>(rq, "GetDefaultPort");
ScriptFunction::Register<&IsNetController>(rq, "IsNetController");
ScriptFunction::Register<&HasNetServer>(rq, "HasNetServer");
ScriptFunction::Register<&HasNetClient>(rq, "HasNetClient");
ScriptFunction::Register<&StartNetworkHost>(rq, "StartNetworkHost");
ScriptFunction::Register<&StartNetworkJoin>(rq, "StartNetworkJoin");
ScriptFunction::Register<&StartNetworkJoinLobby>(rq, "StartNetworkJoinLobby");
ScriptFunction::Register<&DisconnectNetworkGame>(rq, "DisconnectNetworkGame");
ScriptFunction::Register<&GetPlayerGUID>(rq, "GetPlayerGUID");
ScriptFunction::Register<&PollNetworkClient>(rq, "PollNetworkClient");
ScriptFunction::Register<&SendGameSetupMessage>(rq, "SendGameSetupMessage");
ScriptFunction::Register<&AssignNetworkPlayer>(rq, "AssignNetworkPlayer");
ScriptFunction::Register<&KickPlayer>(rq, "KickPlayer");
ScriptFunction::Register<&SendNetworkChat>(rq, "SendNetworkChat");
ScriptFunction::Register<&SendNetworkReady>(rq, "SendNetworkReady");
ScriptFunction::Register<&ClearAllPlayerReady>(rq, "ClearAllPlayerReady");
ScriptFunction::Register<&StartNetworkGame>(rq, "StartNetworkGame");
ScriptFunction::Register<&SetTurnLength>(rq, "SetTurnLength");
ScriptFunction::Register<&SendNetworkFlare>(rq, "SendNetworkFlare");
Script::Function::Register<&GetDefaultPort>(rq, "GetDefaultPort");
Script::Function::Register<&IsNetController>(rq, "IsNetController");
Script::Function::Register<&HasNetServer>(rq, "HasNetServer");
Script::Function::Register<&HasNetClient>(rq, "HasNetClient");
Script::Function::Register<&StartNetworkHost>(rq, "StartNetworkHost");
Script::Function::Register<&StartNetworkJoin>(rq, "StartNetworkJoin");
Script::Function::Register<&StartNetworkJoinLobby>(rq, "StartNetworkJoinLobby");
Script::Function::Register<&DisconnectNetworkGame>(rq, "DisconnectNetworkGame");
Script::Function::Register<&GetPlayerGUID>(rq, "GetPlayerGUID");
Script::Function::Register<&PollNetworkClient>(rq, "PollNetworkClient");
Script::Function::Register<&SendGameSetupMessage>(rq, "SendGameSetupMessage");
Script::Function::Register<&AssignNetworkPlayer>(rq, "AssignNetworkPlayer");
Script::Function::Register<&KickPlayer>(rq, "KickPlayer");
Script::Function::Register<&SendNetworkChat>(rq, "SendNetworkChat");
Script::Function::Register<&SendNetworkReady>(rq, "SendNetworkReady");
Script::Function::Register<&ClearAllPlayerReady>(rq, "ClearAllPlayerReady");
Script::Function::Register<&StartNetworkGame>(rq, "StartNetworkGame");
Script::Function::Register<&SetTurnLength>(rq, "SetTurnLength");
Script::Function::Register<&SendNetworkFlare>(rq, "SendNetworkFlare");
}
}
@@ -1,4 +1,4 @@
/* Copyright (C) 2021 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -18,11 +18,11 @@
#ifndef INCLUDED_JSI_NETWORK
#define INCLUDED_JSI_NETWORK
class ScriptRequest;
namespace Script { class Request; }
namespace JSI_Network
{
void RegisterScriptFunctions(const ScriptRequest& rq);
void RegisterScriptFunctions(const Script::Request& rq);
}
#endif // INCLUDED_JSI_NETWORK
+6 -6
View File
@@ -35,8 +35,8 @@
#include "ps/XML/Xeromyces.h"
#include "scriptinterface/JSON.h"
#include "scriptinterface/Object.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Interface.h"
#include "scriptinterface/Request.h"
#include "simulation2/system/TurnManager.h"
#include <SDL_timer.h>
@@ -152,8 +152,8 @@ public:
// This doesn't actually test much, it just runs a very quick multiplayer game
// and prints a load of debug output so you can see if anything funny's going on
ScriptInterface scriptInterface("Engine", "Test", g_ScriptContext);
ScriptRequest rq(scriptInterface);
Script::Interface scriptInterface("Engine", "Test", g_ScriptContext);
Script::Request rq(scriptInterface);
TestStdoutLogger logger;
@@ -229,8 +229,8 @@ public:
void DISABLED_test_rejoin()
{
ScriptInterface scriptInterface("Engine", "Test", g_ScriptContext);
ScriptRequest rq(scriptInterface);
Script::Interface scriptInterface("Engine", "Test", g_ScriptContext);
Script::Request rq(scriptInterface);
TestStdoutLogger logger;
+4 -4
View File
@@ -21,8 +21,8 @@
#include "network/NetMessage.h"
#include "ps/CStr.h"
#include "scriptinterface/Object.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Interface.h"
#include "scriptinterface/Request.h"
#include <cstddef>
#include <js/RootingAPI.h>
@@ -34,8 +34,8 @@ class TestNetMessage : public CxxTest::TestSuite
public:
void test_sim()
{
ScriptInterface script("Test", "Test", g_ScriptContext);
ScriptRequest rq(script);
Script::Interface script("Test", "Test", g_ScriptContext);
Script::Request rq(script);
JS::RootedValueArray<1> val{rq.cx, JS::ValueArray<1>{JS::NumberValue(4)}};
CSimulationMessage msg(script, 1, 2, 3,
+4 -4
View File
@@ -49,8 +49,8 @@
#include "ps/Profiler2.h"
#include "ps/VideoMode.h"
#include "scriptinterface/JSON.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Interface.h"
#include "scriptinterface/Request.h"
#include <SDL_clipboard.h>
#include <SDL_events.h>
@@ -611,8 +611,8 @@ void CConsole::ProcessBuffer(const wchar_t* szLine)
}
// Process it as JavaScript
std::shared_ptr<ScriptInterface> pScriptInterface = g_GUI->GetActiveGUI()->GetScriptInterface();
ScriptRequest rq(*pScriptInterface);
std::shared_ptr<Script::Interface> pScriptInterface = g_GUI->GetActiveGUI()->GetScriptInterface();
Script::Request rq(*pScriptInterface);
JS::RootedValue rval(rq.cx);
pScriptInterface->Eval(CStrW(szLine).ToUTF8().c_str(), &rval);
+10 -10
View File
@@ -43,9 +43,9 @@
#include "scriptinterface/FunctionWrapper.h"
#include "scriptinterface/JSON.h"
#include "scriptinterface/Object.h"
#include "scriptinterface/ScriptContext.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Context.h"
#include "scriptinterface/Interface.h"
#include "scriptinterface/Request.h"
#include "simulation2/Simulation2.h"
#include "simulation2/components/ICmpPlayer.h"
#include "simulation2/components/ICmpPlayerManager.h"
@@ -204,8 +204,8 @@ bool CGame::StartVisualReplay(const OsPath& replayPath)
std::string line;
std::getline(*m_ReplayStream, line);
const ScriptInterface& scriptInterface = m_Simulation2->GetScriptInterface();
ScriptRequest rq(scriptInterface);
const Script::Interface& scriptInterface = m_Simulation2->GetScriptInterface();
Script::Request rq(scriptInterface);
JS::RootedValue attribs(rq.cx);
Script::ParseJSON(rq, line, &attribs);
@@ -221,8 +221,8 @@ bool CGame::StartVisualReplay(const OsPath& replayPath)
**/
void CGame::RegisterInit(const JS::HandleValue attribs, const std::string& savedState)
{
const ScriptInterface& scriptInterface = m_Simulation2->GetScriptInterface();
ScriptRequest rq(scriptInterface);
const Script::Interface& scriptInterface = m_Simulation2->GetScriptInterface();
Script::Request rq(scriptInterface);
m_IsSavedGame = !savedState.empty();
@@ -358,12 +358,12 @@ PSRETURN CGame::ReallyStartGame()
// Call the reallyStartGame GUI function, but only if it exists
if (g_GUI && g_GUI->GetPageCount())
{
std::shared_ptr<ScriptInterface> scriptInterface = g_GUI->GetActiveGUI()->GetScriptInterface();
ScriptRequest rq(scriptInterface);
std::shared_ptr<Script::Interface> scriptInterface = g_GUI->GetActiveGUI()->GetScriptInterface();
Script::Request rq(scriptInterface);
JS::RootedValue global(rq.cx, rq.globalValue());
if (Script::HasProperty(rq, global, "reallyStartGame"))
ScriptFunction::CallVoid(rq, global, "reallyStartGame");
Script::Function::CallVoid(rq, global, "reallyStartGame");
}
debug_printf("GAME STARTED, ALL INIT COMPLETE\n");
+4 -4
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -20,8 +20,8 @@
#include "lib/sysdep/sysdep.h"
#include "scriptinterface/Object.h"
#include "scriptinterface/ScriptConversions.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Conversions.h"
#include "scriptinterface/Request.h"
#include <algorithm>
#include <js/CallArgs.h>
@@ -127,7 +127,7 @@ std::vector<CStr> CmdLineArgs::GetArgsWithoutName() const
return m_ArgsWithoutName;
}
template<> void Script::ToJSVal<CmdLineArgs>(const ScriptRequest& rq, JS::MutableHandleValue ret, const CmdLineArgs& val)
template<> void Script::ToJSVal<CmdLineArgs>(const Script::Request& rq, JS::MutableHandleValue ret, const CmdLineArgs& val)
{
if (!Script::CreateObject(rq, ret))
return;
+24 -24
View File
@@ -82,11 +82,11 @@
#include "renderer/SceneRenderer.h"
#include "scriptinterface/FunctionWrapper.h"
#include "scriptinterface/Object.h"
#include "scriptinterface/ScriptContext.h"
#include "scriptinterface/ScriptConversions.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/ScriptStats.h"
#include "scriptinterface/Context.h"
#include "scriptinterface/Conversions.h"
#include "scriptinterface/Interface.h"
#include "scriptinterface/Request.h"
#include "scriptinterface/Stats.h"
#include "simulation2/Simulation2.h"
#include "simulation2/scripting/JSInterface_Simulation.h"
#include "simulation2/system/Component.h"
@@ -139,7 +139,7 @@ ERROR_TYPE(System, SDLInitFailed);
ERROR_TYPE(System, VmodeFailed);
ERROR_TYPE(System, RequiredExtensionsMissing);
thread_local std::shared_ptr<ScriptContext> g_ScriptContext;
thread_local std::shared_ptr<Script::Context> g_ScriptContext;
bool g_InDevelopmentCopy;
bool g_CheckedIfInDevelopmentCopy = false;
@@ -237,7 +237,7 @@ void InitVfs(const CmdLineArgs& args)
}
static void InitPs(bool setup_gui, const CStrW& gui_page, ScriptInterface* srcScriptInterface, JS::HandleValue initData)
static void InitPs(bool setup_gui, const CStrW& gui_page, Script::Interface* srcScriptInterface, JS::HandleValue initData)
{
g_Console->Init();
LoadHotkeys(g_ConfigDB);
@@ -528,7 +528,7 @@ bool Init(const CmdLineArgs& args, int flags)
new CProfileViewer;
new CProfileManager; // before any script code
g_ScriptStatsTable = new CScriptStatsTable;
g_ScriptStatsTable = new Script::CScriptStatsTable;
g_ProfileViewer.AddRootTable(g_ScriptStatsTable);
// Set up the console early, so that debugging
@@ -543,7 +543,7 @@ bool Init(const CmdLineArgs& args, int flags)
// their own threads and also their own contexts.
const int contextSize = 384 * 1024 * 1024;
const int heapGrowthBytesGCTrigger = 12 * 1024 * 1024;
g_ScriptContext = std::make_shared<ScriptContext>(contextSize, heapGrowthBytesGCTrigger);
g_ScriptContext = std::make_shared<Script::Context>(contextSize, heapGrowthBytesGCTrigger);
// On the first Init (INIT_MODS), check for command-line arguments
// or use the default mods from the config and enable those.
@@ -551,7 +551,7 @@ bool Init(const CmdLineArgs& args, int flags)
// to avoid overwriting the newly selected mods.
if (flags & INIT_MODS)
{
ScriptInterface modInterface("Engine", "Mod", g_ScriptContext);
Script::Interface modInterface("Engine", "Mod", g_ScriptContext);
g_Mods.UpdateAvailableMods(modInterface);
std::vector<CStr> mods;
if (args.Has("mod"))
@@ -623,8 +623,8 @@ bool Init(const CmdLineArgs& args, int flags)
}
[[nodiscard]] std::unique_ptr<InputHandlers> InitGraphics(const CmdLineArgs& args, int flags,
const std::vector<CStr>& installedMods, ScriptContext& scriptContext,
ScriptInterface& scriptInterface)
const std::vector<CStr>& installedMods, Script::Context& scriptContext,
Script::Interface& scriptInterface)
{
const bool setup_vmode = (flags & INIT_HAVE_VMODE) == 0;
@@ -678,7 +678,7 @@ bool Init(const CmdLineArgs& args, int flags)
{
const bool setup_gui = ((flags & INIT_NO_GUI) == 0);
ScriptRequest rq{g_GUI->GetScriptInterface()};
Script::Request rq{g_GUI->GetScriptInterface()};
JS::RootedValue data(rq.cx);
Script::CreateObject(rq, &data, "isStartup", true);
if (!installedMods.empty())
@@ -766,8 +766,8 @@ bool Autostart(const CmdLineArgs& args)
return false;
// Create some scriptinterface to store the js values for the settings.
ScriptInterface scriptInterface("Engine", "Game Setup", g_ScriptContext);
ScriptRequest rq(scriptInterface);
Script::Interface scriptInterface("Engine", "Game Setup", g_ScriptContext);
Script::Request rq(scriptInterface);
// We use the javascript gameSettings to handle options, but that requires running JS.
// Since we don't want to use the full Gui manager, we load an entrypoint script
@@ -775,7 +775,7 @@ bool Autostart(const CmdLineArgs& args)
// TODO: this essentially duplicates the CGUI logic to load directory or scripts.
std::unordered_set<VfsPath> templateCache;
const auto autostartLoadScript = [&templateCache](const ScriptInterface& scriptInterface,
const auto autostartLoadScript = [&templateCache](const Script::Interface& scriptInterface,
const VfsPath& path)
{
if (!std::get<1>(templateCache.insert(path)))
@@ -792,7 +792,7 @@ bool Autostart(const CmdLineArgs& args)
scriptInterface.LoadGlobalScriptFile(path);
};
const auto loadScriptCallback = ScriptFunction::Register(rq, "LoadScript", autostartLoadScript);
const auto loadScriptCallback = Script::Function::Register(rq, "LoadScript", autostartLoadScript);
// Load the entire folder to allow mods to extend the entrypoint without copying the whole file.
autostartLoadScript(scriptInterface, VfsPath(L"autostart/"));
@@ -813,7 +813,7 @@ bool Autostart(const CmdLineArgs& args)
}
};
std::optional<ScriptFunction::StatefulCallback<GetTemplate>> getTemplateCallback;
std::optional<Script::Function::StatefulCallback<GetTemplate>> getTemplateCallback;
if (args.Has("autostart-nonvisual"))
getTemplateCallback.emplace(rq, "GetTemplate", GetTemplate{});
else
@@ -838,7 +838,7 @@ bool Autostart(const CmdLineArgs& args)
JS::RootedValue resultValue{rq.cx};
JS::RootedValue global(rq.cx, rq.globalValue());
if (!ScriptFunction::Call(rq, global,
if (!Script::Function::Call(rq, global,
args.Has("autostart-client") ? "autostartClient" : "autostartHost", &resultValue,
cmdLineArgs, args.Has("autostart-host")) && !resultValue.isObject())
{
@@ -885,8 +885,8 @@ bool AutostartVisualReplay(const std::string& replayFile)
g_Game->SetPlayerID(-1);
g_Game->StartVisualReplay(replayFile);
ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface();
ScriptRequest rq(scriptInterface);
Script::Interface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface();
Script::Request rq(scriptInterface);
JS::RootedValue attrs(rq.cx, g_Game->GetSimulation2()->GetInitAttributes());
JS::RootedValue playerAssignments(rq.cx);
@@ -910,8 +910,8 @@ bool AutostartVisualReplay(const std::string& replayFile)
void CancelLoad(const CStrW& message)
{
std::shared_ptr<ScriptInterface> pScriptInterface = g_GUI->GetActiveGUI()->GetScriptInterface();
ScriptRequest rq(pScriptInterface);
std::shared_ptr<Script::Interface> pScriptInterface = g_GUI->GetActiveGUI()->GetScriptInterface();
Script::Request rq(pScriptInterface);
JS::RootedValue global(rq.cx, rq.globalValue());
@@ -920,7 +920,7 @@ void CancelLoad(const CStrW& message)
if (g_GUI &&
g_GUI->GetPageCount() &&
Script::HasProperty(rq, global, "cancelOnLoadGameError"))
ScriptFunction::CallVoid(rq, global, "cancelOnLoadGameError", message);
Script::Function::CallVoid(rq, global, "cancelOnLoadGameError", message);
}
bool InDevelopmentCopy()
+4 -4
View File
@@ -26,8 +26,8 @@
class CmdLineArgs;
class Paths;
class ScriptContext;
class ScriptInterface;
namespace Script { class Context; }
namespace Script { class Interface; }
/**
* initialize global modules that are be needed before Init.
@@ -80,8 +80,8 @@ using InputHandlers = std::queue<Input::Handler<Input::Reaction(&)(const SDL_Eve
* `ShutdownNetworkAndUI` has to be called later.
*/
[[nodiscard]] std::unique_ptr<InputHandlers> InitGraphics(const CmdLineArgs& args, int flags,
const std::vector<CStr>& installedMods, ScriptContext& scriptContext,
ScriptInterface& scriptInterface);
const std::vector<CStr>& installedMods, Script::Context& scriptContext,
Script::Interface& scriptInterface);
/**
* `ShutdownNetworkAndUI` has to be called later.
+12 -12
View File
@@ -52,8 +52,8 @@
#include "scriptinterface/FunctionWrapper.h"
#include "scriptinterface/JSON.h"
#include "scriptinterface/Object.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Interface.h"
#include "scriptinterface/Request.h"
#include "scriptinterface/StructuredClone.h"
#include "soundmanager/ISoundManager.h"
@@ -115,7 +115,7 @@ namespace
class Reporter
{
public:
Reporter(const ScriptRequest& rq)
Reporter(const Script::Request& rq)
: m_Rq(rq), m_LibrarySettings(rq.cx)
{
Script::CreateObject(m_Rq, &m_LibrarySettings);
@@ -134,21 +134,21 @@ public:
}
private:
const ScriptRequest& m_Rq;
const Script::Request& m_Rq;
JS::RootedValue m_LibrarySettings;
};
class LibraryReporter : public Reporter
{
public:
LibraryReporter(const ScriptRequest& rq, const char* name)
LibraryReporter(const Script::Request& rq, const char* name)
: Reporter(rq)
{
Add("name", name);
}
};
JS::Value MakeSDLReport(const ScriptRequest& rq)
JS::Value MakeSDLReport(const Script::Request& rq)
{
LibraryReporter reporter{rq, "sdl"};
@@ -175,7 +175,7 @@ JS::Value MakeSDLReport(const ScriptRequest& rq)
return reporter.MakeReport();
}
JS::Value MakeFreeTypeReport(const ScriptRequest& rq)
JS::Value MakeFreeTypeReport(const Script::Request& rq)
{
FT_Library FTLibrary;
@@ -194,7 +194,7 @@ JS::Value MakeFreeTypeReport(const ScriptRequest& rq)
return libraryReporter.MakeReport();
}
void ReportLibraries(const ScriptRequest& rq, JS::HandleValue settings)
void ReportLibraries(const Script::Request& rq, JS::HandleValue settings)
{
JS::RootedValueVector librariesSettings{rq.cx};
@@ -336,14 +336,14 @@ void RunHardwareDetection(bool writeSystemInfoBeforeDetection, Renderer::Backend
PROFILE2("RunHardwareDetection");
ScriptInterface scriptInterface("Engine", "HWDetect", g_ScriptContext);
Script::Interface scriptInterface("Engine", "HWDetect", g_ScriptContext);
ScriptRequest rq(scriptInterface);
Script::Request rq(scriptInterface);
JSI_Debug::RegisterScriptFunctions(scriptInterface); // Engine.DisplayErrorDialog
JSI_ConfigDB::RegisterScriptFunctions(scriptInterface);
ScriptFunction::Register<SetDisableAudio>(rq, "SetDisableAudio");
Script::Function::Register<SetDisableAudio>(rq, "SetDisableAudio");
// Load the detection script:
@@ -478,5 +478,5 @@ void RunHardwareDetection(bool writeSystemInfoBeforeDetection, Renderer::Backend
// Run the detection script:
JS::RootedValue global(rq.cx, rq.globalValue());
ScriptFunction::CallVoid(rq, global, "RunHardwareDetection", settings);
Script::Function::CallVoid(rq, global, "RunHardwareDetection", settings);
}
+2 -2
View File
@@ -24,8 +24,8 @@
#include "ps/Profile.h"
#include "ps/TouchInput.h"
#include "scriptinterface/JSON.h"
#include "scriptinterface/ScriptConversions.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Conversions.h"
#include "scriptinterface/Request.h"
#include <utility>
+7 -7
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -32,8 +32,8 @@
#include "ps/Profiler2.h"
#include "scriptinterface/JSON.h"
#include "scriptinterface/Object.h"
#include "scriptinterface/ScriptConversions.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Conversions.h"
#include "scriptinterface/Request.h"
#include <algorithm>
#include <boost/algorithm/string/classification.hpp>
@@ -55,7 +55,7 @@
#include "lib/os_path.h"
#endif
class ScriptInterface;
namespace Script { class Interface; }
namespace
{
@@ -112,7 +112,7 @@ bool LoadModJSON(const PIVFS& vfs, OsPath modsPath, OsPath mod, std::string& tex
}
}
bool ParseModJSON(const ScriptRequest& rq, const PIVFS& vfs, OsPath modsPath, OsPath mod, Mod::ModData& data)
bool ParseModJSON(const Script::Request& rq, const PIVFS& vfs, OsPath modsPath, OsPath mod, Mod::ModData& data)
{
std::string text;
if (!LoadModJSON(vfs, modsPath, mod, text))
@@ -245,7 +245,7 @@ bool Mod::AreModsPlayCompatible(const std::vector<const Mod::ModData*>& modsA, c
return true;
}
void Mod::UpdateAvailableMods(const ScriptInterface& scriptInterface)
void Mod::UpdateAvailableMods(const Script::Interface& scriptInterface)
{
PROFILE2("UpdateAvailableMods");
@@ -265,7 +265,7 @@ void Mod::UpdateAvailableMods(const ScriptInterface& scriptInterface)
PIVFS vfs = CreateVfs();
ScriptRequest rq(scriptInterface);
Script::Request rq(scriptInterface);
for (DirectoryNames::iterator iter = modDirs.begin(); iter != modDirs.end(); ++iter)
{
ModData data;
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 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 <vector>
class ScriptInterface;
namespace Script { class Interface; }
#define g_Mods (Mod::Instance())
@@ -65,7 +65,7 @@ public:
* TODO: if this did not need the scriptInterface to parse JSON,
* we could run it in different contexts and possibly cleaner.
*/
void UpdateAvailableMods(const ScriptInterface& scriptInterface);
void UpdateAvailableMods(const Script::Interface& scriptInterface);
/**
* Enables specified mods (& mods required by the engine).
+7 -7
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -26,9 +26,9 @@
#include "ps/Errors.h"
#include "ps/Filesystem.h"
#include "scriptinterface/JSON.h"
#include "scriptinterface/ScriptConversions.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Conversions.h"
#include "scriptinterface/Interface.h"
#include "scriptinterface/Request.h"
#include <js/PropertyAndElement.h>
#include <js/RootingAPI.h>
@@ -60,7 +60,7 @@ CModInstaller::~CModInstaller()
CModInstaller::ModInstallationResult CModInstaller::Install(
const OsPath& mod,
const std::shared_ptr<ScriptContext>& scriptContext,
const std::shared_ptr<Script::Context>& scriptContext,
bool keepFile)
{
const OsPath modTemp = m_TempDir / mod.Basename() / mod.Filename().ChangeExtension(L".zip");
@@ -92,8 +92,8 @@ CModInstaller::ModInstallationResult CModInstaller::Install(
// Extract the name of the mod
CStr modName;
{
ScriptInterface scriptInterface("Engine", "ModInstaller", scriptContext);
ScriptRequest rq(scriptInterface);
Script::Interface scriptInterface("Engine", "ModInstaller", scriptContext);
Script::Request rq(scriptInterface);
JS::RootedValue json_val(rq.cx);
if (!Script::ParseJSON(rq, modinfo.GetAsString(), &json_val))
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 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 @@
#include <memory>
#include <vector>
class ScriptContext;
namespace Script { class Context; }
/**
* Install a mod into the mods directory.
@@ -63,7 +63,7 @@ public:
*/
ModInstallationResult Install(
const OsPath& mod,
const std::shared_ptr<ScriptContext>& scriptContext,
const std::shared_ptr<Script::Context>& scriptContext,
bool keepFile);
/**
+11 -11
View File
@@ -40,9 +40,9 @@
#include "ps/ModInstaller.h"
#include "ps/Util.h"
#include "scriptinterface/JSON.h"
#include "scriptinterface/ScriptContext.h"
#include "scriptinterface/ScriptConversions.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Context.h"
#include "scriptinterface/Conversions.h"
#include "scriptinterface/Request.h"
#include <algorithm>
#include <boost/algorithm/string/classification.hpp>
@@ -59,7 +59,7 @@
#include <js/Value.h>
#include <system_error>
class ScriptInterface;
namespace Script { class Interface; }
ModIo* g_ModIo = nullptr;
@@ -412,7 +412,7 @@ void ModIo::CancelRequest()
}
}
bool ModIo::AdvanceRequest(const ScriptInterface& scriptInterface)
bool ModIo::AdvanceRequest(const Script::Interface& scriptInterface)
{
// If the request was cancelled, stop trying to advance it
if (m_DownloadProgressData.status != DownloadProgressStatus::GAMEID &&
@@ -526,7 +526,7 @@ bool ModIo::AdvanceRequest(const ScriptInterface& scriptInterface)
return true;
}
bool ModIo::ParseGameId(const ScriptInterface& scriptInterface, std::string& err)
bool ModIo::ParseGameId(const Script::Interface& scriptInterface, std::string& err)
{
int id = -1;
bool ret = ParseGameIdResponse(scriptInterface, m_ResponseData, id, err);
@@ -538,7 +538,7 @@ bool ModIo::ParseGameId(const ScriptInterface& scriptInterface, std::string& err
return true;
}
bool ModIo::ParseMods(const ScriptInterface& scriptInterface, std::string& err)
bool ModIo::ParseMods(const Script::Interface& scriptInterface, std::string& err)
{
bool ret = ParseModsResponse(scriptInterface, m_ResponseData, m_ModData, m_pk, err);
m_ResponseData.clear();
@@ -623,10 +623,10 @@ bool ModIo::VerifyDownloadedFile(std::string& err)
*
* @returns true iff it successfully parsed the id.
*/
bool ModIo::ParseGameIdResponse(const ScriptInterface& scriptInterface, const std::string& responseData, int& id, std::string& err)
bool ModIo::ParseGameIdResponse(const Script::Interface& scriptInterface, const std::string& responseData, int& id, std::string& err)
{
#define CLEANUP() id = -1;
ScriptRequest rq(scriptInterface);
Script::Request rq(scriptInterface);
JS::RootedValue gameResponse(rq.cx);
@@ -689,12 +689,12 @@ bool ModIo::ParseGameIdResponse(const ScriptInterface& scriptInterface, const st
* Only the listed properties are of interest to consumers, and we flatten
* the modfile structure as that simplifies handling and there are no conflicts.
*/
bool ModIo::ParseModsResponse(const ScriptInterface& scriptInterface, const std::string& responseData, std::vector<ModIoModData>& modData, const PKStruct& pk, std::string& err)
bool ModIo::ParseModsResponse(const Script::Interface& scriptInterface, const std::string& responseData, std::vector<ModIoModData>& modData, const PKStruct& pk, std::string& err)
{
// Make sure we don't end up passing partial results back
#define CLEANUP() modData.clear();
ScriptRequest rq(scriptInterface);
Script::Request rq(scriptInterface);
JS::RootedValue modResponse(rq.cx);
+7 -7
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@@ -34,7 +34,7 @@
#include <string>
#include <vector>
class ScriptInterface;
namespace Script { class Interface; }
// TODO: Allocate instance of the below two using sodium_malloc?
struct PKStruct
@@ -147,7 +147,7 @@ public:
* @param scriptInterface used for parsing the data and possibly install the mod.
* @return true if the download is complete (successful or not), false otherwise.
*/
bool AdvanceRequest(const ScriptInterface& scriptInterface);
bool AdvanceRequest(const Script::Interface& scriptInterface);
/**
* Cancel the current async request and clean things up
@@ -171,15 +171,15 @@ private:
CURLMcode SetupRequest(const std::string& url, bool fileDownload);
void TearDownRequest();
bool ParseGameId(const ScriptInterface& scriptInterface, std::string& err);
bool ParseMods(const ScriptInterface& scriptInterface, std::string& err);
bool ParseGameId(const Script::Interface& scriptInterface, std::string& err);
bool ParseMods(const Script::Interface& scriptInterface, std::string& err);
void DeleteDownloadedFile();
bool VerifyDownloadedFile(std::string& err);
// Utility methods for parsing mod.io responses and metadata
static bool ParseGameIdResponse(const ScriptInterface& scriptInterface, const std::string& responseData, int& id, std::string& err);
static bool ParseModsResponse(const ScriptInterface& scriptInterface, const std::string& responseData, std::vector<ModIoModData>& modData, const PKStruct& pk, std::string& err);
static bool ParseGameIdResponse(const Script::Interface& scriptInterface, const std::string& responseData, int& id, std::string& err);
static bool ParseModsResponse(const Script::Interface& scriptInterface, const std::string& responseData, std::vector<ModIoModData>& modData, const PKStruct& pk, std::string& err);
static bool ParseSignature(const std::vector<std::string>& minisigs, SigStruct& sig, const PKStruct& pk, std::string& err);
// Url parts
+8 -8
View File
@@ -37,7 +37,7 @@
#include "ps/Pyrogenesis.h"
#include "ps/VideoMode.h"
#include "scriptinterface/Object.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Request.h"
#include <SDL_events.h>
#include <SDL_keycode.h>
@@ -49,7 +49,7 @@
#include <js/Value.h>
#include <string>
class ScriptInterface;
namespace Script { class Interface; }
struct CProfileViewerInternals
{
@@ -448,12 +448,12 @@ namespace
struct DumpTable
{
const ScriptInterface& m_ScriptInterface;
const Script::Interface& m_ScriptInterface;
JS::PersistentRooted<JS::Value> m_Root;
DumpTable(const ScriptInterface& scriptInterface, JS::HandleValue root) :
DumpTable(const Script::Interface& scriptInterface, JS::HandleValue root) :
m_ScriptInterface(scriptInterface)
{
ScriptRequest rq(scriptInterface);
Script::Request rq(scriptInterface);
m_Root.init(rq.cx, root);
}
@@ -462,13 +462,13 @@ namespace
DumpTable(DumpTable && original) :
m_ScriptInterface(original.m_ScriptInterface)
{
ScriptRequest rq(m_ScriptInterface);
Script::Request rq(m_ScriptInterface);
m_Root.init(rq.cx, original.m_Root.get());
}
void operator() (AbstractProfileTable* table)
{
ScriptRequest rq(m_ScriptInterface);
Script::Request rq(m_ScriptInterface);
JS::RootedValue t(rq.cx);
Script::CreateObject(
@@ -494,7 +494,7 @@ namespace
JS::Value DumpRows(AbstractProfileTable* table)
{
ScriptRequest rq(m_ScriptInterface);
Script::Request rq(m_ScriptInterface);
JS::RootedValue data(rq.cx);
Script::CreateObject(rq, &data);
+15 -15
View File
@@ -41,10 +41,10 @@
#include "ps/VisualReplay.h"
#include "scriptinterface/JSON.h"
#include "scriptinterface/Object.h"
#include "scriptinterface/ScriptContext.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/ScriptStats.h"
#include "scriptinterface/Context.h"
#include "scriptinterface/Interface.h"
#include "scriptinterface/Request.h"
#include "scriptinterface/Stats.h"
#include "simulation2/Simulation2.h"
#include "simulation2/components/ICmpGuiInterface.h"
#include "simulation2/helpers/Player.h"
@@ -62,7 +62,7 @@
*/
static const int PROFILE_TURN_INTERVAL = 20;
CReplayLogger::CReplayLogger(const ScriptInterface& scriptInterface) :
CReplayLogger::CReplayLogger(const Script::Interface& scriptInterface) :
m_ScriptInterface(scriptInterface), m_Stream(NULL)
{
}
@@ -74,7 +74,7 @@ CReplayLogger::~CReplayLogger()
void CReplayLogger::StartGame(JS::MutableHandleValue attribs)
{
ScriptRequest rq(m_ScriptInterface);
Script::Request rq(m_ScriptInterface);
// Add timestamp, since the file-modification-date can change
Script::SetProperty(rq, attribs, "timestamp", (double)std::time(nullptr));
@@ -94,7 +94,7 @@ void CReplayLogger::StartGame(JS::MutableHandleValue attribs)
void CReplayLogger::Turn(u32 n, u32 turnLength, std::vector<SimulationCommand>& commands)
{
ScriptRequest rq(m_ScriptInterface);
Script::Request rq(m_ScriptInterface);
*m_Stream << "turn " << n << " " << turnLength << "\n";
@@ -122,8 +122,8 @@ void CReplayLogger::SaveMetadata(const CSimulation2& simulation)
return;
}
ScriptInterface& scriptInterface = simulation.GetScriptInterface();
ScriptRequest rq(scriptInterface);
Script::Interface& scriptInterface = simulation.GetScriptInterface();
Script::Request rq(scriptInterface);
JS::RootedValue arg(rq.cx);
JS::RootedValue metadata(rq.cx);
@@ -198,12 +198,12 @@ void CReplayPlayer::Replay(const int serializationtestturn, const int rejointest
new CProfileViewer;
new CProfileManager;
g_ScriptStatsTable = new CScriptStatsTable;
g_ScriptStatsTable = new Script::CScriptStatsTable;
g_ProfileViewer.AddRootTable(g_ScriptStatsTable);
const int contextSize = 384 * 1024 * 1024;
const int heapGrowthBytesGCTrigger = 12 * 1024 * 1024;
g_ScriptContext = std::make_shared<ScriptContext>(contextSize, heapGrowthBytesGCTrigger);
g_ScriptContext = std::make_shared<Script::Context>(contextSize, heapGrowthBytesGCTrigger);
std::vector<SimulationCommand> commands;
u32 turn = 0;
@@ -218,8 +218,8 @@ void CReplayPlayer::Replay(const int serializationtestturn, const int rejointest
{
std::string attribsStr;
{
ScriptInterface scriptInterface("Engine", "Replay", g_ScriptContext);
ScriptRequest rq(scriptInterface);
Script::Interface scriptInterface("Engine", "Replay", g_ScriptContext);
Script::Request rq(scriptInterface);
std::getline(*m_Stream, attribsStr);
JS::RootedValue attribs(rq.cx);
if (!Script::ParseJSON(rq, attribsStr, &attribs))
@@ -266,7 +266,7 @@ void CReplayPlayer::Replay(const int serializationtestturn, const int rejointest
g_Game = new CGame(false, debugOption);
ScriptRequest rq(g_Game->GetSimulation2()->GetScriptInterface());
Script::Request rq(g_Game->GetSimulation2()->GetScriptInterface());
JS::RootedValue attribs(rq.cx);
ENSURE(Script::ParseJSON(rq, attribsStr, &attribs));
g_Game->StartGame(&attribs, "");
@@ -289,7 +289,7 @@ void CReplayPlayer::Replay(const int serializationtestturn, const int rejointest
std::string line;
std::getline(*m_Stream, line);
ScriptRequest rq(g_Game->GetSimulation2()->GetScriptInterface());
Script::Request rq(g_Game->GetSimulation2()->GetScriptInterface());
JS::RootedValue data(rq.cx);
Script::ParseJSON(rq, line, &data);
Script::DeepFreezeObject(rq, data);
+3 -3
View File
@@ -30,7 +30,7 @@
#include <vector>
class CSimulation2;
class ScriptInterface;
namespace Script { class Interface; }
struct SimulationCommand;
/**
@@ -89,7 +89,7 @@ class CReplayLogger : public IReplayLogger
{
NONCOPYABLE(CReplayLogger);
public:
CReplayLogger(const ScriptInterface& scriptInterface);
CReplayLogger(const Script::Interface& scriptInterface);
~CReplayLogger();
virtual void StartGame(JS::MutableHandleValue attribs);
@@ -99,7 +99,7 @@ public:
virtual OsPath GetDirectory() const;
private:
const ScriptInterface& m_ScriptInterface;
const Script::Interface& m_ScriptInterface;
std::ostream* m_Stream;
OsPath m_Directory;
};
+13 -13
View File
@@ -44,8 +44,8 @@
#include "ps/Pyrogenesis.h"
#include "scriptinterface/JSON.h"
#include "scriptinterface/Object.h"
#include "scriptinterface/ScriptConversions.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Conversions.h"
#include "scriptinterface/Request.h"
#include "scriptinterface/StructuredClone.h"
#include "simulation2/Simulation2.h"
@@ -59,7 +59,7 @@
#include <system_error>
#include <utility>
class ScriptInterface;
namespace Script { class Interface; }
// TODO: we ought to check version numbers when loading files
@@ -80,7 +80,7 @@ Status SavedGames::SavePrefix(const CStrW& prefix, const CStrW& description, CSi
Status SavedGames::Save(const CStrW& name, const CStrW& description, CSimulation2& simulation, const Script::StructuredClone& guiMetadataClone)
{
ScriptRequest rq(simulation.GetScriptInterface());
Script::Request rq(simulation.GetScriptInterface());
// Determine the filename to save under
const VfsPath basenameFormat(L"saves/" + name);
@@ -180,7 +180,7 @@ class CGameLoader
public:
/**
* @param scriptInterface the ScriptInterface used for loading metadata.
* @param scriptInterface the Script::Interface used for loading metadata.
* @param[out] savedState serialized simulation state stored as string of bytes,
* loaded from simulation.dat inside the archive.
*
@@ -189,11 +189,11 @@ 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(const ScriptInterface& scriptInterface, std::string* savedState) :
CGameLoader(const Script::Interface& scriptInterface, std::string* savedState) :
m_ScriptInterface(scriptInterface),
m_SavedState(savedState)
{
ScriptRequest rq(scriptInterface);
Script::Request rq(scriptInterface);
m_Metadata.init(rq.cx);
}
@@ -209,7 +209,7 @@ public:
std::string buffer;
buffer.resize(fileInfo.Size());
WARN_IF_ERR(archiveFile->Load("", DummySharedPtr((u8*)buffer.data()), buffer.size()));
Script::ParseJSON(ScriptRequest(m_ScriptInterface), buffer, &m_Metadata);
Script::ParseJSON(Script::Request(m_ScriptInterface), buffer, &m_Metadata);
}
else if (pathname == L"simulation.dat" && m_SavedState)
{
@@ -225,12 +225,12 @@ public:
private:
const ScriptInterface& m_ScriptInterface;
const Script::Interface& m_ScriptInterface;
JS::PersistentRooted<JS::Value> m_Metadata;
std::string* m_SavedState;
};
std::optional<SavedGames::LoadResult> SavedGames::Load(const ScriptInterface& scriptInterface,
std::optional<SavedGames::LoadResult> SavedGames::Load(const Script::Interface& scriptInterface,
const std::wstring& name)
{
// Determine the filename to load
@@ -269,17 +269,17 @@ std::optional<SavedGames::LoadResult> SavedGames::Load(const ScriptInterface& sc
return std::nullopt;
}
}
const ScriptRequest rq{scriptInterface};
const Script::Request rq{scriptInterface};
JS::RootedValue metadata{rq.cx, loader.GetMetadata()};
// `std::make_optional` can't be used since `LoadResult` doesn't have a constructor.
return {{metadata, std::move(savedState)}};
}
JS::Value SavedGames::GetSavedGames(const ScriptInterface& scriptInterface)
JS::Value SavedGames::GetSavedGames(const Script::Interface& scriptInterface)
{
PROFILE2("GetSavedGames");
ScriptRequest rq(scriptInterface);
Script::Request rq(scriptInterface);
JS::RootedValueVector games{rq.cx};
+5 -5
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 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 @@
class CSimulation2;
class CStrW;
class ScriptInterface;
namespace Script { class Interface; }
/**
* @file
@@ -82,15 +82,15 @@ namespace SavedGames
* @param scriptInterface
* @return An empty `std::optional` if an error ocoured.
*/
std::optional<LoadResult> Load(const ScriptInterface& scriptInterface, const std::wstring& name);
std::optional<LoadResult> Load(const Script::Interface& scriptInterface, const std::wstring& name);
/**
* Get list of saved games for GUI script usage
*
* @param scriptInterface the ScriptInterface in which to create the return data.
* @param scriptInterface the Script::Interface in which to create the return data.
* @return array of objects containing saved game data
*/
JS::Value GetSavedGames(const ScriptInterface& scriptInterface);
JS::Value GetSavedGames(const Script::Interface& scriptInterface);
/**
* Permanently deletes the saved game archive with the given name
+1 -1
View File
@@ -47,7 +47,7 @@
#include "renderer/backend/dummy/DeviceForward.h"
#include "renderer/backend/gl/DeviceForward.h"
#include "renderer/backend/vulkan/DeviceForward.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/Interface.h"
#include <SDL.h>
#include <SDL_error.h>
+17 -17
View File
@@ -38,7 +38,7 @@
#include "ps/Pyrogenesis.h"
#include "scriptinterface/JSON.h"
#include "scriptinterface/Object.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Request.h"
#include <SDL_events.h>
#include <SDL_quit.h>
@@ -91,7 +91,7 @@ bool VisualReplay::StartVisualReplay(const OsPath& directory)
return g_Game->StartVisualReplay(replayFile);
}
bool VisualReplay::ReadCacheFile(const ScriptInterface& scriptInterface, JS::MutableHandleObject cachedReplaysObject)
bool VisualReplay::ReadCacheFile(const Script::Interface& scriptInterface, JS::MutableHandleObject cachedReplaysObject)
{
if (!std::filesystem::is_regular_file(GetCacheFilePath().string()))
return false;
@@ -100,7 +100,7 @@ bool VisualReplay::ReadCacheFile(const ScriptInterface& scriptInterface, JS::Mut
CStr cacheStr((std::istreambuf_iterator<char>(cacheStream)), std::istreambuf_iterator<char>());
cacheStream.close();
ScriptRequest rq(scriptInterface);
Script::Request rq(scriptInterface);
JS::RootedValue cachedReplays(rq.cx);
if (Script::ParseJSON(rq, cacheStr, &cachedReplays))
@@ -117,9 +117,9 @@ bool VisualReplay::ReadCacheFile(const ScriptInterface& scriptInterface, JS::Mut
return false;
}
void VisualReplay::StoreCacheFile(const ScriptInterface& scriptInterface, JS::HandleObject replays)
void VisualReplay::StoreCacheFile(const Script::Interface& scriptInterface, JS::HandleObject replays)
{
ScriptRequest rq(scriptInterface);
Script::Request rq(scriptInterface);
JS::RootedValue replaysRooted(rq.cx, JS::ObjectValue(*replays));
std::ofstream cacheStream(OsString(GetTempCacheFilePath()), std::ofstream::out | std::ofstream::trunc);
@@ -132,10 +132,10 @@ void VisualReplay::StoreCacheFile(const ScriptInterface& scriptInterface, JS::Ha
LOGERROR("Could not store the replay cache");
}
JS::HandleObject VisualReplay::ReloadReplayCache(const ScriptInterface& scriptInterface, bool compareFiles)
JS::HandleObject VisualReplay::ReloadReplayCache(const Script::Interface& scriptInterface, bool compareFiles)
{
PROFILE2("ReloadReplayCache");
ScriptRequest rq(scriptInterface);
Script::Request rq(scriptInterface);
// Maps the filename onto the index, mtime and size
using replayCacheMap = std::map<OsPath, std::tuple<u32, u64, off_t>>;
@@ -252,11 +252,11 @@ JS::HandleObject VisualReplay::ReloadReplayCache(const ScriptInterface& scriptIn
return replays;
}
JS::Value VisualReplay::GetReplays(const ScriptInterface& scriptInterface, bool compareFiles)
JS::Value VisualReplay::GetReplays(const Script::Interface& scriptInterface, bool compareFiles)
{
PROFILE2("GetReplays");
ScriptRequest rq(scriptInterface);
Script::Request rq(scriptInterface);
JS::RootedObject replays(rq.cx, ReloadReplayCache(scriptInterface, compareFiles));
// Only take entries with data
JS::RootedValueVector replaysWithoutNullEntries{rq.cx};
@@ -358,7 +358,7 @@ inline int getReplayDuration(std::istream* replayStream, const OsPath& fileName,
return -1;
}
JS::Value VisualReplay::LoadReplayData(const ScriptInterface& scriptInterface, const OsPath& directory)
JS::Value VisualReplay::LoadReplayData(const Script::Interface& scriptInterface, const OsPath& directory)
{
// The directory argument must not be constant, otherwise concatenating will fail
const OsPath replayFile = GetDirectoryPath() / directory / L"commands.txt";
@@ -394,7 +394,7 @@ JS::Value VisualReplay::LoadReplayData(const ScriptInterface& scriptInterface, c
// Parse header / first line
CStr header;
std::getline(*replayStream, header);
ScriptRequest rq(scriptInterface);
Script::Request rq(scriptInterface);
JS::RootedValue attribs(rq.cx);
if (!Script::ParseJSON(rq, header, &attribs))
{
@@ -452,10 +452,10 @@ bool VisualReplay::DeleteReplay(const OsPath& replayDirectory)
return DirectoryExists(directory) && DeleteDirectory(directory) == INFO::OK;
}
JS::Value VisualReplay::GetReplayAttributes(const ScriptInterface& scriptInterface, const OsPath& directoryName)
JS::Value VisualReplay::GetReplayAttributes(const Script::Interface& scriptInterface, const OsPath& directoryName)
{
// Create empty JS object
ScriptRequest rq(scriptInterface);
Script::Request rq(scriptInterface);
JS::RootedValue attribs(rq.cx);
Script::CreateObject(rq, &attribs);
@@ -476,10 +476,10 @@ JS::Value VisualReplay::GetReplayAttributes(const ScriptInterface& scriptInterfa
return attribs;
}
void VisualReplay::AddReplayToCache(const ScriptInterface& scriptInterface, const CStrW& directoryName)
void VisualReplay::AddReplayToCache(const Script::Interface& scriptInterface, const CStrW& directoryName)
{
PROFILE2("AddReplayToCache");
ScriptRequest rq(scriptInterface);
Script::Request rq(scriptInterface);
JS::RootedValue replayData(rq.cx, LoadReplayData(scriptInterface, OsPath(directoryName)));
if (replayData.isNull())
@@ -509,12 +509,12 @@ bool VisualReplay::HasReplayMetadata(const OsPath& directoryName)
return fileInfo.Size() > 0;
}
JS::Value VisualReplay::GetReplayMetadata(const ScriptInterface& scriptInterface, const OsPath& directoryName)
JS::Value VisualReplay::GetReplayMetadata(const Script::Interface& scriptInterface, const OsPath& directoryName)
{
if (!HasReplayMetadata(directoryName))
return JS::NullValue();
ScriptRequest rq(scriptInterface);
Script::Request rq(scriptInterface);
JS::RootedValue metadata(rq.cx);
std::ifstream* stream = new std::ifstream(OsString(GetDirectoryPath() / directoryName / L"metadata.json"));
+14 -14
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -23,8 +23,8 @@
#include <js/TypeDecls.h>
class CStrW;
class ScriptInterface;
namespace JS { class Value; }
namespace Script { class Interface; }
/**
* Contains functions for visually replaying past games.
@@ -56,44 +56,44 @@ bool StartVisualReplay(const OsPath& directory);
/**
* Reads the replay Cache file and parses it into a jsObject
*
* @param scriptInterface - the ScriptInterface in which to create the return data.
* @param scriptInterface - the Script::Interface in which to create the return data.
* @param cachedReplaysObject - the cached replays.
* @return true on succes
*/
bool ReadCacheFile(const ScriptInterface& scriptInterface, JS::MutableHandleObject cachedReplaysObject);
bool ReadCacheFile(const Script::Interface& scriptInterface, JS::MutableHandleObject cachedReplaysObject);
/**
* Stores the replay list in the replay cache file
*
* @param scriptInterface - the ScriptInterface in which to create the return data.
* @param scriptInterface - the Script::Interface in which to create the return data.
* @param replays - the replay list to store.
*/
void StoreCacheFile(const ScriptInterface& scriptInterface, JS::HandleObject replays);
void StoreCacheFile(const Script::Interface& scriptInterface, JS::HandleObject replays);
/**
* Load the replay cache and check if there are new/deleted replays. If so, update the cache.
*
* @param scriptInterface - the ScriptInterface in which to create the return data.
* @param scriptInterface - the Script::Interface in which to create the return data.
* @param compareFiles - compare the directory name and the FileSize of the replays and the cache.
* @return cache entries
*/
JS::HandleObject ReloadReplayCache(const ScriptInterface& scriptInterface, bool compareFiles);
JS::HandleObject ReloadReplayCache(const Script::Interface& scriptInterface, bool compareFiles);
/**
* Get a list of replays to display in the GUI.
*
* @param scriptInterface - the ScriptInterface in which to create the return data.
* @param scriptInterface - the Script::Interface in which to create the return data.
* @param compareFiles - reload the cache, which takes more time,
* but nearly ensures, that no changed replay is missed.
* @return array of objects containing replay data
*/
JS::Value GetReplays(const ScriptInterface& scriptInterface, bool compareFiles);
JS::Value GetReplays(const Script::Interface& scriptInterface, bool compareFiles);
/**
* Parses a commands.txt file and extracts metadata.
* Works similarly to CGame::LoadReplayData().
*/
JS::Value LoadReplayData(const ScriptInterface& scriptInterface, const OsPath& directory);
JS::Value LoadReplayData(const Script::Interface& scriptInterface, const OsPath& directory);
/**
* Permanently deletes the visual replay (including the parent directory)
@@ -106,7 +106,7 @@ bool DeleteReplay(const OsPath& replayFile);
/**
* Returns the parsed header of the replay file (commands.txt).
*/
JS::Value GetReplayAttributes(const ScriptInterface& scriptInterface, const OsPath& directoryName);
JS::Value GetReplayAttributes(const Script::Interface& scriptInterface, const OsPath& directoryName);
/**
* Returns whether or not the metadata / summary screen data has been saved properly when the game ended.
@@ -116,12 +116,12 @@ bool HasReplayMetadata(const OsPath& directoryName);
/**
* Returns the metadata of a replay.
*/
JS::Value GetReplayMetadata(const ScriptInterface& scriptInterface, const OsPath& directoryName);
JS::Value GetReplayMetadata(const Script::Interface& scriptInterface, const OsPath& directoryName);
/**
* Adds a replay to the replayCache.
*/
void AddReplayToCache(const ScriptInterface& scriptInterface, const CStrW& directoryName);
void AddReplayToCache(const Script::Interface& scriptInterface, const CStrW& directoryName);
}
#endif
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -66,7 +66,7 @@ CWorld::~CWorld() = default;
/**
* Initializes the game world with the attributes provided.
**/
void CWorld::RegisterInit(const CStrW& mapFile, const ScriptContext& cx, JS::HandleValue settings, int playerID)
void CWorld::RegisterInit(const CStrW& mapFile, const Script::Context& cx, JS::HandleValue settings, int playerID)
{
// Load the map, if one was specified
if (mapFile.length())
@@ -100,7 +100,7 @@ void CWorld::RegisterInit(const CStrW& mapFile, const ScriptContext& cx, JS::Han
}
}
void CWorld::RegisterInitRMS(const CStrW& scriptFile, const ScriptContext& cx, JS::HandleValue settings, int playerID)
void CWorld::RegisterInitRMS(const CStrW& scriptFile, const Script::Context& cx, JS::HandleValue settings, int playerID)
{
// If scriptFile is empty, a blank map will be generated using settings (no RMS run)
CTriggerManager* pTriggerManager = nullptr;
+4 -4
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -34,7 +34,7 @@ class CMapReader;
class CStrW;
class CTerrain;
class CUnitManager;
class ScriptContext;
namespace Script { class Context; }
#ifndef ERROR_GROUP_GAME_DEFINED
#define ERROR_GROUP_GAME_DEFINED
@@ -56,12 +56,12 @@ public:
/*
Initialize the World - load the map and all objects
*/
void RegisterInit(const CStrW& mapFile, const ScriptContext& cx, JS::HandleValue settings, int playerID);
void RegisterInit(const CStrW& mapFile, const Script::Context& cx, JS::HandleValue settings, int playerID);
/*
Initialize the World - generate and load the random map
*/
void RegisterInitRMS(const CStrW& scriptFile, const ScriptContext& cx, JS::HandleValue settings, int playerID);
void RegisterInitRMS(const CStrW& scriptFile, const Script::Context& cx, JS::HandleValue settings, int playerID);
/**
* Explicitly delete m_MapReader once the map has finished loading.
+8 -8
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -24,9 +24,9 @@
#include "lib/file/vfs/vfs.h"
#include "ps/CLogger.h"
#include "scriptinterface/Object.h"
#include "scriptinterface/ScriptConversions.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Conversions.h"
#include "scriptinterface/Interface.h"
#include "scriptinterface/Request.h"
#include <algorithm>
#include <js/Array.h>
@@ -155,7 +155,7 @@ void XMBStorageWriter::OutputNames(WriteBuffer& writeBuffer, const std::unordere
class JSNodeData
{
public:
JSNodeData(const ScriptInterface& s) : scriptInterface(s), rq(s) {}
JSNodeData(const Script::Interface& s) : scriptInterface(s), rq(s) {}
bool Setup(XMBStorageWriter& xmb, JS::HandleValue value);
bool Output(WriteBuffer& writeBuffer, JS::HandleValue value) const;
@@ -163,8 +163,8 @@ public:
std::vector<std::pair<u32, std::string>> m_Attributes;
std::vector<std::pair<u32, JS::Heap<JS::Value>>> m_Children;
const ScriptInterface& scriptInterface;
const ScriptRequest rq;
const Script::Interface& scriptInterface;
const Script::Request rq;
};
template<>
@@ -470,7 +470,7 @@ bool XMBStorage::LoadXMLDoc(const xmlDocPtr doc)
return true;
}
bool XMBStorage::LoadJSValue(const ScriptInterface& scriptInterface, JS::HandleValue value, const std::string& rootName)
bool XMBStorage::LoadJSValue(const Script::Interface& scriptInterface, JS::HandleValue value, const std::string& rootName)
{
WriteBuffer writeBuffer;
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 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 @@
#include <memory>
#include <string>
class ScriptInterface;
namespace Script { class Interface; }
typedef struct _xmlDoc xmlDoc;
typedef xmlDoc* xmlDocPtr;
@@ -106,7 +106,7 @@ public:
* </a>
* See also tests for some other examples.
*/
bool LoadJSValue(const ScriptInterface& scriptInterface, JS::HandleValue value, const std::string& rootName);
bool LoadJSValue(const Script::Interface& scriptInterface, JS::HandleValue value, const std::string& rootName);
std::shared_ptr<u8> m_Buffer;
size_t m_Size = 0;
+6 -6
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -22,8 +22,8 @@
#include "ps/XMB/XMBData.h"
#include "ps/XMB/XMBStorage.h"
#include "ps/XML/Xeromyces.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Interface.h"
#include "scriptinterface/Request.h"
#include <cstring>
#include <js/RootingAPI.h>
@@ -38,7 +38,7 @@ class TestXMBData : public CxxTest::TestSuite
private:
std::shared_ptr<u8> m_Buffer;
std::unique_ptr<ScriptInterface> m_ScriptInterface;
std::unique_ptr<Script::Interface> m_ScriptInterface;
CXeromyces parseXML(const char* doc)
{
@@ -55,7 +55,7 @@ private:
CXeromyces parseJS(const std::string rootName, const char* code)
{
ScriptRequest rq(*m_ScriptInterface);
Script::Request rq(*m_ScriptInterface);
JS::RootedValue val(rq.cx);
m_ScriptInterface->Eval(code, &val);
CXeromyces xmb;
@@ -68,7 +68,7 @@ private:
void setUp()
{
m_ScriptInterface = std::make_unique<ScriptInterface>("Test", "Test", g_ScriptContext);
m_ScriptInterface = std::make_unique<Script::Interface>("Test", "Test", g_ScriptContext);
}
void tearDown()
+15 -15
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -208,20 +208,20 @@ void SetGUIScale(float scale)
g_VideoMode.Rescale(scale);
}
void RegisterScriptFunctions(const ScriptRequest& rq)
void RegisterScriptFunctions(const Script::Request& rq)
{
ScriptFunction::Register<&HasChanges>(rq, "ConfigDB_HasChanges");
ScriptFunction::Register<&SetChanges>(rq, "ConfigDB_SetChanges");
ScriptFunction::Register<&GetValue>(rq, "ConfigDB_GetValue");
ScriptFunction::Register<&CreateValue>(rq, "ConfigDB_CreateValue");
ScriptFunction::Register<&CreateValues>(rq, "ConfigDB_CreateValues");
ScriptFunction::Register<&RemoveValue>(rq, "ConfigDB_RemoveValue");
ScriptFunction::Register<&RemoveValueAndSave>(rq, "ConfigDB_RemoveValueAndSave");
ScriptFunction::Register<&SaveChanges>(rq, "ConfigDB_SaveChanges");
ScriptFunction::Register<&SaveValue>(rq, "ConfigDB_SaveValue");
ScriptFunction::Register<&CreateAndSaveValue>(rq, "ConfigDB_CreateAndSaveValue");
ScriptFunction::Register<&Reload>(rq, "ConfigDB_Reload");
ScriptFunction::Register<&PauseOnFocusLoss>(rq, "PauseOnFocusLoss");
ScriptFunction::Register<&SetGUIScale>(rq, "SetGUIScale");
Script::Function::Register<&HasChanges>(rq, "ConfigDB_HasChanges");
Script::Function::Register<&SetChanges>(rq, "ConfigDB_SetChanges");
Script::Function::Register<&GetValue>(rq, "ConfigDB_GetValue");
Script::Function::Register<&CreateValue>(rq, "ConfigDB_CreateValue");
Script::Function::Register<&CreateValues>(rq, "ConfigDB_CreateValues");
Script::Function::Register<&RemoveValue>(rq, "ConfigDB_RemoveValue");
Script::Function::Register<&RemoveValueAndSave>(rq, "ConfigDB_RemoveValueAndSave");
Script::Function::Register<&SaveChanges>(rq, "ConfigDB_SaveChanges");
Script::Function::Register<&SaveValue>(rq, "ConfigDB_SaveValue");
Script::Function::Register<&CreateAndSaveValue>(rq, "ConfigDB_CreateAndSaveValue");
Script::Function::Register<&Reload>(rq, "ConfigDB_Reload");
Script::Function::Register<&PauseOnFocusLoss>(rq, "PauseOnFocusLoss");
Script::Function::Register<&SetGUIScale>(rq, "SetGUIScale");
}
}
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2021 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -19,11 +19,11 @@
#define INCLUDED_JSI_CONFIGDB
extern bool g_PauseOnFocusLoss;
class ScriptRequest;
namespace Script { class Request; }
namespace JSI_ConfigDB
{
void RegisterScriptFunctions(const ScriptRequest& rq);
void RegisterScriptFunctions(const Script::Request& rq);
}
#endif // INCLUDED_JSI_CONFIGDB
+5 -5
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 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 @@ namespace JS { class CallArgs; }
namespace JSI_Console
{
CConsole* ConsoleGetter(const ScriptRequest&, JS::CallArgs&)
CConsole* ConsoleGetter(const Script::Request&, JS::CallArgs&)
{
if (!g_Console)
{
@@ -37,9 +37,9 @@ CConsole* ConsoleGetter(const ScriptRequest&, JS::CallArgs&)
return g_Console;
}
void RegisterScriptFunctions(const ScriptRequest& rq)
void RegisterScriptFunctions(const Script::Request& rq)
{
ScriptFunction::Register<&CConsole::IsActive, ConsoleGetter>(rq, "Console_GetVisibleEnabled");
ScriptFunction::Register<&CConsole::SetVisible, ConsoleGetter>(rq, "Console_SetVisibleEnabled");
Script::Function::Register<&CConsole::IsActive, ConsoleGetter>(rq, "Console_GetVisibleEnabled");
Script::Function::Register<&CConsole::SetVisible, ConsoleGetter>(rq, "Console_SetVisibleEnabled");
}
}
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2021 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -18,11 +18,11 @@
#ifndef INCLUDED_JSI_CONSOLE
#define INCLUDED_JSI_CONSOLE
class ScriptRequest;
namespace Script { class Request; }
namespace JSI_Console
{
void RegisterScriptFunctions(const ScriptRequest& rq);
void RegisterScriptFunctions(const Script::Request& rq);
}
#endif // INCLUDED_JSI_CONSOLE
+9 -9
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -100,14 +100,14 @@ std::wstring GetBuildVersion(bool longerHash = false)
return buildVersion;
}
void RegisterScriptFunctions(const ScriptRequest& rq)
void RegisterScriptFunctions(const Script::Request& rq)
{
ScriptFunction::Register<&GetMicroseconds>(rq, "GetMicroseconds");
ScriptFunction::Register<&Crash>(rq, "Crash");
ScriptFunction::Register<&DebugWarn>(rq, "DebugWarn");
ScriptFunction::Register<&DisplayErrorDialog>(rq, "DisplayErrorDialog");
ScriptFunction::Register<&GetBuildDate>(rq, "GetBuildDate");
ScriptFunction::Register<&GetBuildTimestamp>(rq, "GetBuildTimestamp");
ScriptFunction::Register<&GetBuildVersion>(rq, "GetBuildVersion");
Script::Function::Register<&GetMicroseconds>(rq, "GetMicroseconds");
Script::Function::Register<&Crash>(rq, "Crash");
Script::Function::Register<&DebugWarn>(rq, "DebugWarn");
Script::Function::Register<&DisplayErrorDialog>(rq, "DisplayErrorDialog");
Script::Function::Register<&GetBuildDate>(rq, "GetBuildDate");
Script::Function::Register<&GetBuildTimestamp>(rq, "GetBuildTimestamp");
Script::Function::Register<&GetBuildVersion>(rq, "GetBuildVersion");
}
}
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2019 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -18,11 +18,11 @@
#ifndef INCLUDED_JSI_DEBUG
#define INCLUDED_JSI_DEBUG
class ScriptRequest;
namespace Script { class Request; }
namespace JSI_Debug
{
void RegisterScriptFunctions(const ScriptRequest& rq);
void RegisterScriptFunctions(const Script::Request& rq);
}
#endif // INCLUDED_JSI_DEBUG
+21 -21
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -35,7 +35,7 @@
#include "ps/Replay.h"
#include "ps/World.h"
#include "scriptinterface/FunctionWrapper.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Request.h"
#include "scriptinterface/StructuredClone.h"
#include "simulation2/Simulation2.h"
#include "simulation2/system/TurnManager.h"
@@ -47,11 +47,11 @@
#include <stdexcept>
#include <string>
class ScriptInterface;
namespace Script { class Interface; }
namespace JSI_Game
{
void StartGame(const ScriptInterface& guiInterface, JS::HandleValue attribs, int playerID, bool storeReplay)
void StartGame(const Script::Interface& guiInterface, JS::HandleValue attribs, int playerID, bool storeReplay)
{
ENSURE(!g_NetServer);
ENSURE(!g_NetClient);
@@ -61,7 +61,7 @@ void StartGame(const ScriptInterface& guiInterface, JS::HandleValue attribs, int
// Convert from GUI script context to sim script context/
CSimulation2* sim = g_Game->GetSimulation2();
ScriptRequest rqSim(sim->GetScriptInterface());
Script::Request rqSim(sim->GetScriptInterface());
JS::RootedValue gameAttribs(rqSim.cx, Script::CloneValueFromOtherCompartment(sim->GetScriptInterface(), guiInterface, attribs));
@@ -193,22 +193,22 @@ void DumpTerrainMipmap()
LOGMESSAGERENDER("Terrain mipmap written to '%s'", realPath.string8());
}
void RegisterScriptFunctions(const ScriptRequest& rq)
void RegisterScriptFunctions(const Script::Request& rq)
{
ScriptFunction::Register<&StartGame>(rq, "StartGame");
ScriptFunction::Register<&Script_EndGame>(rq, "EndGame");
ScriptFunction::Register<&GetPlayerID>(rq, "GetPlayerID");
ScriptFunction::Register<&SetPlayerID>(rq, "SetPlayerID");
ScriptFunction::Register<&SetViewedPlayer>(rq, "SetViewedPlayer");
ScriptFunction::Register<&GetSimRate>(rq, "GetSimRate");
ScriptFunction::Register<&SetSimRate>(rq, "SetSimRate");
ScriptFunction::Register<&GetPendingTurns>(rq, "GetPendingTurns");
ScriptFunction::Register<&IsPaused>(rq, "IsPaused");
ScriptFunction::Register<&SetPaused>(rq, "SetPaused");
ScriptFunction::Register<&IsVisualReplay>(rq, "IsVisualReplay");
ScriptFunction::Register<&GetCurrentReplayDirectory>(rq, "GetCurrentReplayDirectory");
ScriptFunction::Register<&EnableTimeWarpRecording>(rq, "EnableTimeWarpRecording");
ScriptFunction::Register<&RewindTimeWarp>(rq, "RewindTimeWarp");
ScriptFunction::Register<&DumpTerrainMipmap>(rq, "DumpTerrainMipmap");
Script::Function::Register<&StartGame>(rq, "StartGame");
Script::Function::Register<&Script_EndGame>(rq, "EndGame");
Script::Function::Register<&GetPlayerID>(rq, "GetPlayerID");
Script::Function::Register<&SetPlayerID>(rq, "SetPlayerID");
Script::Function::Register<&SetViewedPlayer>(rq, "SetViewedPlayer");
Script::Function::Register<&GetSimRate>(rq, "GetSimRate");
Script::Function::Register<&SetSimRate>(rq, "SetSimRate");
Script::Function::Register<&GetPendingTurns>(rq, "GetPendingTurns");
Script::Function::Register<&IsPaused>(rq, "IsPaused");
Script::Function::Register<&SetPaused>(rq, "SetPaused");
Script::Function::Register<&IsVisualReplay>(rq, "IsVisualReplay");
Script::Function::Register<&GetCurrentReplayDirectory>(rq, "GetCurrentReplayDirectory");
Script::Function::Register<&EnableTimeWarpRecording>(rq, "EnableTimeWarpRecording");
Script::Function::Register<&RewindTimeWarp>(rq, "RewindTimeWarp");
Script::Function::Register<&DumpTerrainMipmap>(rq, "DumpTerrainMipmap");
}
}
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2018 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -18,11 +18,11 @@
#ifndef INCLUDED_JSI_GAME
#define INCLUDED_JSI_GAME
class ScriptRequest;
namespace Script { class Request; }
namespace JSI_Game
{
void RegisterScriptFunctions(const ScriptRequest& rq);
void RegisterScriptFunctions(const Script::Request& rq);
}
#endif // INCLUDED_JSI_GAME
+15 -15
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -26,8 +26,8 @@
#include "ps/KeyName.h"
#include "ps/containers/StaticVector.h"
#include "scriptinterface/FunctionWrapper.h"
#include "scriptinterface/ScriptConversions.h"
#include "scriptinterface/ScriptRequest.h"
#include "scriptinterface/Conversions.h"
#include "scriptinterface/Request.h"
#include <SDL_scancode.h>
#include <js/PropertyAndElement.h>
@@ -48,7 +48,7 @@
* TODO: this could be moved to ScriptConversions.cpp if the need arises.
*/
template<typename T, typename U>
static void ToJSVal_unordered_map(const ScriptRequest& rq, JS::MutableHandleValue ret, const std::unordered_map<T, U>& val)
static void ToJSVal_unordered_map(const Script::Request& rq, JS::MutableHandleValue ret, const std::unordered_map<T, U>& val)
{
JS::RootedObject obj(rq.cx, JS_NewPlainObject(rq.cx));
if (!obj)
@@ -66,13 +66,13 @@ static void ToJSVal_unordered_map(const ScriptRequest& rq, JS::MutableHandleValu
}
template<>
void Script::ToJSVal<std::unordered_map<std::string, std::vector<std::vector<std::string>>>>(const ScriptRequest& rq, JS::MutableHandleValue ret, const std::unordered_map<std::string, std::vector<std::vector<std::string>>>& val)
void Script::ToJSVal<std::unordered_map<std::string, std::vector<std::vector<std::string>>>>(const Script::Request& rq, JS::MutableHandleValue ret, const std::unordered_map<std::string, std::vector<std::vector<std::string>>>& val)
{
ToJSVal_unordered_map(rq, ret, val);
}
template<>
void Script::ToJSVal<std::unordered_map<std::string, std::string>>(const ScriptRequest& rq, JS::MutableHandleValue ret, const std::unordered_map<std::string, std::string>& val)
void Script::ToJSVal<std::unordered_map<std::string, std::string>>(const Script::Request& rq, JS::MutableHandleValue ret, const std::unordered_map<std::string, std::string>& val)
{
ToJSVal_unordered_map(rq, ret, val);
}
@@ -82,7 +82,7 @@ namespace
/**
* @return a (js) object mapping hotkey name (from cfg files) to a list ofscancode names
*/
JS::Value GetHotkeyMap(const ScriptRequest& rq)
JS::Value GetHotkeyMap(const Script::Request& rq)
{
JS::RootedValue hotkeyMap(rq.cx);
@@ -108,7 +108,7 @@ JS::Value GetHotkeyMap(const ScriptRequest& rq)
/**
* @return a (js) object mapping scancode names to their locale-dependent name.
*/
JS::Value GetScancodeKeyNames(const ScriptRequest& rq)
JS::Value GetScancodeKeyNames(const Script::Request& rq)
{
JS::RootedValue obj(rq.cx);
std::unordered_map<std::string, std::string> map;
@@ -128,7 +128,7 @@ void ReloadHotkeys()
LoadHotkeys(g_ConfigDB);
}
JS::Value GetConflicts(const ScriptRequest& rq, JS::HandleValue combination)
JS::Value GetConflicts(const Script::Request& rq, JS::HandleValue combination)
{
std::vector<std::string> keys;
if (!Script::FromJSVal(rq, combination, keys))
@@ -172,11 +172,11 @@ JS::Value GetConflicts(const ScriptRequest& rq, JS::HandleValue combination)
}
}
void JSI_Hotkey::RegisterScriptFunctions(const ScriptRequest& rq)
void JSI_Hotkey::RegisterScriptFunctions(const Script::Request& rq)
{
ScriptFunction::Register<&HotkeyIsPressed>(rq, "HotkeyIsPressed");
ScriptFunction::Register<&GetHotkeyMap>(rq, "GetHotkeyMap");
ScriptFunction::Register<&GetScancodeKeyNames>(rq, "GetScancodeKeyNames");
ScriptFunction::Register<&ReloadHotkeys>(rq, "ReloadHotkeys");
ScriptFunction::Register<&GetConflicts>(rq, "GetConflicts");
Script::Function::Register<&HotkeyIsPressed>(rq, "HotkeyIsPressed");
Script::Function::Register<&GetHotkeyMap>(rq, "GetHotkeyMap");
Script::Function::Register<&GetScancodeKeyNames>(rq, "GetScancodeKeyNames");
Script::Function::Register<&ReloadHotkeys>(rq, "ReloadHotkeys");
Script::Function::Register<&GetConflicts>(rq, "GetConflicts");
}
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2021 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -18,11 +18,11 @@
#ifndef INCLUDED_JSI_HOTKEY
#define INCLUDED_JSI_HOTKEY
class ScriptRequest;
namespace Script { class Request; }
namespace JSI_Hotkey
{
void RegisterScriptFunctions(const ScriptRequest& rq);
void RegisterScriptFunctions(const Script::Request& rq);
}
#endif // INCLUDED_JSI_HOTKEY

Some files were not shown because too many files have changed in this diff Show More