forked from 0ad/0ad
scripting-interface improvements
- strict param count checks - use ScriptingHost::RunMemScript instead of copy+pasted code - replace duplicated parameter access code with macros StringBuffer: use pointer instead of reference to allow compiler-generated copy ctor singleton: fix whitespace This was SVN commit r2586.
This commit is contained in:
parent
a69ac0dee9
commit
52ebd6ba11
@ -117,7 +117,7 @@ void JSI_Camera::Camera_Info::FreshenTarget()
|
|||||||
m_sv_Target = m_Data->GetFocus();
|
m_sv_Target = m_Data->GetFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
JSBool JSI_Camera::getCamera( JSContext* cx, JSObject* obj, jsval id, jsval* vp )
|
JSBool JSI_Camera::getCamera( JSContext* cx, JSObject* UNUSED(obj), jsval UNUSED(id), jsval* vp )
|
||||||
{
|
{
|
||||||
JSObject* camera = JS_NewObject( cx, &JSI_Camera::JSI_class, NULL, NULL );
|
JSObject* camera = JS_NewObject( cx, &JSI_Camera::JSI_class, NULL, NULL );
|
||||||
JS_SetPrivate( cx, camera, new Camera_Info( g_Game->GetView()->GetCamera() ) );
|
JS_SetPrivate( cx, camera, new Camera_Info( g_Game->GetView()->GetCamera() ) );
|
||||||
@ -125,7 +125,7 @@ JSBool JSI_Camera::getCamera( JSContext* cx, JSObject* obj, jsval id, jsval* vp
|
|||||||
return( JS_TRUE );
|
return( JS_TRUE );
|
||||||
}
|
}
|
||||||
|
|
||||||
JSBool JSI_Camera::setCamera( JSContext* cx, JSObject* obj, jsval id, jsval* vp )
|
JSBool JSI_Camera::setCamera( JSContext* cx, JSObject* UNUSED(obj), jsval UNUSED(id), jsval* vp )
|
||||||
{
|
{
|
||||||
JSObject* camera = JSVAL_TO_OBJECT( *vp );
|
JSObject* camera = JSVAL_TO_OBJECT( *vp );
|
||||||
Camera_Info* cameraInfo;
|
Camera_Info* cameraInfo;
|
||||||
@ -154,7 +154,7 @@ JSBool JSI_Camera::getProperty( JSContext* cx, JSObject* obj, jsval id, jsval* v
|
|||||||
|
|
||||||
CVector3D* d;
|
CVector3D* d;
|
||||||
|
|
||||||
switch( g_ScriptingHost.ValueToInt( id ) )
|
switch( ToPrimitive<int>( id ) )
|
||||||
{
|
{
|
||||||
case vector_position: d = &cameraInfo->m_sv_Position; break;
|
case vector_position: d = &cameraInfo->m_sv_Position; break;
|
||||||
case vector_orientation: d = &cameraInfo->m_sv_Orientation; break;
|
case vector_orientation: d = &cameraInfo->m_sv_Orientation; break;
|
||||||
@ -187,7 +187,7 @@ JSBool JSI_Camera::setProperty( JSContext* cx, JSObject* obj, jsval id, jsval* v
|
|||||||
{
|
{
|
||||||
cameraInfo->Freshen();
|
cameraInfo->Freshen();
|
||||||
|
|
||||||
switch( g_ScriptingHost.ValueToInt( id ) )
|
switch( ToPrimitive<int>( id ) )
|
||||||
{
|
{
|
||||||
case vector_position: cameraInfo->m_sv_Position = *( v->vector ); break;
|
case vector_position: cameraInfo->m_sv_Position = *( v->vector ); break;
|
||||||
case vector_orientation: cameraInfo->m_sv_Orientation = *( v->vector ); break;
|
case vector_orientation: cameraInfo->m_sv_Orientation = *( v->vector ); break;
|
||||||
@ -200,16 +200,15 @@ JSBool JSI_Camera::setProperty( JSContext* cx, JSObject* obj, jsval id, jsval* v
|
|||||||
return( JS_TRUE );
|
return( JS_TRUE );
|
||||||
}
|
}
|
||||||
|
|
||||||
JSBool JSI_Camera::lookAt( JSContext* cx, JSObject* obj, unsigned int argc, jsval* argv, jsval* rval )
|
#define GETVECTOR( jv ) ( ( JSVAL_IS_OBJECT( jv ) && ( v = (JSI_Vector3D::Vector3D_Info*)JS_GetInstancePrivate( g_ScriptingHost.getContext(), JSVAL_TO_OBJECT( jv ), &JSI_Vector3D::JSI_class, NULL ) ) ) ? *(v->vector) : CVector3D() )
|
||||||
{
|
|
||||||
debug_assert( argc >= 2 );
|
|
||||||
|
|
||||||
|
|
||||||
|
JSBool JSI_Camera::lookAt( JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* rval )
|
||||||
|
{
|
||||||
JSI_Vector3D::Vector3D_Info* v = NULL;
|
JSI_Vector3D::Vector3D_Info* v = NULL;
|
||||||
Camera_Info* cameraInfo = (Camera_Info*)JS_GetPrivate( cx, obj );
|
Camera_Info* cameraInfo = (Camera_Info*)JS_GetPrivate( cx, obj );
|
||||||
|
|
||||||
#define GETVECTOR( jv ) ( ( JSVAL_IS_OBJECT( jv ) && ( v = (JSI_Vector3D::Vector3D_Info*)JS_GetInstancePrivate( g_ScriptingHost.getContext(), JSVAL_TO_OBJECT( jv ), &JSI_Vector3D::JSI_class, NULL ) ) ) ? *(v->vector) : CVector3D() )
|
if( 2 <= argc && argc <= 3 )
|
||||||
|
|
||||||
if( argc <= 3 )
|
|
||||||
{
|
{
|
||||||
cameraInfo->m_sv_Position = GETVECTOR( argv[0] );
|
cameraInfo->m_sv_Position = GETVECTOR( argv[0] );
|
||||||
cameraInfo->m_sv_Orientation = ( GETVECTOR( argv[1] ) - GETVECTOR( argv[0] ) );
|
cameraInfo->m_sv_Orientation = ( GETVECTOR( argv[1] ) - GETVECTOR( argv[0] ) );
|
||||||
@ -217,7 +216,7 @@ JSBool JSI_Camera::lookAt( JSContext* cx, JSObject* obj, unsigned int argc, jsva
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
JS_ReportError( cx, "[Camera] Too many arguments to lookAt" );
|
JS_ReportError( cx, "[Camera] lookAt: incorrect argument count" );
|
||||||
*rval = JSVAL_FALSE;
|
*rval = JSVAL_FALSE;
|
||||||
return( JS_TRUE );
|
return( JS_TRUE );
|
||||||
}
|
}
|
||||||
@ -231,15 +230,14 @@ JSBool JSI_Camera::lookAt( JSContext* cx, JSObject* obj, unsigned int argc, jsva
|
|||||||
cameraInfo->m_sv_Up = GETVECTOR( argv[2] );
|
cameraInfo->m_sv_Up = GETVECTOR( argv[2] );
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef GETVECTOR
|
|
||||||
|
|
||||||
cameraInfo->Update();
|
cameraInfo->Update();
|
||||||
|
|
||||||
*rval = JSVAL_TRUE;
|
*rval = JSVAL_TRUE;
|
||||||
return( JS_TRUE );
|
return( JS_TRUE );
|
||||||
}
|
}
|
||||||
|
|
||||||
JSBool JSI_Camera::getFocus( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval )
|
JSBool JSI_Camera::getFocus( JSContext* cx, JSObject* obj,
|
||||||
|
uintN UNUSED(argc), jsval* UNUSED(argv), jsval* rval )
|
||||||
{
|
{
|
||||||
// Largely copied from the equivalent method in CCamera
|
// Largely copied from the equivalent method in CCamera
|
||||||
|
|
||||||
@ -251,14 +249,13 @@ JSBool JSI_Camera::getFocus( JSContext* cx, JSObject* obj, uintN argc, jsval* ar
|
|||||||
return( JS_TRUE );
|
return( JS_TRUE );
|
||||||
}
|
}
|
||||||
|
|
||||||
JSBool JSI_Camera::construct( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval )
|
JSBool JSI_Camera::construct( JSContext* cx, JSObject* UNUSED(obj),
|
||||||
|
uintN argc, jsval* argv, jsval* rval )
|
||||||
{
|
{
|
||||||
JSI_Vector3D::Vector3D_Info* v = NULL;
|
JSI_Vector3D::Vector3D_Info* v = NULL;
|
||||||
|
|
||||||
JSObject* camera = JS_NewObject( cx, &JSI_Camera::JSI_class, NULL, NULL );
|
JSObject* camera = JS_NewObject( cx, &JSI_Camera::JSI_class, NULL, NULL );
|
||||||
|
|
||||||
#define GETVECTOR( jv ) ( ( JSVAL_IS_OBJECT( jv ) && ( v = (JSI_Vector3D::Vector3D_Info*)JS_GetInstancePrivate( g_ScriptingHost.getContext(), JSVAL_TO_OBJECT( jv ), &JSI_Vector3D::JSI_class, NULL ) ) ) ? *(v->vector) : CVector3D() )
|
|
||||||
|
|
||||||
if( argc == 0 )
|
if( argc == 0 )
|
||||||
{
|
{
|
||||||
JS_SetPrivate( cx, camera, new Camera_Info() );
|
JS_SetPrivate( cx, camera, new Camera_Info() );
|
||||||
|
@ -74,11 +74,11 @@ namespace JSI_Camera
|
|||||||
JSBool getCamera( JSContext* cx, JSObject* obj, jsval id, jsval* vp );
|
JSBool getCamera( JSContext* cx, JSObject* obj, jsval id, jsval* vp );
|
||||||
JSBool setCamera( JSContext* cx, JSObject* obj, jsval id, jsval* vp );
|
JSBool setCamera( JSContext* cx, JSObject* obj, jsval id, jsval* vp );
|
||||||
|
|
||||||
JSBool construct( JSContext* cx, JSObject* obj, unsigned int argc, jsval* argv, jsval* rval );
|
JSBool construct( JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* rval );
|
||||||
void finalize( JSContext* cx, JSObject* obj );
|
void finalize( JSContext* cx, JSObject* obj );
|
||||||
|
|
||||||
JSBool lookAt( JSContext* cx, JSObject* obj, unsigned int argc, jsval* argv, jsval* rval );
|
JSBool lookAt( JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* rval );
|
||||||
JSBool getFocus( JSContext* cx, JSObject* obj, unsigned int argc, jsval* argv, jsval* rval );
|
JSBool getFocus( JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* rval );
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
};
|
};
|
||||||
|
@ -218,7 +218,7 @@ int CGUI::HandleEvent(const SDL_Event* ev)
|
|||||||
}
|
}
|
||||||
catch (PS_RESULT e)
|
catch (PS_RESULT e)
|
||||||
{
|
{
|
||||||
UNUSED(e);
|
UNUSED2(e);
|
||||||
debug_warn("CGUI::HandleEvent error");
|
debug_warn("CGUI::HandleEvent error");
|
||||||
// TODO Gee: Handle
|
// TODO Gee: Handle
|
||||||
}
|
}
|
||||||
@ -433,7 +433,7 @@ void CGUI::Draw()
|
|||||||
}
|
}
|
||||||
catch (PS_RESULT e)
|
catch (PS_RESULT e)
|
||||||
{
|
{
|
||||||
UNUSED(e);
|
UNUSED2(e);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
// TODO Gee: Report error.
|
// TODO Gee: Report error.
|
||||||
@ -445,9 +445,9 @@ void CGUI::Draw()
|
|||||||
|
|
||||||
void CGUI::DrawSprite(CGUISpriteInstance& Sprite,
|
void CGUI::DrawSprite(CGUISpriteInstance& Sprite,
|
||||||
int CellID,
|
int CellID,
|
||||||
const float &Z,
|
const float& Z,
|
||||||
const CRect &Rect,
|
const CRect& Rect,
|
||||||
const CRect &Clipping)
|
const CRect& UNUSED(Clipping))
|
||||||
{
|
{
|
||||||
// If the sprite doesn't exist (name == ""), don't bother drawing anything
|
// If the sprite doesn't exist (name == ""), don't bother drawing anything
|
||||||
if (Sprite.IsEmpty())
|
if (Sprite.IsEmpty())
|
||||||
@ -477,7 +477,7 @@ void CGUI::Destroy()
|
|||||||
}
|
}
|
||||||
catch (PS_RESULT e)
|
catch (PS_RESULT e)
|
||||||
{
|
{
|
||||||
UNUSED(e);
|
UNUSED2(e);
|
||||||
debug_warn("CGUI::Destroy error");
|
debug_warn("CGUI::Destroy error");
|
||||||
// TODO Gee: Handle
|
// TODO Gee: Handle
|
||||||
}
|
}
|
||||||
@ -1384,27 +1384,12 @@ void CGUI::Xeromyces_ReadScript(XMBElement Element, CXeromyces* pFile)
|
|||||||
|
|
||||||
// If there is a file specified, open and execute it
|
// If there is a file specified, open and execute it
|
||||||
if (file.Length())
|
if (file.Length())
|
||||||
{
|
g_ScriptingHost.RunScript(file, m_ScriptObject);
|
||||||
CVFSFile scriptfile;
|
|
||||||
if (scriptfile.Load(file) != PSRETURN_OK)
|
|
||||||
{
|
|
||||||
LOG(ERROR, LOG_CATEGORY, "Error opening script file '%s'", file.c_str());
|
|
||||||
throw PSERROR_GUI_JSOpenFailed();
|
|
||||||
}
|
|
||||||
|
|
||||||
jsval result;
|
|
||||||
JS_EvaluateScript(g_ScriptingHost.getContext(), m_ScriptObject, (const char*)scriptfile.GetBuffer(), (int)scriptfile.GetBufferSize(), file, 1, &result);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute inline scripts
|
// Execute inline scripts
|
||||||
CStr code (Element.getText());
|
CStr code (Element.getText());
|
||||||
|
|
||||||
if (code.Length())
|
if (code.Length())
|
||||||
{
|
g_ScriptingHost.RunMemScript(code.c_str(), code.Length(), "Some XML file", Element.getLineNumber(), m_ScriptObject);
|
||||||
jsval result;
|
|
||||||
// TODO: Report the filename
|
|
||||||
JS_EvaluateScript(g_ScriptingHost.getContext(), m_ScriptObject, code.c_str(), (int)code.Length(), "Some XML file", Element.getLineNumber(), &result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGUI::Xeromyces_ReadSprite(XMBElement Element, CXeromyces* pFile)
|
void CGUI::Xeromyces_ReadSprite(XMBElement Element, CXeromyces* pFile)
|
||||||
|
@ -25,7 +25,7 @@ I18n::StringBuffer::operator Str()
|
|||||||
g_UsedCache = false;
|
g_UsedCache = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (Variables.size() != String.VarCount)
|
if (Variables.size() != String->VarCount)
|
||||||
{
|
{
|
||||||
LOG(ERROR, LOG_CATEGORY, "I18n: Incorrect number of parameters passed to Translate");
|
LOG(ERROR, LOG_CATEGORY, "I18n: Incorrect number of parameters passed to Translate");
|
||||||
|
|
||||||
@ -35,9 +35,9 @@ I18n::StringBuffer::operator Str()
|
|||||||
return L"(translation error)";
|
return L"(translation error)";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (String.VarCount == 0)
|
if (String->VarCount == 0)
|
||||||
if (String.Parts.size())
|
if (String->Parts.size())
|
||||||
return String.Parts[0]->ToString(Locale, Variables).str();
|
return String->Parts[0]->ToString(Locale, Variables).str();
|
||||||
else
|
else
|
||||||
return Str();
|
return Str();
|
||||||
|
|
||||||
@ -58,8 +58,8 @@ I18n::StringBuffer::operator Str()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Not in cache - construct the string
|
// Not in cache - construct the string
|
||||||
for (std::vector<const TSComponent*>::iterator it = String.Parts.begin(),
|
for (std::vector<const TSComponent*>::iterator it = String->Parts.begin(),
|
||||||
end = String.Parts.end();
|
end = String->Parts.end();
|
||||||
it != end; ++it)
|
it != end; ++it)
|
||||||
{
|
{
|
||||||
ret += (*it)->ToString(Locale, Variables).str();
|
ret += (*it)->ToString(Locale, Variables).str();
|
||||||
@ -70,11 +70,6 @@ I18n::StringBuffer::operator Str()
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
I18n::StringBuffer::StringBuffer(TranslatedString& str, CLocale* loc)
|
|
||||||
: String(str), Locale(loc)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 I18n::StringBuffer::Hash()
|
u32 I18n::StringBuffer::Hash()
|
||||||
{
|
{
|
||||||
u32 hash = 0;
|
u32 hash = 0;
|
||||||
|
@ -41,10 +41,17 @@ namespace I18n
|
|||||||
u32 Hash();
|
u32 Hash();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
StringBuffer(TranslatedString&, CLocale*);
|
TranslatedString* String;
|
||||||
TranslatedString& String;
|
// pointer instead of reference allows assignment.
|
||||||
|
// this class is returned by value, so it's nicer for the
|
||||||
|
// compiler-generated copy ctor to be used.
|
||||||
std::vector<BufferVariable*> Variables;
|
std::vector<BufferVariable*> Variables;
|
||||||
CLocale* Locale;
|
CLocale* Locale;
|
||||||
|
|
||||||
|
StringBuffer(TranslatedString* str, CLocale* loc)
|
||||||
|
: String(str), Locale(loc)
|
||||||
|
{
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ JSBool JSI_Vector3D::getProperty( JSContext* cx, JSObject* obj, jsval id, jsval*
|
|||||||
|
|
||||||
if( vectorInfo->owner && vectorInfo->freshenFn ) ( (vectorInfo->owner)->*(vectorInfo->freshenFn) )();
|
if( vectorInfo->owner && vectorInfo->freshenFn ) ( (vectorInfo->owner)->*(vectorInfo->freshenFn) )();
|
||||||
|
|
||||||
switch( g_ScriptingHost.ValueToInt( id ) )
|
switch( ToPrimitive<int>( id ) )
|
||||||
{
|
{
|
||||||
case component_x: *vp = DOUBLE_TO_JSVAL( JS_NewDouble( cx, vectorData->X ) ); return( JS_TRUE );
|
case component_x: *vp = DOUBLE_TO_JSVAL( JS_NewDouble( cx, vectorData->X ) ); return( JS_TRUE );
|
||||||
case component_y: *vp = DOUBLE_TO_JSVAL( JS_NewDouble( cx, vectorData->Y ) ); return( JS_TRUE );
|
case component_y: *vp = DOUBLE_TO_JSVAL( JS_NewDouble( cx, vectorData->Y ) ); return( JS_TRUE );
|
||||||
@ -131,11 +131,11 @@ JSBool JSI_Vector3D::setProperty( JSContext* cx, JSObject* obj, jsval id, jsval*
|
|||||||
|
|
||||||
if( vectorInfo->owner && vectorInfo->freshenFn ) ( (vectorInfo->owner)->*(vectorInfo->freshenFn) )();
|
if( vectorInfo->owner && vectorInfo->freshenFn ) ( (vectorInfo->owner)->*(vectorInfo->freshenFn) )();
|
||||||
|
|
||||||
switch( g_ScriptingHost.ValueToInt( id ) )
|
switch( ToPrimitive<int>( id ) )
|
||||||
{
|
{
|
||||||
case component_x: vectorData->X = (float)g_ScriptingHost.ValueToDouble( *vp ); break;
|
case component_x: vectorData->X = ToPrimitive<float>( *vp ); break;
|
||||||
case component_y: vectorData->Y = (float)g_ScriptingHost.ValueToDouble( *vp ); break;
|
case component_y: vectorData->Y = ToPrimitive<float>( *vp ); break;
|
||||||
case component_z: vectorData->Z = (float)g_ScriptingHost.ValueToDouble( *vp ); break;
|
case component_z: vectorData->Z = ToPrimitive<float>( *vp ); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ JSBool JSI_Vector3D::setProperty( JSContext* cx, JSObject* obj, jsval id, jsval*
|
|||||||
return( JS_TRUE );
|
return( JS_TRUE );
|
||||||
}
|
}
|
||||||
|
|
||||||
JSBool JSI_Vector3D::construct( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval )
|
JSBool JSI_Vector3D::construct( JSContext* cx, JSObject* UNUSED(obj), uintN argc, jsval* argv, jsval* rval )
|
||||||
{
|
{
|
||||||
JSObject* vector = JS_NewObject( cx, &JSI_Vector3D::JSI_class, NULL, NULL );
|
JSObject* vector = JS_NewObject( cx, &JSI_Vector3D::JSI_class, NULL, NULL );
|
||||||
|
|
||||||
@ -158,9 +158,9 @@ JSBool JSI_Vector3D::construct( JSContext* cx, JSObject* obj, uintN argc, jsval*
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
float x = (float)g_ScriptingHost.ValueToDouble( argv[0] );
|
float x = ToPrimitive<float>( argv[0] );
|
||||||
float y = (float)g_ScriptingHost.ValueToDouble( argv[1] );
|
float y = ToPrimitive<float>( argv[1] );
|
||||||
float z = (float)g_ScriptingHost.ValueToDouble( argv[2] );
|
float z = ToPrimitive<float>( argv[2] );
|
||||||
JS_SetPrivate( cx, vector, new Vector3D_Info( x, y, z ) );
|
JS_SetPrivate( cx, vector, new Vector3D_Info( x, y, z ) );
|
||||||
*rval = OBJECT_TO_JSVAL( vector );
|
*rval = OBJECT_TO_JSVAL( vector );
|
||||||
return( JS_TRUE );
|
return( JS_TRUE );
|
||||||
@ -186,7 +186,8 @@ void JSI_Vector3D::finalize( JSContext* cx, JSObject* obj )
|
|||||||
delete( (Vector3D_Info*)JS_GetPrivate( cx, obj ) );
|
delete( (Vector3D_Info*)JS_GetPrivate( cx, obj ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
JSBool JSI_Vector3D::toString( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval )
|
JSBool JSI_Vector3D::toString( JSContext* cx, JSObject* obj,
|
||||||
|
uintN UNUSED(argc), jsval* UNUSED(argv), jsval* rval )
|
||||||
{
|
{
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
Vector3D_Info* vectorInfo = (Vector3D_Info*)JS_GetPrivate( cx, obj );
|
Vector3D_Info* vectorInfo = (Vector3D_Info*)JS_GetPrivate( cx, obj );
|
||||||
@ -214,15 +215,35 @@ CVector3D* JSI_Vector3D::GetVector( JSContext* cx, JSObject* obj )
|
|||||||
return( vectorInfo->vector );
|
return( vectorInfo->vector );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define GET_VECTORS\
|
||||||
|
CVector3D* a = GetVector( cx, obj );\
|
||||||
|
if(!a)\
|
||||||
|
return( JS_TRUE );\
|
||||||
|
if( ( argc == 0 ) || !JSVAL_IS_OBJECT( argv[0] ) )\
|
||||||
|
{\
|
||||||
|
invalid_param:\
|
||||||
|
JS_ReportError( cx, "[Vector3D] Invalid parameter" );\
|
||||||
|
return( JS_TRUE );\
|
||||||
|
}\
|
||||||
|
CVector3D* b = GetVector( cx, JSVAL_TO_OBJECT( argv[0] ) );\
|
||||||
|
if(!b)\
|
||||||
|
goto invalid_param;
|
||||||
|
|
||||||
|
#define GET_VECTOR_AND_FLOAT\
|
||||||
|
CVector3D* v = GetVector( cx, obj );\
|
||||||
|
if(!v)\
|
||||||
|
return( JS_TRUE );\
|
||||||
|
float f;\
|
||||||
|
if( ( argc == 0 ) || !ToPrimitive( cx, argv[0], f ) )\
|
||||||
|
{\
|
||||||
|
JS_ReportError( cx, "Invalid parameter" );\
|
||||||
|
return( JS_TRUE );\
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
JSBool JSI_Vector3D::add( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval )
|
JSBool JSI_Vector3D::add( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval )
|
||||||
{
|
{
|
||||||
CVector3D *a, *b;
|
GET_VECTORS;
|
||||||
if( !( a = GetVector( cx, obj ) ) ) return( JS_TRUE );
|
|
||||||
if( ( argc == 0 ) || !JSVAL_IS_OBJECT( argv[0] ) || !( b = GetVector( cx, JSVAL_TO_OBJECT( argv[0] ) ) ) )
|
|
||||||
{
|
|
||||||
JS_ReportError( cx, "[Vector3D] Invalid parameter" );
|
|
||||||
return( JS_TRUE );
|
|
||||||
}
|
|
||||||
|
|
||||||
JSObject* vector3d = JS_NewObject( g_ScriptingHost.getContext(), &JSI_Vector3D::JSI_class, NULL, NULL );
|
JSObject* vector3d = JS_NewObject( g_ScriptingHost.getContext(), &JSI_Vector3D::JSI_class, NULL, NULL );
|
||||||
JS_SetPrivate( g_ScriptingHost.getContext(), vector3d, new JSI_Vector3D::Vector3D_Info( *a + *b ) );
|
JS_SetPrivate( g_ScriptingHost.getContext(), vector3d, new JSI_Vector3D::Vector3D_Info( *a + *b ) );
|
||||||
@ -233,13 +254,7 @@ JSBool JSI_Vector3D::add( JSContext* cx, JSObject* obj, uintN argc, jsval* argv,
|
|||||||
|
|
||||||
JSBool JSI_Vector3D::subtract( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval )
|
JSBool JSI_Vector3D::subtract( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval )
|
||||||
{
|
{
|
||||||
CVector3D *a, *b;
|
GET_VECTORS;
|
||||||
if( !( a = GetVector( cx, obj ) ) ) return( JS_TRUE );
|
|
||||||
if( ( argc == 0 ) || !JSVAL_IS_OBJECT( argv[0] ) || !( b = GetVector( cx, JSVAL_TO_OBJECT( argv[0] ) ) ) )
|
|
||||||
{
|
|
||||||
JS_ReportError( cx, "[Vector3D] Invalid parameter" );
|
|
||||||
return( JS_TRUE );
|
|
||||||
}
|
|
||||||
|
|
||||||
JSObject* vector3d = JS_NewObject( g_ScriptingHost.getContext(), &JSI_Vector3D::JSI_class, NULL, NULL );
|
JSObject* vector3d = JS_NewObject( g_ScriptingHost.getContext(), &JSI_Vector3D::JSI_class, NULL, NULL );
|
||||||
JS_SetPrivate( g_ScriptingHost.getContext(), vector3d, new JSI_Vector3D::Vector3D_Info( *a - *b ) );
|
JS_SetPrivate( g_ScriptingHost.getContext(), vector3d, new JSI_Vector3D::Vector3D_Info( *a - *b ) );
|
||||||
@ -248,10 +263,12 @@ JSBool JSI_Vector3D::subtract( JSContext* cx, JSObject* obj, uintN argc, jsval*
|
|||||||
return( JS_TRUE );
|
return( JS_TRUE );
|
||||||
}
|
}
|
||||||
|
|
||||||
JSBool JSI_Vector3D::negate( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval )
|
JSBool JSI_Vector3D::negate( JSContext* cx, JSObject* obj,
|
||||||
|
uintN UNUSED(argc), jsval* UNUSED(argv), jsval* rval )
|
||||||
{
|
{
|
||||||
CVector3D *v;
|
CVector3D* v = GetVector( cx, obj );
|
||||||
if( !( v = GetVector( cx, obj ) ) ) return( JS_TRUE );
|
if(!v)
|
||||||
|
return( JS_TRUE );
|
||||||
|
|
||||||
*rval = ToJSVal( -( *v ) );
|
*rval = ToJSVal( -( *v ) );
|
||||||
|
|
||||||
@ -260,13 +277,7 @@ JSBool JSI_Vector3D::negate( JSContext* cx, JSObject* obj, uintN argc, jsval* ar
|
|||||||
|
|
||||||
JSBool JSI_Vector3D::scale( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval )
|
JSBool JSI_Vector3D::scale( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval )
|
||||||
{
|
{
|
||||||
CVector3D *v; float f;
|
GET_VECTOR_AND_FLOAT;
|
||||||
if( !( v = GetVector( cx, obj ) ) ) return( JS_TRUE );
|
|
||||||
if( ( argc == 0 ) || !ToPrimitive( cx, argv[0], f ) )
|
|
||||||
{
|
|
||||||
JS_ReportError( cx, "Invalid parameter" );
|
|
||||||
return( JS_TRUE );
|
|
||||||
}
|
|
||||||
|
|
||||||
JSObject* vector3d = JS_NewObject( g_ScriptingHost.getContext(), &JSI_Vector3D::JSI_class, NULL, NULL );
|
JSObject* vector3d = JS_NewObject( g_ScriptingHost.getContext(), &JSI_Vector3D::JSI_class, NULL, NULL );
|
||||||
JS_SetPrivate( g_ScriptingHost.getContext(), vector3d, new JSI_Vector3D::Vector3D_Info( *v * f ) );
|
JS_SetPrivate( g_ScriptingHost.getContext(), vector3d, new JSI_Vector3D::Vector3D_Info( *v * f ) );
|
||||||
@ -277,13 +288,7 @@ JSBool JSI_Vector3D::scale( JSContext* cx, JSObject* obj, uintN argc, jsval* arg
|
|||||||
|
|
||||||
JSBool JSI_Vector3D::divide( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval )
|
JSBool JSI_Vector3D::divide( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval )
|
||||||
{
|
{
|
||||||
CVector3D *v; float f;
|
GET_VECTOR_AND_FLOAT;
|
||||||
if( !( v = GetVector( cx, obj ) ) ) return( JS_TRUE );
|
|
||||||
if( ( argc == 0 ) || !ToPrimitive( cx, argv[0], f ) )
|
|
||||||
{
|
|
||||||
JS_ReportError( cx, "Invalid parameter" );
|
|
||||||
return( JS_TRUE );
|
|
||||||
}
|
|
||||||
|
|
||||||
JSObject* vector3d = JS_NewObject( g_ScriptingHost.getContext(), &JSI_Vector3D::JSI_class, NULL, NULL );
|
JSObject* vector3d = JS_NewObject( g_ScriptingHost.getContext(), &JSI_Vector3D::JSI_class, NULL, NULL );
|
||||||
JS_SetPrivate( g_ScriptingHost.getContext(), vector3d, new JSI_Vector3D::Vector3D_Info( *v * ( 1.0f / f ) ) );
|
JS_SetPrivate( g_ScriptingHost.getContext(), vector3d, new JSI_Vector3D::Vector3D_Info( *v * ( 1.0f / f ) ) );
|
||||||
@ -294,13 +299,7 @@ JSBool JSI_Vector3D::divide( JSContext* cx, JSObject* obj, uintN argc, jsval* ar
|
|||||||
|
|
||||||
JSBool JSI_Vector3D::dot( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval )
|
JSBool JSI_Vector3D::dot( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval )
|
||||||
{
|
{
|
||||||
CVector3D *a, *b;
|
GET_VECTORS;
|
||||||
if( !( a = GetVector( cx, obj ) ) ) return( JS_TRUE );
|
|
||||||
if( ( argc == 0 ) || !JSVAL_IS_OBJECT( argv[0] ) || !( b = GetVector( cx, JSVAL_TO_OBJECT( argv[0] ) ) ) )
|
|
||||||
{
|
|
||||||
JS_ReportError( cx, "[Vector3D] Invalid parameter" );
|
|
||||||
return( JS_TRUE );
|
|
||||||
}
|
|
||||||
|
|
||||||
*rval = ToJSVal( a->Dot( *b ) );
|
*rval = ToJSVal( a->Dot( *b ) );
|
||||||
return( JS_TRUE );
|
return( JS_TRUE );
|
||||||
@ -308,31 +307,29 @@ JSBool JSI_Vector3D::dot( JSContext* cx, JSObject* obj, uintN argc, jsval* argv,
|
|||||||
|
|
||||||
JSBool JSI_Vector3D::cross( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval )
|
JSBool JSI_Vector3D::cross( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval )
|
||||||
{
|
{
|
||||||
CVector3D *a, *b;
|
GET_VECTORS;
|
||||||
if( !( a = GetVector( cx, obj ) ) ) return( JS_TRUE );
|
|
||||||
if( ( argc == 0 ) || !JSVAL_IS_OBJECT( argv[0] ) || !( b = GetVector( cx, JSVAL_TO_OBJECT( argv[0] ) ) ) )
|
|
||||||
{
|
|
||||||
JS_ReportError( cx, "[Vector3D] Invalid parameter" );
|
|
||||||
return( JS_TRUE );
|
|
||||||
}
|
|
||||||
|
|
||||||
*rval = ToJSVal( a->Cross( *b ) );
|
*rval = ToJSVal( a->Cross( *b ) );
|
||||||
return( JS_TRUE );
|
return( JS_TRUE );
|
||||||
}
|
}
|
||||||
|
|
||||||
JSBool JSI_Vector3D::length( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval )
|
JSBool JSI_Vector3D::length( JSContext* cx, JSObject* obj,
|
||||||
|
uintN UNUSED(argc), jsval* UNUSED(argv), jsval* rval )
|
||||||
{
|
{
|
||||||
CVector3D *v;
|
CVector3D* v = GetVector( cx, obj );
|
||||||
if( !( v = GetVector( cx, obj ) ) ) return( JS_TRUE );
|
if(!v)
|
||||||
|
return( JS_TRUE );
|
||||||
|
|
||||||
*rval = ToJSVal( v->GetLength() );
|
*rval = ToJSVal( v->GetLength() );
|
||||||
return( JS_TRUE );
|
return( JS_TRUE );
|
||||||
}
|
}
|
||||||
|
|
||||||
JSBool JSI_Vector3D::normalize( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval )
|
JSBool JSI_Vector3D::normalize( JSContext* cx, JSObject* obj,
|
||||||
|
uintN UNUSED(argc), jsval* UNUSED(argv), jsval* rval )
|
||||||
{
|
{
|
||||||
CVector3D *v;
|
CVector3D* v = GetVector( cx, obj );
|
||||||
if( !( v = GetVector( cx, obj ) ) ) return( JS_TRUE );
|
if(!v)
|
||||||
|
return( JS_TRUE );
|
||||||
|
|
||||||
CVector3D r( v->X, v->Y, v->Z );
|
CVector3D r( v->X, v->Y, v->Z );
|
||||||
r.Normalize();
|
r.Normalize();
|
||||||
|
@ -26,13 +26,13 @@ class Singleton
|
|||||||
{
|
{
|
||||||
static T* ms_singleton;
|
static T* ms_singleton;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Singleton()
|
Singleton()
|
||||||
{
|
{
|
||||||
debug_assert( !ms_singleton );
|
debug_assert( !ms_singleton );
|
||||||
|
|
||||||
//use a cunning trick to get the singleton pointing to the start of
|
// use a cunning trick to get the singleton pointing to the start of
|
||||||
//the whole, rather than the start of the Singleton part of the object
|
// the whole, rather than the start of the Singleton part of the object
|
||||||
uintptr_t offset = (uintptr_t)(T*)1 - (uintptr_t)(Singleton<T>*)(T*)1;
|
uintptr_t offset = (uintptr_t)(T*)1 - (uintptr_t)(Singleton<T>*)(T*)1;
|
||||||
ms_singleton = (T*)((uintptr_t)this + offset);
|
ms_singleton = (T*)((uintptr_t)this + offset);
|
||||||
}
|
}
|
||||||
@ -40,7 +40,7 @@ class Singleton
|
|||||||
~Singleton()
|
~Singleton()
|
||||||
{
|
{
|
||||||
debug_assert( ms_singleton );
|
debug_assert( ms_singleton );
|
||||||
ms_singleton=0;
|
ms_singleton = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static T& GetSingleton()
|
static T& GetSingleton()
|
||||||
|
@ -62,7 +62,7 @@ extern CConsole* g_Console;
|
|||||||
}
|
}
|
||||||
// .. require 0 params (avoids L4 warning "unused argv param")
|
// .. require 0 params (avoids L4 warning "unused argv param")
|
||||||
#define REQUIRE_NO_PARAMS(func_name)\
|
#define REQUIRE_NO_PARAMS(func_name)\
|
||||||
UNUSED(argv);\
|
UNUSED2(argv);\
|
||||||
if(argc != 0)\
|
if(argc != 0)\
|
||||||
{\
|
{\
|
||||||
JS_ReportError(cx, #func_name ": number of parameters passed doesn't match expected count");\
|
JS_ReportError(cx, #func_name ": number of parameters passed doesn't match expected count");\
|
||||||
@ -94,7 +94,7 @@ extern CConsole* g_Console;
|
|||||||
// notes:
|
// notes:
|
||||||
// - Each argument is converted to a string and then written to the log.
|
// - Each argument is converted to a string and then written to the log.
|
||||||
// - Output is in NORMAL style (see LOG).
|
// - Output is in NORMAL style (see LOG).
|
||||||
JSBool WriteLog(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSEDPARAM(rval))
|
JSBool WriteLog(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSED(rval))
|
||||||
{
|
{
|
||||||
REQUIRE_MIN_PARAMS(1, WriteLog);
|
REQUIRE_MIN_PARAMS(1, WriteLog);
|
||||||
|
|
||||||
@ -136,7 +136,7 @@ JSBool getEntityByHandle( JSContext* cx, JSObject*, uint argc, jsval* argv, jsva
|
|||||||
i32 handle;
|
i32 handle;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
handle = g_ScriptingHost.ValueToInt( argv[0] );
|
handle = ToPrimitive<int>( argv[0] );
|
||||||
}
|
}
|
||||||
catch( PSERROR_Scripting_ConversionFailed )
|
catch( PSERROR_Scripting_ConversionFailed )
|
||||||
{
|
{
|
||||||
@ -222,7 +222,7 @@ JSBool issueCommand( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rv
|
|||||||
// Register a global handler for the specified DOM event.
|
// Register a global handler for the specified DOM event.
|
||||||
// params: event type name [wstring], handler [fragment or function]
|
// params: event type name [wstring], handler [fragment or function]
|
||||||
// returns: whether it was actually newly registered [bool]
|
// returns: whether it was actually newly registered [bool]
|
||||||
JSBool AddGlobalHandler( JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* rval )
|
JSBool AddGlobalHandler( JSContext* cx, JSObject* UNUSED(obj), uint argc, jsval* argv, jsval* rval )
|
||||||
{
|
{
|
||||||
REQUIRE_PARAMS(2, AddGlobalHandler);
|
REQUIRE_PARAMS(2, AddGlobalHandler);
|
||||||
|
|
||||||
@ -234,7 +234,7 @@ JSBool AddGlobalHandler( JSContext* cx, JSObject* obj, uint argc, jsval* argv, j
|
|||||||
// Remove a previously registered global handler for the specified DOM event.
|
// Remove a previously registered global handler for the specified DOM event.
|
||||||
// params: event type name [wstring], handler [fragment or function]
|
// params: event type name [wstring], handler [fragment or function]
|
||||||
// returns: whether it was successfully removed [bool]
|
// returns: whether it was successfully removed [bool]
|
||||||
JSBool RemoveGlobalHandler( JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* rval )
|
JSBool RemoveGlobalHandler( JSContext* cx, JSObject* UNUSED(obj), uint argc, jsval* argv, jsval* rval )
|
||||||
{
|
{
|
||||||
REQUIRE_PARAMS(2, RemoveGlobalHandler);
|
REQUIRE_PARAMS(2, RemoveGlobalHandler);
|
||||||
|
|
||||||
@ -263,14 +263,14 @@ JSBool RemoveGlobalHandler( JSContext* cx, JSObject* obj, uint argc, jsval* argv
|
|||||||
// The called function or script executes in the same scope as the
|
// The called function or script executes in the same scope as the
|
||||||
// code that called setTimeout (amongst other things, the
|
// code that called setTimeout (amongst other things, the
|
||||||
// 'this' reference is usually maintained)
|
// 'this' reference is usually maintained)
|
||||||
JSBool setTimeout( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSEDPARAM(rval) )
|
JSBool setTimeout( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSED(rval) )
|
||||||
{
|
{
|
||||||
REQUIRE_PARAMS(2, setTimeout);
|
REQUIRE_PARAMS(2, setTimeout);
|
||||||
|
|
||||||
size_t delay;
|
size_t delay;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
delay = g_ScriptingHost.ValueToInt( argv[1] );
|
delay = ToPrimitive<int>( argv[1] );
|
||||||
}
|
}
|
||||||
catch( PSERROR_Scripting_ConversionFailed )
|
catch( PSERROR_Scripting_ConversionFailed )
|
||||||
{
|
{
|
||||||
@ -305,7 +305,7 @@ JSBool setTimeout( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUS
|
|||||||
// returns:
|
// returns:
|
||||||
// notes:
|
// notes:
|
||||||
// - setTimeout's notes apply here as well.
|
// - setTimeout's notes apply here as well.
|
||||||
JSBool setInterval( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSEDPARAM(rval) )
|
JSBool setInterval( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSED(rval) )
|
||||||
{
|
{
|
||||||
REQUIRE_MIN_PARAMS(2, setInterval);
|
REQUIRE_MIN_PARAMS(2, setInterval);
|
||||||
REQUIRE_MAX_PARAMS(3, setInterval);
|
REQUIRE_MAX_PARAMS(3, setInterval);
|
||||||
@ -313,11 +313,11 @@ JSBool setInterval( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNU
|
|||||||
size_t first, interval;
|
size_t first, interval;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
first = g_ScriptingHost.ValueToInt( argv[1] );
|
first = ToPrimitive<int>( argv[1] );
|
||||||
if( argc == 3 )
|
if( argc == 3 )
|
||||||
{
|
{
|
||||||
// toDo, first, interval
|
// toDo, first, interval
|
||||||
interval = g_ScriptingHost.ValueToInt( argv[2] );
|
interval = ToPrimitive<int>( argv[2] );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -359,7 +359,7 @@ JSBool setInterval( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNU
|
|||||||
// notes:
|
// notes:
|
||||||
// - Execution continues until the end of the triggered function or
|
// - Execution continues until the end of the triggered function or
|
||||||
// script fragment, but is not triggered again.
|
// script fragment, but is not triggered again.
|
||||||
JSBool cancelInterval( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSEDPARAM(rval) )
|
JSBool cancelInterval( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSED(rval) )
|
||||||
{
|
{
|
||||||
REQUIRE_NO_PARAMS(cancelInterval);
|
REQUIRE_NO_PARAMS(cancelInterval);
|
||||||
|
|
||||||
@ -452,7 +452,7 @@ JSBool startGame(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval)
|
|||||||
// Immediately ends the current game (if any).
|
// Immediately ends the current game (if any).
|
||||||
// params:
|
// params:
|
||||||
// returns:
|
// returns:
|
||||||
JSBool endGame(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSEDPARAM(rval))
|
JSBool endGame(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSED(rval))
|
||||||
{
|
{
|
||||||
REQUIRE_NO_PARAMS(endGame);
|
REQUIRE_NO_PARAMS(endGame);
|
||||||
|
|
||||||
@ -473,7 +473,7 @@ JSBool endGame(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSEDPA
|
|||||||
// Replaces the current language (locale) with a new one.
|
// Replaces the current language (locale) with a new one.
|
||||||
// params: language id [string] as in I18n::LoadLanguage
|
// params: language id [string] as in I18n::LoadLanguage
|
||||||
// returns:
|
// returns:
|
||||||
JSBool loadLanguage(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSEDPARAM(rval))
|
JSBool loadLanguage(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSED(rval))
|
||||||
{
|
{
|
||||||
REQUIRE_PARAMS(1, loadLanguage);
|
REQUIRE_PARAMS(1, loadLanguage);
|
||||||
|
|
||||||
@ -514,7 +514,7 @@ JSBool getLanguageID(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rv
|
|||||||
// notes:
|
// notes:
|
||||||
// - currently implemented via access violation (read of address 0)
|
// - currently implemented via access violation (read of address 0)
|
||||||
// - useful for testing the crashlog/stack trace code.
|
// - useful for testing the crashlog/stack trace code.
|
||||||
JSBool crash(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSEDPARAM(rval))
|
JSBool crash(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSED(rval))
|
||||||
{
|
{
|
||||||
REQUIRE_NO_PARAMS(crash);
|
REQUIRE_NO_PARAMS(crash);
|
||||||
|
|
||||||
@ -528,7 +528,7 @@ JSBool crash(JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSEDPARA
|
|||||||
// returns: true [bool]
|
// returns: true [bool]
|
||||||
// notes:
|
// notes:
|
||||||
// - writes an indication of how long this took to the console.
|
// - writes an indication of how long this took to the console.
|
||||||
JSBool forceGC( JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* rval )
|
JSBool forceGC( JSContext* cx, JSObject* UNUSED(obj), uint argc, jsval* argv, jsval* rval )
|
||||||
{
|
{
|
||||||
REQUIRE_NO_PARAMS(forceGC);
|
REQUIRE_NO_PARAMS(forceGC);
|
||||||
|
|
||||||
@ -585,7 +585,7 @@ JSBool getFPS( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval )
|
|||||||
// notes:
|
// notes:
|
||||||
// - Exit happens after the current main loop iteration ends
|
// - Exit happens after the current main loop iteration ends
|
||||||
// (since this only sets a flag telling it to end)
|
// (since this only sets a flag telling it to end)
|
||||||
JSBool exitProgram( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSEDPARAM(rval) )
|
JSBool exitProgram( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSED(rval) )
|
||||||
{
|
{
|
||||||
REQUIRE_NO_PARAMS(exitProgram);
|
REQUIRE_NO_PARAMS(exitProgram);
|
||||||
|
|
||||||
@ -601,11 +601,11 @@ JSBool exitProgram( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNU
|
|||||||
// - Not supported on all platforms.
|
// - Not supported on all platforms.
|
||||||
// - Only a rough approximation; do not base low-level decisions
|
// - Only a rough approximation; do not base low-level decisions
|
||||||
// ("should I allocate one more texture?") on this.
|
// ("should I allocate one more texture?") on this.
|
||||||
JSBool vmem( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSEDPARAM(rval) )
|
JSBool vmem( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSED(rval) )
|
||||||
{
|
{
|
||||||
REQUIRE_NO_PARAMS(vmem);
|
REQUIRE_NO_PARAMS(vmem);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#if OS_WIN
|
||||||
int left, total;
|
int left, total;
|
||||||
if (GetVRAMInfo(left, total))
|
if (GetVRAMInfo(left, total))
|
||||||
g_Console->InsertMessage(L"VRAM: used %d, total %d, free %d", total-left, total, left);
|
g_Console->InsertMessage(L"VRAM: used %d, total %d, free %d", total-left, total, left);
|
||||||
@ -623,7 +623,7 @@ JSBool vmem( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSEDPARA
|
|||||||
// returns:
|
// returns:
|
||||||
// notes:
|
// notes:
|
||||||
// - Cursors are stored in "art\textures\cursors"
|
// - Cursors are stored in "art\textures\cursors"
|
||||||
JSBool setCursor( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSEDPARAM(rval) )
|
JSBool setCursor( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSED(rval) )
|
||||||
{
|
{
|
||||||
REQUIRE_PARAMS(1, setCursor);
|
REQUIRE_PARAMS(1, setCursor);
|
||||||
|
|
||||||
@ -637,7 +637,7 @@ JSBool setCursor( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSE
|
|||||||
// returns:
|
// returns:
|
||||||
// notes:
|
// notes:
|
||||||
// - Usefulness is unclear. If you need it, consider renaming this and updating the docs.
|
// - Usefulness is unclear. If you need it, consider renaming this and updating the docs.
|
||||||
JSBool _rewriteMaps( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSEDPARAM(rval) )
|
JSBool _rewriteMaps( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSED(rval) )
|
||||||
{
|
{
|
||||||
REQUIRE_NO_PARAMS(_rewriteMaps);
|
REQUIRE_NO_PARAMS(_rewriteMaps);
|
||||||
|
|
||||||
@ -652,11 +652,11 @@ JSBool _rewriteMaps( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UN
|
|||||||
// notes:
|
// notes:
|
||||||
// - value is as required by GL_TEXTURE_LOD_BIAS.
|
// - value is as required by GL_TEXTURE_LOD_BIAS.
|
||||||
// - useful for adjusting image "sharpness" (since it affects which mipmap level is chosen)
|
// - useful for adjusting image "sharpness" (since it affects which mipmap level is chosen)
|
||||||
JSBool _lodbias( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSEDPARAM(rval) )
|
JSBool _lodbias( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSED(rval) )
|
||||||
{
|
{
|
||||||
REQUIRE_PARAMS(1, _lodbias);
|
REQUIRE_PARAMS(1, _lodbias);
|
||||||
|
|
||||||
g_Renderer.SetOptionFloat(CRenderer::OPT_LODBIAS, (float)g_ScriptingHost.ValueToDouble(argv[0]));
|
g_Renderer.SetOptionFloat(CRenderer::OPT_LODBIAS, ToPrimitive<float>(argv[0]));
|
||||||
return JS_TRUE;
|
return JS_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -664,13 +664,13 @@ JSBool _lodbias( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* UNUSED
|
|||||||
// Focus the game camera on a given position.
|
// Focus the game camera on a given position.
|
||||||
// params: target position vector [CVector3D]
|
// params: target position vector [CVector3D]
|
||||||
// returns: success [bool]
|
// returns: success [bool]
|
||||||
JSBool setCameraTarget( JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* rval )
|
JSBool setCameraTarget( JSContext* cx, JSObject* UNUSED(obj), uint argc, jsval* argv, jsval* rval )
|
||||||
{
|
{
|
||||||
REQUIRE_PARAMS(1, setCameraTarget);
|
REQUIRE_PARAMS(1, setCameraTarget);
|
||||||
*rval = JSVAL_NULL;
|
*rval = JSVAL_NULL;
|
||||||
|
|
||||||
CVector3D* target;
|
CVector3D* target = ToNative<CVector3D>( argv[0] );
|
||||||
if( !( target = ToNative<CVector3D>( argv[0] ) ) )
|
if(!target)
|
||||||
{
|
{
|
||||||
JS_ReportError( cx, "Invalid camera target" );
|
JS_ReportError( cx, "Invalid camera target" );
|
||||||
return( JS_TRUE );
|
return( JS_TRUE );
|
||||||
@ -716,7 +716,7 @@ JSBool buildTime( JSContext* cx, JSObject*, uint argc, jsval* argv, jsval* rval
|
|||||||
// Return distance between 2 points.
|
// Return distance between 2 points.
|
||||||
// params: 2 position vectors [CVector3D]
|
// params: 2 position vectors [CVector3D]
|
||||||
// returns: Euclidean distance [float]
|
// returns: Euclidean distance [float]
|
||||||
JSBool v3dist( JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* rval )
|
JSBool v3dist( JSContext* cx, JSObject* UNUSED(obj), uint argc, jsval* argv, jsval* rval )
|
||||||
{
|
{
|
||||||
REQUIRE_PARAMS(2, v3dist);
|
REQUIRE_PARAMS(2, v3dist);
|
||||||
|
|
||||||
@ -831,7 +831,7 @@ JSFunctionSpec ScriptFunctionTable[] =
|
|||||||
// property accessors
|
// property accessors
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
JSBool GetEntitySet( JSContext* cx, JSObject*, jsval argv, jsval* vp )
|
JSBool GetEntitySet( JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsval UNUSED(argv), jsval* vp )
|
||||||
{
|
{
|
||||||
std::vector<HEntity>* extant = g_EntityManager.getExtant();
|
std::vector<HEntity>* extant = g_EntityManager.getExtant();
|
||||||
|
|
||||||
@ -842,7 +842,7 @@ JSBool GetEntitySet( JSContext* cx, JSObject*, jsval argv, jsval* vp )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JSBool GetPlayerSet( JSContext* cx, JSObject*, jsval id, jsval* vp )
|
JSBool GetPlayerSet( JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsval UNUSED(id), jsval* vp )
|
||||||
{
|
{
|
||||||
std::vector<CPlayer*>* players = g_Game->GetPlayers();
|
std::vector<CPlayer*>* players = g_Game->GetPlayers();
|
||||||
|
|
||||||
@ -852,21 +852,21 @@ JSBool GetPlayerSet( JSContext* cx, JSObject*, jsval id, jsval* vp )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JSBool GetLocalPlayer( JSContext* cx, JSObject*, jsval id, jsval* vp )
|
JSBool GetLocalPlayer( JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsval UNUSED(id), jsval* vp )
|
||||||
{
|
{
|
||||||
*vp = OBJECT_TO_JSVAL( g_Game->GetLocalPlayer()->GetScript() );
|
*vp = OBJECT_TO_JSVAL( g_Game->GetLocalPlayer()->GetScript() );
|
||||||
return( JS_TRUE );
|
return( JS_TRUE );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JSBool GetGaiaPlayer( JSContext* cx, JSObject*, jsval id, jsval* vp )
|
JSBool GetGaiaPlayer( JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsval UNUSED(id), jsval* vp )
|
||||||
{
|
{
|
||||||
*vp = OBJECT_TO_JSVAL( g_Game->GetPlayer( 0 )->GetScript() );
|
*vp = OBJECT_TO_JSVAL( g_Game->GetPlayer( 0 )->GetScript() );
|
||||||
return( JS_TRUE );
|
return( JS_TRUE );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JSBool SetLocalPlayer( JSContext* cx, JSObject* obj, jsval id, jsval* vp )
|
JSBool SetLocalPlayer( JSContext* cx, JSObject* UNUSED(obj), jsval UNUSED(id), jsval* vp )
|
||||||
{
|
{
|
||||||
CPlayer* newLocalPlayer = ToNative<CPlayer>( *vp );
|
CPlayer* newLocalPlayer = ToNative<CPlayer>( *vp );
|
||||||
|
|
||||||
@ -881,7 +881,7 @@ JSBool SetLocalPlayer( JSContext* cx, JSObject* obj, jsval id, jsval* vp )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JSBool GetGameView( JSContext* cx, JSObject*, jsval id, jsval* vp )
|
JSBool GetGameView( JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsval UNUSED(id), jsval* vp )
|
||||||
{
|
{
|
||||||
if (g_Game)
|
if (g_Game)
|
||||||
*vp = OBJECT_TO_JSVAL( g_Game->GetView()->GetScript() );
|
*vp = OBJECT_TO_JSVAL( g_Game->GetView()->GetScript() );
|
||||||
|
Loading…
Reference in New Issue
Block a user