Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
OOSystemDescriptionManager Class Reference

#include <OOSystemDescriptionManager.h>

+ Inheritance diagram for OOSystemDescriptionManager:
+ Collaboration diagram for OOSystemDescriptionManager:

Instance Methods

(void) - buildRouteCache
 
(void) - setUniversalProperties:
 
(void) - setInterstellarProperties:
 
(void) - setProperties:forSystemKey:
 
(void) - setProperty:forSystemKey:andLayer:toValue:fromManifest:
 
(void) - importScriptedChanges:
 
(void) - importLegacyScriptedChanges:
 
(NSDictionary *) - exportScriptedChanges
 
(NSDictionary *) - getPropertiesForSystemKey:
 
(NSDictionary *) - getPropertiesForSystem:inGalaxy:
 
(NSDictionary *) - getPropertiesForCurrentSystem
 
(id) - getProperty:forSystemKey:
 
(id) - getProperty:forSystem:inGalaxy:
 
(NSPoint) - getCoordinatesForSystem:inGalaxy:
 
(NSArray *) - getNeighbourIDsForSystem:inGalaxy:
 
(Random_Seed- getRandomSeedForCurrentSystem
 
(Random_Seed- getRandomSeedForSystem:inGalaxy:
 
(id) - init [implementation]
 
(void) - dealloc [implementation]
 
(void) - saveScriptedChangeToProperty:forSystemKey:andLayer:toValue:fromManifest: [implementation]
 
(id) - getProperty:forSystemKey:withUniversal: [implementation]
 
(id) - getProperty:orProperty:forSystemKey:withUniversal: [implementation]
 
(void) - setProperties:inDescription: [implementation]
 
(NSDictionary *) - calculatePropertiesForSystemKey: [implementation]
 
(void) - updateCacheEntry: [implementation]
 
(void) - updateCacheEntry:forProperty: [implementation]
 

Private Attributes

NSMutableDictionary * universalProperties
 
OOSystemDescriptionEntryinterstellarSpace
 
NSMutableDictionary * systemDescriptions
 
NSMutableDictionary * propertyCache [OO_SYSTEM_CACHE_LENGTH]
 
NSMutableSet * propertiesInUse
 
NSPoint coordinatesCache [OO_SYSTEM_CACHE_LENGTH]
 
NSMutableArray * neighbourCache [OO_SYSTEM_CACHE_LENGTH]
 
NSMutableDictionary * scriptedChanges
 

Detailed Description

Note: forSystem: inGalaxy: returns from the (fast) propertyCache

forSystemKey calculates the values - but is necessary for interstellar space

Definition at line 73 of file OOSystemDescriptionManager.h.

Method Documentation

◆ buildRouteCache

- (void) buildRouteCache

Definition at line 58 of file OOSystemDescriptionManager.m.

101{
102 NSUInteger i,j,k,jIndex,kIndex;
103 // firstly, cache all coordinates
104 for (i=0;i<OO_SYSTEM_CACHE_LENGTH;i++)
105 {
106 coordinatesCache[i] = PointFromString([propertyCache[i] oo_stringForKey:@"coordinates"]);
107 }
108 // now for each system find its neighbours
109 for (i=0;i<OO_GALAXIES_AVAILABLE;i++)
110 {
111 // one galaxy at a time
112 for (j=0;j<OO_SYSTEMS_PER_GALAXY;j++)
113 {
114 jIndex = j+(i*OO_SYSTEMS_PER_GALAXY);
115 for (k=j+1;k<OO_SYSTEMS_PER_GALAXY;k++)
116 {
117 kIndex = k+(i*OO_SYSTEMS_PER_GALAXY);
119 {
120 // arrays are of system number only
121 [neighbourCache[jIndex] addObject:[NSNumber numberWithUnsignedInteger:k]];
122 [neighbourCache[kIndex] addObject:[NSNumber numberWithUnsignedInteger:j]];
123 }
124 }
125 }
126 }
127
128}
float y
float x
NSPoint PointFromString(NSString *xyString)
#define OO_GALAXIES_AVAILABLE
#define OO_SYSTEM_CACHE_LENGTH
#define OO_SYSTEMS_PER_GALAXY
#define MAX_JUMP_RANGE
Definition ShipEntity.h:107
NSMutableDictionary * propertyCache[OO_SYSTEM_CACHE_LENGTH]
NSPoint coordinatesCache[OO_SYSTEM_CACHE_LENGTH]
OOINLINE double distanceBetweenPlanetPositions(int x1, int y1, int x2, int y2) INLINE_CONST_FUNC

References nil, and OO_SYSTEM_CACHE_LENGTH.

◆ calculatePropertiesForSystemKey:

- (NSDictionary *) calculatePropertiesForSystemKey: (NSString *) key
implementation

Provided by category OOSystemDescriptionManager(OOPrivate).

Definition at line 58 of file OOSystemDescriptionManager.m.

503 :(NSString *)key
504{
505 NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:OO_LIKELY_PROPERTIES_PER_SYSTEM];
506 NSString *property = nil;
507 id val = nil;
508 BOOL interstellar = [key hasPrefix:@"interstellar:"];
509 foreach (property, propertiesInUse)
510 {
511 // don't use universal properties on interstellar specific regions
512 val = [self getProperty:property forSystemKey:key withUniversal:!interstellar];
513
514 if (val != nil)
515 {
516 [dict setObject:val forKey:property];
517 }
518 else if (interstellar)
519 {
520 // interstellar is always overridden by specific regions
521 // universal properties for interstellar get picked up here
522 val = [self getProperty:property forSystemKey:@"interstellar"];
523 if (val != nil)
524 {
525 [dict setObject:val forKey:property];
526 }
527 }
528 }
529 return dict;
530}
return nil

◆ dealloc

- (void) dealloc
implementation

Definition at line 58 of file OOSystemDescriptionManager.m.

85{
89 for (NSUInteger i=0;i<OO_SYSTEM_CACHE_LENGTH;i++)
90 {
93 }
96 [super dealloc];
97}
#define DESTROY(x)
Definition OOCocoa.h:77
NSMutableArray * neighbourCache[OO_SYSTEM_CACHE_LENGTH]
NSMutableDictionary * universalProperties
OOSystemDescriptionEntry * interstellarSpace

◆ exportScriptedChanges

- (NSDictionary *) exportScriptedChanges

Definition at line 58 of file OOSystemDescriptionManager.m.

313{
314 return [[scriptedChanges copy] autorelease];
315}

◆ getCoordinatesForSystem:inGalaxy:

- (NSPoint) getCoordinatesForSystem: (OOSystemID) s
inGalaxy: (OOGalaxyID) g 

Definition at line 58 of file OOSystemDescriptionManager.m.

560 :(OOSystemID)s inGalaxy:(OOGalaxyID)g
561{
562 if (s < 0)
563 {
564 OOLog(@"system.description.error",@"'%d %d' is an invalid system key. This is an internal error. Please report it.",g,s);
565 return (NSPoint){0,0};
566 }
567 NSUInteger index = (g * OO_SYSTEMS_PER_GALAXY) + s;
568 if (index >= OO_SYSTEM_CACHE_LENGTH)
569 {
570 OOLog(@"system.description.error",@"'%d %d' is an invalid system key. This is an internal error. Please report it.",g,s);
571 return (NSPoint){0,0};
572 }
573 return coordinatesCache[index];
574}
#define OOLog(class, format,...)
Definition OOLogging.h:88
int16_t OOSystemID
Definition OOTypes.h:211
uint8_t OOGalaxyID
Definition OOTypes.h:210

◆ getNeighbourIDsForSystem:inGalaxy:

- (NSArray *) getNeighbourIDsForSystem: (OOSystemID) s
inGalaxy: (OOGalaxyID) g 

Definition at line 58 of file OOSystemDescriptionManager.m.

577 :(OOSystemID)s inGalaxy:(OOGalaxyID)g
578{
579 if (s < 0)
580 {
581 OOLog(@"system.description.error",@"'%d %d' is an invalid system key. This is an internal error. Please report it.",g,s);
582 return nil;
583 }
584 NSUInteger index = (g * OO_SYSTEMS_PER_GALAXY) + s;
585 if (index >= OO_SYSTEM_CACHE_LENGTH)
586 {
587 OOLog(@"system.description.error",@"'%d %d' is an invalid system key. This is an internal error. Please report it.",g,s);
588 return nil;
589 }
590
591 return neighbourCache[index];
592}

◆ getPropertiesForCurrentSystem

- (NSDictionary *) getPropertiesForCurrentSystem

Definition at line 58 of file OOSystemDescriptionManager.m.

319{
320 OOSystemID s = [UNIVERSE currentSystemID];
321 if (s >= 0)
322 {
323 NSUInteger index = ([PLAYER galaxyNumber] * OO_SYSTEMS_PER_GALAXY) + s;
324 if (index >= OO_SYSTEM_CACHE_LENGTH)
325 {
326 OOLog(@"system.description.error",@"'%lu' is an invalid system index for the current system. This is an internal error. Please report it.",index);
327 return [NSDictionary dictionary];
328 }
329 return propertyCache[index];
330 }
331 else
332 {
333 OOLog(@"system.description.error", @"%@", @"getPropertiesForCurrentSystem called while player in interstellar space. This is an internal error. Please report it.");
334 // this shouldn't be called for interstellar space
335 return [NSDictionary dictionary];
336 }
337}

◆ getPropertiesForSystem:inGalaxy:

- (NSDictionary *) getPropertiesForSystem: (OOSystemID) s
inGalaxy: (OOGalaxyID) g 

Definition at line 58 of file OOSystemDescriptionManager.m.

360 :(OOSystemID)s inGalaxy:(OOGalaxyID)g
361{
362 NSUInteger index = (g * OO_SYSTEMS_PER_GALAXY) + s;
363 if (index >= OO_SYSTEM_CACHE_LENGTH)
364 {
365 OOLog(@"system.description.error",@"'%u, %u' is an invalid system. This is an internal error. Please report it.",g,s);
366 return [NSDictionary dictionary];
367 }
368 return propertyCache[index];
369}

◆ getPropertiesForSystemKey:

- (NSDictionary *) getPropertiesForSystemKey: (NSString *) key

Definition at line 58 of file OOSystemDescriptionManager.m.

340 :(NSString *)key
341{
342 NSArray *tokens = ScanTokensFromString(key);
343 if ([tokens count] == 2 && [tokens oo_unsignedIntegerAtIndex:0] < OO_GALAXIES_AVAILABLE && [tokens oo_unsignedIntegerAtIndex:1] < OO_SYSTEMS_PER_GALAXY)
344 {
345 OOGalaxyID g = [tokens oo_unsignedIntegerAtIndex:0];
346 OOSystemID s = [tokens oo_unsignedIntegerAtIndex:1];
347 NSUInteger index = (g * OO_SYSTEMS_PER_GALAXY) + s;
348 if (index >= OO_SYSTEM_CACHE_LENGTH)
349 {
350 OOLog(@"system.description.error",@"'%@' is an invalid system key. This is an internal error. Please report it.",key);
351 return [NSDictionary dictionary];
352 }
353 return propertyCache[index];
354 }
355 // interstellar spaces aren't cached
356 return [self calculatePropertiesForSystemKey:key];
357}
unsigned count
NSMutableArray * ScanTokensFromString(NSString *values)

◆ getProperty:forSystem:inGalaxy:

- (id) getProperty: (NSString *) property
forSystem: (OOSystemID) s
inGalaxy: (OOGalaxyID) g 

Definition at line 58 of file OOSystemDescriptionManager.m.

377 :(NSString *)property forSystem:(OOSystemID)s inGalaxy:(OOGalaxyID)g
378{
379 if (s < 0)
380 {
381 OOLog(@"system.description.error",@"'%d %d' is an invalid system key. This is an internal error. Please report it.",g,s);
382 return nil;
383 }
384 NSUInteger index = (g * OO_SYSTEMS_PER_GALAXY) + s;
385 if (index >= OO_SYSTEM_CACHE_LENGTH)
386 {
387 OOLog(@"system.description.error",@"'%d %d' is an invalid system key. This is an internal error. Please report it.",g,s);
388 return nil;
389 }
390 return [propertyCache[index] objectForKey:property];
391}

Referenced by SystemInfoGetProperty().

+ Here is the caller graph for this function:

◆ getProperty:forSystemKey:

- (id) getProperty: (NSString *) property
forSystemKey: (NSString *) key 

Definition at line 58 of file OOSystemDescriptionManager.m.

372 :(NSString *)property forSystemKey:(NSString *)key
373{
374 return [self getProperty:property forSystemKey:key withUniversal:YES];
375}

◆ getProperty:forSystemKey:withUniversal:

- (id) getProperty: (NSString *) property
forSystemKey: (NSString *) key
withUniversal: (BOOL) universal 
implementation

Provided by category OOSystemDescriptionManager(OOPrivate).

Definition at line 58 of file OOSystemDescriptionManager.m.

394 :(NSString *)property forSystemKey:(NSString *)key withUniversal:(BOOL)universal
395{
397 if (EXPECT_NOT([key isEqualToString:@"interstellar"]))
398 {
399 desc = interstellarSpace;
400 }
401 else
402 {
403 desc = [systemDescriptions objectForKey:key];
404 }
405 if (desc == nil)
406 {
407 return nil;
408 }
409 id result = nil;
410 result = [desc getProperty:property forLayer:OO_LAYER_OXP_PRIORITY];
411 if (result == nil)
412 {
413 result = [desc getProperty:property forLayer:OO_LAYER_OXP_DYNAMIC];
414 }
415 if (result == nil)
416 {
417 result = [desc getProperty:property forLayer:OO_LAYER_OXP_STATIC];
418 }
419 if (result == nil && universal)
420 {
421 result = [universalProperties objectForKey:property];
422 }
423 if (result == nil)
424 {
425 result = [desc getProperty:property forLayer:OO_LAYER_CORE];
426 }
427 return result;
428}
#define EXPECT_NOT(x)
id getProperty:forLayer:(NSString *property,[forLayer] OOSystemLayer layer)

◆ getProperty:orProperty:forSystemKey:withUniversal:

- (id) getProperty: (NSString *) property1
orProperty: (NSString *) property2
forSystemKey: (NSString *) key
withUniversal: (BOOL) universal 
implementation

Provided by category OOSystemDescriptionManager(OOPrivate).

Definition at line 58 of file OOSystemDescriptionManager.m.

431 :(NSString *)property1 orProperty:(NSString *)property2 forSystemKey:(NSString *)key withUniversal:(BOOL)universal
432{
433 OOSystemDescriptionEntry *desc = [systemDescriptions objectForKey:key];
434 if (desc == nil)
435 {
436 return nil;
437 }
438 id result = nil;
439 result = [desc getProperty:property1 forLayer:OO_LAYER_OXP_PRIORITY];
440 if (result == nil)
441 {
442 result = [desc getProperty:property2 forLayer:OO_LAYER_OXP_PRIORITY];
443 }
444 if (result == nil)
445 {
446 result = [desc getProperty:property1 forLayer:OO_LAYER_OXP_DYNAMIC];
447 }
448 if (result == nil)
449 {
450 result = [desc getProperty:property2 forLayer:OO_LAYER_OXP_DYNAMIC];
451 }
452 if (result == nil)
453 {
454 result = [desc getProperty:property1 forLayer:OO_LAYER_OXP_STATIC];
455 }
456 if (result == nil)
457 {
458 result = [desc getProperty:property2 forLayer:OO_LAYER_OXP_STATIC];
459 }
460 if (universal)
461 {
462 if (result == nil)
463 {
464 result = [universalProperties objectForKey:property1];
465 }
466 if (result == nil)
467 {
468 result = [universalProperties objectForKey:property2];
469 }
470 }
471 if (result == nil)
472 {
473 result = [desc getProperty:property1 forLayer:OO_LAYER_CORE];
474 }
475 if (result == nil)
476 {
477 result = [desc getProperty:property2 forLayer:OO_LAYER_CORE];
478 }
479 return result;
480}

◆ getRandomSeedForCurrentSystem

- (Random_Seed) getRandomSeedForCurrentSystem

Definition at line 58 of file OOSystemDescriptionManager.m.

596{
597 if ([UNIVERSE currentSystemID] < 0)
598 {
599 return kNilRandomSeed;
600 }
601 else
602 {
603 OOSystemID s = [UNIVERSE currentSystemID];
604 NSUInteger index = ([PLAYER galaxyNumber] * OO_SYSTEMS_PER_GALAXY) + s;
605 if (index >= OO_SYSTEM_CACHE_LENGTH)
606 {
607 OOLog(@"system.description.error",@"'%lu' is an invalid system index for the current system. This is an internal error. Please report it.",(unsigned long)index);
608 return kNilRandomSeed;
609 }
610 return RandomSeedFromString([propertyCache[index] oo_stringForKey:@"random_seed"]);
611 }
612}
Random_Seed RandomSeedFromString(NSString *abcdefString)
#define UNIVERSE
Definition Universe.h:833
const Random_Seed kNilRandomSeed

◆ getRandomSeedForSystem:inGalaxy:

- (Random_Seed) getRandomSeedForSystem: (OOSystemID) s
inGalaxy: (OOGalaxyID) g 

Definition at line 58 of file OOSystemDescriptionManager.m.

615 :(OOSystemID)s inGalaxy:(OOGalaxyID)g
616{
617 if (s < 0)
618 {
619 OOLog(@"system.description.error",@"'%d %d' is an invalid system key. This is an internal error. Please report it.",g,s);
620 return kNilRandomSeed;
621 }
622 NSUInteger index = (g * OO_SYSTEMS_PER_GALAXY) + s;
623 if (index >= OO_SYSTEM_CACHE_LENGTH)
624 {
625 OOLog(@"system.description.error",@"'%d %d' is an invalid system key. This is an internal error. Please report it.",g,s);
626 return kNilRandomSeed;
627 }
628 return RandomSeedFromString([propertyCache[index] oo_stringForKey:@"random_seed"]);
629}

◆ importLegacyScriptedChanges:

- (void) importLegacyScriptedChanges: (NSDictionary *) scripted

Definition at line 58 of file OOSystemDescriptionManager.m.

273 :(NSDictionary *)scripted
274{
275 NSString *systemKey = nil;
276 NSString *propertyKey = nil;
277 NSString *defaultManifest = @"org.oolite.oolite";
278
279 foreachkey(systemKey,scripted)
280 {
281 NSDictionary *legacyChanges = [scripted oo_dictionaryForKey:systemKey];
282 if ([legacyChanges objectForKey:@"sun_gone_nova"] != nil)
283 {
284 // then this is a change to import even if we don't know
285 // if the OXP is still installed
286 foreachkey (propertyKey, legacyChanges)
287 {
288 [self setProperty:propertyKey
289 forSystemKey:systemKey
290 andLayer:OO_LAYER_OXP_DYNAMIC
291 toValue:[legacyChanges objectForKey:propertyKey]
292 fromManifest:defaultManifest];
293 }
294 /* Fix for older savegames not having a larger sun radius
295 * property set from the Nova mission. */
296 id sr = [self getProperty:@"sun_radius" forSystemKey:systemKey];
297 float sr_num = [sr floatValue];
298 if (sr_num < 600000) {
299 // fix sun radius values
300 [self setProperty:@"sun_radius"
301 forSystemKey:systemKey
302 andLayer:OO_LAYER_OXP_DYNAMIC
303 toValue:[NSNumber numberWithFloat:sr_num+600000.0f]
304 fromManifest:defaultManifest];
305 }
306 }
307 }
308
309}
#define foreachkey(VAR, DICT)
Definition OOCocoa.h:366

◆ importScriptedChanges:

- (void) importScriptedChanges: (NSDictionary *) scripted

Definition at line 58 of file OOSystemDescriptionManager.m.

238 :(NSDictionary *)scripted
239{
240 NSArray *key = nil;
241 NSString *keyStr = nil;
242 NSString *manifest = nil;
243 foreachkey(keyStr, scripted)
244 {
245 key = [keyStr componentsSeparatedByString:kOOScriptedChangeJoiner];
246 if ([key count] == 4)
247 {
248 manifest = [key oo_stringAtIndex:0];
249 if ([ResourceManager manifestForIdentifier:manifest] != nil)
250 {
251// OOLog(@"importing",@"%@ -> %@",keyStr,[scripted objectForKey:keyStr]);
252 [self setProperty:[key oo_stringAtIndex:2]
253 forSystemKey:[key oo_stringAtIndex:1]
254 andLayer:[key oo_intAtIndex:3]
255 toValue:[scripted objectForKey:keyStr]
256 fromManifest:manifest];
257 // and doing this set stores it into the manager's copy
258 // of scripted changes
259 // this means in theory we could import more than one
260 }
261 // else OXP not installed, do not load
262 }
263 else
264 {
265 OOLog(@"systemManager.import",@"Key '%@' has unexpected format - skipping",keyStr);
266 }
267 }
268
269}

◆ init

- (id) init
implementation

Definition at line 58 of file OOSystemDescriptionManager.m.

63{
64 self = [super init];
65 if (self != nil)
66 {
67 universalProperties = [[NSMutableDictionary alloc] initWithCapacity:OO_LIKELY_PROPERTIES_PER_SYSTEM];
69 // assume specific interstellar settings are rare
70 systemDescriptions = [[NSMutableDictionary alloc] initWithCapacity:OO_SYSTEM_CACHE_LENGTH+20];
71 for (NSUInteger i=0;i<OO_SYSTEM_CACHE_LENGTH;i++)
72 {
73 propertyCache[i] = [[NSMutableDictionary alloc] initWithCapacity:OO_LIKELY_PROPERTIES_PER_SYSTEM];
74 // hub count of 24 is considerably higher than occurs in
75 // standard planetinfo
76 neighbourCache[i] = [[NSMutableArray alloc] initWithCapacity:24];
77 }
78 propertiesInUse = [[NSMutableSet alloc] initWithCapacity:OO_LIKELY_PROPERTIES_PER_SYSTEM];
79 scriptedChanges = [[NSMutableDictionary alloc] initWithCapacity:64];
80 }
81 return self;
82}

◆ saveScriptedChangeToProperty:forSystemKey:andLayer:toValue:fromManifest:

- (void) saveScriptedChangeToProperty: (NSString *) property
forSystemKey: (NSString *) key
andLayer: (OOSystemLayer) layer
toValue: (id) value
fromManifest: (NSString *) manifest 
implementation

Provided by category OOSystemDescriptionManager(OOPrivate).

Definition at line 58 of file OOSystemDescriptionManager.m.

215 :(NSString *)property forSystemKey:(NSString *)key andLayer:(OOSystemLayer)layer toValue:(id)value fromManifest:(NSString *)manifest
216{
217 // if OXP doesn't have a manifest, cancel saving the change
218 if (manifest == nil)
219 {
220 return;
221 }
222// OOLog(@"saving change",@"%@ %@ %@ %d",manifest,key,property,layer);
223 NSArray *overrideKey = [NSArray arrayWithObjects:manifest,key,property,[[NSNumber numberWithInt:layer] stringValue],nil];
224 // Obj-C copes with NSArray keys to dictionaries fine, but the
225 // plist format doesn't, so they can't be saved.
226 NSString *overrideKeyStr = [overrideKey componentsJoinedByString:kOOScriptedChangeJoiner];
227 if (value != nil)
228 {
229 [scriptedChanges setObject:value forKey:overrideKeyStr];
230 }
231 else
232 {
233 [scriptedChanges removeObjectForKey:overrideKeyStr];
234 }
235}

◆ setInterstellarProperties:

- (void) setInterstellarProperties: (NSDictionary *) properties

Definition at line 58 of file OOSystemDescriptionManager.m.

142 :(NSDictionary *)properties
143{
144 [self setProperties:properties inDescription:interstellarSpace];
145}

◆ setProperties:forSystemKey:

- (void) setProperties: (NSDictionary *) properties
forSystemKey: (NSString *) key 

Definition at line 58 of file OOSystemDescriptionManager.m.

148 :(NSDictionary *)properties forSystemKey:(NSString *)key
149{
150 OOSystemDescriptionEntry *desc = [systemDescriptions objectForKey:key];
151 if (desc == nil)
152 {
153 // create it
154 desc = [[[OOSystemDescriptionEntry alloc] init] autorelease];
155 [systemDescriptions setObject:desc forKey:key];
156 }
157 [self setProperties:properties inDescription:desc];
158 [propertiesInUse addObjectsFromArray:[properties allKeys]];
159
160 NSArray *tokens = ScanTokensFromString(key);
161 if ([tokens count] == 2 && [tokens oo_unsignedIntegerAtIndex:0] < OO_GALAXIES_AVAILABLE && [tokens oo_unsignedIntegerAtIndex:1] < OO_SYSTEMS_PER_GALAXY)
162 {
163 OOGalaxyID g = [tokens oo_unsignedIntegerAtIndex:0];
164 OOSystemID s = [tokens oo_unsignedIntegerAtIndex:1];
165 NSUInteger index = (g * OO_SYSTEMS_PER_GALAXY) + s;
166 if (index >= OO_SYSTEM_CACHE_LENGTH)
167 {
168 OOLog(@"system.description.error",@"'%@' is an invalid system key. This is an internal error. Please report it.",key);
169 }
170 else
171 {
172 [self updateCacheEntry:index];
173 }
174 }
175}

◆ setProperties:inDescription:

- (void) setProperties: (NSDictionary *) properties
inDescription: (OOSystemDescriptionEntry *) desc 
implementation

Provided by category OOSystemDescriptionManager(OOPrivate).

Definition at line 58 of file OOSystemDescriptionManager.m.

483 :(NSDictionary *)properties inDescription:(OOSystemDescriptionEntry *)desc
484{
485 OOSystemLayer layer = [properties oo_unsignedIntForKey:kOOSystemLayerProperty defaultValue:OO_LAYER_OXP_STATIC];
486 if (layer > OO_LAYER_OXP_PRIORITY)
487 {
488 OOLog(@"system.description.error",@"Layer %u is not a valid layer number in system information.",layer);
489 layer = OO_LAYER_OXP_PRIORITY;
490 }
491 NSString *key = nil;
492 foreachkey(key, properties)
493 {
494 if (![key isEqualToString:kOOSystemLayerProperty])
495 {
496 [propertiesInUse addObject:key];
497 [desc setProperty:key forLayer:layer toValue:[properties objectForKey:key]];
498 }
499 }
500}
static NSString * kOOSystemLayerProperty
void setProperty:forLayer:toValue:(NSString *property,[forLayer] OOSystemLayer layer,[toValue] id value)

◆ setProperty:forSystemKey:andLayer:toValue:fromManifest:

- (void) setProperty: (NSString *) property
forSystemKey: (NSString *) key
andLayer: (OOSystemLayer) layer
toValue: (id) value
fromManifest: (NSString *) manifest 

Definition at line 58 of file OOSystemDescriptionManager.m.

178 :(NSString *)property forSystemKey:(NSString *)key andLayer:(OOSystemLayer)layer toValue:(id)value fromManifest:(NSString *)manifest
179{
180 OOSystemDescriptionEntry *desc = [systemDescriptions objectForKey:key];
181 if (desc == nil)
182 {
183 // create it
184 desc = [[[OOSystemDescriptionEntry alloc] init] autorelease];
185 [systemDescriptions setObject:desc forKey:key];
186 }
187 [desc setProperty:property forLayer:layer toValue:value];
188 [propertiesInUse addObject:property];
189
190 NSArray *tokens = ScanTokensFromString(key);
191 if ([tokens count] == 2 && [tokens oo_unsignedIntegerAtIndex:0] < OO_GALAXIES_AVAILABLE && [tokens oo_unsignedIntegerAtIndex:1] < OO_SYSTEMS_PER_GALAXY)
192 {
193 [self saveScriptedChangeToProperty:property forSystemKey:key andLayer:layer toValue:value fromManifest:manifest];
194
195 OOGalaxyID g = [tokens oo_unsignedIntegerAtIndex:0];
196 OOSystemID s = [tokens oo_unsignedIntegerAtIndex:1];
197 NSUInteger index = (g * OO_SYSTEMS_PER_GALAXY) + s;
198 if (index >= OO_SYSTEM_CACHE_LENGTH)
199 {
200 OOLog(@"system.description.error",@"'%@' is an invalid system key. This is an internal error. Please report it.",key);
201 }
202 else
203 {
204 [self updateCacheEntry:index forProperty:property];
205 }
206 }
207 // for interstellar updates, save but don't update cache
208 else if ([tokens count] == 4 && [tokens oo_unsignedIntegerAtIndex:1] < OO_GALAXIES_AVAILABLE && [tokens oo_unsignedIntegerAtIndex:2] < OO_SYSTEMS_PER_GALAXY && [tokens oo_unsignedIntegerAtIndex:3] < OO_SYSTEMS_PER_GALAXY)
209 {
210 [self saveScriptedChangeToProperty:property forSystemKey:key andLayer:layer toValue:value fromManifest:manifest];
211 }
212}

◆ setUniversalProperties:

- (void) setUniversalProperties: (NSDictionary *) properties

Definition at line 58 of file OOSystemDescriptionManager.m.

131 :(NSDictionary *)properties
132{
133 [universalProperties addEntriesFromDictionary:properties];
134 [propertiesInUse addObjectsFromArray:[properties allKeys]];
135 for (NSUInteger i = 0; i<OO_SYSTEM_CACHE_LENGTH; i++)
136 {
137 [self updateCacheEntry:i];
138 }
139}

◆ updateCacheEntry:

- (void) updateCacheEntry: (NSUInteger) i
implementation

Provided by category OOSystemDescriptionManager(OOPrivate).

Definition at line 58 of file OOSystemDescriptionManager.m.

533 :(NSUInteger)i
534{
535 NSAssert(i < OO_SYSTEM_CACHE_LENGTH,@"Invalid cache entry number");
536 NSString *key = [NSString stringWithFormat:@"%lu %lu",i/OO_SYSTEMS_PER_GALAXY,i%OO_SYSTEMS_PER_GALAXY];
537 NSDictionary *current = [self calculatePropertiesForSystemKey:key];
538
539 [propertyCache[i] removeAllObjects];
540 [propertyCache[i] addEntriesFromDictionary:current];
541}

◆ updateCacheEntry:forProperty:

- (void) updateCacheEntry: (NSUInteger) i
forProperty: (NSString *) property 
implementation

Provided by category OOSystemDescriptionManager(OOPrivate).

Definition at line 58 of file OOSystemDescriptionManager.m.

544 :(NSUInteger)i forProperty:(NSString *)property
545{
546 NSAssert(i < OO_SYSTEM_CACHE_LENGTH,@"Invalid cache entry number");
547 NSString *key = [NSString stringWithFormat:@"%lu %lu",i/OO_SYSTEMS_PER_GALAXY,i%OO_SYSTEMS_PER_GALAXY];
548 id current = [self getProperty:property forSystemKey:key];
549 if (current == nil)
550 {
551 [propertyCache[i] removeObjectForKey:property];
552 }
553 else
554 {
555 [propertyCache[i] setObject:current forKey:property];
556 }
557}

Member Data Documentation

◆ coordinatesCache

- (NSPoint coordinatesCache[OO_SYSTEM_CACHE_LENGTH])
private

Definition at line 81 of file OOSystemDescriptionManager.h.

◆ interstellarSpace

- (OOSystemDescriptionEntry*) interstellarSpace
private

Definition at line 77 of file OOSystemDescriptionManager.h.

◆ neighbourCache

- (NSMutableArray* neighbourCache[OO_SYSTEM_CACHE_LENGTH])
private

Definition at line 82 of file OOSystemDescriptionManager.h.

◆ propertiesInUse

- (NSMutableSet*) propertiesInUse
private

Definition at line 80 of file OOSystemDescriptionManager.h.

◆ propertyCache

- (NSMutableDictionary* propertyCache[OO_SYSTEM_CACHE_LENGTH])
private

Definition at line 79 of file OOSystemDescriptionManager.h.

◆ scriptedChanges

- (NSMutableDictionary*) scriptedChanges
private

Definition at line 83 of file OOSystemDescriptionManager.h.

◆ systemDescriptions

- (NSMutableDictionary*) systemDescriptions
private

Definition at line 78 of file OOSystemDescriptionManager.h.

◆ universalProperties

- (NSMutableDictionary*) universalProperties
private

Definition at line 76 of file OOSystemDescriptionManager.h.


The documentation for this class was generated from the following files: