Remove Vector2D/Vector3D prototype workaround from EngineScriptConversions.
Fixes #5376, refs #2394. Differential Revision: https://code.wildfiregames.com/D1991 Patch By: Krinkle Comments By: Vladislav, wraitii This was SVN commit r22487.
This commit is contained in:
parent
29a8852ea4
commit
65b02395b3
@ -39,7 +39,3 @@ Vector3D.prototype.add = function(v)
|
||||
this.z += v.z;
|
||||
return this;
|
||||
};
|
||||
|
||||
// make the prototypes easily accessible to C++
|
||||
const Vector2Dprototype = Vector2D.prototype;
|
||||
const Vector3Dprototype = Vector3D.prototype;
|
||||
|
@ -429,8 +429,3 @@ Vector3D.div = function(v, f)
|
||||
{
|
||||
return new Vector3D(v.x / f, v.y / f, v.z / f);
|
||||
};
|
||||
|
||||
|
||||
// make the prototypes easily accessible to C++
|
||||
const Vector2Dprototype = Vector2D.prototype;
|
||||
const Vector3Dprototype = Vector3D.prototype;
|
||||
|
@ -67,9 +67,6 @@ struct ScriptInterface_impl
|
||||
JSCompartment* m_comp;
|
||||
boost::rand48* m_rng;
|
||||
JS::PersistentRootedObject m_nativeScope; // native function scope object
|
||||
|
||||
typedef std::map<ScriptInterface::CACHED_VAL, JS::PersistentRootedValue> ScriptValCache;
|
||||
ScriptValCache m_ScriptValCache;
|
||||
};
|
||||
|
||||
namespace
|
||||
@ -450,13 +447,6 @@ ScriptInterface::CxPrivate* ScriptInterface::GetScriptInterfaceAndCBData(JSConte
|
||||
return pCxPrivate;
|
||||
}
|
||||
|
||||
JS::Value ScriptInterface::GetCachedValue(CACHED_VAL valueIdentifier) const
|
||||
{
|
||||
std::map<ScriptInterface::CACHED_VAL, JS::PersistentRootedValue>::const_iterator it = m->m_ScriptValCache.find(valueIdentifier);
|
||||
ENSURE(it != m->m_ScriptValCache.end());
|
||||
return it->second.get();
|
||||
}
|
||||
|
||||
|
||||
bool ScriptInterface::LoadGlobalScripts()
|
||||
{
|
||||
@ -474,13 +464,6 @@ bool ScriptInterface::LoadGlobalScripts()
|
||||
return false;
|
||||
}
|
||||
|
||||
JSAutoRequest rq(m->m_cx);
|
||||
JS::RootedValue proto(m->m_cx);
|
||||
JS::RootedObject global(m->m_cx, m->m_glob);
|
||||
if (JS_GetProperty(m->m_cx, global, "Vector2Dprototype", &proto))
|
||||
m->m_ScriptValCache[CACHE_VECTOR2DPROTO].init(GetJSRuntime(), proto);
|
||||
if (JS_GetProperty(m->m_cx, global, "Vector3Dprototype", &proto))
|
||||
m->m_ScriptValCache[CACHE_VECTOR3DPROTO].init(GetJSRuntime(), proto);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -115,9 +115,6 @@ public:
|
||||
*/
|
||||
bool LoadGlobalScripts();
|
||||
|
||||
enum CACHED_VAL { CACHE_VECTOR2DPROTO, CACHE_VECTOR3DPROTO };
|
||||
JS::Value GetCachedValue(CACHED_VAL valueIdentifier) const;
|
||||
|
||||
/**
|
||||
* Replace the default JS random number geenrator with a seeded, network-sync'd one.
|
||||
*/
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "simulation2/system/ParamNode.h"
|
||||
|
||||
#define FAIL(msg) STMT(JS_ReportError(cx, msg); return false)
|
||||
#define FAILVOID(msg) STMT(JS_ReportError(cx, msg))
|
||||
|
||||
template<> void ScriptInterface::ToJSVal<IComponent*>(JSContext* cx, JS::MutableHandleValue ret, IComponent* const& val)
|
||||
{
|
||||
@ -180,29 +181,19 @@ template<> void ScriptInterface::ToJSVal<CFixedVector3D>(JSContext* cx, JS::Muta
|
||||
{
|
||||
JSAutoRequest rq(cx);
|
||||
|
||||
// apply the Vector3D prototype to the return value;
|
||||
ScriptInterface::CxPrivate* pCxPrivate = ScriptInterface::GetScriptInterfaceAndCBData(cx);
|
||||
JS::RootedObject proto(cx, &pCxPrivate->pScriptInterface->GetCachedValue(ScriptInterface::CACHE_VECTOR3DPROTO).toObject());
|
||||
JS::RootedObject obj(cx, JS_NewObjectWithGivenProto(cx, nullptr, proto));
|
||||
JS::RootedObject global(cx, &pCxPrivate->pScriptInterface->GetGlobalObject().toObject());
|
||||
JS::RootedValue valueVector3D(cx);
|
||||
if (!JS_GetProperty(cx, global, "Vector3D", &valueVector3D))
|
||||
FAILVOID("Failed to get Vector3D constructor");
|
||||
|
||||
if (!obj)
|
||||
{
|
||||
ret.setUndefined();
|
||||
return;
|
||||
}
|
||||
JS::AutoValueArray<3> args(cx);
|
||||
args[0].setNumber(val.X.ToDouble());
|
||||
args[1].setNumber(val.Y.ToDouble());
|
||||
args[2].setNumber(val.Z.ToDouble());
|
||||
|
||||
JS::RootedValue x(cx);
|
||||
JS::RootedValue y(cx);
|
||||
JS::RootedValue z(cx);
|
||||
ToJSVal(cx, &x, val.X);
|
||||
ToJSVal(cx, &y, val.Y);
|
||||
ToJSVal(cx, &z, val.Z);
|
||||
|
||||
JS_SetProperty(cx, obj, "x", x);
|
||||
JS_SetProperty(cx, obj, "y", y);
|
||||
JS_SetProperty(cx, obj, "z", z);
|
||||
|
||||
ret.setObject(*obj);
|
||||
if (!JS::Construct(cx, valueVector3D, args, ret))
|
||||
FAILVOID("Failed to construct Vector3D object");
|
||||
}
|
||||
|
||||
template<> bool ScriptInterface::FromJSVal<CFixedVector2D>(JSContext* cx, JS::HandleValue v, CFixedVector2D& out)
|
||||
@ -227,25 +218,18 @@ template<> void ScriptInterface::ToJSVal<CFixedVector2D>(JSContext* cx, JS::Muta
|
||||
{
|
||||
JSAutoRequest rq(cx);
|
||||
|
||||
// apply the Vector2D prototype to the return value
|
||||
ScriptInterface::CxPrivate* pCxPrivate = ScriptInterface::GetScriptInterfaceAndCBData(cx);
|
||||
JS::RootedObject proto(cx, &pCxPrivate->pScriptInterface->GetCachedValue(ScriptInterface::CACHE_VECTOR2DPROTO).toObject());
|
||||
JS::RootedObject obj(cx, JS_NewObjectWithGivenProto(cx, nullptr, proto));
|
||||
if (!obj)
|
||||
{
|
||||
ret.setUndefined();
|
||||
return;
|
||||
}
|
||||
JS::RootedObject global(cx, &pCxPrivate->pScriptInterface->GetGlobalObject().toObject());
|
||||
JS::RootedValue valueVector2D(cx);
|
||||
if (!JS_GetProperty(cx, global, "Vector2D", &valueVector2D))
|
||||
FAILVOID("Failed to get Vector2D constructor");
|
||||
|
||||
JS::RootedValue x(cx);
|
||||
JS::RootedValue y(cx);
|
||||
ToJSVal(cx, &x, val.X);
|
||||
ToJSVal(cx, &y, val.Y);
|
||||
JS::AutoValueArray<2> args(cx);
|
||||
args[0].setNumber(val.X.ToDouble());
|
||||
args[1].setNumber(val.Y.ToDouble());
|
||||
|
||||
JS_SetProperty(cx, obj, "x", x);
|
||||
JS_SetProperty(cx, obj, "y", y);
|
||||
|
||||
ret.setObject(*obj);
|
||||
if (!JS::Construct(cx, valueVector2D, args, ret))
|
||||
FAILVOID("Failed to construct Vector2D object");
|
||||
}
|
||||
|
||||
template<> void ScriptInterface::ToJSVal<Grid<u8> >(JSContext* cx, JS::MutableHandleValue ret, const Grid<u8>& val)
|
||||
|
Loading…
Reference in New Issue
Block a user