Oolite
Loading...
Searching...
No Matches
OOJSWaypoint.m File Reference
Include dependency graph for OOJSWaypoint.m:

Go to the source code of this file.

Enumerations

enum  { kWaypoint_beaconCode , kWaypoint_beaconLabel , kWaypoint_orientation , kWaypoint_size }

Functions

static BOOL JSWaypointGetWaypointEntity (JSContext *context, JSValueConst waypointObj, OOWaypointEntity **outEntity)
static JSValue WaypointGetProperty (OOJS_GETTER_ARGS)
static JSValue WaypointSetProperty (OOJS_SETTER_ARGS)
void InitOOJSWaypoint (JSContext *context, JSValueConst global)
JSClassID JSWaypointClassID (void)

Variables

static JSClassID sWaypointClassID
static JSClassDef sWaypointClass
static const JSCFunctionListEntry sWaypointProperties []

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kWaypoint_beaconCode 
kWaypoint_beaconLabel 
kWaypoint_orientation 
kWaypoint_size 

Definition at line 45 of file OOJSWaypoint.m.

45 {
46 // Property IDs
49 kWaypoint_orientation, // overrides entity as waypoints can be unoriented
51};
@ kWaypoint_beaconCode
@ kWaypoint_size
@ kWaypoint_beaconLabel
@ kWaypoint_orientation

Function Documentation

◆ InitOOJSWaypoint()

void InitOOJSWaypoint ( JSContext * context,
JSValueConst global )

Definition at line 63 of file OOJSWaypoint.m.

64{
66
67 JSValue parentPrototype = JS_GetClassProto(context, JSEntityClassID());
68 NSCAssert(JS_IsObject(parentPrototype), @"Entity must be initialized before Waypoint.");
69 OOJSInitClass(context, global, sWaypointClassID, parentPrototype, OOJSUnconstructableConstruct, 0,
71 JS_FreeValue(context, parentPrototype);
72
75}
static JSPropertySpec sWaypointProperties[]
static JSClass sWaypointClass
void OOJSRegisterObjectConverter(JSClass *theClass, OOJSClassConverterCallback converter)
JSBool OOJSUnconstructableConstruct(JSContext *context, uintN argc, jsval *vp)
void OOJSRegisterSubclass(JSClass *subclass, JSClass *superclass)
id OOJSBasicPrivateObjectConverter(JSContext *context, JSObject *object)
JSClassID JSEntityClassID(void)
Definition OOJSEntity.m:115
static JSClassID sWaypointClassID
JSClassID OOJSRegisterClass(JSClassID *ioClassID, const JSClassDef *classDef)
Definition OOJSClasses.m:61
JSValueConst OOJSInitClass(JSContext *context, JSValueConst global, JSClassID classID, JSValueConst parentPrototype, JSCFunction *constructor, int constructorArgCount, const JSCFunctionListEntry *properties, size_t propertyCount, const JSCFunctionListEntry *methods, size_t methodCount, const JSCFunctionListEntry *staticMethods, size_t staticMethodCount)
#define OOJS_COUNT(array)

References JSEntityClassID(), OOJS_COUNT, OOJSBasicPrivateObjectConverter(), OOJSInitClass(), OOJSRegisterClass(), OOJSRegisterObjectConverter(), OOJSRegisterSubclass(), OOJSUnconstructableConstruct(), sWaypointClass, sWaypointClassID, and sWaypointProperties.

Here is the call graph for this function:

◆ JSWaypointClassID()

JSClassID JSWaypointClassID ( void )

Definition at line 77 of file OOJSWaypoint.m.

78{
79 return sWaypointClassID;
80}

References sWaypointClassID.

◆ JSWaypointGetWaypointEntity()

BOOL JSWaypointGetWaypointEntity ( JSContext * context,
JSValueConst waypointObj,
OOWaypointEntity ** outEntity )
static

Definition at line 82 of file OOJSWaypoint.m.

83{
85
86 BOOL result;
87 Entity* entity = nil;
88
89 if (outEntity == NULL)
90 return NO;
91 *outEntity = nil;
92
93 result = OOJSEntityGetEntity(context, waypointObj, &entity);
94 if (!result)
95 return NO;
96
97 if (![entity isKindOfClass:[OOWaypointEntity class]])
98 return NO;
99
100 *outEntity = (OOWaypointEntity*)entity;
101 return YES;
102
104}
#define OOJS_PROFILE_EXIT
#define OOJS_PROFILE_ENTER
return nil

References nil, OOJS_PROFILE_ENTER, and OOJS_PROFILE_EXIT.

◆ WaypointGetProperty()

JSValue WaypointGetProperty ( OOJS_GETTER_ARGS )
static

Definition at line 125 of file OOJSWaypoint.m.

126{
127 OOJS_NATIVE_ENTER(context)
128
129 OOWaypointEntity* entity = nil;
130 id result = nil;
132
133 if (!JSWaypointGetWaypointEntity(context, this, &entity))
134 return OOJSNativeFailure(context);
135 if (entity == nil) {
136 return JS_UNDEFINED;
137 }
138
139 switch (magic) {
141 result = [entity beaconCode];
142 break;
143
145 result = [entity beaconLabel];
146 break;
147
149 q = [entity orientation];
150 if (![entity oriented]) {
151 q = kZeroQuaternion;
152 }
154
155 case kWaypoint_size:
156 return JS_NewNumber(context, [entity size]);
157
158 default:
160 return OOJSNativeFailure(context);
161 }
162
163 return OOJSValueFromNativeObject(context, result);
164
166}
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_NATIVE_EXIT
static BOOL JSWaypointGetWaypointEntity(JSContext *context, JSObject *stationObj, OOWaypointEntity **outEntity)
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
#define OOJS_RETURN_QUATERNION(value)
const Quaternion kIdentityQuaternion
const Quaternion kZeroQuaternion
JSValue OOJSNativeFailure(JSContext *context)
Quaternion orientation
Definition Entity.m:682
voidpf void uLong size
Definition ioapi.h:126

References OOWaypointEntity::beaconCode, OOWaypointEntity::beaconLabel, JSWaypointGetWaypointEntity(), kIdentityQuaternion, kWaypoint_beaconCode, kWaypoint_beaconLabel, kWaypoint_orientation, kWaypoint_size, kZeroQuaternion, nil, OOJS_COUNT, OOJS_GETTER_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_QUATERNION, OOJSNativeFailure(), OOJSReportBadPropertySelector(), OOJSValueFromNativeObject(), Entity::orientation, and sWaypointProperties.

Here is the call graph for this function:

◆ WaypointSetProperty()

JSValue WaypointSetProperty ( OOJS_SETTER_ARGS )
static

Definition at line 168 of file OOJSWaypoint.m.

169{
170 OOJS_NATIVE_ENTER(context)
171
172 OOWaypointEntity* entity = nil;
173 double fValue;
174 NSString* sValue = nil;
175 Quaternion qValue;
176
177 if (!JSWaypointGetWaypointEntity(context, this, &entity))
178 return OOJSNativeFailure(context);
179 if (entity == nil)
180 return JS_UNDEFINED;
181
182 switch (magic) {
184 sValue = OOStringFromJSValue(context, value);
185 if (sValue == nil || [sValue length] == 0) {
186 if ([entity isBeacon]) {
187 [UNIVERSE clearBeacon:entity];
188 if ([PLAYER nextBeacon] == entity) {
189 [PLAYER setCompassMode:COMPASS_MODE_PLANET];
190 }
191 }
192 } else {
193 if ([entity isBeacon]) {
194 [entity setBeaconCode:sValue];
195 } else // Universe needs to update beacon lists in this case only
196 {
197 [entity setBeaconCode:sValue];
198 [UNIVERSE setNextBeacon:entity];
199 }
200 }
201 return JS_UNDEFINED;
202 break;
203
205 sValue = OOStringFromJSValue(context, value);
206 if (sValue != nil) {
207 [entity setBeaconLabel:sValue];
208 return JS_UNDEFINED;
209 }
210 break;
211
213 if (JSValueToQuaternion(context, value, &qValue)) {
214 [entity setNormalOrientation:qValue];
215 return JS_UNDEFINED;
216 }
217 break;
218
219 case kWaypoint_size:
220 if (JS_ToFloat64(context, &fValue, value) == 0) {
221 if (fValue > 0.0) {
222 [entity setSize:fValue];
223 return JS_UNDEFINED;
224 }
225 }
226 break;
227
228 default:
230 return OOJSNativeFailure(context);
231 }
232
234 return OOJSNativeFailure(context);
235
237}
BOOL JSValueToQuaternion(JSContext *context, jsval value, Quaternion *outQuaternion) NONNULL_FUNC
NSString * OOStringFromJSValue(JSContext *context, jsval value)
void OOJSReportBadPropertyValue(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec, jsval value)
#define PLAYER
void setNormalOrientation:(Quaternion quat)
Definition Entity.m:692
void setBeaconLabel:(NSString *blabel)
void setBeaconCode:(NSString *bcode)
void setSize:(OOScalar newSize)

References JSValueToQuaternion(), JSWaypointGetWaypointEntity(), kWaypoint_beaconCode, kWaypoint_beaconLabel, kWaypoint_orientation, kWaypoint_size, nil, OOJS_COUNT, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_SETTER_ARGS, OOJSNativeFailure(), OOJSReportBadPropertySelector(), OOJSReportBadPropertyValue(), OOStringFromJSValue(), PLAYER, OOWaypointEntity::setBeaconCode:, OOWaypointEntity::setBeaconLabel:, Entity::setNormalOrientation:, OOWaypointEntity::setSize:, and sWaypointProperties.

Here is the call graph for this function:

Variable Documentation

◆ sWaypointClass

JSClassDef sWaypointClass
static
Initial value:
= {
.class_name = "Waypoint",
}
void OOJSObjectWrapperFinalize(JSContext *context, JSObject *this)

Definition at line 40 of file OOJSWaypoint.m.

40 {
41 .class_name = "Waypoint",
42 .finalizer = OOJSObjectWrapperFinalize,
43};

◆ sWaypointClassID

JSClassID sWaypointClassID
static

◆ sWaypointProperties

const JSCFunctionListEntry sWaypointProperties[]
static
Initial value:
= {
}
static JSBool WaypointSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
static JSBool WaypointGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
#define OOJS_PROPERTY_RW(name, getter, setter, magic)

Definition at line 53 of file OOJSWaypoint.m.