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, JSValueConst jsobj, OOFlasherEntity **outEntity)
static JSValue FlasherGetProperty (OOJS_GETTER_ARGS)
static JSValue FlasherSetProperty (OOJS_SETTER_ARGS)
static JSValue FlasherRemove (OOJS_NATIVE_ARGS)
void InitOOJSFlasher (JSContext *context, JSValueConst global)
JSClassID JSFlasherClassID (void)

Variables

static JSClassID sFlasherClassID
static JSClassDef sFlasherClass
static const JSCFunctionListEntry sFlasherProperties []
static const JSCFunctionListEntry sFlasherMethods []

Macro Definition Documentation

◆ GET_THIS_FLASHER

#define GET_THIS_FLASHER ( THISENT)
Value:
do { \
if (EXPECT_NOT(!JSFlasherGetFlasherEntity(context, OOJS_THIS, &THISENT))) \
return OOJSNativeFailure(context); /* 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
JSValue OOJSNativeFailure(JSContext *context)

Definition at line 254 of file OOJSFlasher.m.

254#define GET_THIS_FLASHER(THISENT) \
255 do { \
256 if (EXPECT_NOT(!JSFlasherGetFlasherEntity(context, OOJS_THIS, &THISENT))) \
257 return OOJSNativeFailure(context); /* Exception */ \
258 if (OOIsStaleEntity(THISENT)) \
259 OOJS_RETURN_VOID; \
260 } while (0)

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kFlasher_active 
kFlasher_color 
kFlasher_fraction 
kFlasher_frequency 
kFlasher_phase 
kFlasher_size 

Definition at line 47 of file OOJSFlasher.m.

47 {
48 // Property IDs
55};
@ 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()

JSValue FlasherGetProperty ( OOJS_GETTER_ARGS )
static

Definition at line 134 of file OOJSFlasher.m.

135{
136 OOJS_NATIVE_ENTER(context)
137
138 OOFlasherEntity* entity = nil;
139 id result = nil;
140
141 if (!JSFlasherGetFlasherEntity(context, this, &entity))
142 return OOJSNativeFailure(context);
143 if (entity == nil) {
144 return JS_UNDEFINED;
145 }
146
147 switch (magic) {
148 case kFlasher_active:
149 return OOJSValueFromBOOL([entity isActive]);
150
151 case kFlasher_color:
152 result = [[entity color] normalizedArray];
153 break;
154
156 return JS_NewNumber(context, [entity frequency]);
157
159 return JS_NewNumber(context, [entity fraction]);
160
161 case kFlasher_phase:
162 return JS_NewNumber(context, [entity phase]);
163
164 case kFlasher_size:
165 return JS_NewNumber(context, [entity diameter]);
166
167 default:
169 return OOJSNativeFailure(context);
170 }
171
172 return OOJSValueFromNativeObject(context, result);
173
175}
#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
#define OOJS_COUNT(array)
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_COUNT, OOJS_GETTER_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSNativeFailure(), OOJSReportBadPropertySelector(), OOJSValueFromBOOL(), OOJSValueFromNativeObject(), and sFlasherProperties.

Here is the call graph for this function:

◆ FlasherRemove()

JSValue FlasherRemove ( OOJS_NATIVE_ARGS )
static

Definition at line 262 of file OOJSFlasher.m.

263{
264 OOJS_NATIVE_ENTER(context)
265
266 OOFlasherEntity* thisEnt = nil;
267 GET_THIS_FLASHER(thisEnt);
268
269 Entity* parent = [thisEnt owner];
270 if ([parent isShip]) {
271 [(ShipEntity*)parent removeFlasher:thisEnt];
272 } else {
274 }
275
277
279}
#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_ARGS, 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()

JSValue FlasherSetProperty ( OOJS_SETTER_ARGS )
static

Definition at line 177 of file OOJSFlasher.m.

178{
179 OOJS_NATIVE_ENTER(context)
180
181 OOFlasherEntity* entity = nil;
182 double fValue;
183 int bValue;
184 OOColor* colorForScript = nil;
185
186 if (!JSFlasherGetFlasherEntity(context, this, &entity))
187 return OOJSNativeFailure(context);
188 if (entity == nil)
189 return JS_UNDEFINED;
190
191 switch (magic) {
192 case kFlasher_active:
193 if ((bValue = JS_ToBool(context, value)) >= 0) {
194 [entity setActive:bValue];
195 return JS_UNDEFINED;
196 }
197 break;
198
199 case kFlasher_color:
200 colorForScript = [OOColor colorWithDescription:OOJSNativeObjectFromJSValue(context, value)];
201 if (colorForScript != nil || JS_IsNull(value)) {
202 [entity setColor:colorForScript];
203 return JS_UNDEFINED;
204 }
205 break;
206
208 if (JS_ToFloat64(context, &fValue, value) == 0) {
209 if (fValue >= 0.0) {
210 [entity setFrequency:fValue];
211 return JS_UNDEFINED;
212 }
213 }
214 break;
215
217 if (JS_ToFloat64(context, &fValue, value) == 0) {
218 if (fValue > 0.0 && fValue <= 1.0) {
219 [entity setFraction:fValue];
220 return JS_UNDEFINED;
221 }
222 }
223 break;
224
225 case kFlasher_phase:
226 if (JS_ToFloat64(context, &fValue, value) == 0) {
227 [entity setPhase:fValue];
228 return JS_UNDEFINED;
229 }
230 break;
231
232 case kFlasher_size:
233 if (JS_ToFloat64(context, &fValue, value) == 0) {
234 if (fValue > 0.0) {
235 [entity setDiameter:fValue];
236 return JS_UNDEFINED;
237 }
238 }
239 break;
240
241 default:
243 return OOJSNativeFailure(context);
244 }
245
247 return OOJSNativeFailure(context);
248
250}
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_COUNT, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_SETTER_ARGS, OOJSNativeFailure(), 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,
JSValueConst global )

Definition at line 72 of file OOJSFlasher.m.

73{
75
76 JSValue parentPrototype = JS_GetClassProto(context, JSEntityClassID());
77 NSCAssert(JS_IsObject(parentPrototype), @"Entity must be initialized before Flasher.");
78 OOJSInitClass(context, global, sFlasherClassID, parentPrototype, OOJSUnconstructableConstruct, 0,
80 JS_FreeValue(context, parentPrototype);
81
84}
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)
JSClassID JSEntityClassID(void)
Definition OOJSEntity.m:115
static JSClassID sFlasherClassID
Definition OOJSFlasher.m:33
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)

References JSEntityClassID(), OOJS_COUNT, OOJSBasicPrivateObjectConverter(), OOJSInitClass(), OOJSRegisterClass(), OOJSRegisterObjectConverter(), OOJSRegisterSubclass(), OOJSUnconstructableConstruct(), sFlasherClass, sFlasherClassID, sFlasherMethods, and sFlasherProperties.

Here is the call graph for this function:

◆ JSFlasherClassID()

JSClassID JSFlasherClassID ( void )

Definition at line 86 of file OOJSFlasher.m.

87{
88 return sFlasherClassID;
89}

References sFlasherClassID.

◆ JSFlasherGetFlasherEntity()

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

Definition at line 91 of file OOJSFlasher.m.

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

References nil, OOJS_PROFILE_ENTER, and OOJS_PROFILE_EXIT.

Variable Documentation

◆ sFlasherClass

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

Definition at line 42 of file OOJSFlasher.m.

42 {
43 .class_name = "Flasher",
44 .finalizer = OOJSObjectWrapperFinalize,
45};

◆ sFlasherClassID

JSClassID sFlasherClassID
static

◆ sFlasherMethods

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

Definition at line 67 of file OOJSFlasher.m.

67 {
68 // JS name, min args, function
69 JS_CFUNC_DEF("remove", 0, FlasherRemove),
70};

◆ sFlasherProperties

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

Definition at line 57 of file OOJSFlasher.m.