Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/scripting/JSInterface_Simulation.cpp
Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | JS::Value JSI_Simulation::GuiInterfaceCall(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& name, JS::HandleValue data) | ||||
CSimulation2* sim = g_Game->GetSimulation2(); | CSimulation2* sim = g_Game->GetSimulation2(); | ||||
ENSURE(sim); | ENSURE(sim); | ||||
CmpPtr<ICmpGuiInterface> cmpGuiInterface(*sim, SYSTEM_ENTITY); | CmpPtr<ICmpGuiInterface> cmpGuiInterface(*sim, SYSTEM_ENTITY); | ||||
if (!cmpGuiInterface) | if (!cmpGuiInterface) | ||||
return JS::UndefinedValue(); | return JS::UndefinedValue(); | ||||
ScriptInterface::Request rqSim(sim->GetScriptInterface()); | ScriptInterface::Request rqSim(sim->GetScriptInterface()); | ||||
JS::RootedValue arg(rqSim.cx, sim->GetScriptInterface().CloneValueFromOtherContext(*(pCmptPrivate->pScriptInterface), data)); | JS::RootedValue arg(rqSim.cx, sim->GetScriptInterface().CloneValueFromOtherCompartment(*(pCmptPrivate->pScriptInterface), data)); | ||||
JS::RootedValue ret(rqSim.cx); | JS::RootedValue ret(rqSim.cx); | ||||
cmpGuiInterface->ScriptCall(g_Game->GetViewedPlayerID(), name, arg, &ret); | cmpGuiInterface->ScriptCall(g_Game->GetViewedPlayerID(), name, arg, &ret); | ||||
return pCmptPrivate->pScriptInterface->CloneValueFromOtherContext(sim->GetScriptInterface(), ret); | return pCmptPrivate->pScriptInterface->CloneValueFromOtherCompartment(sim->GetScriptInterface(), ret); | ||||
} | } | ||||
void JSI_Simulation::PostNetworkCommand(ScriptInterface::CmptPrivate* pCmptPrivate, JS::HandleValue cmd) | void JSI_Simulation::PostNetworkCommand(ScriptInterface::CmptPrivate* pCmptPrivate, JS::HandleValue cmd) | ||||
{ | { | ||||
if (!g_Game) | if (!g_Game) | ||||
return; | return; | ||||
CSimulation2* sim = g_Game->GetSimulation2(); | CSimulation2* sim = g_Game->GetSimulation2(); | ||||
ENSURE(sim); | ENSURE(sim); | ||||
CmpPtr<ICmpCommandQueue> cmpCommandQueue(*sim, SYSTEM_ENTITY); | CmpPtr<ICmpCommandQueue> cmpCommandQueue(*sim, SYSTEM_ENTITY); | ||||
if (!cmpCommandQueue) | if (!cmpCommandQueue) | ||||
return; | return; | ||||
ScriptInterface::Request rqSim(sim->GetScriptInterface()); | ScriptInterface::Request rqSim(sim->GetScriptInterface()); | ||||
JS::RootedValue cmd2(rqSim.cx, sim->GetScriptInterface().CloneValueFromOtherContext(*(pCmptPrivate->pScriptInterface), cmd)); | JS::RootedValue cmd2(rqSim.cx, sim->GetScriptInterface().CloneValueFromOtherCompartment(*(pCmptPrivate->pScriptInterface), cmd)); | ||||
cmpCommandQueue->PostNetworkCommand(cmd2); | cmpCommandQueue->PostNetworkCommand(cmd2); | ||||
} | } | ||||
void JSI_Simulation::DumpSimState(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate)) | void JSI_Simulation::DumpSimState(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate)) | ||||
{ | { | ||||
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); | ||||
▲ Show 20 Lines • Show All 136 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator