Oolite 1.91.0.7644-241112-7f5034b
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 74 of file OOJSSystemInfo.m.

75{
76 // Property IDs
77 kSystemInfo_coordinates, // system coordinates (in LY), Vector3D (with z = 0), read-only
78 kSystemInfo_internalCoordinates, // system coordinates (unscaled), Vector3D (with z = 0), read-only
79 kSystemInfo_galaxyID, // galaxy number, integer, read-only
80 kSystemInfo_systemID // system number, integer, read-only
81};
@ 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 297 of file OOJSSystemInfo.m.

298{
300
301 // Use cached object if possible.
302 if (sCachedSystemInfo != NULL &&
303 sCachedGalaxy == galaxy &&
304 sCachedSystem == system)
305 {
306 return OBJECT_TO_JSVAL(sCachedSystemInfo);
307 }
308
309 // If not, create a new one.
310 OOSystemInfo *info = nil;
311 jsval result;
313 info = [[[OOSystemInfo alloc] initWithGalaxy:galaxy system:system] autorelease];
315
316 if (EXPECT_NOT(info == nil))
317 {
318 OOJSReportWarning(context, @"Could not create system info object for galaxy %u, system %i.", galaxy, system);
319 }
320
321 result = OOJSValueFromNativeObject(context, info);
322
323 // Cache is not a root; we clear it in finalize if necessary.
324 sCachedSystemInfo = JSVAL_TO_OBJECT(result);
325 sCachedGalaxy = galaxy;
326 sCachedSystem = system;
327
328 return result;
329
331}
#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

References EXPECT_NOT, OOSystemInfo::galaxy, nil, OOJS_BEGIN_FULL_NATIVE, OOJS_END_FULL_NATIVE, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT_JSVAL, OOJSReportWarning(), OOJSValueFromNativeObject(), sCachedGalaxy, sCachedSystem, sCachedSystemInfo, and OOSystemInfo::system.

Referenced by SystemGetProperty(), and SystemStaticInfoForSystem().

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

◆ InitOOJSSystemInfo()

void InitOOJSSystemInfo ( JSContext * context,
JSObject * global )

Definition at line 290 of file OOJSSystemInfo.m.

291{
294}
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.

+ Here is the call graph for this function:

◆ SystemInfoDeleteProperty()

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

Definition at line 403 of file OOJSSystemInfo.m.

404{
405 OOJS_PROFILE_ENTER // Any exception will be converted in SystemInfoSetProperty()
406
407 jsval v = JSVAL_VOID;
408 return SystemInfoSetProperty(context, this, propID, NO, &v);
409
411}
#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()

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

Definition at line 532 of file OOJSSystemInfo.m.

533{
534 OOJS_NATIVE_ENTER(context)
535
536 OOSystemInfo *thisInfo = nil;
537 JSObject *otherObj = NULL;
538 OOSystemInfo *otherInfo = nil;
539
540 if (!JSSystemInfoGetSystemInfo(context, OOJS_THIS, &thisInfo)) return NO;
541 if (argc < 1 || !JS_ValueToObject(context, OOJS_ARGV[0], &otherObj) || !JSSystemInfoGetSystemInfo(context, otherObj, &otherInfo))
542 {
543 OOJSReportBadArguments(context, @"SystemInfo", @"distanceToSystem", MIN(argc, 1U), OOJS_ARGV, nil, @"system info");
544 return NO;
545 }
546
547 BOOL sameGalaxy = ([thisInfo galaxy] == [otherInfo galaxy]);
548 if (!sameGalaxy)
549 {
550 OOJSReportErrorForCaller(context, @"SystemInfo", @"distanceToSystem", @"Cannot calculate distance for systems in other galaxies.");
551 return NO;
552 }
553
554 NSPoint thisCoord = [thisInfo coordinates];
555 NSPoint otherCoord = [otherInfo coordinates];
556
557 OOJS_RETURN_DOUBLE(distanceBetweenPlanetPositions(thisCoord.x, thisCoord.y, otherCoord.x, otherCoord.y));
558
560}
#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:111
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()

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

Definition at line 348 of file OOJSSystemInfo.m.

349{
350 OOJS_NATIVE_ENTER(context)
351
352 NSEnumerator *enumerator = nil;
353
354 switch (enumOp)
355 {
356 case JSENUMERATE_INIT:
357 case JSENUMERATE_INIT_ALL: // For ES5 Object.getOwnPropertyNames(). Since we have no non-enumerable properties, this is the same as _INIT.
358 {
359 OOSystemInfo *info = JS_GetPrivate(context, this);
360 NSArray *keys = [info allKeys];
361 enumerator = [[keys objectEnumerator] retain];
362 *state = PRIVATE_TO_JSVAL(enumerator);
363
364 NSUInteger count = [keys count];
365 assert(count <= INT32_MAX);
366 if (idp != NULL) *idp = INT_TO_JSID((int32_t)count);
367 return YES;
368 }
369
370 case JSENUMERATE_NEXT:
371 {
372 enumerator = JSVAL_TO_PRIVATE(*state);
373 NSString *next = [enumerator nextObject];
374 if (next != nil)
375 {
376 jsval val = [next oo_jsValueInContext:context];
377 return JS_ValueToId(context, val, idp);
378 }
379 // else:
380 *state = JSVAL_NULL;
381 // Fall through.
382 }
383
384 case JSENUMERATE_DESTROY:
385 {
386 if (enumerator == nil && JSVAL_IS_DOUBLE(*state))
387 {
388 enumerator = JSVAL_TO_PRIVATE(*state);
389 }
390 [enumerator release];
391
392 if (idp != NULL) *idp = JSID_VOID;
393 return YES;
394 }
395 }
396
397
398
400}
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()

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

Definition at line 334 of file OOJSSystemInfo.m.

335{
337
338 [(id)JS_GetPrivate(context, this) release];
339 JS_SetPrivate(context, this, nil);
340
341 // Clear now-stale cache entry if appropriate.
342 if (sCachedSystemInfo == this) sCachedSystemInfo = NULL;
343
345}
#define OOJS_PROFILE_EXIT_VOID

References nil, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT_VOID, and sCachedSystemInfo.

◆ SystemInfoGetProperty()

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

Definition at line 414 of file OOJSSystemInfo.m.

415{
416 OOJS_NATIVE_ENTER(context)
417
418 if (this == sSystemInfoPrototype)
419 {
420 // Let SpiderMonkey handle access to the prototype object (where info will be nil).
421 return YES;
422 }
423
424 OOSystemInfo *info = OOJSNativeObjectOfClassFromJSObject(context, this, [OOSystemInfo class]);
425 // What if we're trying to access a saved witchspace systemInfo object?
426 BOOL savedInterstellarInfo = ![UNIVERSE inInterstellarSpace] && [info system] == -1;
427 BOOL sameGalaxy = [PLAYER currentGalaxyID] == [info galaxy];
428
429
430 if (JSID_IS_INT(propID))
431 {
432 switch (JSID_TO_INT(propID))
433 {
435 if (sameGalaxy && !savedInterstellarInfo)
436 {
437 return VectorToJSValue(context, OOGalacticCoordinatesFromInternal([info coordinates]), value);
438 }
439 else
440 {
441 OOJSReportError(context, @"Cannot read systemInfo values for %@.", savedInterstellarInfo ? @"invalid interstellar space reference" : @"other galaxies");
442 return NO;
443 }
444 break;
445
447 if (sameGalaxy && !savedInterstellarInfo)
448 {
449 return NSPointToVectorJSValue(context, [info coordinates], value);
450 }
451 else
452 {
453 OOJSReportError(context, @"Cannot read systemInfo values for %@.", savedInterstellarInfo ? @"invalid interstellar space reference" : @"other galaxies");
454 return NO;
455 }
456 break;
457
459 *value = INT_TO_JSVAL([info galaxy]);
460 return YES;
461
463 *value = INT_TO_JSVAL([info system]);
464 return YES;
465
466 default:
468 return NO;
469 }
470 }
471 else if (JSID_IS_STRING(propID))
472 {
473 NSString *key = OOStringFromJSString(context, JSID_TO_STRING(propID));
474
475 OOSystemDescriptionManager *systemManager = [UNIVERSE systemManager];
476 id propValue = nil;
477 // interstellar space needs more work at this stage
478 if ([info system] != -1)
479 {
480 propValue = [systemManager getProperty:key forSystem:[info system] inGalaxy:[info galaxy]];
481 } else {
482 propValue = [info valueForKey:key];
483 }
484
485 if (propValue != nil)
486 {
487 if ([propValue isKindOfClass:[NSNumber class]] || OOIsNumberLiteral([propValue description], YES))
488 {
489 BOOL OK = JS_NewNumberValue(context, [propValue doubleValue], value);
490 if (!OK)
491 {
492 *value = JSVAL_VOID;
493 return NO;
494 }
495 }
496 else
497 {
498 *value = [propValue oo_jsValueInContext:context];
499 }
500 }
501 }
502 return YES;
503
505}
BOOL OOIsNumberLiteral(NSString *string, BOOL allowSpaces)
BOOL NSPointToVectorJSValue(JSContext *context, NSPoint point, jsval *outValue) NONNULL_FUNC
Definition OOJSVector.m:246
BOOL VectorToJSValue(JSContext *context, Vector vector, jsval *outValue) NONNULL_FUNC
Definition OOJSVector.m:185
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()

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

Definition at line 564 of file OOJSSystemInfo.m.

565{
566 OOJS_NATIVE_ENTER(context)
567
568 OOSystemInfo *thisInfo = nil;
569 JSObject *otherObj = NULL;
570 OOSystemInfo *otherInfo = nil;
571 NSDictionary *result = nil;
573
574 if (!JSSystemInfoGetSystemInfo(context, OOJS_THIS, &thisInfo)) return NO;
575 if (argc < 1 || !JS_ValueToObject(context, OOJS_ARGV[0], &otherObj) || !JSSystemInfoGetSystemInfo(context, otherObj, &otherInfo))
576 {
577 OOJSReportBadArguments(context, @"SystemInfo", @"routeToSystem", MIN(argc, 1U), OOJS_ARGV, nil, @"system info");
578 return NO;
579 }
580
581 BOOL sameGalaxy = ([thisInfo galaxy] == [otherInfo galaxy]);
582 if (!sameGalaxy)
583 {
584 OOJSReportErrorForCaller(context, @"SystemInfo", @"routeToSystem", @"Cannot calculate route for destinations in other galaxies.");
585 return NO;
586 }
587
588 if (argc >= 2)
589 {
590 routeType = StringToRouteType(OOStringFromJSValue(context, OOJS_ARGV[1]));
591 }
592
594 result = [UNIVERSE routeFromSystem:[thisInfo system] toSystem:[otherInfo system] optimizedBy:routeType];
596
597 OOJS_RETURN_OBJECT(result);
598
600}
OORouteType StringToRouteType(NSString *string)
#define OOJS_RETURN_OBJECT(o)
NSString * OOStringFromJSValue(JSContext *context, jsval value)
OORouteType
Definition OOTypes.h:33
@ OPTIMIZED_BY_JUMPS
Definition OOTypes.h:35

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()

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

Definition at line 604 of file OOJSSystemInfo.m.

605{
606 OOJS_NATIVE_ENTER(context)
607
608 OOSystemInfo *thisInfo = nil;
609
610 if (!JSSystemInfoGetSystemInfo(context, OOJS_THIS, &thisInfo)) return NO;
611 OOCommodityType commodity = OOStringFromJSValue(context, OOJS_ARGV[0]);
612 if (EXPECT_NOT(![[UNIVERSE commodities] goodDefined:commodity]))
613 {
614 OOJSReportBadArguments(context, @"SystemInfo", @"samplePrice", MIN(argc, 1U), OOJS_ARGV, NULL, @"Unrecognised commodity type");
615 return NO;
616 }
617
618 BOOL sameGalaxy = ([thisInfo galaxy] == [PLAYER galaxyNumber]);
619 if (!sameGalaxy)
620 {
621 OOJSReportErrorForCaller(context, @"SystemInfo", @"samplePrice", @"Cannot calculate sample price for destinations in other galaxies.");
622 return NO;
623 }
624
625 OOCreditsQuantity price = [[UNIVERSE commodities] samplePriceForCommodity:commodity inEconomy:[[thisInfo valueForKey:@"economy"] intValue] withScript:[thisInfo valueForKey:@"commodity_script"] inSystem:[thisInfo system]];
626
627 return JS_NewNumberValue(context, price, &OOJS_RVAL);
628
630}
#define OOJS_RVAL
NSString * OOCommodityType
Definition OOTypes.h:106
uint64_t OOCreditsQuantity
Definition OOTypes.h:182
#define UNIVERSE
Definition Universe.h:833
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()

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

Definition at line 508 of file OOJSSystemInfo.m.

509{
510 if (EXPECT_NOT(this == sSystemInfoPrototype))
511 {
512 // Let SpiderMonkey handle access to the prototype object (where info will be nil).
513 return YES;
514 }
515
516 OOJS_NATIVE_ENTER(context);
517
518 if (JSID_IS_STRING(propID))
519 {
520 NSString *key = OOStringFromJSString(context, JSID_TO_STRING(propID));
521 OOSystemInfo *info = OOJSNativeObjectOfClassFromJSObject(context, this, [OOSystemInfo class]);
522
523 [info setValue:OOStringFromJSValue(context, *value) forKey:key];
524 }
525 return YES;
526
528}
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()

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

Definition at line 633 of file OOJSSystemInfo.m.

634{
635 OOJS_NATIVE_ENTER(context)
636
637 OOSystemInfo *thisInfo = nil;
638
639 if (!JSSystemInfoGetSystemInfo(context, OOJS_THIS, &thisInfo)) return NO;
640
641 NSString *property = nil;
642 id value = nil;
643 NSString *manifest = nil;
644
645 int32 iValue;
646
647 if (argc < 3)
648 {
649 OOJSReportBadArguments(context, @"SystemInfo", @"setProperty", MIN(argc, 3U), OOJS_ARGV, NULL, @"setProperty(layer, property, value [,manifest])");
650 return NO;
651 }
652 if (!JS_ValueToInt32(context, OOJS_ARGV[0], &iValue))
653 {
654 OOJSReportBadArguments(context, @"SystemInfo", @"setProperty", MIN(argc, 3U), OOJS_ARGV, NULL, @"setProperty(layer, property, value [,manifest])");
655 return NO;
656 }
657 if (iValue < 0 || iValue >= OO_SYSTEM_LAYERS)
658 {
659 OOJSReportBadArguments(context, @"SystemInfo", @"setProperty", MIN(argc, 3U), OOJS_ARGV, NULL, @"layer must be 0, 1, 2 or 3");
660 return NO;
661 }
662 OOSystemLayer layer = (OOSystemLayer)iValue;
663
664 property = OOStringFromJSValue(context, OOJS_ARGV[1]);
665 if (!JSVAL_IS_NULL(OOJS_ARGV[2]))
666 {
667 value = OOJSNativeObjectFromJSValue(context, OOJS_ARGV[2]);
668 }
669 if (argc >= 4)
670 {
671 manifest = OOStringFromJSValue(context, OOJS_ARGV[3]);
672 }
673 else
674 {
675 manifest = [[OOJSScript currentlyRunningScript] propertyNamed:kLocalManifestProperty];
676 }
677
678 [UNIVERSE setSystemDataForGalaxy:[thisInfo galaxy] planet:[thisInfo system] key:property value:value fromManifest:manifest forLayer:layer];
679
681
683}
id OOJSNativeObjectFromJSValue(JSContext *context, jsval value)
#define OOJS_RETURN_VOID
#define OO_SYSTEM_LAYERS
id propertyNamed:(NSString *name)
Definition OOJSScript.m:491
OOJSScript * currentlyRunningScript()
Definition OOJSScript.m:339

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()

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

Definition at line 687 of file OOJSSystemInfo.m.

688{
689 OOJS_NATIVE_ENTER(context)
690
691 JSObject *jsThis = NULL;
692
693 // Get this and predicate arguments
694 if (argc < 2 || !OOJSValueIsFunction(context, OOJS_ARGV[1]) || !JS_ValueToObject(context, OOJS_ARGV[0], &jsThis))
695 {
696 OOJSReportBadArguments(context, @"SystemInfo", @"filteredSystems", argc, OOJS_ARGV, nil, @"this and predicate function");
697 return NO;
698 }
699 jsval predicate = OOJS_ARGV[1];
700
701 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
702 NSMutableArray *result = [NSMutableArray arrayWithCapacity:256];
703
704 // Not OOJS_BEGIN_FULL_NATIVE() - we use JSAPI while paused.
706
707 // Iterate over systems.
708 BOOL OK = result != nil;
709 OOGalaxyID galaxy = [PLAYER currentGalaxyID];
710 OOSystemID system;
711 for (system = 0; system <= kOOMaximumSystemID; system++)
712 {
713 // NOTE: this deliberately bypasses the cache, since iteration is inherently unfriendly to a single-item cache.
714 OOSystemInfo *info = [[[OOSystemInfo alloc] initWithGalaxy:galaxy system:system] autorelease];
715 jsval args[1] = { OOJSValueFromNativeObject(context, info) };
716
717 jsval rval = JSVAL_VOID;
719 OK = JS_CallFunctionValue(context, jsThis, predicate, 1, args, &rval);
721
722 if (OK)
723 {
724 if (JS_IsExceptionPending(context))
725 {
726 JS_ReportPendingException(context);
727 OK = NO;
728 }
729 }
730
731 if (OK)
732 {
733 JSBool boolVal;
734 if (JS_ValueToBoolean(context, rval, &boolVal) && boolVal)
735 {
736 [result addObject:info];
737 }
738 }
739
740 if (!OK) break;
741 }
742
743 if (OK)
744 {
745 OOJS_SET_RVAL([result oo_jsValueInContext:context]);
746 }
747 else
748 {
749 OOJS_SET_RVAL(JSVAL_VOID);
750 }
751
752 [pool release];
753
755 return OK;
756
758}
void OOJSPauseTimeLimiter(void)
#define OOJS_SET_RVAL(v)
OOINLINE BOOL OOJSValueIsFunction(JSContext *context, jsval value)
void OOJSResumeTimeLimiter(void)
int16_t OOSystemID
Definition OOTypes.h:211
uint8_t OOGalaxyID
Definition OOTypes.h:210
@ kOOMaximumSystemID
Definition OOTypes.h:217

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()

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

Definition at line 761 of file OOJSSystemInfo.m.

762{
763 OOJS_NATIVE_ENTER(context)
764
765 NSString *property = nil;
766 id value = nil;
767 NSString *manifest = nil;
768
769 int32 iValue;
770 OOGalaxyID g;
771 OOSystemID s1,s2;
772
773 if (argc < 6)
774 {
775 OOJSReportBadArguments(context, @"SystemInfo", @"setInterstellarProperty", MIN(argc, 3U), OOJS_ARGV, NULL, @"setProperty(galaxy, fromsystem, tosystem, layer, property, value [,manifest])");
776 return NO;
777 }
778 if (!JS_ValueToInt32(context, OOJS_ARGV[0], &iValue))
779 {
780 OOJSReportBadArguments(context, @"SystemInfo", @"setInterstellarProperty", MIN(argc, 3U), OOJS_ARGV, NULL, @"setProperty(galaxy, fromsystem, tosystem, layer, property, value [,manifest])");
781 return NO;
782 }
783 if (iValue < 0 || iValue > kOOMaximumGalaxyID)
784 {
785 OOJSReportBadArguments(context, @"SystemInfo", @"setInterstellarProperty", MIN(argc, 3U), OOJS_ARGV, NULL, @"galaxy out of range");
786 return NO;
787 }
788 else
789 {
790 g = (OOGalaxyID)iValue;
791 }
792
793 if (!JS_ValueToInt32(context, OOJS_ARGV[1], &iValue))
794 {
795 OOJSReportBadArguments(context, @"SystemInfo", @"setInterstellarProperty", MIN(argc, 3U), OOJS_ARGV, NULL, @"setProperty(galaxy, fromsystem, tosystem, layer, property, value [,manifest])");
796 return NO;
797 }
798 if (iValue < 0 || iValue > kOOMaximumSystemID)
799 {
800 OOJSReportBadArguments(context, @"SystemInfo", @"setInterstellarProperty", MIN(argc, 3U), OOJS_ARGV, NULL, @"fromsystem out of range");
801 return NO;
802 }
803 else
804 {
805 s1 = (OOSystemID)iValue;
806 }
807
808 if (!JS_ValueToInt32(context, OOJS_ARGV[2], &iValue))
809 {
810 OOJSReportBadArguments(context, @"SystemInfo", @"setInterstellarProperty", MIN(argc, 3U), OOJS_ARGV, NULL, @"setProperty(galaxy, fromsystem, tosystem, layer, property, value [,manifest])");
811 return NO;
812 }
813 if (iValue < 0 || iValue > kOOMaximumSystemID)
814 {
815 OOJSReportBadArguments(context, @"SystemInfo", @"setInterstellarProperty", MIN(argc, 3U), OOJS_ARGV, NULL, @"tosystem out of range");
816 return NO;
817 }
818 else
819 {
820 s2 = (OOSystemID)iValue;
821 }
822
823 if (!JS_ValueToInt32(context, OOJS_ARGV[3], &iValue))
824 {
825 OOJSReportBadArguments(context, @"SystemInfo", @"setInterstellarProperty", MIN(argc, 3U), OOJS_ARGV, NULL, @"setProperty(galaxy, fromsystem, tosystem, layer, property, value [,manifest])");
826 return NO;
827 }
828 if (iValue < 0 || iValue >= OO_SYSTEM_LAYERS)
829 {
830 OOJSReportBadArguments(context, @"SystemInfo", @"setInterstellarProperty", MIN(argc, 3U), OOJS_ARGV, NULL, @"layer must be 0, 1, 2 or 3");
831 return NO;
832 }
833 OOSystemLayer layer = (OOSystemLayer)iValue;
834
835 property = OOStringFromJSValue(context, OOJS_ARGV[4]);
836 if (!JSVAL_IS_NULL(OOJS_ARGV[5]))
837 {
838 value = OOJSNativeObjectFromJSValue(context, OOJS_ARGV[5]);
839 }
840 if (argc >= 7)
841 {
842 manifest = OOStringFromJSValue(context, OOJS_ARGV[6]);
843 }
844 else
845 {
846 manifest = [[OOJSScript currentlyRunningScript] propertyNamed:kLocalManifestProperty];
847 }
848
849 NSString *key = [NSString stringWithFormat:@"interstellar: %u %u %u",g,s1,s2];
850
851 [[UNIVERSE systemManager] setProperty:property forSystemKey:key andLayer:layer toValue:value fromManifest:manifest];
852
854
856}
@ kOOMaximumGalaxyID
Definition OOTypes.h:216

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 38 of file OOJSSystemInfo.m.

Referenced by GetJSSystemInfoForSystem().

◆ sCachedSystem

OOSystemID sCachedSystem
static

Definition at line 39 of file OOJSSystemInfo.m.

Referenced by GetJSSystemInfoForSystem().

◆ sCachedSystemInfo

JSObject* sCachedSystemInfo
static

Definition at line 37 of file OOJSSystemInfo.m.

Referenced by GetJSSystemInfoForSystem(), and SystemInfoFinalize().

◆ 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 57 of file OOJSSystemInfo.m.

58{
59 "SystemInfo",
60 JSCLASS_HAS_PRIVATE | JSCLASS_NEW_ENUMERATE,
61
62 JS_PropertyStub,
66 (JSEnumerateOp)SystemInfoEnumerate,
67 JS_ResolveStub,
68 JS_ConvertStub,
70 JSCLASS_NO_OPTIONAL_MEMBERS
71};

Referenced by 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 95 of file OOJSSystemInfo.m.

96{
97 // JS name Function min args
98 { "toString", OOJSObjectWrapperToString, 0 },
99 { "distanceToSystem", SystemInfoDistanceToSystem, 1 },
100 { "routeToSystem", SystemInfoRouteToSystem, 1 },
101 { "samplePrice", SystemInfoSamplePrice, 1 },
102 { "setProperty", SystemInfoSetPropertyMethod, 3 },
103 { 0 }
104};

Referenced by InitOOJSSystemInfo().

◆ sSystemInfoProperties

JSPropertySpec sSystemInfoProperties[]
static
Initial value:

Definition at line 84 of file OOJSSystemInfo.m.

85{
86 // JS name ID flags
91 { 0 }
92};

Referenced by InitOOJSSystemInfo(), 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 107 of file OOJSSystemInfo.m.

108{
109 // JS name Function min args
110 { "filteredSystems", SystemInfoStaticFilteredSystems, 2 },
111 { "setInterstellarProperty",SystemInfoStaticSetInterstellarProperty, 4 },
112 { 0 }
113};

Referenced by InitOOJSSystemInfo().