Oolite
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, JSValueConst global)
void OOJSFrameCallbacksInvoke (OOTimeDelta delta)
void OOJSFrameCallbacksRemoveAll (void)

Function Documentation

◆ InitOOJSFrameCallbacks()

void InitOOJSFrameCallbacks ( JSContext * context,
JSValueConst global )

Definition at line 124 of file OOJSFrameCallbacks.m.

125{
126 JS_SetPropertyFunctionList(context, global, sFrameCallbackMethods, OOJS_COUNT(sFrameCallbackMethods));
127
128#if DEBUG_FCB_SIMPLE_TRACKING_IDS
129 sNextID = 1;
130#else
131 // Set randomish initial ID to catch bad habits.
132 sNextID = [[NSDate date] timeIntervalSinceReferenceDate];
133#endif
134}
static uint32 sNextID
static const JSCFunctionListEntry sFrameCallbackMethods[]
#define OOJS_COUNT(array)

References OOJS_COUNT, sFrameCallbackMethods, and sNextID.

◆ OOJSFrameCallbacksInvoke()

void OOJSFrameCallbacksInvoke ( OOTimeDelta delta)

Definition at line 127 of file OOJSFrameCallbacks.m.

128{
129 NSCAssert1(!sRunning, @"%s cannot be called while frame callbacks are running.", __PRETTY_FUNCTION__);
130
131 if (sCount != 0) {
132 const OOTimeDelta delta = inDeltaT * [UNIVERSE timeAccelerationFactor];
133 JSContext* context = OOJSAcquireContext();
134 jsval deltaVal, result;
135 NSUInteger i;
136
137 if (EXPECT(JS_NewNumberValue(context, delta, &deltaVal))) {
138 // Block mutations.
139 sRunning = YES;
140
141 /*
142 The watchdog timer only fires once per second in deployment builds,
143 but in testrelease builds at least we can keep them on a short leash.
144 */
146
147 for (i = 0; i < sCount; i++) {
148 // TODO: remove out of scope callbacks - post MNSR!
149 JS_CallFunctionValue(context, NULL, sCallbacks[i].callback, 1, &deltaVal, &result);
150 JS_ReportPendingException(context);
151 }
152
154 sRunning = NO;
155
156 if (EXPECT_NOT(sDeferredOps != NULL)) {
157 RunDeferredOperations(context);
159 }
160 }
161 OOJSRelinquishContext(context);
162 }
163}
#define DESTROY(x)
#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:193
#define UNIVERSE
Definition Universe.h:827

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

Here is the call graph for this function:

◆ OOJSFrameCallbacksRemoveAll()

void OOJSFrameCallbacksRemoveAll ( void )

Definition at line 165 of file OOJSFrameCallbacks.m.

166{
167 NSCAssert1(!sRunning, @"%s cannot be called while frame callbacks are running.", __PRETTY_FUNCTION__);
168
169 if (sCount != 0) {
170 JSContext* context = OOJSAcquireContext();
171 while (sCount != 0)
172 RemoveCallbackAtIndex(context, sCount - 1);
173 OOJSRelinquishContext(context);
174 }
175}
static void RemoveCallbackAtIndex(JSContext *context, NSUInteger index)

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

Here is the call graph for this function: