Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/scripting/JSInterface_Simulation.cpp
/* Copyright (C) 2021 Wildfire Games. | /* Copyright (C) 2022 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 17 Lines | |||||
#include "scriptinterface/FunctionWrapper.h" | #include "scriptinterface/FunctionWrapper.h" | ||||
#include "scriptinterface/StructuredClone.h" | #include "scriptinterface/StructuredClone.h" | ||||
#include "simulation2/components/ICmpAIManager.h" | #include "simulation2/components/ICmpAIManager.h" | ||||
#include "simulation2/components/ICmpCommandQueue.h" | #include "simulation2/components/ICmpCommandQueue.h" | ||||
#include "simulation2/components/ICmpGuiInterface.h" | #include "simulation2/components/ICmpGuiInterface.h" | ||||
#include "simulation2/components/ICmpObstruction.h" | #include "simulation2/components/ICmpObstruction.h" | ||||
#include "simulation2/components/ICmpPosition.h" | #include "simulation2/components/ICmpPosition.h" | ||||
#include "simulation2/components/ICmpSelectable.h" | #include "simulation2/components/ICmpSelectable.h" | ||||
#include "simulation2/components/ICmpTemplateManager.h" | |||||
#include "simulation2/helpers/Geometry.h" | #include "simulation2/helpers/Geometry.h" | ||||
#include "simulation2/helpers/Selection.h" | #include "simulation2/helpers/Selection.h" | ||||
#include "simulation2/Simulation2.h" | #include "simulation2/Simulation2.h" | ||||
#include "simulation2/system/Entity.h" | #include "simulation2/system/Entity.h" | ||||
#include "simulation2/system/ParamNode.h" | |||||
#include <array> | #include <array> | ||||
#include <fstream> | #include <fstream> | ||||
namespace JSI_Simulation | namespace JSI_Simulation | ||||
{ | { | ||||
JS::Value GuiInterfaceCall(const ScriptInterface& scriptInterface, const std::wstring& name, JS::HandleValue data) | JS::Value GuiInterfaceCall(const ScriptInterface& scriptInterface, const std::wstring& name, JS::HandleValue data) | ||||
{ | { | ||||
Show All 35 Lines | |||||
void DumpSimState() | void DumpSimState() | ||||
{ | { | ||||
OsPath path = psLogDir()/"sim_dump.txt"; | OsPath path = psLogDir()/"sim_dump.txt"; | ||||
std::ofstream file (OsString(path).c_str(), std::ofstream::out | std::ofstream::trunc); | std::ofstream file (OsString(path).c_str(), std::ofstream::out | std::ofstream::trunc); | ||||
g_Game->GetSimulation2()->DumpDebugState(file); | g_Game->GetSimulation2()->DumpDebugState(file); | ||||
} | } | ||||
CParamNode GetTemplate(const std::string& templateName) | |||||
bb: This function probably allows us to nuke many templateManager calls from the JS. One should… | |||||
{ | |||||
if (!g_Game) | |||||
return CParamNode(false); | |||||
CSimulation2* sim = g_Game->GetSimulation2(); | |||||
ENSURE(sim); | |||||
bbUnsubmitted Done Inline ActionsProbably just inline. bb: Probably just inline. | |||||
CmpPtr<ICmpTemplateManager> cmpTemplateManager(*sim, SYSTEM_ENTITY); | |||||
if (!cmpTemplateManager) | |||||
return CParamNode(false); | |||||
return *cmpTemplateManager->GetTemplate(templateName); | |||||
} | |||||
entity_id_t PickEntityAtPoint(int x, int y) | entity_id_t PickEntityAtPoint(int x, int y) | ||||
{ | { | ||||
return EntitySelection::PickEntityAtPoint(*g_Game->GetSimulation2(), *g_Game->GetView()->GetCamera(), x, y, g_Game->GetViewedPlayerID(), false); | return EntitySelection::PickEntityAtPoint(*g_Game->GetSimulation2(), *g_Game->GetView()->GetCamera(), x, y, g_Game->GetViewedPlayerID(), false); | ||||
} | } | ||||
std::vector<entity_id_t> PickPlayerEntitiesInRect(int x0, int y0, int x1, int y1, int player) | std::vector<entity_id_t> PickPlayerEntitiesInRect(int x0, int y0, int x1, int y1, int player) | ||||
{ | { | ||||
return EntitySelection::PickEntitiesInRect(*g_Game->GetSimulation2(), *g_Game->GetView()->GetCamera(), x0, y0, x1, y1, player, false); | return EntitySelection::PickEntitiesInRect(*g_Game->GetSimulation2(), *g_Game->GetView()->GetCamera(), x0, y0, x1, y1, player, false); | ||||
▲ Show 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | void RegisterScriptFunctions(const ScriptRequest& rq) | ||||
ScriptFunction::Register<&PickPlayerEntitiesInRect>(rq, "PickPlayerEntitiesInRect"); | ScriptFunction::Register<&PickPlayerEntitiesInRect>(rq, "PickPlayerEntitiesInRect"); | ||||
ScriptFunction::Register<&PickPlayerEntitiesOnScreen>(rq, "PickPlayerEntitiesOnScreen"); | ScriptFunction::Register<&PickPlayerEntitiesOnScreen>(rq, "PickPlayerEntitiesOnScreen"); | ||||
ScriptFunction::Register<&PickNonGaiaEntitiesOnScreen>(rq, "PickNonGaiaEntitiesOnScreen"); | ScriptFunction::Register<&PickNonGaiaEntitiesOnScreen>(rq, "PickNonGaiaEntitiesOnScreen"); | ||||
ScriptFunction::Register<&GetEntitiesWithStaticObstructionOnScreen>(rq, "GetEntitiesWithStaticObstructionOnScreen"); | ScriptFunction::Register<&GetEntitiesWithStaticObstructionOnScreen>(rq, "GetEntitiesWithStaticObstructionOnScreen"); | ||||
ScriptFunction::Register<&GetEdgesOfStaticObstructionsOnScreenNearTo>(rq, "GetEdgesOfStaticObstructionsOnScreenNearTo"); | ScriptFunction::Register<&GetEdgesOfStaticObstructionsOnScreenNearTo>(rq, "GetEdgesOfStaticObstructionsOnScreenNearTo"); | ||||
ScriptFunction::Register<&PickSimilarPlayerEntities>(rq, "PickSimilarPlayerEntities"); | ScriptFunction::Register<&PickSimilarPlayerEntities>(rq, "PickSimilarPlayerEntities"); | ||||
ScriptFunction::Register<&SetBoundingBoxDebugOverlay>(rq, "SetBoundingBoxDebugOverlay"); | ScriptFunction::Register<&SetBoundingBoxDebugOverlay>(rq, "SetBoundingBoxDebugOverlay"); | ||||
} | } | ||||
void RegisterScriptFunctions_Simulation(const ScriptRequest& rq) | |||||
{ | |||||
ScriptFunction::Register<&GetTemplate>(rq, "GetTemplate"); | |||||
} | |||||
} | } |
Wildfire Games · Phabricator
This function probably allows us to nuke many templateManager calls from the JS. One should test if this gives a performance difference. Obviously out of scope.