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

Go to the source code of this file.

Classes

class  OOSystemInfo

Enumerations

enum  { kSystemInfo_coordinates , kSystemInfo_internalCoordinates , kSystemInfo_galaxyID , kSystemInfo_systemID }

Functions

static JSBool SystemInfoDeleteProperty (JSContext *context, JSObject *this, jsid propID, jsval *value)
static JSBool SystemInfoGetProperty (JSContext *context, JSObject *this, jsid propID, jsval *value)
static JSBool SystemInfoSetProperty (JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
static void SystemInfoFinalize (JSContext *context, JSObject *this)
static JSBool SystemInfoEnumerate (JSContext *context, JSObject *this, JSIterateOp enumOp, jsval *state, jsid *idp)
static JSBool SystemInfoDistanceToSystem (JSContext *context, uintN argc, jsval *vp)
static JSBool SystemInfoRouteToSystem (JSContext *context, uintN argc, jsval *vp)
static JSBool SystemInfoSamplePrice (JSContext *context, uintN argc, jsval *vp)
static JSBool SystemInfoSetPropertyMethod (JSContext *context, uintN argc, jsval *vp)
static JSBool SystemInfoStaticSetInterstellarProperty (JSContext *context, uintN argc, jsval *vp)
static JSBool SystemInfoStaticFilteredSystems (JSContext *context, uintN argc, jsval *vp)
 DEFINE_JS_OBJECT_GETTER (JSSystemInfoGetSystemInfo, &sSystemInfoClass, sSystemInfoPrototype, OOSystemInfo)
void InitOOJSSystemInfo (JSContext *context, JSObject *global)
jsval GetJSSystemInfoForSystem (JSContext *context, OOGalaxyID galaxy, OOSystemID system)

Variables

static JSObject * sSystemInfoPrototype
static JSObject * sCachedSystemInfo
static OOGalaxyID sCachedGalaxy
static OOSystemID sCachedSystem
static JSClass sSystemInfoClass
static JSPropertySpec sSystemInfoProperties []
static JSFunctionSpec sSystemInfoMethods []
static JSFunctionSpec sSystemInfoStaticMethods []

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kSystemInfo_coordinates 
kSystemInfo_internalCoordinates 
kSystemInfo_galaxyID 
kSystemInfo_systemID 

Definition at line 69 of file OOJSSystemInfo.m.

69 {
70 // Property IDs
71 kSystemInfo_coordinates, // system coordinates (in LY), Vector3D (with z = 0), read-only
72 kSystemInfo_internalCoordinates, // system coordinates (unscaled), Vector3D (with z = 0), read-only
73 kSystemInfo_galaxyID, // galaxy number, integer, read-only
74 kSystemInfo_systemID // system number, integer, read-only
75};
@ kSystemInfo_systemID
@ kSystemInfo_coordinates
@ kSystemInfo_internalCoordinates
@ kSystemInfo_galaxyID

Function Documentation

◆ DEFINE_JS_OBJECT_GETTER()

DEFINE_JS_OBJECT_GETTER ( JSSystemInfoGetSystemInfo ,
& sSystemInfoClass,
sSystemInfoPrototype ,
OOSystemInfo  )

◆ GetJSSystemInfoForSystem()

jsval GetJSSystemInfoForSystem ( JSContext * context,
OOGalaxyID galaxy,
OOSystemID system )

Definition at line 255 of file OOJSSystemInfo.m.

256{
258
259 // Use cached object if possible.
260 if (sCachedSystemInfo != NULL && sCachedGalaxy == galaxy && sCachedSystem == system) {
261 return OBJECT_TO_JSVAL(sCachedSystemInfo);
262 }
263
264 // If not, create a new one.
265 OOSystemInfo* info = nil;
266 jsval result;
268 info = [[[OOSystemInfo alloc] initWithGalaxy:galaxy system:system] autorelease];
270
271 if (EXPECT_NOT(info == nil)) {
272 OOJSReportWarning(context, @"Could not create system info object for galaxy %u, system %i.", galaxy, system);
273 }
274
275 result = OOJSValueFromNativeObject(context, info);
276
277 // Cache is not a root; we clear it in finalize if necessary.
278 sCachedSystemInfo = JSVAL_TO_OBJECT(result);
279 sCachedGalaxy = galaxy;
280 sCachedSystem = system;
281
282 return result;
283
285}
#define EXPECT_NOT(x)
#define OOJS_END_FULL_NATIVE
#define OOJS_BEGIN_FULL_NATIVE(context)
#define OOJS_PROFILE_ENTER
#define OOJS_PROFILE_EXIT_JSVAL
static OOSystemID sCachedSystem
static JSObject * sCachedSystemInfo
static OOGalaxyID sCachedGalaxy
void OOJSReportWarning(JSContext *context, NSString *format,...)
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
return nil

◆ InitOOJSSystemInfo()

void InitOOJSSystemInfo ( JSContext * context,
JSObject * global )

Definition at line 249 of file OOJSSystemInfo.m.

250{
253}
static JSPropertySpec sSystemInfoProperties[]
static JSFunctionSpec sSystemInfoStaticMethods[]
static JSObject * sSystemInfoPrototype
static JSClass sSystemInfoClass
static JSFunctionSpec sSystemInfoMethods[]
void OOJSRegisterObjectConverter(JSClass *theClass, OOJSClassConverterCallback converter)
JSBool OOJSUnconstructableConstruct(JSContext *context, uintN argc, jsval *vp)
id OOJSBasicPrivateObjectConverter(JSContext *context, JSObject *object)

References OOJSBasicPrivateObjectConverter(), OOJSRegisterObjectConverter(), OOJSUnconstructableConstruct(), sSystemInfoClass, sSystemInfoMethods, sSystemInfoProperties, sSystemInfoPrototype, and sSystemInfoStaticMethods.

Referenced by OOJavaScriptEngine(Private)::createMainThreadContext.

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

◆ SystemInfoDeleteProperty()

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

Definition at line 350 of file OOJSSystemInfo.m.

351{
352 OOJS_PROFILE_ENTER // Any exception will be converted in SystemInfoSetProperty()
353
354 jsval v = JSVAL_VOID;
355 return SystemInfoSetProperty(context, this, propID, NO, &v);
356
358}
#define OOJS_PROFILE_EXIT
static JSBool SystemInfoSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)

References OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and SystemInfoSetProperty().

Here is the call graph for this function:

◆ SystemInfoDistanceToSystem()

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

Definition at line 456 of file OOJSSystemInfo.m.

457{
458 OOJS_NATIVE_ENTER(context)
459
460 OOSystemInfo* thisInfo = nil;
461 JSObject* otherObj = NULL;
462 OOSystemInfo* otherInfo = nil;
463
464 if (!JSSystemInfoGetSystemInfo(context, OOJS_THIS, &thisInfo))
465 return NO;
466 if (argc < 1 || !JS_ValueToObject(context, OOJS_ARGV[0], &otherObj) || !JSSystemInfoGetSystemInfo(context, otherObj, &otherInfo)) {
467 OOJSReportBadArguments(context, @"SystemInfo", @"distanceToSystem", MIN(argc, 1U), OOJS_ARGV, nil, @"system info");
468 return NO;
469 }
470
471 BOOL sameGalaxy = ([thisInfo galaxy] == [otherInfo galaxy]);
472 if (!sameGalaxy) {
473 OOJSReportErrorForCaller(context, @"SystemInfo", @"distanceToSystem", @"Cannot calculate distance for systems in other galaxies.");
474 return NO;
475 }
476
477 NSPoint thisCoord = [thisInfo coordinates];
478 NSPoint otherCoord = [otherInfo coordinates];
479
480 OOJS_RETURN_DOUBLE(distanceBetweenPlanetPositions(thisCoord.x, thisCoord.y, otherCoord.x, otherCoord.y));
481
483}
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_NATIVE_EXIT
#define OOJS_THIS
#define OOJS_RETURN_DOUBLE(value)
void OOJSReportErrorForCaller(JSContext *context, NSString *scriptClass, NSString *function, NSString *format,...)
#define OOJS_ARGV
void OOJSReportBadArguments(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, NSString *message, NSString *expectedArgsDescription)
#define MIN(A, B)
Definition OOMaths.h:91
NSPoint coordinates()
OOGalaxyID galaxy()
OOINLINE double distanceBetweenPlanetPositions(int x1, int y1, int x2, int y2) INLINE_CONST_FUNC

References OOSystemInfo::coordinates, distanceBetweenPlanetPositions(), OOSystemInfo::galaxy, MIN, nil, OOJS_ARGV, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_DOUBLE, OOJS_THIS, OOJSReportBadArguments(), and OOJSReportErrorForCaller().

Here is the call graph for this function:

◆ SystemInfoEnumerate()

JSBool SystemInfoEnumerate ( JSContext * context,
JSObject * this,
JSIterateOp enumOp,
jsval * state,
jsid * idp )
static

Definition at line 301 of file OOJSSystemInfo.m.

302{
303 OOJS_NATIVE_ENTER(context)
304
305 NSEnumerator* enumerator = nil;
306
307 switch (enumOp) {
308 case JSENUMERATE_INIT:
309 case JSENUMERATE_INIT_ALL: // For ES5 Object.getOwnPropertyNames(). Since we have no non-enumerable properties, this is the same as _INIT.
310 {
311 OOSystemInfo* info = JS_GetPrivate(context, this);
312 NSArray* keys = [info allKeys];
313 enumerator = [[keys objectEnumerator] retain];
314 *state = PRIVATE_TO_JSVAL(enumerator);
315
316 NSUInteger count = [keys count];
317 assert(count <= INT32_MAX);
318 if (idp != NULL)
319 *idp = INT_TO_JSID((int32_t)count);
320 return YES;
321 }
322
323 case JSENUMERATE_NEXT: {
324 enumerator = JSVAL_TO_PRIVATE(*state);
325 NSString* next = [enumerator nextObject];
326 if (next != nil) {
327 jsval val = [next oo_jsValueInContext:context];
328 return JS_ValueToId(context, val, idp);
329 }
330 // else:
331 *state = JSVAL_NULL;
332 // Fall through.
333 }
334
335 case JSENUMERATE_DESTROY: {
336 if (enumerator == nil && JSVAL_IS_DOUBLE(*state)) {
337 enumerator = JSVAL_TO_PRIVATE(*state);
338 }
339 [enumerator release];
340
341 if (idp != NULL)
342 *idp = JSID_VOID;
343 return YES;
344 }
345 }
346
348}
unsigned count
NSArray * allKeys()

References OOSystemInfo::allKeys, count, nil, OOJS_NATIVE_ENTER, and OOJS_NATIVE_EXIT.

Here is the call graph for this function:

◆ SystemInfoFinalize()

void SystemInfoFinalize ( JSContext * context,
JSObject * this )
static

Definition at line 287 of file OOJSSystemInfo.m.

288{
290
291 [(id)JS_GetPrivate(context, this) release];
292 JS_SetPrivate(context, this, nil);
293
294 // Clear now-stale cache entry if appropriate.
295 if (sCachedSystemInfo == this)
296 sCachedSystemInfo = NULL;
297
299}
#define OOJS_PROFILE_EXIT_VOID

References nil, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT_VOID, and sCachedSystemInfo.

◆ SystemInfoGetProperty()

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

Definition at line 360 of file OOJSSystemInfo.m.

361{
362 OOJS_NATIVE_ENTER(context)
363
364 if (this == sSystemInfoPrototype) {
365 // Let SpiderMonkey handle access to the prototype object (where info will be nil).
366 return YES;
367 }
368
369 OOSystemInfo* info = OOJSNativeObjectOfClassFromJSObject(context, this, [OOSystemInfo class]);
370 // What if we're trying to access a saved witchspace systemInfo object?
371 BOOL savedInterstellarInfo = ![UNIVERSE inInterstellarSpace] && [info system] == -1;
372 BOOL sameGalaxy = [PLAYER currentGalaxyID] == [info galaxy];
373
374 if (JSID_IS_INT(propID)) {
375 switch (JSID_TO_INT(propID)) {
377 if (sameGalaxy && !savedInterstellarInfo) {
378 return VectorToJSValue(context, OOGalacticCoordinatesFromInternal([info coordinates]), value);
379 } else {
380 OOJSReportError(context, @"Cannot read systemInfo values for %@.", savedInterstellarInfo ? @"invalid interstellar space reference" : @"other galaxies");
381 return NO;
382 }
383 break;
384
386 if (sameGalaxy && !savedInterstellarInfo) {
387 return NSPointToVectorJSValue(context, [info coordinates], value);
388 } else {
389 OOJSReportError(context, @"Cannot read systemInfo values for %@.", savedInterstellarInfo ? @"invalid interstellar space reference" : @"other galaxies");
390 return NO;
391 }
392 break;
393
395 *value = INT_TO_JSVAL([info galaxy]);
396 return YES;
397
399 *value = INT_TO_JSVAL([info system]);
400 return YES;
401
402 default:
404 return NO;
405 }
406 } else if (JSID_IS_STRING(propID)) {
407 NSString* key = OOStringFromJSString(context, JSID_TO_STRING(propID));
408
409 OOSystemDescriptionManager* systemManager = [UNIVERSE systemManager];
410 id propValue = nil;
411 // interstellar space needs more work at this stage
412 if ([info system] != -1) {
413 propValue = [systemManager getProperty:key forSystem:[info system] inGalaxy:[info galaxy]];
414 } else {
415 propValue = [info valueForKey:key];
416 }
417
418 if (propValue != nil) {
419 if ([propValue isKindOfClass:[NSNumber class]] || OOIsNumberLiteral([propValue description], YES)) {
420 BOOL OK = JS_NewNumberValue(context, [propValue doubleValue], value);
421 if (!OK) {
422 *value = JSVAL_VOID;
423 return NO;
424 }
425 } else {
426 *value = [propValue oo_jsValueInContext:context];
427 }
428 }
429 }
430 return YES;
431
433}
BOOL OOIsNumberLiteral(NSString *string, BOOL allowSpaces)
BOOL NSPointToVectorJSValue(JSContext *context, NSPoint point, jsval *outValue) NONNULL_FUNC
Definition OOJSVector.m:328
BOOL VectorToJSValue(JSContext *context, Vector vector, jsval *outValue) NONNULL_FUNC
Definition OOJSVector.m:264
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
void OOJSReportError(JSContext *context, NSString *format,...)
NSString * OOStringFromJSString(JSContext *context, JSString *string)
id OOJSNativeObjectOfClassFromJSObject(JSContext *context, JSObject *object, Class requiredClass)
Vector OOGalacticCoordinatesFromInternal(NSPoint internalCoordinates)
id getProperty:forSystem:inGalaxy:(NSString *property,[forSystem] OOSystemID s,[inGalaxy] OOGalaxyID g)
id valueForKey:(NSString *key)
OOSystemID system()

References OOSystemInfo::coordinates, OOSystemInfo::galaxy, OOSystemDescriptionManager::getProperty:forSystem:inGalaxy:, kSystemInfo_coordinates, kSystemInfo_galaxyID, kSystemInfo_internalCoordinates, kSystemInfo_systemID, nil, NSPointToVectorJSValue(), OOGalacticCoordinatesFromInternal(), OOIsNumberLiteral(), OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSNativeObjectOfClassFromJSObject(), OOJSReportBadPropertySelector(), OOJSReportError(), OOStringFromJSString(), sSystemInfoProperties, sSystemInfoPrototype, OOSystemInfo::system, OOSystemInfo::valueForKey:, and VectorToJSValue().

Here is the call graph for this function:

◆ SystemInfoRouteToSystem()

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

Definition at line 486 of file OOJSSystemInfo.m.

487{
488 OOJS_NATIVE_ENTER(context)
489
490 OOSystemInfo* thisInfo = nil;
491 JSObject* otherObj = NULL;
492 OOSystemInfo* otherInfo = nil;
493 NSDictionary* result = nil;
495
496 if (!JSSystemInfoGetSystemInfo(context, OOJS_THIS, &thisInfo))
497 return NO;
498 if (argc < 1 || !JS_ValueToObject(context, OOJS_ARGV[0], &otherObj) || !JSSystemInfoGetSystemInfo(context, otherObj, &otherInfo)) {
499 OOJSReportBadArguments(context, @"SystemInfo", @"routeToSystem", MIN(argc, 1U), OOJS_ARGV, nil, @"system info");
500 return NO;
501 }
502
503 BOOL sameGalaxy = ([thisInfo galaxy] == [otherInfo galaxy]);
504 if (!sameGalaxy) {
505 OOJSReportErrorForCaller(context, @"SystemInfo", @"routeToSystem", @"Cannot calculate route for destinations in other galaxies.");
506 return NO;
507 }
508
509 if (argc >= 2) {
510 routeType = StringToRouteType(OOStringFromJSValue(context, OOJS_ARGV[1]));
511 }
512
514 result = [UNIVERSE routeFromSystem:[thisInfo system] toSystem:[otherInfo system] optimizedBy:routeType];
516
517 OOJS_RETURN_OBJECT(result);
518
520}
OORouteType StringToRouteType(NSString *string)
#define OOJS_RETURN_OBJECT(o)
NSString * OOStringFromJSValue(JSContext *context, jsval value)
OORouteType
Definition OOTypes.h:31
@ OPTIMIZED_BY_JUMPS
Definition OOTypes.h:33

References OOSystemInfo::galaxy, MIN, nil, OOJS_ARGV, OOJS_BEGIN_FULL_NATIVE, OOJS_END_FULL_NATIVE, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, OOJS_THIS, OOJSReportBadArguments(), OOJSReportErrorForCaller(), OOStringFromJSValue(), OPTIMIZED_BY_JUMPS, StringToRouteType(), and OOSystemInfo::system.

Here is the call graph for this function:

◆ SystemInfoSamplePrice()

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

Definition at line 523 of file OOJSSystemInfo.m.

524{
525 OOJS_NATIVE_ENTER(context)
526
527 OOSystemInfo* thisInfo = nil;
528
529 if (!JSSystemInfoGetSystemInfo(context, OOJS_THIS, &thisInfo))
530 return NO;
531 OOCommodityType commodity = OOStringFromJSValue(context, OOJS_ARGV[0]);
532 if (EXPECT_NOT(![[UNIVERSE commodities] goodDefined:commodity])) {
533 OOJSReportBadArguments(context, @"SystemInfo", @"samplePrice", MIN(argc, 1U), OOJS_ARGV, NULL, @"Unrecognised commodity type");
534 return NO;
535 }
536
537 BOOL sameGalaxy = ([thisInfo galaxy] == [PLAYER galaxyNumber]);
538 if (!sameGalaxy) {
539 OOJSReportErrorForCaller(context, @"SystemInfo", @"samplePrice", @"Cannot calculate sample price for destinations in other galaxies.");
540 return NO;
541 }
542
543 OOCreditsQuantity price = [[UNIVERSE commodities] samplePriceForCommodity:commodity inEconomy:[[thisInfo valueForKey:@"economy"] intValue] withScript:[thisInfo valueForKey:@"commodity_script"] inSystem:[thisInfo system]];
544
545 return JS_NewNumberValue(context, price, &OOJS_RVAL);
546
548}
#define OOJS_RVAL
NSString * OOCommodityType
Definition OOTypes.h:97
uint64_t OOCreditsQuantity
Definition OOTypes.h:160
#define UNIVERSE
Definition Universe.h:827
OOCreditsQuantity samplePriceForCommodity:inEconomy:withScript:inSystem:(OOCommodityType commodity,[inEconomy] OOEconomyID economy,[withScript] NSString *scriptName,[inSystem] OOSystemID system)

References EXPECT_NOT, OOSystemInfo::galaxy, MIN, nil, OOJS_ARGV, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RVAL, OOJS_THIS, OOJSReportBadArguments(), OOJSReportErrorForCaller(), OOStringFromJSValue(), OOCommodities::samplePriceForCommodity:inEconomy:withScript:inSystem:, OOSystemInfo::system, UNIVERSE, and OOSystemInfo::valueForKey:.

Here is the call graph for this function:

◆ SystemInfoSetProperty()

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

Definition at line 435 of file OOJSSystemInfo.m.

436{
437 if (EXPECT_NOT(this == sSystemInfoPrototype)) {
438 // Let SpiderMonkey handle access to the prototype object (where info will be nil).
439 return YES;
440 }
441
442 OOJS_NATIVE_ENTER(context);
443
444 if (JSID_IS_STRING(propID)) {
445 NSString* key = OOStringFromJSString(context, JSID_TO_STRING(propID));
446 OOSystemInfo* info = OOJSNativeObjectOfClassFromJSObject(context, this, [OOSystemInfo class]);
447
448 [info setValue:OOStringFromJSValue(context, *value) forKey:key];
449 }
450 return YES;
451
453}
void setValue:forKey:(id value,[forKey] NSString *key)

References EXPECT_NOT, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSNativeObjectOfClassFromJSObject(), OOStringFromJSString(), OOSystemInfo::setValue:forKey:, and sSystemInfoPrototype.

Referenced by SystemInfoDeleteProperty().

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

◆ SystemInfoSetPropertyMethod()

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

Definition at line 550 of file OOJSSystemInfo.m.

551{
552 OOJS_NATIVE_ENTER(context)
553
554 OOSystemInfo* thisInfo = nil;
555
556 if (!JSSystemInfoGetSystemInfo(context, OOJS_THIS, &thisInfo))
557 return NO;
558
559 NSString* property = nil;
560 id value = nil;
561 NSString* manifest = nil;
562
563 int32 iValue;
564
565 if (argc < 3) {
566 OOJSReportBadArguments(context, @"SystemInfo", @"setProperty", MIN(argc, 3U), OOJS_ARGV, NULL, @"setProperty(layer, property, value [,manifest])");
567 return NO;
568 }
569 if (!JS_ValueToInt32(context, OOJS_ARGV[0], &iValue)) {
570 OOJSReportBadArguments(context, @"SystemInfo", @"setProperty", MIN(argc, 3U), OOJS_ARGV, NULL, @"setProperty(layer, property, value [,manifest])");
571 return NO;
572 }
573 if (iValue < 0 || iValue >= OO_SYSTEM_LAYERS) {
574 OOJSReportBadArguments(context, @"SystemInfo", @"setProperty", MIN(argc, 3U), OOJS_ARGV, NULL, @"layer must be 0, 1, 2 or 3");
575 return NO;
576 }
577 OOSystemLayer layer = (OOSystemLayer)iValue;
578
579 property = OOStringFromJSValue(context, OOJS_ARGV[1]);
580 if (!JSVAL_IS_NULL(OOJS_ARGV[2])) {
581 value = OOJSNativeObjectFromJSValue(context, OOJS_ARGV[2]);
582 }
583 if (argc >= 4) {
584 manifest = OOStringFromJSValue(context, OOJS_ARGV[3]);
585 } else {
586 manifest = [[OOJSScript currentlyRunningScript] propertyNamed:kLocalManifestProperty];
587 }
588
589 [UNIVERSE setSystemDataForGalaxy:[thisInfo galaxy] planet:[thisInfo system] key:property value:value fromManifest:manifest forLayer:layer];
590
592
594}
id OOJSNativeObjectFromJSValue(JSContext *context, jsval value)
#define OOJS_RETURN_VOID
#define OO_SYSTEM_LAYERS
id propertyNamed:(NSString *name)
Definition OOJSScript.m:431
OOJSScript * currentlyRunningScript()
Definition OOJSScript.m:101

References OOJSScript::currentlyRunningScript, OOSystemInfo::galaxy, MIN, nil, OO_SYSTEM_LAYERS, OOJS_ARGV, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJS_THIS, OOJSNativeObjectFromJSValue(), OOJSReportBadArguments(), OOStringFromJSValue(), OOJSScript::propertyNamed:, and OOSystemInfo::system.

Here is the call graph for this function:

◆ SystemInfoStaticFilteredSystems()

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

Definition at line 597 of file OOJSSystemInfo.m.

598{
599 OOJS_NATIVE_ENTER(context)
600
601 JSObject* jsThis = NULL;
602
603 // Get this and predicate arguments
604 if (argc < 2 || !OOJSValueIsFunction(context, OOJS_ARGV[1]) || !JS_ValueToObject(context, OOJS_ARGV[0], &jsThis)) {
605 OOJSReportBadArguments(context, @"SystemInfo", @"filteredSystems", argc, OOJS_ARGV, nil, @"this and predicate function");
606 return NO;
607 }
608 jsval predicate = OOJS_ARGV[1];
609
610 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
611 NSMutableArray* result = [NSMutableArray arrayWithCapacity:256];
612
613 // Not OOJS_BEGIN_FULL_NATIVE() - we use JSAPI while paused.
615
616 // Iterate over systems.
617 BOOL OK = result != nil;
618 OOGalaxyID galaxy = [PLAYER currentGalaxyID];
619 OOSystemID system;
620 for (system = 0; system <= kOOMaximumSystemID; system++) {
621 // NOTE: this deliberately bypasses the cache, since iteration is inherently unfriendly to a single-item cache.
622 OOSystemInfo* info = [[[OOSystemInfo alloc] initWithGalaxy:galaxy system:system] autorelease];
623 jsval args[1] = { OOJSValueFromNativeObject(context, info) };
624
625 jsval rval = JSVAL_VOID;
627 OK = JS_CallFunctionValue(context, jsThis, predicate, 1, args, &rval);
629
630 if (OK) {
631 if (JS_IsExceptionPending(context)) {
632 JS_ReportPendingException(context);
633 OK = NO;
634 }
635 }
636
637 if (OK) {
638 JSBool boolVal;
639 if (JS_ValueToBoolean(context, rval, &boolVal) && boolVal) {
640 [result addObject:info];
641 }
642 }
643
644 if (!OK)
645 break;
646 }
647
648 if (OK) {
649 OOJS_SET_RVAL([result oo_jsValueInContext:context]);
650 } else {
651 OOJS_SET_RVAL(JSVAL_VOID);
652 }
653
654 [pool release];
655
657 return OK;
658
660}
void OOJSPauseTimeLimiter(void)
#define OOJS_SET_RVAL(v)
OOINLINE BOOL OOJSValueIsFunction(JSContext *context, jsval value)
void OOJSResumeTimeLimiter(void)
@ kOOMaximumSystemID
Definition OOTypes.h:187
int16_t OOSystemID
Definition OOTypes.h:183
uint8_t OOGalaxyID
Definition OOTypes.h:182

References OOSystemInfo::galaxy, kOOMaximumSystemID, nil, OOJS_ARGV, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_SET_RVAL, OOJSPauseTimeLimiter(), OOJSReportBadArguments(), OOJSResumeTimeLimiter(), OOJSValueFromNativeObject(), OOJSValueIsFunction(), and OOSystemInfo::system.

Here is the call graph for this function:

◆ SystemInfoStaticSetInterstellarProperty()

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

Definition at line 662 of file OOJSSystemInfo.m.

663{
664 OOJS_NATIVE_ENTER(context)
665
666 NSString* property = nil;
667 id value = nil;
668 NSString* manifest = nil;
669
670 int32 iValue;
671 OOGalaxyID g;
672 OOSystemID s1, s2;
673
674 if (argc < 6) {
675 OOJSReportBadArguments(context, @"SystemInfo", @"setInterstellarProperty", MIN(argc, 3U), OOJS_ARGV, NULL, @"setProperty(galaxy, fromsystem, tosystem, layer, property, value [,manifest])");
676 return NO;
677 }
678 if (!JS_ValueToInt32(context, OOJS_ARGV[0], &iValue)) {
679 OOJSReportBadArguments(context, @"SystemInfo", @"setInterstellarProperty", MIN(argc, 3U), OOJS_ARGV, NULL, @"setProperty(galaxy, fromsystem, tosystem, layer, property, value [,manifest])");
680 return NO;
681 }
682 if (iValue < 0 || iValue > kOOMaximumGalaxyID) {
683 OOJSReportBadArguments(context, @"SystemInfo", @"setInterstellarProperty", MIN(argc, 3U), OOJS_ARGV, NULL, @"galaxy out of range");
684 return NO;
685 } else {
686 g = (OOGalaxyID)iValue;
687 }
688
689 if (!JS_ValueToInt32(context, OOJS_ARGV[1], &iValue)) {
690 OOJSReportBadArguments(context, @"SystemInfo", @"setInterstellarProperty", MIN(argc, 3U), OOJS_ARGV, NULL, @"setProperty(galaxy, fromsystem, tosystem, layer, property, value [,manifest])");
691 return NO;
692 }
693 if (iValue < 0 || iValue > kOOMaximumSystemID) {
694 OOJSReportBadArguments(context, @"SystemInfo", @"setInterstellarProperty", MIN(argc, 3U), OOJS_ARGV, NULL, @"fromsystem out of range");
695 return NO;
696 } else {
697 s1 = (OOSystemID)iValue;
698 }
699
700 if (!JS_ValueToInt32(context, OOJS_ARGV[2], &iValue)) {
701 OOJSReportBadArguments(context, @"SystemInfo", @"setInterstellarProperty", MIN(argc, 3U), OOJS_ARGV, NULL, @"setProperty(galaxy, fromsystem, tosystem, layer, property, value [,manifest])");
702 return NO;
703 }
704 if (iValue < 0 || iValue > kOOMaximumSystemID) {
705 OOJSReportBadArguments(context, @"SystemInfo", @"setInterstellarProperty", MIN(argc, 3U), OOJS_ARGV, NULL, @"tosystem out of range");
706 return NO;
707 } else {
708 s2 = (OOSystemID)iValue;
709 }
710
711 if (!JS_ValueToInt32(context, OOJS_ARGV[3], &iValue)) {
712 OOJSReportBadArguments(context, @"SystemInfo", @"setInterstellarProperty", MIN(argc, 3U), OOJS_ARGV, NULL, @"setProperty(galaxy, fromsystem, tosystem, layer, property, value [,manifest])");
713 return NO;
714 }
715 if (iValue < 0 || iValue >= OO_SYSTEM_LAYERS) {
716 OOJSReportBadArguments(context, @"SystemInfo", @"setInterstellarProperty", MIN(argc, 3U), OOJS_ARGV, NULL, @"layer must be 0, 1, 2 or 3");
717 return NO;
718 }
719 OOSystemLayer layer = (OOSystemLayer)iValue;
720
721 property = OOStringFromJSValue(context, OOJS_ARGV[4]);
722 if (!JSVAL_IS_NULL(OOJS_ARGV[5])) {
723 value = OOJSNativeObjectFromJSValue(context, OOJS_ARGV[5]);
724 }
725 if (argc >= 7) {
726 manifest = OOStringFromJSValue(context, OOJS_ARGV[6]);
727 } else {
728 manifest = [[OOJSScript currentlyRunningScript] propertyNamed:kLocalManifestProperty];
729 }
730
731 NSString* key = [NSString stringWithFormat:@"interstellar: %u %u %u", g, s1, s2];
732
733 [[UNIVERSE systemManager] setProperty:property forSystemKey:key andLayer:layer toValue:value fromManifest:manifest];
734
736
738}
@ kOOMaximumGalaxyID
Definition OOTypes.h:186

References OOJSScript::currentlyRunningScript, kOOMaximumGalaxyID, kOOMaximumSystemID, MIN, nil, OO_SYSTEM_LAYERS, OOJS_ARGV, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJSNativeObjectFromJSValue(), OOJSReportBadArguments(), OOStringFromJSValue(), and OOJSScript::propertyNamed:.

Here is the call graph for this function:

Variable Documentation

◆ sCachedGalaxy

OOGalaxyID sCachedGalaxy
static

Definition at line 37 of file OOJSSystemInfo.m.

Referenced by GetJSSystemInfoForSystem().

◆ sCachedSystem

OOSystemID sCachedSystem
static

Definition at line 38 of file OOJSSystemInfo.m.

Referenced by GetJSSystemInfoForSystem().

◆ sCachedSystemInfo

JSObject* sCachedSystemInfo
static

◆ sSystemInfoClass

JSClass sSystemInfoClass
static
Initial value:
= {
"SystemInfo",
JSCLASS_HAS_PRIVATE | JSCLASS_NEW_ENUMERATE,
JS_PropertyStub,
(JSEnumerateOp)SystemInfoEnumerate,
JS_ResolveStub,
JS_ConvertStub,
JSCLASS_NO_OPTIONAL_MEMBERS
}
static JSBool SystemInfoDeleteProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
static JSBool SystemInfoGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
static void SystemInfoFinalize(JSContext *context, JSObject *this)
static JSBool SystemInfoEnumerate(JSContext *context, JSObject *this, JSIterateOp enumOp, jsval *state, jsid *idp)

Definition at line 54 of file OOJSSystemInfo.m.

54 {
55 "SystemInfo",
56 JSCLASS_HAS_PRIVATE | JSCLASS_NEW_ENUMERATE,
57
58 JS_PropertyStub,
62 (JSEnumerateOp)SystemInfoEnumerate,
63 JS_ResolveStub,
64 JS_ConvertStub,
66 JSCLASS_NO_OPTIONAL_MEMBERS
67};

Referenced by DEFINE_JS_OBJECT_GETTER(), InitOOJSSystemInfo(), and InitOOJSSystemInfo().

◆ sSystemInfoMethods

JSFunctionSpec sSystemInfoMethods[]
static
Initial value:
= {
{ "toString", OOJSObjectWrapperToString, 0 },
{ "distanceToSystem", SystemInfoDistanceToSystem, 1 },
{ "routeToSystem", SystemInfoRouteToSystem, 1 },
{ "samplePrice", SystemInfoSamplePrice, 1 },
{ "setProperty", SystemInfoSetPropertyMethod, 3 },
{ 0 }
}
static JSBool SystemInfoDistanceToSystem(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemInfoRouteToSystem(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemInfoSetPropertyMethod(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemInfoSamplePrice(JSContext *context, uintN argc, jsval *vp)
JSBool OOJSObjectWrapperToString(JSContext *context, uintN argc, jsval *vp)

Definition at line 86 of file OOJSSystemInfo.m.

86 {
87 // JS name Function min args
88 { "toString", OOJSObjectWrapperToString, 0 },
89 { "distanceToSystem", SystemInfoDistanceToSystem, 1 },
90 { "routeToSystem", SystemInfoRouteToSystem, 1 },
91 { "samplePrice", SystemInfoSamplePrice, 1 },
92 { "setProperty", SystemInfoSetPropertyMethod, 3 },
93 { 0 }
94};

Referenced by InitOOJSSystemInfo(), and InitOOJSSystemInfo().

◆ sSystemInfoProperties

JSPropertySpec sSystemInfoProperties[]
static
Initial value:

Definition at line 77 of file OOJSSystemInfo.m.

77 {
78 // JS name ID flags
83 { 0 }
84};

Referenced by InitOOJSSystemInfo(), InitOOJSSystemInfo(), SystemInfoGetProperty(), and SystemInfoGetProperty().

◆ sSystemInfoPrototype

JSObject* sSystemInfoPrototype
static

◆ sSystemInfoStaticMethods

JSFunctionSpec sSystemInfoStaticMethods[]
static
Initial value:
= {
{ "filteredSystems", SystemInfoStaticFilteredSystems, 2 },
{ "setInterstellarProperty", SystemInfoStaticSetInterstellarProperty, 4 },
{ 0 }
}
static JSBool SystemInfoStaticFilteredSystems(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemInfoStaticSetInterstellarProperty(JSContext *context, uintN argc, jsval *vp)

Definition at line 96 of file OOJSSystemInfo.m.

96 {
97 // JS name Function min args
98 { "filteredSystems", SystemInfoStaticFilteredSystems, 2 },
99 { "setInterstellarProperty", SystemInfoStaticSetInterstellarProperty, 4 },
100 { 0 }
101};

Referenced by InitOOJSSystemInfo(), and InitOOJSSystemInfo().