Added exception checks in OOLog(). Exceptions caught in [Universe update:] now report context at entity granularity.
git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@1500 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
parent
aa77a4fc6c
commit
b9d729fb01
@ -90,6 +90,7 @@ SOFTWARE.
|
||||
#define OOLOG_BAD_SETTING 1
|
||||
#define OOLOG_BAD_DEFAULT_SETTING 1
|
||||
#define OOLOG_BAD_POP_INDENT 1
|
||||
#define OOLOG_EXCEPTION_IN_LOG 1
|
||||
|
||||
|
||||
// Used to track OOLogPushIndent()/OOLogPopIndent() state.
|
||||
@ -433,81 +434,84 @@ void OOLogWithFunctionFileAndLineAndArguments(NSString *inMessageClass, const ch
|
||||
#endif
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
// Do argument substitution
|
||||
formattedMessage = [[[NSString alloc] initWithFormat:inFormat arguments:inArguments] autorelease];
|
||||
|
||||
// Apply various prefix options
|
||||
#ifndef OOLOG_NO_FILE_NAME
|
||||
if (sShowFileAndLine && inFile != NULL)
|
||||
{
|
||||
if (sShowFunction)
|
||||
NS_DURING
|
||||
// Do argument substitution
|
||||
formattedMessage = [[[NSString alloc] initWithFormat:inFormat arguments:inArguments] autorelease];
|
||||
|
||||
// Apply various prefix options
|
||||
#ifndef OOLOG_NO_FILE_NAME
|
||||
if (sShowFileAndLine && inFile != NULL)
|
||||
{
|
||||
formattedMessage = [NSString stringWithFormat:@"%s (%@:%u): %@", inFunction, AbbreviatedFileName(inFile), inLine, formattedMessage];
|
||||
if (sShowFunction)
|
||||
{
|
||||
formattedMessage = [NSString stringWithFormat:@"%s (%@:%u): %@", inFunction, AbbreviatedFileName(inFile), inLine, formattedMessage];
|
||||
}
|
||||
else
|
||||
{
|
||||
formattedMessage = [NSString stringWithFormat:@"%@:%u: %@", AbbreviatedFileName(inFile), inLine, formattedMessage];
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
formattedMessage = [NSString stringWithFormat:@"%@:%u: %@", AbbreviatedFileName(inFile), inLine, formattedMessage];
|
||||
if (sShowFunction)
|
||||
{
|
||||
formattedMessage = [NSString stringWithFormat:@"%s: %@", inFunction, formattedMessage];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
if (sShowFunction)
|
||||
{
|
||||
formattedMessage = [NSString stringWithFormat:@"%s: %@", inFunction, formattedMessage];
|
||||
}
|
||||
}
|
||||
|
||||
if (sShowClass)
|
||||
{
|
||||
if (sShowFunction || sShowFileAndLine)
|
||||
{
|
||||
formattedMessage = [NSString stringWithFormat:@"[%@] %@", inMessageClass, formattedMessage];
|
||||
}
|
||||
else
|
||||
{
|
||||
formattedMessage = [NSString stringWithFormat:@"[%@]: %@", inMessageClass, formattedMessage];
|
||||
}
|
||||
}
|
||||
|
||||
if (sShowApplication)
|
||||
{
|
||||
|
||||
if (sShowClass)
|
||||
{
|
||||
formattedMessage = [NSString stringWithFormat:@"%@ %@", APPNAME, formattedMessage];
|
||||
if (sShowFunction || sShowFileAndLine)
|
||||
{
|
||||
formattedMessage = [NSString stringWithFormat:@"[%@] %@", inMessageClass, formattedMessage];
|
||||
}
|
||||
else
|
||||
{
|
||||
formattedMessage = [NSString stringWithFormat:@"[%@]: %@", inMessageClass, formattedMessage];
|
||||
}
|
||||
}
|
||||
else if (sShowFunction || sShowFileAndLine)
|
||||
|
||||
if (sShowApplication)
|
||||
{
|
||||
formattedMessage = [NSString stringWithFormat:@"%@ - %@", APPNAME, formattedMessage];
|
||||
if (sShowClass)
|
||||
{
|
||||
formattedMessage = [NSString stringWithFormat:@"%@ %@", APPNAME, formattedMessage];
|
||||
}
|
||||
else if (sShowFunction || sShowFileAndLine)
|
||||
{
|
||||
formattedMessage = [NSString stringWithFormat:@"%@ - %@", APPNAME, formattedMessage];
|
||||
}
|
||||
else
|
||||
{
|
||||
formattedMessage = [NSString stringWithFormat:@"%@: %@", APPNAME, formattedMessage];
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
// Apply indentation
|
||||
indentLevel = GetIndentLevel();
|
||||
if (indentLevel != 0)
|
||||
{
|
||||
formattedMessage = [NSString stringWithFormat:@"%@: %@", APPNAME, formattedMessage];
|
||||
#define INDENT_FACTOR 2 /* Spaces per indent level */
|
||||
#define MAX_INDENT 64 /* Maximum number of indentation _spaces_ */
|
||||
|
||||
unsigned indent;
|
||||
// String of 64 spaces (null-terminated)
|
||||
const char spaces[MAX_INDENT + 1] =
|
||||
" ";
|
||||
const char *indentString;
|
||||
|
||||
indent = INDENT_FACTOR * indentLevel;
|
||||
if (MAX_INDENT < indent) indent = MAX_INDENT;
|
||||
indentString = &spaces[MAX_INDENT - indent];
|
||||
|
||||
formattedMessage = [NSString stringWithFormat:@"%s%@", indentString, formattedMessage];
|
||||
}
|
||||
}
|
||||
|
||||
// Apply indentation
|
||||
indentLevel = GetIndentLevel();
|
||||
if (indentLevel != 0)
|
||||
{
|
||||
#define INDENT_FACTOR 2 /* Spaces per indent level */
|
||||
#define MAX_INDENT 64 /* Maximum number of indentation _spaces_ */
|
||||
|
||||
unsigned indent;
|
||||
// String of 64 spaces (null-terminated)
|
||||
const char spaces[MAX_INDENT + 1] =
|
||||
" ";
|
||||
const char *indentString;
|
||||
|
||||
indent = INDENT_FACTOR * indentLevel;
|
||||
if (MAX_INDENT < indent) indent = MAX_INDENT;
|
||||
indentString = &spaces[MAX_INDENT - indent];
|
||||
|
||||
formattedMessage = [NSString stringWithFormat:@"%s%@", indentString, formattedMessage];
|
||||
}
|
||||
|
||||
OOLogOutputHandlerPrint(formattedMessage);
|
||||
OOLogOutputHandlerPrint(formattedMessage);
|
||||
NS_HANDLER
|
||||
OOLogInternal(OOLOG_EXCEPTION_IN_LOG, @"***** Exception thrown during logging: %@ : %@", [localException name], [localException reason]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
[pool release];
|
||||
}
|
||||
@ -679,14 +683,18 @@ static void OOLogInternal_(const char *inFunction, NSString *inFormat, ...)
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
va_start(args, inFormat);
|
||||
formattedMessage = [[[NSString alloc] initWithFormat:inFormat arguments:args] autorelease];
|
||||
va_end(args);
|
||||
|
||||
formattedMessage = [NSString stringWithFormat:@"OOLogging internal - %s: %@", inFunction, formattedMessage];
|
||||
if (sShowApplication) formattedMessage = [NSString stringWithFormat:@"%@: %@", APPNAME, formattedMessage];
|
||||
|
||||
OOLogOutputHandlerPrint(formattedMessage);
|
||||
NS_DURING
|
||||
va_start(args, inFormat);
|
||||
formattedMessage = [[[NSString alloc] initWithFormat:inFormat arguments:args] autorelease];
|
||||
va_end(args);
|
||||
|
||||
formattedMessage = [NSString stringWithFormat:@"OOLogging internal - %s: %@", inFunction, formattedMessage];
|
||||
if (sShowApplication) formattedMessage = [NSString stringWithFormat:@"%@: %@", APPNAME, formattedMessage];
|
||||
|
||||
OOLogOutputHandlerPrint(formattedMessage);
|
||||
NS_HANDLER
|
||||
fprintf(stderr, "***** Exception in OOLogInternal_(): %s : %s", [[localException name] UTF8String], [[localException reason] UTF8String]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
[pool release];
|
||||
}
|
||||
|
@ -5303,29 +5303,27 @@ OOINLINE BOOL EntityInRange(Vector p1, Entity *e2, float range)
|
||||
for (i = 0; i < ent_count; i++)
|
||||
{
|
||||
Entity *thing = my_entities[i];
|
||||
#ifndef NDEBUG
|
||||
update_stage = [NSString stringWithFormat:@"update:entity[%@]", [thing shortDescription]];
|
||||
#endif
|
||||
|
||||
[thing update:delta_t];
|
||||
|
||||
// maintain sorted lists
|
||||
|
||||
// maintain distance-from-player list
|
||||
double z_distance = thing->zero_distance;
|
||||
|
||||
// zero_index first..
|
||||
int index = thing->zero_index;
|
||||
while ((index > 0)&&(z_distance < sortedEntities[index - 1]->zero_distance))
|
||||
while (index > 0 && z_distance < sortedEntities[index - 1]->zero_distance)
|
||||
{
|
||||
sortedEntities[index] = sortedEntities[index - 1]; // bubble up the list, usually by just one position
|
||||
sortedEntities[index - 1 ] = thing;
|
||||
sortedEntities[index - 1] = thing;
|
||||
thing->zero_index = index - 1;
|
||||
sortedEntities[index]->zero_index = index;
|
||||
index--;
|
||||
}
|
||||
|
||||
// done maintaining sorted lists
|
||||
|
||||
// update deterministic AI
|
||||
|
||||
if (thing->isShip)
|
||||
if ([thing isShip])
|
||||
{
|
||||
AI* theShipsAI = [(ShipEntity *)thing getAI];
|
||||
if (theShipsAI)
|
||||
@ -5333,6 +5331,9 @@ OOINLINE BOOL EntityInRange(Vector p1, Entity *e2, float range)
|
||||
double thinkTime = [theShipsAI nextThinkTime];
|
||||
if ((universal_time > thinkTime)||(thinkTime == 0.0))
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
update_stage = [NSString stringWithFormat:@"update:think[%@]", [thing shortDescription]];
|
||||
#endif
|
||||
[theShipsAI setNextThinkTime:universal_time + [theShipsAI thinkTimeInterval]];
|
||||
[theShipsAI think];
|
||||
}
|
||||
@ -5340,10 +5341,12 @@ OOINLINE BOOL EntityInRange(Vector p1, Entity *e2, float range)
|
||||
}
|
||||
}
|
||||
|
||||
// Maintain x/y/z order lists
|
||||
update_stage = @"updating linked lists";
|
||||
for (i = 0; i < ent_count; i++)
|
||||
{
|
||||
[my_entities[i] updateLinkedLists];
|
||||
|
||||
}
|
||||
|
||||
// detect collisions and light ships that can see the sun
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user