Oolite
Loading...
Searching...
No Matches
OOJSVector.h File Reference
import "OOMaths.h"
import <Foundation/Foundation.h>
#include <jsapi.h>
Include dependency graph for OOJSVector.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void InitOOJSVector (JSContext *context, JSObject *global)
JSObject * JSVectorWithVector (JSContext *context, Vector vector) NONNULL_FUNC
JSObject * JSVectorWithHPVector (JSContext *context, HPVector vector) NONNULL_FUNC
BOOL VectorToJSValue (JSContext *context, Vector vector, jsval *outValue) NONNULL_FUNC
BOOL HPVectorToJSValue (JSContext *context, HPVector vector, jsval *outValue) NONNULL_FUNC
BOOL NSPointToVectorJSValue (JSContext *context, NSPoint point, jsval *outValue) NONNULL_FUNC
BOOL JSValueToVector (JSContext *context, jsval value, Vector *outVector) NONNULL_FUNC
BOOL JSValueToHPVector (JSContext *context, jsval value, HPVector *outVector) NONNULL_FUNC
BOOL JSObjectGetVector (JSContext *context, JSObject *vectorObj, HPVector *outVector) GCC_ATTR((nonnull(1
BOOL BOOL JSVectorSetVector (JSContext *context, JSObject *vectorObj, Vector vector) GCC_ATTR((nonnull(1)))
BOOL JSVectorSetHPVector (JSContext *context, JSObject *vectorObj, HPVector vector) GCC_ATTR((nonnull(1)))
BOOL VectorFromArgumentList (JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, HPVector *outVector, uintN *outConsumed) GCC_ATTR((nonnull(1
BOOL BOOL VectorFromArgumentListNoError (JSContext *context, uintN argc, jsval *argv, HPVector *outVector, uintN *outConsumed) GCC_ATTR((nonnull(1

Function Documentation

◆ HPVectorToJSValue()

BOOL HPVectorToJSValue ( JSContext * context,
HPVector vector,
jsval * outValue )

Definition at line 310 of file OOJSVector.m.

311{
313
314 JSObject* object = NULL;
315
316 assert(outValue != NULL);
317
318 object = JSVectorWithHPVector(context, vector);
319 if (EXPECT_NOT(object == NULL))
320 return NO;
321
322 *outValue = OBJECT_TO_JSVAL(object);
323 return YES;
324
326}
#define EXPECT_NOT(x)
#define OOJS_PROFILE_EXIT
#define OOJS_PROFILE_ENTER
JSObject * JSVectorWithHPVector(JSContext *context, HPVector vector)
Definition OOJSVector.m:282

References EXPECT_NOT, JSVectorWithHPVector(), OOJS_PROFILE_ENTER, and OOJS_PROFILE_EXIT.

Referenced by EntityGetProperty(), ShipGetProperty(), and VectorToJSValue().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitOOJSVector()

void InitOOJSVector ( JSContext * context,
JSObject * global )

Definition at line 231 of file OOJSVector.m.

232{
233 sVectorPrototype = JS_InitClass(context, global, NULL, &sVectorClass, VectorConstruct, 0, sVectorProperties, sVectorMethods, NULL, sVectorStaticMethods);
234}
static JSPropertySpec sVectorProperties[]
Definition OOJSVector.m:96
static JSObject * sVectorPrototype
Definition OOJSVector.m:38
static JSFunctionSpec sVectorMethods[]
Definition OOJSVector.m:104
static JSFunctionSpec sVectorStaticMethods[]
Definition OOJSVector.m:204
static JSBool VectorConstruct(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:683
static JSClass sVectorClass
Definition OOJSVector.m:74

References sVectorClass, sVectorMethods, sVectorProperties, sVectorPrototype, sVectorStaticMethods, and VectorConstruct().

Referenced by OOJavaScriptEngine(Private)::createMainThreadContext.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ JSObjectGetVector()

BOOL JSObjectGetVector ( JSContext * context,
JSObject * vectorObj,
HPVector * outVector )

Referenced by GetThisVector(), VectorFromArgumentListNoErrorInternal(), VectorGetProperty(), and VectorSetProperty().

Here is the caller graph for this function:

◆ JSValueToHPVector()

BOOL JSValueToHPVector ( JSContext * context,
jsval value,
HPVector * outVector )

Definition at line 333 of file OOJSVector.m.

334{
335 if (EXPECT_NOT(!JSVAL_IS_OBJECT(value)))
336 return NO;
337
338 return JSObjectGetVector(context, JSVAL_TO_OBJECT(value), outVector);
339}
BOOL JSObjectGetVector(JSContext *context, JSObject *vectorObj, HPVector *outVector)
Definition OOJSVector.m:415

References EXPECT_NOT, and JSObjectGetVector().

Referenced by EntitySetProperty(), EntitySetProperty(), ShipSetProperty(), ShipSetProperty(), SystemSetWaypoint(), and SystemSetWaypoint().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ JSValueToVector()

BOOL JSValueToVector ( JSContext * context,
jsval value,
Vector * outVector )

Definition at line 341 of file OOJSVector.m.

342{
343 if (EXPECT_NOT(!JSVAL_IS_OBJECT(value)))
344 return NO;
346 BOOL result = JSObjectGetVector(context, JSVAL_TO_OBJECT(value), &tmp);
347 *outVector = HPVectorToVector(tmp);
348 return result;
349}
const HPVector kZeroHPVector
Definition OOHPVector.m:27
OOINLINE Vector HPVectorToVector(HPVector v) INLINE_CONST_FUNC
Definition OOHPVector.h:175

References EXPECT_NOT, HPVectorToVector(), JSObjectGetVector(), and kZeroHPVector.

Referenced by ExhaustPlumeSetProperty(), ExhaustPlumeSetProperty(), MissionRunScreen(), MissionRunScreen(), PlanetSetProperty(), PlanetSetProperty(), PlayerShipSetCustomView(), PlayerShipSetCustomView(), PlayerShipSetProperty(), PlayerShipSetProperty(), ShipEntity(Private)::refreshEscortPositions, ShipSetProperty(), ShipSetProperty(), SoundSourceSetProperty(), SoundSourceSetProperty(), SystemSetPopulator(), SystemSetPopulator(), VisualEffectSetProperty(), and VisualEffectSetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ JSVectorSetHPVector()

BOOL JSVectorSetHPVector ( JSContext * context,
JSObject * vectorObj,
HPVector vector )

Definition at line 498 of file OOJSVector.m.

499{
501
502 HPVector* private = NULL;
503
504 if (EXPECT_NOT(vectorObj == NULL))
505 return NO;
506
507private
508 = JS_GetInstancePrivate(context, vectorObj, &sVectorClass, NULL);
509 if (private != NULL) // If this is a (JS) Vector...
510 {
511 *private = vector;
512 return YES;
513 }
514
515 if (JS_InstanceOf(context, vectorObj, &sVectorClass, NULL)) {
516 // Silently fail for the prototype.
517 return YES;
518 }
519
520 return NO;
521
523}

References EXPECT_NOT, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and sVectorClass.

Referenced by JSVectorSetVector(), and VectorSetProperty().

Here is the caller graph for this function:

◆ JSVectorSetVector()

BOOL BOOL JSVectorSetVector ( JSContext * context,
JSObject * vectorObj,
Vector vector )

Definition at line 493 of file OOJSVector.m.

494{
495 return JSVectorSetHPVector(context, vectorObj, vectorToHPVector(vector));
496}
OOINLINE HPVector vectorToHPVector(Vector v) INLINE_CONST_FUNC
Definition OOHPVector.h:166
BOOL JSVectorSetHPVector(JSContext *context, JSValueConst vectorObj, HPVector vector)
Definition OOJSVector.m:309

References JSVectorSetHPVector(), and vectorToHPVector().

Here is the call graph for this function:

◆ JSVectorWithHPVector()

JSObject * JSVectorWithHPVector ( JSContext * context,
HPVector vector )

Definition at line 282 of file OOJSVector.m.

283{
285
286 JSObject* result = NULL;
287 HPVector* private = NULL;
288
289private
290 = malloc(sizeof *private);
291 if (EXPECT_NOT(private == NULL))
292 return NULL;
293
294 *private = vector;
295
296 result = JS_NewObject(context, &sVectorClass, sVectorPrototype, NULL);
297 if (result != NULL) {
298 if (EXPECT_NOT(!JS_SetPrivate(context, result, private)))
299 result = NULL;
300 }
301
302 if (EXPECT_NOT(result == NULL))
303 free(private);
304
305 return result;
306
308}

References EXPECT_NOT, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, sVectorClass, and sVectorPrototype.

◆ JSVectorWithVector()

JSObject * JSVectorWithVector ( JSContext * context,
Vector vector )

Definition at line 236 of file OOJSVector.m.

237{
239
240 JSObject* result = NULL;
241 HPVector* private = NULL;
242
243private
244 = malloc(sizeof *private);
245 if (EXPECT_NOT(private == NULL))
246 return NULL;
247
248 *private = vectorToHPVector(vector);
249
250 result = JS_NewObject(context, &sVectorClass, sVectorPrototype, NULL);
251 if (result != NULL) {
252 if (EXPECT_NOT(!JS_SetPrivate(context, result, private)))
253 result = NULL;
254 }
255
256 if (EXPECT_NOT(result == NULL))
257 free(private);
258
259 return result;
260
262}

References EXPECT_NOT, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, sVectorClass, sVectorPrototype, and vectorToHPVector().

Here is the call graph for this function:

◆ NSPointToVectorJSValue()

BOOL NSPointToVectorJSValue ( JSContext * context,
NSPoint point,
jsval * outValue )

Definition at line 328 of file OOJSVector.m.

329{
330 return VectorToJSValue(context, make_vector(point.x, point.y, 0), outValue);
331}
BOOL VectorToJSValue(JSContext *context, Vector vector, jsval *outValue)
Definition OOJSVector.m:264
OOINLINE Vector make_vector(OOScalar vx, OOScalar vy, OOScalar vz) INLINE_CONST_FUNC
Definition OOVector.h:149

References make_vector(), and VectorToJSValue().

Referenced by PlayerShipGetProperty(), PlayerShipGetProperty(), SystemInfoGetProperty(), and SystemInfoGetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ VectorFromArgumentList()

BOOL VectorFromArgumentList ( JSContext * context,
NSString * scriptClass,
NSString * function,
uintN argc,
jsval * argv,
HPVector * outVector,
uintN * outConsumed )

Referenced by QuaternionRotate(), QuaternionRotate(), VectorAdd(), VectorAngleTo(), VectorCross(), VectorDistanceTo(), VectorDot(), VectorRotationTo(), VectorSquaredDistanceTo(), VectorStaticInterpolate(), VectorSubtract(), and VectorTripleProduct().

Here is the caller graph for this function:

◆ VectorFromArgumentListNoError()

BOOL BOOL VectorFromArgumentListNoError ( JSContext * context,
uintN argc,
jsval * argv,
HPVector * outVector,
uintN * outConsumed )

◆ VectorToJSValue()

BOOL VectorToJSValue ( JSContext * context,
Vector vector,
jsval * outValue )

Definition at line 264 of file OOJSVector.m.

265{
267
268 JSObject* object = NULL;
269
270 assert(outValue != NULL);
271
272 object = JSVectorWithVector(context, vector);
273 if (EXPECT_NOT(object == NULL))
274 return NO;
275
276 *outValue = OBJECT_TO_JSVAL(object);
277 return YES;
278
280}
JSObject * JSVectorWithVector(JSContext *context, Vector vector)
Definition OOJSVector.m:236

References EXPECT_NOT, JSVectorWithVector(), OOJS_PROFILE_ENTER, and OOJS_PROFILE_EXIT.

Referenced by EntityGetProperty(), ExhaustPlumeGetProperty(), NSPointToVectorJSValue(), NSPointToVectorJSValue(), OONativeVector(OOJavaScriptConversion)::oo_jsValueInContext:, PlanetGetProperty(), PlayerShipGetProperty(), OOJSPopulatorDefinition::runCallback:, ShipGetProperty(), SoundSourceGetProperty(), SystemInfoGetProperty(), and VisualEffectGetProperty().

Here is the call graph for this function:
Here is the caller graph for this function: