Various twiddles while failing to fix corona bug: gDebugFlags now exposed through JS console (as console.debugFlags), added warning message for shipyard entries with no matching shipdata entry (but suppressed by default for compatibility with Realistic Shipyards), log on PPC Macs no longer reports incorrect Altivec availability information (we don't use Altivec anyway), removed unused shipdata ivar from Universe.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@1621 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2008-05-08 19:48:22 +00:00
parent 1a04936501
commit d7badeebd4
9 changed files with 93 additions and 282 deletions

View File

@ -1020,7 +1020,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>"; };
1A020E0A0D020AFB00C3F51E /* changedScriptHandlers.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = changedScriptHandlers.plist; sourceTree = "<group>"; };
@ -1688,7 +1688,7 @@
19C28FACFE9D520D11CA2CBB /* Products */ = {
isa = PBXGroup;
children = (
0865432206B8447D000CA0AB /* Oolite.app */,
0865432206B8447D000CA0AB /* OoliteDev.app */,
1A71E6F30BCE340C00CD5C13 /* libpng.a */,
);
name = Products;
@ -2912,7 +2912,7 @@
name = Oolite;
productInstallPath = "$(HOME)/Applications";
productName = Oolite;
productReference = 0865432206B8447D000CA0AB /* Oolite.app */;
productReference = 0865432206B8447D000CA0AB /* OoliteDev.app */;
productType = "com.apple.product-type.application";
};
1A71E6F20BCE340C00CD5C13 /* libpng-custom */ = {

View File

@ -294,6 +294,8 @@
ship.noPrimaryRole = no;
ship.escort.reject = no;
shipData.load.shipyard.unknown = no; // Warning for when shipyard.plist entries do not have matching shipdata.plist entry, disabled by default for Realistic Shipyards OXP.
sky.setup = no;

View File

@ -51,6 +51,8 @@ static JSObject *sConsolePrototype = NULL;
static JSObject *sConsoleSettingsPrototype = NULL;
static JSBool ConsoleGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
static JSBool ConsoleSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value);
static void ConsoleFinalize(JSContext *context, JSObject *this);
// Methods
@ -71,8 +73,8 @@ static JSClass sConsoleClass =
JS_PropertyStub, // addProperty
JS_PropertyStub, // delProperty
JS_PropertyStub, // getProperty
JS_PropertyStub, // setProperty
ConsoleGetProperty, // getProperty
ConsoleSetProperty, // setProperty
JS_EnumerateStub, // enumerate
JS_ResolveStub, // resolve
JS_ConvertStub, // convert
@ -81,6 +83,21 @@ static JSClass sConsoleClass =
};
enum
{
// Property IDs
kConsole_debugFlags // debug flags, integer, read/write
};
static JSPropertySpec sConsoleProperties[] =
{
// JS name ID flags
{ "debugFlags", kConsole_debugFlags, JSPROP_PERMANENT | JSPROP_ENUMERATE },
{ 0 }
};
static JSFunctionSpec sConsoleMethods[] =
{
// JS name Function min args
@ -111,7 +128,7 @@ static JSClass sConsoleSettingsClass =
static void InitOOJSConsole(JSContext *context, JSObject *global)
{
sConsolePrototype = JS_InitClass(context, global, NULL, &sConsoleClass, NULL, 0, NULL, sConsoleMethods, NULL, NULL);
sConsolePrototype = JS_InitClass(context, global, NULL, &sConsoleClass, NULL, 0, sConsoleProperties, sConsoleMethods, NULL, NULL);
JSRegisterObjectConverter(&sConsoleClass, JSBasicPrivateObjectConverter);
sConsoleSettingsPrototype = JS_InitClass(context, global, NULL, &sConsoleSettingsClass, NULL, 0, NULL, NULL, NULL, NULL);
@ -164,6 +181,49 @@ JSObject *DebugMonitorToJSConsole(JSContext *context, OODebugMonitor *monitor)
}
static JSBool ConsoleGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue)
{
if (!JSVAL_IS_INT(name)) return YES;
switch (JSVAL_TO_INT(name))
{
case kConsole_debugFlags:
*outValue = INT_TO_JSVAL(gDebugFlags);
break;
default:
OOReportJavaScriptBadPropertySelector(context, @"Console", JSVAL_TO_INT(name));
return NO;
}
return YES;
}
static JSBool ConsoleSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value)
{
int32 iValue;
if (!JSVAL_IS_INT(name)) return YES;
switch (JSVAL_TO_INT(name))
{
case kConsole_debugFlags:
if (JS_ValueToInt32(context, *value, &iValue))
{
gDebugFlags = iValue;
}
break;
default:
OOReportJavaScriptBadPropertySelector(context, @"Console", JSVAL_TO_INT(name));
return NO;
}
return YES;
}
static void ConsoleFinalize(JSContext *context, JSObject *this)
{
[(id)JS_GetPrivate(context, this) release];

View File

@ -1530,7 +1530,7 @@ static GLfloat texture_uv_array[10400 * 2];
void drawActiveCorona(GLfloat inner_radius, GLfloat outer_radius, GLfloat step, GLfloat z_distance, GLfloat *col4v1, int rv)
{
if (inner_radius >= z_distance) return; // inside the sphere
if (EXPECT_NOT(inner_radius >= z_distance)) return; // inside the sphere
NSRange activity = { 0.34, 1.0 };

View File

@ -86,10 +86,7 @@ void OOCPUInfoInit(void)
}
#endif
/* Count processors - only implemented for OS X and Windows at the moment.
sysconf(_SC_NPROCESSORS_ONLN) may be appropriate for some Unices, but
_SC_NPROCESSORS_ONLN is not defined on OS X.
*/
// Count processors
#if OOLITE_MAC_OS_X
int flag = 0;
size_t size = sizeof flag;
@ -106,10 +103,10 @@ void OOCPUInfoInit(void)
GetSystemInfo(&sysInfo);
sNumberOfCPUs = sysInfo.dwNumberOfProcessors;
#elif OOLITE_LINUX
#ifdef _SC_NPROCESSORS_ONLN
sNumberOfCPUs = sysconf(_SC_NPROCESSORS_ONLN);
#endif
#elif defined _SC_NPROCESSORS_ONLN
sNumberOfCPUs = sysconf(_SC_NPROCESSORS_ONLN);
#else
#warning Do not know how to find number of CPUs on this architecture.
#endif
// Check for AltiVec if relelevant

View File

@ -111,17 +111,6 @@ void OOPrintLogHeader(void)
[miscString appendString:AdditionalLogHeaderInfo()];
#if OOLITE_ALTIVEC
if (OOAltiVecAvailable())
{
[miscString appendString:@" Altivec acceleration available."];
}
else
{
[miscString appendString:@" Altivec acceleration not available."];
}
#endif
[miscString appendString:@"\nNote that the contents of the log file can be adjusted by editing logcontrol.plist."];
OOLog(@"log.header", @"%@\n", miscString);

View File

@ -522,7 +522,10 @@ static NSString * const kDefaultDemoShip = @"coriolis-station";
[playerShips addObject:key];
}
// Else we have a shipyard entry with no matching shipdata entry, which we ignore.
else
{
OOLog(@"shipData.load.shipyard.unknown", @"WARNING: the shipyard.plist entry \"%@\" does not have a corresponding shipdata.plist entry, ignoring.", key);
}
}
_playerShips = [playerShips copy];

View File

@ -193,7 +193,6 @@ enum
BOOL dumpCollisionInfo;
NSDictionary *shipdata; // holds data on all ships available, loaded at initialisation
NSDictionary *shipyard; // holds data on all ships for sale, loaded at initialisation
NSDictionary *commoditylists; // holds data on commodities for various types of station, loaded at initialisation

View File

@ -99,7 +99,6 @@ static NSComparisonResult comparePrice(NSDictionary *dict1, NSDictionary *dict2,
#if SUPPORT_GRAPHVIZ_OUT
- (void) dumpDebugGraphViz;
- (void) dumpShipHierarchyGraphViz;
- (void) dumpSystemDescriptionGraphViz;
#endif
@ -213,8 +212,6 @@ static NSComparisonResult comparePrice(NSDictionary *dict1, NSDictionary *dict2,
time_delta = 0.0;
universal_time = 0.0;
shipdata = [[ResourceManager dictionaryFromFilesNamed:@"shipdata.plist" inFolder:@"Config" andMerge:YES] retain];
shipyard = [[ResourceManager dictionaryFromFilesNamed:@"shipyard.plist" inFolder:@"Config" andMerge:YES] retain];
commoditylists = [(NSDictionary *)[ResourceManager dictionaryFromFilesNamed:@"commodities.plist" inFolder:@"Config" andMerge:YES] retain];
@ -315,7 +312,6 @@ static NSComparisonResult comparePrice(NSDictionary *dict1, NSDictionary *dict2,
[comm_log_gui release];
[entities release];
[shipdata release];
[shipyard release];
[commoditylists release];
@ -459,9 +455,6 @@ static NSComparisonResult comparePrice(NSDictionary *dict1, NSDictionary *dict2,
time_delta = 0.0;
universal_time = 0.0;
[shipdata autorelease];
shipdata = [[ResourceManager dictionaryFromFilesNamed:@"shipdata.plist" inFolder:@"Config" andMerge:YES] retain];
[shipyard autorelease];
shipyard = [[ResourceManager dictionaryFromFilesNamed:@"shipyard.plist" inFolder:@"Config" andMerge:YES] retain];
@ -772,7 +765,7 @@ static NSComparisonResult comparePrice(NSDictionary *dict1, NSDictionary *dict2,
[thing setScanClass: CLASS_NO_DRAW];
quaternion_set_random(&randomQ);
[thing setOrientation:randomQ];
[self addEntity:thing]; // [entities addObject:thing];
[self addEntity:thing];
[thing release];
/*--*/
@ -888,7 +881,7 @@ static NSComparisonResult comparePrice(NSDictionary *dict1, NSDictionary *dict2,
thing = [[SkyEntity alloc] initWithColors:col1:col2 andSystemInfo: systeminfo]; // alloc retains!
[thing setScanClass: CLASS_NO_DRAW];
[self addEntity:thing]; // [entities addObject:thing];
[self addEntity:thing];
bgcolor = [(SkyEntity *)thing skyColor];
pale_bgcolor = [bgcolor blendedColorWithFraction:0.5 ofColor:[OOColor whiteColor]];
[thing release];
@ -940,8 +933,9 @@ static NSComparisonResult comparePrice(NSDictionary *dict1, NSDictionary *dict2,
// here we need to check if the sun collides with (or is too close to) the witchpoint
// otherwise at (for example) Maregais in Galaxy 1 we go BANG!
do {
sunPos = a_planet->position;
do
{
sunPos = [a_planet position];
quaternion_set_random(&q_sun);
// set up planet's direction in space so it gets a proper day
@ -974,7 +968,7 @@ static NSComparisonResult comparePrice(NSDictionary *dict1, NSDictionary *dict2,
}
/*- space station -*/
stationPos = a_planet->position;
stationPos = [a_planet position];
double station_orbit = 2.0 * planet_radius;
Quaternion q_station;
vf.z = -1;
@ -2825,114 +2819,6 @@ static BOOL IsCandidateMainStationPredicate(Entity *entity, void *parameter)
}
#if OBSOLETE
- (ShipEntity *) newShipWithRole:(NSString *) desc
{
unsigned i, found = 0;
ShipEntity *ship = nil;
NSString *search = nil;
NSAutoreleasePool *pool = nil;
NSEnumerator *shipEnum = nil;
NSString *shipKey = nil;
NSMutableArray *foundShips = nil;
NSMutableArray *foundChance = nil;
float foundf = 0.0, chance, selectedf;
NSDictionary *shipDict = nil;
NSString *autoAI = nil;
NSDictionary *autoAIMap = nil;
OORoleSet *roles = nil;
pool = [[NSAutoreleasePool alloc] init];
search = [ScanTokensFromString(desc) componentsJoinedByString:@"_"];
foundShips = [NSMutableArray array];
foundChance = [NSMutableArray array];
for (shipEnum = [shipdata keyEnumerator]; (shipKey = [shipEnum nextObject]); )
{
shipDict = [shipdata dictionaryForKey:shipKey];
roles = [OORoleSet roleSetWithString:[shipDict stringForKey:@"roles"]];
chance = [roles probabilityForRole:search];
if (0.0f < chance && [shipDict arrayForKey:@"conditions"])
{
PlayerEntity* player = [PlayerEntity sharedPlayer];
if ((player) && (player->isPlayer) && (![player checkCouplet:shipDict onEntity:player]))
{
chance = 0.0f;
}
}
if (0.0f < chance)
{
[foundShips addObject:shipKey];
[foundChance addObject:[NSNumber numberWithFloat:chance]];
found++;
foundf += chance;
}
}
i = 0;
if (found > 1)
{
selectedf = randf() * foundf;
while (selectedf > [foundChance floatAtIndex:i])
{
selectedf -= [foundChance floatAtIndex:i];
i++;
}
if (i >= found) // sanity check
i = 0;
}
if (found)
{
shipKey = [foundShips stringAtIndex:i];
ship = [self newShipWithName:shipKey]; // may return nil if not found!
[ship setPrimaryRole:search];
shipDict = [shipdata dictionaryForKey:shipKey];
if ([shipDict fuzzyBooleanForKey:@"auto_ai" defaultValue:YES])
{
// Set AI based on role
autoAIMap = [ResourceManager dictionaryFromFilesNamed:@"autoAImap.plist" inFolder:@"Config" andMerge:YES];
autoAI = [autoAIMap stringForKey:search];
if (autoAI != nil)
{
[ship setAITo:autoAI];
}
}
}
else
{
/* Note: this is a common "error", since the game will look for
special containers by looking up a ship using the commodity name
as a ship role.
*/
#ifndef NDEBUG
if (gDebugFlags & DEBUG_MISC)
{
OOLog(@"universe.newShip.unknownRole", @"DEBUG [Universe newShipWithRole: %@] couldn't find a ship!", search);
}
#endif
}
[pool release]; // tidy everything up
// check a trader has fuel
if ([ship fuel] == 0 && [[ship primaryRole] isEqual:@"trader"])
{
[ship setFuel: PLAYER_MAX_FUEL];
}
return ship;
}
#else
#define PROFILE_SHIP_SELECTION 1
@ -2974,7 +2860,10 @@ static BOOL IsCandidateMainStationPredicate(Entity *entity, void *parameter)
#if PROFILE_SHIP_SELECTION
++profSlowPath;
OOLog(@"shipRegistry.selection.profile", @"Hit slow path in ship selection for role \"%@\", having selected ship \"%@\". Now %lu of %lu on slow path (%f%%).", role, shipKey, profSlowPath, profTotal, ((double)profSlowPath)/((double)profTotal) * 100.0f);
if ((profSlowPath % 10) == 0) // Only print every tenth slow path, to reduce spamminess.
{
OOLog(@"shipRegistry.selection.profile", @"Hit slow path in ship selection for role \"%@\", having selected ship \"%@\". Now %lu of %lu on slow path (%f%%).", role, shipKey, profSlowPath, profTotal, ((double)profSlowPath)/((double)profTotal) * 100.0f);
}
#endif
pset = [[[registry probabilitySetForRole:role] mutableCopy] autorelease];
@ -3025,8 +2914,6 @@ static BOOL IsCandidateMainStationPredicate(Entity *entity, void *parameter)
return ship;
}
#endif
- (ShipEntity *) newShipWithName:(NSString *)shipKey
{
@ -3570,17 +3457,17 @@ static const OOMatrix starboard_matrix =
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE); // face culling
glDepthMask(GL_TRUE); // restore write to depth buffer
if (!displayGUI)
glClearColor(skyClearColor[0], skyClearColor[1], skyClearColor[2], skyClearColor[3]);
else
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity(); // reset matrix
gluLookAt(0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0);
// HACK BUSTED
glScalef(-1.0, 1.0, 1.0); // flip left and right
glPushMatrix(); // save this flat viewpoint
@ -3590,7 +3477,7 @@ static const OOMatrix starboard_matrix =
flipMatrix.m[2][2] = -1;
view_matrix = OOMatrixMultiply(view_matrix, flipMatrix);
Vector viewOffset = [player viewpointOffset];
gluLookAt(view_dir.x, view_dir.y, view_dir.z, 0.0, 0.0, 0.0, view_up.x, view_up.y, view_up.z);
if (!displayGUI || inGUIMode)
@ -3642,7 +3529,6 @@ static const OOMatrix starboard_matrix =
BOOL bpHide = [self breakPatternHide];
// DRAW ALL THE OPAQUE ENTITIES
for (i = furthest; i >= nearest; i--)
{
int d_status;
@ -8136,79 +8022,6 @@ static NSComparisonResult comparePrice(NSDictionary *dict1, NSDictionary *dict2,
}
#if OBSOLETE
- (NSDictionary *)getDictionaryForShip:(NSString *)desc recursionLimit:(uint32_t)recursionLimit
{
static NSDictionary *cachedResult = nil;
static NSString *cachedKey = nil;
if (desc == nil) return nil;
if ([desc isEqualToString:cachedKey]) return [[cachedResult retain] autorelease];
NSMutableDictionary *shipdict = [[[shipdata dictionaryForKey:desc] mutableCopy] autorelease];
if (shipdict == nil)
{
/* There used to be an attempt to throw a OOLITE_EXCEPTION_SHIP_NOT_FOUND
exception here. However, it never worked -- the line above was
broken so an empty dictionary was created instead, which was
rather pointless. Once this was fixed, it turned out there are OXPs
causing bad ships to be created, which wasn't noticed because the
exception wasn't handled.
-- Ahruman
*/
OOLog(@"universe.getShip.unknown", @"Attempt to create ship of type \"%@\", but no such type could be found.", desc);
return nil;
}
// check if this is based upon a different ship
/* TODO: move all like_ship handling into one place. (Actually, it may be
that this already _is_ that place and all others are redundant.) Should
probably fold resolved like_ships back into dictionary. -- Ahruman
*/
while ([shipdict stringForKey:@"like_ship"])
{
NSString* other_shipdesc = [shipdict stringForKey:@"like_ship"];
NSDictionary* other_shipdict = nil;
if (recursionLimit == 0)
{
OOLog(@"universe.getShip.badReference", @"Failed to construct ship dictionary for \"%@\" -- hit safety limit for like_ship redirections.", desc);
return nil;
}
if (other_shipdesc != nil)
{
other_shipdict = [self getDictionaryForShip:other_shipdesc recursionLimit:recursionLimit - 1];
}
if (other_shipdict != nil)
{
[shipdict removeObjectForKey:@"like_ship"]; // so it may inherit a new one from the like_ship
NSMutableDictionary* this_shipdict = [NSMutableDictionary dictionaryWithDictionary:other_shipdict]; // basics from that one
// If the like_ship (source) has a display_name assigned, this must be removed on our ship. We will use own ship's display name.
if ([this_shipdict objectForKey:@"display_name"] && [shipdict objectForKey:@"name"] != nil)
{
[this_shipdict removeObjectForKey:@"display_name"];
}
[this_shipdict addEntriesFromDictionary:shipdict]; // overrides from this one
shipdict = [NSMutableDictionary dictionaryWithDictionary:this_shipdict]; // synthesis'
}
else
{
OOLog(@"universe.getShip.badReference", @"Failed to construct ship dictionary for \"%@\" -- like_ship reference to unknown ship type \"%@\".", desc, other_shipdesc);
return nil;
}
}
[cachedResult release];
cachedResult = [shipdict copy];
[cachedKey release];
cachedKey = [desc copy];
return shipdict;
}
#endif
- (void) preloadSounds
{
NSEnumerator *soundEnum = nil;
@ -8230,63 +8043,11 @@ static NSComparisonResult comparePrice(NSDictionary *dict1, NSDictionary *dict2,
{
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"universe-dump-debug-graphviz"])
{
[self dumpShipHierarchyGraphViz];
[self dumpSystemDescriptionGraphViz];
}
}
- (void) dumpShipHierarchyGraphViz
{
NSMutableString *graphViz = nil;
NSEnumerator *shipEnum = nil;
NSString *shipKey = nil;
NSString *likeKey = nil;
NSDictionary *shipDef = nil;
NSString *label = nil;
graphViz = [NSMutableString stringWithString:
@"// Shipdata like_ship dependencies:\n\n"
"digraph like_ships\n"
"{\n"
"\tgraph [charset=\"UTF-8\", label=\"Shipdata like_ships\", labelloc=t, labeljust=l rankdir=LR]\n"
"\tedge [arrowhead=none sametail=1]\n"
"\tnode [shape=box]\n\t\n"];
// First, define nodes.
for (shipEnum = [shipdata keyEnumerator]; (shipKey = [shipEnum nextObject]); )
{
shipDef = [shipdata objectForKey:shipKey];
// Define node
label = [shipDef stringForKey:@"name"];
if (label == nil) label = shipKey;
else label = [NSString stringWithFormat:@"%@\n%@", shipKey, label];
[graphViz appendFormat:@"\t\"%@\" [label=\"%@\"]\n", EscapedGraphVizString(shipKey), EscapedGraphVizString(label)];
}
// Any new nodes beyond this point are dangling references, so colour them red.
[graphViz appendString:@"\t\n\t// Implicit nodes beyond this point are undefined ships.\n\tnode [style=filled fillcolor=red]\n\t\n"];
for (shipEnum = [shipdata keyEnumerator]; (shipKey = [shipEnum nextObject]); )
{
shipDef = [shipdata objectForKey:shipKey];
// Define edge
likeKey = [shipDef stringForKey:@"like_ship"];
if (likeKey != nil)
{
[graphViz appendFormat:@"\t\"%@\" -> \"%@\"\n", EscapedGraphVizString(likeKey), EscapedGraphVizString(shipKey)];
}
}
// Write file
[graphViz appendString:@"}\n"];
[ResourceManager writeDiagnosticData:[graphViz dataUsingEncoding:NSUTF8StringEncoding] toFileNamed:@"LikeShips.dot"];
}
- (void) addNumericRefsInString:(NSString *)string toGraphViz:(NSMutableString *)graphViz fromNode:(NSString *)fromNode nodeCount:(unsigned)nodeCount
{
NSString *index = nil;