mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-09-21 20:06:40 +00:00
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:
@@ -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;
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user