Oolite
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
OOSystemDescriptionEntry * interstellarSpace
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 68 of file OOSystemDescriptionManager.h.

Method Documentation

◆ buildRouteCache

- (void) buildRouteCache

Definition at line 96 of file OOSystemDescriptionManager.m.

97{
98 NSUInteger i, j, k, jIndex, kIndex;
99 // firstly, cache all coordinates
100 for (i = 0; i < OO_SYSTEM_CACHE_LENGTH; i++) {
101 coordinatesCache[i] = PointFromString([propertyCache[i] oo_stringForKey:@"coordinates"]);
102 }
103 // now for each system find its neighbours
104 for (i = 0; i < OO_GALAXIES_AVAILABLE; i++) {
105 // one galaxy at a time
106 for (j = 0; j < OO_SYSTEMS_PER_GALAXY; j++) {
107 jIndex = j + (i * OO_SYSTEMS_PER_GALAXY);
108 for (k = j + 1; k < OO_SYSTEMS_PER_GALAXY; k++) {
109 kIndex = k + (i * OO_SYSTEMS_PER_GALAXY);
111 // arrays are of system number only
112 [neighbourCache[jIndex] addObject:[NSNumber numberWithUnsignedInteger:k]];
113 [neighbourCache[kIndex] addObject:[NSNumber numberWithUnsignedInteger:j]];
114 }
115 }
116 }
117 }
118}
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:109
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 buildRouteCache, coordinatesCache, distanceBetweenPlanetPositions(), MAX_JUMP_RANGE, OO_GALAXIES_AVAILABLE, OO_SYSTEM_CACHE_LENGTH, OO_SYSTEMS_PER_GALAXY, PointFromString(), propertyCache, x, and y.

Referenced by buildRouteCache, and ResourceManager::systemDescriptionManager.

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

◆ calculatePropertiesForSystemKey:

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

Provided by category OOSystemDescriptionManager(OOPrivate).

Definition at line 424 of file OOSystemDescriptionManager.m.

424 :(NSString*)key
425{
426 NSMutableDictionary* dict = [NSMutableDictionary dictionaryWithCapacity:OO_LIKELY_PROPERTIES_PER_SYSTEM];
427 NSString* property = nil;
428 id val = nil;
429 BOOL interstellar = [key hasPrefix:@"interstellar:"];
430 foreach (property, propertiesInUse) {
431 // don't use universal properties on interstellar specific regions
432 val = [self getProperty:property forSystemKey:key withUniversal:!interstellar];
433
434 if (val != nil) {
435 [dict setObject:val forKey:property];
436 } else if (interstellar) {
437 // interstellar is always overridden by specific regions
438 // universal properties for interstellar get picked up here
439 val = [self getProperty:property forSystemKey:@"interstellar"];
440 if (val != nil) {
441 [dict setObject:val forKey:property];
442 }
443 }
444 }
445 return dict;
446}
return nil

References getProperty:forSystemKey:, getProperty:forSystemKey:withUniversal:, and nil.

Referenced by getPropertiesForSystemKey:, and OOSystemDescriptionManager(OOPrivate)::updateCacheEntry:.

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

◆ dealloc

- (void) dealloc
implementation

Definition at line 82 of file OOSystemDescriptionManager.m.

83{
87 for (NSUInteger i = 0; i < OO_SYSTEM_CACHE_LENGTH; i++) {
90 }
93 [super dealloc];
94}
#define DESTROY(x)
NSMutableArray * neighbourCache[OO_SYSTEM_CACHE_LENGTH]
NSMutableDictionary * universalProperties
OOSystemDescriptionEntry * interstellarSpace

References dealloc, DESTROY, interstellarSpace, neighbourCache, OO_SYSTEM_CACHE_LENGTH, propertiesInUse, propertyCache, scriptedChanges, systemDescriptions, and universalProperties.

Referenced by dealloc.

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

◆ exportScriptedChanges

- (NSDictionary *) exportScriptedChanges

Definition at line 271 of file OOSystemDescriptionManager.m.

272{
273 return [[scriptedChanges copy] autorelease];
274}

References exportScriptedChanges.

Referenced by exportScriptedChanges.

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

◆ getCoordinatesForSystem:inGalaxy:

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

Definition at line 470 of file OOSystemDescriptionManager.m.

470 :(OOSystemID)s inGalaxy:(OOGalaxyID)g
471{
472 if (s < 0) {
473 OOLog(@"system.description.error", @"'%d %d' is an invalid system key. This is an internal error. Please report it.", g, s);
474 return (NSPoint) { 0, 0 };
475 }
476 NSUInteger index = (g * OO_SYSTEMS_PER_GALAXY) + s;
477 if (index >= OO_SYSTEM_CACHE_LENGTH) {
478 OOLog(@"system.description.error", @"'%d %d' is an invalid system key. This is an internal error. Please report it.", g, s);
479 return (NSPoint) { 0, 0 };
480 }
481 return coordinatesCache[index];
482}
#define OOLog(class, format,...)
Definition OOLogging.h:84
int16_t OOSystemID
Definition OOTypes.h:183
uint8_t OOGalaxyID
Definition OOTypes.h:182

References coordinatesCache, OO_SYSTEM_CACHE_LENGTH, OO_SYSTEMS_PER_GALAXY, and OOLog.

Referenced by Universe::coordinatesForSystem:, GuiDisplayGen(Internal)::drawAdvancedNavArrayAtX:y:z:alpha:usingRoute:optimizedBy:zoom:, GuiDisplayGen(Internal)::drawStarChart:y:z:alpha:compact:, Universe::findConnectedSystemAtCoords:withGalaxy:, Universe::findNeighbouringSystemToCoords:withGalaxy:, Universe::findSystemCoordinatesWithPrefix:exactMatch:, Universe::findSystemNumberAtCoords:withGalaxy:includingHidden:, and Universe::routeFromSystem:toSystem:optimizedBy:.

Here is the caller graph for this function:

◆ getNeighbourIDsForSystem:inGalaxy:

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

Definition at line 484 of file OOSystemDescriptionManager.m.

484 :(OOSystemID)s inGalaxy:(OOGalaxyID)g
485{
486 if (s < 0) {
487 OOLog(@"system.description.error", @"'%d %d' is an invalid system key. This is an internal error. Please report it.", g, s);
488 return nil;
489 }
490 NSUInteger index = (g * OO_SYSTEMS_PER_GALAXY) + s;
491 if (index >= OO_SYSTEM_CACHE_LENGTH) {
492 OOLog(@"system.description.error", @"'%d %d' is an invalid system key. This is an internal error. Please report it.", g, s);
493 return nil;
494 }
495
496 return neighbourCache[index];
497}

References neighbourCache, nil, OO_SYSTEM_CACHE_LENGTH, OO_SYSTEMS_PER_GALAXY, and OOLog.

Referenced by Universe::neighboursToSystem:.

Here is the caller graph for this function:

◆ getPropertiesForCurrentSystem

- (NSDictionary *) getPropertiesForCurrentSystem

Definition at line 276 of file OOSystemDescriptionManager.m.

277{
278 OOSystemID s = [UNIVERSE currentSystemID];
279 if (s >= 0) {
280 NSUInteger index = ([PLAYER galaxyNumber] * OO_SYSTEMS_PER_GALAXY) + s;
281 if (index >= OO_SYSTEM_CACHE_LENGTH) {
282 OOLog(@"system.description.error", @"'%zu' is an invalid system index for the current system. This is an internal error. Please report it.", index);
283 return [NSDictionary dictionary];
284 }
285 return propertyCache[index];
286 } else {
287 OOLog(@"system.description.error", @"%@", @"getPropertiesForCurrentSystem called while player in interstellar space. This is an internal error. Please report it.");
288 // this shouldn't be called for interstellar space
289 return [NSDictionary dictionary];
290 }
291}

References getPropertiesForCurrentSystem, OO_SYSTEM_CACHE_LENGTH, OO_SYSTEMS_PER_GALAXY, OOLog, and propertyCache.

Referenced by getPropertiesForCurrentSystem, Universe::populateNormalSpace, Universe::setSystemDataForGalaxy:planet:key:value:fromManifest:forLayer:, Universe::setUpPlanet, and Universe::setUpSpace.

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

◆ getPropertiesForSystem:inGalaxy:

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

Definition at line 310 of file OOSystemDescriptionManager.m.

310 :(OOSystemID)s inGalaxy:(OOGalaxyID)g
311{
312 NSUInteger index = (g * OO_SYSTEMS_PER_GALAXY) + s;
313 if (index >= OO_SYSTEM_CACHE_LENGTH) {
314 OOLog(@"system.description.error", @"'%u, %u' is an invalid system. This is an internal error. Please report it.", g, s);
315 return [NSDictionary dictionary];
316 }
317 return propertyCache[index];
318}

References OO_SYSTEM_CACHE_LENGTH, OO_SYSTEMS_PER_GALAXY, OOLog, and propertyCache.

Referenced by GuiDisplayGen(Internal)::drawAdvancedNavArrayAtX:y:z:alpha:usingRoute:optimizedBy:zoom:, GuiDisplayGen(Internal)::drawStarChart:y:z:alpha:compact:, Universe::findSystemCoordinatesWithPrefix:exactMatch:, Universe::findSystemNumberAtCoords:withGalaxy:includingHidden:, and Universe::routeFromSystem:toSystem:optimizedBy:.

Here is the caller graph for this function:

◆ getPropertiesForSystemKey:

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

Definition at line 293 of file OOSystemDescriptionManager.m.

293 :(NSString*)key
294{
295 NSArray* tokens = ScanTokensFromString(key);
296 if ([tokens count] == 2 && [tokens oo_unsignedIntegerAtIndex:0] < OO_GALAXIES_AVAILABLE && [tokens oo_unsignedIntegerAtIndex:1] < OO_SYSTEMS_PER_GALAXY) {
297 OOGalaxyID g = [tokens oo_unsignedIntegerAtIndex:0];
298 OOSystemID s = [tokens oo_unsignedIntegerAtIndex:1];
299 NSUInteger index = (g * OO_SYSTEMS_PER_GALAXY) + s;
300 if (index >= OO_SYSTEM_CACHE_LENGTH) {
301 OOLog(@"system.description.error", @"'%@' is an invalid system key. This is an internal error. Please report it.", key);
302 return [NSDictionary dictionary];
303 }
304 return propertyCache[index];
305 }
306 // interstellar spaces aren't cached
307 return [self calculatePropertiesForSystemKey:key];
308}
unsigned count
NSMutableArray * ScanTokensFromString(NSString *values)

References calculatePropertiesForSystemKey:, count, OO_GALAXIES_AVAILABLE, OO_SYSTEM_CACHE_LENGTH, OO_SYSTEMS_PER_GALAXY, OOLog, propertyCache, and ScanTokensFromString().

Referenced by Universe::generateSystemData:useCache:, Universe::generateSystemDataForGalaxy:planet:, and Universe::setUpWitchspaceBetweenSystem:andSystem:.

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

◆ getProperty:forSystem:inGalaxy:

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

Definition at line 325 of file OOSystemDescriptionManager.m.

325 :(NSString*)property forSystem:(OOSystemID)s inGalaxy:(OOGalaxyID)g
326{
327 if (s < 0) {
328 OOLog(@"system.description.error", @"'%d %d' is an invalid system key. This is an internal error. Please report it.", g, s);
329 return nil;
330 }
331 NSUInteger index = (g * OO_SYSTEMS_PER_GALAXY) + s;
332 if (index >= OO_SYSTEM_CACHE_LENGTH) {
333 OOLog(@"system.description.error", @"'%d %d' is an invalid system key. This is an internal error. Please report it.", g, s);
334 return nil;
335 }
336 return [propertyCache[index] objectForKey:property];
337}

References nil, OO_SYSTEM_CACHE_LENGTH, OO_SYSTEMS_PER_GALAXY, and OOLog.

Referenced by Universe::getSystemGovernment:, Universe::getSystemInhabitants:plural:, Universe::getSystemName:forGalaxy:, Universe::setGalaxyTo:andReinit:, Universe::systemDataForGalaxy:planet:key:, SystemInfoGetProperty(), and SystemInfoGetSystemDataValue().

Here is the caller graph for this function:

◆ getProperty:forSystemKey:

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

Definition at line 320 of file OOSystemDescriptionManager.m.

320 :(NSString*)property forSystemKey:(NSString*)key
321{
322 return [self getProperty:property forSystemKey:key withUniversal:YES];
323}

References getProperty:forSystemKey:withUniversal:.

Referenced by OOSystemDescriptionManager(OOPrivate)::calculatePropertiesForSystemKey:, GuiDisplayGen(Internal)::drawAdvancedNavArrayAtX:y:z:alpha:usingRoute:optimizedBy:zoom:, importLegacyScriptedChanges:, and OOSystemDescriptionManager(OOPrivate)::updateCacheEntry:forProperty:.

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

◆ getProperty:forSystemKey:withUniversal:

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

Provided by category OOSystemDescriptionManager(OOPrivate).

Definition at line 339 of file OOSystemDescriptionManager.m.

339 :(NSString*)property forSystemKey:(NSString*)key withUniversal:(BOOL)universal
340{
341 OOSystemDescriptionEntry* desc = nil;
342 if (EXPECT_NOT([key isEqualToString:@"interstellar"])) {
343 desc = interstellarSpace;
344 } else {
345 desc = [systemDescriptions objectForKey:key];
346 }
347 if (desc == nil) {
348 return nil;
349 }
350 id result = nil;
351 result = [desc getProperty:property forLayer:OO_LAYER_OXP_PRIORITY];
352 if (result == nil) {
353 result = [desc getProperty:property forLayer:OO_LAYER_OXP_DYNAMIC];
354 }
355 if (result == nil) {
356 result = [desc getProperty:property forLayer:OO_LAYER_OXP_STATIC];
357 }
358 if (result == nil && universal) {
359 result = [universalProperties objectForKey:property];
360 }
361 if (result == nil) {
362 result = [desc getProperty:property forLayer:OO_LAYER_CORE];
363 }
364 return result;
365}
#define EXPECT_NOT(x)
id getProperty:forLayer:(NSString *property,[forLayer] OOSystemLayer layer)

References EXPECT_NOT, OOSystemDescriptionEntry::getProperty:forLayer:, and nil.

Referenced by OOSystemDescriptionManager(OOPrivate)::calculatePropertiesForSystemKey:, and getProperty:forSystemKey:.

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

◆ 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 367 of file OOSystemDescriptionManager.m.

367 :(NSString*)property1 orProperty:(NSString*)property2 forSystemKey:(NSString*)key withUniversal:(BOOL)universal
368{
369 OOSystemDescriptionEntry* desc = [systemDescriptions objectForKey:key];
370 if (desc == nil) {
371 return nil;
372 }
373 id result = nil;
374 result = [desc getProperty:property1 forLayer:OO_LAYER_OXP_PRIORITY];
375 if (result == nil) {
376 result = [desc getProperty:property2 forLayer:OO_LAYER_OXP_PRIORITY];
377 }
378 if (result == nil) {
379 result = [desc getProperty:property1 forLayer:OO_LAYER_OXP_DYNAMIC];
380 }
381 if (result == nil) {
382 result = [desc getProperty:property2 forLayer:OO_LAYER_OXP_DYNAMIC];
383 }
384 if (result == nil) {
385 result = [desc getProperty:property1 forLayer:OO_LAYER_OXP_STATIC];
386 }
387 if (result == nil) {
388 result = [desc getProperty:property2 forLayer:OO_LAYER_OXP_STATIC];
389 }
390 if (universal) {
391 if (result == nil) {
392 result = [universalProperties objectForKey:property1];
393 }
394 if (result == nil) {
395 result = [universalProperties objectForKey:property2];
396 }
397 }
398 if (result == nil) {
399 result = [desc getProperty:property1 forLayer:OO_LAYER_CORE];
400 }
401 if (result == nil) {
402 result = [desc getProperty:property2 forLayer:OO_LAYER_CORE];
403 }
404 return result;
405}

References OOSystemDescriptionEntry::getProperty:forLayer:, and nil.

Here is the call graph for this function:

◆ getRandomSeedForCurrentSystem

- (Random_Seed) getRandomSeedForCurrentSystem

Definition at line 499 of file OOSystemDescriptionManager.m.

500{
501 if ([UNIVERSE currentSystemID] < 0) {
502 return kNilRandomSeed;
503 } else {
504 OOSystemID s = [UNIVERSE currentSystemID];
505 NSUInteger index = ([PLAYER galaxyNumber] * OO_SYSTEMS_PER_GALAXY) + s;
506 if (index >= OO_SYSTEM_CACHE_LENGTH) {
507 OOLog(@"system.description.error", @"'%zu' is an invalid system index for the current system. This is an internal error. Please report it.", index);
508 return kNilRandomSeed;
509 }
510 return RandomSeedFromString([propertyCache[index] oo_stringForKey:@"random_seed"]);
511 }
512}
Random_Seed RandomSeedFromString(NSString *abcdefString)
#define UNIVERSE
Definition Universe.h:827
const Random_Seed kNilRandomSeed

References getRandomSeedForCurrentSystem, kNilRandomSeed, OO_SYSTEM_CACHE_LENGTH, OO_SYSTEMS_PER_GALAXY, OOLog, propertyCache, RandomSeedFromString(), and UNIVERSE.

Referenced by getRandomSeedForCurrentSystem, Universe::marketSeed, Universe::populateSystemFromDictionariesWithSun:andPlanet:, Universe::setUpPlanet, and Universe::setUpSpace.

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

◆ getRandomSeedForSystem:inGalaxy:

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

Definition at line 514 of file OOSystemDescriptionManager.m.

514 :(OOSystemID)s inGalaxy:(OOGalaxyID)g
515{
516 if (s < 0) {
517 OOLog(@"system.description.error", @"'%d %d' is an invalid system key. This is an internal error. Please report it.", g, s);
518 return kNilRandomSeed;
519 }
520 NSUInteger index = (g * OO_SYSTEMS_PER_GALAXY) + s;
521 if (index >= OO_SYSTEM_CACHE_LENGTH) {
522 OOLog(@"system.description.error", @"'%d %d' is an invalid system key. This is an internal error. Please report it.", g, s);
523 return kNilRandomSeed;
524 }
525 return RandomSeedFromString([propertyCache[index] oo_stringForKey:@"random_seed"]);
526}

References kNilRandomSeed, OO_SYSTEM_CACHE_LENGTH, OO_SYSTEMS_PER_GALAXY, OOLog, propertyCache, and RandomSeedFromString().

Here is the call graph for this function:

◆ importLegacyScriptedChanges:

- (void) importLegacyScriptedChanges: (NSDictionary*) scripted

Definition at line 235 of file OOSystemDescriptionManager.m.

235 :(NSDictionary*)scripted
236{
237 NSString* systemKey = nil;
238 NSString* propertyKey = nil;
239 NSString* defaultManifest = @"org.oolite.oolite";
240
241 foreachkey(systemKey, scripted)
242 {
243 NSDictionary* legacyChanges = [scripted oo_dictionaryForKey:systemKey];
244 if ([legacyChanges objectForKey:@"sun_gone_nova"] != nil) {
245 // then this is a change to import even if we don't know
246 // if the OXP is still installed
247 foreachkey(propertyKey, legacyChanges)
248 {
249 [self setProperty:propertyKey
250 forSystemKey:systemKey
251 andLayer:OO_LAYER_OXP_DYNAMIC
252 toValue:[legacyChanges objectForKey:propertyKey]
253 fromManifest:defaultManifest];
254 }
255 /* Fix for older savegames not having a larger sun radius
256 * property set from the Nova mission. */
257 id sr = [self getProperty:@"sun_radius" forSystemKey:systemKey];
258 float sr_num = [sr floatValue];
259 if (sr_num < 600000) {
260 // fix sun radius values
261 [self setProperty:@"sun_radius"
262 forSystemKey:systemKey
263 andLayer:OO_LAYER_OXP_DYNAMIC
264 toValue:[NSNumber numberWithFloat:sr_num + 600000.0f]
265 fromManifest:defaultManifest];
266 }
267 }
268 }
269}
#define foreachkey(VAR, DICT)

References foreachkey, getProperty:forSystemKey:, nil, and setProperty:forSystemKey:andLayer:toValue:fromManifest:.

Here is the call graph for this function:

◆ importScriptedChanges:

- (void) importScriptedChanges: (NSDictionary*) scripted

Definition at line 206 of file OOSystemDescriptionManager.m.

206 :(NSDictionary*)scripted
207{
208 NSArray* key = nil;
209 NSString* keyStr = nil;
210 NSString* manifest = nil;
211 foreachkey(keyStr, scripted)
212 {
213 key = [keyStr componentsSeparatedByString:kOOScriptedChangeJoiner];
214 if ([key count] == 4) {
215 manifest = [key oo_stringAtIndex:0];
216 if ([ResourceManager manifestForIdentifier:manifest] != nil) {
217 // OOLog(@"importing",@"%@ -> %@",keyStr,[scripted objectForKey:keyStr]);
218 [self setProperty:[key oo_stringAtIndex:2]
219 forSystemKey:[key oo_stringAtIndex:1]
220 andLayer:[key oo_intAtIndex:3]
221 toValue:[scripted objectForKey:keyStr]
222 fromManifest:manifest];
223 // and doing this set stores it into the manager's copy
224 // of scripted changes
225 // this means in theory we could import more than one
226 }
227 // else OXP not installed, do not load
228 } else {
229 OOLog(@"systemManager.import", @"Key '%@' has unexpected format - skipping", keyStr);
230 }
231 }
232}

References count, foreachkey, nil, OOLog, and setProperty:forSystemKey:andLayer:toValue:fromManifest:.

Here is the call graph for this function:

◆ init

- (id) init
implementation

Definition at line 62 of file OOSystemDescriptionManager.m.

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

References init, interstellarSpace, neighbourCache, nil, OO_SYSTEM_CACHE_LENGTH, propertiesInUse, propertyCache, scriptedChanges, systemDescriptions, and universalProperties.

Referenced by init.

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

◆ 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 188 of file OOSystemDescriptionManager.m.

188 :(NSString*)property forSystemKey:(NSString*)key andLayer:(OOSystemLayer)layer toValue:(id)value fromManifest:(NSString*)manifest
189{
190 // if OXP doesn't have a manifest, cancel saving the change
191 if (manifest == nil) {
192 return;
193 }
194 // OOLog(@"saving change",@"%@ %@ %@ %d",manifest,key,property,layer);
195 NSArray* overrideKey = [NSArray arrayWithObjects:manifest, key, property, [[NSNumber numberWithInt:layer] stringValue], nil];
196 // Obj-C copes with NSArray keys to dictionaries fine, but the
197 // plist format doesn't, so they can't be saved.
198 NSString* overrideKeyStr = [overrideKey componentsJoinedByString:kOOScriptedChangeJoiner];
199 if (value != nil) {
200 [scriptedChanges setObject:value forKey:overrideKeyStr];
201 } else {
202 [scriptedChanges removeObjectForKey:overrideKeyStr];
203 }
204}

References nil.

Referenced by setProperty:forSystemKey:andLayer:toValue:fromManifest:.

Here is the caller graph for this function:

◆ setInterstellarProperties:

- (void) setInterstellarProperties: (NSDictionary*) properties

Definition at line 129 of file OOSystemDescriptionManager.m.

129 :(NSDictionary*)properties
130{
131 [self setProperties:properties inDescription:interstellarSpace];
132}

References setProperties:inDescription:.

Referenced by ResourceManager::systemDescriptionManager.

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

◆ setProperties:forSystemKey:

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

Definition at line 134 of file OOSystemDescriptionManager.m.

134 :(NSDictionary*)properties forSystemKey:(NSString*)key
135{
136 OOSystemDescriptionEntry* desc = [systemDescriptions objectForKey:key];
137 if (desc == nil) {
138 // create it
139 desc = [[[OOSystemDescriptionEntry alloc] init] autorelease];
140 [systemDescriptions setObject:desc forKey:key];
141 }
142 [self setProperties:properties inDescription:desc];
143 [propertiesInUse addObjectsFromArray:[properties allKeys]];
144
145 NSArray* tokens = ScanTokensFromString(key);
146 if ([tokens count] == 2 && [tokens oo_unsignedIntegerAtIndex:0] < OO_GALAXIES_AVAILABLE && [tokens oo_unsignedIntegerAtIndex:1] < OO_SYSTEMS_PER_GALAXY) {
147 OOGalaxyID g = [tokens oo_unsignedIntegerAtIndex:0];
148 OOSystemID s = [tokens oo_unsignedIntegerAtIndex:1];
149 NSUInteger index = (g * OO_SYSTEMS_PER_GALAXY) + s;
150 if (index >= OO_SYSTEM_CACHE_LENGTH) {
151 OOLog(@"system.description.error", @"'%@' is an invalid system key. This is an internal error. Please report it.", key);
152 } else {
153 [self updateCacheEntry:index];
154 }
155 }
156}

References count, nil, OO_GALAXIES_AVAILABLE, OO_SYSTEM_CACHE_LENGTH, OO_SYSTEMS_PER_GALAXY, OOLog, ScanTokensFromString(), setProperties:inDescription:, and updateCacheEntry:.

Referenced by ResourceManager::systemDescriptionManager.

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

◆ setProperties:inDescription:

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

Provided by category OOSystemDescriptionManager(OOPrivate).

Definition at line 407 of file OOSystemDescriptionManager.m.

407 :(NSDictionary*)properties inDescription:(OOSystemDescriptionEntry*)desc
408{
409 OOSystemLayer layer = [properties oo_unsignedIntForKey:kOOSystemLayerProperty defaultValue:OO_LAYER_OXP_STATIC];
410 if (layer > OO_LAYER_OXP_PRIORITY) {
411 OOLog(@"system.description.error", @"Layer %u is not a valid layer number in system information.", layer);
412 layer = OO_LAYER_OXP_PRIORITY;
413 }
414 NSString* key = nil;
415 foreachkey(key, properties)
416 {
417 if (![key isEqualToString:kOOSystemLayerProperty]) {
418 [propertiesInUse addObject:key];
419 [desc setProperty:key forLayer:layer toValue:[properties objectForKey:key]];
420 }
421 }
422}
static NSString * kOOSystemLayerProperty
void setProperty:forLayer:toValue:(NSString *property,[forLayer] OOSystemLayer layer,[toValue] id value)

References foreachkey, kOOSystemLayerProperty, nil, OO_LAYER_OXP_PRIORITY, OOLog, and OOSystemDescriptionEntry::setProperty:forLayer:toValue:.

Referenced by setInterstellarProperties:, and setProperties:forSystemKey:.

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

◆ setProperty:forSystemKey:andLayer:toValue:fromManifest:

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

Definition at line 158 of file OOSystemDescriptionManager.m.

158 :(NSString*)property forSystemKey:(NSString*)key andLayer:(OOSystemLayer)layer toValue:(id)value fromManifest:(NSString*)manifest
159{
160 OOSystemDescriptionEntry* desc = [systemDescriptions objectForKey:key];
161 if (desc == nil) {
162 // create it
163 desc = [[[OOSystemDescriptionEntry alloc] init] autorelease];
164 [systemDescriptions setObject:desc forKey:key];
165 }
166 [desc setProperty:property forLayer:layer toValue:value];
167 [propertiesInUse addObject:property];
168
169 NSArray* tokens = ScanTokensFromString(key);
170 if ([tokens count] == 2 && [tokens oo_unsignedIntegerAtIndex:0] < OO_GALAXIES_AVAILABLE && [tokens oo_unsignedIntegerAtIndex:1] < OO_SYSTEMS_PER_GALAXY) {
171 [self saveScriptedChangeToProperty:property forSystemKey:key andLayer:layer toValue:value fromManifest:manifest];
172
173 OOGalaxyID g = [tokens oo_unsignedIntegerAtIndex:0];
174 OOSystemID s = [tokens oo_unsignedIntegerAtIndex:1];
175 NSUInteger index = (g * OO_SYSTEMS_PER_GALAXY) + s;
176 if (index >= OO_SYSTEM_CACHE_LENGTH) {
177 OOLog(@"system.description.error", @"'%@' is an invalid system key. This is an internal error. Please report it.", key);
178 } else {
179 [self updateCacheEntry:index forProperty:property];
180 }
181 }
182 // for interstellar updates, save but don't update cache
183 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) {
184 [self saveScriptedChangeToProperty:property forSystemKey:key andLayer:layer toValue:value fromManifest:manifest];
185 }
186}

References count, nil, OO_GALAXIES_AVAILABLE, OO_SYSTEM_CACHE_LENGTH, OO_SYSTEMS_PER_GALAXY, OOLog, saveScriptedChangeToProperty:forSystemKey:andLayer:toValue:fromManifest:, ScanTokensFromString(), OOSystemDescriptionEntry::setProperty:forLayer:toValue:, and updateCacheEntry:forProperty:.

Referenced by importLegacyScriptedChanges:, importScriptedChanges:, and Universe::setSystemDataForGalaxy:planet:key:value:fromManifest:forLayer:.

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

◆ setUniversalProperties:

- (void) setUniversalProperties: (NSDictionary*) properties

Definition at line 120 of file OOSystemDescriptionManager.m.

120 :(NSDictionary*)properties
121{
122 [universalProperties addEntriesFromDictionary:properties];
123 [propertiesInUse addObjectsFromArray:[properties allKeys]];
124 for (NSUInteger i = 0; i < OO_SYSTEM_CACHE_LENGTH; i++) {
125 [self updateCacheEntry:i];
126 }
127}

References OO_SYSTEM_CACHE_LENGTH, and updateCacheEntry:.

Referenced by ResourceManager::systemDescriptionManager.

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

◆ updateCacheEntry:

- (void) updateCacheEntry: (NSUInteger) i
implementation

Provided by category OOSystemDescriptionManager(OOPrivate).

Definition at line 448 of file OOSystemDescriptionManager.m.

448 :(NSUInteger)i
449{
450 NSAssert(i < OO_SYSTEM_CACHE_LENGTH, @"Invalid cache entry number");
451 NSString* key = [NSString stringWithFormat:@"%zu %zu", i / OO_SYSTEMS_PER_GALAXY, i % OO_SYSTEMS_PER_GALAXY];
452 NSDictionary* current = [self calculatePropertiesForSystemKey:key];
453
454 [propertyCache[i] removeAllObjects];
455 [propertyCache[i] addEntriesFromDictionary:current];
456}

References calculatePropertiesForSystemKey:, and OO_SYSTEM_CACHE_LENGTH.

Referenced by setProperties:forSystemKey:, and setUniversalProperties:.

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

◆ updateCacheEntry:forProperty:

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

Provided by category OOSystemDescriptionManager(OOPrivate).

Definition at line 458 of file OOSystemDescriptionManager.m.

458 :(NSUInteger)i forProperty:(NSString*)property
459{
460 NSAssert(i < OO_SYSTEM_CACHE_LENGTH, @"Invalid cache entry number");
461 NSString* key = [NSString stringWithFormat:@"%zu %zu", i / OO_SYSTEMS_PER_GALAXY, i % OO_SYSTEMS_PER_GALAXY];
462 id current = [self getProperty:property forSystemKey:key];
463 if (current == nil) {
464 [propertyCache[i] removeObjectForKey:property];
465 } else {
466 [propertyCache[i] setObject:current forKey:property];
467 }
468}

References getProperty:forSystemKey:, nil, and OO_SYSTEM_CACHE_LENGTH.

Referenced by setProperty:forSystemKey:andLayer:toValue:fromManifest:.

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

Member Data Documentation

◆ coordinatesCache

- (NSPoint coordinatesCache[OO_SYSTEM_CACHE_LENGTH])
private

Definition at line 75 of file OOSystemDescriptionManager.h.

Referenced by buildRouteCache, and getCoordinatesForSystem:inGalaxy:.

◆ interstellarSpace

- (OOSystemDescriptionEntry*) interstellarSpace
private

Definition at line 71 of file OOSystemDescriptionManager.h.

Referenced by dealloc, and init.

◆ neighbourCache

- (NSMutableArray* neighbourCache[OO_SYSTEM_CACHE_LENGTH])
private

Definition at line 76 of file OOSystemDescriptionManager.h.

Referenced by dealloc, getNeighbourIDsForSystem:inGalaxy:, and init.

◆ propertiesInUse

- (NSMutableSet*) propertiesInUse
private

Definition at line 74 of file OOSystemDescriptionManager.h.

Referenced by dealloc, and init.

◆ propertyCache

◆ scriptedChanges

- (NSMutableDictionary*) scriptedChanges
private

Definition at line 77 of file OOSystemDescriptionManager.h.

Referenced by dealloc, and init.

◆ systemDescriptions

- (NSMutableDictionary*) systemDescriptions
private

Definition at line 72 of file OOSystemDescriptionManager.h.

Referenced by dealloc, and init.

◆ universalProperties

- (NSMutableDictionary*) universalProperties
private

Definition at line 70 of file OOSystemDescriptionManager.h.

Referenced by dealloc, and init.


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