Changeset View
Standalone View
source/simulation2/scripting/EngineScriptConversions.cpp
Show All 22 Lines | |||||
#include "maths/Fixed.h" | #include "maths/Fixed.h" | ||||
#include "maths/FixedVector2D.h" | #include "maths/FixedVector2D.h" | ||||
#include "maths/FixedVector3D.h" | #include "maths/FixedVector3D.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/Shapes.h" | #include "ps/Shapes.h" | ||||
#include "ps/utf16string.h" | #include "ps/utf16string.h" | ||||
#include "simulation2/helpers/CinemaPath.h" | #include "simulation2/helpers/CinemaPath.h" | ||||
#include "simulation2/helpers/Grid.h" | #include "simulation2/helpers/Grid.h" | ||||
#include "simulation2/components/ICmpVisual.h" | |||||
#include "simulation2/system/IComponent.h" | #include "simulation2/system/IComponent.h" | ||||
#include "simulation2/system/ParamNode.h" | #include "simulation2/system/ParamNode.h" | ||||
#define FAIL(msg) STMT(JS_ReportError(cx, msg); return false) | #define FAIL(msg) STMT(JS_ReportError(cx, msg); return false) | ||||
#define FAIL_VOID(msg) STMT(JS_ReportError(cx, msg); return) | #define FAIL_VOID(msg) STMT(JS_ReportError(cx, msg); return) | ||||
template<> void ScriptInterface::ToJSVal<IComponent*>(JSContext* cx, JS::MutableHandleValue ret, IComponent* const& val) | template<> void ScriptInterface::ToJSVal<IComponent*>(JSContext* cx, JS::MutableHandleValue ret, IComponent* const& val) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 295 Lines • ▼ Show 20 Lines | template<> bool ScriptInterface::FromJSVal<CCinemaPath>(JSContext* cx, JS::HandleValue v, CCinemaPath& out) | ||||
if (!FromJSProperty(cx, v, "style", pathData.m_Style)) | if (!FromJSProperty(cx, v, "style", pathData.m_Style)) | ||||
pathData.m_Style = L"default"; | pathData.m_Style = L"default"; | ||||
out = CCinemaPath(pathData, positionSpline, targetSpline); | out = CCinemaPath(pathData, positionSpline, targetSpline); | ||||
return true; | return true; | ||||
} | } | ||||
template<> void ScriptInterface::ToJSVal<JsProp>(JSContext* cx, JS::MutableHandleValue ret, const JsProp& val) | |||||
{ | |||||
JSAutoRequest rq(cx); | |||||
JS::RootedObject obj(cx, JS_NewPlainObject(cx)); | |||||
JS::RootedValue name(cx); | |||||
JS::RootedValue position(cx); | |||||
JS::RootedValue rotation(cx); | |||||
ToJSVal(cx, &name, val.m_Name); | |||||
ToJSVal(cx, &position, val.m_Position); | |||||
ToJSVal(cx, &rotation, val.m_Rotation); | |||||
elexis: ScriptInterface::CreateObject | |||||
ScriptInterface::CreateObject( | |||||
cx, | |||||
ret, | |||||
"name", name, | |||||
"rotation", rotation, | |||||
"position", position); | |||||
Done Inline ActionsThere is probably a way to make it generic for every type of std::vector but I haven't found it. Stan: There is probably a way to make it generic for every type of std::vector but I haven't found it. | |||||
Done Inline ActionsTake a look at the line after the code you insert here. elexis: Take a look at the line after the code you insert here. | |||||
} | |||||
Not Done Inline ActionsI dont assume that you envision to allow JS to change prop points. If so, specifying this method is wrong.
One can. elexis: I dont assume that you envision to allow JS to change prop points. If so, specifying this… | |||||
Done Inline ActionsSo how does one prevent that when the function is explicitely called by a macro you asked me to use ? Stan: So how does one prevent that when the function is explicitely called by a macro you asked me to… | |||||
Not Done Inline ActionsYou are permitted to find a solution that meets the objective of the macro without implementing a function that is not used and depending on design of the patch must or must not exist. elexis: You are permitted to find a solution that meets the objective of the macro without implementing… | |||||
Done Inline ActionsThat makes no sense to me, as I would've done it had I know how to :) but thanks I guess. Stan: That makes no sense to me, as I would've done it had I know how to :) but thanks I guess. | |||||
Not Done Inline ActionsThis is an example of how to define only one of the two functions without having to reimplement the vector<->JS array conversion: class IComponent; template<> void ScriptInterface::ToJSVal<std::vector<IComponent*> >(JSContext* cx, JS::MutableHandleValue ret, const std::vector<IComponent*>& val) { ToJSVal_vector(cx, ret, val); } template<> bool ScriptInterface::FromJSVal<std::vector<Entity> >(JSContext* cx, JS::HandleValue v, std::vector<Entity>& out) { return FromJSVal_vector(cx, v, out); } elexis: This is an example of how to define only one of the two functions without having to reimplement… | |||||
template<> bool ScriptInterface::FromJSVal<JsProp>(JSContext* cx, JS::HandleValue v, JsProp& out) | |||||
{ | |||||
JSAutoRequest rq(cx); | |||||
if (!v.isObject()) | |||||
Not Done Inline ActionsFromJSVal means that we create a new JS object without properties and then try to read the name and position property of that empty object? elexis: FromJSVal means that we create a new JS object without properties and then try to read the name… | |||||
Done Inline ActionsI guess not just copied the code above, as I said, I didn't need that function until I started using the macro. Stan: I guess not just copied the code above, as I said, I didn't need that function until I started… | |||||
return false; // TODO: report type error | |||||
Done Inline Actions(Otherwise had said ScriptInterface::CreateArray) elexis: (Otherwise had said ScriptInterface::CreateArray) | |||||
Done Inline ActionsWhat are the advantages / disadvantages ? Stan: What are the advantages / disadvantages ? | |||||
Done Inline ActionsNevermind. Got it ^^' Stan: Nevermind. Got it ^^' | |||||
JS::RootedObject obj(cx, &v.toObject()); | |||||
JS::RootedValue name(cx); | |||||
JS::RootedValue position(cx); | |||||
JS::RootedValue rotation(cx); | |||||
if (!JS_GetProperty(cx, obj, "name", &name)) return false; // TODO: report type errors | |||||
if (!FromJSVal(cx, name, out.m_Name)) return false; | |||||
if (!JS_GetProperty(cx, obj, "position", &position)) return false; | |||||
if (!FromJSVal(cx, position, out.m_Position)) return false; | |||||
if (!JS_GetProperty(cx, obj, "rotation", &rotation)) return false; | |||||
if (!FromJSVal(cx, rotation, out.m_Rotation)) return false; | |||||
return true; | |||||
} | |||||
// define vectors | // define vectors | ||||
JSVAL_VECTOR(CFixedVector2D) | JSVAL_VECTOR(CFixedVector2D) | ||||
JSVAL_VECTOR(JsProp) | |||||
#undef FAIL | #undef FAIL | ||||
#undef FAIL_VOID | #undef FAIL_VOID |
ScriptInterface::CreateObject