Oolite
Loading...
Searching...
No Matches
OOCacheManager Class Reference

#include <OOCacheManager.h>

Inheritance diagram for OOCacheManager:
Collaboration diagram for OOCacheManager:

Instance Methods

(id) - objectForKey:inCache:
(void) - setObject:forKey:inCache:
(void) - removeObjectForKey:inCache:
(void) - clearCache:
(void) - clearAllCaches
(void) - reloadAllCaches
(void) - setAllowCacheWrites:
(NSString *) - cacheDirectoryPathCreatingIfNecessary:
(void) - flush
(void) - finishOngoingFlush
(id) - init [implementation]
(void) - dealloc [implementation]
(NSString *) - description [implementation]
(NSString *) - cachePathCreatingIfNecessary: [implementation]
(void) - loadCache [implementation]
(void) - write [implementation]
(void) - clear [implementation]
(BOOL) - dirty [implementation]
(void) - markClean [implementation]
(NSDictionary *) - loadDict [implementation]
(BOOL) - writeDict: [implementation]
(void) - buildCachesFromDictionary: [implementation]
(NSDictionary *) - dictionaryOfCaches [implementation]
(BOOL) - directoryExists:create: [implementation]
(id) - copyWithZone: [implementation]
(id) - retain [implementation]
(NSUInteger) - retainCount [implementation]
(void) - release [implementation]
(id) - autorelease [implementation]

Class Methods

(OOCacheManager *) + sharedCache
(Octree *) + octreeForModel:
(void) + setOctree:forModel:
(static void) + VFRAddFace [implementation]
(static NSUInteger) + VFRGetCount [implementation]
(static NSUInteger) + VFRGetFaceAtIndex [implementation]
(NSDictionary *) + meshDataForName: [implementation]
(void) + setMeshData:forName: [implementation]
(id) + allocWithZone: [implementation]

Private Attributes

NSMutableDictionary * _caches
id _scheduledWrite
BOOL _permitWrites
BOOL _dirty

Detailed Description

Definition at line 34 of file OOCacheManager.h.

Method Documentation

◆ allocWithZone:

+ (id) allocWithZone: (NSZone*) inZone
implementation

Provided by category OOCacheManager(Singleton).

Definition at line 594 of file OOCacheManager.m.

594 :(NSZone*)inZone
595{
596 if (sSingleton == nil) {
597 sSingleton = [super allocWithZone:inZone];
598 return sSingleton;
599 }
600 return nil;
601}
static OONullTexture * sSingleton
return nil

◆ autorelease

- (id) autorelease
implementation

Provided by category OOCacheManager(Singleton).

Definition at line 622 of file OOCacheManager.m.

623{
624 return self;
625}

◆ buildCachesFromDictionary:

- (void) buildCachesFromDictionary: (NSDictionary*) inDict
implementation

Provided by category OOCacheManager(Private).

Definition at line 513 of file OOCacheManager.m.

513 :(NSDictionary*)inDict
514{
515 id key = nil;
516 id value = nil;
517 NSMutableDictionary* cache = nil;
518
519 if (inDict == nil)
520 return;
521
522 [_caches release];
523 _caches = [[NSMutableDictionary alloc] initWithCapacity:[inDict count]];
524
525 foreachkey(key, inDict)
526 {
527 value = [inDict oo_dictionaryForKey:key];
528 if (value != nil) {
529 cache = [NSMutableDictionary dictionaryWithDictionary:value];
530 if (cache != nil) {
531 [_caches setObject:cache forKey:key];
532 }
533 }
534 }
535}
#define foreachkey(VAR, DICT)
NSMutableDictionary * _caches

Referenced by OOCacheManager(Private)::loadCache.

Here is the caller graph for this function:

◆ cacheDirectoryPathCreatingIfNecessary:

- (NSString *) cacheDirectoryPathCreatingIfNecessary: (BOOL) create

Definition at line 256 of file OOCacheManager.m.

256 :(BOOL)create
257{
258 /* Construct the path to the directory for cache files, which is:
259 ~/Library/Caches/org.aegidian.oolite/
260 or
261 ~/GNUStep/Library/Caches/org.aegidian.oolite/
262 In addition to generally being the right place to put caches,
263 ~/Library/Caches has the particular advantage of not being indexed by
264 Spotlight or backed up by Time Machine.
265 */
266 NSString* cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
267 if (![self directoryExists:cachePath create:create])
268 return nil;
269
270#if !OOLITE_MAC_OS_X
271 // the old cache file on GNUstep was one level up, so remove it if it exists
272 [[NSFileManager defaultManager] removeFileAtPath:[cachePath stringByAppendingPathComponent:@"Oolite-cache.plist"] handler:nil];
273#endif
274
275 cachePath = [cachePath stringByAppendingPathComponent:@"org.aegidian.oolite"];
276 if (![self directoryExists:cachePath create:create])
277 return nil;
278 return cachePath;
279}

References nil.

Referenced by OOCacheManager(Private)::cachePathCreatingIfNecessary:, OOOXZManager(NSURLConnectionDataDelegate)::downloadPath, and OOOXZManager(NSURLConnectionDataDelegate)::manifestPath.

Here is the caller graph for this function:

◆ cachePathCreatingIfNecessary:

- (NSString *) cachePathCreatingIfNecessary: (BOOL) inCreate
implementation

Provided by category OOCacheManager(Private).

Definition at line 567 of file OOCacheManager.m.

567 :(BOOL)create
568{
569 NSString* cachePath = [self cacheDirectoryPathCreatingIfNecessary:create];
570 return [cachePath stringByAppendingPathComponent:@"Data Cache.plist"];
571}

References cacheDirectoryPathCreatingIfNecessary:.

Referenced by OOCacheManager(Private)::loadDict, and OOCacheManager(Private)::writeDict:.

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

◆ clear

- (void) clear
implementation

Provided by category OOCacheManager(Private).

Definition at line 417 of file OOCacheManager.m.

418{
419 [_caches release];
420 _caches = nil;
421}

Referenced by clearAllCaches, dealloc, OOCacheManager(Private)::loadCache, and reloadAllCaches.

Here is the caller graph for this function:

◆ clearAllCaches

- (void) clearAllCaches

Definition at line 223 of file OOCacheManager.m.

224{
225 [self clear];
226 _caches = [[NSMutableDictionary alloc] init];
227 _dirty = YES;
228}

References _caches, _dirty, clear, and clearAllCaches.

Referenced by ResourceManager::checkCacheUpToDateForPaths:, clearAllCaches, and ResourceManager::setUseAddOns:.

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

◆ clearCache:

- (void) clearCache: (NSString*) inCacheKey

Definition at line 210 of file OOCacheManager.m.

210 :(NSString*)inCacheKey
211{
212 NSParameterAssert(inCacheKey != nil);
213
214 if (nil != [_caches objectForKey:inCacheKey]) {
215 [_caches removeObjectForKey:inCacheKey];
216 _dirty = YES;
217 OODebugLog(kOOLogDataCacheClearSuccess, @"Cleared cache \"%@\".", inCacheKey);
218 } else {
219 OODebugLog(kOOLogDataCacheClearSuccess, @"No need to clear non-existent cache \"%@\".", inCacheKey);
220 }
221}
static NSString *const kOOLogDataCacheClearSuccess
#define OODebugLog(class, format,...)
Definition OOLogging.h:156

References _caches, _dirty, kOOLogDataCacheClearSuccess, nil, and OODebugLog.

◆ copyWithZone:

- (id) copyWithZone: (NSZone*) inZone
implementation

Provided by category OOCacheManager(Singleton).

Definition at line 603 of file OOCacheManager.m.

603 :(NSZone*)inZone
604{
605 return self;
606}

◆ dealloc

- (void) dealloc
implementation

Definition at line 122 of file OOCacheManager.m.

123{
124 [self clear];
125
126 [super dealloc];
127}

References clear, and dealloc.

Referenced by dealloc.

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

◆ description

- (NSString *) description
implementation

Definition at line 129 of file OOCacheManager.m.

130{
131 return [NSString stringWithFormat:@"<%@ %p>{dirty=%s}", [self class], self, [self dirty] ? "yes" : "no"];
132}

References description, and dirty.

Referenced by description.

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

◆ dictionaryOfCaches

- (NSDictionary *) dictionaryOfCaches
implementation

Provided by category OOCacheManager(Private).

Definition at line 537 of file OOCacheManager.m.

538{
539 return [OODeepCopy(_caches) autorelease];
540}

Referenced by OOCacheManager(Private)::write.

Here is the caller graph for this function:

◆ directoryExists:create:

- (BOOL) directoryExists: (NSString*) inPath
create: (BOOL) inCreate 
implementation

Provided by category OOCacheManager(Private).

Definition at line 542 of file OOCacheManager.m.

542 :(NSString*)inPath create:(BOOL)inCreate
543{
544 BOOL exists, directory;
545 NSFileManager* fmgr = [NSFileManager defaultManager];
546
547 exists = [fmgr fileExistsAtPath:inPath isDirectory:&directory];
548
549 if (exists && !directory) {
550 OOLog(kOOLogDataCacheBuildPathError, @"Expected %@ to be a folder, but it is a file.", inPath);
551 return NO;
552 }
553 if (!exists) {
554 if (!inCreate)
555 return NO;
556 if (![fmgr oo_createDirectoryAtPath:inPath attributes:nil]) {
557 OOLog(kOOLogDataCacheBuildPathError, @"Could not create folder %@.", inPath);
558 return NO;
559 }
560 }
561
562 return YES;
563}
static NSString *const kOOLogDataCacheBuildPathError
#define OOLog(class, format,...)
Definition OOLogging.h:84

◆ dirty

- (BOOL) dirty
implementation

Provided by category OOCacheManager(Private).

Definition at line 423 of file OOCacheManager.m.

424{
425 return _dirty;
426}

Referenced by description, and flush.

Here is the caller graph for this function:

◆ finishOngoingFlush

- (void) finishOngoingFlush

Definition at line 244 of file OOCacheManager.m.

245{
246#if WRITE_ASYNC
248#endif
249}
void waitForTaskToComplete:(id< OOAsyncWorkTask > task)
OOAsyncWorkManager * sharedAsyncWorkManager()

References finishOngoingFlush, OOAsyncWorkManager::sharedAsyncWorkManager, and OOAsyncWorkManager::waitForTaskToComplete:.

Referenced by GameController::applicationShouldTerminate:, and finishOngoingFlush.

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

◆ flush

- (void) flush

Definition at line 236 of file OOCacheManager.m.

237{
238 if (_permitWrites && [self dirty] && _scheduledWrite == nil) {
239 [self write];
240 [self markClean];
241 }
242}

References _permitWrites, _scheduledWrite, dirty, flush, markClean, nil, and write.

Referenced by Universe::dealloc, PlayerEntity::docked, flush, OOOXPVerifier(OOPrivate)::run, and PlayerEntity::setGuiToIntroFirstGo:.

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

◆ init

- (id) init
implementation

Definition at line 112 of file OOCacheManager.m.

113{
114 self = [super init];
115 if (self != nil) {
116 _permitWrites = YES;
117 [self loadCache];
118 }
119 return self;
120}

References _permitWrites, init, loadCache, and nil.

Referenced by init.

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

◆ loadCache

- (void) loadCache
implementation

Provided by category OOCacheManager(Private).

Definition at line 285 of file OOCacheManager.m.

286{
287 NSDictionary* cache = nil;
288 NSString* cacheVersion = nil;
289 NSString* ooliteVersion = nil;
290 NSData* endianTag = nil;
291 NSNumber* formatVersion = nil;
292 BOOL accept = YES;
293 uint64_t endianTagValue = 0;
294
295 ooliteVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
296
297 [self clear];
298
299 cache = [self loadDict];
300 if (cache != nil) {
301 // We have a cache
302 OOLog(kOOLogDataCacheFound, @"%@", @"Found data cache.");
304
305 cacheVersion = [cache objectForKey:kCacheKeyVersion];
306 if (![cacheVersion isEqual:ooliteVersion]) {
307 OOLog(kOOLogDataCacheRebuild, @"Data cache version (%@) does not match Oolite version (%@), rebuilding cache.", cacheVersion, ooliteVersion);
308 accept = NO;
309 }
310
311 formatVersion = [cache objectForKey:kCacheKeyFormatVersion];
312 if (accept && [formatVersion unsignedIntValue] != kFormatVersionValue) {
313 OOLog(kOOLogDataCacheRebuild, @"Data cache format (%@) is not supported format (%zu), rebuilding cache.", formatVersion, kFormatVersionValue);
314 accept = NO;
315 }
316
317 if (accept) {
318 endianTag = [cache objectForKey:kCacheKeyEndianTag];
319 if (![endianTag isKindOfClass:[NSData class]] || [endianTag length] != sizeof endianTagValue) {
320 OOLog(kOOLogDataCacheRebuild, @"%@", @"Data cache endian tag is invalid, rebuilding cache.");
321 accept = NO;
322 } else {
323 endianTagValue = *(const uint64_t*)[endianTag bytes];
324 if (endianTagValue != kEndianTagValue) {
325 OOLog(kOOLogDataCacheRebuild, @"%@", @"Data cache endianness is inappropriate for this system, rebuilding cache.");
326 accept = NO;
327 }
328 }
329 }
330
331 if (accept) {
332 // We have a cache, and it's the right format.
333 [self buildCachesFromDictionary:[cache objectForKey:kCacheKeyCaches]];
334 }
335
337 } else {
338 // No cache
339 OOLog(kOOLogDataCacheNotFound, @"%@", @"No data cache found, starting from scratch.");
340 }
341
342 // If loading failed, or there was a version or endianness conflict
343 if (_caches == nil)
344 _caches = [[NSMutableDictionary alloc] init];
345 [self markClean];
346}
@ kFormatVersionValue
@ kEndianTagValue
static NSString *const kOOLogDataCacheRebuild
static NSString *const kOOLogDataCacheNotFound
static NSString *const kOOLogDataCacheFound
#define OOLogOutdentIf(class)
Definition OOLogging.h:112
#define OOLogIndentIf(class)
Definition OOLogging.h:107

Referenced by init, and reloadAllCaches.

Here is the caller graph for this function:

◆ loadDict

- (NSDictionary *) loadDict
implementation

Provided by category OOCacheManager(Private).

Definition at line 433 of file OOCacheManager.m.

434{
435 NSString* path = nil;
436 NSData* data = nil;
437 NSString* errorString = nil;
438 id contents = nil;
439
440 path = [self cachePathCreatingIfNecessary:NO];
441 if (path == nil)
442 return nil;
443
444 @try {
445 data = [NSData dataWithContentsOfFile:path];
446 if (data == nil)
447 return nil;
448
449 contents = [NSPropertyListSerialization propertyListFromData:data
450 mutabilityOption:NSPropertyListImmutable
451 format:NULL
452 errorDescription:&errorString];
453 }
454 @catch (NSException* exception) {
455 errorString = [exception reason];
456 contents = nil;
457 }
458
459 if (errorString != nil) {
460 OOLog(@"dataCache.badData", @"Could not read data cache: %@", errorString);
461#if OOLITE_RELEASE_PLIST_ERROR_STRINGS
462 [errorString release];
463#endif
464 return nil;
465 }
466 if (![contents isKindOfClass:[NSDictionary class]])
467 return nil;
468
469 return contents;
470}

Referenced by OOCacheManager(Private)::loadCache.

Here is the caller graph for this function:

◆ markClean

- (void) markClean
implementation

Provided by category OOCacheManager(Private).

Definition at line 428 of file OOCacheManager.m.

429{
430 _dirty = NO;
431}

Referenced by flush, OOCacheManager(Private)::loadCache, and OOCacheManager(Private)::write.

Here is the caller graph for this function:

◆ meshDataForName:

+ (NSDictionary *) meshDataForName: (NSString*) inShipName
implementation

Provided by category OOCacheManager(OOMesh).

Definition at line 2006 of file OOMesh.m.

2006 :(NSString*)inShipName
2007{
2008 return [[self sharedCache] objectForKey:inShipName inCache:kOOCacheMeshes];
2009}

Referenced by OOMesh(Private)::loadData:scaleFactor:.

Here is the caller graph for this function:

◆ objectForKey:inCache:

- (id) objectForKey: (NSString*) inKey
inCache: (NSString*) inCacheKey 

Definition at line 144 of file OOCacheManager.m.

144 :(NSString*)inKey inCache:(NSString*)inCacheKey
145{
146 NSMutableDictionary* cache = nil;
147 id result = nil;
148
149 NSParameterAssert(inKey != nil && inCacheKey != nil);
150
151 cache = [_caches objectForKey:inCacheKey];
152 if (cache != nil) {
153 result = [cache objectForKey:inKey];
154 if (result != nil) {
155 OODebugLog(kOOLogDataCacheRetrieveSuccess, @"Retrieved \"%@\" cache object %@.", inCacheKey, inKey);
156 } else {
157 OODebugLog(kOOLogDataCacheRetrieveFailed, @"Failed to retrieve \"%@\" cache object %@ -- no such entry.", inCacheKey, inKey);
158 }
159 } else {
160 OODebugLog(kOOLogDataCacheRetrieveFailed, @"Failed to retrieve \"%@\" cache object %@ -- no such cache.", inCacheKey, inKey);
161 }
162
163 return result;
164}
static NSString *const kOOLogDataCacheRetrieveSuccess
static NSString *const kOOLogDataCacheRetrieveFailed

References kOOLogDataCacheRetrieveFailed, kOOLogDataCacheRetrieveSuccess, nil, and OODebugLog.

Referenced by ResourceManager::arrayFromFilesNamed:inFolder:andMerge:cache:, CachedCompiledScript(), ResourceManager::checkCacheUpToDateForPaths:, OOMaterial(OOConvenienceCreators)::defaultShaderMaterialWithName:cacheKey:configuration:macros:bindingTarget:, ResourceManager::dictionaryFromFilesNamed:inFolder:mergeMode:cache:, OOShipRegistry::init, OOShipRegistry(OODataLoader)::loadCachedRoleProbabilitySets, Universe::loadConditionScripts, LoadScriptWithName(), AI(OOPrivate)::loadStateMachine:jsName:, OOCacheManager(OOMesh)::meshDataForName:, OOCacheManager(Octree)::octreeForModel:, ResourceManager::pathForFileNamed:inFolder:cache:, ResourceManager::preloadFilePathFor:inFolder:atPath:, OOPListScript::scriptsInPListFile:, and Universe::soundNameForCustomSoundKey:.

Here is the caller graph for this function:

◆ octreeForModel:

+ (Octree *) octreeForModel: (NSString*) inKey

Provided by category OOCacheManager(Octree).

Definition at line 2024 of file OOMesh.m.

2024 :(NSString*)inKey
2025{
2026 NSDictionary* dict = nil;
2027 Octree* result = nil;
2028
2029 if (inKey == nil)
2030 return nil;
2031
2032 dict = [[self sharedCache] objectForKey:inKey inCache:kOOCacheOctrees];
2033 if (dict != nil) {
2034 result = [[Octree alloc] initWithDictionary:dict];
2035 [result autorelease];
2036 }
2037
2038 return result;
2039}

◆ release

- (void) release
implementation

Provided by category OOCacheManager(Singleton).

Definition at line 618 of file OOCacheManager.m.

619{
620}

◆ reloadAllCaches

- (void) reloadAllCaches

Definition at line 230 of file OOCacheManager.m.

231{
232 [self clear];
233 [self loadCache];
234}

References clear, loadCache, and reloadAllCaches.

Referenced by reloadAllCaches, and ResourceManager::setUseAddOns:.

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

◆ removeObjectForKey:inCache:

- (void) removeObjectForKey: (NSString*) inKey
inCache: (NSString*) inCacheKey 

Definition at line 190 of file OOCacheManager.m.

190 :(NSString*)inKey inCache:(NSString*)inCacheKey
191{
192 NSMutableDictionary* cache = nil;
193
194 NSParameterAssert(inKey != nil && inCacheKey != nil);
195
196 cache = [_caches objectForKey:inCacheKey];
197 if (cache != nil) {
198 if (nil != [cache objectForKey:inKey]) {
199 [cache removeObjectForKey:inKey];
200 _dirty = YES;
201 OODebugLog(kOOLogDataCacheRemoveSuccess, @"Removed entry keyed %@ from cache \"%@\".", inKey, inCacheKey);
202 } else {
203 OODebugLog(kOOLogDataCacheRemoveSuccess, @"No need to remove non-existent entry keyed %@ from cache \"%@\".", inKey, inCacheKey);
204 }
205 } else {
206 OODebugLog(kOOLogDataCacheRemoveSuccess, @"No need to remove entry keyed %@ from non-existent cache \"%@\".", inKey, inCacheKey);
207 }
208}
static NSString *const kOOLogDataCacheRemoveSuccess

References _dirty, kOOLogDataCacheRemoveSuccess, nil, and OODebugLog.

◆ retain

- (id) retain
implementation

Provided by category OOCacheManager(Singleton).

Definition at line 608 of file OOCacheManager.m.

609{
610 return self;
611}

◆ retainCount

- (NSUInteger) retainCount
implementation

Provided by category OOCacheManager(Singleton).

Definition at line 613 of file OOCacheManager.m.

614{
615 return UINT_MAX;
616}

◆ setAllowCacheWrites:

- (void) setAllowCacheWrites: (BOOL) flag

Definition at line 251 of file OOCacheManager.m.

251 :(BOOL)flag
252{
253 _permitWrites = (flag != NO);
254}

References _permitWrites.

Referenced by OOOXPVerifier(OOPrivate)::run, and ResourceManager::setUseAddOns:.

Here is the caller graph for this function:

◆ setMeshData:forName:

+ (void) setMeshData: (NSDictionary*) inData
forName: (NSString*) inShipName 
implementation

Provided by category OOCacheManager(OOMesh).

Definition at line 2011 of file OOMesh.m.

2011 :(NSDictionary*)inData forName:(NSString*)inShipName
2012{
2013 if (inData != nil && inShipName != nil) {
2014 [[self sharedCache] setObject:inData forKey:inShipName inCache:kOOCacheMeshes];
2015 }
2016}

Referenced by OOMesh(Private)::loadData:scaleFactor:.

Here is the caller graph for this function:

◆ setObject:forKey:inCache:

- (void) setObject: (id) inElement
forKey: (NSString*) inKey
inCache: (NSString*) inCacheKey 

Definition at line 166 of file OOCacheManager.m.

166 :(id)inObject forKey:(NSString*)inKey inCache:(NSString*)inCacheKey
167{
168 NSMutableDictionary* cache = nil;
169
170 NSParameterAssert(inObject != nil && inKey != nil && inCacheKey != nil);
171
172 if (EXPECT_NOT(_caches == nil))
173 return;
174
175 cache = [_caches objectForKey:inCacheKey];
176 if (cache == nil) {
177 cache = [NSMutableDictionary dictionary];
178 if (cache == nil) {
179 OODebugLog(kOOLogDataCacheSetFailed, @"Failed to create cache for key \"%@\".", inCacheKey);
180 return;
181 }
182 [_caches setObject:cache forKey:inCacheKey];
183 }
184
185 [cache setObject:inObject forKey:inKey];
186 _dirty = YES;
187 OODebugLog(kOOLogDataCacheSetSuccess, @"Updated entry %@ in cache \"%@\".", inKey, inCacheKey);
188}
static NSString *const kOOLogDataCacheSetFailed
static NSString *const kOOLogDataCacheSetSuccess
#define EXPECT_NOT(x)

References _caches, _dirty, EXPECT_NOT, kOOLogDataCacheSetFailed, kOOLogDataCacheSetSuccess, nil, and OODebugLog.

Referenced by ResourceManager::arrayFromFilesNamed:inFolder:andMerge:cache:, OOShipRegistry(OODataLoader)::buildRoleProbabilitySets, CacheCompiledScript(), ResourceManager::checkCacheUpToDateForPaths:, OOMaterial(OOConvenienceCreators)::defaultShaderMaterialWithName:cacheKey:configuration:macros:bindingTarget:, ResourceManager::dictionaryFromFilesNamed:inFolder:mergeMode:cache:, OOShipRegistry(OODataLoader)::loadAndMergeShipyard:, OOShipRegistry(OODataLoader)::loadDemoShipConditions, OOEquipmentType::loadEquipment, LoadScriptWithName(), OOShipRegistry(OODataLoader)::loadShipData, AI(OOPrivate)::loadStateMachine:jsName:, ResourceManager::pathForFileNamed:inFolder:cache:, ResourceManager::preloadFilePathFor:inFolder:atPath:, OOShipRegistry(OODataLoader)::sanitizeConditions:, OOPListScript(SetUp)::scriptsFromDictionaryOfScripts:filePath:, OOCacheManager(OOMesh)::setMeshData:forName:, OOCacheManager(Octree)::setOctree:forModel:, and Universe::soundNameForCustomSoundKey:.

Here is the caller graph for this function:

◆ setOctree:forModel:

+ (void) setOctree: (Octree*) inOctree
forModel: (NSString*) inKey 

Provided by category OOCacheManager(Octree).

Definition at line 2041 of file OOMesh.m.

2041 :(Octree*)inOctree forModel:(NSString*)inKey
2042{
2043 if (inOctree != nil && inKey != nil) {
2044 [[self sharedCache] setObject:[inOctree dictionaryRepresentation] forKey:inKey inCache:kOOCacheOctrees];
2045 }
2046}
NSDictionary * dictionaryRepresentation()
Definition Octree.m:626

◆ sharedCache

+ (OOCacheManager *) sharedCache

Definition at line 134 of file OOCacheManager.m.

135{
136 // NOTE: assumes single-threaded access.
137 if (sSingleton == nil) {
138 sSingleton = [[self alloc] init];
139 }
140
141 return sSingleton;
142}

References nil, sharedCache, and sSingleton.

Referenced by GameController::applicationShouldTerminate:, ResourceManager::arrayFromFilesNamed:inFolder:andMerge:cache:, OOShipRegistry(OODataLoader)::buildRoleProbabilitySets, CacheCompiledScript(), CachedCompiledScript(), ResourceManager::checkCacheUpToDateForPaths:, Universe::dealloc, OOMaterial(OOConvenienceCreators)::defaultShaderMaterialWithName:cacheKey:configuration:macros:bindingTarget:, ResourceManager::dictionaryFromFilesNamed:inFolder:mergeMode:cache:, PlayerEntity::docked, OOOXZManager(NSURLConnectionDataDelegate)::downloadPath, OOShipRegistry::init, Universe::initWithGameView:, OOShipRegistry(OODataLoader)::loadAndMergeShipyard:, OOShipRegistry(OODataLoader)::loadCachedRoleProbabilitySets, Universe::loadConditionScripts, OOShipRegistry(OODataLoader)::loadDemoShipConditions, OOEquipmentType::loadEquipment, LoadScriptWithName(), OOShipRegistry(OODataLoader)::loadShipData, AI(OOPrivate)::loadStateMachine:jsName:, OOOXZManager(NSURLConnectionDataDelegate)::manifestPath, OOCacheManager(OOMesh)::meshDataForName:, OOCacheManager(Octree)::octreeForModel:, ResourceManager::pathForFileNamed:inFolder:cache:, ResourceManager::preloadFilePathFor:inFolder:atPath:, OOOXPVerifier(OOPrivate)::run, OOShipRegistry(OODataLoader)::sanitizeConditions:, OOPListScript(SetUp)::scriptsFromDictionaryOfScripts:filePath:, OOPListScript::scriptsInPListFile:, PlayerEntity::setGuiToIntroFirstGo:, OOCacheManager(OOMesh)::setMeshData:forName:, OOCacheManager(Octree)::setOctree:forModel:, ResourceManager::setUseAddOns:, sharedCache, and Universe::soundNameForCustomSoundKey:.

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

◆ VFRAddFace

+ (void) VFRAddFace (VertexFaceRef *) vfr
(NSUInteger) index 
implementation

Provided by category OOCacheManager(Octree).

Definition at line 2048 of file OOMesh.m.

2049{
2050 NSCParameterAssert(vfr != NULL);
2051
2052 if (index < UINT16_MAX && vfr->internCount < kVertexFaceDefInternalCount) {
2053 vfr->internFaces[vfr->internCount++] = index;
2054 } else {
2055 if (vfr->extra == nil)
2056 vfr->extra = [NSMutableArray array];
2057 [vfr->extra addObject:[NSNumber numberWithInteger:index]];
2058 }
2059}
@ kVertexFaceDefInternalCount
Definition OOMesh.m:110
uint16_t internFaces[kVertexFaceDefInternalCount]
Definition OOMesh.m:116
NSMutableArray * extra
Definition OOMesh.m:117

◆ VFRGetCount

+ (NSUInteger) VFRGetCount (VertexFaceRef *) vfr
implementation

Provided by category OOCacheManager(Octree).

Definition at line 2061 of file OOMesh.m.

2062{
2063 NSCParameterAssert(vfr != NULL);
2064
2065 return vfr->internCount + [vfr->extra count];
2066}
unsigned count
uint16_t internCount
Definition OOMesh.m:115

◆ VFRGetFaceAtIndex

+ (NSUInteger) VFRGetFaceAtIndex (VertexFaceRef *) vfr
(NSUInteger) index 
implementation

Provided by category OOCacheManager(Octree).

Definition at line 2068 of file OOMesh.m.

2069{
2070 NSCParameterAssert(vfr != NULL && index < VFRGetCount(vfr));
2071
2072 if (index < vfr->internCount)
2073 return vfr->internFaces[index];
2074 else
2075 return [vfr->extra oo_unsignedIntegerAtIndex:index - vfr->internCount];
2076}
static NSUInteger VFRGetCount(VertexFaceRef *vfr)
Definition OOMesh.m:2061

◆ write

- (void) write
implementation

Provided by category OOCacheManager(Private).

Definition at line 348 of file OOCacheManager.m.

349{
350 NSMutableDictionary* newCache = nil;
351 NSString* ooliteVersion = nil;
352 NSData* endianTag = nil;
353 NSNumber* formatVersion = nil;
354 NSDictionary* pListRep = nil;
355 uint64_t endianTagValue = kEndianTagValue;
356
357 if (_caches == nil)
358 return;
359 if (_scheduledWrite != nil)
360 return;
361
362#if PROFILE_WRITES
363 OOProfilingStopwatch* stopwatch = [OOProfilingStopwatch stopwatch];
364#endif
365
366#if WRITE_ASYNC
367 OOLog(@"dataCache.willWrite", @"%@", @"Scheduling data cache write.");
368#else
369 OOLog(@"dataCache.willWrite", @"%@", @"About to write cache.");
370#endif
371
372 ooliteVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
373 endianTag = [NSData dataWithBytes:&endianTagValue length:sizeof endianTagValue];
374 formatVersion = [NSNumber numberWithUnsignedInt:kFormatVersionValue];
375
376 pListRep = [self dictionaryOfCaches];
377 if (ooliteVersion == nil || endianTag == nil || formatVersion == nil || pListRep == nil) {
378 OOLog(@"dataCache.cantWrite", @"%@", @"Failed to write data cache -- prerequisites not fulfilled. This is an internal error, please report it.");
379 return;
380 }
381
382 newCache = [NSMutableDictionary dictionaryWithCapacity:4];
383 [newCache setObject:ooliteVersion forKey:kCacheKeyVersion];
384 [newCache setObject:formatVersion forKey:kCacheKeyFormatVersion];
385 [newCache setObject:endianTag forKey:kCacheKeyEndianTag];
386 [newCache setObject:pListRep forKey:kCacheKeyCaches];
387
388#if PROFILE_WRITES && !WRITE_ASYNC
389 OOTimeDelta prepareT = [stopwatch reset];
390#endif
391
392#if WRITE_ASYNC
393 NSDictionary* cacheData = newCache;
394 _scheduledWrite = [[OOAsyncCacheWriter alloc] initWithCacheContents:cacheData];
395
396#if PROFILE_WRITES
397 OOTimeDelta endT = [stopwatch reset];
398 OOLog(@"dataCache.profile", @"Time to prepare cache data: %g seconds.", endT);
399#endif
400
402 priority:kOOAsyncPriorityLow];
403#else
404#if PROFILE_WRITES
405 OOLog(@"dataCache.profile", @"Time to prepare cache data: %g seconds.", prepareT);
406#endif
407
408 if ([self writeDict:newCache]) {
409 [self markClean];
410 OOLog(kOOLogDataCacheWriteSuccess, @"%@", @"Wrote data cache.");
411 } else {
412 OOLog(kOOLogDataCacheWriteFailed, @"%@", @"Failed to write data cache.");
413 }
414#endif
415}
static NSString *const kOOLogDataCacheWriteSuccess
static NSString *const kOOLogDataCacheWriteFailed
double OOTimeDelta
Definition OOTypes.h:193
BOOL addTask:priority:(id< OOAsyncWorkTask > task,[priority] OOAsyncWorkPriority priority)

Referenced by flush.

Here is the caller graph for this function:

◆ writeDict:

- (BOOL) writeDict: (NSDictionary*) inDict
implementation

Provided by category OOCacheManager(Private).

Definition at line 472 of file OOCacheManager.m.

472 :(NSDictionary*)inDict
473{
474 NSString* path = nil;
475 NSData* plist = nil;
476 NSString* errorDesc = nil;
477
478 path = [self cachePathCreatingIfNecessary:YES];
479 if (path == nil)
480 return NO;
481
482#if PROFILE_WRITES
483 OOProfilingStopwatch* stopwatch = [OOProfilingStopwatch stopwatch];
484#endif
485
486 plist = [NSPropertyListSerialization dataFromPropertyList:inDict format:CACHE_PLIST_FORMAT errorDescription:&errorDesc];
487 if (plist == nil) {
488#if OOLITE_RELEASE_PLIST_ERROR_STRINGS
489 [errorDesc autorelease];
490#endif
491 OOLog(kOOLogDataCacheSerializationError, @"Could not convert data cache to property list data: %@", errorDesc);
492 return NO;
493 }
494
495#if PROFILE_WRITES
496 OOTimeDelta serializeT = [stopwatch reset];
497#endif
498
499 BOOL result = [plist writeToFile:path atomically:NO];
500
501#if PROFILE_WRITES
502 OOTimeDelta writeT = [stopwatch reset];
503
504 OOLog(@"dataCache.profile", @"Time to serialize cache: %g seconds. Time to write data: %g seconds.", serializeT, writeT);
505#endif
506
507#if WRITE_ASYNC
509#endif
510 return result;
511}
static NSString *const kOOLogDataCacheSerializationError
#define DESTROY(x)

Member Data Documentation

◆ _caches

- (NSMutableDictionary*) _caches
private

Definition at line 36 of file OOCacheManager.h.

Referenced by clearAllCaches, clearCache:, and setObject:forKey:inCache:.

◆ _dirty

- (BOOL) _dirty
private

◆ _permitWrites

- (BOOL) _permitWrites
private

Definition at line 38 of file OOCacheManager.h.

Referenced by flush, init, and setAllowCacheWrites:.

◆ _scheduledWrite

- (id) _scheduledWrite
private

Definition at line 37 of file OOCacheManager.h.

Referenced by flush.


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