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

Go to the source code of this file.

Macros

#define GET_THIS_FLASHER(THISENT)

Enumerations

enum  {
  kFlasher_active , kFlasher_color , kFlasher_fraction , kFlasher_frequency ,
  kFlasher_phase , kFlasher_size
}

Functions

static BOOL JSFlasherGetFlasherEntity (JSContext *context, JSObject *jsobj, OOFlasherEntity **outEntity)
static JSBool FlasherGetProperty (JSContext *context, JSObject *this, jsid propID, jsval *value)
static JSBool FlasherSetProperty (JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
static JSBool FlasherRemove (JSContext *context, uintN argc, jsval *vp)
void InitOOJSFlasher (JSContext *context, JSObject *global)

Variables

static JSObject * sFlasherPrototype
static JSClass sFlasherClass
static JSPropertySpec sFlasherProperties []
static JSFunctionSpec sFlasherMethods []

Macro Definition Documentation

◆ GET_THIS_FLASHER

#define GET_THIS_FLASHER ( THISENT)
Value:
do { \
if (EXPECT_NOT(!JSFlasherGetFlasherEntity(context, OOJS_THIS, &THISENT))) \
return NO; /* Exception */ \
if (OOIsStaleEntity(THISENT)) \
} while (0)
#define EXPECT_NOT(x)
OOINLINE BOOL OOIsStaleEntity(Entity *entity)
Definition OOJSEntity.h:69
static BOOL JSFlasherGetFlasherEntity(JSContext *context, JSObject *jsobj, OOFlasherEntity **outEntity)
Definition OOJSFlasher.m:92
#define OOJS_THIS
#define OOJS_RETURN_VOID

Definition at line 265 of file OOJSFlasher.m.

265#define GET_THIS_FLASHER(THISENT) \
266 do { \
267 if (EXPECT_NOT(!JSFlasherGetFlasherEntity(context, OOJS_THIS, &THISENT))) \
268 return NO; /* Exception */ \
269 if (OOIsStaleEntity(THISENT)) \
270 OOJS_RETURN_VOID; \
271 } while (0)

Referenced by FlasherRemove(), and FlasherRemove().

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kFlasher_active 
kFlasher_color 
kFlasher_fraction 
kFlasher_frequency 
kFlasher_phase 
kFlasher_size 

Definition at line 57 of file OOJSFlasher.m.

57 {
58 // Property IDs
65};
@ kFlasher_size
Definition OOJSFlasher.m:64
@ kFlasher_phase
Definition OOJSFlasher.m:63
@ kFlasher_active
Definition OOJSFlasher.m:59
@ kFlasher_fraction
Definition OOJSFlasher.m:61
@ kFlasher_frequency
Definition OOJSFlasher.m:62
@ kFlasher_color
Definition OOJSFlasher.m:60

Function Documentation

◆ FlasherGetProperty()

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

Definition at line 136 of file OOJSFlasher.m.

137{
138 if (!JSID_IS_INT(propID))
139 return YES;
140
141 OOJS_NATIVE_ENTER(context)
142
143 OOFlasherEntity* entity = nil;
144 id result = nil;
145
146 if (!JSFlasherGetFlasherEntity(context, this, &entity))
147 return NO;
148 if (entity == nil) {
149 *value = JSVAL_VOID;
150 return YES;
151 }
152
153 switch (JSID_TO_INT(propID)) {
154 case kFlasher_active:
155 *value = OOJSValueFromBOOL([entity isActive]);
156 return YES;
157
158 case kFlasher_color:
159 result = [[entity color] normalizedArray];
160 break;
161
163 return JS_NewNumberValue(context, [entity frequency], value);
164
166 return JS_NewNumberValue(context, [entity fraction], value);
167
168 case kFlasher_phase:
169 return JS_NewNumberValue(context, [entity phase], value);
170
171 case kFlasher_size:
172 return JS_NewNumberValue(context, [entity diameter], value);
173
174 default:
176 return NO;
177 }
178
179 *value = OOJSValueFromNativeObject(context, result);
180 return YES;
181
183}
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_NATIVE_EXIT
static JSPropertySpec sFlasherProperties[]
Definition OOJSFlasher.m:67
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
NSArray * normalizedArray()
Definition OOColor.m:465

References OOFlasherEntity::color, JSFlasherGetFlasherEntity(), kFlasher_active, kFlasher_color, kFlasher_fraction, kFlasher_frequency, kFlasher_phase, kFlasher_size, nil, OOColor::normalizedArray, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSReportBadPropertySelector(), OOJSValueFromBOOL(), OOJSValueFromNativeObject(), and sFlasherProperties.

Here is the call graph for this function:

◆ FlasherRemove()

JSBool FlasherRemove ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 273 of file OOJSFlasher.m.

274{
275 OOJS_NATIVE_ENTER(context)
276
277 OOFlasherEntity* thisEnt = nil;
278 GET_THIS_FLASHER(thisEnt);
279
280 Entity* parent = [thisEnt owner];
281 if ([parent isShip]) {
282 [(ShipEntity*)parent removeFlasher:thisEnt];
283 } else {
285 }
286
288
290}
#define GET_THIS_FLASHER(THISENT)
id owner()
Definition Entity.m:548
void removeSubEntity:(Entity< OOSubEntity > *sub)
void removeFlasher:(OOFlasherEntity *flasher)

References GET_THIS_FLASHER, nil, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, Entity::owner, ShipEntity::removeFlasher:, and OOVisualEffectEntity::removeSubEntity:.

Here is the call graph for this function:

◆ FlasherSetProperty()

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

Definition at line 185 of file OOJSFlasher.m.

186{
187 if (!JSID_IS_INT(propID))
188 return YES;
189
190 OOJS_NATIVE_ENTER(context)
191
192 OOFlasherEntity* entity = nil;
193 jsdouble fValue;
194 JSBool bValue;
195 OOColor* colorForScript = nil;
196
197 if (!JSFlasherGetFlasherEntity(context, this, &entity))
198 return NO;
199 if (entity == nil)
200 return YES;
201
202 switch (JSID_TO_INT(propID)) {
203 case kFlasher_active:
204 if (JS_ValueToBoolean(context, *value, &bValue)) {
205 [entity setActive:bValue];
206 return YES;
207 }
208 break;
209
210 case kFlasher_color:
211 colorForScript = [OOColor colorWithDescription:OOJSNativeObjectFromJSValue(context, *value)];
212 if (colorForScript != nil || JSVAL_IS_NULL(*value)) {
213 [entity setColor:colorForScript];
214 return YES;
215 }
216 break;
217
219 if (JS_ValueToNumber(context, *value, &fValue)) {
220 if (fValue >= 0.0) {
221 [entity setFrequency:fValue];
222 return YES;
223 }
224 }
225 break;
226
228 if (JS_ValueToNumber(context, *value, &fValue)) {
229 if (fValue > 0.0 && fValue <= 1.0) {
230 [entity setFraction:fValue];
231 return YES;
232 }
233 }
234 break;
235
236 case kFlasher_phase:
237 if (JS_ValueToNumber(context, *value, &fValue)) {
238 [entity setPhase:fValue];
239 return YES;
240 }
241 break;
242
243 case kFlasher_size:
244 if (JS_ValueToNumber(context, *value, &fValue)) {
245 if (fValue > 0.0) {
246 [entity setDiameter:fValue];
247 return YES;
248 }
249 }
250 break;
251
252 default:
254 return NO;
255 }
256
257 OOJSReportBadPropertyValue(context, this, propID, sFlasherProperties, *value);
258 return NO;
259
261}
void OOJSReportBadPropertyValue(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec, jsval value)
OOColor * colorWithDescription:(id description)
Definition OOColor.m:135
void setPhase:(float phase)
void setFrequency:(float frequency)
void setActive:(BOOL active)
void setFraction:(float fraction)
void setColor:(OOColor *color)
void setDiameter:(float diameter)

References OOColor::colorWithDescription:, JSFlasherGetFlasherEntity(), kFlasher_active, kFlasher_color, kFlasher_fraction, kFlasher_frequency, kFlasher_phase, kFlasher_size, nil, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSReportBadPropertySelector(), OOJSReportBadPropertyValue(), OOFlasherEntity::setActive:, OOLightParticleEntity::setColor:, OOLightParticleEntity::setDiameter:, OOFlasherEntity::setFraction:, OOFlasherEntity::setFrequency:, OOFlasherEntity::setPhase:, and sFlasherProperties.

Here is the call graph for this function:

◆ InitOOJSFlasher()

void InitOOJSFlasher ( JSContext * context,
JSObject * global )

Definition at line 85 of file OOJSFlasher.m.

86{
90}
OOINLINE JSClass * JSEntityClass(void)
Definition OOJSEntity.h:42
OOINLINE JSObject * JSEntityPrototype(void)
Definition OOJSEntity.h:43
static JSObject * sFlasherPrototype
Definition OOJSFlasher.m:33
static JSFunctionSpec sFlasherMethods[]
Definition OOJSFlasher.m:78
static JSClass sFlasherClass
Definition OOJSFlasher.m:42
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 JSEntityClass(), JSEntityPrototype(), OOJSBasicPrivateObjectConverter(), OOJSRegisterObjectConverter(), OOJSRegisterSubclass(), OOJSUnconstructableConstruct(), sFlasherClass, sFlasherMethods, sFlasherProperties, and sFlasherPrototype.

Referenced by OOJavaScriptEngine(Private)::createMainThreadContext.

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

◆ JSFlasherGetFlasherEntity()

BOOL JSFlasherGetFlasherEntity ( JSContext * context,
JSObject * jsobj,
OOFlasherEntity ** outEntity )
static

Definition at line 92 of file OOJSFlasher.m.

93{
95
96 BOOL result;
97 Entity* entity = nil;
98
99 if (outEntity == NULL)
100 return NO;
101 *outEntity = nil;
102
103 result = OOJSEntityGetEntity(context, jsobj, &entity);
104 if (!result)
105 return NO;
106
107 if (![entity isKindOfClass:[OOFlasherEntity class]])
108 return NO;
109
110 *outEntity = (OOFlasherEntity*)entity;
111 return YES;
112
114}
#define OOJS_PROFILE_EXIT
#define OOJS_PROFILE_ENTER

References nil, OOJS_PROFILE_ENTER, and OOJS_PROFILE_EXIT.

Referenced by FlasherGetProperty(), FlasherGetProperty(), FlasherSetProperty(), and FlasherSetProperty().

Here is the caller graph for this function:

Variable Documentation

◆ sFlasherClass

JSClass sFlasherClass
static
Initial value:
= {
"Flasher",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
JSCLASS_NO_OPTIONAL_MEMBERS
}
static JSBool FlasherGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
static JSBool FlasherSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
void OOJSObjectWrapperFinalize(JSContext *context, JSObject *this)

Definition at line 42 of file OOJSFlasher.m.

42 {
43 "Flasher",
44 JSCLASS_HAS_PRIVATE,
45
46 JS_PropertyStub, // addProperty
47 JS_PropertyStub, // delProperty
48 FlasherGetProperty, // getProperty
49 FlasherSetProperty, // setProperty
50 JS_EnumerateStub, // enumerate
51 JS_ResolveStub, // resolve
52 JS_ConvertStub, // convert
53 OOJSObjectWrapperFinalize, // finalize
54 JSCLASS_NO_OPTIONAL_MEMBERS
55};

Referenced by OOFlasherEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, InitOOJSFlasher(), and InitOOJSFlasher().

◆ sFlasherMethods

JSFunctionSpec sFlasherMethods[]
static
Initial value:
= {
{ "remove", FlasherRemove, 0 },
{ 0 }
}
static JSBool FlasherRemove(JSContext *context, uintN argc, jsval *vp)

Definition at line 78 of file OOJSFlasher.m.

78 {
79 // JS name Function min args
80 { "remove", FlasherRemove, 0 },
81
82 { 0 }
83};

Referenced by InitOOJSFlasher(), and InitOOJSFlasher().

◆ sFlasherProperties

JSPropertySpec sFlasherProperties[]
static

◆ sFlasherPrototype

JSObject* sFlasherPrototype
static