Oolite 1.91.0.7646-241128-10e222e
Loading...
Searching...
No Matches
OOJSFrameCallbacks.h File Reference
+ Include dependency graph for OOJSFrameCallbacks.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void InitOOJSFrameCallbacks (JSContext *context, JSObject *global)
 
void OOJSFrameCallbacksInvoke (OOTimeDelta delta)
 
void OOJSFrameCallbacksRemoveAll (void)
 

Function Documentation

◆ InitOOJSFrameCallbacks()

void InitOOJSFrameCallbacks ( JSContext * context,
JSObject * global )

Definition at line 117 of file OOJSFrameCallbacks.m.

118{
119 JS_DefineFunction(context, global, "addFrameCallback", GlobalAddFrameCallback, 1, OOJS_METHOD_READONLY);
120 JS_DefineFunction(context, global, "removeFrameCallback", GlobalRemoveFrameCallback, 1, OOJS_METHOD_READONLY);
121 JS_DefineFunction(context, global, "isValidFrameCallback", GlobalIsValidFrameCallback, 1, OOJS_METHOD_READONLY);
122
123#if DEBUG_FCB_SIMPLE_TRACKING_IDS
124 sNextID = 1;
125#else
126 // Set randomish initial ID to catch bad habits.
127 sNextID = [[NSDate date] timeIntervalSinceReferenceDate];
128#endif
129}
static JSBool GlobalAddFrameCallback(JSContext *context, uintN argc, jsval *vp)
static uint32 sNextID
static JSBool GlobalRemoveFrameCallback(JSContext *context, uintN argc, jsval *vp)
static JSBool GlobalIsValidFrameCallback(JSContext *context, uintN argc, jsval *vp)
#define OOJS_METHOD_READONLY

References GlobalAddFrameCallback(), GlobalIsValidFrameCallback(), GlobalRemoveFrameCallback(), OOJS_METHOD_READONLY, and sNextID.

+ Here is the call graph for this function:

◆ OOJSFrameCallbacksInvoke()

void OOJSFrameCallbacksInvoke ( OOTimeDelta delta)

Definition at line 132 of file OOJSFrameCallbacks.m.

133{
134 NSCAssert1(!sRunning, @"%s cannot be called while frame callbacks are running.", __PRETTY_FUNCTION__);
135
136 if (sCount != 0)
137 {
138 const OOTimeDelta delta = inDeltaT * [UNIVERSE timeAccelerationFactor];
139 JSContext *context = OOJSAcquireContext();
140 jsval deltaVal, result;
141 NSUInteger i;
142
143 if (EXPECT(JS_NewNumberValue(context, delta, &deltaVal)))
144 {
145 // Block mutations.
146 sRunning = YES;
147
148 /*
149 The watchdog timer only fires once per second in deployment builds,
150 but in testrelease builds at least we can keep them on a short leash.
151 */
153
154 for (i = 0; i < sCount; i++)
155 {
156 // TODO: remove out of scope callbacks - post MNSR!
157 JS_CallFunctionValue(context, NULL, sCallbacks[i].callback, 1, &deltaVal, &result);
158 JS_ReportPendingException(context);
159 }
160
162 sRunning = NO;
163
164 if (EXPECT_NOT(sDeferredOps != NULL))
165 {
166 RunDeferredOperations(context);
168 }
169 }
170 OOJSRelinquishContext(context);
171 }
172}
#define DESTROY(x)
Definition OOCocoa.h:77
#define EXPECT_NOT(x)
#define EXPECT(x)
#define OOJSStopTimeLimiter()
#define OOJSStartTimeLimiterWithTimeLimit(limit)
static NSUInteger sCount
static BOOL sRunning
static CallbackEntry * sCallbacks
static void RunDeferredOperations(JSContext *context)
static NSMutableArray * sDeferredOps
OOINLINE JSContext * OOJSAcquireContext(void)
OOINLINE void OOJSRelinquishContext(JSContext *context)
double OOTimeDelta
Definition OOTypes.h:224
#define UNIVERSE
Definition Universe.h:840

References DESTROY, EXPECT, EXPECT_NOT, OOJSAcquireContext(), OOJSRelinquishContext(), OOJSStartTimeLimiterWithTimeLimit, OOJSStopTimeLimiter, RunDeferredOperations(), sCallbacks, sCount, sDeferredOps, and sRunning.

+ Here is the call graph for this function:

◆ OOJSFrameCallbacksRemoveAll()

void OOJSFrameCallbacksRemoveAll ( void )

Definition at line 175 of file OOJSFrameCallbacks.m.

176{
177 NSCAssert1(!sRunning, @"%s cannot be called while frame callbacks are running.", __PRETTY_FUNCTION__);
178
179 if (sCount != 0)
180 {
181 JSContext *context = OOJSAcquireContext();
182 while (sCount != 0) RemoveCallbackAtIndex(context, sCount - 1);
183 OOJSRelinquishContext(context);
184 }
185}
static void RemoveCallbackAtIndex(JSContext *context, NSUInteger index)

References OOJSAcquireContext(), OOJSRelinquishContext(), RemoveCallbackAtIndex(), sCount, and sRunning.

+ Here is the call graph for this function: