forked from 0ad/0ad
Ykkrosh
6cfb96855a
Atlas: Added simulation play/pause/reset controls; automatically plays while recording cinematics. FFmpeg: Fixed broken output files. MapReader: Fixed entity loading. ObjectHandlers: Made unit preview more robust when the preview unit gets destroyed. Various: Replaced manual matrix construction with SetYRotation call. Turned some more CStr8 back into CStr. h_mgr: Optimisation - don't calculate slow debug-output strings if they're never going to be seen (since it takes a few hundred milliseconds). TerrainRenderer: Made more tolerant of accidental negative times. Entity: Fixed m_refd being out of date when deleteAll is called. Fixed problems when doing an initializeAll...deleteAll...initializeAll sequence. SCN: Removed non-useful AoE3Ed code that never did anything. SVNLog: Made output more valid and made titles more descriptive, so it works properly in FF's live bookmarks. This was SVN commit r4779.
59 lines
1.6 KiB
C++
59 lines
1.6 KiB
C++
// A generic type and some helper functions
|
|
// for scripts
|
|
|
|
// Mark Thompson (mark@wildfiregames.com / mot20@cam.ac.uk)
|
|
|
|
#ifndef SCRIPTOBJECT_INCLUDED
|
|
#define SCRIPTOBJECT_INCLUDED
|
|
|
|
#include "scripting/SpiderMonkey.h"
|
|
|
|
class CStrW;
|
|
class CScriptEvent;
|
|
|
|
class CScriptObject
|
|
{
|
|
JSFunction* Function;
|
|
JSObject* FunctionObject;
|
|
void Root();
|
|
void Uproot();
|
|
|
|
public:
|
|
|
|
CScriptObject();
|
|
CScriptObject( JSFunction* _Function );
|
|
CScriptObject( jsval v );
|
|
CScriptObject( const CScriptObject& copy );
|
|
|
|
~CScriptObject();
|
|
|
|
// Initialize in various ways: from a JS function, a string to be compiled, or a jsval containing either.
|
|
void SetFunction( JSFunction* _Function );
|
|
void SetJSVal( jsval v );
|
|
void Compile( const CStrW& FileNameTag, const CStrW& FunctionBody );
|
|
|
|
inline bool Defined()
|
|
{
|
|
return( Function != NULL );
|
|
}
|
|
|
|
inline operator bool() { return( Function != NULL ); }
|
|
inline bool operator!() { return( !Function ); }
|
|
inline bool operator==( const CScriptObject& compare ) { return( Function == compare.Function ); }
|
|
|
|
// JSObject wrapping the function if it's defined, NULL if it isn't.
|
|
JSObject* GetFunctionObject();
|
|
|
|
// Executes a script attached to a JS object.
|
|
// Returns false if the script isn't defined, if the script can't be executed,
|
|
// otherwise true. Script return value is in rval.
|
|
bool Run( JSObject* Context, jsval* rval, uintN argc = 0, jsval* argv = NULL );
|
|
// This variant casts script return value to a boolean, and passes it back.
|
|
bool Run( JSObject* Context, uintN argc = 0, jsval* argv = NULL );
|
|
|
|
// Treat this as an event handler and dispatch an event to it.
|
|
bool DispatchEvent( JSObject* Context, CScriptEvent* evt );
|
|
};
|
|
|
|
#endif
|