Moved property list reading (with error checking) into OOPListParsing.h/m. Build without warnings under Windows.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@862 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2007-03-20 17:12:39 +00:00
parent 946ef40873
commit d2914c3afb
22 changed files with 199 additions and 127 deletions

View File

@ -725,7 +725,7 @@
083325DC09DDBCDE00F5B8E4 /* OOColor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OOColor.m; sourceTree = "<group>"; };
083DB4D30A70E51E00B419B2 /* OOBrain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OOBrain.h; sourceTree = "<group>"; };
083DB4D40A70E51E00B419B2 /* OOBrain.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OOBrain.m; sourceTree = "<group>"; };
0865432206B8447D000CA0AB /* Oolite.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Oolite.app; sourceTree = BUILT_PRODUCTS_DIR; };
0865432206B8447D000CA0AB /* OoliteDev.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = OoliteDev.app; sourceTree = BUILT_PRODUCTS_DIR; };
0878FD2F086EF845004CB752 /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = /System/Library/Frameworks/Carbon.framework; sourceTree = "<absolute>"; };
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
1A23154E0B9C778400EF0852 /* solar.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = solar.png; sourceTree = "<group>"; };
@ -1186,7 +1186,7 @@
19C28FACFE9D520D11CA2CBB /* Products */ = {
isa = PBXGroup;
children = (
0865432206B8447D000CA0AB /* Oolite.app */,
0865432206B8447D000CA0AB /* OoliteDev.app */,
);
name = Products;
sourceTree = "<group>";
@ -1973,7 +1973,7 @@
name = Oolite;
productInstallPath = "$(HOME)/Applications";
productName = Oolite;
productReference = 0865432206B8447D000CA0AB /* Oolite.app */;
productReference = 0865432206B8447D000CA0AB /* OoliteDev.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */

View File

@ -124,6 +124,10 @@ mesh.load.error.tooManyVertices = inherit;
mesh.load.error.tooManyFaces = inherit;
plist.parse.foundation.failed = $error;
plist.wrongType = $error;
rendering.opengl.error = $error; // Test for and display OpenGL errors
rendering.opengl.version = $troubleShootingDump; // Display renderer version information at startup
rendering.opengl.extensions = $troubleShootingDump; // List OpenGL extensions at startup

View File

@ -28,9 +28,8 @@ MA 02110-1301, USA.
#include <stdlib.h>
#import "NSFileManagerOOExtensions.h"
#ifdef WIN32
#import "ResourceManager.h"
#endif
#import "OOPListParsing.h"
@implementation NSFileManager (OOExtensions)
@ -55,11 +54,7 @@ MA 02110-1301, USA.
}
// check can parse the file okay
NSDictionary* cdr = [NSDictionary dictionaryWithContentsOfFile: path];
#ifdef WIN32
if (!cdr)
cdr = (NSDictionary *)[ResourceManager parseXMLPropertyList: [NSString stringWithContentsOfFile: path]];
#endif
NSDictionary* cdr = OODictionaryFromFile(path);
if(!cdr)
{
NSLog(@">>>> %@ could not be parsed as a saved game", path);
@ -103,11 +98,7 @@ MA 02110-1301, USA.
}
// check to see if we can parse the file okay
NSDictionary* cdr = [NSDictionary dictionaryWithContentsOfFile: path];
#ifdef WIN32
if (!cdr)
cdr = (NSDictionary *)[ResourceManager parseXMLPropertyList: [NSString stringWithContentsOfFile: path]];
#endif
NSDictionary* cdr = OODictionaryFromFile(path);
if(!cdr)
{
NSLog(@">>>> %@ could not be parsed as a saved game", path);

View File

@ -468,7 +468,7 @@ static BOOL CacheRemoveOldest(OOCacheImpl *cache)
static id CacheRetrieve(OOCacheImpl *cache, NSString *key)
{
OOCacheNode *node = nil;
OOCacheNode *node = NULL;
id result = nil;
if (cache == NULL || key == NULL) return nil;
@ -538,7 +538,7 @@ static OOCacheNode *CacheNodeAllocate(id key, id value)
{
OOCacheNode *result = NULL;
if (key == nil || value == nil) return nil;
if (key == nil || value == nil) return NULL;
result = calloc(sizeof *result, 1);
if (result != NULL)

View File

@ -24,6 +24,7 @@ MA 02110-1301, USA.
#import "OOCacheManager.h"
#import "OOCache.h"
#import "OOPListParsing.h"
static NSString * const kOOLogDataCacheFound = @"dataCache.found";
@ -460,9 +461,10 @@ static OOCacheManager *sSingleton = nil;
}
// Should probably be using NSPropertyListGNUstepBinaryFormat.
- (NSDictionary *)loadDict
{
return [NSDictionary dictionaryWithContentsOfFile:[self cachePath]];
return OODictionaryFromFile([self cachePath]);
}

View File

@ -23,6 +23,7 @@ MA 02110-1301, USA.
*/
#import "OOCollectionExtractors.h"
#import <limits.h>
@implementation NSArray (OOExtractor)
@ -556,4 +557,4 @@ MA 02110-1301, USA.
return result;
}
@end
@end

View File

@ -27,6 +27,7 @@ MA 02110-1301, USA.
#import "OOLogging.h"
#import "OOPListParsing.h"
#ifdef GNUSTEP // We really need better target macros.
@ -63,8 +64,8 @@ static BOOL sOverrideInEffect = NO;
static BOOL sOverrideValue = NO;
// These specific values are used for true, false and inherit in the cache and explicitSettings dictionaries so we can use pointer comparison.
static NSNumber * const kTrueToken = @"on";
static NSNumber * const kFalseToken = @"off";
static NSString * const kTrueToken = @"on";
static NSString * const kFalseToken = @"off";
static NSString * const kInheritToken = @"inherit";
@ -100,8 +101,8 @@ static inline void PrimitiveLog(NSString *inString)
// Given a boolean, return the appropriate value for the cache dictionary.
static inline NSNumber *CacheValue(BOOL inValue) __attribute__((pure));
static inline NSNumber *CacheValue(BOOL inValue)
static inline id CacheValue(BOOL inValue) __attribute__((pure));
static inline id CacheValue(BOOL inValue)
{
return inValue ? kTrueToken : kFalseToken;
}
@ -387,7 +388,7 @@ static void LoadExplicitSettings(void)
configPath = [configPath stringByAppendingPathComponent:@"Config"];
configPath = [configPath stringByAppendingPathComponent:@"logcontrol.plist"];
#endif
dict = [NSDictionary dictionaryWithContentsOfFile:configPath];
dict = OODictionaryFromFile(configPath);
LoadExplicitSettingsFromDictionary(dict, NO);
// Get overrides from preferences

View File

@ -29,12 +29,13 @@ MA 02110-1301, USA.
#import <Foundation/Foundation.h>
id OOPropertyListFromData(NSData *inData);
id OOPropertyListFromFile(NSString *inPath);
// whereFrom is an optional description of the data source, for error reporting.
id OOPropertyListFromData(NSData *data, NSString *whereFrom);
id OOPropertyListFromFile(NSString *path);
// Wrappers which ensure that the plist contains the right type of object.
NSDictionary *OODictionaryFromData(NSData *inData);
NSDictionary *OODictionaryFromFile(NSString *inPath);
NSDictionary *OODictionaryFromData(NSData *data, NSString *whereFrom);
NSDictionary *OODictionaryFromFile(NSString *path);
NSArray *OOArrayFromData(NSData *inData);
NSArray *OOArrayFromFile(NSString *inPath);
NSArray *OOArrayFromData(NSData *data, NSString *whereFrom);
NSArray *OOArrayFromFile(NSString *path);

View File

@ -24,6 +24,106 @@ MA 02110-1301, USA.
#import "OOPListParsing.h"
#import "OOLogging.h"
static NSString * const kOOLogPListFoundationParseError = @"plist.parse.foundation.failed";
static NSString * const kOOLogPListWrongType = @"plist.wrongType";
static id ValueIfClass(id value, Class class);
id OOPropertyListFromData(NSData *data, NSString *whereFrom)
{
id result = nil;
NSString *error = nil;
if (data != nil)
{
result = [NSPropertyListSerialization propertyListFromData:data mutabilityOption:NSPropertyListImmutable format:NULL errorDescription:&error];
if (result == nil) // Foundation parser failed
{
// Ensure we can say something sensible...
if (error == nil) error = @"<no error message>";
if (whereFrom == nil) whereFrom = @"<data in memory>";
// Complain
OOLog(kOOLogPListFoundationParseError, @"Failed to parse %@ as a property list using Foundation. Retrying using home-grown parser. WARNING: the home-grown parser is deprecated and will be removed in a future version of Oolite.\n%@", whereFrom, error);
OOLogIndentIf(kOOLogPListFoundationParseError);
// TODO: use homebrew parser here
OOLogOutdentIf(kOOLogPListFoundationParseError);
}
}
return result;
}
id OOPropertyListFromFile(NSString *path)
{
id result = nil;
NSData *data = nil;
if (path != nil)
{
// Load file, if it exists...
data = [[NSData alloc] initWithContentsOfMappedFile:path];
if (data != nil)
{
// ...and parse it
result = OOPropertyListFromData(data, path);
[data release];
}
// Non-existent file is not an error.
}
return result;
}
// Wrappers which ensure that the plist contains the right type of object.
NSDictionary *OODictionaryFromData(NSData *data, NSString *whereFrom)
{
id result = OOPropertyListFromData(data, whereFrom);
return ValueIfClass(result, [NSDictionary class]);
}
NSDictionary *OODictionaryFromFile(NSString *path)
{
id result = OOPropertyListFromFile(path);
return ValueIfClass(result, [NSDictionary class]);
}
NSArray *OOArrayFromData(NSData *data, NSString *whereFrom)
{
id result = OOPropertyListFromData(data, whereFrom);
return ValueIfClass(result, [NSArray class]);
}
NSArray *OOArrayFromFile(NSString *path)
{
id result = OOPropertyListFromFile(path);
return ValueIfClass(result, [NSArray class]);
}
// Ensure that object is of desired class.
static id ValueIfClass(id value, Class class)
{
if (value != nil && ![value isKindOfClass:class])
{
OOLog(kOOLogPListWrongType, @"Property list is wrong type - expected %@, got %@.", class, [value class]);
value = nil;
}
return value;
}
#if 0

View File

@ -71,7 +71,7 @@ BOOL ScanVectorFromString(NSString *xyzString, Vector *outVector)
NSScanner *scanner = nil;
if (xyzString == nil) return NO;
else if (outVector == nil) error = @"nil result pointer";
else if (outVector == NULL) error = @"nil result pointer";
if (!error) scanner = [NSScanner scannerWithString:xyzString];
while (![scanner isAtEnd] && i < 3 && !error)
@ -102,7 +102,7 @@ BOOL ScanQuaternionFromString(NSString *wxyzString, Quaternion *outQuaternion)
NSScanner *scanner = nil;
if (wxyzString == nil) return NO;
else if (outQuaternion == nil) error = @"nil result pointer";
else if (outQuaternion == NULL) error = @"nil result pointer";
if (!error) scanner = [NSScanner scannerWithString:wxyzString];
while (![scanner isAtEnd] && i < 4 && !error)
@ -136,7 +136,7 @@ BOOL ScanVectorAndQuaternionFromString(NSString *xyzwxyzString, Vector *outVecto
NSScanner *scanner = nil;
if (xyzwxyzString == nil) return NO;
else if (outVector == nil || outQuaternion == nil) error = @"nil result pointer";
else if (outVector == NULL || outQuaternion == NULL) error = @"nil result pointer";
if (!error) scanner = [NSScanner scannerWithString:xyzwxyzString];
while (![scanner isAtEnd] && i < 7 && !error)

View File

@ -418,8 +418,8 @@ void setUpSinTable()
//
isTextured = NO;
textureName = 0;
textureData = nil;
normalMapTextureData = nil;
textureData = NULL;
normalMapTextureData = NULL;
//
planet_seed = p_seed.a * 13 + p_seed.c * 11 + p_seed.e * 7; // pseudo-random set-up for vertex colours
//

View File

@ -48,6 +48,7 @@ MA 02110-1301, USA.
#import "OOCacheManager.h"
#import "OXPScript.h"
#import "OOStringParsing.h"
#import "OOPListParsing.h"
#ifndef GNUSTEP
#import "Groolite.h"
@ -4292,8 +4293,8 @@ double scoopSoundPlayTime = 0.0;
NSString* fail_reason = nil;
if (fileToOpen)
{
fileDic = [NSDictionary dictionaryWithContentsOfFile:fileToOpen];
fileDic = OODictionaryFromFile(fileToOpen);
if (fileDic)
{
[self set_up];
@ -5240,9 +5241,9 @@ static int last_outfitting_index;
// find options that agree with this ship
BOOL option_okay[[equipdata count]];
NSMutableArray* options = [NSMutableArray arrayWithArray:(NSArray*)[[[universe shipyard] objectForKey:ship_desc] objectForKey:KEY_OPTIONAL_EQUIPMENT]];
NSMutableArray* options = [NSMutableArray arrayWithArray:[(NSDictionary *)[[universe shipyard] objectForKey:ship_desc] objectForKey:KEY_OPTIONAL_EQUIPMENT]];
// add standard items too!
[options addObjectsFromArray:(NSArray*)[[[[universe shipyard] objectForKey:ship_desc] objectForKey:KEY_STANDARD_EQUIPMENT] objectForKey:KEY_EQUIPMENT_EXTRAS]];
[options addObjectsFromArray:[(NSDictionary *)[(NSDictionary *)[[universe shipyard] objectForKey:ship_desc] objectForKey:KEY_STANDARD_EQUIPMENT] objectForKey:KEY_EQUIPMENT_EXTRAS]];
int i,j;
for (i = 0; i < [equipdata count]; i++)

View File

@ -32,6 +32,7 @@ MA 02110-1301, USA.
#import "StationEntity.h"
#import "GuiDisplayGen.h"
#import "OOStringParsing.h"
#import "OOCollectionExtractors.h"
static NSString * const kOOLogNoteShowShipyardModel = @"script.debug.note.showShipyardModel";
@ -1246,9 +1247,8 @@ static NSMutableDictionary* currentShipyard = nil;
NSString* sales_pitch = (NSString*)[info objectForKey:KEY_SHORT_DESCRIPTION];
int cargo_rating = [(NSNumber*)[(NSDictionary *)[info objectForKey:SHIPYARD_KEY_SHIP] objectForKey:@"max_cargo"] intValue];
int cargo_extra = 15;
if ([[info objectForKey:SHIPYARD_KEY_SHIP] objectForKey:@"extra_cargo"])
cargo_extra = [[[info objectForKey:SHIPYARD_KEY_SHIP] objectForKey:@"extra_cargo"] intValue];
int cargo_extra;
cargo_extra = [[info objectForKey:SHIPYARD_KEY_SHIP] intForKey:@"extra_cargo" defaultValue:15];
float speed_rating = 0.001 * [(NSNumber*)[(NSDictionary *)[info objectForKey:SHIPYARD_KEY_SHIP] objectForKey:@"max_flight_speed"] intValue];
NSArray* ship_extras = (NSArray*)[info objectForKey:KEY_EQUIPMENT_EXTRAS];
for (i = 0; i < [ship_extras count]; i++)

View File

@ -33,6 +33,7 @@ MA 02110-1301, USA.
#import "OOSound.h"
#import "OOColor.h"
#import "OOStringParsing.h"
#import "OOPListParsing.h"
#ifdef WIN32
#import "ResourceManager.h"
@ -159,12 +160,7 @@ MA 02110-1301, USA.
BOOL pathIsDirectory = NO;
if ([cdrFileManager fileExistsAtPath:path isDirectory:&pathIsDirectory] && (!pathIsDirectory))
{
NSDictionary* cdr = [NSDictionary dictionaryWithContentsOfFile: path];
#ifdef WIN32
// untested... I don't have a Windows box to test this with.
if(!cdr)
cdr=(NSDictionary *)[ResourceManager parseXMLPropertyList: [NSString stringWithContentsOfFile:path]];
#endif
NSDictionary *cdr = OODictionaryFromFile(path);
if(cdr)
{
// okay use the same dictionary but add a 'saved_game_path' attribute
@ -395,8 +391,8 @@ MA 02110-1301, USA.
{
[self showCommanderShip: idx];
}
if ([[cdrDetailArray objectAtIndex:idx] objectForKey:@"isSavedGame"]) // don't show things that aren't saved games
commanderNameString = [[cdrDetailArray objectAtIndex:idx] objectForKey:@"player_name"];
if ([(NSDictionary *)[cdrDetailArray objectAtIndex:idx] objectForKey:@"isSavedGame"]) // don't show things that aren't saved games
commanderNameString = [(NSDictionary *)[cdrDetailArray objectAtIndex:idx] objectForKey:@"player_name"];
else
commanderNameString = [gameView typedString];
}
@ -669,7 +665,7 @@ MA 02110-1301, USA.
int i;
for (i=0; i < [cdrDetailArray count]; i++)
{
NSString *currentName=[[cdrDetailArray objectAtIndex: i] objectForKey:@"player_name"];
NSString *currentName=[(NSDictionary *)[cdrDetailArray objectAtIndex: i] objectForKey:@"player_name"];
if([cdrName compare: currentName] == NSOrderedSame)
{
return i;

View File

@ -36,6 +36,7 @@ MA 02110-1301, USA.
#import "PlanetEntity.h"
#import "ParticleEntity.h"
#import "StationEntity.h"
#ifdef GNUSTEP
#import "Comparison.h"

View File

@ -29,6 +29,7 @@ MA 02110-1301, USA.
#import "OOCacheManager.h"
#import "Universe.h"
#import "OOStringParsing.h"
#import "OOPListParsing.h"
static NSString * const kOOLogDumpSearchPaths = @"searchPaths.dumpAll";
@ -255,15 +256,17 @@ NSMutableDictionary* surface_cache;
NSString* requiresPath = [possibleExpansionPath stringByAppendingPathComponent:@"requires.plist"];
BOOL require_test = YES;
BOOL failed_parsing = NO;
// check for compatibility
if ([fmgr fileExistsAtPath:requiresPath])
NSDictionary* requires_dic = OODictionaryFromFile(requiresPath);
if (requires_dic != nil)
{
NSDictionary* requires_dic = [NSDictionary dictionaryWithContentsOfFile:requiresPath];
require_test = [ResourceManager areRequirementsFulfilled:requires_dic];
}
if (require_test)
{
[file_paths addObject:possibleExpansionPath];
}
else
{
NSString* version = (NSString *)[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
@ -350,33 +353,20 @@ NSMutableDictionary* surface_cache;
dictionary_cache = [[NSMutableDictionary alloc] initWithCapacity:32];
if ([dictionary_cache objectForKey:dict_key])
{
return [NSDictionary dictionaryWithDictionary:(NSDictionary *)[dictionary_cache objectForKey:dict_key]]; // return the cached dictionary
return [[[dictionary_cache objectForKey:dict_key] copy] autorelease]; // return the cached dictionary
}
for (i = 0; i < [fpaths count]; i++)
{
NSString *filepath = [(NSString *)[fpaths objectAtIndex:i] stringByAppendingPathComponent:filename];
if ([[NSFileManager defaultManager] fileExistsAtPath:filepath])
{
NSDictionary* found_dic = [NSDictionary dictionaryWithContentsOfFile:filepath];
if (found_dic)
[results addObject:found_dic];
else
NSLog(@"ERROR ***** could not parse %@ as a NSDictionary.", filepath);
}
NSDictionary* found_dic = OODictionaryFromFile(filepath);
if (found_dic) [results addObject:found_dic];
if (foldername)
{
filepath = [[(NSString *)[fpaths objectAtIndex:i] stringByAppendingPathComponent:foldername] stringByAppendingPathComponent:filename];
if ([[NSFileManager defaultManager] fileExistsAtPath:filepath])
{
NSDictionary* found_dic = [NSDictionary dictionaryWithContentsOfFile:filepath];
if (found_dic)
[results addObject:found_dic];
else
NSLog(@"ERROR ***** could not parse %@ as a NSDictionary.", filepath);
}
NSDictionary* found_dic = OODictionaryFromFile(filepath);
if (found_dic) [results addObject:found_dic];
}
}
if ([results count] == 0)
@ -425,30 +415,16 @@ NSMutableDictionary* surface_cache;
for (i = 0; i < [fpaths count]; i++)
{
NSString *filepath = [(NSString *)[fpaths objectAtIndex:i] stringByAppendingPathComponent:filename];
if ([[NSFileManager defaultManager] fileExistsAtPath:filepath])
{
NSArray* found_array = [NSArray arrayWithContentsOfFile:filepath];
if (found_array)
[results addObject:found_array];
else
NSLog(@"ERROR ***** could not parse %@ as a NSArray.", filepath);
}
// [results addObject:[NSArray arrayWithContentsOfFile:filepath]];
NSArray* found_array = OOArrayFromFile(filepath);
if (found_array) [results addObject:found_array];
if (foldername)
{
filepath = [[(NSString *)[fpaths objectAtIndex:i] stringByAppendingPathComponent:foldername] stringByAppendingPathComponent:filename];
if ([[NSFileManager defaultManager] fileExistsAtPath:filepath])
{
NSArray* found_array = [NSArray arrayWithContentsOfFile:filepath];
if (found_array)
[results addObject:found_array];
else
NSLog(@"ERROR ***** could not parse %@ as a NSArray.", filepath);
}
// [results addObject:[NSArray arrayWithContentsOfFile:filepath]];
NSArray* found_array = OOArrayFromFile(filepath);
if (found_array) [results addObject:found_array];
}
}
if ([results count] == 0)
@ -668,15 +644,8 @@ NSMutableDictionary* surface_cache;
// This can be simplified if we make a rule that it is a configuration error
// that isn't handled if there is a script.oos and script.plist file in
// the same place. But that probably isn't realistic.
if ([[NSFileManager defaultManager] fileExistsAtPath:filepath])
{
NSDictionary* found_dic = [NSDictionary dictionaryWithContentsOfFile:filepath];
if (found_dic)
[results addObject:found_dic];
else
NSLog(@"ERROR ***** could not parse %@ as a NSDictionary.", filepath);
}
NSDictionary* found_dic = OODictionaryFromFile(filepath);
if (found_dic) [results addObject:found_dic];
}
if (foldername)
{
@ -697,16 +666,8 @@ NSMutableDictionary* surface_cache;
else
{
filepath = [[filepath stringByDeletingPathExtension] stringByAppendingPathExtension:@"plist"];
//NSLog(@"oos not found, looking for plist file: %@", filepath);
if ([[NSFileManager defaultManager] fileExistsAtPath:filepath])
{
NSDictionary* found_dic = [NSDictionary dictionaryWithContentsOfFile:filepath];
if (found_dic)
[results addObject:found_dic];
else
NSLog(@"ERROR ***** could not parse %@ as a NSDictionary.", filepath);
}
NSDictionary* found_dic = OODictionaryFromFile(filepath);
if (found_dic) [results addObject:found_dic];
}
}
}

View File

@ -36,7 +36,7 @@ MA 02110-1301, USA.
- (void) replaceString:(NSString*)aString withString:(NSString*)otherString
{
[self replaceOccurrencesOfString:aString withString:otherString options:nil range:NSMakeRange(0,[self length])];
[self replaceOccurrencesOfString:aString withString:otherString options:0 range:NSMakeRange(0,[self length])];
}
- (void) trimSpaces

View File

@ -28,9 +28,11 @@ MA 02110-1301, USA.
#import "OOStringParsing.h"
#import "Universe.h"
#import "PlayerEntityScripting.h"
#import "HeadUpDisplay.h"
#import "PlayerEntityScripting.h"
#import "PlanetEntity.h"
#import "AI.h"
#import "OOCharacter.h"

View File

@ -65,14 +65,14 @@ GLuint max_texture_dimension = 512; // conservative start
+ (GLuint) getTextureNameFor:(NSString *)filename
{
if ([textureUniversalDictionary objectForKey:filename])
return (GLuint)[(NSNumber *)[[textureUniversalDictionary objectForKey:filename] objectForKey:@"texName"] intValue];
return [[(NSDictionary *)[textureUniversalDictionary objectForKey:filename] objectForKey:@"texName"] intValue];
return [TextureStore getTextureNameFor: filename inFolder: @"Textures"];
}
+ (GLuint) getImageNameFor:(NSString *)filename
{
if ([textureUniversalDictionary objectForKey:filename])
return (GLuint)[(NSNumber *)[[textureUniversalDictionary objectForKey:filename] objectForKey:@"texName"] intValue];
return [[(NSDictionary *)[textureUniversalDictionary objectForKey:filename] objectForKey:@"texName"] intValue];
return [TextureStore getTextureNameFor: filename inFolder: @"Images"];
}
@ -367,8 +367,8 @@ GLuint max_texture_dimension = 512; // conservative start
NSSize size = NSMakeSize(0.0, 0.0); // zero size
if ([textureUniversalDictionary objectForKey:filename])
{
size.width = [[[textureUniversalDictionary objectForKey:filename] objectForKey:@"width"] intValue];
size.height = [[[textureUniversalDictionary objectForKey:filename] objectForKey:@"height"] intValue];
size.width = [[(NSDictionary *)[textureUniversalDictionary objectForKey:filename] objectForKey:@"width"] intValue];
size.height = [[(NSDictionary *)[textureUniversalDictionary objectForKey:filename] objectForKey:@"height"] intValue];
}
return size;
}
@ -538,7 +538,7 @@ GLuint max_texture_dimension = 512; // conservative start
NSArray *keys = [textureUniversalDictionary allKeys];
for (i = 0; i < [keys count]; i++)
{
GLuint texName = (GLuint)[(NSNumber *)[[textureUniversalDictionary objectForKey:[keys objectAtIndex:i]] objectForKey:@"texName"] intValue];
GLuint texName = [[(NSDictionary *)[textureUniversalDictionary objectForKey:[keys objectAtIndex:i]] objectForKey:@"texName"] intValue];
NSLog(@"deleting texture #%d (%@)", texName, (NSString *)[keys objectAtIndex:i]);
glDeleteTextures(1, &texName);
}

View File

@ -466,8 +466,6 @@ double estimatedTimeForJourney(double distance, int hops);
- (NSArray *) contractsForSystem:(Random_Seed) s_seed atTime:(double) current_time;
- (NSArray *) shipsForSaleForSystem:(Random_Seed) s_seed withTL:(int) specialTL atTime:(double) current_time;
NSComparisonResult compareName( id dict1, id dict2, void * context);
NSComparisonResult comparePrice( id dict1, id dict2, void * context);
- (int) tradeInValueForCommanderDictionary:(NSDictionary*) cmdr_dict;
- (int) weaponForEquipmentKey:(NSString*) weapon_string;
- (NSString*) equipmentKeyForWeapon:(int) weapon;
@ -525,3 +523,7 @@ NSComparisonResult comparePrice( id dict1, id dict2, void * context);
////
@end
NSComparisonResult compareName(NSDictionary *dict1, NSDictionary *dict2, void * context);
NSComparisonResult comparePrice(NSDictionary *dict1, NSDictionary *dict2, void * context);

View File

@ -7220,7 +7220,7 @@ double estimatedTimeForJourney(double distance, int hops)
i = 1;
while (i < [resultArray count])
{
if (compareName( [resultArray objectAtIndex:i - 1], [resultArray objectAtIndex:i], nil) == NSOrderedSame )
if (compareName([resultArray objectAtIndex:i - 1], [resultArray objectAtIndex:i], nil) == NSOrderedSame )
[resultArray removeObjectAtIndex: i];
else
i++;
@ -7231,18 +7231,26 @@ double estimatedTimeForJourney(double distance, int hops)
return [NSArray arrayWithArray:resultArray];
}
NSComparisonResult compareName( id dict1, id dict2, void * context)
{
NSComparisonResult result = [(NSString*)[(NSDictionary*)[dict1 objectForKey:SHIPYARD_KEY_SHIP] objectForKey:KEY_NAME] compare:(NSString*)[(NSDictionary*)[dict2 objectForKey:SHIPYARD_KEY_SHIP] objectForKey:KEY_NAME]];
NSComparisonResult compareName(NSDictionary *dict1, NSDictionary *dict2, void * context)
{
NSDictionary *ship1 = [dict1 objectForKey:SHIPYARD_KEY_SHIP];
NSDictionary *ship2 = [dict2 objectForKey:SHIPYARD_KEY_SHIP];
NSString *name1 = [ship1 objectForKey:KEY_NAME];
NSString *name2 = [ship2 objectForKey:KEY_NAME];
NSComparisonResult result = [name1 compare:name2];
if (result != NSOrderedSame)
return result;
else
return comparePrice(dict1, dict2, context);
}
NSComparisonResult comparePrice( id dict1, id dict2, void * context)
NSComparisonResult comparePrice(NSDictionary *dict1, NSDictionary *dict2, void * context)
{
return [(NSNumber*)[(NSDictionary*)dict1 objectForKey:SHIPYARD_KEY_PRICE] compare:(NSNumber*)[(NSDictionary*)dict2 objectForKey:SHIPYARD_KEY_PRICE]];
NSNumber *price1 = [dict1 objectForKey:SHIPYARD_KEY_PRICE];
NSNumber *price2 = [dict2 objectForKey:SHIPYARD_KEY_PRICE];
return [price1 compare:price2];
}
- (int) tradeInValueForCommanderDictionary:(NSDictionary*) cmdr_dict

View File

@ -32,6 +32,7 @@ MA 02110-1301, USA.
#import "NSFileManagerOOExtensions.h" // to find savedir
#import "PlayerEntity.h"
#import "GUIDisplayGen.h"
#import "PlanetEntity.h"
#ifdef WIN32
#import "TextureStore.h"