From 64e0b4ac3160b19029a2f46b33a26051ac4580b0 Mon Sep 17 00:00:00 2001 From: "C.W. Betts" Date: Sat, 9 May 2015 00:34:02 -0600 Subject: [PATCH 1/9] Begin migrating away from NSEnumerator: Use foreachkey or foreach macro when appropriate. --- src/Core/AI.m | 9 +++------ src/Core/AIGraphViz.m | 12 ++++-------- src/Core/GuiDisplayGen.m | 3 +-- src/Core/HeadUpDisplay.m | 3 +-- src/Core/OXPVerifier/OOAIStateMachineVerifierStage.m | 12 ++++-------- 5 files changed, 13 insertions(+), 26 deletions(-) diff --git a/src/Core/AI.m b/src/Core/AI.m index b5aa002ff..f6b1f8ca5 100644 --- a/src/Core/AI.m +++ b/src/Core/AI.m @@ -803,7 +803,6 @@ - (NSDictionary *) loadStateMachine:(NSString *)smName jsName:(NSString *)script NSDictionary *newSM = nil; NSMutableDictionary *cleanSM = nil; OOCacheManager *cacheMgr = [OOCacheManager sharedCache]; - NSEnumerator *stateEnum = nil; NSString *stateKey = nil; NSDictionary *stateHandlers = nil; NSAutoreleasePool *pool = nil; @@ -844,7 +843,7 @@ - (NSDictionary *) loadStateMachine:(NSString *)smName jsName:(NSString *)script cleanSM = [NSMutableDictionary dictionaryWithCapacity:[newSM count]]; - for (stateEnum = [newSM keyEnumerator]; (stateKey = [stateEnum nextObject]); ) + foreachkey (stateKey, newSM) { stateHandlers = [newSM objectForKey:stateKey]; if (![stateHandlers isKindOfClass:[NSDictionary class]]) @@ -887,13 +886,12 @@ - (NSDictionary *) loadStateMachine:(NSString *)smName jsName:(NSString *)script - (NSDictionary *) cleanHandlers:(NSDictionary *)handlers forState:(NSString *)stateKey stateMachine:(NSString *)smName { - NSEnumerator *handlerEnum = nil; NSString *handlerKey = nil; NSArray *handlerActions = nil; NSMutableDictionary *result = nil; result = [NSMutableDictionary dictionaryWithCapacity:[handlers count]]; - for (handlerEnum = [handlers keyEnumerator]; (handlerKey = [handlerEnum nextObject]); ) + foreachkey (handlerKey, handlers) { handlerActions = [handlers objectForKey:handlerKey]; if (![handlerActions isKindOfClass:[NSArray class]]) @@ -913,7 +911,6 @@ - (NSDictionary *) cleanHandlers:(NSDictionary *)handlers forState:(NSString *)s - (NSArray *) cleanActions:(NSArray *)actions forHandler:(NSString *)handlerKey state:(NSString *)stateKey stateMachine:(NSString *)smName { - NSEnumerator *actionEnum = nil; NSString *action = nil; NSRange spaceRange; NSString *selector = nil; @@ -936,7 +933,7 @@ - (NSArray *) cleanActions:(NSArray *)actions forHandler:(NSString *)handlerKey } result = [NSMutableArray arrayWithCapacity:[actions count]]; - for (actionEnum = [actions objectEnumerator]; (action = [actionEnum nextObject]); ) + foreach (action, actions) { if (![action isKindOfClass:[NSString class]]) { diff --git a/src/Core/AIGraphViz.m b/src/Core/AIGraphViz.m index 5764089b6..aca206a47 100644 --- a/src/Core/AIGraphViz.m +++ b/src/Core/AIGraphViz.m @@ -50,21 +50,19 @@ void GenerateGraphVizForAIStateMachine(NSDictionary *stateMachine, NSString *smN "\tnode [shape=box height=0.2 width=3.5 fontname=Helvetica color=\"#808080\"]\n\t\n" "\tspecial_start [shape=ellipse color=\"#0000C0\" label=\"Start\"]\n\tspecial_start -> %@ [lhead=\"cluster_GLOBAL\" color=\"#0000A0\"]\n", EscapedGraphVizString(smName), HandlerToken(@"GLOBAL", @"ENTER", handlerKeys, uniqueSet)]; - NSEnumerator *stateKeyEnum = [stateMachine keyEnumerator]; NSString *stateKey = nil; NSMutableSet *specialNodes = [NSMutableSet set]; - while ((stateKey = [stateKeyEnum nextObject])) + foreachkey (stateKey, stateMachine) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; [graphViz appendFormat:@"\t\n\tsubgraph cluster_%@\n\t{\n\t\tlabel=\"%@\"\n", stateKey, EscapedGraphVizString(stateKey)]; NSDictionary *state = [stateMachine oo_dictionaryForKey:stateKey]; - NSEnumerator *handlerKeyEnum = [state keyEnumerator]; NSString *handlerKey = nil; - while ((handlerKey = [handlerKeyEnum nextObject])) + foreachkey (handlerKey, state) { [graphViz appendFormat:@"\t\t%@ [label=\"%@\"]\n", HandlerToken(stateKey, handlerKey, handlerKeys, uniqueSet), EscapedGraphVizString(handlerKey)]; } @@ -78,8 +76,7 @@ void GenerateGraphVizForAIStateMachine(NSDictionary *stateMachine, NSString *smN [graphViz appendString:@"\t}\n"]; // Go through each handler looking for interesting methods. - handlerKeyEnum = [state keyEnumerator]; - while ((handlerKey = [handlerKeyEnum nextObject])) + foreachkey (handlerKey, state) { NSArray *handlerCommands = [state oo_arrayForKey:handlerKey]; NSUInteger commandIter, commandCount = [handlerCommands count]; @@ -98,9 +95,8 @@ void GenerateGraphVizForAIStateMachine(NSDictionary *stateMachine, NSString *smN { [graphViz appendString:@"\t\n"]; - NSEnumerator *specialEnum = [specialNodes objectEnumerator]; NSString *special = nil; - while ((special = [specialEnum nextObject])) + foreach (special, specialNodes) { [graphViz appendString:special]; } diff --git a/src/Core/GuiDisplayGen.m b/src/Core/GuiDisplayGen.m index 481e6ebb1..dcd843e9a 100644 --- a/src/Core/GuiDisplayGen.m +++ b/src/Core/GuiDisplayGen.m @@ -2126,9 +2126,8 @@ - (void) drawStarChart:(GLfloat)x :(GLfloat)y :(GLfloat)z :(GLfloat) alpha - (void) drawSystemMarkers:(NSArray *)markers atX:(GLfloat)x andY:(GLfloat)y andZ:(GLfloat)z withAlpha:(GLfloat)alpha andScale:(GLfloat)scale { - NSEnumerator *mEnum; NSDictionary *marker; - for (mEnum = [markers objectEnumerator]; (marker = [mEnum nextObject]); ) + foreach (marker, markers) { [self drawSystemMarker:marker atX:x andY:y andZ:z withAlpha:alpha andScale:scale]; } diff --git a/src/Core/HeadUpDisplay.m b/src/Core/HeadUpDisplay.m index afbb09884..ad45f1a0f 100644 --- a/src/Core/HeadUpDisplay.m +++ b/src/Core/HeadUpDisplay.m @@ -2654,11 +2654,10 @@ - (void) drawWaypoints:(NSDictionary *)info GLfloat alpha = [info oo_nonNegativeFloatForKey:ALPHA_KEY defaultValue:1.0f] * overallAlpha; GLfloat scale = [info oo_floatForKey:@"reticle_scale" defaultValue:ONE_SIXTYFOURTH]; - NSEnumerator *waypoints = [[UNIVERSE currentWaypoints] objectEnumerator]; OOWaypointEntity *waypoint = nil; Entity *compass = [PLAYER compassTarget]; - while ((waypoint = [waypoints nextObject])) + foreach (waypoint, [[UNIVERSE currentWaypoints] allValues]) { hudDrawWaypoint(waypoint, PLAYER, z1, alpha, waypoint==compass, scale); } diff --git a/src/Core/OXPVerifier/OOAIStateMachineVerifierStage.m b/src/Core/OXPVerifier/OOAIStateMachineVerifierStage.m index 1be48d9c2..68cad5c51 100644 --- a/src/Core/OXPVerifier/OOAIStateMachineVerifierStage.m +++ b/src/Core/OXPVerifier/OOAIStateMachineVerifierStage.m @@ -67,7 +67,6 @@ - (BOOL) shouldRun - (void) run { NSArray *aiNames = nil; - NSEnumerator *aiEnum = nil; NSString *aiName = nil; NSMutableSet *whitelist = nil; @@ -80,7 +79,7 @@ - (void) run [whitelist release]; aiNames = [[_usedAIs allObjects] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]; - for (aiEnum = [aiNames objectEnumerator]; (aiName = [aiEnum nextObject]); ) + foreach (aiName, aiNames) { [self validateAI:aiName]; } @@ -124,13 +123,10 @@ - (void) validateAI:(NSString *)aiName { NSString *path = nil; NSDictionary *aiStateMachine = nil; - NSEnumerator *stateEnum = nil; NSString *stateKey = nil; NSDictionary *stateHandlers = nil; - NSEnumerator *handlerEnum = nil; NSString *handlerKey = nil; NSArray *handlerActions = nil; - NSEnumerator *actionEnum = nil; NSString *action = nil; NSRange spaceRange; NSString *selector = nil; @@ -155,7 +151,7 @@ - (void) validateAI:(NSString *)aiName } // Validate each state. - for (stateEnum = [aiStateMachine keyEnumerator]; (stateKey = [stateEnum nextObject]); ) + foreachkey (stateKey, aiStateMachine) { stateHandlers = [aiStateMachine objectForKey:stateKey]; if (![stateHandlers isKindOfClass:[NSDictionary class]]) @@ -165,7 +161,7 @@ - (void) validateAI:(NSString *)aiName } // Verify handlers for this state. - for (handlerEnum = [stateHandlers keyEnumerator]; (handlerKey = [handlerEnum nextObject]); ) + foreachkey (handlerKey, stateHandlers) { handlerActions = [stateHandlers objectForKey:handlerKey]; if (![handlerActions isKindOfClass:[NSArray class]]) @@ -176,7 +172,7 @@ - (void) validateAI:(NSString *)aiName // Verify commands for this handler. index = 0; - for (actionEnum = [handlerActions objectEnumerator]; (action = [actionEnum nextObject]); ) + foreach (action, handlerActions) { index++; if (![action isKindOfClass:[NSString class]]) From 90a633b8c33e2a584e25cdc66adb6aeb4b114ad3 Mon Sep 17 00:00:00 2001 From: "C.W. Betts" Date: Sat, 9 May 2015 00:48:20 -0600 Subject: [PATCH 2/9] Have each foreach and foreachkey enums have a different value for the NSEnumerator object. --- src/Core/OOCocoa.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Core/OOCocoa.h b/src/Core/OOCocoa.h index de6c3bb12..3d14e1126 100644 --- a/src/Core/OOCocoa.h +++ b/src/Core/OOCocoa.h @@ -352,8 +352,10 @@ enum { #define foreach(VAR, COLLECTION) for(VAR in COLLECTION) #define foreachkey(VAR, DICT) for(VAR in DICT) #else -#define foreach(VAR, COLLECTION) for (NSEnumerator *ooForEachEnum = [(COLLECTION) objectEnumerator]; ((VAR) = [ooForEachEnum nextObject]); ) -#define foreachkey(VAR, DICT) for (NSEnumerator *ooForEachEnum = [(DICT) keyEnumerator]; ((VAR) = [ooForEachEnum nextObject]); ) +#define foreachLinewrapper2(x, y) x ## y +#define foreachLine(x, y) foreachLinewrapper2(x, y) +#define foreach(VAR, COLLECTION) for (NSEnumerator * foreachLine(ooForEachEnum, __LINE__) = [(COLLECTION) objectEnumerator]; ((VAR) = [ foreachLine(ooForEachEnum, __LINE__) nextObject]); ) +#define foreachkey(VAR, DICT) for (NSEnumerator * foreachLine(ooForEachEnum, __LINE__) = [(DICT) keyEnumerator]; ((VAR) = [ foreachLine(ooForEachEnum, __LINE__) nextObject]); ) #endif From 0a229dfb0d3ab8a3d9ae969103e0e1060140aa52 Mon Sep 17 00:00:00 2001 From: "C.W. Betts" Date: Sat, 9 May 2015 11:25:06 -0600 Subject: [PATCH 3/9] More migrating away from NSEnumerator. --- src/Core/Debug/OODebugMonitor.m | 21 +++++++------------ src/Core/Entities/OOFlasherEntity.m | 3 +-- src/Core/OOCache.m | 3 +-- src/Core/OOCacheManager.m | 3 +-- src/Core/OOConvertSystemDescriptions.m | 18 ++++++---------- src/Core/OOEncodingConverter.m | 3 +-- src/Core/OOEquipmentType.m | 3 +-- .../OOCheckDemoShipsPListVerifierStage.m | 3 +-- .../OOCheckEquipmentPListVerifierStage.m | 3 +-- .../OXPVerifier/OOFileScannerVerifierStage.m | 6 ++---- src/Core/OXPVerifier/OOModelVerifierStage.m | 3 +-- src/Core/Scripting/OOJSEngineTimeManagement.m | 3 +-- src/Core/Scripting/OOJSFrameCallbacks.m | 3 +-- src/Core/Scripting/OOJSScript.m | 5 ++--- src/Core/Scripting/OOJSShip.m | 6 ++---- src/Core/Scripting/OOJSWorldScripts.m | 3 +-- src/Core/Scripting/OOJavaScriptEngine.m | 3 +-- src/Core/Scripting/OOLegacyScriptWhitelist.m | 6 ++---- 18 files changed, 34 insertions(+), 64 deletions(-) diff --git a/src/Core/Debug/OODebugMonitor.m b/src/Core/Debug/OODebugMonitor.m index bd8c5b56c..9fdb05988 100644 --- a/src/Core/Debug/OODebugMonitor.m +++ b/src/Core/Debug/OODebugMonitor.m @@ -463,9 +463,8 @@ - (void) dumpEntity:(id)entity withState:(EntityDumpState *)state parentVisible: OOLogIndent(); if ([entity isShip]) { - NSEnumerator *subEnum = nil; id subentity = nil; - for (subEnum = [entity subEntityEnumerator]; (subentity = [subEnum nextObject]); ) + foreach (subentity, [entity subEntityEnumerator]) { [self dumpEntity:subentity withState:state parentVisible:visible]; } @@ -494,9 +493,8 @@ - (void) dumpEntity:(id)entity withState:(EntityDumpState *)state parentVisible: } if ([entity isWormhole]) { - NSEnumerator *shipEnum = nil; NSDictionary *shipInfo = nil; - for (shipEnum = [[entity shipsInTransit] objectEnumerator]; (shipInfo = [shipEnum nextObject]); ) + foreach (shipInfo, [entity shipsInTransit]) { ShipEntity *ship = [shipInfo objectForKey:@"ship"]; [self dumpEntity:ship withState:state parentVisible:NO]; @@ -516,8 +514,7 @@ - (void) dumpMemoryStatistics NSMutableDictionary *textureRefCounts = [NSMutableDictionary dictionaryWithCapacity:[allTextures count]]; OOTexture *tex = nil; - NSEnumerator *texEnum = nil; - for (texEnum = [allTextures objectEnumerator]; (tex = [texEnum nextObject]); ) + foreach (tex, allTextures) { // We subtract one because allTextures retains the textures. [textureRefCounts setObject:[NSNumber numberWithUnsignedInteger:[tex retainCount] - 1] forKey:[NSValue valueWithNonretainedObject:tex]]; @@ -537,12 +534,11 @@ - (void) dumpMemoryStatistics }; id entity = nil; - NSEnumerator *entityEnum = nil; - for (entityEnum = [entities objectEnumerator]; (entity = [entityEnum nextObject]); ) + foreach (entity, entities) { [self dumpEntity:entity withState:&entityDumpState parentVisible:YES]; } - for (entityEnum = [[PLAYER scannedWormholes] objectEnumerator]; (entity = [entityEnum nextObject]); ) + foreach (entity, [PLAYER scannedWormholes]) { [self dumpEntity:entity withState:&entityDumpState parentVisible:YES]; } @@ -560,7 +556,7 @@ - (void) dumpMemoryStatistics */ NSMutableArray *textures = [[[OOTexture cachedTexturesByAge] mutableCopy] autorelease]; - for (texEnum = [allTextures objectEnumerator]; (tex = [texEnum nextObject]); ) + foreach (tex, allTextures) { if ([textures indexOfObject:tex] == NSNotFound) { @@ -575,7 +571,7 @@ - (void) dumpMemoryStatistics [self writeMemStat:@"Textures:"]; OOLogIndent(); - for (texEnum = [textures objectEnumerator]; (tex = [texEnum nextObject]); ) + foreach (tex, textures) { size_t objSize = [tex oo_objectSize]; size_t dataSize = [tex dataSize]; @@ -828,12 +824,11 @@ - (NSArray *)loadSourceFile:(NSString *)filePath - (NSMutableDictionary *)normalizeConfigDictionary:(NSDictionary *)dictionary { NSMutableDictionary *result = nil; - NSEnumerator *keyEnum = nil; NSString *key = nil; id value = nil; result = [NSMutableDictionary dictionaryWithCapacity:[dictionary count]]; - for (keyEnum = [dictionary keyEnumerator]; (key = [keyEnum nextObject]); ) + foreachkey (key, dictionary) { value = [dictionary objectForKey:key]; value = [self normalizeConfigValue:value forKey:key]; diff --git a/src/Core/Entities/OOFlasherEntity.m b/src/Core/Entities/OOFlasherEntity.m index 9ad0d90fa..9172c526b 100644 --- a/src/Core/Entities/OOFlasherEntity.m +++ b/src/Core/Entities/OOFlasherEntity.m @@ -78,8 +78,7 @@ - (void) setUpColors:(NSArray *)colorSpecifiers { NSMutableArray *colors = [NSMutableArray arrayWithCapacity:[colorSpecifiers count]]; id specifier = nil; - NSEnumerator *specEnum = [colorSpecifiers objectEnumerator]; - while ((specifier = [specEnum nextObject])) + foreach (specifier, colorSpecifiers) { [colors addObject:[OOColor colorWithDescription:specifier saturationFactor:0.75f]]; } diff --git a/src/Core/OOCache.m b/src/Core/OOCache.m index 49279c45c..9912367ea 100644 --- a/src/Core/OOCache.m +++ b/src/Core/OOCache.m @@ -363,14 +363,13 @@ @implementation OOCache (Private) - (void)loadFromArray:(NSArray *)array { - NSEnumerator *entryEnum = nil; NSDictionary *entry = nil; NSString *key = nil; id value = nil; if (array == nil) return; - for (entryEnum = [array objectEnumerator]; (entry = [entryEnum nextObject]); ) + foreach (entry, array) { if ([entry isKindOfClass:[NSDictionary class]]) { diff --git a/src/Core/OOCacheManager.m b/src/Core/OOCacheManager.m index 1799dc7a2..3bd7618b9 100644 --- a/src/Core/OOCacheManager.m +++ b/src/Core/OOCacheManager.m @@ -574,7 +574,6 @@ - (BOOL)writeDict:(NSDictionary *)inDict - (void)buildCachesFromDictionary:(NSDictionary *)inDict { - NSEnumerator *keyEnum = nil; id key = nil; id value = nil; NSMutableDictionary *cache = nil; @@ -584,7 +583,7 @@ - (void)buildCachesFromDictionary:(NSDictionary *)inDict [_caches release]; _caches = [[NSMutableDictionary alloc] initWithCapacity:[inDict count]]; - for (keyEnum = [inDict keyEnumerator]; (key = [keyEnum nextObject]); ) + foreachkey (key, inDict) { value = [inDict oo_dictionaryForKey:key]; if (value != nil) diff --git a/src/Core/OOConvertSystemDescriptions.m b/src/Core/OOConvertSystemDescriptions.m index 41cc46ffc..c94fd2c27 100644 --- a/src/Core/OOConvertSystemDescriptions.m +++ b/src/Core/OOConvertSystemDescriptions.m @@ -159,7 +159,6 @@ void ExportSystemDescriptions(BOOL asXML) NSAutoreleasePool *pool = nil; NSString *key = nil; NSArray *entry = nil; - NSEnumerator *keyEnum = nil; NSMutableDictionary *keysToIndices = nil; NSMutableSet *usedIndices = nil; NSUInteger slotCache = 0; @@ -174,7 +173,7 @@ void ExportSystemDescriptions(BOOL asXML) keysToIndices = InitKeyToIndexDict(indicesToKeys, &usedIndices); - for (keyEnum = [descriptionsInDictionaryFormat keyEnumerator]; (key = [keyEnum nextObject]); ) + foreachkey (key, descriptionsInDictionaryFormat) { entry = ConvertKeysToIndices([descriptionsInDictionaryFormat objectForKey:key], keysToIndices, usedIndices, &slotCache); index = KeyToIndex(key, keysToIndices, usedIndices, &slotCache); @@ -202,14 +201,13 @@ void ExportSystemDescriptions(BOOL asXML) NSMutableDictionary *result = nil; NSAutoreleasePool *pool = nil; NSArray *entry = nil; - NSEnumerator *entryEnum = nil; NSString *key = nil; NSUInteger i = 0; result = [NSMutableDictionary dictionaryWithCapacity:[descriptionsInArrayFormat count]]; pool = [[NSAutoreleasePool alloc] init]; - for (entryEnum = [descriptionsInArrayFormat objectEnumerator]; (entry = [entryEnum nextObject]); ) + foreach (entry, descriptionsInArrayFormat) { entry = ConvertIndicesToKeys(entry, indicesToKeys); key = IndexToKey(i, indicesToKeys, YES); @@ -261,7 +259,6 @@ void ExportSystemDescriptions(BOOL asXML) static NSMutableDictionary *InitKeyToIndexDict(NSDictionary *dict, NSMutableSet **outUsedIndices) { - NSEnumerator *keyEnum = nil; NSString *key = nil; NSNumber *number = nil; NSMutableDictionary *result = nil; @@ -272,7 +269,7 @@ void ExportSystemDescriptions(BOOL asXML) result = [NSMutableDictionary dictionaryWithCapacity:[dict count]]; used = [NSMutableSet setWithCapacity:[dict count]]; - for (keyEnum = [dict keyEnumerator]; (key = [keyEnum nextObject]); ) + foreachkey (key, dict) { // Convert keys of dict to array indices number = [NSNumber numberWithInt:[key intValue]]; @@ -296,13 +293,12 @@ void ExportSystemDescriptions(BOOL asXML) static NSArray *ConvertIndicesToKeys(NSArray *entry, NSDictionary *indicesToKeys) { - NSEnumerator *lineEnum = nil; NSString *line = nil; NSMutableArray *result = nil; result = [NSMutableArray arrayWithCapacity:[entry count]]; - for (lineEnum = [entry objectEnumerator]; (line = [lineEnum nextObject]); ) + foreach (line, entry) { [result addObject:OOStringifySystemDescriptionLine(line, indicesToKeys, YES)]; } @@ -338,7 +334,6 @@ void ExportSystemDescriptions(BOOL asXML) static NSArray *ConvertKeysToIndices(NSArray *entry, NSMutableDictionary *ioKeysToIndices, NSMutableSet *ioUsedIndicies, NSUInteger *ioSlotCache) { - NSEnumerator *lineEnum = nil; NSString *line = nil; NSUInteger p1, p2; NSRange searchRange; @@ -347,7 +342,7 @@ void ExportSystemDescriptions(BOOL asXML) result = [NSMutableArray arrayWithCapacity:[entry count]]; - for (lineEnum = [entry objectEnumerator]; (line = [lineEnum nextObject]); ) + foreach (line, entry) { searchRange.location = 0; searchRange.length = [line length]; @@ -380,11 +375,10 @@ void ExportSystemDescriptions(BOOL asXML) static NSUInteger HighestIndex(NSMutableDictionary *sparseArray) { - NSEnumerator *keyEnum = nil; NSNumber *key = nil; NSUInteger curr, highest = 0; - for (keyEnum = [sparseArray keyEnumerator]; (key = [keyEnum nextObject]); ) + foreachkey (key, sparseArray) { curr = [key intValue]; if (highest < curr) highest = curr; diff --git a/src/Core/OOEncodingConverter.m b/src/Core/OOEncodingConverter.m index fb1d84442..a5e521aa6 100644 --- a/src/Core/OOEncodingConverter.m +++ b/src/Core/OOEncodingConverter.m @@ -165,13 +165,12 @@ @implementation OOEncodingConverter (Private) - (NSData *) performConversionForString:(NSString *)string { NSString *subst = nil; - NSEnumerator *substEnum = nil; NSMutableString *mutable = nil; mutable = [[string mutableCopy] autorelease]; if (mutable == nil) return nil; - for (substEnum = [_substitutions keyEnumerator]; (subst = [substEnum nextObject]); ) + foreachkey (subst, _substitutions) { [mutable replaceOccurrencesOfString:subst withString:[_substitutions objectForKey:subst] diff --git a/src/Core/OOEquipmentType.m b/src/Core/OOEquipmentType.m index 04e26dcef..16965ca2f 100644 --- a/src/Core/OOEquipmentType.m +++ b/src/Core/OOEquipmentType.m @@ -54,7 +54,6 @@ + (void) loadEquipment NSMutableDictionary *equipmentTypesByIdentifier = nil; NSArray *itemInfo = nil; OOEquipmentType *item = nil; - NSEnumerator *itemEnum = nil; NSMutableArray *conditionScripts = nil; equipmentData = [UNIVERSE equipmentData]; @@ -66,7 +65,7 @@ + (void) loadEquipment DESTROY(sEquipmentTypesByIdentifier); equipmentTypesByIdentifier = [NSMutableDictionary dictionaryWithCapacity:[equipmentData count]]; - for (itemEnum = [equipmentData objectEnumerator]; (itemInfo = [itemEnum nextObject]); ) + foreach (itemInfo, equipmentData) { item = [[[OOEquipmentType alloc] initWithInfo:itemInfo] autorelease]; if (item != nil) diff --git a/src/Core/OXPVerifier/OOCheckDemoShipsPListVerifierStage.m b/src/Core/OXPVerifier/OOCheckDemoShipsPListVerifierStage.m index ec92fd446..c361204dc 100644 --- a/src/Core/OXPVerifier/OOCheckDemoShipsPListVerifierStage.m +++ b/src/Core/OXPVerifier/OOCheckDemoShipsPListVerifierStage.m @@ -106,10 +106,9 @@ @implementation OOCheckDemoShipsPListVerifierStage (OOPrivate) - (void)runCheckWithDemoShips:(NSArray *)demoshipsPList shipData:(NSDictionary *)shipdataPList { - NSEnumerator *nameEnum = nil; NSString *name = nil; - for (nameEnum = [demoshipsPList objectEnumerator]; (name = [nameEnum nextObject]); ) + foreach (name, demoshipsPList) { if ([shipdataPList objectForKey:name] == nil) { diff --git a/src/Core/OXPVerifier/OOCheckEquipmentPListVerifierStage.m b/src/Core/OXPVerifier/OOCheckEquipmentPListVerifierStage.m index 926515f34..2697547e4 100644 --- a/src/Core/OXPVerifier/OOCheckEquipmentPListVerifierStage.m +++ b/src/Core/OXPVerifier/OOCheckEquipmentPListVerifierStage.m @@ -93,14 +93,13 @@ @implementation OOCheckEquipmentPListVerifierStage (OOPrivate) - (void)runCheckWithEquipment:(NSArray *)equipmentPList { - NSEnumerator *entryEnum = nil; NSArray *entry = nil; unsigned entryIndex = 0; NSUInteger elemCount; NSString *name = nil; NSString *entryDesc = nil; - for (entryEnum = [equipmentPList objectEnumerator]; (entry = [entryEnum nextObject]); ) + foreach (entry, equipmentPList) { ++entryIndex; diff --git a/src/Core/OXPVerifier/OOFileScannerVerifierStage.m b/src/Core/OXPVerifier/OOFileScannerVerifierStage.m index 565352c8a..2ae3faf29 100644 --- a/src/Core/OXPVerifier/OOFileScannerVerifierStage.m +++ b/src/Core/OXPVerifier/OOFileScannerVerifierStage.m @@ -246,7 +246,6 @@ - (id)plistNamed:(NSString *)file NSPropertyListFormat format; id plist = nil; NSArray *errorLines = nil; - NSEnumerator *errLineEnum = nil; NSString *displayName = nil, *errorKey = nil; NSAutoreleasePool *pool = nil; @@ -284,7 +283,7 @@ - (id)plistNamed:(NSString *)file OOLog(@"verifyOXP.plist.parseError", @"Could not interpret property list %@.", displayName); OOLogIndent(); errorLines = [errorString componentsSeparatedByString:@"\n"]; - for (errLineEnum = [errorLines objectEnumerator]; (errorString = [errLineEnum nextObject]); ) + foreach (errorString, errorLines) { while ([errorString hasPrefix:@"\t"]) { @@ -418,13 +417,12 @@ - (void)scanForFiles - (void)checkRootFolders { NSArray *knownNames = nil; - NSEnumerator *nameEnum = nil; NSString *name = nil; NSString *lcName = nil; NSString *actual = nil; knownNames = [[self verifier] configurationArrayForKey:@"knownRootDirectories"]; - for (nameEnum = [knownNames objectEnumerator]; (name = [nameEnum nextObject]); ) + foreach (name, knownNames) { if (![name isKindOfClass:[NSString class]]) continue; diff --git a/src/Core/OXPVerifier/OOModelVerifierStage.m b/src/Core/OXPVerifier/OOModelVerifierStage.m index 0bf570d8f..e24e86dec 100644 --- a/src/Core/OXPVerifier/OOModelVerifierStage.m +++ b/src/Core/OXPVerifier/OOModelVerifierStage.m @@ -94,7 +94,6 @@ - (BOOL)shouldRun - (void)run { - NSEnumerator *nameEnum = nil; NSDictionary *info = nil; NSAutoreleasePool *pool = nil; NSString *name = nil, @@ -104,7 +103,7 @@ - (void)run OOLog(@"verifyOXP.models.unimplemented", @"TODO: implement model verifier."); - for (nameEnum = [_modelsToCheck objectEnumerator]; (info = [nameEnum nextObject]); ) + foreach (info, _modelsToCheck) { pool = [[NSAutoreleasePool alloc] init]; diff --git a/src/Core/Scripting/OOJSEngineTimeManagement.m b/src/Core/Scripting/OOJSEngineTimeManagement.m index 15c83ca19..807149413 100644 --- a/src/Core/Scripting/OOJSEngineTimeManagement.m +++ b/src/Core/Scripting/OOJSEngineTimeManagement.m @@ -760,9 +760,8 @@ - (NSDictionary *) propertyListRepresentation { NSArray *profileEntries = [self profileEntries]; NSMutableArray *convertedEntries = [NSMutableArray arrayWithCapacity:[profileEntries count]]; - NSEnumerator *entryEnum = nil; OOTimeProfileEntry *entry = nil; - for (entryEnum = [profileEntries objectEnumerator]; (entry = [entryEnum nextObject]); ) + foreachkey (entry, profileEntries) { [convertedEntries addObject:[entry propertyListRepresentation]]; } diff --git a/src/Core/Scripting/OOJSFrameCallbacks.m b/src/Core/Scripting/OOJSFrameCallbacks.m index 2ce6fd178..effe2f46e 100644 --- a/src/Core/Scripting/OOJSFrameCallbacks.m +++ b/src/Core/Scripting/OOJSFrameCallbacks.m @@ -451,12 +451,11 @@ static void QueueDeferredOperation(NSString *opType, uint32 trackingID, OOJSValu static void RunDeferredOperations(JSContext *context) { NSDictionary *operation = nil; - NSEnumerator *operationEnum = nil; FCBLog(@"script.frameCallback.debug.run-deferred", @"Running %lu deferred frame callback operations.", (long)[sDeferredOps count]); FCBLogIndentIf(@"script.frameCallback.debug.run-deferred"); - for (operationEnum = [sDeferredOps objectEnumerator]; (operation = [operationEnum nextObject]); ) + foreach (operation, sDeferredOps) { NSString *opType = [operation objectForKey:@"operation"]; uint32 trackingID = [operation oo_intForKey:@"trackingID"]; diff --git a/src/Core/Scripting/OOJSScript.m b/src/Core/Scripting/OOJSScript.m index 5d4801bd9..e0d9336db 100644 --- a/src/Core/Scripting/OOJSScript.m +++ b/src/Core/Scripting/OOJSScript.m @@ -122,7 +122,6 @@ - (id) initWithPath:(NSString *)path properties:(NSDictionary *)properties JSScript *script = NULL; JSObject *scriptObject = NULL; jsval returnValue = JSVAL_VOID; - NSEnumerator *keyEnum = nil; NSString *key = nil; id property = nil; @@ -182,7 +181,7 @@ - (id) initWithPath:(NSString *)path properties:(NSDictionary *)properties // Set default properties from manifest.plist NSDictionary *defaultProperties = [self defaultPropertiesFromPath:path]; - for (keyEnum = [defaultProperties keyEnumerator]; (key = [keyEnum nextObject]); ) + foreachkey (key, defaultProperties) { if ([key isKindOfClass:[NSString class]]) { @@ -203,7 +202,7 @@ - (id) initWithPath:(NSString *)path properties:(NSDictionary *)properties // Set properties. (read-only) if (!problem && properties != nil) { - for (keyEnum = [properties keyEnumerator]; (key = [keyEnum nextObject]); ) + foreachkey (key, properties) { if ([key isKindOfClass:[NSString class]]) { diff --git a/src/Core/Scripting/OOJSShip.m b/src/Core/Scripting/OOJSShip.m index acb993f9e..f1315a9e7 100644 --- a/src/Core/Scripting/OOJSShip.m +++ b/src/Core/Scripting/OOJSShip.m @@ -2917,9 +2917,8 @@ static JSBool ShipFindNearestStation(JSContext *context, uintN argc, jsval *vp) double sdist, distance = 1E32; - NSEnumerator *statEnum = [[UNIVERSE stations] objectEnumerator]; StationEntity *se = nil; - while ((se = [statEnum nextObject])) + foreach (se, [UNIVERSE stations]) { sdist = HPdistance2([thisEnt position],[se position]); @@ -4084,9 +4083,8 @@ static JSBool ShipThreatAssessment(JSContext *context, uintN argc, jsval *vp) } /* Turret count is public knowledge */ - NSEnumerator *subEnum = [thisEnt shipSubEntityEnumerator]; ShipEntity *se = nil; - while ((se = [subEnum nextObject])) + foreach (se, [thisEnt shipSubEntityEnumerator]) { if ([se isTurret]) { diff --git a/src/Core/Scripting/OOJSWorldScripts.m b/src/Core/Scripting/OOJSWorldScripts.m index c6dee7a1c..bade8e3d1 100644 --- a/src/Core/Scripting/OOJSWorldScripts.m +++ b/src/Core/Scripting/OOJSWorldScripts.m @@ -105,12 +105,11 @@ Since WorldScriptsGetProperty() will be called for each access anyway, */ NSArray *names = nil; - NSEnumerator *nameEnum = nil; NSString *name = nil; names = [OOPlayerForScripting() worldScriptNames]; - for (nameEnum = [names objectEnumerator]; (name = [nameEnum nextObject]); ) + foreach (name, names) { if (!JS_DefineProperty(context, object, [name UTF8String], JSVAL_NULL, WorldScriptsGetProperty, NULL, OOJS_PROP_READONLY_CB)) return NO; } diff --git a/src/Core/Scripting/OOJavaScriptEngine.m b/src/Core/Scripting/OOJavaScriptEngine.m index 078a263e4..d3ca2b3c7 100644 --- a/src/Core/Scripting/OOJavaScriptEngine.m +++ b/src/Core/Scripting/OOJavaScriptEngine.m @@ -1281,7 +1281,6 @@ static BOOL JSNewNSArrayValue(JSContext *context, NSArray *array, jsval *value) JSObject *result = NULL; BOOL OK = YES; - NSEnumerator *keyEnum = nil; id key = nil; jsval value; jsint index; @@ -1293,7 +1292,7 @@ static BOOL JSNewNSArrayValue(JSContext *context, NSArray *array, jsval *value) result = JS_NewObject(context, NULL, NULL, NULL); // create object of class Object if (result != NULL) { - for (keyEnum = [dictionary keyEnumerator]; (key = [keyEnum nextObject]); ) + foreachkey (key, dictionary) { if ([key isKindOfClass:[NSString class]] && [key length] != 0) { diff --git a/src/Core/Scripting/OOLegacyScriptWhitelist.m b/src/Core/Scripting/OOLegacyScriptWhitelist.m index df99516a1..c504a40a8 100644 --- a/src/Core/Scripting/OOLegacyScriptWhitelist.m +++ b/src/Core/Scripting/OOLegacyScriptWhitelist.m @@ -71,7 +71,6 @@ { NSAutoreleasePool *pool = nil; NSMutableArray *result = nil; - NSEnumerator *statementEnum = nil; id statement = nil; NSUInteger index = 0; @@ -79,7 +78,7 @@ result = [NSMutableArray arrayWithCapacity:[script count]]; - for (statementEnum = [script objectEnumerator]; (statement = [statementEnum nextObject]); ) + foreach (statement, script) { SanStackElement subStack = { @@ -124,7 +123,6 @@ static NSArray *OOSanitizeLegacyScriptConditionsInternal(NSArray *conditions, SanStackElement *stack) { - NSEnumerator *conditionEnum = nil; NSString *condition = nil; NSMutableArray *result = nil; NSArray *tokens = nil; @@ -135,7 +133,7 @@ result = [NSMutableArray arrayWithCapacity:[conditions count]]; - for (conditionEnum = [conditions objectEnumerator]; (condition = [conditionEnum nextObject]); ) + foreach (condition, conditions) { SanStackElement subStack = { From ecc436d39e394fbee42dd9c5ea30344474ee1dfc Mon Sep 17 00:00:00 2001 From: "C.W. Betts" Date: Sat, 9 May 2015 12:23:40 -0600 Subject: [PATCH 4/9] Slowly picking away at this... --- src/Core/Entities/PlayerEntity.m | 35 ++++------ src/Core/Entities/PlayerEntityContracts.m | 5 +- .../Entities/PlayerEntityLegacyScriptEngine.m | 6 +- src/Core/Materials/OOShaderMaterial.m | 12 ++-- src/Core/Materials/OOShaderProgram.m | 8 +-- src/Core/Materials/OOTexture.m | 3 +- src/Core/OOOpenGLExtensionManager.m | 9 +-- src/Core/OORoleSet.m | 9 +-- src/Core/OOShipRegistry.m | 66 +++++++------------ src/Core/OOSkyDrawable.m | 6 +- src/Core/OOStringParsing.m | 3 +- src/Core/OXPVerifier/OOOXPVerifier.m | 34 ++++------ src/Core/OXPVerifier/OOOXPVerifierStage.m | 3 +- src/Core/OXPVerifier/OOPListSchemaVerifier.m | 6 +- src/Core/OXPVerifier/OOTextureVerifierStage.m | 8 +-- src/Core/Scripting/OOPListScript.m | 6 +- src/Core/Scripting/OOScript.m | 3 +- src/Core/Scripting/OOScriptTimer.m | 3 +- 18 files changed, 80 insertions(+), 145 deletions(-) diff --git a/src/Core/Entities/PlayerEntity.m b/src/Core/Entities/PlayerEntity.m index a2fcc3735..da3609dbe 100644 --- a/src/Core/Entities/PlayerEntity.m +++ b/src/Core/Entities/PlayerEntity.m @@ -810,9 +810,8 @@ - (NSDictionary *) commanderDataDictionary // extra equipment flags NSMutableDictionary *equipment = [NSMutableDictionary dictionary]; - NSEnumerator *eqEnum = nil; NSString *eqDesc = nil; - for (eqEnum = [self equipmentEnumerator]; (eqDesc = [eqEnum nextObject]); ) + foreach(eqDesc, [self equipmentEnumerator]) { [equipment oo_setInteger:[self countEquipmentItem:eqDesc] forKey:eqDesc]; } @@ -902,9 +901,8 @@ - (NSDictionary *) commanderDataDictionary // wormhole information NSMutableArray *wormholeDicts = [NSMutableArray arrayWithCapacity:[scannedWormholes count]]; - NSEnumerator *wormholes = [scannedWormholes objectEnumerator]; WormholeEntity *wh = nil; - foreach(wh, wormholes) + foreach (wh, scannedWormholes) { [wormholeDicts addObject:[wh getDict]]; } @@ -1519,11 +1517,10 @@ energy bomb (900 credits). This must be done after missiles are // wormholes NSArray * whArray; whArray = [dict objectForKey:@"wormholes"]; - NSEnumerator * whDicts = [whArray objectEnumerator]; NSDictionary * whCurrDict; [scannedWormholes release]; scannedWormholes = [[NSMutableArray alloc] initWithCapacity:[whArray count]]; - while ((whCurrDict = [whDicts nextObject]) != nil) + foreach(whCurrDict, whArray) { WormholeEntity * wh = [[WormholeEntity alloc] initWithDict:whCurrDict]; [scannedWormholes addObject:wh]; @@ -5791,9 +5788,8 @@ - (GLfloat) doesHitLine:(HPVector)v0 :(HPVector)v1 :(ShipEntity **)hitEntity shields = true; } - NSEnumerator *subEnum = nil; ShipEntity *se = nil; - for (subEnum = [self shipSubEntityEnumerator]; (se = [subEnum nextObject]); ) + foreach(se, [self shipSubEntityEnumerator]) { HPVector p0 = [se absolutePositionForSubentity]; Triangle ijk = [se absoluteIJKForSubentity]; @@ -7494,14 +7490,13 @@ - (NSArray *) equipmentList GuiDisplayGen *gui = [UNIVERSE gui]; NSMutableArray *quip1 = [NSMutableArray array]; // damaged NSMutableArray *quip2 = [NSMutableArray array]; // working - NSEnumerator *eqTypeEnum = nil; OOEquipmentType *eqType = nil; NSString *desc = nil; NSString *alldesc = nil; BOOL prioritiseDamaged = [[gui userSettings] oo_boolForKey:kGuiStatusPrioritiseDamaged defaultValue:YES]; - for (eqTypeEnum = [OOEquipmentType reverseEquipmentEnumerator]; (eqType = [eqTypeEnum nextObject]); ) + foreach(eqType, [OOEquipmentType reverseEquipmentEnumerator]) { if ([eqType isVisible]) { @@ -7729,12 +7724,11 @@ - (NSArray *) cargoList { NSMutableArray *manifest = [NSMutableArray array]; NSArray *list = [self cargoListForScripting]; - NSEnumerator *cargoEnum = nil; NSDictionary *commodity; if (specialCargo) [manifest addObject:specialCargo]; - for (cargoEnum = [list objectEnumerator]; (commodity = [cargoEnum nextObject]); ) + foreach(commodity, list) { NSInteger quantity = [commodity oo_integerForKey:@"quantity"]; NSString *units = [commodity oo_stringForKey:@"unit"]; @@ -8083,10 +8077,9 @@ - (NSDictionary *) markedDestinations [self prepareMarkedDestination:destinations:marker]; } - NSEnumerator *keyEnum = nil; NSString *key = nil; - for (keyEnum = [missionDestinations keyEnumerator]; (key = [keyEnum nextObject]); ) + foreachkey(key, missionDestinations) { marker = [missionDestinations objectForKey:key]; [self prepareMarkedDestination:destinations:marker]; @@ -11897,10 +11890,9 @@ - (void) doWorldScriptEvent:(jsid)message inContext:(JSContext *)context withArg { NSParameterAssert(context != NULL && JS_IsInRequest(context)); - NSEnumerator *scriptEnum = nil; OOScript *theScript = nil; - for (scriptEnum = [worldScripts objectEnumerator]; (theScript = [scriptEnum nextObject]); ) + foreachkey (theScript, worldScripts) { OOJSStartTimeLimiterWithTimeLimit(limit); [theScript callMethod:message inContext:context withArguments:argv count:argc result:NULL]; @@ -12142,9 +12134,8 @@ - (void)addScannedWormhole:(WormholeEntity*)whole assert(whole != nil); // Only add if we don't have it already! - NSEnumerator *wormholes = [scannedWormholes objectEnumerator]; WormholeEntity *wh = nil; - while ((wh = [wormholes nextObject])) + foreach (wh, scannedWormholes) { if (wh == whole) return; } @@ -12165,10 +12156,9 @@ - (void)updateWormholes double now = [self clockTimeAdjusted]; NSMutableArray * savedWormholes = [[NSMutableArray alloc] initWithCapacity:[scannedWormholes count]]; - NSEnumerator * wormholes = [scannedWormholes objectEnumerator]; WormholeEntity *wh; - while ((wh = (WormholeEntity*)[wormholes nextObject])) + foreachkey (wh, scannedWormholes) { // TODO: Start drawing wormhole exit a few seconds before the first // ship is disgorged. @@ -12200,7 +12190,6 @@ - (NSArray *) scannedWormholes - (void) initialiseMissionDestinations:(NSDictionary *)destinations andLegacy:(NSArray *)legacy { - NSEnumerator *keyEnum = nil; NSString *key = nil; id value = nil; @@ -12209,7 +12198,7 @@ - (void) initialiseMissionDestinations:(NSDictionary *)destinations andLegacy:(N [missionDestinations release]; missionDestinations = [[NSMutableDictionary alloc] init]; - for (keyEnum = [destinations keyEnumerator]; (key = [keyEnum nextObject]); ) + foreachkey (key, destinations) { value = [destinations objectForKey:key]; if (value != nil) @@ -12227,7 +12216,7 @@ - (void) initialiseMissionDestinations:(NSDictionary *)destinations andLegacy:(N { OOSystemID dest; NSNumber *legacyMarker; - for (keyEnum = [legacy objectEnumerator]; (legacyMarker = [keyEnum nextObject]); ) + foreach (legacyMarker, legacy) { dest = [legacyMarker intValue]; [self addMissionDestinationMarker:[self defaultMarker:dest]]; diff --git a/src/Core/Entities/PlayerEntityContracts.m b/src/Core/Entities/PlayerEntityContracts.m index 1403a3732..4655b563b 100644 --- a/src/Core/Entities/PlayerEntityContracts.m +++ b/src/Core/Entities/PlayerEntityContracts.m @@ -1933,11 +1933,10 @@ - (void) newShipCommonSetup:(NSString *)shipKey yardInfo:(NSDictionary *)ship_in // keep track of portable equipment.. NSMutableSet *portable_equipment = [NSMutableSet set]; - NSEnumerator *eqEnum = nil; NSString *eq_desc = nil; OOEquipmentType *item = nil; - for (eqEnum = [self equipmentEnumerator]; (eq_desc = [eqEnum nextObject]);) + foreach (eq_desc, [self equipmentEnumerator]) { item = [OOEquipmentType equipmentTypeWithIdentifier:eq_desc]; if ([item isPortableBetweenShips]) [portable_equipment addObject:eq_desc]; @@ -1947,7 +1946,7 @@ - (void) newShipCommonSetup:(NSString *)shipKey yardInfo:(NSDictionary *)ship_in [self removeAllEquipment]; // restore portable equipment - for (eqEnum = [portable_equipment objectEnumerator]; (eq_desc = [eqEnum nextObject]); ) + foreach (eq_desc, portable_equipment) { [self addEquipmentItem:eq_desc withValidation:NO inContext:@"portable"]; } diff --git a/src/Core/Entities/PlayerEntityLegacyScriptEngine.m b/src/Core/Entities/PlayerEntityLegacyScriptEngine.m index 9c1fd9ce3..f4ecc41d2 100644 --- a/src/Core/Entities/PlayerEntityLegacyScriptEngine.m +++ b/src/Core/Entities/PlayerEntityLegacyScriptEngine.m @@ -231,11 +231,10 @@ static void PerformActionStatment(NSArray *statement, Entity *target) static BOOL TestScriptConditions(NSArray *conditions) { - NSEnumerator *condEnum = nil; NSArray *condition = nil; PlayerEntity *player = PLAYER; - for (condEnum = [conditions objectEnumerator]; (condition = [condEnum nextObject]); ) + foreach(condition, conditions) { if (![player scriptTestCondition:condition]) return NO; } @@ -609,13 +608,12 @@ have been generated by OOSanitizeLegacyScriptConditions() and doesn't - (NSString *) expandScriptRightHandSide:(NSArray *)rhsComponents { NSMutableArray *result = nil; - NSEnumerator *componentEnum = nil; NSArray *component = nil; NSString *value = nil; result = [NSMutableArray arrayWithCapacity:[rhsComponents count]]; - for (componentEnum = [rhsComponents objectEnumerator]; (component = [componentEnum nextObject]); ) + foreach (component, rhsComponents) { /* Each component is a two-element array. The second element is a string. The first element is a boolean indicating whether the diff --git a/src/Core/Materials/OOShaderMaterial.m b/src/Core/Materials/OOShaderMaterial.m index 69b477d5d..d100992d7 100644 --- a/src/Core/Materials/OOShaderMaterial.m +++ b/src/Core/Materials/OOShaderMaterial.m @@ -478,7 +478,6 @@ - (void)setUniform:(NSString *)uniformName quaternionValue:(Quaternion)value asM -(void)addUniformsFromDictionary:(NSDictionary *)uniformDefs withBindingTarget:(id)target { - NSEnumerator *uniformEnum = nil; NSString *name = nil; id definition = nil; id value = nil; @@ -505,7 +504,7 @@ -(void)addUniformsFromDictionary:(NSDictionary *)uniformDefs withBindingTarget:( ranrot_srand(randomSeed); keys = [[uniformDefs allKeys] sortedArrayUsingSelector:@selector(compare:)]; - for (uniformEnum = [keys objectEnumerator]; (name = [uniformEnum nextObject]); ) + foreach(name, keys) { gotValue = NO; definition = [uniformDefs objectForKey:name]; @@ -655,7 +654,6 @@ -(void)addUniformsFromDictionary:(NSDictionary *)uniformDefs withBindingTarget:( - (BOOL)doApply { - NSEnumerator *uniformEnum = nil; OOShaderUniform *uniform = nil; uint32_t i; @@ -673,7 +671,7 @@ - (BOOL)doApply @try { - for (uniformEnum = [uniforms objectEnumerator]; (uniform = [uniformEnum nextObject]); ) + foreach(uniform, uniforms) { [uniform apply]; } @@ -813,13 +811,12 @@ - (void) addTexturesFromArray:(NSArray *)textureObjects unitCount:(GLuint)max static NSString *MacrosToString(NSDictionary *macros) { NSMutableString *result = nil; - NSEnumerator *macroEnum = nil; id key = nil, value = nil; if (macros == nil) return nil; result = [NSMutableString string]; - for (macroEnum = [macros keyEnumerator]; (key = [macroEnum nextObject]); ) + foreachkey(key, macros) { if (![key isKindOfClass:[NSString class]]) continue; value = [macros objectForKey:key]; @@ -843,7 +840,6 @@ static BOOL GetShaderSource(NSString *fileName, NSString *shaderType, NSString * { NSString *result = nil; NSArray *extensions = nil; - NSEnumerator *extEnum = nil; NSString *extension = nil; NSString *nameWithExtension = nil; @@ -857,7 +853,7 @@ static BOOL GetShaderSource(NSString *fileName, NSString *shaderType, NSString * // Futureproofing -- in future, we may wish to support automatic selection between supported shader languages. if (![fileName pathHasExtensionInArray:extensions]) { - for (extEnum = [extensions objectEnumerator]; (extension = [extEnum nextObject]); ) + foreachkey(extension, extensions) { nameWithExtension = [fileName stringByAppendingPathExtension:extension]; result = [ResourceManager stringFromFilesNamed:nameWithExtension diff --git a/src/Core/Materials/OOShaderProgram.m b/src/Core/Materials/OOShaderProgram.m index 37352d513..9d70590b8 100644 --- a/src/Core/Materials/OOShaderProgram.m +++ b/src/Core/Materials/OOShaderProgram.m @@ -392,9 +392,8 @@ - (void) bindAttributes:(NSDictionary *)attributeBindings OO_ENTER_OPENGL(); NSString *attrKey = nil; - NSEnumerator *keyEnum = nil; - for (keyEnum = [attributeBindings keyEnumerator]; (attrKey = [keyEnum nextObject]); ) + foreachkey(attrKey, attributeBindings) { OOGL(glBindAttribLocationARB(program, [attributeBindings oo_unsignedIntForKey:attrKey], [attrKey UTF8String])); } @@ -412,7 +411,7 @@ - (void) bindStandardMatrixUniforms OO_ENTER_OPENGL(); [matrixManager syncModelView]; - while ((obj = [enumerator nextObject])) + foreachkey(obj, enumerator) { if ([obj isKindOfClass:[NSArray class]]) { @@ -444,7 +443,6 @@ static BOOL GetShaderSource(NSString *fileName, NSString *shaderType, NSString * { NSString *result = nil; NSArray *extensions = nil; - NSEnumerator *extEnum = nil; NSString *extension = nil; NSString *nameWithExtension = nil; @@ -458,7 +456,7 @@ static BOOL GetShaderSource(NSString *fileName, NSString *shaderType, NSString * // Futureproofing -- in future, we may wish to support automatic selection between supported shader languages. if (![fileName pathHasExtensionInArray:extensions]) { - for (extEnum = [extensions objectEnumerator]; (extension = [extEnum nextObject]); ) + foreach(extension, extensions) { nameWithExtension = [fileName stringByAppendingPathExtension:extension]; result = [ResourceManager stringFromFilesNamed:nameWithExtension diff --git a/src/Core/Materials/OOTexture.m b/src/Core/Materials/OOTexture.m index ef71da3a8..a05df2b84 100644 --- a/src/Core/Materials/OOTexture.m +++ b/src/Core/Materials/OOTexture.m @@ -400,8 +400,7 @@ + (NSSet *) allTextures { NSMutableSet *result = [NSMutableSet setWithCapacity:[sAllLiveTextures count]]; NSValue *box = nil; - NSEnumerator *texEnum = nil; - for (texEnum = [sAllLiveTextures objectEnumerator]; (box = [texEnum nextObject]); ) + foreach(box, sAllLiveTextures) { [result addObject:[box pointerValue]]; } diff --git a/src/Core/OOOpenGLExtensionManager.m b/src/Core/OOOpenGLExtensionManager.m index 225dd3203..93b9dd481 100644 --- a/src/Core/OOOpenGLExtensionManager.m +++ b/src/Core/OOOpenGLExtensionManager.m @@ -148,9 +148,8 @@ - (NSDictionary *) lookUpPerGPUSettingsWithVersionString:(NSString *)version ext { NSArray *components = [extensionString componentsSeparatedByString:@" "]; NSMutableArray *result = [NSMutableArray arrayWithCapacity:[components count]]; - NSEnumerator *extEnum = nil; NSString *extStr = nil; - for (extEnum = [components objectEnumerator]; (extStr = [extEnum nextObject]); ) + foreach (extStr, components) { if ([extStr length] > 0) [result addObject:extStr]; } @@ -514,10 +513,9 @@ - (void)checkShadersSupported * -noshaders may help get the game up and running at a frame rate * where thegraphics settings can be changed. - CIM */ NSArray *arguments = [[NSProcessInfo processInfo] arguments]; - NSEnumerator *argEnum = nil; NSString *arg = nil; // scan for shader overrides: -noshaders || --noshaders - for (argEnum = [arguments objectEnumerator]; (arg = [argEnum nextObject]); ) + foreach (arg, arguments) { if ([arg isEqual:@"-noshaders"] || [arg isEqual:@"--noshaders"]) { @@ -712,11 +710,10 @@ - (NSDictionary *) lookUpPerGPUSettingsWithVersionString:(NSString *)versionStr NSArray *keys = [[configurations allKeys] sortedArrayUsingFunction:CompareGPUSettingsByPriority context:configurations]; - NSEnumerator *keyEnum = nil; NSString *key = nil; NSDictionary *config = nil; - for (keyEnum = [keys objectEnumerator]; (key = [keyEnum nextObject]); ) + foreach (key, keys) { config = [configurations oo_dictionaryForKey:key]; if (EXPECT_NOT(config == nil)) continue; diff --git a/src/Core/OORoleSet.m b/src/Core/OORoleSet.m index d4c20a282..82552ac8c 100644 --- a/src/Core/OORoleSet.m +++ b/src/Core/OORoleSet.m @@ -115,7 +115,6 @@ - (id)copyWithZone:(NSZone *)zone - (NSString *)roleString { NSArray *roles = nil; - NSEnumerator *roleEnum = nil; NSString *role = nil; float probability; NSMutableString *result = nil; @@ -126,7 +125,7 @@ - (NSString *)roleString // Construct role string. We always do this so that it's in a normalized form. result = [NSMutableString string]; roles = [self sortedRoles]; - for (roleEnum = [roles objectEnumerator]; (role = [roleEnum nextObject]); ) + foreach(role, roles) { if (!first) [result appendString:@" "]; else first = NO; @@ -192,7 +191,6 @@ - (NSDictionary *)rolesAndProbabilities - (NSString *)anyRole { - NSEnumerator *roleEnum = nil; NSString *role = nil; float prob, selected; @@ -201,7 +199,7 @@ - (NSString *)anyRole if ([_rolesAndProbabilities count] == 0) return nil; - for (roleEnum = [_rolesAndProbabilities keyEnumerator]; (role = [roleEnum nextObject]); ) + foreachkey (role, _rolesAndProbabilities) { prob += [_rolesAndProbabilities oo_floatForKey:role]; if (selected <= prob) break; @@ -263,7 +261,6 @@ @implementation OORoleSet (OOPrivate) - (id)initWithRolesAndProbabilities:(NSDictionary *)dict { - NSEnumerator *roleEnum = nil; NSString *role = nil; float prob; @@ -293,7 +290,7 @@ - (id)initWithRolesAndProbabilities:(NSDictionary *)dict _rolesAndProbabilities = [tDict copy]; - for (roleEnum = [dict keyEnumerator]; (role = [roleEnum nextObject]); ) + foreachkey(role, dict) { prob = [dict oo_floatForKey:role defaultValue:-1]; if (prob < 0) diff --git a/src/Core/OOShipRegistry.m b/src/Core/OOShipRegistry.m index 96fe46995..db7941b41 100644 --- a/src/Core/OOShipRegistry.m +++ b/src/Core/OOShipRegistry.m @@ -384,7 +384,6 @@ - (void) loadShipData - (void) loadDemoShipConditions { NSMutableArray *conditionScripts = [[NSMutableArray alloc] init]; - NSEnumerator *enumerator = nil; NSDictionary *key = nil; NSArray *initialDemoShips = nil; @@ -393,7 +392,7 @@ - (void) loadDemoShipConditions andMerge:YES cache:NO]; - for (enumerator = [initialDemoShips objectEnumerator]; (key = [enumerator nextObject]); ) + foreach(key, initialDemoShips) { NSString *conditions = [key oo_stringForKey:kOODemoShipConditions defaultValue:nil]; if (conditions != nil) @@ -415,7 +414,6 @@ - (void) loadDemoShipConditions */ - (void) loadDemoShips { - NSEnumerator *enumerator = nil; NSDictionary *key = nil; NSArray *initialDemoShips = nil; NSMutableArray *demoShips = nil; @@ -429,7 +427,7 @@ - (void) loadDemoShips demoShips = [NSMutableArray arrayWithArray:initialDemoShips]; // Note: iterate over initialDemoShips to avoid mutating the collection being enu,erated. - for (enumerator = [initialDemoShips objectEnumerator]; (key = [enumerator nextObject]); ) + foreach(key, initialDemoShips) { NSString *shipKey = [key oo_stringForKey:kOODemoShipKey]; if (![key isKindOfClass:[NSDictionary class]] || [self shipInfoForKey:shipKey] == nil) @@ -535,14 +533,13 @@ - (void) loadCachedRoleProbabilitySets { NSDictionary *cachedSets = nil; NSMutableDictionary *restoredSets = nil; - NSEnumerator *roleEnum = nil; NSString *role = nil; cachedSets = [[OOCacheManager sharedCache] objectForKey:kRoleWeightsCacheKey inCache:kShipRegistryCacheName]; if (cachedSets == nil) return; restoredSets = [NSMutableDictionary dictionaryWithCapacity:[cachedSets count]]; - for (roleEnum = [cachedSets keyEnumerator]; (role = [roleEnum nextObject]); ) + foreachkey(role, cachedSets) { [restoredSets setObject:[OOProbabilitySet probabilitySetWithPropertyListRepresentation:[cachedSets objectForKey:role]] forKey:role]; } @@ -554,11 +551,9 @@ - (void) loadCachedRoleProbabilitySets - (void) buildRoleProbabilitySets { NSMutableDictionary *probabilitySets = nil; - NSEnumerator *shipEnum = nil; NSString *shipKey = nil; NSDictionary *shipEntry = nil; NSString *roles = nil; - NSEnumerator *roleEnum = nil; NSString *role = nil; OOProbabilitySet *pset = nil; NSMutableDictionary *cacheEntry = nil; @@ -566,7 +561,7 @@ - (void) buildRoleProbabilitySets probabilitySets = [NSMutableDictionary dictionary]; // Build role sets - for (shipEnum = [_shipData keyEnumerator]; (shipKey = [shipEnum nextObject]); ) + foreachkey(shipKey, _shipData) { shipEntry = [_shipData objectForKey:shipKey]; roles = [shipEntry oo_stringForKey:@"roles"]; @@ -576,7 +571,7 @@ - (void) buildRoleProbabilitySets // Convert role sets to immutable form, and build cache entry. // Note: we iterate over a copy of the keys to avoid mutating while iterating. cacheEntry = [NSMutableDictionary dictionaryWithCapacity:[probabilitySets count]]; - for (roleEnum = [[probabilitySets allKeys] objectEnumerator]; (role = [roleEnum nextObject]); ) + foreach(role, [probabilitySets allKeys]) { pset = [probabilitySets objectForKey:role]; pset = [[pset copy] autorelease]; @@ -606,7 +601,6 @@ - (void) buildRoleProbabilitySets - (BOOL) applyLikeShips:(NSMutableDictionary *)ioData withKey:(NSString *)likeKey { NSMutableSet *remainingLikeShips = nil; - NSEnumerator *enumerator = nil; NSString *key = nil; NSString *parentKey = nil; NSDictionary *shipEntry = nil; @@ -616,7 +610,7 @@ - (BOOL) applyLikeShips:(NSMutableDictionary *)ioData withKey:(NSString *)likeKe // Build set of ships with like_ship references remainingLikeShips = [NSMutableSet set]; - for (enumerator = [ioData keyEnumerator]; (key = [enumerator nextObject]); ) + foreachkey(key, ioData) { shipEntry = [ioData objectForKey:key]; if ([shipEntry oo_stringForKey:likeKey] != nil) @@ -628,7 +622,7 @@ - (BOOL) applyLikeShips:(NSMutableDictionary *)ioData withKey:(NSString *)likeKe count = lastCount = [remainingLikeShips count]; while (count != 0) { - for (enumerator = [[[remainingLikeShips copy] autorelease] objectEnumerator]; (key = [enumerator nextObject]); ) + foreach(key, [[remainingLikeShips copy] autorelease]) { // Look up like_ship entry shipEntry = [ioData objectForKey:key]; @@ -654,7 +648,7 @@ - (BOOL) applyLikeShips:(NSMutableDictionary *)ioData withKey:(NSString *)likeKe don't have is_external_dependency set. */ reportedBadShips = [NSMutableArray array]; - for (enumerator = [remainingLikeShips objectEnumerator]; (key = [enumerator nextObject]); ) + foreach(key, remainingLikeShips) { if (![[ioData oo_dictionaryForKey:key] oo_boolForKey:@"is_external_dependency"]) { @@ -737,11 +731,10 @@ - (NSMutableDictionary *) mergeShip:(NSDictionary *)child withParent:(NSDictiona - (BOOL) makeShipEntriesMutable:(NSMutableDictionary *)ioData { - NSEnumerator *shipKeyEnum = nil; NSString *shipKey = nil; NSDictionary *shipEntry = nil; - for (shipKeyEnum = [[ioData allKeys] objectEnumerator]; (shipKey = [shipKeyEnum nextObject]); ) + foreach(shipKey, [ioData allKeys]) { shipEntry = [ioData objectForKey:shipKey]; if (![shipEntry isKindOfClass:[NSDictionary class]]) @@ -764,7 +757,6 @@ - (BOOL) makeShipEntriesMutable:(NSMutableDictionary *)ioData - (BOOL) loadAndApplyShipDataOverrides:(NSMutableDictionary *)ioData { - NSEnumerator *shipKeyEnum = nil; NSString *shipKey = nil; NSMutableDictionary *shipEntry = nil; NSDictionary *overrides = nil; @@ -775,7 +767,7 @@ - (BOOL) loadAndApplyShipDataOverrides:(NSMutableDictionary *)ioData mergeMode:MERGE_SMART cache:NO]; - for (shipKeyEnum = [overrides keyEnumerator]; (shipKey = [shipKeyEnum nextObject]); ) + foreachkey(shipKey, overrides) { shipEntry = [ioData objectForKey:shipKey]; if (shipEntry != nil) @@ -798,17 +790,15 @@ - (BOOL) loadAndApplyShipDataOverrides:(NSMutableDictionary *)ioData - (BOOL) stripPrivateKeys:(NSMutableDictionary *)ioData { - NSEnumerator *shipKeyEnum = nil; NSString *shipKey = nil; NSMutableDictionary *shipEntry = nil; - NSEnumerator *attrKeyEnum = nil; NSString *attrKey = nil; - for (shipKeyEnum = [ioData keyEnumerator]; (shipKey = [shipKeyEnum nextObject]); ) + foreachkey(shipKey, ioData) { shipEntry = [ioData objectForKey:shipKey]; - for (attrKeyEnum = [shipEntry keyEnumerator]; (attrKey = [attrKeyEnum nextObject]); ) + foreachkey(attrKey, shipEntry) { if ([attrKey hasPrefix:@"_oo_"]) { @@ -830,7 +820,6 @@ - (BOOL) stripPrivateKeys:(NSMutableDictionary *)ioData */ - (BOOL) loadAndMergeShipyard:(NSMutableDictionary *)ioData { - NSEnumerator *shipKeyEnum = nil; NSString *shipKey = nil; NSMutableDictionary *shipEntry = nil; NSDictionary *shipyard = nil; @@ -840,7 +829,7 @@ - (BOOL) loadAndMergeShipyard:(NSMutableDictionary *)ioData NSMutableArray *playerShips = nil; // Strip out any shipyard stuff in shipdata (there shouldn't be any). - for (shipKeyEnum = [ioData keyEnumerator]; (shipKey = [shipKeyEnum nextObject]); ) + foreachkey(shipKey, ioData) { shipEntry = [ioData objectForKey:shipKey]; if ([shipEntry objectForKey:@"_oo_shipyard"] != nil) @@ -861,7 +850,7 @@ - (BOOL) loadAndMergeShipyard:(NSMutableDictionary *)ioData playerShips = [NSMutableArray arrayWithCapacity:[shipyard count]]; // Insert merged shipyard and shipyardOverrides entries. - for (shipKeyEnum = [shipyard keyEnumerator]; (shipKey = [shipKeyEnum nextObject]); ) + foreachkey(shipKey, shipyard) { shipEntry = [ioData objectForKey:shipKey]; if (shipEntry != nil) @@ -889,11 +878,9 @@ - (BOOL) loadAndMergeShipyard:(NSMutableDictionary *)ioData - (BOOL) canonicalizeAndTagSubentities:(NSMutableDictionary *)ioData { - NSEnumerator *shipKeyEnum = nil; NSString *shipKey = nil; NSMutableDictionary *shipEntry = nil; NSArray *subentityDeclarations = nil; - NSEnumerator *subentityEnum = nil; id subentityDecl = nil; NSDictionary *subentityDict = nil; NSString *subentityKey = nil; @@ -907,7 +894,7 @@ - (BOOL) canonicalizeAndTagSubentities:(NSMutableDictionary *)ioData // _oo_is_subentity=YES to all entries used as subentities. // Iterate over all ships. (Iterates over a copy of keys since it mutates the dictionary.) - for (shipKeyEnum = [[ioData allKeys] objectEnumerator]; (shipKey = [shipKeyEnum nextObject]); ) + foreach(shipKey, [ioData allKeys]) { shipEntry = [ioData objectForKey:shipKey]; remove = NO; @@ -918,7 +905,7 @@ - (BOOL) canonicalizeAndTagSubentities:(NSMutableDictionary *)ioData if (subentityDeclarations != nil) { okSubentities = [NSMutableArray arrayWithCapacity:[subentityDeclarations count]]; - for (subentityEnum = [subentityDeclarations objectEnumerator]; (subentityDecl = [subentityEnum nextObject]); ) + foreach(subentityDecl, subentityDeclarations) { subentityDict = [self canonicalizeSubentityDeclaration:subentityDecl forShip:shipKey shipData:ioData fatalError:&fatal]; @@ -987,14 +974,13 @@ - (BOOL) canonicalizeAndTagSubentities:(NSMutableDictionary *)ioData - (BOOL) removeUnusableEntries:(NSMutableDictionary *)ioData shipMode:(BOOL)shipMode { - NSEnumerator *shipKeyEnum = nil; NSString *shipKey = nil; NSMutableDictionary *shipEntry = nil; BOOL remove; NSString *modelName = nil; // Clean out invalid entries and templates. (Iterates over a copy of keys since it mutates the dictionary.) - for (shipKeyEnum = [[ioData allKeys] objectEnumerator]; (shipKey = [shipKeyEnum nextObject]); ) + foreach(shipKey, [ioData allKeys]) { shipEntry = [ioData objectForKey:shipKey]; remove = NO; @@ -1035,7 +1021,6 @@ - (BOOL) removeUnusableEntries:(NSMutableDictionary *)ioData shipMode:(BOOL)ship */ - (BOOL) sanitizeConditions:(NSMutableDictionary *)ioData { - NSEnumerator *shipKeyEnum = nil; NSString *shipKey = nil; NSMutableDictionary *shipEntry = nil; NSMutableDictionary *mutableShipyard = nil; @@ -1047,7 +1032,7 @@ - (BOOL) sanitizeConditions:(NSMutableDictionary *)ioData NSMutableArray *conditionScripts = [[NSMutableArray alloc] init]; - for (shipKeyEnum = [[ioData allKeys] objectEnumerator]; (shipKey = [shipKeyEnum nextObject]); ) + foreach(shipKey, [ioData allKeys]) { shipEntry = [ioData objectForKey:shipKey]; conditions = [shipEntry objectForKey:@"conditions"]; @@ -1216,7 +1201,6 @@ - (void) mergeShipRoles:(NSString *)roles intoProbabilityMap:(NSMutableDictionary *)probabilitySets { NSDictionary *rolesAndWeights = nil; - NSEnumerator *roleEnum = nil; NSString *role = nil; OOMutableProbabilitySet *probSet = nil; @@ -1243,7 +1227,7 @@ - (void) mergeShipRoles:(NSString *)roles rolesAndWeights = mutable; } - for (roleEnum = [rolesAndWeights keyEnumerator]; (role = [roleEnum nextObject]); ) + foreachkey (role, rolesAndWeights) { probSet = [probabilitySets objectForKey:role]; if (probSet == nil) @@ -1650,12 +1634,11 @@ - (BOOL) shipIsBallTurretForKey:(NSString *)shipKey inShipData:(NSDictionary *)s { // Test for presence of setup_actions containing initialiseTurret. NSArray *setupActions = nil; - NSEnumerator *actionEnum = nil; NSString *action = nil; setupActions = [[shipData oo_dictionaryForKey:shipKey] oo_arrayForKey:@"setup_actions"]; - for (actionEnum = [setupActions objectEnumerator]; (action = [actionEnum nextObject]); ) + foreachkey(action, setupActions) { if ([[ScanTokensFromString(action) objectAtIndex:0] isEqualToString:@"initialiseTurret"]) return YES; } @@ -1733,9 +1716,8 @@ static void DumpStringAddrs(NSDictionary *dict, NSString *context) NSMutableSet *strings = [NSMutableSet set]; GatherStringAddrs(dict, strings, context); - NSEnumerator *entryEnum = nil; NSDictionary *entry = nil; - for (entryEnum = [strings objectEnumerator]; (entry = [entryEnum nextObject]); ) + foreachkey(entry, strings) { NSString *string = [entry objectForKey:@"string"]; NSString *context = [entry objectForKey:@"context"]; @@ -1754,10 +1736,9 @@ static void DumpStringAddrs(NSDictionary *dict, NSString *context) static void GatherStringAddrsDict(NSDictionary *dict, NSMutableSet *strings, NSString *context) { - NSEnumerator *keyEnum = nil; id key = nil; NSString *keyContext = [context stringByAppendingString:@" key"]; - for (keyEnum = [dict keyEnumerator]; (key = [keyEnum nextObject]); ) + foreachkey(key, dict) { GatherStringAddrs(key, strings, keyContext); GatherStringAddrs([dict objectForKey:key], strings, [context stringByAppendingFormat:@".%@", key]); @@ -1767,10 +1748,9 @@ static void GatherStringAddrsDict(NSDictionary *dict, NSMutableSet *strings, NSS static void GatherStringAddrsArray(NSArray *array, NSMutableSet *strings, NSString *context) { - NSEnumerator *vEnum = nil; NSString *v = nil; unsigned i = 0; - for (vEnum = [array objectEnumerator]; (v = [vEnum nextObject]); ) + foreach(v, array) { GatherStringAddrs(v, strings, [context stringByAppendingFormat:@"[%u]", i++]); } diff --git a/src/Core/OOSkyDrawable.m b/src/Core/OOSkyDrawable.m index ea3b0c0ae..f910d00e7 100644 --- a/src/Core/OOSkyDrawable.m +++ b/src/Core/OOSkyDrawable.m @@ -255,9 +255,8 @@ - (NSSet *) allTextures { NSMutableSet *result = [NSMutableSet setWithCapacity:[_quadSets count]]; - NSEnumerator *quadSetEnum = nil; OOSkyQuadSet *quadSet = nil; - for (quadSetEnum = [_quadSets objectEnumerator]; (quadSet = [quadSetEnum nextObject]); ) + foreach (quadSet, _quadSets) { [result addObject:[quadSet texture]]; } @@ -270,9 +269,8 @@ - (size_t) totalSize { size_t result = [super totalSize]; - NSEnumerator *quadSetEnum = nil; OOSkyQuadSet *quadSet = nil; - for (quadSetEnum = [_quadSets objectEnumerator]; (quadSet = [quadSetEnum nextObject]); ) + foreach (quadSet, _quadSets) { result += [quadSet totalSize]; } diff --git a/src/Core/OOStringParsing.m b/src/Core/OOStringParsing.m index 74293385b..795c4f2d6 100644 --- a/src/Core/OOStringParsing.m +++ b/src/Core/OOStringParsing.m @@ -342,10 +342,9 @@ - (BOOL)pathHasExtension:(NSString *)extension - (BOOL)pathHasExtensionInArray:(NSArray *)extensions { - NSEnumerator *extEnum = nil; NSString *extension = nil; - for (extEnum = [extensions objectEnumerator]; (extension = [extEnum nextObject]); ) + foreach (extension, extensions) { if ([[self pathExtension] caseInsensitiveCompare:extension] == NSOrderedSame) return YES; } diff --git a/src/Core/OXPVerifier/OOOXPVerifier.m b/src/Core/OXPVerifier/OOOXPVerifier.m index 2b8c070a2..23a251794 100644 --- a/src/Core/OXPVerifier/OOOXPVerifier.m +++ b/src/Core/OXPVerifier/OOOXPVerifier.m @@ -306,14 +306,13 @@ - (void)run - (void)setUpLogOverrides { NSDictionary *overrides = nil; - NSEnumerator *messageClassEnum = nil; NSString *messageClass = nil; id verbose = nil; OOLogSetShowMessageClassTemporary([_verifierPList oo_boolForKey:@"logShowMessageClassOverride" defaultValue:NO]); overrides = [_verifierPList oo_dictionaryForKey:@"logControlOverride"]; - for (messageClassEnum = [overrides keyEnumerator]; (messageClass = [messageClassEnum nextObject]); ) + foreachkey(messageClass, overrides) { OOLogSetDisplayMessagesInClass(messageClass, [overrides oo_boolForKey:messageClass defaultValue:NO]); } @@ -332,7 +331,6 @@ - (void)registerBaseStages NSAutoreleasePool *pool = nil; NSSet *stages = nil; NSSet *excludeStages = nil; - NSEnumerator *stageEnum = nil; NSString *stageName = nil; Class stageClass = Nil; OOOXPVerifierStage *stage = nil; @@ -347,7 +345,7 @@ - (void)registerBaseStages stages = [[stages mutableCopy] autorelease]; [(NSMutableSet *)stages minusSet:excludeStages]; } - for (stageEnum = [stages objectEnumerator]; (stageName = [stageEnum nextObject]); ) + foreach (stageName, stages) { if ([stageName isKindOfClass:[NSString class]]) { @@ -371,7 +369,6 @@ - (void)buildDependencyGraph { NSAutoreleasePool *pool = nil; NSArray *stageKeys = nil; - NSEnumerator *stageEnum = nil; NSString *stageKey = nil; OOOXPVerifierStage *stage = nil; NSString *name = nil; @@ -423,7 +420,7 @@ - (void)buildDependencyGraph // Iterate over all stages, resolving dependencies. stageKeys = [_stagesByName allKeys]; // Get the keys up front because we may need to remove entries from dictionary. - for (stageEnum = [stageKeys objectEnumerator]; (stageKey = [stageEnum nextObject]); ) + foreach(stageKey, stageKeys) { stage = [_stagesByName objectForKey:stageKey]; if (stage == nil) continue; @@ -453,7 +450,7 @@ - (void)buildDependencyGraph */ stageKeys = [_stagesByName allKeys]; - for (stageEnum = [stageKeys objectEnumerator]; (stageKey = [stageEnum nextObject]); ) + foreach (stageKey, stageKeys) { stage = [_stagesByName objectForKey:stageKey]; if (stage == nil) continue; @@ -483,7 +480,6 @@ - (void)buildDependencyGraph - (void)runStages { NSAutoreleasePool *pool = nil; - NSEnumerator *stageEnum = nil; OOOXPVerifierStage *candidateStage = nil, *stageToRun = nil; NSString *stageName = nil; @@ -495,7 +491,7 @@ - (void)runStages // Look through queue for a stage that's ready stageToRun = nil; - for (stageEnum = [_waitingStages objectEnumerator]; (candidateStage = [stageEnum nextObject]); ) + foreach (candidateStage, _waitingStages) { if ([candidateStage canRun]) { @@ -545,7 +541,7 @@ - (void)runStages { OOLog(@"verifyOXP.incomplete", @"Some verifier stages could not be run:"); OOLogIndent(); - for (stageEnum = [_waitingStages objectEnumerator]; (candidateStage = [stageEnum nextObject]); ) + foreach (candidateStage, _waitingStages) { OOLog(@"verifyOXP.incomplete.item", @"%@", candidateStage); } @@ -562,11 +558,10 @@ - (BOOL)setUpDependencies:(NSSet *)dependencies forStage:(OOOXPVerifierStage *)stage { NSString *depName = nil; - NSEnumerator *depEnum = nil; OOOXPVerifierStage *depStage = nil; // Iterate over dependencies, connecting them up. - for (depEnum = [dependencies objectEnumerator]; (depName = [depEnum nextObject]); ) + foreach(depName, dependencies) { depStage = [_stagesByName objectForKey:depName]; if (depStage == nil) @@ -593,11 +588,10 @@ - (void)setUpDependents:(NSSet *)dependents forStage:(OOOXPVerifierStage *)stage { NSString *depName = nil; - NSEnumerator *depEnum = nil; OOOXPVerifierStage *depStage = nil; // Iterate over dependents, connecting them up. - for (depEnum = [dependents objectEnumerator]; (depName = [depEnum nextObject]); ) + foreach(depName, dependents) { depStage = [_stagesByName objectForKey:depName]; if (depStage == nil) @@ -624,10 +618,8 @@ - (void)dumpDebugGraphviz NSString *template = nil, *startTemplate = nil, *endTemplate = nil; - NSEnumerator *stageEnum = nil; OOOXPVerifierStage *stage = nil; NSSet *deps = nil; - NSEnumerator *depEnum = nil; OOOXPVerifierStage *dep = nil; graphVizTemplate = [self configurationDictionaryForKey:@"debugGraphvizTempate"]; @@ -637,7 +629,7 @@ - (void)dumpDebugGraphviz We use pointers as node names for simplicity of generation. */ template = [graphVizTemplate oo_stringForKey:@"node"]; - for (stageEnum = [_stagesByName objectEnumerator]; (stage = [stageEnum nextObject]); ) + foreach(stage, [_stagesByName allValues]) { [graphViz appendFormat:template, stage, [stage class], [stage name]]; } @@ -648,12 +640,12 @@ - (void)dumpDebugGraphviz */ template = [graphVizTemplate oo_stringForKey:@"forwardArc"]; startTemplate = [graphVizTemplate oo_stringForKey:@"startArc"]; - for (stageEnum = [_stagesByName objectEnumerator]; (stage = [stageEnum nextObject]); ) + foreach (stage, [_stagesByName allValues]) { deps = [stage resolvedDependencies]; if ([deps count] != 0) { - for (depEnum = [deps objectEnumerator]; (dep = [depEnum nextObject]); ) + foreach (dep, deps) { [graphViz appendFormat:template, dep, stage]; } @@ -670,12 +662,12 @@ - (void)dumpDebugGraphviz */ template = [graphVizTemplate oo_stringForKey:@"backwardArc"]; endTemplate = [graphVizTemplate oo_stringForKey:@"endArc"]; - for (stageEnum = [_stagesByName objectEnumerator]; (stage = [stageEnum nextObject]); ) + foreach (stage, [_stagesByName allValues]) { deps = [stage resolvedDependents]; if ([deps count] != 0) { - for (depEnum = [deps objectEnumerator]; (dep = [depEnum nextObject]); ) + foreach (dep, deps) { [graphViz appendFormat:template, dep, stage]; } diff --git a/src/Core/OXPVerifier/OOOXPVerifierStage.m b/src/Core/OXPVerifier/OOOXPVerifierStage.m index afa4335f6..178c250fd 100644 --- a/src/Core/OXPVerifier/OOOXPVerifierStage.m +++ b/src/Core/OXPVerifier/OOOXPVerifierStage.m @@ -128,7 +128,6 @@ - (void)setVerifier:(OOOXPVerifier *)verifier - (BOOL)isDependentOf:(OOOXPVerifierStage *)stage { - NSEnumerator *directDepEnum = nil; OOOXPVerifierStage *directDep = nil; if (stage == nil) return NO; @@ -137,7 +136,7 @@ - (BOOL)isDependentOf:(OOOXPVerifierStage *)stage if ([_dependencies containsObject:stage]) return YES; // Recursive dependency check. - for (directDepEnum = [_dependencies objectEnumerator]; (directDep = [directDepEnum nextObject]); ) + foreach (directDep, _dependencies) { if ([directDep isDependentOf:stage]) return YES; } diff --git a/src/Core/OXPVerifier/OOPListSchemaVerifier.m b/src/Core/OXPVerifier/OOPListSchemaVerifier.m index a1c9915fb..d885896fe 100644 --- a/src/Core/OXPVerifier/OOPListSchemaVerifier.m +++ b/src/Core/OXPVerifier/OOPListSchemaVerifier.m @@ -285,13 +285,12 @@ - (BOOL)verifyPropertyList:(id)plist named:(NSString *)name + (NSString *)descriptionForKeyPath:(NSArray *)keyPath { NSMutableString *result = nil; - NSEnumerator *componentEnum = nil; id component = nil; BOOL first = YES; result = [NSMutableString string]; - for (componentEnum = [keyPath objectEnumerator]; (component = [componentEnum nextObject]); ) + foreach (component, keyPath) { if ([component isKindOfClass:[NSNumber class]]) { @@ -1207,7 +1206,6 @@ static BOOL ApplyStringTest(NSString *string, id test, SEL testSelector, NSStrin { NSArray *options = nil; BOOL OK = NO, stop = NO; - NSEnumerator *optionEnum = nil; id option = nil; NSError *error; NSMutableDictionary *errors = nil; @@ -1223,7 +1221,7 @@ static BOOL ApplyStringTest(NSString *string, id test, SEL testSelector, NSStrin errors = [[NSMutableDictionary alloc] initWithCapacity:[options count]]; - for (optionEnum = [options objectEnumerator]; (option = [optionEnum nextObject]) ;) + foreach (option, options) { if ([verifier verifyPList:rootPList named:name diff --git a/src/Core/OXPVerifier/OOTextureVerifierStage.m b/src/Core/OXPVerifier/OOTextureVerifierStage.m index 60f2d0ec8..36fd530e6 100644 --- a/src/Core/OXPVerifier/OOTextureVerifierStage.m +++ b/src/Core/OXPVerifier/OOTextureVerifierStage.m @@ -82,11 +82,11 @@ - (BOOL)shouldRun - (void)run { - NSEnumerator *nameEnum = nil; + NSArray *nameEnum = nil; NSString *name = nil; NSAutoreleasePool *pool = nil; - for (nameEnum = [_usedTextures objectEnumerator]; (name = [nameEnum nextObject]); ) + foreach (name, _usedTextures) { pool = [[NSAutoreleasePool alloc] init]; [self checkTextureNamed:name inFolder:@"Textures"]; @@ -96,8 +96,8 @@ - (void)run _usedTextures = nil; // All "images" are considered used, since we don't have a reasonable way to look for images referenced in JavaScript scripts. - nameEnum = [[[[self verifier] fileScannerStage] filesInFolder:@"Images"] objectEnumerator]; - while ((name = [nameEnum nextObject])) + nameEnum = [[[self verifier] fileScannerStage] filesInFolder:@"Images"]; + foreach (name, nameEnum) { [self checkTextureNamed:name inFolder:@"Images"]; } diff --git a/src/Core/Scripting/OOPListScript.m b/src/Core/Scripting/OOPListScript.m index ee7b68a9f..2d241bebd 100644 --- a/src/Core/Scripting/OOPListScript.m +++ b/src/Core/Scripting/OOPListScript.m @@ -125,7 +125,6 @@ @implementation OOPListScript (SetUp) + (NSArray *)scriptsFromDictionaryOfScripts:(NSDictionary *)dictionary filePath:(NSString *)filePath { NSMutableArray *result = nil; - NSEnumerator *keyEnum = nil; NSString *key = nil; NSArray *scriptArray = nil; NSDictionary *metadata = nil; @@ -139,7 +138,7 @@ + (NSArray *)scriptsFromDictionaryOfScripts:(NSDictionary *)dictionary filePath: metadata = [dictionary objectForKey:kKeyMetadata]; if (![metadata isKindOfClass:[NSDictionary class]]) metadata = nil; - for (keyEnum = [dictionary keyEnumerator]; (key = [keyEnum nextObject]); ) + foreachkey(key, dictionary) { scriptArray = [dictionary objectForKey:key]; if ([key isKindOfClass:[NSString class]] && @@ -169,12 +168,11 @@ + (NSArray *)scriptsFromDictionaryOfScripts:(NSDictionary *)dictionary filePath: + (NSArray *) loadCachedScripts:(NSDictionary *)cachedScripts { - NSEnumerator *keyEnum = nil; NSString *key = nil; NSMutableArray *result = [NSMutableArray arrayWithCapacity:[cachedScripts count]]; - for (keyEnum = [cachedScripts keyEnumerator]; (key = [keyEnum nextObject]); ) + foreachkey(key, cachedScripts) { NSDictionary *cacheValue = [cachedScripts oo_dictionaryForKey:key]; NSArray *scriptArray = [cacheValue oo_arrayForKey:kKeyScript]; diff --git a/src/Core/Scripting/OOScript.m b/src/Core/Scripting/OOScript.m index bb5892e79..ef4ff3964 100644 --- a/src/Core/Scripting/OOScript.m +++ b/src/Core/Scripting/OOScript.m @@ -143,14 +143,13 @@ + (NSArray *)scriptsFromFileNamed:(NSString *)fileName + (NSArray *)scriptsFromList:(NSArray *)fileNames { - NSEnumerator *nameEnum = nil; NSString *name = nil; NSMutableArray *result = nil; NSArray *scripts = nil; result = [NSMutableArray arrayWithCapacity:[fileNames count]]; - for (nameEnum = [fileNames objectEnumerator]; (name = [nameEnum nextObject]); ) + foreach(name, fileNames) { scripts = [self scriptsFromFileNamed:name]; if (scripts != nil) [result addObjectsFromArray:scripts]; diff --git a/src/Core/Scripting/OOScriptTimer.m b/src/Core/Scripting/OOScriptTimer.m index 926f6e717..1af75c5f4 100644 --- a/src/Core/Scripting/OOScriptTimer.m +++ b/src/Core/Scripting/OOScriptTimer.m @@ -201,12 +201,11 @@ + (void) updateTimers + (void) noteGameReset { NSArray *timers = nil; - NSEnumerator *timerEnum = nil; OOScriptTimer *timer = nil; // Intermediate array is required so we don't get stuck in an endless loop over reinserted timers. Note that -sortedObjects also clears the queue! timers = [sTimers sortedObjects]; - for (timerEnum = [timers objectEnumerator]; (timer = [timerEnum nextObject]); ) + foreach(timer, timers) { timer->_isScheduled = NO; } From 64ab5c7b25c441b0cab69e49ee861836132062a1 Mon Sep 17 00:00:00 2001 From: "C.W. Betts" Date: Sat, 9 May 2015 13:14:20 -0600 Subject: [PATCH 5/9] Almost done. Skipping StationEntity.m because of its heavy use of custom enumerators. --- src/Core/Debug/OODebugTCPConsoleClient.m | 2 +- .../Entities/PlayerEntityLegacyScriptEngine.m | 3 +- src/Core/Entities/ShipEntity.m | 55 +++++++------------ src/Core/Entities/ShipEntityAI.m | 21 +++---- src/Core/Entities/ShipEntityLoadRestore.m | 11 ++-- src/Core/Entities/StationEntity.m | 2 +- src/Core/Entities/WormholeEntity.m | 3 +- src/Core/Materials/OOShaderProgram.m | 3 +- .../OXPVerifier/OOFileScannerVerifierStage.m | 9 +-- src/Core/ResourceManager.m | 41 +++++--------- src/Core/Universe.m | 27 ++++----- 11 files changed, 64 insertions(+), 113 deletions(-) diff --git a/src/Core/Debug/OODebugTCPConsoleClient.m b/src/Core/Debug/OODebugTCPConsoleClient.m index b3477c0a4..17f11dc12 100644 --- a/src/Core/Debug/OODebugTCPConsoleClient.m +++ b/src/Core/Debug/OODebugTCPConsoleClient.m @@ -584,7 +584,7 @@ - (void) handleNoteConfigurationChangePacket:(NSDictionary *)packet configuration = [packet oo_dictionaryForKey:kOOTCPConfiguration]; if (configuration != nil) { - for (keyEnum = [configuration keyEnumerator]; (key = [keyEnum nextObject]); ) + foreachkey(key, configuration) { value = [configuration objectForKey:key]; [_monitor setConfigurationValue:value forKey:key]; diff --git a/src/Core/Entities/PlayerEntityLegacyScriptEngine.m b/src/Core/Entities/PlayerEntityLegacyScriptEngine.m index f4ecc41d2..3b32afe33 100644 --- a/src/Core/Entities/PlayerEntityLegacyScriptEngine.m +++ b/src/Core/Entities/PlayerEntityLegacyScriptEngine.m @@ -1981,7 +1981,6 @@ - (void) setMissionChoicesDictionary:(NSDictionary *)choicesDict [UNIVERSE enterGUIViewModeWithMouseInteraction:YES]; // enables mouse selection of the choices list items OOGUIRow choicesRow = (end_row+1) - [choiceKeys count]; - NSEnumerator *choiceEnum = nil; NSString *choiceKey = nil; id choiceValue = nil; NSString *choiceText = nil; @@ -1989,7 +1988,7 @@ - (void) setMissionChoicesDictionary:(NSDictionary *)choicesDict BOOL selectableRowExists = NO; NSUInteger firstSelectableRow = end_row; - for (choiceEnum = [choiceKeys objectEnumerator]; (choiceKey = [choiceEnum nextObject]); ) + foreach(choiceKey, choiceKeys) { choiceValue = [choicesDict objectForKey:choiceKey]; OOGUIAlignment alignment = GUI_ALIGN_CENTER; diff --git a/src/Core/Entities/ShipEntity.m b/src/Core/Entities/ShipEntity.m index 891305366..54eb4739a 100644 --- a/src/Core/Entities/ShipEntity.m +++ b/src/Core/Entities/ShipEntity.m @@ -784,11 +784,10 @@ - (NSString *) repeatString:(NSString *)str times:(NSUInteger)times - (NSString *) serializeShipSubEntities { NSMutableString *result = [NSMutableString stringWithCapacity:4]; - NSEnumerator *subEnum = nil; ShipEntity *se = nil; NSUInteger diff, i = 0; - for (subEnum = [self shipSubEntityEnumerator]; (se = [subEnum nextObject]); ) + foreach (se, [self shipSubEntityEnumerator]) { diff = [se subIdx] - i; i += diff + 1; @@ -1420,9 +1419,8 @@ - (GLfloat) doesHitLine:(HPVector)v0 :(HPVector)v1 :(ShipEntity **)hitEntity hitEntity[0] = self; } - NSEnumerator *subEnum = nil; ShipEntity *se = nil; - for (subEnum = [self shipSubEntityEnumerator]; (se = [subEnum nextObject]); ) + foreach (se, [self shipSubEntityEnumerator]) { HPVector p0 = [se absolutePositionForSubentity]; Triangle ijk = [se absoluteIJKForSubentity]; @@ -1752,7 +1750,6 @@ - (void) setUpMixedEscorts @"Ship %@ has bad escort_roles definition.", self); return; } - NSEnumerator *edefEnumerator = nil; NSDictionary *escortDefinition = nil; NSDictionary *systeminfo = nil; OOGovernmentID government; @@ -1773,7 +1770,7 @@ - (void) setUpMixedEscorts _maxEscortCount = 0; int8_t i = 0; - for (edefEnumerator = [escortRoles objectEnumerator]; (escortDefinition = [edefEnumerator nextObject]); ) + foreach(escortDefinition, escortRoles) { if (currentEscortCount >= MAX_ESCORTS) { @@ -2975,7 +2972,6 @@ - (BOOL) hasOneEquipmentItem:(NSString *)itemKey includeMissiles:(BOOL)includeMi - (BOOL) hasPrimaryWeapon:(OOWeaponType)weaponType { - NSEnumerator *subEntEnum = nil; ShipEntity *subEntity = nil; if ([[forward_weapon_type identifier] isEqualToString:[weaponType identifier]] || @@ -2986,7 +2982,7 @@ - (BOOL) hasPrimaryWeapon:(OOWeaponType)weaponType return YES; } - for (subEntEnum = [self shipSubEntityEnumerator]; (subEntity = [subEntEnum nextObject]); ) + foreach(subEntity, [self shipSubEntityEnumerator]) { if ([subEntity hasPrimaryWeapon:weaponType]) return YES; } @@ -3256,11 +3252,10 @@ - (NSArray *) equipmentListForScripting { NSArray *eqTypes = [OOEquipmentType allEquipmentTypes]; NSMutableArray *quip = [NSMutableArray arrayWithCapacity:[eqTypes count]]; - NSEnumerator *eqTypeEnum = nil; OOEquipmentType *eqType = nil; BOOL isDamaged; - for (eqTypeEnum = [eqTypes objectEnumerator]; (eqType = [eqTypeEnum nextObject]); ) + foreach(eqType, eqTypes) { // Equipment list, consistent with the rest of the API - Kaks if ([eqType canCarryMultiple]) @@ -3686,9 +3681,8 @@ - (OOEquipmentType *) verifiedMissileTypeFromRole:(NSString *)role if(isRandomMissile) { id value; - NSEnumerator *enumerator = [[[missile roleSet] roles] objectEnumerator]; - while ((value = [enumerator nextObject])) + foreach(value, [[missile roleSet] roles]) { role = (NSString *)value; missileType = [OOEquipmentType equipmentTypeWithIdentifier:role]; @@ -9292,9 +9286,8 @@ - (void) becomeExplosion } // Explode subentities. - NSEnumerator *subEnum = nil; ShipEntity *se = nil; - for (subEnum = [self shipSubEntityEnumerator]; (se = [subEnum nextObject]); ) + foreach(se, [self shipSubEntityEnumerator]) { [se setSuppressExplosion:suppressExplosion]; [se becomeExplosion]; @@ -9526,9 +9519,8 @@ - (void) becomeLargeExplosion:(double)factor [self releaseCargoPodsDebris]; - NSEnumerator *subEnum = nil; ShipEntity *se = nil; - for (subEnum = [self shipSubEntityEnumerator]; (se = [subEnum nextObject]); ) + foreach(se, [self shipSubEntityEnumerator]) { [se setSuppressExplosion:suppressExplosion]; [se becomeExplosion]; @@ -9658,10 +9650,9 @@ - (void)setSuppressExplosion:(BOOL)suppress - (void) resetExhaustPlumes { - NSEnumerator *exEnum = nil; OOExhaustPlumeEntity *exEnt = nil; - for (exEnum = [self exhaustEnumerator]; (exEnt = [exEnum nextObject]); ) + foreach(exEnt, [self exhaustEnumerator]) { [exEnt resetPlume]; } @@ -11378,9 +11369,8 @@ - (BOOL) fireWeapon:(OOWeaponType)weapon_type direction:(OOWeaponFacing)directio if (direction == WEAPON_FACING_FORWARD) { //can we fire lasers from our subentities? - NSEnumerator *subEnum = nil; ShipEntity *se = nil; - for (subEnum = [self shipSubEntityEnumerator]; (se = [subEnum nextObject]); ) + foreach(se, [self shipSubEntityEnumerator]) { if ([se fireSubentityLaserShot:range]) fired = YES; } @@ -13509,17 +13499,16 @@ - (void) markAsOffender:(int)offence_value withReason:(OOLegalStatusReason)reaso // Exposed to AI - (void) switchLightsOn { - NSEnumerator *subEnum = nil; OOFlasherEntity *se = nil; ShipEntity *sub = nil; _lightsActive = YES; - for (subEnum = [self flasherEnumerator]; (se = [subEnum nextObject]); ) + foreach (se, [self flasherEnumerator]) { [se setActive:YES]; } - for (subEnum = [self shipSubEntityEnumerator]; (sub = [subEnum nextObject]); ) + foreach (sub, [self shipSubEntityEnumerator]) { [sub switchLightsOn]; } @@ -13528,17 +13517,16 @@ - (void) switchLightsOn // Exposed to AI - (void) switchLightsOff { - NSEnumerator *subEnum = nil; OOFlasherEntity *se = nil; ShipEntity *sub = nil; _lightsActive = NO; - for (subEnum = [self flasherEnumerator]; (se = [subEnum nextObject]); ) + foreach (se, [self flasherEnumerator]) { [se setActive:NO]; } - for (subEnum = [self shipSubEntityEnumerator]; (sub = [subEnum nextObject]); ) + foreach (sub, [self shipSubEntityEnumerator]) { [sub switchLightsOff]; } @@ -13718,7 +13706,6 @@ - (HPVector) coordinatesForEscortPosition:(unsigned)idx // Exposed to AI - (void) deployEscorts { - NSEnumerator *escortEnum = nil; ShipEntity *escort = nil; ShipEntity *target = nil; NSMutableSet *idleEscorts = nil; @@ -13742,7 +13729,7 @@ - (void) deployEscorts // Find idle escorts idleEscorts = [NSMutableSet set]; - for (escortEnum = [self escortEnumerator]; (escort = [escortEnum nextObject]); ) + foreach (escort, [self escortEnumerator]) { if (![[[escort getAI] name] isEqualToString:@"interceptAI.plist"] && ![escort hasNewAI]) { @@ -13762,7 +13749,7 @@ - (void) deployEscorts // Deploy deployCount idle escorts. target = [self primaryTarget]; - for (escortEnum = [idleEscorts objectEnumerator]; (escort = [escortEnum nextObject]); ) + foreach (escort, idleEscorts) { [escort addTarget:target]; [escort setAITo:@"interceptAI.plist"]; @@ -13781,12 +13768,11 @@ - (void) dockEscorts if (![self hasEscorts]) return; OOShipGroup *escortGroup = [self escortGroup]; - NSEnumerator *escortEnum = nil; ShipEntity *escort = nil; ShipEntity *target = [self primaryTarget]; unsigned i = 0; // Note: works on escortArray rather than escortEnumerator because escorts may be mutated. - for (escortEnum = [[self escortArray] objectEnumerator]; (escort = [escortEnum nextObject]); ) + foreach(escort, [self escortArray]) { float delay = i++ * 3.0 + 1.5; // send them off at three second intervals AI *ai = [escort getAI]; @@ -13986,15 +13972,13 @@ - (void) broadcastHitByLaserFrom:(ShipEntity *) aggressor_ship (scanClass == CLASS_PLAYER)) // only for active ships... { NSArray *authorities = nil; - NSEnumerator *authEnum = nil; ShipEntity *auth = nil; authorities = [UNIVERSE findShipsMatchingPredicate:AuthorityPredicate parameter:self inRange:-1 ofEntity:nil]; - authEnum = [authorities objectEnumerator]; - while ((auth = [authEnum nextObject])) + foreach (auth, authorities) { [auth setFoundTarget:aggressor_ship]; [auth doScriptEvent:OOJSID("offenceCommittedNearby") withArgument:aggressor_ship andArgument:self]; @@ -14626,7 +14610,8 @@ - (OOAlertCondition) realAlertCondition NSEnumerator *sEnum = [_defenseTargets objectEnumerator]; ShipEntity *ship = nil; double scanrange2 = scannerRange * scannerRange; - while ((ship = [sEnum nextObject])) + // FIXME: OOWeakSet doesn't implement NSFastEnumeration protocol. + foreach (ship, sEnum) { if ([ship hasHostileTarget] || ([ship isPlayer] && [PLAYER weaponsOnline])) { diff --git a/src/Core/Entities/ShipEntityAI.m b/src/Core/Entities/ShipEntityAI.m index 0a1281691..8d055a029 100644 --- a/src/Core/Entities/ShipEntityAI.m +++ b/src/Core/Entities/ShipEntityAI.m @@ -338,7 +338,6 @@ - (void) scanForHostiles - (void) groupAttackTarget { - NSEnumerator *shipEnum = nil; ShipEntity *target = nil, *ship = nil; target = [self primaryTarget]; @@ -353,7 +352,7 @@ - (void) groupAttackTarget return; } - for (shipEnum = [[self group] mutationSafeEnumerator]; (ship = [shipEnum nextObject]); ) + foreach (ship, [[self group] mutationSafeEnumerator]) { [ship setFoundTarget:target]; [ship reactToAIMessage:@"GROUP_ATTACK_TARGET" context:@"groupAttackTarget"]; @@ -362,9 +361,8 @@ - (void) groupAttackTarget if ([ship escortGroup] != [ship group] && [[ship escortGroup] count] > 1) // Ship has a seperate escort group. { ShipEntity *escort = nil; - NSEnumerator *shipEnum = nil; NSArray *escortMembers = [[ship escortGroup] memberArrayExcludingLeader]; - for (shipEnum = [escortMembers objectEnumerator]; (escort = [shipEnum nextObject]); ) + foreach (escort, escortMembers) { [escort setFoundTarget:target]; [escort reactToAIMessage:@"GROUP_ATTACK_TARGET" context:@"groupAttackTarget"]; @@ -675,7 +673,6 @@ - (void) enterTargetWormhole // FIXME: resolve this stuff. - (void) wormholeEscorts { - NSEnumerator *shipEnum = nil; ShipEntity *ship = nil; NSString *context = nil; WormholeEntity *whole = nil; @@ -687,7 +684,7 @@ - (void) wormholeEscorts context = [NSString stringWithFormat:@"%@ wormholeEscorts", [self shortDescription]]; #endif - for (shipEnum = [self escortEnumerator]; (ship = [shipEnum nextObject]); ) + foreach(ship, [self escortEnumerator]) { [ship addTarget:whole]; [ship reactToAIMessage:@"ENTER WORMHOLE" context:context]; @@ -867,12 +864,11 @@ - (void) randomPauseAI:(NSString *)intervalString - (void) dropMessages:(NSString *)messageString { NSArray *messages = nil; - NSEnumerator *messageEnum = nil; NSString *message = nil; NSCharacterSet *whiteSpace = [NSCharacterSet whitespaceCharacterSet]; messages = [messageString componentsSeparatedByString:@","]; - for (messageEnum = [messages objectEnumerator]; (message = [messageEnum nextObject]); ) + foreach(message, messages) { [shipAI dropMessage:[message stringByTrimmingCharactersInSet:whiteSpace]]; } @@ -1226,7 +1222,6 @@ - (void) fightOrFleeMissile // ShipEntity *missile = nil; unsigned i; - NSEnumerator *escortEnum = nil; ShipEntity *escort = nil; ShipEntity *target = nil; @@ -1244,7 +1239,7 @@ - (void) fightOrFleeMissile } else { - for (escortEnum = [self escortEnumerator]; (escort = [escortEnum nextObject]); ) + foreach (escort, [self escortEnumerator]) { if (target == escort) { @@ -1269,10 +1264,9 @@ - (void) fightOrFleeMissile { // Notify other police in group of attacker. // Note: prior to 1.73 this was done only if we had ECM. - NSEnumerator *policeEnum = nil; ShipEntity *police = nil; - for (policeEnum = [[self group] mutationSafeEnumerator]; (police = [policeEnum nextObject]); ) + foreach (police, [[self group] mutationSafeEnumerator]) { [police setFoundTarget:hunter]; [police setPrimaryAggressor:hunter]; @@ -1638,14 +1632,13 @@ - (void) disengageAutopilot - (void) wormholeGroup { - NSEnumerator *shipEnum = nil; ShipEntity *ship = nil; WormholeEntity *whole = nil; whole = [self primaryTarget]; if (![whole isWormhole]) return; - for (shipEnum = [[self group] mutationSafeEnumerator]; (ship = [shipEnum nextObject]); ) + foreach(ship, [[self group] mutationSafeEnumerator]) { [ship addTarget:whole]; [ship reactToAIMessage:@"ENTER WORMHOLE" context:@"wormholeGroup"]; diff --git a/src/Core/Entities/ShipEntityLoadRestore.m b/src/Core/Entities/ShipEntityLoadRestore.m index f90438f23..3ea7f647a 100644 --- a/src/Core/Entities/ShipEntityLoadRestore.m +++ b/src/Core/Entities/ShipEntityLoadRestore.m @@ -220,15 +220,14 @@ + (id) shipRestoredFromDictionary:(NSDictionary *)dict [ship setEnergy:energyLevel * [ship maxEnergy]]; [ship removeAllEquipment]; - NSEnumerator *eqEnum = nil; NSString *eqKey = nil; - for (eqEnum = [[dict oo_arrayForKey:KEY_EQUIPMENT] objectEnumerator]; (eqKey = [eqEnum nextObject]); ) + foreach(eqKey, [dict oo_arrayForKey:KEY_EQUIPMENT]) { [ship addEquipmentItem:eqKey withValidation:NO inContext:@"loading"]; } [ship removeMissiles]; - for (eqEnum = [[dict oo_arrayForKey:KEY_MISSILES] objectEnumerator]; (eqKey = [eqEnum nextObject]); ) + foreach(eqKey, [dict oo_arrayForKey:KEY_MISSILES]) { [ship addEquipmentItem:eqKey withValidation:NO inContext:@"loading"]; } @@ -275,9 +274,8 @@ - (void) simplifyShipdata:(NSMutableDictionary *)data andGetDeletes:(NSArray **) // Note items that are in referenceData, but not data. NSMutableArray *foundDeletes = [NSMutableArray array]; - NSEnumerator *enumerator = nil; NSString *key = nil; - for (enumerator = [referenceData keyEnumerator]; (key = [enumerator nextObject]); ) + foreachkey(key, referenceData) { if ([data objectForKey:key] == nil) { @@ -309,9 +307,8 @@ static void StripIgnoredKeys(NSMutableDictionary *dict) static NSArray *ignoredKeys = nil; if (ignoredKeys == nil) ignoredKeys = [[NSArray alloc] initWithObjects:@"ai_type", @"has_ecm", @"has_scoop", @"has_escape_pod", @"has_energy_bomb", @"has_fuel_injection", @"has_cloaking_device", @"has_military_jammer", @"has_military_scanner_filter", @"has_shield_booster", @"has_shield_enhancer", @"escorts", @"escort_role", @"escort-ship", @"conditions", @"missiles", @"auto_ai", nil]; - NSEnumerator *keyEnum = nil; NSString *key = nil; - for (keyEnum = [ignoredKeys objectEnumerator]; (key = [keyEnum nextObject]); ) + foreachkey(key, ignoredKeys) { [dict removeObjectForKey:key]; } diff --git a/src/Core/Entities/StationEntity.m b/src/Core/Entities/StationEntity.m index 5b0c90fa6..75367a3f5 100644 --- a/src/Core/Entities/StationEntity.m +++ b/src/Core/Entities/StationEntity.m @@ -2442,7 +2442,7 @@ - (void)dumpSelfState NSEnumerator *onHoldEnum = [_shipsOnHold objectEnumerator]; ShipEntity *ship = nil; unsigned i = 1; - while ((ship = [onHoldEnum nextObject])) + foreach(ship, onHoldEnum) { OOLog(@"dumpState.stationEntity", @"Nr %i: %@ at distance %g with role: %@", i++, [ship displayName], HPdistance([self position], [ship position]), [ship primaryRole]); } diff --git a/src/Core/Entities/WormholeEntity.m b/src/Core/Entities/WormholeEntity.m index 1b28cc0fe..493fc556f 100644 --- a/src/Core/Entities/WormholeEntity.m +++ b/src/Core/Entities/WormholeEntity.m @@ -119,12 +119,11 @@ - (WormholeEntity*)initWithDict:(NSDictionary*)dict // Setup shipsInTransit NSArray * shipDictsArray = [dict oo_arrayForKey:@"ships"]; - NSEnumerator *shipDicts = [shipDictsArray objectEnumerator]; NSDictionary *currShipDict = nil; [shipsInTransit removeAllObjects]; NSMutableDictionary *restoreContext = [NSMutableDictionary dictionary]; - while ((currShipDict = [shipDicts nextObject]) != nil) + foreach (currShipDict, shipDictsArray) { NSDictionary *shipInfo = [currShipDict oo_dictionaryForKey:@"ship_info"]; if (shipInfo != nil) diff --git a/src/Core/Materials/OOShaderProgram.m b/src/Core/Materials/OOShaderProgram.m index 9d70590b8..d5099e4bc 100644 --- a/src/Core/Materials/OOShaderProgram.m +++ b/src/Core/Materials/OOShaderProgram.m @@ -404,14 +404,13 @@ - (void) bindStandardMatrixUniforms if (standardMatrixUniformLocations != nil) { OOOpenGLMatrixManager *matrixManager = [[UNIVERSE gameView] getOpenGLMatrixManager]; - NSEnumerator *enumerator = [standardMatrixUniformLocations objectEnumerator]; id obj; NSArray *pair; OO_ENTER_OPENGL(); [matrixManager syncModelView]; - foreachkey(obj, enumerator) + foreachkey(obj, standardMatrixUniformLocations) { if ([obj isKindOfClass:[NSArray class]]) { diff --git a/src/Core/OXPVerifier/OOFileScannerVerifierStage.m b/src/Core/OXPVerifier/OOFileScannerVerifierStage.m index 2ae3faf29..78776d308 100644 --- a/src/Core/OXPVerifier/OOFileScannerVerifierStage.m +++ b/src/Core/OXPVerifier/OOFileScannerVerifierStage.m @@ -442,14 +442,13 @@ - (void)checkRootFolders - (void)checkConfigFiles { NSArray *knownNames = nil; - NSEnumerator *nameEnum = nil; NSString *name = nil, *lcName = nil, *realFileName = nil; BOOL inConfigDir; knownNames = [[self verifier] configurationArrayForKey:@"knownConfigFiles"]; - for (nameEnum = [knownNames objectEnumerator]; (name = [nameEnum nextObject]); ) + foreach (name, knownNames) { if (![name isKindOfClass:[NSString class]]) continue; @@ -475,22 +474,20 @@ - (void)checkConfigFiles - (void)checkKnownFiles { NSDictionary *directories = nil; - NSEnumerator *directoryEnum = nil; NSString *directory = nil, *lcDirectory = nil; NSArray *fileList = nil; - NSEnumerator *nameEnum = nil; NSString *name = nil, *lcName = nil, *realFileName = nil; BOOL inDirectory; directories = [[self verifier] configurationDictionaryForKey:@"knownFiles"]; - for (directoryEnum = [directories keyEnumerator]; (directory = [directoryEnum nextObject]); ) + foreachkey(directory, directories) { fileList = [directories objectForKey:directory]; lcDirectory = [directory lowercaseString]; - for (nameEnum = [fileList objectEnumerator]; (name = [nameEnum nextObject]); ) + foreach (name, fileList) { if (![name isKindOfClass:[NSString class]]) continue; diff --git a/src/Core/ResourceManager.m b/src/Core/ResourceManager.m index 284f456da..bd7965238 100644 --- a/src/Core/ResourceManager.m +++ b/src/Core/ResourceManager.m @@ -247,7 +247,6 @@ + (NSArray *)pathsWithAddOns NSFileManager *fmgr = [NSFileManager defaultManager]; NSArray *rootPaths = nil; NSMutableArray *existingRootPaths = nil; - NSEnumerator *pathEnum = nil; NSString *root = nil; NSDirectoryEnumerator *dirEnum = nil; NSString *subPath = nil; @@ -257,7 +256,7 @@ + (NSArray *)pathsWithAddOns // Copy those root paths that actually exist to search paths. rootPaths = [self rootPaths]; existingRootPaths = [NSMutableArray arrayWithCapacity:[rootPaths count]]; - for (pathEnum = [rootPaths objectEnumerator]; (root = [pathEnum nextObject]); ) + foreach (root, rootPaths) { if ([fmgr fileExistsAtPath:root isDirectory:&isDirectory] && isDirectory) { @@ -268,13 +267,13 @@ + (NSArray *)pathsWithAddOns // validate default search paths DESTROY(sSearchPaths); sSearchPaths = [NSMutableArray new]; - foreach(path, existingRootPaths) + foreach (path, existingRootPaths) { [self checkPotentialPath:path :sSearchPaths]; } // Iterate over root paths. - for (pathEnum = [existingRootPaths objectEnumerator]; (root = [pathEnum nextObject]); ) + foreach (root, existingRootPaths) { // Iterate over each root path's contents. if ([fmgr fileExistsAtPath:root isDirectory:&isDirectory] && isDirectory) @@ -313,7 +312,7 @@ + (NSArray *)pathsWithAddOns } } - for (pathEnum = [sExternalPaths objectEnumerator]; (path = [pathEnum nextObject]); ) + foreach (path, sExternalPaths) { [self checkPotentialPath:path :sSearchPaths]; if ([sSearchPaths containsObject:path]) [self checkOXPMessagesInPath:path]; @@ -1134,7 +1133,6 @@ + (BOOL)checkCacheUpToDateForPaths:(NSArray *)searchPaths BOOL upToDate = YES; id oldPaths = nil; NSMutableArray *modDates = nil; - NSEnumerator *pathEnum = nil; NSString *path = nil; id modDate = nil; @@ -1160,7 +1158,7 @@ + (BOOL)checkCacheUpToDateForPaths:(NSArray *)searchPaths // Build modification date list. (We need this regardless of whether the search paths matched.) modDates = [NSMutableArray arrayWithCapacity:[searchPaths count]]; - for (pathEnum = [searchPaths objectEnumerator]; (path = [pathEnum nextObject]); ) + foreach(path, searchPaths) { modDate = [[fmgr oo_fileAttributesAtPath:path traverseLink:YES] objectForKey:NSFileModificationDate]; if (modDate != nil) @@ -1525,8 +1523,7 @@ + (NSDictionary *) logControlDictionary NSDictionary *dict = nil; // Look for logcontrol.plists inside OXPs (but not in root paths). These are not allowed to define keys in hierarchies used by the build-in one. - NSEnumerator *pathEnum = [self pathEnumerator]; - while ((path = [pathEnum nextObject])) + foreach(path, [self pathEnumerator]) { if ([rootPaths containsObject:path]) continue; @@ -1548,8 +1545,7 @@ + (NSDictionary *) logControlDictionary } // Now, look for logcontrol.plists in root paths, i.e. not within OXPs. These are allowed to override the built-in copy. - pathEnum = [rootPaths objectEnumerator]; - while ((path = [pathEnum nextObject])) + foreach(path, rootPaths) { configPath = [[path stringByAppendingPathComponent:@"Config"] stringByAppendingPathComponent:@"logcontrol.plist"]; @@ -1581,8 +1577,7 @@ + (NSDictionary *) roleCategoriesDictionary NSString *configPath = nil; NSDictionary *categories = nil; - NSEnumerator *pathEnum = [self pathEnumerator]; - while ((path = [pathEnum nextObject])) + foreach(path, [self pathEnumerator]) { if ([ResourceManager corePlist:@"role-categories.plist" excludedAt:path]) { @@ -1640,8 +1635,7 @@ + (OOSystemDescriptionManager *) systemDescriptionManager NSDictionary *categories = nil; NSString *systemKey = nil; - NSEnumerator *pathEnum = [self pathEnumerator]; - while ((path = [pathEnum nextObject])) + foreach (path, [self pathEnumerator]) { if ([ResourceManager corePlist:@"planetinfo.plist" excludedAt:path]) { @@ -1652,7 +1646,7 @@ + (OOSystemDescriptionManager *) systemDescriptionManager categories = OODictionaryFromFile(configPath); if (categories != nil) { - foreachkey(systemKey,categories) + foreachkey (systemKey,categories) { NSDictionary *values = [categories oo_dictionaryForKey:systemKey defaultValue:nil]; if (values != nil) @@ -1739,7 +1733,6 @@ + (NSString *) pathForFileNamed:(NSString *)fileName inFolder:(NSString *)folder NSString *result = nil; NSString *cacheKey = nil; OOCacheManager *cache = [OOCacheManager sharedCache]; - NSEnumerator *pathEnum = nil; NSString *path = nil; NSString *filePath = nil; NSFileManager *fmgr = nil; @@ -1757,7 +1750,7 @@ + (NSString *) pathForFileNamed:(NSString *)fileName inFolder:(NSString *)folder // Search for file fmgr = [NSFileManager defaultManager]; // reverse object enumerator allows OXPs to override core - for (pathEnum = [[ResourceManager paths] reverseObjectEnumerator]; (path = [pathEnum nextObject]); ) + foreach(path, [[ResourceManager paths] reverseObjectEnumerator]) { filePath = [[path stringByAppendingPathComponent:folderName] stringByAppendingPathComponent:fileName]; if ([fmgr oo_oxzFileExistsAtPath:filePath]) @@ -1885,9 +1878,7 @@ + (NSDictionary *)loadScripts NSMutableDictionary *loadedScripts = nil; NSArray *results = nil; NSArray *paths = nil; - NSEnumerator *pathEnum = nil; NSString *path = nil; - NSEnumerator *scriptEnum = nil; OOScript *script = nil; NSString *name = nil; NSAutoreleasePool *pool = nil; @@ -1896,7 +1887,7 @@ + (NSDictionary *)loadScripts loadedScripts = [NSMutableDictionary dictionary]; paths = [ResourceManager paths]; - for (pathEnum = [paths objectEnumerator]; (path = [pathEnum nextObject]); ) + foreach (path, paths) { // excluding world-scripts.plist also excludes script.js / script.plist // though as those core files don't and won't exist this is not @@ -1911,7 +1902,7 @@ + (NSDictionary *)loadScripts if (results == nil) results = [OOScript worldScriptsAtPath:path]; if (results != nil) { - for (scriptEnum = [results objectEnumerator]; (script = [scriptEnum nextObject]); ) + foreach (script, results) { name = [script name]; if (name != nil) [loadedScripts setObject:script forKey:name]; @@ -1935,13 +1926,12 @@ + (NSDictionary *)loadScripts if (count != 0) { NSMutableArray *displayNames = nil; - NSEnumerator *scriptEnum = nil; OOScript *script = nil; NSString *displayString = nil; displayNames = [NSMutableArray arrayWithCapacity:count]; - for (scriptEnum = [loadedScripts objectEnumerator]; (script = [scriptEnum nextObject]); ) + foreach (script, [loadedScripts allValues]) { [displayNames addObject:[script displayName]]; } @@ -2045,12 +2035,11 @@ + (NSString *) diagnosticFileLocation + (void) logPaths { NSMutableArray *displayPaths = nil; - NSEnumerator *pathEnum = nil; NSString *path = nil; // Prettify paths for logging. displayPaths = [NSMutableArray arrayWithCapacity:[sSearchPaths count]]; - for (pathEnum = [sSearchPaths objectEnumerator]; (path = [pathEnum nextObject]); ) + foreach(path, sSearchPaths) { [displayPaths addObject:[[path stringByStandardizingPath] stringByAbbreviatingWithTildeInPath]]; } diff --git a/src/Core/Universe.m b/src/Core/Universe.m index 504657271..f828a5c70 100644 --- a/src/Core/Universe.m +++ b/src/Core/Universe.m @@ -1337,7 +1337,7 @@ - (void) populateSystemFromDictionariesWithSun:(OOSunEntity *)sun andPlanet:(OOP { Random_Seed systemSeed = [systemManager getRandomSeedForCurrentSystem]; NSArray *blocks = [populatorSettings allValues]; - NSEnumerator *enumerator = [[blocks sortedArrayUsingFunction:populatorPrioritySort context:nil] objectEnumerator]; + NSArray *sortedBlocks = [blocks sortedArrayUsingFunction:populatorPrioritySort context:nil]; NSDictionary *populator = nil; HPVector location = kZeroHPVector; uint32_t i, locationSeed, groupCount, rndvalue; @@ -1345,7 +1345,7 @@ - (void) populateSystemFromDictionariesWithSun:(OOSunEntity *)sun andPlanet:(OOP RANROTSeed rndlocal = RANROTGetFullSeed(); NSString *locationCode = nil; OOJSPopulatorDefinition *pdef = nil; - while ((populator = [enumerator nextObject])) + foreach (populator, sortedBlocks) { deterministic_population = [populator oo_boolForKey:@"deterministic" defaultValue:NO]; if (EXPECT_NOT(sun == nil || planet == nil)) @@ -2705,7 +2705,6 @@ - (BOOL) dockingClearanceProtocolActive - (void) setDockingClearanceProtocolActive:(BOOL)newValue { OOShipRegistry *registry = [OOShipRegistry sharedRegistry]; - NSEnumerator *statEnum = [allStations objectEnumerator]; StationEntity *station = nil; /* CIM: picking a random ship type which can take the same primary @@ -2713,7 +2712,7 @@ - (void) setDockingClearanceProtocolActive:(BOOL)newValue * clearance requirements seems unlikely to work entirely * correctly. To be fixed. */ - while ((station = [statEnum nextObject])) + foreach (station, allStations) { NSString *stationKey = [registry randomShipKeyForRole:[station primaryRole]]; if (![[[registry shipInfoForKey:stationKey] allKeys] containsObject:@"requires_docking_clearance"]) @@ -6377,10 +6376,9 @@ - (void) speakWithSubstitutions:(NSString *)text NSString *spokenText = text; if (speechArray != nil) { - NSEnumerator *speechEnumerator = nil; NSArray *thePair = nil; - for (speechEnumerator = [speechArray objectEnumerator]; (thePair = [speechEnumerator nextObject]); ) + foreach (thePair, speechArray) { NSString *original_phrase = [thePair oo_stringAtIndex:0]; @@ -6672,9 +6670,8 @@ - (void) update:(OOTimeDelta)inDeltaT if (zombies != nil) { update_stage = @"shootin' zombies"; - NSEnumerator *zombieEnum = nil; Entity *zombie = nil; - for (zombieEnum = [zombies objectEnumerator]; (zombie = [zombieEnum nextObject]); ) + foreach(zombie, zombies) { OOLogERR(@"universe.zombie", @"Found dead entity %@ in active entity list, removing. This is an internal error, please report it.", zombie); [self removeEntity:zombie]; @@ -8552,11 +8549,10 @@ - (NSArray *) shipsForSaleForSystem:(OOSystemID)s withTL:(OOTechLevelID)specialT if ([item incompatibleEquipment] != nil && extras != nil) { - NSEnumerator *keyEnum = nil; id key = nil; BOOL incompatible = NO; - for (keyEnum = [[item incompatibleEquipment] objectEnumerator]; (key = [keyEnum nextObject]); ) + foreach (key, [item incompatibleEquipment]) { if ([extras containsObject:key]) { @@ -8568,7 +8564,7 @@ - (NSArray *) shipsForSaleForSystem:(OOSystemID)s withTL:(OOTechLevelID)specialT if (incompatible) break; // make sure the incompatible equipment is not choosen later on. - for (keyEnum = [[item incompatibleEquipment] objectEnumerator]; (key = [keyEnum nextObject]); ) + foreach (key, [item incompatibleEquipment]) { if ([options containsObject:key]) { @@ -8612,11 +8608,10 @@ - (NSArray *) shipsForSaleForSystem:(OOSystemID)s withTL:(OOTechLevelID)specialT if ([item requiresEquipment] != nil && extras != nil) { - NSEnumerator *keyEnum = nil; id key = nil; BOOL missing = NO; - for (keyEnum = [[item requiresEquipment] objectEnumerator]; (key = [keyEnum nextObject]); ) + foreach(key, [item requiresEquipment]) { if (![extras containsObject:key]) { @@ -8628,11 +8623,10 @@ - (NSArray *) shipsForSaleForSystem:(OOSystemID)s withTL:(OOTechLevelID)specialT if ([item requiresAnyEquipment] != nil && extras != nil) { - NSEnumerator *keyEnum = nil; id key = nil; BOOL missing = YES; - for (keyEnum = [[item requiresAnyEquipment] objectEnumerator]; (key = [keyEnum nextObject]); ) + foreach(key, [item requiresAnyEquipment]) { if ([extras containsObject:key]) { @@ -10272,13 +10266,12 @@ - (void) runLocalizationTools // Handle command line options to transform system_description array for easier localization NSArray *arguments = nil; - NSEnumerator *argEnum = nil; NSString *arg = nil; BOOL compileSysDesc = NO, exportSysDesc = NO, xml = NO; arguments = [[NSProcessInfo processInfo] arguments]; - for (argEnum = [arguments objectEnumerator]; (arg = [argEnum nextObject]); ) + foreach(arg, arguments) { if ([arg isEqual:@"--compile-sysdesc"]) compileSysDesc = YES; else if ([arg isEqual:@"--export-sysdesc"]) exportSysDesc = YES; From 1e3dbfc591799cc6a9adc32a5282ff78f82b56d4 Mon Sep 17 00:00:00 2001 From: "C.W. Betts" Date: Sat, 9 May 2015 13:18:39 -0600 Subject: [PATCH 6/9] Have the foreach and foreachkey macros match the space after the declaration, as is done for "for". --- src/Core/Debug/OODebugTCPConsoleClient.m | 2 +- src/Core/Entities/PlayerEntity.m | 12 ++--- .../Entities/PlayerEntityLegacyScriptEngine.m | 6 +-- src/Core/Entities/ShipEntity.m | 20 ++++---- src/Core/Entities/ShipEntityAI.m | 6 +-- src/Core/Entities/ShipEntityLoadRestore.m | 8 ++-- src/Core/Entities/StationEntity.m | 2 +- src/Core/Materials/OOShaderMaterial.m | 8 ++-- src/Core/Materials/OOShaderProgram.m | 6 +-- src/Core/Materials/OOTexture.m | 2 +- src/Core/OOOXZManager.m | 2 +- src/Core/OORoleSet.m | 4 +- src/Core/OOShipRegistry.m | 48 +++++++++---------- src/Core/OOStringExpander.m | 2 +- src/Core/OOSystemDescriptionManager.m | 6 +-- .../OXPVerifier/OOFileScannerVerifierStage.m | 2 +- src/Core/OXPVerifier/OOOXPVerifier.m | 10 ++-- src/Core/ResourceManager.m | 16 +++---- src/Core/Scripting/OOPListScript.m | 4 +- src/Core/Scripting/OOScript.m | 2 +- src/Core/Scripting/OOScriptTimer.m | 2 +- src/Core/Universe.m | 8 ++-- 22 files changed, 89 insertions(+), 89 deletions(-) diff --git a/src/Core/Debug/OODebugTCPConsoleClient.m b/src/Core/Debug/OODebugTCPConsoleClient.m index 17f11dc12..164c1cd29 100644 --- a/src/Core/Debug/OODebugTCPConsoleClient.m +++ b/src/Core/Debug/OODebugTCPConsoleClient.m @@ -584,7 +584,7 @@ - (void) handleNoteConfigurationChangePacket:(NSDictionary *)packet configuration = [packet oo_dictionaryForKey:kOOTCPConfiguration]; if (configuration != nil) { - foreachkey(key, configuration) + foreachkey (key, configuration) { value = [configuration objectForKey:key]; [_monitor setConfigurationValue:value forKey:key]; diff --git a/src/Core/Entities/PlayerEntity.m b/src/Core/Entities/PlayerEntity.m index da3609dbe..f904a5102 100644 --- a/src/Core/Entities/PlayerEntity.m +++ b/src/Core/Entities/PlayerEntity.m @@ -811,7 +811,7 @@ - (NSDictionary *) commanderDataDictionary // extra equipment flags NSMutableDictionary *equipment = [NSMutableDictionary dictionary]; NSString *eqDesc = nil; - foreach(eqDesc, [self equipmentEnumerator]) + foreach (eqDesc, [self equipmentEnumerator]) { [equipment oo_setInteger:[self countEquipmentItem:eqDesc] forKey:eqDesc]; } @@ -1520,7 +1520,7 @@ energy bomb (900 credits). This must be done after missiles are NSDictionary * whCurrDict; [scannedWormholes release]; scannedWormholes = [[NSMutableArray alloc] initWithCapacity:[whArray count]]; - foreach(whCurrDict, whArray) + foreach (whCurrDict, whArray) { WormholeEntity * wh = [[WormholeEntity alloc] initWithDict:whCurrDict]; [scannedWormholes addObject:wh]; @@ -5789,7 +5789,7 @@ - (GLfloat) doesHitLine:(HPVector)v0 :(HPVector)v1 :(ShipEntity **)hitEntity } ShipEntity *se = nil; - foreach(se, [self shipSubEntityEnumerator]) + foreach (se, [self shipSubEntityEnumerator]) { HPVector p0 = [se absolutePositionForSubentity]; Triangle ijk = [se absoluteIJKForSubentity]; @@ -7496,7 +7496,7 @@ - (NSArray *) equipmentList BOOL prioritiseDamaged = [[gui userSettings] oo_boolForKey:kGuiStatusPrioritiseDamaged defaultValue:YES]; - foreach(eqType, [OOEquipmentType reverseEquipmentEnumerator]) + foreach (eqType, [OOEquipmentType reverseEquipmentEnumerator]) { if ([eqType isVisible]) { @@ -7728,7 +7728,7 @@ - (NSArray *) cargoList if (specialCargo) [manifest addObject:specialCargo]; - foreach(commodity, list) + foreach (commodity, list) { NSInteger quantity = [commodity oo_integerForKey:@"quantity"]; NSString *units = [commodity oo_stringForKey:@"unit"]; @@ -8079,7 +8079,7 @@ - (NSDictionary *) markedDestinations NSString *key = nil; - foreachkey(key, missionDestinations) + foreachkey (key, missionDestinations) { marker = [missionDestinations objectForKey:key]; [self prepareMarkedDestination:destinations:marker]; diff --git a/src/Core/Entities/PlayerEntityLegacyScriptEngine.m b/src/Core/Entities/PlayerEntityLegacyScriptEngine.m index 3b32afe33..e407fd566 100644 --- a/src/Core/Entities/PlayerEntityLegacyScriptEngine.m +++ b/src/Core/Entities/PlayerEntityLegacyScriptEngine.m @@ -234,7 +234,7 @@ static BOOL TestScriptConditions(NSArray *conditions) NSArray *condition = nil; PlayerEntity *player = PLAYER; - foreach(condition, conditions) + foreach (condition, conditions) { if (![player scriptTestCondition:condition]) return NO; } @@ -1395,7 +1395,7 @@ - (void) removeAllCargo:(BOOL)forceRemoval OOLog(kOOLogNoteRemoveAllCargo, @"%@ removeAllCargo", forceRemoval ? @"Forcing" : @"Going to"); - foreach(type, [shipCommodityData goods]) + foreach (type, [shipCommodityData goods]) { if ([shipCommodityData massUnitForGood:type] == UNITS_TONS) { @@ -1988,7 +1988,7 @@ - (void) setMissionChoicesDictionary:(NSDictionary *)choicesDict BOOL selectableRowExists = NO; NSUInteger firstSelectableRow = end_row; - foreach(choiceKey, choiceKeys) + foreach (choiceKey, choiceKeys) { choiceValue = [choicesDict objectForKey:choiceKey]; OOGUIAlignment alignment = GUI_ALIGN_CENTER; diff --git a/src/Core/Entities/ShipEntity.m b/src/Core/Entities/ShipEntity.m index 54eb4739a..e9dbe7e06 100644 --- a/src/Core/Entities/ShipEntity.m +++ b/src/Core/Entities/ShipEntity.m @@ -1770,7 +1770,7 @@ - (void) setUpMixedEscorts _maxEscortCount = 0; int8_t i = 0; - foreach(escortDefinition, escortRoles) + foreach (escortDefinition, escortRoles) { if (currentEscortCount >= MAX_ESCORTS) { @@ -2631,7 +2631,7 @@ - (void) update:(OOTimeDelta)delta_t ShipEntity *escort = nil; unsigned i = 0; // Note: works on escortArray rather than escortEnumerator because escorts may be mutated. - foreach(escort, [self escortArray]) + foreach (escort, [self escortArray]) { [escort setEscortDestination:[self coordinatesForEscortPosition:i++]]; } @@ -2982,7 +2982,7 @@ - (BOOL) hasPrimaryWeapon:(OOWeaponType)weaponType return YES; } - foreach(subEntity, [self shipSubEntityEnumerator]) + foreach (subEntity, [self shipSubEntityEnumerator]) { if ([subEntity hasPrimaryWeapon:weaponType]) return YES; } @@ -3255,7 +3255,7 @@ - (NSArray *) equipmentListForScripting OOEquipmentType *eqType = nil; BOOL isDamaged; - foreach(eqType, eqTypes) + foreach (eqType, eqTypes) { // Equipment list, consistent with the rest of the API - Kaks if ([eqType canCarryMultiple]) @@ -3682,7 +3682,7 @@ - (OOEquipmentType *) verifiedMissileTypeFromRole:(NSString *)role { id value; - foreach(value, [[missile roleSet] roles]) + foreach (value, [[missile roleSet] roles]) { role = (NSString *)value; missileType = [OOEquipmentType equipmentTypeWithIdentifier:role]; @@ -9287,7 +9287,7 @@ - (void) becomeExplosion // Explode subentities. ShipEntity *se = nil; - foreach(se, [self shipSubEntityEnumerator]) + foreach (se, [self shipSubEntityEnumerator]) { [se setSuppressExplosion:suppressExplosion]; [se becomeExplosion]; @@ -9520,7 +9520,7 @@ - (void) becomeLargeExplosion:(double)factor [self releaseCargoPodsDebris]; ShipEntity *se = nil; - foreach(se, [self shipSubEntityEnumerator]) + foreach (se, [self shipSubEntityEnumerator]) { [se setSuppressExplosion:suppressExplosion]; [se becomeExplosion]; @@ -9652,7 +9652,7 @@ - (void) resetExhaustPlumes { OOExhaustPlumeEntity *exEnt = nil; - foreach(exEnt, [self exhaustEnumerator]) + foreach (exEnt, [self exhaustEnumerator]) { [exEnt resetPlume]; } @@ -11370,7 +11370,7 @@ - (BOOL) fireWeapon:(OOWeaponType)weapon_type direction:(OOWeaponFacing)directio { //can we fire lasers from our subentities? ShipEntity *se = nil; - foreach(se, [self shipSubEntityEnumerator]) + foreach (se, [self shipSubEntityEnumerator]) { if ([se fireSubentityLaserShot:range]) fired = YES; } @@ -13772,7 +13772,7 @@ - (void) dockEscorts ShipEntity *target = [self primaryTarget]; unsigned i = 0; // Note: works on escortArray rather than escortEnumerator because escorts may be mutated. - foreach(escort, [self escortArray]) + foreach (escort, [self escortArray]) { float delay = i++ * 3.0 + 1.5; // send them off at three second intervals AI *ai = [escort getAI]; diff --git a/src/Core/Entities/ShipEntityAI.m b/src/Core/Entities/ShipEntityAI.m index 8d055a029..6e7e272fb 100644 --- a/src/Core/Entities/ShipEntityAI.m +++ b/src/Core/Entities/ShipEntityAI.m @@ -684,7 +684,7 @@ - (void) wormholeEscorts context = [NSString stringWithFormat:@"%@ wormholeEscorts", [self shortDescription]]; #endif - foreach(ship, [self escortEnumerator]) + foreach (ship, [self escortEnumerator]) { [ship addTarget:whole]; [ship reactToAIMessage:@"ENTER WORMHOLE" context:context]; @@ -868,7 +868,7 @@ - (void) dropMessages:(NSString *)messageString NSCharacterSet *whiteSpace = [NSCharacterSet whitespaceCharacterSet]; messages = [messageString componentsSeparatedByString:@","]; - foreach(message, messages) + foreach (message, messages) { [shipAI dropMessage:[message stringByTrimmingCharactersInSet:whiteSpace]]; } @@ -1638,7 +1638,7 @@ - (void) wormholeGroup whole = [self primaryTarget]; if (![whole isWormhole]) return; - foreach(ship, [[self group] mutationSafeEnumerator]) + foreach (ship, [[self group] mutationSafeEnumerator]) { [ship addTarget:whole]; [ship reactToAIMessage:@"ENTER WORMHOLE" context:@"wormholeGroup"]; diff --git a/src/Core/Entities/ShipEntityLoadRestore.m b/src/Core/Entities/ShipEntityLoadRestore.m index 3ea7f647a..79fdbbaa9 100644 --- a/src/Core/Entities/ShipEntityLoadRestore.m +++ b/src/Core/Entities/ShipEntityLoadRestore.m @@ -221,13 +221,13 @@ + (id) shipRestoredFromDictionary:(NSDictionary *)dict [ship removeAllEquipment]; NSString *eqKey = nil; - foreach(eqKey, [dict oo_arrayForKey:KEY_EQUIPMENT]) + foreach (eqKey, [dict oo_arrayForKey:KEY_EQUIPMENT]) { [ship addEquipmentItem:eqKey withValidation:NO inContext:@"loading"]; } [ship removeMissiles]; - foreach(eqKey, [dict oo_arrayForKey:KEY_MISSILES]) + foreach (eqKey, [dict oo_arrayForKey:KEY_MISSILES]) { [ship addEquipmentItem:eqKey withValidation:NO inContext:@"loading"]; } @@ -275,7 +275,7 @@ - (void) simplifyShipdata:(NSMutableDictionary *)data andGetDeletes:(NSArray **) // Note items that are in referenceData, but not data. NSMutableArray *foundDeletes = [NSMutableArray array]; NSString *key = nil; - foreachkey(key, referenceData) + foreachkey (key, referenceData) { if ([data objectForKey:key] == nil) { @@ -308,7 +308,7 @@ static void StripIgnoredKeys(NSMutableDictionary *dict) if (ignoredKeys == nil) ignoredKeys = [[NSArray alloc] initWithObjects:@"ai_type", @"has_ecm", @"has_scoop", @"has_escape_pod", @"has_energy_bomb", @"has_fuel_injection", @"has_cloaking_device", @"has_military_jammer", @"has_military_scanner_filter", @"has_shield_booster", @"has_shield_enhancer", @"escorts", @"escort_role", @"escort-ship", @"conditions", @"missiles", @"auto_ai", nil]; NSString *key = nil; - foreachkey(key, ignoredKeys) + foreachkey (key, ignoredKeys) { [dict removeObjectForKey:key]; } diff --git a/src/Core/Entities/StationEntity.m b/src/Core/Entities/StationEntity.m index 75367a3f5..c9c1725c0 100644 --- a/src/Core/Entities/StationEntity.m +++ b/src/Core/Entities/StationEntity.m @@ -2442,7 +2442,7 @@ - (void)dumpSelfState NSEnumerator *onHoldEnum = [_shipsOnHold objectEnumerator]; ShipEntity *ship = nil; unsigned i = 1; - foreach(ship, onHoldEnum) + foreach (ship, onHoldEnum) { OOLog(@"dumpState.stationEntity", @"Nr %i: %@ at distance %g with role: %@", i++, [ship displayName], HPdistance([self position], [ship position]), [ship primaryRole]); } diff --git a/src/Core/Materials/OOShaderMaterial.m b/src/Core/Materials/OOShaderMaterial.m index d100992d7..7c4451757 100644 --- a/src/Core/Materials/OOShaderMaterial.m +++ b/src/Core/Materials/OOShaderMaterial.m @@ -504,7 +504,7 @@ -(void)addUniformsFromDictionary:(NSDictionary *)uniformDefs withBindingTarget:( ranrot_srand(randomSeed); keys = [[uniformDefs allKeys] sortedArrayUsingSelector:@selector(compare:)]; - foreach(name, keys) + foreach (name, keys) { gotValue = NO; definition = [uniformDefs objectForKey:name]; @@ -671,7 +671,7 @@ - (BOOL)doApply @try { - foreach(uniform, uniforms) + foreach (uniform, uniforms) { [uniform apply]; } @@ -816,7 +816,7 @@ - (void) addTexturesFromArray:(NSArray *)textureObjects unitCount:(GLuint)max if (macros == nil) return nil; result = [NSMutableString string]; - foreachkey(key, macros) + foreachkey (key, macros) { if (![key isKindOfClass:[NSString class]]) continue; value = [macros objectForKey:key]; @@ -853,7 +853,7 @@ static BOOL GetShaderSource(NSString *fileName, NSString *shaderType, NSString * // Futureproofing -- in future, we may wish to support automatic selection between supported shader languages. if (![fileName pathHasExtensionInArray:extensions]) { - foreachkey(extension, extensions) + foreachkey (extension, extensions) { nameWithExtension = [fileName stringByAppendingPathExtension:extension]; result = [ResourceManager stringFromFilesNamed:nameWithExtension diff --git a/src/Core/Materials/OOShaderProgram.m b/src/Core/Materials/OOShaderProgram.m index d5099e4bc..ed14634ae 100644 --- a/src/Core/Materials/OOShaderProgram.m +++ b/src/Core/Materials/OOShaderProgram.m @@ -393,7 +393,7 @@ - (void) bindAttributes:(NSDictionary *)attributeBindings NSString *attrKey = nil; - foreachkey(attrKey, attributeBindings) + foreachkey (attrKey, attributeBindings) { OOGL(glBindAttribLocationARB(program, [attributeBindings oo_unsignedIntForKey:attrKey], [attrKey UTF8String])); } @@ -410,7 +410,7 @@ - (void) bindStandardMatrixUniforms OO_ENTER_OPENGL(); [matrixManager syncModelView]; - foreachkey(obj, standardMatrixUniformLocations) + foreachkey (obj, standardMatrixUniformLocations) { if ([obj isKindOfClass:[NSArray class]]) { @@ -455,7 +455,7 @@ static BOOL GetShaderSource(NSString *fileName, NSString *shaderType, NSString * // Futureproofing -- in future, we may wish to support automatic selection between supported shader languages. if (![fileName pathHasExtensionInArray:extensions]) { - foreach(extension, extensions) + foreach (extension, extensions) { nameWithExtension = [fileName stringByAppendingPathExtension:extension]; result = [ResourceManager stringFromFilesNamed:nameWithExtension diff --git a/src/Core/Materials/OOTexture.m b/src/Core/Materials/OOTexture.m index a05df2b84..b8020c826 100644 --- a/src/Core/Materials/OOTexture.m +++ b/src/Core/Materials/OOTexture.m @@ -400,7 +400,7 @@ + (NSSet *) allTextures { NSMutableSet *result = [NSMutableSet setWithCapacity:[sAllLiveTextures count]]; NSValue *box = nil; - foreach(box, sAllLiveTextures) + foreach (box, sAllLiveTextures) { [result addObject:[box pointerValue]]; } diff --git a/src/Core/OOOXZManager.m b/src/Core/OOOXZManager.m index 88ed97518..279a28c76 100644 --- a/src/Core/OOOXZManager.m +++ b/src/Core/OOOXZManager.m @@ -403,7 +403,7 @@ - (NSArray *) applyCurrentFilter:(NSArray *)list [invocation setArgument:¶meter atIndex:3]; } - foreach(manifest, list) + foreach (manifest, list) { [invocation setArgument:&manifest atIndex:2]; [invocation invoke]; diff --git a/src/Core/OORoleSet.m b/src/Core/OORoleSet.m index 82552ac8c..ca43ea58d 100644 --- a/src/Core/OORoleSet.m +++ b/src/Core/OORoleSet.m @@ -125,7 +125,7 @@ - (NSString *)roleString // Construct role string. We always do this so that it's in a normalized form. result = [NSMutableString string]; roles = [self sortedRoles]; - foreach(role, roles) + foreach (role, roles) { if (!first) [result appendString:@" "]; else first = NO; @@ -290,7 +290,7 @@ - (id)initWithRolesAndProbabilities:(NSDictionary *)dict _rolesAndProbabilities = [tDict copy]; - foreachkey(role, dict) + foreachkey (role, dict) { prob = [dict oo_floatForKey:role defaultValue:-1]; if (prob < 0) diff --git a/src/Core/OOShipRegistry.m b/src/Core/OOShipRegistry.m index db7941b41..aad437388 100644 --- a/src/Core/OOShipRegistry.m +++ b/src/Core/OOShipRegistry.m @@ -392,7 +392,7 @@ - (void) loadDemoShipConditions andMerge:YES cache:NO]; - foreach(key, initialDemoShips) + foreach (key, initialDemoShips) { NSString *conditions = [key oo_stringForKey:kOODemoShipConditions defaultValue:nil]; if (conditions != nil) @@ -427,7 +427,7 @@ - (void) loadDemoShips demoShips = [NSMutableArray arrayWithArray:initialDemoShips]; // Note: iterate over initialDemoShips to avoid mutating the collection being enu,erated. - foreach(key, initialDemoShips) + foreach (key, initialDemoShips) { NSString *shipKey = [key oo_stringForKey:kOODemoShipKey]; if (![key isKindOfClass:[NSDictionary class]] || [self shipInfoForKey:shipKey] == nil) @@ -493,7 +493,7 @@ - (void) loadDemoShips // now separate out the demoships by class, and add some extra keys NSMutableDictionary *demoList = [NSMutableDictionary dictionaryWithCapacity:8]; NSMutableArray *demoClass = nil; - foreach(key, demoShips) + foreach (key, demoShips) { NSString *class = [key oo_stringForKey:kOODemoShipClass defaultValue:@"ship"]; if ([OOShipLibraryCategoryPlural(class) length] == 0) @@ -519,7 +519,7 @@ - (void) loadDemoShips } // sort each ship list by name NSString *demoClassName = nil; - foreach(demoClassName, demoList) + foreach (demoClassName, demoList) { [[demoList objectForKey:demoClassName] sortUsingFunction:SortDemoShipsByName context:NULL]; } @@ -539,7 +539,7 @@ - (void) loadCachedRoleProbabilitySets if (cachedSets == nil) return; restoredSets = [NSMutableDictionary dictionaryWithCapacity:[cachedSets count]]; - foreachkey(role, cachedSets) + foreachkey (role, cachedSets) { [restoredSets setObject:[OOProbabilitySet probabilitySetWithPropertyListRepresentation:[cachedSets objectForKey:role]] forKey:role]; } @@ -561,7 +561,7 @@ - (void) buildRoleProbabilitySets probabilitySets = [NSMutableDictionary dictionary]; // Build role sets - foreachkey(shipKey, _shipData) + foreachkey (shipKey, _shipData) { shipEntry = [_shipData objectForKey:shipKey]; roles = [shipEntry oo_stringForKey:@"roles"]; @@ -571,7 +571,7 @@ - (void) buildRoleProbabilitySets // Convert role sets to immutable form, and build cache entry. // Note: we iterate over a copy of the keys to avoid mutating while iterating. cacheEntry = [NSMutableDictionary dictionaryWithCapacity:[probabilitySets count]]; - foreach(role, [probabilitySets allKeys]) + foreach (role, [probabilitySets allKeys]) { pset = [probabilitySets objectForKey:role]; pset = [[pset copy] autorelease]; @@ -610,7 +610,7 @@ - (BOOL) applyLikeShips:(NSMutableDictionary *)ioData withKey:(NSString *)likeKe // Build set of ships with like_ship references remainingLikeShips = [NSMutableSet set]; - foreachkey(key, ioData) + foreachkey (key, ioData) { shipEntry = [ioData objectForKey:key]; if ([shipEntry oo_stringForKey:likeKey] != nil) @@ -622,7 +622,7 @@ - (BOOL) applyLikeShips:(NSMutableDictionary *)ioData withKey:(NSString *)likeKe count = lastCount = [remainingLikeShips count]; while (count != 0) { - foreach(key, [[remainingLikeShips copy] autorelease]) + foreach (key, [[remainingLikeShips copy] autorelease]) { // Look up like_ship entry shipEntry = [ioData objectForKey:key]; @@ -648,7 +648,7 @@ - (BOOL) applyLikeShips:(NSMutableDictionary *)ioData withKey:(NSString *)likeKe don't have is_external_dependency set. */ reportedBadShips = [NSMutableArray array]; - foreach(key, remainingLikeShips) + foreach (key, remainingLikeShips) { if (![[ioData oo_dictionaryForKey:key] oo_boolForKey:@"is_external_dependency"]) { @@ -734,7 +734,7 @@ - (BOOL) makeShipEntriesMutable:(NSMutableDictionary *)ioData NSString *shipKey = nil; NSDictionary *shipEntry = nil; - foreach(shipKey, [ioData allKeys]) + foreach (shipKey, [ioData allKeys]) { shipEntry = [ioData objectForKey:shipKey]; if (![shipEntry isKindOfClass:[NSDictionary class]]) @@ -767,7 +767,7 @@ - (BOOL) loadAndApplyShipDataOverrides:(NSMutableDictionary *)ioData mergeMode:MERGE_SMART cache:NO]; - foreachkey(shipKey, overrides) + foreachkey (shipKey, overrides) { shipEntry = [ioData objectForKey:shipKey]; if (shipEntry != nil) @@ -794,11 +794,11 @@ - (BOOL) stripPrivateKeys:(NSMutableDictionary *)ioData NSMutableDictionary *shipEntry = nil; NSString *attrKey = nil; - foreachkey(shipKey, ioData) + foreachkey (shipKey, ioData) { shipEntry = [ioData objectForKey:shipKey]; - foreachkey(attrKey, shipEntry) + foreachkey (attrKey, shipEntry) { if ([attrKey hasPrefix:@"_oo_"]) { @@ -829,7 +829,7 @@ - (BOOL) loadAndMergeShipyard:(NSMutableDictionary *)ioData NSMutableArray *playerShips = nil; // Strip out any shipyard stuff in shipdata (there shouldn't be any). - foreachkey(shipKey, ioData) + foreachkey (shipKey, ioData) { shipEntry = [ioData objectForKey:shipKey]; if ([shipEntry objectForKey:@"_oo_shipyard"] != nil) @@ -850,7 +850,7 @@ - (BOOL) loadAndMergeShipyard:(NSMutableDictionary *)ioData playerShips = [NSMutableArray arrayWithCapacity:[shipyard count]]; // Insert merged shipyard and shipyardOverrides entries. - foreachkey(shipKey, shipyard) + foreachkey (shipKey, shipyard) { shipEntry = [ioData objectForKey:shipKey]; if (shipEntry != nil) @@ -894,7 +894,7 @@ - (BOOL) canonicalizeAndTagSubentities:(NSMutableDictionary *)ioData // _oo_is_subentity=YES to all entries used as subentities. // Iterate over all ships. (Iterates over a copy of keys since it mutates the dictionary.) - foreach(shipKey, [ioData allKeys]) + foreach (shipKey, [ioData allKeys]) { shipEntry = [ioData objectForKey:shipKey]; remove = NO; @@ -905,7 +905,7 @@ - (BOOL) canonicalizeAndTagSubentities:(NSMutableDictionary *)ioData if (subentityDeclarations != nil) { okSubentities = [NSMutableArray arrayWithCapacity:[subentityDeclarations count]]; - foreach(subentityDecl, subentityDeclarations) + foreach (subentityDecl, subentityDeclarations) { subentityDict = [self canonicalizeSubentityDeclaration:subentityDecl forShip:shipKey shipData:ioData fatalError:&fatal]; @@ -980,7 +980,7 @@ - (BOOL) removeUnusableEntries:(NSMutableDictionary *)ioData shipMode:(BOOL)ship NSString *modelName = nil; // Clean out invalid entries and templates. (Iterates over a copy of keys since it mutates the dictionary.) - foreach(shipKey, [ioData allKeys]) + foreach (shipKey, [ioData allKeys]) { shipEntry = [ioData objectForKey:shipKey]; remove = NO; @@ -1032,7 +1032,7 @@ - (BOOL) sanitizeConditions:(NSMutableDictionary *)ioData NSMutableArray *conditionScripts = [[NSMutableArray alloc] init]; - foreach(shipKey, [ioData allKeys]) + foreach (shipKey, [ioData allKeys]) { shipEntry = [ioData objectForKey:shipKey]; conditions = [shipEntry objectForKey:@"conditions"]; @@ -1638,7 +1638,7 @@ - (BOOL) shipIsBallTurretForKey:(NSString *)shipKey inShipData:(NSDictionary *)s setupActions = [[shipData oo_dictionaryForKey:shipKey] oo_arrayForKey:@"setup_actions"]; - foreachkey(action, setupActions) + foreachkey (action, setupActions) { if ([[ScanTokensFromString(action) objectAtIndex:0] isEqualToString:@"initialiseTurret"]) return YES; } @@ -1717,7 +1717,7 @@ static void DumpStringAddrs(NSDictionary *dict, NSString *context) GatherStringAddrs(dict, strings, context); NSDictionary *entry = nil; - foreachkey(entry, strings) + foreachkey (entry, strings) { NSString *string = [entry objectForKey:@"string"]; NSString *context = [entry objectForKey:@"context"]; @@ -1738,7 +1738,7 @@ static void GatherStringAddrsDict(NSDictionary *dict, NSMutableSet *strings, NSS { id key = nil; NSString *keyContext = [context stringByAppendingString:@" key"]; - foreachkey(key, dict) + foreachkey (key, dict) { GatherStringAddrs(key, strings, keyContext); GatherStringAddrs([dict objectForKey:key], strings, [context stringByAppendingFormat:@".%@", key]); @@ -1750,7 +1750,7 @@ static void GatherStringAddrsArray(NSArray *array, NSMutableSet *strings, NSStri { NSString *v = nil; unsigned i = 0; - foreach(v, array) + foreach (v, array) { GatherStringAddrs(v, strings, [context stringByAppendingFormat:@"[%u]", i++]); } diff --git a/src/Core/OOStringExpander.m b/src/Core/OOStringExpander.m index a9eac4ebb..c744bf415 100644 --- a/src/Core/OOStringExpander.m +++ b/src/Core/OOStringExpander.m @@ -444,7 +444,7 @@ limits the number of recursive calls of Expand() that are permitted. If one NSArray *operators = [operatorsString componentsSeparatedByString:@"|"]; NSString *op = nil; - foreach(op, operators) + foreach (op, operators) { NSString *param = nil; NSRange colon = [op rangeOfString:@":"]; diff --git a/src/Core/OOSystemDescriptionManager.m b/src/Core/OOSystemDescriptionManager.m index 68540ba4e..92b4aec29 100644 --- a/src/Core/OOSystemDescriptionManager.m +++ b/src/Core/OOSystemDescriptionManager.m @@ -240,7 +240,7 @@ - (void) importScriptedChanges:(NSDictionary *)scripted NSArray *key = nil; NSString *keyStr = nil; NSString *manifest = nil; - foreachkey(keyStr, scripted) + foreachkey (keyStr, scripted) { key = [keyStr componentsSeparatedByString:kOOScriptedChangeJoiner]; if ([key count] == 4) @@ -276,7 +276,7 @@ - (void) importLegacyScriptedChanges:(NSDictionary *)scripted NSString *propertyKey = nil; NSString *defaultManifest = @"org.oolite.oolite"; - foreachkey(systemKey,scripted) + foreachkey (systemKey,scripted) { NSDictionary *legacyChanges = [scripted oo_dictionaryForKey:systemKey]; if ([legacyChanges objectForKey:@"sun_gone_nova"] != nil) @@ -477,7 +477,7 @@ - (void) setProperties:(NSDictionary *)properties inDescription:(OOSystemDescrip layer = OO_LAYER_OXP_PRIORITY; } NSString *key = nil; - foreachkey(key, properties) + foreachkey (key, properties) { if (![key isEqualToString:kOOSystemLayerProperty]) { diff --git a/src/Core/OXPVerifier/OOFileScannerVerifierStage.m b/src/Core/OXPVerifier/OOFileScannerVerifierStage.m index 78776d308..c68f96d68 100644 --- a/src/Core/OXPVerifier/OOFileScannerVerifierStage.m +++ b/src/Core/OXPVerifier/OOFileScannerVerifierStage.m @@ -483,7 +483,7 @@ - (void)checkKnownFiles BOOL inDirectory; directories = [[self verifier] configurationDictionaryForKey:@"knownFiles"]; - foreachkey(directory, directories) + foreachkey (directory, directories) { fileList = [directories objectForKey:directory]; lcDirectory = [directory lowercaseString]; diff --git a/src/Core/OXPVerifier/OOOXPVerifier.m b/src/Core/OXPVerifier/OOOXPVerifier.m index 23a251794..bad4c1d5f 100644 --- a/src/Core/OXPVerifier/OOOXPVerifier.m +++ b/src/Core/OXPVerifier/OOOXPVerifier.m @@ -312,7 +312,7 @@ - (void)setUpLogOverrides OOLogSetShowMessageClassTemporary([_verifierPList oo_boolForKey:@"logShowMessageClassOverride" defaultValue:NO]); overrides = [_verifierPList oo_dictionaryForKey:@"logControlOverride"]; - foreachkey(messageClass, overrides) + foreachkey (messageClass, overrides) { OOLogSetDisplayMessagesInClass(messageClass, [overrides oo_boolForKey:messageClass defaultValue:NO]); } @@ -420,7 +420,7 @@ - (void)buildDependencyGraph // Iterate over all stages, resolving dependencies. stageKeys = [_stagesByName allKeys]; // Get the keys up front because we may need to remove entries from dictionary. - foreach(stageKey, stageKeys) + foreach (stageKey, stageKeys) { stage = [_stagesByName objectForKey:stageKey]; if (stage == nil) continue; @@ -561,7 +561,7 @@ - (BOOL)setUpDependencies:(NSSet *)dependencies OOOXPVerifierStage *depStage = nil; // Iterate over dependencies, connecting them up. - foreach(depName, dependencies) + foreach (depName, dependencies) { depStage = [_stagesByName objectForKey:depName]; if (depStage == nil) @@ -591,7 +591,7 @@ - (void)setUpDependents:(NSSet *)dependents OOOXPVerifierStage *depStage = nil; // Iterate over dependents, connecting them up. - foreach(depName, dependents) + foreach (depName, dependents) { depStage = [_stagesByName objectForKey:depName]; if (depStage == nil) @@ -629,7 +629,7 @@ - (void)dumpDebugGraphviz We use pointers as node names for simplicity of generation. */ template = [graphVizTemplate oo_stringForKey:@"node"]; - foreach(stage, [_stagesByName allValues]) + foreach (stage, [_stagesByName allValues]) { [graphViz appendFormat:template, stage, [stage class], [stage name]]; } diff --git a/src/Core/ResourceManager.m b/src/Core/ResourceManager.m index bd7965238..2ab403d6e 100644 --- a/src/Core/ResourceManager.m +++ b/src/Core/ResourceManager.m @@ -1158,7 +1158,7 @@ + (BOOL)checkCacheUpToDateForPaths:(NSArray *)searchPaths // Build modification date list. (We need this regardless of whether the search paths matched.) modDates = [NSMutableArray arrayWithCapacity:[searchPaths count]]; - foreach(path, searchPaths) + foreach (path, searchPaths) { modDate = [[fmgr oo_fileAttributesAtPath:path traverseLink:YES] objectForKey:NSFileModificationDate]; if (modDate != nil) @@ -1513,7 +1513,7 @@ + (NSDictionary *) logControlDictionary // Build list of root log message classes that appear in the built-in list. NSMutableSet *coreRoots = [NSMutableSet set]; NSString *key = nil; - foreachkey(key, logControl) + foreachkey (key, logControl) { [coreRoots addObject:LogClassKeyRoot(key)]; } @@ -1523,7 +1523,7 @@ + (NSDictionary *) logControlDictionary NSDictionary *dict = nil; // Look for logcontrol.plists inside OXPs (but not in root paths). These are not allowed to define keys in hierarchies used by the build-in one. - foreach(path, [self pathEnumerator]) + foreach (path, [self pathEnumerator]) { if ([rootPaths containsObject:path]) continue; @@ -1545,7 +1545,7 @@ + (NSDictionary *) logControlDictionary } // Now, look for logcontrol.plists in root paths, i.e. not within OXPs. These are allowed to override the built-in copy. - foreach(path, rootPaths) + foreach (path, rootPaths) { configPath = [[path stringByAppendingPathComponent:@"Config"] stringByAppendingPathComponent:@"logcontrol.plist"]; @@ -1577,7 +1577,7 @@ + (NSDictionary *) roleCategoriesDictionary NSString *configPath = nil; NSDictionary *categories = nil; - foreach(path, [self pathEnumerator]) + foreach (path, [self pathEnumerator]) { if ([ResourceManager corePlist:@"role-categories.plist" excludedAt:path]) { @@ -1610,7 +1610,7 @@ + (void) mergeRoleCategories:(NSDictionary *)catData intoDictionary:(NSMutableDi NSMutableSet *contents = nil; NSArray *catDataEntry = nil; NSString *key; - foreachkey(key, catData) + foreachkey (key, catData) { contents = [categories objectForKey:key]; if (contents == nil) @@ -1750,7 +1750,7 @@ + (NSString *) pathForFileNamed:(NSString *)fileName inFolder:(NSString *)folder // Search for file fmgr = [NSFileManager defaultManager]; // reverse object enumerator allows OXPs to override core - foreach(path, [[ResourceManager paths] reverseObjectEnumerator]) + foreach (path, [[ResourceManager paths] reverseObjectEnumerator]) { filePath = [[path stringByAppendingPathComponent:folderName] stringByAppendingPathComponent:fileName]; if ([fmgr oo_oxzFileExistsAtPath:filePath]) @@ -2039,7 +2039,7 @@ + (void) logPaths // Prettify paths for logging. displayPaths = [NSMutableArray arrayWithCapacity:[sSearchPaths count]]; - foreach(path, sSearchPaths) + foreach (path, sSearchPaths) { [displayPaths addObject:[[path stringByStandardizingPath] stringByAbbreviatingWithTildeInPath]]; } diff --git a/src/Core/Scripting/OOPListScript.m b/src/Core/Scripting/OOPListScript.m index 2d241bebd..f3b3c42d7 100644 --- a/src/Core/Scripting/OOPListScript.m +++ b/src/Core/Scripting/OOPListScript.m @@ -138,7 +138,7 @@ + (NSArray *)scriptsFromDictionaryOfScripts:(NSDictionary *)dictionary filePath: metadata = [dictionary objectForKey:kKeyMetadata]; if (![metadata isKindOfClass:[NSDictionary class]]) metadata = nil; - foreachkey(key, dictionary) + foreachkey (key, dictionary) { scriptArray = [dictionary objectForKey:key]; if ([key isKindOfClass:[NSString class]] && @@ -172,7 +172,7 @@ + (NSArray *) loadCachedScripts:(NSDictionary *)cachedScripts NSMutableArray *result = [NSMutableArray arrayWithCapacity:[cachedScripts count]]; - foreachkey(key, cachedScripts) + foreachkey (key, cachedScripts) { NSDictionary *cacheValue = [cachedScripts oo_dictionaryForKey:key]; NSArray *scriptArray = [cacheValue oo_arrayForKey:kKeyScript]; diff --git a/src/Core/Scripting/OOScript.m b/src/Core/Scripting/OOScript.m index ef4ff3964..f22af1ba8 100644 --- a/src/Core/Scripting/OOScript.m +++ b/src/Core/Scripting/OOScript.m @@ -149,7 +149,7 @@ + (NSArray *)scriptsFromList:(NSArray *)fileNames result = [NSMutableArray arrayWithCapacity:[fileNames count]]; - foreach(name, fileNames) + foreach (name, fileNames) { scripts = [self scriptsFromFileNamed:name]; if (scripts != nil) [result addObjectsFromArray:scripts]; diff --git a/src/Core/Scripting/OOScriptTimer.m b/src/Core/Scripting/OOScriptTimer.m index 1af75c5f4..6657eb468 100644 --- a/src/Core/Scripting/OOScriptTimer.m +++ b/src/Core/Scripting/OOScriptTimer.m @@ -205,7 +205,7 @@ + (void) noteGameReset // Intermediate array is required so we don't get stuck in an endless loop over reinserted timers. Note that -sortedObjects also clears the queue! timers = [sTimers sortedObjects]; - foreach(timer, timers) + foreach (timer, timers) { timer->_isScheduled = NO; } diff --git a/src/Core/Universe.m b/src/Core/Universe.m index f828a5c70..97a4e9974 100644 --- a/src/Core/Universe.m +++ b/src/Core/Universe.m @@ -6671,7 +6671,7 @@ - (void) update:(OOTimeDelta)inDeltaT { update_stage = @"shootin' zombies"; Entity *zombie = nil; - foreach(zombie, zombies) + foreach (zombie, zombies) { OOLogERR(@"universe.zombie", @"Found dead entity %@ in active entity list, removing. This is an internal error, please report it.", zombie); [self removeEntity:zombie]; @@ -8611,7 +8611,7 @@ - (NSArray *) shipsForSaleForSystem:(OOSystemID)s withTL:(OOTechLevelID)specialT id key = nil; BOOL missing = NO; - foreach(key, [item requiresEquipment]) + foreach (key, [item requiresEquipment]) { if (![extras containsObject:key]) { @@ -8626,7 +8626,7 @@ - (NSArray *) shipsForSaleForSystem:(OOSystemID)s withTL:(OOTechLevelID)specialT id key = nil; BOOL missing = YES; - foreach(key, [item requiresAnyEquipment]) + foreach (key, [item requiresAnyEquipment]) { if ([extras containsObject:key]) { @@ -10271,7 +10271,7 @@ - (void) runLocalizationTools arguments = [[NSProcessInfo processInfo] arguments]; - foreach(arg, arguments) + foreach (arg, arguments) { if ([arg isEqual:@"--compile-sysdesc"]) compileSysDesc = YES; else if ([arg isEqual:@"--export-sysdesc"]) exportSysDesc = YES; From 3e8d91e61b7c518bfd84ef1f413717589f53bfda Mon Sep 17 00:00:00 2001 From: "C.W. Betts" Date: Sat, 9 May 2015 22:25:20 -0600 Subject: [PATCH 7/9] Fix a couple of bugs. --- src/Core/Entities/PlayerEntity.m | 2 +- src/Core/Materials/OOShaderMaterial.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Core/Entities/PlayerEntity.m b/src/Core/Entities/PlayerEntity.m index f904a5102..10998f2cb 100644 --- a/src/Core/Entities/PlayerEntity.m +++ b/src/Core/Entities/PlayerEntity.m @@ -11892,7 +11892,7 @@ - (void) doWorldScriptEvent:(jsid)message inContext:(JSContext *)context withArg OOScript *theScript = nil; - foreachkey (theScript, worldScripts) + foreach (theScript, [worldScripts allValues]) { OOJSStartTimeLimiterWithTimeLimit(limit); [theScript callMethod:message inContext:context withArguments:argv count:argc result:NULL]; diff --git a/src/Core/Materials/OOShaderMaterial.m b/src/Core/Materials/OOShaderMaterial.m index 7c4451757..09865d62d 100644 --- a/src/Core/Materials/OOShaderMaterial.m +++ b/src/Core/Materials/OOShaderMaterial.m @@ -671,7 +671,7 @@ - (BOOL)doApply @try { - foreach (uniform, uniforms) + foreach (uniform, [uniforms allValues]) { [uniform apply]; } From d1dd01fb856c1102125eb895a1e8c8fe56609f5b Mon Sep 17 00:00:00 2001 From: "C.W. Betts" Date: Sat, 9 May 2015 22:44:57 -0600 Subject: [PATCH 8/9] Revert some changes that use their own custom enumerators. --- src/Core/Entities/PlayerEntity.m | 9 ++++++--- src/Core/Entities/PlayerEntityContracts.m | 5 +++-- src/Core/Entities/PlayerEntityLegacyScriptEngine.m | 3 ++- src/Core/Entities/ShipEntity.m | 9 ++++++--- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/Core/Entities/PlayerEntity.m b/src/Core/Entities/PlayerEntity.m index 10998f2cb..2a7d6b263 100644 --- a/src/Core/Entities/PlayerEntity.m +++ b/src/Core/Entities/PlayerEntity.m @@ -810,8 +810,9 @@ - (NSDictionary *) commanderDataDictionary // extra equipment flags NSMutableDictionary *equipment = [NSMutableDictionary dictionary]; + NSEnumerator *eqEnum = nil; NSString *eqDesc = nil; - foreach (eqDesc, [self equipmentEnumerator]) + for (eqEnum = [self equipmentEnumerator]; (eqDesc = [eqEnum nextObject]); ) { [equipment oo_setInteger:[self countEquipmentItem:eqDesc] forKey:eqDesc]; } @@ -5788,8 +5789,9 @@ - (GLfloat) doesHitLine:(HPVector)v0 :(HPVector)v1 :(ShipEntity **)hitEntity shields = true; } + NSEnumerator *subEnum = nil; ShipEntity *se = nil; - foreach (se, [self shipSubEntityEnumerator]) + for (subEnum = [self shipSubEntityEnumerator]; (se = [subEnum nextObject]); ) { HPVector p0 = [se absolutePositionForSubentity]; Triangle ijk = [se absoluteIJKForSubentity]; @@ -7490,13 +7492,14 @@ - (NSArray *) equipmentList GuiDisplayGen *gui = [UNIVERSE gui]; NSMutableArray *quip1 = [NSMutableArray array]; // damaged NSMutableArray *quip2 = [NSMutableArray array]; // working + NSEnumerator *eqTypeEnum = nil; OOEquipmentType *eqType = nil; NSString *desc = nil; NSString *alldesc = nil; BOOL prioritiseDamaged = [[gui userSettings] oo_boolForKey:kGuiStatusPrioritiseDamaged defaultValue:YES]; - foreach (eqType, [OOEquipmentType reverseEquipmentEnumerator]) + for (eqTypeEnum = [OOEquipmentType reverseEquipmentEnumerator]; (eqType = [eqTypeEnum nextObject]); ) { if ([eqType isVisible]) { diff --git a/src/Core/Entities/PlayerEntityContracts.m b/src/Core/Entities/PlayerEntityContracts.m index 4655b563b..1403a3732 100644 --- a/src/Core/Entities/PlayerEntityContracts.m +++ b/src/Core/Entities/PlayerEntityContracts.m @@ -1933,10 +1933,11 @@ - (void) newShipCommonSetup:(NSString *)shipKey yardInfo:(NSDictionary *)ship_in // keep track of portable equipment.. NSMutableSet *portable_equipment = [NSMutableSet set]; + NSEnumerator *eqEnum = nil; NSString *eq_desc = nil; OOEquipmentType *item = nil; - foreach (eq_desc, [self equipmentEnumerator]) + for (eqEnum = [self equipmentEnumerator]; (eq_desc = [eqEnum nextObject]);) { item = [OOEquipmentType equipmentTypeWithIdentifier:eq_desc]; if ([item isPortableBetweenShips]) [portable_equipment addObject:eq_desc]; @@ -1946,7 +1947,7 @@ - (void) newShipCommonSetup:(NSString *)shipKey yardInfo:(NSDictionary *)ship_in [self removeAllEquipment]; // restore portable equipment - foreach (eq_desc, portable_equipment) + for (eqEnum = [portable_equipment objectEnumerator]; (eq_desc = [eqEnum nextObject]); ) { [self addEquipmentItem:eq_desc withValidation:NO inContext:@"portable"]; } diff --git a/src/Core/Entities/PlayerEntityLegacyScriptEngine.m b/src/Core/Entities/PlayerEntityLegacyScriptEngine.m index e407fd566..2e46f7182 100644 --- a/src/Core/Entities/PlayerEntityLegacyScriptEngine.m +++ b/src/Core/Entities/PlayerEntityLegacyScriptEngine.m @@ -231,10 +231,11 @@ static void PerformActionStatment(NSArray *statement, Entity *target) static BOOL TestScriptConditions(NSArray *conditions) { + NSEnumerator *condEnum = nil; NSArray *condition = nil; PlayerEntity *player = PLAYER; - foreach (condition, conditions) + for (condEnum = [conditions objectEnumerator]; (condition = [condEnum nextObject]); ) { if (![player scriptTestCondition:condition]) return NO; } diff --git a/src/Core/Entities/ShipEntity.m b/src/Core/Entities/ShipEntity.m index e9dbe7e06..fba7d73e2 100644 --- a/src/Core/Entities/ShipEntity.m +++ b/src/Core/Entities/ShipEntity.m @@ -784,10 +784,11 @@ - (NSString *) repeatString:(NSString *)str times:(NSUInteger)times - (NSString *) serializeShipSubEntities { NSMutableString *result = [NSMutableString stringWithCapacity:4]; + NSEnumerator *subEnum = nil; ShipEntity *se = nil; NSUInteger diff, i = 0; - foreach (se, [self shipSubEntityEnumerator]) + for (subEnum = [self shipSubEntityEnumerator]; (se = [subEnum nextObject]); ) { diff = [se subIdx] - i; i += diff + 1; @@ -1419,8 +1420,9 @@ - (GLfloat) doesHitLine:(HPVector)v0 :(HPVector)v1 :(ShipEntity **)hitEntity hitEntity[0] = self; } + NSEnumerator *subEnum = nil; ShipEntity *se = nil; - foreach (se, [self shipSubEntityEnumerator]) + for (subEnum = [self shipSubEntityEnumerator]; (se = [subEnum nextObject]); ) { HPVector p0 = [se absolutePositionForSubentity]; Triangle ijk = [se absoluteIJKForSubentity]; @@ -2972,6 +2974,7 @@ - (BOOL) hasOneEquipmentItem:(NSString *)itemKey includeMissiles:(BOOL)includeMi - (BOOL) hasPrimaryWeapon:(OOWeaponType)weaponType { + NSEnumerator *subEntEnum = nil; ShipEntity *subEntity = nil; if ([[forward_weapon_type identifier] isEqualToString:[weaponType identifier]] || @@ -2982,7 +2985,7 @@ - (BOOL) hasPrimaryWeapon:(OOWeaponType)weaponType return YES; } - foreach (subEntity, [self shipSubEntityEnumerator]) + for (subEntEnum = [self shipSubEntityEnumerator]; (subEntity = [subEntEnum nextObject]); ) { if ([subEntity hasPrimaryWeapon:weaponType]) return YES; } From 32821da2b9766cf1d02a6b8b7755d2b8206780f0 Mon Sep 17 00:00:00 2001 From: "C.W. Betts" Date: Sun, 10 May 2015 11:43:16 -0600 Subject: [PATCH 9/9] Fixed a few improper foreachkeys. --- src/Core/Entities/PlayerEntity.m | 2 +- src/Core/Entities/ShipEntityLoadRestore.m | 2 +- src/Core/Materials/OOShaderMaterial.m | 2 +- src/Core/Materials/OOShaderProgram.m | 2 +- src/Core/OOOXZManager.m | 4 ++-- src/Core/OOShipRegistry.m | 7 ++++--- src/Core/Scripting/OOJSEngineTimeManagement.m | 2 +- 7 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Core/Entities/PlayerEntity.m b/src/Core/Entities/PlayerEntity.m index 2a7d6b263..1c4120b35 100644 --- a/src/Core/Entities/PlayerEntity.m +++ b/src/Core/Entities/PlayerEntity.m @@ -12161,7 +12161,7 @@ - (void)updateWormholes NSMutableArray * savedWormholes = [[NSMutableArray alloc] initWithCapacity:[scannedWormholes count]]; WormholeEntity *wh; - foreachkey (wh, scannedWormholes) + foreach (wh, scannedWormholes) { // TODO: Start drawing wormhole exit a few seconds before the first // ship is disgorged. diff --git a/src/Core/Entities/ShipEntityLoadRestore.m b/src/Core/Entities/ShipEntityLoadRestore.m index 79fdbbaa9..874b99b2e 100644 --- a/src/Core/Entities/ShipEntityLoadRestore.m +++ b/src/Core/Entities/ShipEntityLoadRestore.m @@ -308,7 +308,7 @@ static void StripIgnoredKeys(NSMutableDictionary *dict) if (ignoredKeys == nil) ignoredKeys = [[NSArray alloc] initWithObjects:@"ai_type", @"has_ecm", @"has_scoop", @"has_escape_pod", @"has_energy_bomb", @"has_fuel_injection", @"has_cloaking_device", @"has_military_jammer", @"has_military_scanner_filter", @"has_shield_booster", @"has_shield_enhancer", @"escorts", @"escort_role", @"escort-ship", @"conditions", @"missiles", @"auto_ai", nil]; NSString *key = nil; - foreachkey (key, ignoredKeys) + foreach (key, ignoredKeys) { [dict removeObjectForKey:key]; } diff --git a/src/Core/Materials/OOShaderMaterial.m b/src/Core/Materials/OOShaderMaterial.m index 09865d62d..8ca75c59a 100644 --- a/src/Core/Materials/OOShaderMaterial.m +++ b/src/Core/Materials/OOShaderMaterial.m @@ -853,7 +853,7 @@ static BOOL GetShaderSource(NSString *fileName, NSString *shaderType, NSString * // Futureproofing -- in future, we may wish to support automatic selection between supported shader languages. if (![fileName pathHasExtensionInArray:extensions]) { - foreachkey (extension, extensions) + foreach (extension, extensions) { nameWithExtension = [fileName stringByAppendingPathExtension:extension]; result = [ResourceManager stringFromFilesNamed:nameWithExtension diff --git a/src/Core/Materials/OOShaderProgram.m b/src/Core/Materials/OOShaderProgram.m index ed14634ae..bcb307110 100644 --- a/src/Core/Materials/OOShaderProgram.m +++ b/src/Core/Materials/OOShaderProgram.m @@ -410,7 +410,7 @@ - (void) bindStandardMatrixUniforms OO_ENTER_OPENGL(); [matrixManager syncModelView]; - foreachkey (obj, standardMatrixUniformLocations) + foreach (obj, standardMatrixUniformLocations) { if ([obj isKindOfClass:[NSArray class]]) { diff --git a/src/Core/OOOXZManager.m b/src/Core/OOOXZManager.m index 279a28c76..ca09ad71b 100644 --- a/src/Core/OOOXZManager.m +++ b/src/Core/OOOXZManager.m @@ -778,7 +778,7 @@ - (BOOL) processDownloadedOXZ } NSDictionary *requirement = nil; NSMutableString *progress = [NSMutableString stringWithCapacity:2048]; - OOLog(kOOOXZDebugLog,@"Dependency stack has %u elements",[_dependencyStack count]); + OOLog(kOOOXZDebugLog,@"Dependency stack has %lu elements", (unsigned long)[_dependencyStack count]); if ([_dependencyStack count] > 0) { @@ -845,7 +845,7 @@ - (BOOL) processDownloadedOXZ _downloadStatus = OXZ_DOWNLOAD_NONE; if (_downloadAllDependencies) { - OOLog(kOOOXZDebugLog,@"Dependency stack: installing %u from list",index); + OOLog(kOOOXZDebugLog,@"Dependency stack: installing %lu from list",(unsigned long)index); if (![self installOXZ:index]) { // if a required dependency is somehow uninstallable // e.g. required+maximum version don't match this Oolite diff --git a/src/Core/OOShipRegistry.m b/src/Core/OOShipRegistry.m index aad437388..cab0826fe 100644 --- a/src/Core/OOShipRegistry.m +++ b/src/Core/OOShipRegistry.m @@ -792,13 +792,14 @@ - (BOOL) stripPrivateKeys:(NSMutableDictionary *)ioData { NSString *shipKey = nil; NSMutableDictionary *shipEntry = nil; + NSEnumerator *attrKeyEnum = nil; NSString *attrKey = nil; foreachkey (shipKey, ioData) { shipEntry = [ioData objectForKey:shipKey]; - foreachkey (attrKey, shipEntry) + for (attrKeyEnum = [shipEntry keyEnumerator]; (attrKey = [attrKeyEnum nextObject]); ) { if ([attrKey hasPrefix:@"_oo_"]) { @@ -1638,7 +1639,7 @@ - (BOOL) shipIsBallTurretForKey:(NSString *)shipKey inShipData:(NSDictionary *)s setupActions = [[shipData oo_dictionaryForKey:shipKey] oo_arrayForKey:@"setup_actions"]; - foreachkey (action, setupActions) + foreach (action, setupActions) { if ([[ScanTokensFromString(action) objectAtIndex:0] isEqualToString:@"initialiseTurret"]) return YES; } @@ -1717,7 +1718,7 @@ static void DumpStringAddrs(NSDictionary *dict, NSString *context) GatherStringAddrs(dict, strings, context); NSDictionary *entry = nil; - foreachkey (entry, strings) + foreach (entry, strings) { NSString *string = [entry objectForKey:@"string"]; NSString *context = [entry objectForKey:@"context"]; diff --git a/src/Core/Scripting/OOJSEngineTimeManagement.m b/src/Core/Scripting/OOJSEngineTimeManagement.m index 807149413..6c2868b5b 100644 --- a/src/Core/Scripting/OOJSEngineTimeManagement.m +++ b/src/Core/Scripting/OOJSEngineTimeManagement.m @@ -761,7 +761,7 @@ - (NSDictionary *) propertyListRepresentation NSArray *profileEntries = [self profileEntries]; NSMutableArray *convertedEntries = [NSMutableArray arrayWithCapacity:[profileEntries count]]; OOTimeProfileEntry *entry = nil; - foreachkey (entry, profileEntries) + foreach (entry, profileEntries) { [convertedEntries addObject:[entry propertyListRepresentation]]; }