Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/scripting/EngineScriptConversions.cpp
Show First 20 Lines • Show All 162 Lines • ▼ Show 20 Lines | template<> void ScriptInterface::ToJSVal<CFixedVector3D>(const ScriptRequest& rq, JS::MutableHandleValue ret, const CFixedVector3D& val) | ||||
if (!JS_GetProperty(rq.cx, global, "Vector3D", &valueVector3D)) | if (!JS_GetProperty(rq.cx, global, "Vector3D", &valueVector3D)) | ||||
FAIL_VOID("Failed to get Vector3D constructor"); | FAIL_VOID("Failed to get Vector3D constructor"); | ||||
JS::AutoValueArray<3> args(rq.cx); | JS::AutoValueArray<3> args(rq.cx); | ||||
args[0].setNumber(val.X.ToDouble()); | args[0].setNumber(val.X.ToDouble()); | ||||
args[1].setNumber(val.Y.ToDouble()); | args[1].setNumber(val.Y.ToDouble()); | ||||
args[2].setNumber(val.Z.ToDouble()); | args[2].setNumber(val.Z.ToDouble()); | ||||
if (!JS::Construct(rq.cx, valueVector3D, args, ret)) | JS::RootedObject objVec(rq.cx); | ||||
if (!JS::Construct(rq.cx, valueVector3D, args, &objVec)) | |||||
FAIL_VOID("Failed to construct Vector3D object"); | FAIL_VOID("Failed to construct Vector3D object"); | ||||
ret.setObject(*objVec); | |||||
} | } | ||||
template<> bool ScriptInterface::FromJSVal<CFixedVector2D>(const ScriptRequest& rq, JS::HandleValue v, CFixedVector2D& out) | template<> bool ScriptInterface::FromJSVal<CFixedVector2D>(const ScriptRequest& rq, JS::HandleValue v, CFixedVector2D& out) | ||||
{ | { | ||||
if (!v.isObject()) | if (!v.isObject()) | ||||
return false; // TODO: report type error | return false; // TODO: report type error | ||||
JS::RootedObject obj(rq.cx, &v.toObject()); | JS::RootedObject obj(rq.cx, &v.toObject()); | ||||
Show All 14 Lines | template<> void ScriptInterface::ToJSVal<CFixedVector2D>(const ScriptRequest& rq, JS::MutableHandleValue ret, const CFixedVector2D& val) | ||||
JS::RootedValue valueVector2D(rq.cx); | JS::RootedValue valueVector2D(rq.cx); | ||||
if (!JS_GetProperty(rq.cx, global, "Vector2D", &valueVector2D)) | if (!JS_GetProperty(rq.cx, global, "Vector2D", &valueVector2D)) | ||||
FAIL_VOID("Failed to get Vector2D constructor"); | FAIL_VOID("Failed to get Vector2D constructor"); | ||||
JS::AutoValueArray<2> args(rq.cx); | JS::AutoValueArray<2> args(rq.cx); | ||||
args[0].setNumber(val.X.ToDouble()); | args[0].setNumber(val.X.ToDouble()); | ||||
args[1].setNumber(val.Y.ToDouble()); | args[1].setNumber(val.Y.ToDouble()); | ||||
if (!JS::Construct(rq.cx, valueVector2D, args, ret)) | JS::RootedObject objVec(rq.cx); | ||||
if (!JS::Construct(rq.cx, valueVector2D, args, &objVec)) | |||||
FAIL_VOID("Failed to construct Vector2D object"); | FAIL_VOID("Failed to construct Vector2D object"); | ||||
ret.setObject(*objVec); | |||||
} | } | ||||
template<> void ScriptInterface::ToJSVal<Grid<u8> >(const ScriptRequest& rq, JS::MutableHandleValue ret, const Grid<u8>& val) | template<> void ScriptInterface::ToJSVal<Grid<u8> >(const ScriptRequest& rq, JS::MutableHandleValue ret, const Grid<u8>& val) | ||||
{ | { | ||||
u32 length = (u32)(val.m_W * val.m_H); | u32 length = (u32)(val.m_W * val.m_H); | ||||
u32 nbytes = (u32)(length * sizeof(u8)); | u32 nbytes = (u32)(length * sizeof(u8)); | ||||
JS::RootedObject objArr(rq.cx, JS_NewUint8Array(rq.cx, length)); | JS::RootedObject objArr(rq.cx, JS_NewUint8Array(rq.cx, length)); | ||||
// Copy the array data and then remove the no-GC check to allow further changes to the JS data | // Copy the array data and then remove the no-GC check to allow further changes to the JS data | ||||
▲ Show 20 Lines • Show All 115 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator