Added script events for planet and station proximity events. Fast PowerPC square root approximation is now actually used. Redefined nil and Nil to be type-pedantic under Cocoa (as they are under GNUstep). Waved a rubber chicken to appease the compiler.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@1401 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2008-02-22 11:56:23 +00:00
parent c5b9b92365
commit 4b3a74e847
12 changed files with 119 additions and 58 deletions

View File

@ -237,6 +237,7 @@
1A2319B80B9D031D00EF0852 /* warning.ogg in Copy Sounds */ = {isa = PBXBuildFile; fileRef = 1A2319A40B9D031D00EF0852 /* warning.ogg */; }; 1A2319B80B9D031D00EF0852 /* warning.ogg in Copy Sounds */ = {isa = PBXBuildFile; fileRef = 1A2319A40B9D031D00EF0852 /* warning.ogg */; };
1A2319B90B9D031D00EF0852 /* witchabort.ogg in Copy Sounds */ = {isa = PBXBuildFile; fileRef = 1A2319A50B9D031D00EF0852 /* witchabort.ogg */; }; 1A2319B90B9D031D00EF0852 /* witchabort.ogg in Copy Sounds */ = {isa = PBXBuildFile; fileRef = 1A2319A50B9D031D00EF0852 /* witchabort.ogg */; };
1A231A180B9D8B1B00EF0852 /* OOCacheManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A231A160B9D8B1B00EF0852 /* OOCacheManager.h */; }; 1A231A180B9D8B1B00EF0852 /* OOCacheManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A231A160B9D8B1B00EF0852 /* OOCacheManager.h */; };
1A2324FC0D6ED7C2003578B6 /* OOJSClock.h in Copy Debug OXP */ = {isa = PBXBuildFile; fileRef = 1A6B25EC0C9C2745000717CF /* OOJSClock.h */; };
1A26D0AC0BCF9CF80073F257 /* PlayerEntityLegacyScriptEngine.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A26D0880BCF9CF70073F257 /* PlayerEntityLegacyScriptEngine.m */; }; 1A26D0AC0BCF9CF80073F257 /* PlayerEntityLegacyScriptEngine.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A26D0880BCF9CF70073F257 /* PlayerEntityLegacyScriptEngine.m */; };
1A26D0AD0BCF9CF80073F257 /* ShipEntityAI.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A26D0890BCF9CF70073F257 /* ShipEntityAI.m */; }; 1A26D0AD0BCF9CF80073F257 /* ShipEntityAI.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A26D0890BCF9CF70073F257 /* ShipEntityAI.m */; };
1A26D0AE0BCF9CF80073F257 /* ShipEntityAI.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A26D08A0BCF9CF70073F257 /* ShipEntityAI.h */; }; 1A26D0AE0BCF9CF80073F257 /* ShipEntityAI.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A26D08A0BCF9CF70073F257 /* ShipEntityAI.h */; };
@ -975,6 +976,7 @@
dstSubfolderSpec = 16; dstSubfolderSpec = 16;
files = ( files = (
1AD267650C83058C00B4BFD1 /* Debug.oxp in Copy Debug OXP */, 1AD267650C83058C00B4BFD1 /* Debug.oxp in Copy Debug OXP */,
1A2324FC0D6ED7C2003578B6 /* OOJSClock.h in Copy Debug OXP */,
); );
name = "Copy Debug OXP"; name = "Copy Debug OXP";
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;

View File

@ -326,16 +326,16 @@ static NSString * kOOLogKeyDown = @"input.keyMapping.keyPress.keyDown";
NSBitmapImageRep* bitmapRep = NSBitmapImageRep* bitmapRep =
[[NSBitmapImageRep alloc] [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes: nil // --> let the class allocate it initWithBitmapDataPlanes:NULL // --> let the class allocate it
pixelsWide: w pixelsWide: w
pixelsHigh: h pixelsHigh: h
bitsPerSample: 8 // each component is 8 bits (1 byte) bitsPerSample: 8 // each component is 8 bits (1 byte)
samplesPerPixel: 3 // number of components (R, G, B) samplesPerPixel: 3 // number of components (R, G, B)
hasAlpha: NO // no transparency hasAlpha: NO // no transparency
isPlanar: NO // data integrated into single plane isPlanar: NO // data integrated into single plane
colorSpaceName: NSDeviceRGBColorSpace colorSpaceName: NSDeviceRGBColorSpace
bytesPerRow: 3*w // can no longer let the class figure it out bytesPerRow: 3*w // can no longer let the class figure it out
bitsPerPixel: 24 // can no longer let the class figure it out bitsPerPixel: 24 // can no longer let the class figure it out
]; ];
unsigned char *pixels = [bitmapRep bitmapData]; unsigned char *pixels = [bitmapRep bitmapData];

View File

@ -186,7 +186,7 @@ enum
if (OK) if (OK)
{ {
context = calloc(1, sizeof *context); context = calloc(1, sizeof *context);
if (nil != context) if (context != NULL)
{ {
*outContext = (OOCASoundRenderContext)context; *outContext = (OOCASoundRenderContext)context;
context->loop = inLoop; context->loop = inLoop;

View File

@ -127,7 +127,7 @@ static NSString *GetAppName(void);
static BOOL sInited = NO; static BOOL sInited = NO;
static BOOL sWriteToStderr = YES; static BOOL sWriteToStderr = YES;
static OOAsyncLogger *sLogger = nil; static OOAsyncLogger *sLogger = nil;
static LogCStringFunctionProc sDefaultLogCStringFunction = nil; static LogCStringFunctionProc sDefaultLogCStringFunction = NULL;
static NSString *sLogFileName = @"Latest.log"; static NSString *sLogFileName = @"Latest.log";
@ -462,7 +462,7 @@ enum
*/ */
static void LoadLogCStringFunctions(void) static void LoadLogCStringFunctions(void)
{ {
CFBundleRef foundationBundle = nil; CFBundleRef foundationBundle = NULL;
LogCStringFunctionGetterProc getter = NULL; LogCStringFunctionGetterProc getter = NULL;
LogCStringFunctionSetterProc setter = NULL; LogCStringFunctionSetterProc setter = NULL;

View File

@ -1006,21 +1006,21 @@ static GLfloat texture_uv_array[10400 * 2];
- (NSString*) descriptionComponents - (NSString*) descriptionComponents
{ {
NSString* type_string; NSString *typeString;
switch (planet_type) switch (planet_type)
{ {
case PLANET_TYPE_MINIATURE: case PLANET_TYPE_MINIATURE:
type_string = @"PLANET_TYPE_MINIATURE"; break; typeString = @"PLANET_TYPE_MINIATURE"; break;
case PLANET_TYPE_SUN: case PLANET_TYPE_SUN:
type_string = @"PLANET_TYPE_SUN"; break; typeString = @"PLANET_TYPE_SUN"; break;
case PLANET_TYPE_GREEN: case PLANET_TYPE_GREEN:
type_string = @"PLANET_TYPE_GREEN"; break; typeString = @"PLANET_TYPE_GREEN"; break;
case PLANET_TYPE_ATMOSPHERE: case PLANET_TYPE_ATMOSPHERE:
type_string = @"PLANET_TYPE_ATMOSPHERE"; break; typeString = @"PLANET_TYPE_ATMOSPHERE"; break;
default : default :
type_string = @"UNKNOWN"; typeString = @"UNKNOWN";
} }
return [NSString stringWithFormat:@"%@ type: %@ radius: %.3fkm", [super descriptionComponents], type_string, 0.001 * [self radius]]; return [NSString stringWithFormat:@"ID: %u position: %@ %@ type: %@ radius: %.3fkm", [self universalID], VectorDescription([self position]), typeString, 0.001 * [self radius]];
} }

View File

@ -2589,6 +2589,7 @@ static BOOL toggling_music;
station = dockedStation; // leaveDock will clear dockedStation. station = dockedStation; // leaveDock will clear dockedStation.
[self leaveDock:dockedStation]; [self leaveDock:dockedStation];
[UNIVERSE setDisplayCursor:NO]; [UNIVERSE setDisplayCursor:NO];
suppressAegisMessages = YES;
if ([self checkForAegis] != AEGIS_NONE) if ([self checkForAegis] != AEGIS_NONE)
{ {
[self setCompassMode:COMPASS_MODE_STATION]; [self setCompassMode:COMPASS_MODE_STATION];
@ -2597,6 +2598,7 @@ static BOOL toggling_music;
{ {
[self setCompassMode:COMPASS_MODE_PLANET]; [self setCompassMode:COMPASS_MODE_PLANET];
} }
suppressAegisMessages = NO;
[self doScriptEvent:@"shipWillLaunchFromStation" withArgument:station]; [self doScriptEvent:@"shipWillLaunchFromStation" withArgument:station];
[self playBreakPattern]; [self playBreakPattern];
} }

View File

@ -157,12 +157,12 @@ MA 02110-1301, USA.
is_hulk: 1, // This is used to distinguish abandoned ships from cargo is_hulk: 1, // This is used to distinguish abandoned ships from cargo
trackCloseContacts: 1, trackCloseContacts: 1,
// check for landing on planet isNearPlanetSurface: 1, // check for landing on planet
isNearPlanetSurface: 1,
isFrangible: 1, // frangible => subentities can be damaged individually isFrangible: 1, // frangible => subentities can be damaged individually
cloaking_device_active: 1, // cloaking_device cloaking_device_active: 1, // cloaking_device
canFragment: 1, // Can it break into wreckage? canFragment: 1, // Can it break into wreckage?
suppressExplosion: 1, // Avoid exploding on death (script hook) suppressExplosion: 1, // Avoid exploding on death (script hook)
suppressAegisMessages: 1, // No script/AI messages sent by -checkForAegis
// scripting // scripting
haveExecutedSpawnAction: 1, haveExecutedSpawnAction: 1,

View File

@ -1043,10 +1043,7 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
- (Triangle) absoluteIJKForSubentity - (Triangle) absoluteIJKForSubentity
{ {
Triangle result; Triangle result = {{ kBasisXVector, kBasisYVector, kBasisZVector, kZeroVector }};
result.v[0] = kBasisXVector;
result.v[1] = kBasisYVector;
result.v[2] = kBasisZVector;
Entity *last = nil; Entity *last = nil;
Entity *father = self; Entity *father = self;
OOMatrix r_mat; OOMatrix r_mat;
@ -3094,6 +3091,22 @@ static GLfloat mascem_color2[4] = { 0.4, 0.1, 0.4, 1.0}; // purple
} }
- (void) transitionToAegisNone
{
if (!suppressAegisMessages && aegis_status != AEGIS_NONE)
{
if (aegis_status == AEGIS_IN_DOCKING_RANGE)
{
[self doScriptEvent:@"shipExitedStationAegis"];
[shipAI message:@"AEGIS_LEAVING_DOCKING_RANGE"];
}
[self doScriptEvent:@"shipExitedPlanetaryVicinity"];
[shipAI message:@"AEGIS_NONE"];
}
aegis_status = AEGIS_NONE;
}
- (OOAegisStatus) checkForAegis - (OOAegisStatus) checkForAegis
{ {
PlanetEntity* the_planet = [UNIVERSE planet]; PlanetEntity* the_planet = [UNIVERSE planet];
@ -3101,57 +3114,89 @@ static GLfloat mascem_color2[4] = { 0.4, 0.1, 0.4, 1.0}; // purple
if (!the_planet) if (!the_planet)
{ {
if (aegis_status != AEGIS_NONE) if (aegis_status != AEGIS_NONE)
[shipAI message:@"AEGIS_NONE"]; {
// Planet disappeared!
[self transitionToAegisNone];
}
return AEGIS_NONE; return AEGIS_NONE;
} }
// check planet // check planet
Vector p1 = the_planet->position; float cr = [the_planet collisionRadius];
double cr = the_planet->collision_radius; float cr2 = cr * cr;
double cr2 = cr * cr; OOAegisStatus result = AEGIS_NONE;
OOAegisStatus result = AEGIS_NONE; float d2;
p1.x -= position.x; p1.y -= position.y; p1.z -= position.z;
double d2 = p1.x*p1.x + p1.y*p1.y + p1.z*p1.z; d2 = magnitude2(vector_subtract([the_planet position], [self position]));
// check if nearing surface // check if nearing surface
// FIXME: need script and probably AI notification for all planets, not just main.
BOOL wasNearPlanetSurface = isNearPlanetSurface; BOOL wasNearPlanetSurface = isNearPlanetSurface;
isNearPlanetSurface = (d2 - cr2 < 250000+1000*cr); //less than 500m from the surface: (a+b)*(a+b) = a*a+b*b +2*a*b isNearPlanetSurface = (d2 - cr2 < 250000+1000*cr); //less than 500m from the surface: (a+b)*(a+b) = a*a+b*b +2*a*b
if ((!wasNearPlanetSurface)&&(isNearPlanetSurface)) if (!suppressAegisMessages)
[shipAI reactToMessage:@"APPROACHING_SURFACE"]; {
if ((wasNearPlanetSurface)&&(!isNearPlanetSurface)) if (!wasNearPlanetSurface && isNearPlanetSurface)
[shipAI reactToMessage:@"LEAVING_SURFACE"]; {
// [self doScriptEvent:@"shipApproachingPlanetSurface" withArgument:the_planet];
d2 -= cr2 * 9.0; // to 3x radius of planet [shipAI reactToMessage:@"APPROACHING_SURFACE"];
if (d2 < 0.0) }
if (wasNearPlanetSurface && !isNearPlanetSurface)
{
[self doScriptEvent:@"shipLeavingPlanetSurface" withArgument:the_planet];
[shipAI reactToMessage:@"LEAVING_SURFACE"];
}
}
if (d2 < cr2 * 9.0) // to 3x radius of planet
{
result = AEGIS_CLOSE_TO_PLANET; result = AEGIS_CLOSE_TO_PLANET;
}
// check station // check station
StationEntity* the_station = [UNIVERSE station]; StationEntity *the_station = [UNIVERSE station];
if (!the_station) if (!the_station)
{ {
if (aegis_status != AEGIS_NONE) if (aegis_status != AEGIS_NONE)
[shipAI message:@"AEGIS_NONE"]; {
// Station disappeared!
[self transitionToAegisNone];
}
return AEGIS_NONE; return AEGIS_NONE;
} }
p1 = the_station->position;
p1.x -= position.x; p1.y -= position.y; p1.z -= position.z;
d2 = p1.x*p1.x + p1.y*p1.y + p1.z*p1.z - SCANNER_MAX_RANGE2*4.0; // double scanner range
if (d2 < 0.0)
result = AEGIS_IN_DOCKING_RANGE;
// ai messages on change in status d2 = magnitude2(vector_subtract([the_station position], [self position]));
// approaching.. if (d2 < SCANNER_MAX_RANGE2 * 4.0) // double scanner range
if ((aegis_status == AEGIS_NONE)&&(result == AEGIS_CLOSE_TO_PLANET)) {
[shipAI message:@"AEGIS_CLOSE_TO_PLANET"]; result = AEGIS_IN_DOCKING_RANGE;
if (((aegis_status == AEGIS_CLOSE_TO_PLANET)||(aegis_status == AEGIS_NONE))&&(result == AEGIS_IN_DOCKING_RANGE)) }
[shipAI message:@"AEGIS_IN_DOCKING_RANGE"];
// leaving.. if (!suppressAegisMessages)
if ((aegis_status == AEGIS_IN_DOCKING_RANGE)&&(result == AEGIS_CLOSE_TO_PLANET)) {
[shipAI message:@"AEGIS_LEAVING_DOCKING_RANGE"]; // script/AI messages on change in status
if ((aegis_status != AEGIS_NONE)&&(result == AEGIS_NONE)) // approaching..
[shipAI message:@"AEGIS_NONE"]; if ((aegis_status == AEGIS_NONE)&&(result == AEGIS_CLOSE_TO_PLANET))
{
[self doScriptEvent:@"shipEnteredPlanetaryVicinity" withArgument:the_planet];
[shipAI message:@"AEGIS_CLOSE_TO_PLANET"];
}
if (((aegis_status == AEGIS_CLOSE_TO_PLANET)||(aegis_status == AEGIS_NONE))&&(result == AEGIS_IN_DOCKING_RANGE))
{
[self doScriptEvent:@"shipEnteredStationAegis" withArgument:the_station];
[shipAI message:@"AEGIS_IN_DOCKING_RANGE"];
}
// leaving..
if ((aegis_status == AEGIS_IN_DOCKING_RANGE)&&(result == AEGIS_CLOSE_TO_PLANET))
{
[self doScriptEvent:@"shipExitedStationAegis"];
[shipAI message:@"AEGIS_LEAVING_DOCKING_RANGE"];
}
if ((aegis_status != AEGIS_NONE)&&(result == AEGIS_NONE))
{
[self transitionToAegisNone];
}
}
aegis_status = result; // put this here aegis_status = result; // put this here
return result; return result;
} }

View File

@ -38,6 +38,16 @@ MA 02110-1301, USA.
#ifdef OOLITE_SDL_MAC #ifdef OOLITE_SDL_MAC
#define OOLITE_SDL 1 #define OOLITE_SDL 1
#endif #endif
/* Enforce type-clean use of nil and Nil under OS X. (They are untyped in
Cocoa, apparently for compatibility with legacy Mac OS code, but typed in
GNUstep.)
*/
#undef nil
#define nil ((id)0)
#undef Nil
#define Nil ((Class)nil)
#endif #endif

View File

@ -176,6 +176,8 @@ OOINLINE float OOFastInvSqrtf(float x)
x = *(float*)&i; x = *(float*)&i;
x = x * (1.5f - xhalf * x * x); x = x * (1.5f - xhalf * x * x);
return x; return x;
#elif OO_PPC
return OOInvSqrtf(x);
#else #else
return OOReciprocalEstimate(sqrt(x)); return OOReciprocalEstimate(sqrt(x));
#endif #endif

View File

@ -204,7 +204,7 @@ static NSString *GetCPUDescription(void)
static NSString *GetSysCtlString(const char *name) static NSString *GetSysCtlString(const char *name)
{ {
char *buffer = nil; char *buffer = NULL;
size_t size = 0; size_t size = 0;
// Get size // Get size

View File

@ -204,7 +204,7 @@ OOINLINE GLfloat magnitude(Vector vec)
OOINLINE GLfloat fast_magnitude(Vector vec) OOINLINE GLfloat fast_magnitude(Vector vec)
{ {
#if FASTINVSQRT_ENABLED #if FASTINVSQRT_ENABLED || OO_PPC
GLfloat mag2 = magnitude2(vec); GLfloat mag2 = magnitude2(vec);
return mag2 * OOFastInvSqrtf(mag2); /* x = sqrt(x) * sqrt(x); x * 1/sqrt(x) = (sqrt(x) * sqrt(x))/sqrt(x) = sqrt(x). */ return mag2 * OOFastInvSqrtf(mag2); /* x = sqrt(x) * sqrt(x); x * 1/sqrt(x) = (sqrt(x) * sqrt(x))/sqrt(x) = sqrt(x). */
#else #else