Oolite 1.91.0.7645-241119-222d325
Loading...
Searching...
No Matches
OOJSVector.h File Reference
import <Foundation/Foundation.h>
#include <jsapi.h>
import "OOMaths.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 228 of file OOJSVector.m.

229{
231
232 JSObject *object = NULL;
233
234 assert(outValue != NULL);
235
236 object = JSVectorWithHPVector(context, vector);
237 if (EXPECT_NOT(object == NULL)) return NO;
238
239 *outValue = OBJECT_TO_JSVAL(object);
240 return YES;
241
243}
#define EXPECT_NOT(x)
#define OOJS_PROFILE_EXIT
#define OOJS_PROFILE_ENTER
JSObject * JSVectorWithHPVector(JSContext *context, HPVector vector)
Definition OOJSVector.m:202

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

Referenced by EntityGetProperty(), and ShipGetProperty().

+ 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 153 of file OOJSVector.m.

154{
155 sVectorPrototype = JS_InitClass(context, global, NULL, &sVectorClass, VectorConstruct, 0, sVectorProperties, sVectorMethods, NULL, sVectorStaticMethods);
156}
static JSPropertySpec sVectorProperties[]
Definition OOJSVector.m:104
static JSObject * sVectorPrototype
Definition OOJSVector.m:39
static JSFunctionSpec sVectorMethods[]
Definition OOJSVector.m:114
static JSFunctionSpec sVectorStaticMethods[]
Definition OOJSVector.m:140
static JSBool VectorConstruct(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:609
static JSClass sVectorClass
Definition OOJSVector.m:78

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

+ Here is the call 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 252 of file OOJSVector.m.

253{
254 if (EXPECT_NOT(!JSVAL_IS_OBJECT(value))) return NO;
255
256 return JSObjectGetVector(context, JSVAL_TO_OBJECT(value), outVector);
257}
BOOL JSObjectGetVector(JSContext *context, JSObject *vectorObj, HPVector *outVector)
Definition OOJSVector.m:330

References EXPECT_NOT, and JSObjectGetVector().

Referenced by EntitySetProperty(), ShipSetProperty(), 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 259 of file OOJSVector.m.

260{
261 if (EXPECT_NOT(!JSVAL_IS_OBJECT(value))) return NO;
262 HPVector tmp = kZeroHPVector;
263 BOOL result = JSObjectGetVector(context, JSVAL_TO_OBJECT(value), &tmp);
264 *outVector = HPVectorToVector(tmp);
265 return result;
266}
const HPVector kZeroHPVector
Definition OOHPVector.m:28

References EXPECT_NOT, JSObjectGetVector(), and kZeroHPVector.

Referenced by ExhaustPlumeSetProperty(), OOPlanetEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, MissionRunScreen(), PlayerShipSetCustomView(), PlayerShipSetProperty(), ShipSetProperty(), SoundSourceSetProperty(), SystemSetPopulator(), 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 426 of file OOJSVector.m.

427{
429
430 HPVector *private = NULL;
431
432 if (EXPECT_NOT(vectorObj == NULL)) return NO;
433
434 private = JS_GetInstancePrivate(context, vectorObj, &sVectorClass, NULL);
435 if (private != NULL) // If this is a (JS) Vector...
436 {
437 *private = vector;
438 return YES;
439 }
440
441 if (JS_InstanceOf(context, vectorObj, &sVectorClass, NULL))
442 {
443 // Silently fail for the prototype.
444 return YES;
445 }
446
447 return NO;
448
450}

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 420 of file OOJSVector.m.

421{
422 return JSVectorSetHPVector(context,vectorObj,vectorToHPVector(vector));
423}
BOOL JSVectorSetHPVector(JSContext *context, JSObject *vectorObj, HPVector vector)
Definition OOJSVector.m:426

References JSVectorSetHPVector().

+ Here is the call graph for this function:

◆ JSVectorWithHPVector()

JSObject * JSVectorWithHPVector ( JSContext * context,
HPVector vector )

Definition at line 202 of file OOJSVector.m.

203{
205
206 JSObject *result = NULL;
207 HPVector *private = NULL;
208
209 private = malloc(sizeof *private);
210 if (EXPECT_NOT(private == NULL)) return NULL;
211
212 *private = vector;
213
214 result = JS_NewObject(context, &sVectorClass, sVectorPrototype, NULL);
215 if (result != NULL)
216 {
217 if (EXPECT_NOT(!JS_SetPrivate(context, result, private))) result = NULL;
218 }
219
220 if (EXPECT_NOT(result == NULL)) free(private);
221
222 return result;
223
225}

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

Referenced by HPVectorToJSValue().

+ Here is the caller graph for this function:

◆ JSVectorWithVector()

JSObject * JSVectorWithVector ( JSContext * context,
Vector vector )

Definition at line 159 of file OOJSVector.m.

160{
162
163 JSObject *result = NULL;
164 HPVector *private = NULL;
165
166 private = malloc(sizeof *private);
167 if (EXPECT_NOT(private == NULL)) return NULL;
168
169 *private = vectorToHPVector(vector);
170
171 result = JS_NewObject(context, &sVectorClass, sVectorPrototype, NULL);
172 if (result != NULL)
173 {
174 if (EXPECT_NOT(!JS_SetPrivate(context, result, private))) result = NULL;
175 }
176
177 if (EXPECT_NOT(result == NULL)) free(private);
178
179 return result;
180
182}

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

Referenced by OOJSCallObjCObjectMethod(), and VectorToJSValue().

+ Here is the caller graph for this function:

◆ NSPointToVectorJSValue()

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

Definition at line 246 of file OOJSVector.m.

247{
248 return VectorToJSValue(context, make_vector(point.x, point.y, 0), outValue);
249}
BOOL VectorToJSValue(JSContext *context, Vector vector, jsval *outValue)
Definition OOJSVector.m:185

References VectorToJSValue().

Referenced by PlayerShipGetProperty(), 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(), 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 )

Referenced by SystemAddShipsOrGroup(), SystemAddVisualEffect(), SystemLegacyAddShipsAt(), SystemLegacyAddShipsAtPrecisely(), and SystemLegacyAddShipsWithinRadius().

+ Here is the caller graph for this function:

◆ VectorToJSValue()

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

Definition at line 185 of file OOJSVector.m.

186{
188
189 JSObject *object = NULL;
190
191 assert(outValue != NULL);
192
193 object = JSVectorWithVector(context, vector);
194 if (EXPECT_NOT(object == NULL)) return NO;
195
196 *outValue = OBJECT_TO_JSVAL(object);
197 return YES;
198
200}
JSObject * JSVectorWithVector(JSContext *context, Vector vector)
Definition OOJSVector.m:159

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

Referenced by EntityGetProperty(), ExhaustPlumeGetProperty(), NSPointToVectorJSValue(), PlanetGetProperty(), PlayerShipGetProperty(), ShipGetProperty(), SoundSourceGetProperty(), SystemInfoGetProperty(), and VisualEffectGetProperty().

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