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

Go to the source code of this file.

Enumerations

enum  {
  kPlanet_airColor , kPlanet_airColorMixRatio , kPlanet_airDensity , kPlanet_hasAtmosphere ,
  kPlanet_illuminationColor , kPlanet_isMainPlanet , kPlanet_name , kPlanet_radius ,
  kPlanet_texture , kPlanet_orientation , kPlanet_rotationalVelocity , kPlanet_terminatorThresholdVector
}

Functions

static JSValue PlanetGetProperty (OOJS_GETTER_ARGS)
static JSValue PlanetSetProperty (OOJS_SETTER_ARGS)
void InitOOJSPlanet (JSContext *context, JSValueConst global)
JSClassID JSPlanetClassID (void)

Variables

static JSClassID sPlanetClassID
static JSClassDef sPlanetClass
static const JSCFunctionListEntry sPlanetProperties []

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kPlanet_airColor 
kPlanet_airColorMixRatio 
kPlanet_airDensity 
kPlanet_hasAtmosphere 
kPlanet_illuminationColor 
kPlanet_isMainPlanet 
kPlanet_name 
kPlanet_radius 
kPlanet_texture 
kPlanet_orientation 
kPlanet_rotationalVelocity 
kPlanet_terminatorThresholdVector 

Definition at line 44 of file OOJSPlanet.m.

44 {
45 // Property IDs
46 kPlanet_airColor, // air color, read/write
47 kPlanet_airColorMixRatio, // air color mix ratio, float, read/write
48 kPlanet_airDensity, // air density, float, read/write
50 kPlanet_illuminationColor, // illumination color, read/write
51 kPlanet_isMainPlanet, // Is [UNIVERSE planet], boolean, read-only
52 kPlanet_name, // Name of planet, string, read/write
53 kPlanet_radius, // Radius of planet in metres, read-only
54 kPlanet_texture, // Planet texture read / write
55 kPlanet_orientation, // orientation, quaternion, read/write
56 kPlanet_rotationalVelocity, // read/write
58};
@ kPlanet_airColor
Definition OOJSPlanet.m:54
@ kPlanet_orientation
Definition OOJSPlanet.m:63
@ kPlanet_radius
Definition OOJSPlanet.m:61
@ kPlanet_airColorMixRatio
Definition OOJSPlanet.m:55
@ kPlanet_isMainPlanet
Definition OOJSPlanet.m:59
@ kPlanet_terminatorThresholdVector
Definition OOJSPlanet.m:65
@ kPlanet_airDensity
Definition OOJSPlanet.m:56
@ kPlanet_name
Definition OOJSPlanet.m:60
@ kPlanet_rotationalVelocity
Definition OOJSPlanet.m:64
@ kPlanet_hasAtmosphere
Definition OOJSPlanet.m:57
@ kPlanet_illuminationColor
Definition OOJSPlanet.m:58
@ kPlanet_texture
Definition OOJSPlanet.m:62

Function Documentation

◆ InitOOJSPlanet()

void InitOOJSPlanet ( JSContext * context,
JSValueConst global )

Definition at line 78 of file OOJSPlanet.m.

79{
81
82 JSValue parentPrototype = JS_GetClassProto(context, JSEntityClassID());
83 NSCAssert(JS_IsObject(parentPrototype), @"Entity must be initialized before Planet.");
84 OOJSInitClass(context, global, sPlanetClassID, parentPrototype, OOJSUnconstructableConstruct, 0,
86 JS_FreeValue(context, parentPrototype);
87
90}
static JSClass sPlanetClass
Definition OOJSPlanet.m:37
static JSPropertySpec sPlanetProperties[]
Definition OOJSPlanet.m:68
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 sPlanetClassID
Definition OOJSPlanet.m:34
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 InitOOJSPlanet(), JSEntityClassID(), OOJS_COUNT, OOJSBasicPrivateObjectConverter(), OOJSInitClass(), OOJSRegisterClass(), OOJSRegisterObjectConverter(), OOJSRegisterSubclass(), OOJSUnconstructableConstruct(), sPlanetClass, sPlanetClassID, and sPlanetProperties.

Here is the call graph for this function:

◆ JSPlanetClassID()

JSClassID JSPlanetClassID ( void )

Definition at line 92 of file OOJSPlanet.m.

93{
94 return sPlanetClassID;
95}

References sPlanetClassID.

◆ PlanetGetProperty()

JSValue PlanetGetProperty ( OOJS_GETTER_ARGS )
static

Definition at line 124 of file OOJSPlanet.m.

125{
126 OOJS_NATIVE_ENTER(context)
127
128 OOPlanetEntity* planet = nil;
129 if (!JSPlanetGetPlanetEntity(context, this, &planet))
130 return OOJSNativeFailure(context);
131
132 switch (magic) {
133 case kPlanet_airColor:
134 return OOJSValueFromNativeObject(context, [[planet airColor] normalizedArray]);
135
137 return JS_NewNumber(context, [planet airColorMixRatio]);
138
140 return JS_NewNumber(context, [planet airDensity]);
141
143 return OOJSValueFromNativeObject(context, [[planet illuminationColor] normalizedArray]);
144
146 return OOJSValueFromBOOL(planet == (id)[UNIVERSE planet]);
147
148 case kPlanet_radius:
149 return JS_NewNumber(context, [planet radius]);
150
152 return OOJSValueFromBOOL([planet hasAtmosphere]);
153
154 case kPlanet_texture:
155 return OOJSValueFromNativeObject(context, [planet textureFileName]);
156
157 case kPlanet_name:
158 return OOJSValueFromNativeObject(context, [planet name]);
159
161 OOJS_RETURN_QUATERNION([planet normalOrientation]);
162
164 return JS_NewNumber(context, [planet rotationalVelocity]);
165
167 OOJS_RETURN_VECTOR([planet terminatorThresholdVector]);
168
169 default:
171 return OOJSNativeFailure(context);
172 }
173
175}
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_NATIVE_EXIT
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
#define OOJS_RETURN_QUATERNION(value)
OOINLINE jsval OOJSValueFromBOOL(int b) INLINE_CONST_FUNC
#define OOJS_RETURN_VECTOR(value)
return nil
JSValue OOJSNativeFailure(JSContext *context)
#define UNIVERSE
Definition Universe.h:827

References kPlanet_airColor, kPlanet_airColorMixRatio, kPlanet_airDensity, kPlanet_hasAtmosphere, kPlanet_illuminationColor, kPlanet_isMainPlanet, kPlanet_name, kPlanet_orientation, kPlanet_radius, kPlanet_rotationalVelocity, kPlanet_terminatorThresholdVector, kPlanet_texture, nil, OOJS_COUNT, OOJS_GETTER_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_QUATERNION, OOJS_RETURN_VECTOR, OOJSNativeFailure(), OOJSReportBadPropertySelector(), OOJSValueFromBOOL(), OOJSValueFromNativeObject(), sPlanetProperties, and UNIVERSE.

Here is the call graph for this function:

◆ PlanetSetProperty()

JSValue PlanetSetProperty ( OOJS_SETTER_ARGS )
static

Definition at line 177 of file OOJSPlanet.m.

178{
179 OOJS_NATIVE_ENTER(context)
180
181 OOPlanetEntity* planet = nil;
182 NSString* sValue = nil;
183 Quaternion qValue;
184 Vector vValue;
185 double dValue;
186 OOColor* colorForScript = nil;
187
188 if (!JSPlanetGetPlanetEntity(context, this, &planet))
189 return OOJSNativeFailure(context);
190
191 switch (magic) {
192 case kPlanet_airColor:
193 colorForScript = [OOColor colorWithDescription:OOJSNativeObjectFromJSValue(context, value)];
194 if (colorForScript != nil || JS_IsNull(value)) {
195 [planet setAirColor:colorForScript];
196 return JS_UNDEFINED;
197 }
198 break;
199
201 if (JS_ToFloat64(context, &dValue, value) == 0) {
202 [planet setAirColorMixRatio:dValue];
203 return JS_UNDEFINED;
204 }
205 break;
206
208 if (JS_ToFloat64(context, &dValue, value) == 0) {
209 [planet setAirDensity:dValue];
210 return JS_UNDEFINED;
211 }
212 break;
213
215 colorForScript = [OOColor colorWithDescription:OOJSNativeObjectFromJSValue(context, value)];
216 if (colorForScript != nil || JS_IsNull(value)) {
217 [planet setIlluminationColor:colorForScript];
218 return JS_UNDEFINED;
219 }
220 break;
221
222 case kPlanet_name:
223 sValue = OOStringFromJSValue(context, value);
224 [planet setName:sValue];
225 return JS_UNDEFINED;
226
227 case kPlanet_texture: {
228 BOOL OK = NO;
229 sValue = OOStringFromJSValue(context, value);
230
232
233 if ([planet isKindOfClass:[OOPlanetEntity class]]) {
234 if (sValue == nil) {
235 OOJSReportWarning(context, @"Expected texture string. Value not set.");
236 } else {
237 OK = YES;
238 }
239 }
240
241 if (OK) {
242 OK = [planet setUpPlanetFromTexture:sValue];
243 if (!OK)
244 OOJSReportWarning(context, @"Cannot find texture \"%@\". Value not set.", sValue);
245 }
246
248
249 return JS_UNDEFINED; // Even if !OK, no exception was raised.
250 }
251
253 if (JSValueToQuaternion(context, value, &qValue)) {
254 quaternion_normalize(&qValue);
255 [planet setOrientation:qValue];
256 return JS_UNDEFINED;
257 }
258 break;
259
261 if (JS_ToFloat64(context, &dValue, value) == 0) {
262 [planet setRotationalVelocity:dValue];
263 return JS_UNDEFINED;
264 }
265 break;
266
268 if (JSValueToVector(context, value, &vValue)) {
269 [planet setTerminatorThresholdVector:vValue];
270 return JS_UNDEFINED;
271 }
272 break;
273
274 default:
276 return OOJSNativeFailure(context);
277 }
278
280 return OOJSNativeFailure(context);
281
283}
BOOL JSValueToQuaternion(JSContext *context, jsval value, Quaternion *outQuaternion) NONNULL_FUNC
BOOL JSValueToVector(JSContext *context, jsval value, Vector *outVector) NONNULL_FUNC
Definition OOJSVector.m:341
void OOJSPauseTimeLimiter(void)
void OOJSReportWarning(JSContext *context, NSString *format,...)
NSString * OOStringFromJSValue(JSContext *context, jsval value)
void OOJSReportBadPropertyValue(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec, jsval value)
void OOJSResumeTimeLimiter(void)
OOINLINE void quaternion_normalize(Quaternion *quat) NONNULL_FUNC ALWAYS_INLINE_FUNC
OOColor * colorWithDescription:(id description)
Definition OOColor.m:135

References OOColor::colorWithDescription:, JSValueToQuaternion(), JSValueToVector(), kPlanet_airColor, kPlanet_airColorMixRatio, kPlanet_airDensity, kPlanet_illuminationColor, kPlanet_name, kPlanet_orientation, kPlanet_rotationalVelocity, kPlanet_terminatorThresholdVector, kPlanet_texture, nil, OOJS_COUNT, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_SETTER_ARGS, OOJSNativeFailure(), OOJSPauseTimeLimiter(), OOJSReportBadPropertySelector(), OOJSReportBadPropertyValue(), OOJSReportWarning(), OOJSResumeTimeLimiter(), OOStringFromJSValue(), quaternion_normalize(), and sPlanetProperties.

Here is the call graph for this function:

Variable Documentation

◆ sPlanetClass

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

Definition at line 39 of file OOJSPlanet.m.

39 {
40 .class_name = "Planet",
41 .finalizer = OOJSObjectWrapperFinalize,
42};

◆ sPlanetClassID

JSClassID sPlanetClassID
static

◆ sPlanetProperties

const JSCFunctionListEntry sPlanetProperties[]
static
Initial value:
= {
}
static JSBool PlanetGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
Definition OOJSPlanet.m:122
static JSBool PlanetSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
Definition OOJSPlanet.m:184
#define OOJS_PROPERTY_RW(name, getter, setter, magic)
#define OOJS_PROPERTY_RO(name, getter, magic)

Definition at line 60 of file OOJSPlanet.m.