Oolite
Loading...
Searching...
No Matches
OOJSPlanet.m File Reference
import "OOJSPlanet.h"
import "OOJSEntity.h"
import "OOJSQuaternion.h"
import "OOJSVector.h"
import "OOJavaScriptEngine.h"
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 JSBool PlanetGetProperty (JSContext *context, JSObject *this, jsid propID, jsval *value)
static JSBool PlanetSetProperty (JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
void InitOOJSPlanet (JSContext *context, JSObject *global)

Variables

static JSObject * sPlanetPrototype
static JSClass sPlanetClass
static JSPropertySpec 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 52 of file OOJSPlanet.m.

52 {
53 // Property IDs
54 kPlanet_airColor, // air color, read/write
55 kPlanet_airColorMixRatio, // air color mix ratio, float, read/write
56 kPlanet_airDensity, // air density, float, read/write
58 kPlanet_illuminationColor, // illumination color, read/write
59 kPlanet_isMainPlanet, // Is [UNIVERSE planet], boolean, read-only
60 kPlanet_name, // Name of planet, string, read/write
61 kPlanet_radius, // Radius of planet in metres, read-only
62 kPlanet_texture, // Planet texture read / write
63 kPlanet_orientation, // orientation, quaternion, read/write
64 kPlanet_rotationalVelocity, // read/write
66};
@ 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,
JSObject * global )

Definition at line 87 of file OOJSPlanet.m.

88{
89 sPlanetPrototype = JS_InitClass(context, global, JSEntityPrototype(), &sPlanetClass, OOJSUnconstructableConstruct, 0, sPlanetProperties, NULL, NULL, NULL);
92}
OOINLINE JSClass * JSEntityClass(void)
Definition OOJSEntity.h:42
OOINLINE JSObject * JSEntityPrototype(void)
Definition OOJSEntity.h:43
static JSClass sPlanetClass
Definition OOJSPlanet.m:37
static JSObject * sPlanetPrototype
Definition OOJSPlanet.m:32
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)

References InitOOJSPlanet(), JSEntityClass(), JSEntityPrototype(), OOJSBasicPrivateObjectConverter(), OOJSRegisterObjectConverter(), OOJSRegisterSubclass(), OOJSUnconstructableConstruct(), sPlanetClass, sPlanetProperties, and sPlanetPrototype.

Referenced by OOJavaScriptEngine(Private)::createMainThreadContext, InitOOJSPlanet(), and InitOOJSPlanet().

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

◆ PlanetGetProperty()

JSBool PlanetGetProperty ( JSContext * context,
JSObject * this,
jsid propID,
jsval * value )
static

Definition at line 122 of file OOJSPlanet.m.

123{
124 if (!JSID_IS_INT(propID))
125 return YES;
126
127 OOJS_NATIVE_ENTER(context)
128
129 OOPlanetEntity* planet = nil;
130 if (!JSPlanetGetPlanetEntity(context, this, &planet))
131 return NO;
132
133 switch (JSID_TO_INT(propID)) {
134 case kPlanet_airColor:
135 *value = OOJSValueFromNativeObject(context, [[planet airColor] normalizedArray]);
136 return YES;
137
139 return JS_NewNumberValue(context, [planet airColorMixRatio], value);
140
142 return JS_NewNumberValue(context, [planet airDensity], value);
143
145 *value = OOJSValueFromNativeObject(context, [[planet illuminationColor] normalizedArray]);
146 return YES;
147
149 *value = OOJSValueFromBOOL(planet == (id)[UNIVERSE planet]);
150 return YES;
151
152 case kPlanet_radius:
153 return JS_NewNumberValue(context, [planet radius], value);
154
156 *value = OOJSValueFromBOOL([planet hasAtmosphere]);
157 return YES;
158
159 case kPlanet_texture:
160 *value = OOJSValueFromNativeObject(context, [planet textureFileName]);
161 return YES;
162
163 case kPlanet_name:
164 *value = OOJSValueFromNativeObject(context, [planet name]);
165 return YES;
166
168 return QuaternionToJSValue(context, [planet normalOrientation], value);
169
171 return JS_NewNumberValue(context, [planet rotationalVelocity], value);
172
174 return VectorToJSValue(context, [planet terminatorThresholdVector], value);
175
176 default:
177 OOJSReportBadPropertySelector(context, this, propID, sPlanetProperties);
178 return NO;
179 }
180
182}
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_NATIVE_EXIT
BOOL QuaternionToJSValue(JSContext *context, Quaternion quaternion, jsval *outValue) NONNULL_FUNC
BOOL VectorToJSValue(JSContext *context, Vector vector, jsval *outValue) NONNULL_FUNC
Definition OOJSVector.m:264
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
OOINLINE jsval OOJSValueFromBOOL(int b) INLINE_CONST_FUNC
return nil
#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_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSReportBadPropertySelector(), OOJSValueFromBOOL(), OOJSValueFromNativeObject(), QuaternionToJSValue(), sPlanetProperties, UNIVERSE, and VectorToJSValue().

Here is the call graph for this function:

◆ PlanetSetProperty()

JSBool PlanetSetProperty ( JSContext * context,
JSObject * this,
jsid propID,
JSBool strict,
jsval * value )
static

Definition at line 184 of file OOJSPlanet.m.

185{
186 if (!JSID_IS_INT(propID))
187 return YES;
188
189 OOJS_NATIVE_ENTER(context)
190
191 OOPlanetEntity* planet = nil;
192 NSString* sValue = nil;
193 Quaternion qValue;
194 Vector vValue;
195 jsdouble dValue;
196 OOColor* colorForScript = nil;
197
198 if (!JSPlanetGetPlanetEntity(context, this, &planet))
199 return NO;
200
201 switch (JSID_TO_INT(propID)) {
202 case kPlanet_airColor:
203 colorForScript = [OOColor colorWithDescription:OOJSNativeObjectFromJSValue(context, *value)];
204 if (colorForScript != nil || JSVAL_IS_NULL(*value)) {
205 [planet setAirColor:colorForScript];
206 return YES;
207 }
208 break;
209
211 if (JS_ValueToNumber(context, *value, &dValue)) {
212 [planet setAirColorMixRatio:dValue];
213 return YES;
214 }
215 break;
216
218 if (JS_ValueToNumber(context, *value, &dValue)) {
219 [planet setAirDensity:dValue];
220 return YES;
221 }
222 break;
223
225 colorForScript = [OOColor colorWithDescription:OOJSNativeObjectFromJSValue(context, *value)];
226 if (colorForScript != nil || JSVAL_IS_NULL(*value)) {
227 [planet setIlluminationColor:colorForScript];
228 return YES;
229 }
230 break;
231
232 case kPlanet_name:
233 sValue = OOStringFromJSValue(context, *value);
234 [planet setName:sValue];
235 return YES;
236
237 case kPlanet_texture: {
238 BOOL OK = NO;
239 sValue = OOStringFromJSValue(context, *value);
240
242
243 if ([planet isKindOfClass:[OOPlanetEntity class]]) {
244 if (sValue == nil) {
245 OOJSReportWarning(context, @"Expected texture string. Value not set.");
246 } else {
247 OK = YES;
248 }
249 }
250
251 if (OK) {
252 OK = [planet setUpPlanetFromTexture:sValue];
253 if (!OK)
254 OOJSReportWarning(context, @"Cannot find texture \"%@\". Value not set.", sValue);
255 }
256
258
259 return YES; // Even if !OK, no exception was raised.
260 }
261
263 if (JSValueToQuaternion(context, *value, &qValue)) {
264 quaternion_normalize(&qValue);
265 [planet setOrientation:qValue];
266 return YES;
267 }
268 break;
269
271 if (JS_ValueToNumber(context, *value, &dValue)) {
272 [planet setRotationalVelocity:dValue];
273 return YES;
274 }
275 break;
276
278 if (JSValueToVector(context, *value, &vValue)) {
279 [planet setTerminatorThresholdVector:vValue];
280 return YES;
281 }
282 break;
283
284 default:
285 OOJSReportBadPropertySelector(context, this, propID, sPlanetProperties);
286 return NO;
287 }
288
289 OOJSReportBadPropertyValue(context, this, propID, sPlanetProperties, *value);
290 return NO;
291
293}
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_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSPauseTimeLimiter(), OOJSReportBadPropertySelector(), OOJSReportBadPropertyValue(), OOJSReportWarning(), OOJSResumeTimeLimiter(), OOStringFromJSValue(), quaternion_normalize(), and sPlanetProperties.

Here is the call graph for this function:

Variable Documentation

◆ sPlanetClass

JSClass sPlanetClass
static
Initial value:
= {
"Planet",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
JSCLASS_NO_OPTIONAL_MEMBERS
}
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
void OOJSObjectWrapperFinalize(JSContext *context, JSObject *this)

Definition at line 37 of file OOJSPlanet.m.

37 {
38 "Planet",
39 JSCLASS_HAS_PRIVATE,
40
41 JS_PropertyStub, // addProperty
42 JS_PropertyStub, // delProperty
43 PlanetGetProperty, // getProperty
44 PlanetSetProperty, // setProperty
45 JS_EnumerateStub, // enumerate
46 JS_ResolveStub, // resolve
47 JS_ConvertStub, // convert
48 OOJSObjectWrapperFinalize, // finalize
49 JSCLASS_NO_OPTIONAL_MEMBERS
50};

Referenced by OOPlanetEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, InitOOJSPlanet(), and InitOOJSPlanet().

◆ sPlanetProperties

JSPropertySpec sPlanetProperties[]
static
Initial value:

Definition at line 68 of file OOJSPlanet.m.

68 {
69 // JS name ID flags
71 { "airColorMixRatio", kPlanet_airColorMixRatio, OOJS_PROP_READWRITE_CB },
73 { "hasAtmosphere", kPlanet_hasAtmosphere, OOJS_PROP_READONLY_CB },
74 { "illuminationColor", kPlanet_illuminationColor, OOJS_PROP_READWRITE_CB },
78 { "rotationalVelocity", kPlanet_rotationalVelocity, OOJS_PROP_READWRITE_CB },
80 { "orientation", kPlanet_orientation, OOJS_PROP_READWRITE_CB }, // Not documented since it's inherited from Entity
81 { "terminatorThresholdVector", kPlanet_terminatorThresholdVector, OOJS_PROP_READWRITE_CB },
82 { 0 }
83};

Referenced by InitOOJSPlanet(), InitOOJSPlanet(), PlanetGetProperty(), PlanetGetProperty(), PlanetSetProperty(), and PlanetSetProperty().

◆ sPlanetPrototype

JSObject* sPlanetPrototype
static