Started looking at laser drawing bug, ended up doing lots of cleanup of subentity handling instead.
git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@1456 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
parent
2ca6f60d5c
commit
e2a2be7f46
@ -26,7 +26,7 @@ endif
|
||||
OBJC_PROGRAM_NAME = oolite
|
||||
|
||||
oolite_C_FILES = legacy_random.c strlcpy.c OOTCPStreamDecoder.c
|
||||
oolite_OBJC_FILES = OOCocoa.m Comparison.m AI.m DustEntity.m Entity.m GameController.m GuiDisplayGen.m HeadUpDisplay.m main.m MyOpenGLView.m OpenGLSprite.m ParticleEntity.m PlanetEntity.m PlayerEntityLegacyScriptEngine.m PlayerEntityContracts.m PlayerEntityControls.m PlayerEntityLoadSave.m PlayerEntitySound.m PlayerEntity.m ResourceManager.m RingEntity.m ShipEntityAI.m ShipEntity.m SkyEntity.m StationEntity.m Universe.m OOSound.m SDLMusic.m NSFileManagerOOExtensions.m JoystickHandler.m PlayerEntityStickMapper.m OOBasicSoundReferencePoint.m OOBasicSoundSource.m OOCharacter.m OOTrumble.m WormholeEntity.m NSScannerOOExtensions.m OOXMLExtensions.m NSMutableDictionaryOOExtensions.m Geometry.m Octree.m CollisionRegion.m OOColor.m OOLogging.m OOCacheManager.m OOCache.m OOStringParsing.m OOCollectionExtractors.m OOVector.m OOMatrix.m OOQuaternion.m OOVoxel.m OOTriangle.m OOPListParsing.m OOFastArithmetic.m OOTextureScaling.m OOConstToString.m OOScript.m OOJSScript.m OOJavaScriptEngine.m OOPListScript.m NSStringOOExtensions.m PlayerEntityScriptMethods.m OOWeakReference.m OOJSEntity.m EntityOOJavaScriptExtensions.m OOJSQuaternion.m OOMaterial.m OOShaderMaterial.m OOShaderProgram.m OOShaderUniform.m OOTexture.m OOTextureLoader.m OOPNGTextureLoader.m OOOpenGLExtensionManager.m OOBasicMaterial.m OOSingleTextureMaterial.m OOCPUInfo.m OOSelfDrawingEntity.m OOEntityWithDrawable.m OODrawable.m OOJSVector.m OOMesh.m OOOpenGL.m OOGraphicsResetManager.m OOProbabilisticTextureManager.m OODebugGLDrawing.m OOShaderUniformMethodType.m OOAsyncQueue.m TextureStore.m OOOXPVerifier.m OOOXPVerifierStage.m OOFileScannerVerifierStage.m OOCheckRequiresPListVerifierStage.m OOCheckDemoShipsPListVerifierStage.m OOCheckEquipmentPListVerifierStage.m OOTextureVerifierStage.m OOModelVerifierStage.m OOCheckShipDataPListVerifierStage.m OOPListSchemaVerifier.m OOJSShip.m OOJSPlayer.m OOJSCall.m OOJSStation.m OOJSSystem.m OOLegacyEventHandlerScript.m OOJSOolite.m OORoleSet.m OOJSGlobal.m OOJSMissionVariables.m OOJSMission.m OOPriorityQueue.m OOScriptTimer.m OOJSTimer.m OOJSClock.m OODebugSupport.m OODebugMonitor.m OOJSConsole.m OODebugTCPConsoleClient.m OOTCPStreamDecoderAbstractionLayer.m OOEntityFilterPredicate.m OOJSPlanet.m OOJSWorldScripts.m OOJSSun.m NSThreadOOExtensions.m OOEncodingConverter.m OOJSSound.m OOJSSoundSource.m OOMusicController.m OOLogHeader.m OOJSSpecialFunctions.m OOSpatialReference.m OOSkyDrawable.m
|
||||
oolite_OBJC_FILES = OOCocoa.m Comparison.m AI.m DustEntity.m Entity.m GameController.m GuiDisplayGen.m HeadUpDisplay.m main.m MyOpenGLView.m OpenGLSprite.m ParticleEntity.m PlanetEntity.m PlayerEntityLegacyScriptEngine.m PlayerEntityContracts.m PlayerEntityControls.m PlayerEntityLoadSave.m PlayerEntitySound.m PlayerEntity.m ResourceManager.m RingEntity.m ShipEntityAI.m ShipEntity.m SkyEntity.m StationEntity.m Universe.m OOSound.m SDLMusic.m NSFileManagerOOExtensions.m JoystickHandler.m PlayerEntityStickMapper.m OOBasicSoundReferencePoint.m OOBasicSoundSource.m OOCharacter.m OOTrumble.m WormholeEntity.m NSScannerOOExtensions.m OOXMLExtensions.m NSMutableDictionaryOOExtensions.m Geometry.m Octree.m CollisionRegion.m OOColor.m OOLogging.m OOCacheManager.m OOCache.m OOStringParsing.m OOCollectionExtractors.m OOVector.m OOMatrix.m OOQuaternion.m OOVoxel.m OOTriangle.m OOPListParsing.m OOFastArithmetic.m OOTextureScaling.m OOConstToString.m OOScript.m OOJSScript.m OOJavaScriptEngine.m OOPListScript.m NSStringOOExtensions.m PlayerEntityScriptMethods.m OOWeakReference.m OOJSEntity.m EntityOOJavaScriptExtensions.m OOJSQuaternion.m OOMaterial.m OOShaderMaterial.m OOShaderProgram.m OOShaderUniform.m OOTexture.m OOTextureLoader.m OOPNGTextureLoader.m OOOpenGLExtensionManager.m OOBasicMaterial.m OOSingleTextureMaterial.m OOCPUInfo.m OOSelfDrawingEntity.m OOEntityWithDrawable.m OODrawable.m OOJSVector.m OOMesh.m OOOpenGL.m OOGraphicsResetManager.m OOProbabilisticTextureManager.m OODebugGLDrawing.m OOShaderUniformMethodType.m OOAsyncQueue.m TextureStore.m OOOXPVerifier.m OOOXPVerifierStage.m OOFileScannerVerifierStage.m OOCheckRequiresPListVerifierStage.m OOCheckDemoShipsPListVerifierStage.m OOCheckEquipmentPListVerifierStage.m OOTextureVerifierStage.m OOModelVerifierStage.m OOCheckShipDataPListVerifierStage.m OOPListSchemaVerifier.m OOJSShip.m OOJSPlayer.m OOJSCall.m OOJSStation.m OOJSSystem.m OOLegacyEventHandlerScript.m OOJSOolite.m OORoleSet.m OOJSGlobal.m OOJSMissionVariables.m OOJSMission.m OOPriorityQueue.m OOScriptTimer.m OOJSTimer.m OOJSClock.m OODebugSupport.m OODebugMonitor.m OOJSConsole.m OODebugTCPConsoleClient.m OOTCPStreamDecoderAbstractionLayer.m OOEntityFilterPredicate.m OOJSPlanet.m OOJSWorldScripts.m OOJSSun.m NSThreadOOExtensions.m OOEncodingConverter.m OOJSSound.m OOJSSoundSource.m OOMusicController.m OOLogHeader.m OOJSSpecialFunctions.m OOSpatialReference.m OOSkyDrawable.m OOFilteringEnumerator.m
|
||||
|
||||
include $(GNUSTEP_MAKEFILES)/objc.make
|
||||
include GNUmakefile.postamble
|
||||
|
@ -44,6 +44,8 @@
|
||||
1A1502F60C1201C30032F3E8 /* oolite-unknown-ship.dat in Copy Models */ = {isa = PBXBuildFile; fileRef = 1A1502F50C1201C30032F3E8 /* oolite-unknown-ship.dat */; };
|
||||
1A15049E0C12CA070032F3E8 /* OOProbabilisticTextureManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A15049C0C12CA070032F3E8 /* OOProbabilisticTextureManager.h */; };
|
||||
1A15049F0C12CA070032F3E8 /* OOProbabilisticTextureManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A15049D0C12CA070032F3E8 /* OOProbabilisticTextureManager.m */; };
|
||||
1A1616620D7DCFDC0094AE5B /* OOFilteringEnumerator.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A1616600D7DCFDC0094AE5B /* OOFilteringEnumerator.h */; };
|
||||
1A1616630D7DCFDC0094AE5B /* OOFilteringEnumerator.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A1616610D7DCFDC0094AE5B /* OOFilteringEnumerator.m */; };
|
||||
1A1D212E0D2BD4C100F4DEC2 /* bsd_string.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A1D212D0D2BD4C100F4DEC2 /* bsd_string.h */; };
|
||||
1A2315520B9C778400EF0852 /* solar.png in Copy Images */ = {isa = PBXBuildFile; fileRef = 1A23154E0B9C778400EF0852 /* solar.png */; };
|
||||
1A2315530B9C778400EF0852 /* splash.png in Resources */ = {isa = PBXBuildFile; fileRef = 1A23154F0B9C778400EF0852 /* splash.png */; };
|
||||
@ -1014,6 +1016,8 @@
|
||||
1A15044A0C12C50D0032F3E8 /* OOSkyDrawable.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OOSkyDrawable.m; sourceTree = "<group>"; };
|
||||
1A15049C0C12CA070032F3E8 /* OOProbabilisticTextureManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OOProbabilisticTextureManager.h; sourceTree = "<group>"; };
|
||||
1A15049D0C12CA070032F3E8 /* OOProbabilisticTextureManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OOProbabilisticTextureManager.m; sourceTree = "<group>"; };
|
||||
1A1616600D7DCFDC0094AE5B /* OOFilteringEnumerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OOFilteringEnumerator.h; sourceTree = "<group>"; };
|
||||
1A1616610D7DCFDC0094AE5B /* OOFilteringEnumerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OOFilteringEnumerator.m; sourceTree = "<group>"; };
|
||||
1A1D212D0D2BD4C100F4DEC2 /* bsd_string.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = bsd_string.h; path = src/BSDCompat/bsd_string.h; sourceTree = SOURCE_ROOT; };
|
||||
1A23154E0B9C778400EF0852 /* solar.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = solar.png; sourceTree = "<group>"; };
|
||||
1A23154F0B9C778400EF0852 /* splash.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = splash.png; sourceTree = "<group>"; };
|
||||
@ -2352,6 +2356,8 @@
|
||||
1AD1F4C80CD9E42A00EAE520 /* NSThreadOOExtensions.m */,
|
||||
1A1D212D0D2BD4C100F4DEC2 /* bsd_string.h */,
|
||||
1AAB9A960D779F3C00A9F424 /* OOCocoa.m */,
|
||||
1A1616600D7DCFDC0094AE5B /* OOFilteringEnumerator.h */,
|
||||
1A1616610D7DCFDC0094AE5B /* OOFilteringEnumerator.m */,
|
||||
);
|
||||
name = Utilities;
|
||||
sourceTree = "<group>";
|
||||
@ -2802,6 +2808,7 @@
|
||||
1A0DA2EE0D71D280009B0970 /* OOJSSpecialFunctions.h in Headers */,
|
||||
1A5218DA0D72EC21000865E9 /* OOSpatialReference.h in Headers */,
|
||||
1A03658A0D7CA05000B5F46F /* OOSkyDrawable.h in Headers */,
|
||||
1A1616620D7DCFDC0094AE5B /* OOFilteringEnumerator.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@ -3151,6 +3158,7 @@
|
||||
1A5218DE0D72ECE5000865E9 /* OOSpatialReference.m in Sources */,
|
||||
1AAB9A980D779F4500A9F424 /* OOCocoa.m in Sources */,
|
||||
1A0365890D7CA05000B5F46F /* OOSkyDrawable.m in Sources */,
|
||||
1A1616630D7DCFDC0094AE5B /* OOFilteringEnumerator.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -51,7 +51,7 @@ if (this.legacy_launchActions != undefined)
|
||||
}
|
||||
|
||||
|
||||
// death_actions handled on didDie().
|
||||
// death_actions handled on shipDied().
|
||||
if (this.legacy_deathActions != undefined)
|
||||
{
|
||||
this.shipDied = function ()
|
||||
|
@ -31,7 +31,7 @@ MA 02110-1301, USA.
|
||||
#import "OOTypes.h"
|
||||
#import "OOWeakReference.h"
|
||||
|
||||
@class Universe, Geometry, CollisionRegion;
|
||||
@class Universe, Geometry, CollisionRegion, ShipEntity;
|
||||
|
||||
|
||||
#ifndef NDEBUG
|
||||
@ -91,7 +91,7 @@ typedef struct
|
||||
isPlayer: 1,
|
||||
isSky: 1,
|
||||
isWormhole: 1,
|
||||
isSubentity: 1,
|
||||
isSubEntity: 1,
|
||||
hasMoved: 1,
|
||||
hasRotated: 1,
|
||||
hasCollided: 1,
|
||||
@ -191,6 +191,8 @@ typedef struct
|
||||
|
||||
- (void) setOwner:(Entity *)ent;
|
||||
- (id)owner;
|
||||
- (ShipEntity *)parentEntity; // owner if self is subentity of owner, otherwise nil.
|
||||
- (ShipEntity *)rootShipEntity; // like parentEntity, but recursive.
|
||||
|
||||
- (void) setPosition:(Vector)posn;
|
||||
- (void) setPositionX:(GLfloat)x y:(GLfloat)y z:(GLfloat)z;
|
||||
@ -206,6 +208,7 @@ typedef struct
|
||||
|
||||
- (void) setOrientation:(Quaternion) quat;
|
||||
- (Quaternion) orientation;
|
||||
- (Quaternion) normalOrientation; // Historical wart: orientation.w is reversed for player; -normalOrientation corrects this.
|
||||
- (void) orientationChanged;
|
||||
|
||||
- (void) setVelocity:(Vector)vel;
|
||||
@ -266,7 +269,4 @@ typedef struct
|
||||
- (GLfloat)spawnTime;
|
||||
- (GLfloat)timeElapsedSinceSpawn;
|
||||
|
||||
// Resolve subentity-type relationships
|
||||
- (id) rootEntity;
|
||||
|
||||
@end
|
||||
|
@ -113,7 +113,7 @@ static NSString * const kOOLogEntityUpdateError = @"entity.linkedList.update.
|
||||
|
||||
- (BOOL)isSubEntity
|
||||
{
|
||||
return isSubentity;
|
||||
return isSubEntity;
|
||||
}
|
||||
|
||||
|
||||
@ -528,6 +528,23 @@ static NSString * const kOOLogEntityUpdateError = @"entity.linkedList.update.
|
||||
}
|
||||
|
||||
|
||||
- (ShipEntity *)parentEntity
|
||||
{
|
||||
id ownerEnt = [self owner];
|
||||
if ([ownerEnt isShipWithSubEntityShip:self]) return ownerEnt;
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
- (ShipEntity *) rootShipEntity
|
||||
{
|
||||
ShipEntity *parent = [self parentEntity];
|
||||
if (parent != nil) return [parent rootShipEntity];
|
||||
if ([self isShip]) return (ShipEntity *)self;
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
- (void) setPosition:(Vector) posn
|
||||
{
|
||||
position = posn;
|
||||
@ -588,6 +605,12 @@ static NSString * const kOOLogEntityUpdateError = @"entity.linkedList.update.
|
||||
}
|
||||
|
||||
|
||||
- (Quaternion) normalOrientation
|
||||
{
|
||||
return [self orientation];
|
||||
}
|
||||
|
||||
|
||||
- (void) orientationChanged
|
||||
{
|
||||
quaternion_normalize(&orientation);
|
||||
@ -1042,7 +1065,7 @@ static NSString * const kOOLogEntityUpdateError = @"entity.linkedList.update.
|
||||
ADD_FLAG_IF_SET(isPlayer);
|
||||
ADD_FLAG_IF_SET(isSky);
|
||||
ADD_FLAG_IF_SET(isWormhole);
|
||||
ADD_FLAG_IF_SET(isSubentity);
|
||||
ADD_FLAG_IF_SET(isSubEntity);
|
||||
ADD_FLAG_IF_SET(hasMoved);
|
||||
ADD_FLAG_IF_SET(hasRotated);
|
||||
ADD_FLAG_IF_SET(isSunlit);
|
||||
@ -1077,10 +1100,4 @@ static NSString * const kOOLogEntityUpdateError = @"entity.linkedList.update.
|
||||
return [UNIVERSE getTime] - spawnTime;
|
||||
}
|
||||
|
||||
|
||||
- (id) rootEntity
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -64,7 +64,7 @@ MA 02110-1301, USA.
|
||||
GLfloat exhaustBaseColors[34 * 4], verts[34 * 3];
|
||||
}
|
||||
|
||||
- (id) initLaserFromShip:(ShipEntity *) ship view:(int) view offset:(Vector)offset;
|
||||
- (id) initLaserFromShip:(ShipEntity *) ship view:(OOViewID) view offset:(Vector)offset;
|
||||
- (id) initExhaustFromShip:(ShipEntity *) ship details:(NSString *) details;
|
||||
- (id) initECMMineFromShip:(ShipEntity *) ship;
|
||||
- (id) initEnergyMineFromShip:(ShipEntity *) ship;
|
||||
|
@ -29,6 +29,7 @@ MA 02110-1301, USA.
|
||||
#import "OOColor.h"
|
||||
#import "OOTexture.h"
|
||||
#import "OOStringParsing.h"
|
||||
#import "OOCollectionExtractors.h"
|
||||
|
||||
#import "ShipEntity.h"
|
||||
#import "PlayerEntity.h"
|
||||
@ -168,63 +169,58 @@ static Vector circleVertex[65]; // holds vector coordinates for a unit circle
|
||||
}
|
||||
|
||||
|
||||
- (id) initLaserFromShip:(ShipEntity *) srcEntity view:(int) view offset:(Vector)offset
|
||||
- (id) initLaserFromShip:(ShipEntity *) srcEntity view:(OOViewID) view offset:(Vector)offset
|
||||
{
|
||||
ShipEntity *ship = nil;
|
||||
ShipEntity *ship = [srcEntity rootShipEntity];
|
||||
|
||||
self = [super init];
|
||||
if (self == nil) goto FAIL;
|
||||
|
||||
if (srcEntity == nil || !srcEntity->isShip) goto FAIL;
|
||||
if (srcEntity->isSubentity)
|
||||
{
|
||||
ship = [srcEntity owner];
|
||||
if (ship == nil || !ship->isShip) goto FAIL;
|
||||
}
|
||||
else ship = srcEntity;
|
||||
#ifndef NDEBUG
|
||||
if (![srcEntity isShip]) goto FAIL;
|
||||
if (ship == nil) goto FAIL;
|
||||
#endif
|
||||
|
||||
status = STATUS_EFFECT;
|
||||
position = ship->position;
|
||||
if (ship == srcEntity) position = ship->position;
|
||||
if (ship == srcEntity) position = [ship position];
|
||||
else
|
||||
{
|
||||
// FIXME: shouldn't the subentity case work in any case?
|
||||
BoundingBox bbox = [srcEntity boundingBox];
|
||||
Vector midfrontplane = make_vector(0.5 * (bbox.max.x + bbox.min.x), 0.5 * (bbox.max.y + bbox.min.y), bbox.max.z);
|
||||
position = [srcEntity absolutePositionForSubentityOffset:midfrontplane];
|
||||
}
|
||||
orientation = ship->orientation;
|
||||
if (ship->isPlayer)
|
||||
orientation.w = -orientation.w; //reverse view direction for the player
|
||||
|
||||
orientation = [ship normalOrientation];
|
||||
Vector v_up = vector_up_from_quaternion(orientation);
|
||||
Vector v_forward = vector_forward_from_quaternion(orientation);
|
||||
Vector v_right = vector_right_from_quaternion(orientation);
|
||||
GLfloat fs = [ship flightSpeed];
|
||||
velocity = make_vector(v_forward.x * fs, v_forward.y * fs, v_forward.z * fs);
|
||||
velocity = vector_multiply_scalar(v_forward, [ship flightSpeed]);
|
||||
|
||||
GLfloat distance;
|
||||
Vector viewOffset;
|
||||
switch (view)
|
||||
{
|
||||
default:
|
||||
case VIEW_FORWARD:
|
||||
distance = [srcEntity boundingBox].max.z;
|
||||
position.x += distance * v_forward.x; position.y += distance * v_forward.y; position.z += distance * v_forward.z;
|
||||
viewOffset = vector_multiply_scalar(v_forward, [srcEntity boundingBox].max.z);
|
||||
break;
|
||||
|
||||
case VIEW_AFT:
|
||||
quaternion_rotate_about_axis(&orientation, v_up, M_PI);
|
||||
distance = [srcEntity boundingBox].min.z;
|
||||
position.x += distance * v_forward.x; position.y += distance * v_forward.y; position.z += distance * v_forward.z;
|
||||
viewOffset = vector_multiply_scalar(v_forward, [srcEntity boundingBox].min.z);
|
||||
break;
|
||||
|
||||
case VIEW_PORT:
|
||||
quaternion_rotate_about_axis(&orientation, v_up, M_PI/2.0);
|
||||
distance = [srcEntity boundingBox].min.x;
|
||||
position.x += distance * v_right.x; position.y += distance * v_right.y; position.z += distance * v_right.z;
|
||||
viewOffset = vector_multiply_scalar(v_right, [srcEntity boundingBox].min.x);
|
||||
break;
|
||||
|
||||
case VIEW_STARBOARD:
|
||||
quaternion_rotate_about_axis(&orientation, v_up, -M_PI/2.0);
|
||||
distance = [srcEntity boundingBox].max.x;
|
||||
position.x += distance * v_right.x; position.y += distance * v_right.y; position.z += distance * v_right.z;
|
||||
viewOffset = vector_multiply_scalar(v_right, [srcEntity boundingBox].max.x);
|
||||
break;
|
||||
}
|
||||
position = vector_add(position, viewOffset);
|
||||
rotMatrix = OOMatrixForQuaternionRotation(orientation);
|
||||
|
||||
time_counter = 0.0;
|
||||
@ -255,13 +251,13 @@ FAIL:
|
||||
if ([values count] != 6)
|
||||
return nil;
|
||||
Vector offset, scale;
|
||||
offset.x = [(NSString *)[values objectAtIndex:0] floatValue];
|
||||
offset.y = [(NSString *)[values objectAtIndex:1] floatValue];
|
||||
offset.z = [(NSString *)[values objectAtIndex:2] floatValue];
|
||||
scale.x = [(NSString *)[values objectAtIndex:3] floatValue];
|
||||
scale.y = [(NSString *)[values objectAtIndex:4] floatValue];
|
||||
scale.z = [(NSString *)[values objectAtIndex:5] floatValue];
|
||||
|
||||
offset.x = [values floatAtIndex:0];
|
||||
offset.y = [values floatAtIndex:1];
|
||||
offset.z = [values floatAtIndex:2];
|
||||
scale.x = [values floatAtIndex:3];
|
||||
scale.y = [values floatAtIndex:4];
|
||||
scale.z = [values floatAtIndex:5];
|
||||
|
||||
self = [super init];
|
||||
|
||||
status = STATUS_EFFECT;
|
||||
|
@ -1156,14 +1156,11 @@ static PlayerEntity *sSharedPlayer = nil;
|
||||
tractor_position = kZeroVector;
|
||||
ScanVectorFromString([shipDict stringForKey:@"scoop_position"], &tractor_position);
|
||||
|
||||
[sub_entities autorelease];
|
||||
sub_entities = nil;
|
||||
[subEntities autorelease];
|
||||
subEntities = nil;
|
||||
|
||||
|
||||
if (![self setUpSubEntities: shipDict])
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
if (![self setUpSubEntities: shipDict]) return NO;
|
||||
|
||||
// rotating subentities
|
||||
subentityRotationalVelocity = kIdentityQuaternion;
|
||||
@ -1940,11 +1937,11 @@ double scoopSoundPlayTime = 0.0;
|
||||
}
|
||||
|
||||
// update subentities
|
||||
if (sub_entities)
|
||||
NSEnumerator *subEnum = nil;
|
||||
ShipEntity *se = nil;
|
||||
for (subEnum = [self subEntityEnumerator]; (se = [subEnum nextObject]); )
|
||||
{
|
||||
unsigned i;
|
||||
for (i = 0; i < [sub_entities count]; i++)
|
||||
[(Entity *)[sub_entities objectAtIndex:i] update:delta_t];
|
||||
[se update:delta_t];
|
||||
}
|
||||
}
|
||||
|
||||
@ -2008,6 +2005,12 @@ double scoopSoundPlayTime = 0.0;
|
||||
}
|
||||
|
||||
|
||||
- (Quaternion) normalOrientation
|
||||
{
|
||||
return make_quaternion(-orientation.w, orientation.x, orientation.y, orientation.z);
|
||||
}
|
||||
|
||||
|
||||
- (void) moveForward:(double) amount
|
||||
{
|
||||
distanceTravelled += amount;
|
||||
|
@ -2130,7 +2130,7 @@ static int scriptRandomSeed = -1; // ensure proper random function
|
||||
[se1 setFuel: PLAYER_MAX_FUEL];
|
||||
[se1AI setStateMachine:@"exitingTraderAI.plist"];
|
||||
[se1AI setState:@"EXIT_SYSTEM"];
|
||||
// FIXME: I don't think the following line does anything meaningful.
|
||||
// FIXME: I don't think the following line does anything meaningful. -- Ahruman
|
||||
[se1AI reactToMessage:[NSString stringWithFormat:@"pauseAI: %d", 3 + (ranrot_rand() & 15)]];
|
||||
[se1 setPrimaryRole:@"none"]; // prevents new ship from appearing at witchpoint when this one leaves!
|
||||
}
|
||||
|
@ -82,9 +82,6 @@ MA 02110-1301, USA.
|
||||
@interface ShipEntity: OOEntityWithDrawable
|
||||
{
|
||||
@public
|
||||
NSMutableArray *sub_entities;
|
||||
ShipEntity *subentity_taking_damage; // frangible => subentities can be damaged individually
|
||||
|
||||
// derived variables
|
||||
double shot_time; // time elapsed since last shot was fired
|
||||
|
||||
@ -158,7 +155,7 @@ MA 02110-1301, USA.
|
||||
trackCloseContacts: 1,
|
||||
|
||||
isNearPlanetSurface: 1, // check for landing on planet
|
||||
isFrangible: 1, // frangible => subentities can be damaged individually
|
||||
isFrangible: 1, // frangible => subEntities can be damaged individually
|
||||
cloaking_device_active: 1, // cloaking_device
|
||||
canFragment: 1, // Can it break into wreckage?
|
||||
suppressExplosion: 1, // Avoid exploding on death (script hook)
|
||||
@ -292,6 +289,11 @@ MA 02110-1301, USA.
|
||||
|
||||
uint16_t entity_personality; // Per-entity random number. Exposed to shaders and scripts.
|
||||
NSDictionary *scriptInfo; // script_info dictionary from shipdata.plist, exposed to scripts.
|
||||
|
||||
NSMutableArray *subEntities;
|
||||
|
||||
@private
|
||||
OOWeakReference *subEntityTakingDamage; // frangible => subEntities can be damaged individually
|
||||
}
|
||||
|
||||
// ship brains
|
||||
@ -307,6 +309,17 @@ MA 02110-1301, USA.
|
||||
- (void)setMesh:(OOMesh *)mesh;
|
||||
|
||||
- (NSArray *)subEntities;
|
||||
- (unsigned) subEntityCount;
|
||||
- (BOOL) hasSubEntity:(ShipEntity *)sub;
|
||||
|
||||
- (NSEnumerator *)subEntityEnumerator;
|
||||
- (NSEnumerator *)shipSubEntityEnumerator;
|
||||
- (NSEnumerator *)particleSubEntityEnumerator;
|
||||
- (NSEnumerator *)flasherEnumerator;
|
||||
- (NSEnumerator *)exhaustEnumerator;
|
||||
|
||||
- (ShipEntity *) subEntityTakingDamage;
|
||||
- (void) setSubEntityTakingDamage:(ShipEntity *)sub;
|
||||
|
||||
// octree collision hunting
|
||||
- (GLfloat)doesHitLine:(Vector) v0: (Vector) v1;
|
||||
@ -360,7 +373,6 @@ MA 02110-1301, USA.
|
||||
- (void) behaviour_avoid_collision:(double) delta_t;
|
||||
- (void) behaviour_track_as_turret:(double) delta_t;
|
||||
- (void) behaviour_fly_thru_navpoints:(double) delta_t;
|
||||
- (void) behaviour_experimental:(double) delta_t;
|
||||
|
||||
|
||||
- (void) resetTracking;
|
||||
@ -374,9 +386,9 @@ MA 02110-1301, USA.
|
||||
|
||||
- (BOOL) hasMilitaryScannerFilter;
|
||||
|
||||
- (void) addSubEntity:(Entity *) subent;
|
||||
- (void) addExhaust:(ParticleEntity *) exhaust;
|
||||
- (void) addFlasher:(ParticleEntity *) flasher;
|
||||
- (void) addSubEntity:(ShipEntity *) subent;
|
||||
|
||||
- (void) applyThrust:(double) delta_t;
|
||||
|
||||
@ -578,7 +590,7 @@ BOOL class_masslocks(int some_class);
|
||||
- (OOColor *)laserColor;
|
||||
- (BOOL) fireSubentityLaserShot: (double) range;
|
||||
- (BOOL) fireDirectLaserShot;
|
||||
- (BOOL) fireLaserShotInDirection: (int) direction;
|
||||
- (BOOL) fireLaserShotInDirection: (OOViewID) direction;
|
||||
- (BOOL) firePlasmaShot:(double) offset :(double) speed :(OOColor *) color;
|
||||
- (BOOL) fireMissile;
|
||||
- (BOOL) fireECM;
|
||||
@ -681,6 +693,14 @@ BOOL class_masslocks(int some_class);
|
||||
@end
|
||||
|
||||
|
||||
// For the common case of testing whether foo is a ship, bar is a ship, bar is a subentity of foo and this relationship is represented sanely.
|
||||
@interface Entity (SubEntityRelationship)
|
||||
|
||||
- (BOOL) isShipWithSubEntityShip:(Entity *)other;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
BOOL ship_canCollide (ShipEntity* ship);
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -197,7 +197,6 @@ NSString *BehaviourToString(OOBehaviour behaviour)
|
||||
CASE(BEHAVIOUR_FORMATION_BREAK);
|
||||
CASE(BEHAVIOUR_ENERGY_BOMB_COUNTDOWN);
|
||||
CASE(BEHAVIOUR_TRACTORED);
|
||||
CASE(BEHAVIOUR_EXPERIMENTAL);
|
||||
CASE(BEHAVIOUR_FLY_THRU_NAVPOINTS);
|
||||
}
|
||||
|
||||
|
@ -121,7 +121,7 @@ BOOL HasClassPredicate(Entity *entity, void *parameter)
|
||||
|
||||
BOOL IsShipPredicate(Entity *entity, void *parameter)
|
||||
{
|
||||
return entity->isShip && !entity->isSubentity;
|
||||
return [entity isShip] && ![entity isSubEntity];
|
||||
}
|
||||
|
||||
|
||||
|
137
src/Core/OOFilteringEnumerator.h
Normal file
137
src/Core/OOFilteringEnumerator.h
Normal file
@ -0,0 +1,137 @@
|
||||
/*
|
||||
|
||||
OOFilteringEnumerator.h
|
||||
By Jens Ayton
|
||||
|
||||
NSEnumerator which takes an existing enumerator and filters out the objects
|
||||
that return NO from a given method. The method may take 0 or 1 arguments
|
||||
|
||||
Example of use:
|
||||
NSArray *cats = [self cats];
|
||||
NSEnumerator *happyCatEnum = [[cats objectEnumerator] filteredWithSelector:@selector(isHappy)];
|
||||
id happyCat = nil;
|
||||
|
||||
while ((happyCat = [happyCatEnum nextObject]))
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
Filters can be trivially chained. For instance, to get happy red cats, use:
|
||||
NSEnumeratore *happyRedCatEnum = [[[cats objectEnumerator]
|
||||
filteredWithSelector:@selector(isHappy)]
|
||||
filteredWithSelector:@selector(hasColor:)
|
||||
andArgument:[NSColor redColor]];
|
||||
|
||||
Objects that do not respond to the filter selector are treated as if they had
|
||||
returned NO.
|
||||
|
||||
Bonus feature: adds NSArray-like (but non-exception-throwing)
|
||||
makeObjectsPerformSelector: to all enumerators.
|
||||
|
||||
|
||||
Oolite
|
||||
Copyright (C) 2004-2008 Giles C Williams and contributors
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA.
|
||||
|
||||
|
||||
This file may also be distributed under the MIT/X11 license:
|
||||
|
||||
Copyright (C) 2008 Jens Ayton
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#import "OOCocoa.h"
|
||||
|
||||
|
||||
@interface OOFilteringEnumerator: NSEnumerator
|
||||
{
|
||||
NSEnumerator *_underlyingEnum;
|
||||
SEL _selector;
|
||||
id _argument;
|
||||
BOOL _takesArgument;
|
||||
}
|
||||
|
||||
+ (id) filterEnumerator:(NSEnumerator *)enumerator withSelector:(SEL)selector;
|
||||
+ (id) filterEnumerator:(NSEnumerator *)enumerator withSelector:(SEL)selector andArgument:(id)argument;
|
||||
|
||||
- (id) initWithUnderlyingEnumerator:(NSEnumerator *)enumerator
|
||||
withSelector:(SEL)selector
|
||||
takingArgument:(BOOL)takesArgument
|
||||
argumentValue:(id)argument;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface NSEnumerator (OOFilteringEnumerator)
|
||||
|
||||
- (id) filteredWithSelector:(SEL)selector;
|
||||
- (id) filteredWithSelector:(SEL)selector andArgument:(id)argument;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface NSArray (OOFilteringEnumerator)
|
||||
|
||||
- (id) objectEnumeratorFilteredWithSelector:(SEL)selector;
|
||||
- (id) objectEnumeratorFilteredWithSelector:(SEL)selector andArgument:(id)argument;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface NSSet (OOFilteringEnumerator)
|
||||
|
||||
- (id) objectEnumeratorFilteredWithSelector:(SEL)selector;
|
||||
- (id) objectEnumeratorFilteredWithSelector:(SEL)selector andArgument:(id)argument;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface NSDictionary (OOFilteringEnumerator)
|
||||
|
||||
- (id) objectEnumeratorFilteredWithSelector:(SEL)selector;
|
||||
- (id) objectEnumeratorFilteredWithSelector:(SEL)selector andArgument:(id)argument;
|
||||
|
||||
- (id) keyEnumeratorFilteredWithSelector:(SEL)selector;
|
||||
- (id) keyEnumeratorFilteredWithSelector:(SEL)selector andArgument:(id)argument;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface NSEnumerator (OOMakeObjectsPerformSelector)
|
||||
|
||||
- (void)makeObjectsPerformSelector:(SEL)selector;
|
||||
- (void)makeObjectsPerformSelector:(SEL)selector withObject:(id)argument;
|
||||
|
||||
@end
|
280
src/Core/OOFilteringEnumerator.m
Normal file
280
src/Core/OOFilteringEnumerator.m
Normal file
@ -0,0 +1,280 @@
|
||||
/*
|
||||
|
||||
OOFilteringEnumerator.m
|
||||
By Jens Ayton
|
||||
|
||||
|
||||
Oolite
|
||||
Copyright (C) 2004-2008 Giles C Williams and contributors
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA.
|
||||
|
||||
|
||||
This file may also be distributed under the MIT/X11 license:
|
||||
|
||||
Copyright (C) 2008 Jens Ayton
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#import "OOFilteringEnumerator.h"
|
||||
|
||||
|
||||
typedef BOOL (*BoolReturnMsgSend)(id, SEL);
|
||||
typedef BOOL (*BoolReturnWithParamMsgSend)(id, SEL, id);
|
||||
|
||||
|
||||
@implementation OOFilteringEnumerator
|
||||
|
||||
+ (id) filterEnumerator:(NSEnumerator *)enumerator withSelector:(SEL)selector
|
||||
{
|
||||
if (selector == NULL) return [[enumerator retain] autorelease];
|
||||
|
||||
return [[[self alloc] initWithUnderlyingEnumerator:enumerator
|
||||
withSelector:selector
|
||||
takingArgument:NO
|
||||
argumentValue:nil]
|
||||
autorelease];
|
||||
}
|
||||
|
||||
|
||||
+ (id) filterEnumerator:(NSEnumerator *)enumerator withSelector:(SEL)selector andArgument:(id)argument
|
||||
{
|
||||
if (selector == NULL) return [[enumerator retain] autorelease];
|
||||
|
||||
return [[[self alloc] initWithUnderlyingEnumerator:enumerator
|
||||
withSelector:selector
|
||||
takingArgument:YES
|
||||
argumentValue:argument]
|
||||
autorelease];
|
||||
}
|
||||
|
||||
- (id) initWithUnderlyingEnumerator:(NSEnumerator *)enumerator
|
||||
withSelector:(SEL)selector
|
||||
takingArgument:(BOOL)takesArgument
|
||||
argumentValue:(id)argument
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil)
|
||||
{
|
||||
_underlyingEnum = [enumerator retain];
|
||||
_selector = selector;
|
||||
_takesArgument = takesArgument;
|
||||
if (_takesArgument)
|
||||
{
|
||||
_argument = [argument retain];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[_underlyingEnum release];
|
||||
[_argument release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
- (NSString *) descriptionComponents
|
||||
{
|
||||
NSString *subDesc = NSStringFromSelector(_selector);
|
||||
if (_takesArgument)
|
||||
{
|
||||
subDesc = [subDesc stringByAppendingString:[_argument shortDescription]];
|
||||
}
|
||||
|
||||
return [NSString stringWithFormat:@"%@ matching %@", [_underlyingEnum shortDescription], subDesc];
|
||||
}
|
||||
|
||||
|
||||
- (NSString *) shortDescriptionComponents
|
||||
{
|
||||
return NSStringFromSelector(_selector);
|
||||
}
|
||||
|
||||
|
||||
- (id) nextObject
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
// Get next object
|
||||
id obj = [_underlyingEnum nextObject];
|
||||
BOOL filter;
|
||||
|
||||
if (obj == nil)
|
||||
{
|
||||
// End of enumeration
|
||||
if (_underlyingEnum != nil)
|
||||
{
|
||||
[_underlyingEnum release];
|
||||
_underlyingEnum = nil;
|
||||
[_argument release];
|
||||
_argument = nil;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
// Check against filter
|
||||
IMP predicate = [obj methodForSelector:_selector];
|
||||
if (predicate != NULL)
|
||||
{
|
||||
if (!_takesArgument)
|
||||
{
|
||||
filter = ((BoolReturnMsgSend)predicate)(obj, _selector);
|
||||
}
|
||||
else
|
||||
{
|
||||
filter = ((BoolReturnWithParamMsgSend)predicate)(obj, _selector, _argument);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Unsupported method
|
||||
filter = NO;
|
||||
}
|
||||
|
||||
// If object passed, return it.
|
||||
if (filter) return obj;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSEnumerator (OOFilteringEnumerator)
|
||||
|
||||
- (id) filteredWithSelector:(SEL)selector
|
||||
{
|
||||
return [OOFilteringEnumerator filterEnumerator:self withSelector:selector];
|
||||
}
|
||||
|
||||
|
||||
- (id) filteredWithSelector:(SEL)selector andArgument:(id)argument
|
||||
{
|
||||
return [OOFilteringEnumerator filterEnumerator:self withSelector:selector andArgument:argument];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSArray (OOFilteringEnumerator)
|
||||
|
||||
- (id) objectEnumeratorFilteredWithSelector:(SEL)selector
|
||||
{
|
||||
return [[self objectEnumerator] filteredWithSelector:selector];
|
||||
}
|
||||
|
||||
|
||||
- (id) objectEnumeratorFilteredWithSelector:(SEL)selector andArgument:(id)argument
|
||||
{
|
||||
return [[self objectEnumerator] filteredWithSelector:selector andArgument:argument];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSSet (OOFilteringEnumerator)
|
||||
|
||||
- (id) objectEnumeratorFilteredWithSelector:(SEL)selector
|
||||
{
|
||||
return [[self objectEnumerator] filteredWithSelector:selector];
|
||||
}
|
||||
|
||||
|
||||
- (id) objectEnumeratorFilteredWithSelector:(SEL)selector andArgument:(id)argument
|
||||
{
|
||||
return [[self objectEnumerator] filteredWithSelector:selector andArgument:argument];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSDictionary (OOFilteringEnumerator)
|
||||
|
||||
- (id) objectEnumeratorFilteredWithSelector:(SEL)selector
|
||||
{
|
||||
return [[self objectEnumerator] filteredWithSelector:selector];
|
||||
}
|
||||
|
||||
|
||||
- (id) objectEnumeratorFilteredWithSelector:(SEL)selector andArgument:(id)argument
|
||||
{
|
||||
return [[self objectEnumerator] filteredWithSelector:selector andArgument:argument];
|
||||
}
|
||||
|
||||
|
||||
- (id) keyEnumeratorFilteredWithSelector:(SEL)selector
|
||||
{
|
||||
return [[self keyEnumerator] filteredWithSelector:selector];
|
||||
}
|
||||
|
||||
|
||||
- (id) keyEnumeratorFilteredWithSelector:(SEL)selector andArgument:(id)argument
|
||||
{
|
||||
return [[self keyEnumerator] filteredWithSelector:selector andArgument:argument];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSEnumerator (OOMakeObjectsPerformSelector)
|
||||
|
||||
- (void)makeObjectsPerformSelector:(SEL)selector
|
||||
{
|
||||
id object = nil;
|
||||
while ((object = [self nextObject]))
|
||||
{
|
||||
if (selector != NULL && [object respondsToSelector:selector])
|
||||
{
|
||||
[object performSelector:selector];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void)makeObjectsPerformSelector:(SEL)selector withObject:(id)argument
|
||||
{
|
||||
id object = nil;
|
||||
while ((object = [self nextObject]))
|
||||
{
|
||||
if (selector != NULL && [object respondsToSelector:selector])
|
||||
{
|
||||
[object performSelector:selector withObject:argument];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
@ -38,10 +38,6 @@ MA 02110-1301, USA.
|
||||
#include <OpenGL/glu.h>
|
||||
#include <OpenGL/glext.h>
|
||||
|
||||
typedef CGLContextObj OOOpenGLContext;
|
||||
#define OOOpenGLGetCurrentContext CGLGetCurrentContext
|
||||
#define OOOpenGLSetCurrentContext(ctx) (CGLSetCurrentContext(ctx) == kCGLNoError)
|
||||
|
||||
#elif OOLITE_SDL
|
||||
|
||||
// SDL OpenGL includes...
|
||||
@ -56,19 +52,6 @@ typedef CGLContextObj OOOpenGLContext;
|
||||
#include <GL/glext.h>
|
||||
|
||||
|
||||
/* FIXME: should probably use glXCopyContext() and glXMakeCurrent() on Linux;
|
||||
there should be an equivalent for Windows. This isn't very urgent since
|
||||
Oolite doesnt' use distinct contexts, though. I can't see an obvious SDL
|
||||
version, unfortunately.
|
||||
*/
|
||||
|
||||
typedef uintptr_t OOOpenGLContext; // Opaque context identifier
|
||||
// OOOpenGLContext OOOpenGLGetCurrentContext(void)
|
||||
#define OOOpenGLGetCurrentContext() ((OOOpenGLContextID)1UL)
|
||||
// BOOL OOOpenGLSetCurrentContext(OOOpenGLContext context)
|
||||
#define OOOpenGLSetCurrentContext(ctx) ((ctx) == 1UL)
|
||||
|
||||
|
||||
#else // Not OS X or SDL
|
||||
|
||||
#error OOOpenGL.h: unknown target!
|
||||
|
@ -79,15 +79,6 @@ SOFTWARE.
|
||||
#warning NO_SHADERS not defined and GL_ARB_vertex_shader not defined.
|
||||
#endif
|
||||
|
||||
// FIXME: are these last two relevant? Aren't they for the older "assembly-style" shaders?
|
||||
#ifndef GL_ARB_fragment_program
|
||||
#warning NO_SHADERS not defined and GL_ARB_fragment_program not defined.
|
||||
#endif
|
||||
|
||||
#ifndef GL_ARB_vertex_program
|
||||
#warning NO_SHADERS not defined and GL_ARB_vertex_program not defined.
|
||||
#endif
|
||||
|
||||
#endif //NO_SHADERS
|
||||
|
||||
|
||||
|
@ -296,8 +296,6 @@ static unsigned IntegerFromString(const GLubyte **ioString)
|
||||
@"GL_ARB_shading_language_100",
|
||||
@"GL_ARB_fragment_shader",
|
||||
@"GL_ARB_vertex_shader",
|
||||
@"GL_ARB_fragment_program",
|
||||
@"GL_ARB_vertex_program",
|
||||
nil // sentinel - don't remove!
|
||||
};
|
||||
NSString **required = NULL;
|
||||
@ -314,21 +312,21 @@ static unsigned IntegerFromString(const GLubyte **ioString)
|
||||
#if OOLITE_WINDOWS
|
||||
glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC)wglGetProcAddress("glGetObjectParameterivARB");
|
||||
glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)wglGetProcAddress("glCreateShaderObjectARB");
|
||||
glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC)wglGetProcAddress("glGetInfoLogARB");
|
||||
glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC)wglGetProcAddress("glGetInfoLogARB");
|
||||
glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)wglGetProcAddress("glCreateProgramObjectARB");
|
||||
glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)wglGetProcAddress("glAttachObjectARB");
|
||||
glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC)wglGetProcAddress("glDeleteObjectARB");
|
||||
glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)wglGetProcAddress("glLinkProgramARB");
|
||||
glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)wglGetProcAddress("glCompileShaderARB");
|
||||
glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)wglGetProcAddress("glShaderSourceARB");
|
||||
glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)wglGetProcAddress("glAttachObjectARB");
|
||||
glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC)wglGetProcAddress("glDeleteObjectARB");
|
||||
glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)wglGetProcAddress("glLinkProgramARB");
|
||||
glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)wglGetProcAddress("glCompileShaderARB");
|
||||
glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)wglGetProcAddress("glShaderSourceARB");
|
||||
glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)wglGetProcAddress("glUseProgramObjectARB");
|
||||
glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC)wglGetProcAddress("glActiveTextureARB");
|
||||
glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC)wglGetProcAddress("glActiveTextureARB");
|
||||
glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC)wglGetProcAddress("glGetUniformLocationARB");
|
||||
glUniform1iARB = (PFNGLUNIFORM1IARBPROC)wglGetProcAddress("glUniform1iARB");
|
||||
glUniform1fARB = (PFNGLUNIFORM1FARBPROC)wglGetProcAddress("glUniform1fARB");
|
||||
glUniform1iARB = (PFNGLUNIFORM1IARBPROC)wglGetProcAddress("glUniform1iARB");
|
||||
glUniform1fARB = (PFNGLUNIFORM1FARBPROC)wglGetProcAddress("glUniform1fARB");
|
||||
glUniformMatrix4fvARB = (PFNGLUNIFORMMATRIX4FVARBPROC)wglGetProcAddress("glUniformMatrix4fvARB");
|
||||
glUniform4fvARB = (PFNGLUNIFORM4FVARBPROC)wglGetProcAddress("glUniform4fvARB");
|
||||
glUniform2fvARB = (PFNGLUNIFORM2FVARBPROC)wglGetProcAddress("glUniform2fvARB");
|
||||
glUniform4fvARB = (PFNGLUNIFORM4FVARBPROC)wglGetProcAddress("glUniform4fvARB");
|
||||
glUniform2fvARB = (PFNGLUNIFORM2FVARBPROC)wglGetProcAddress("glUniform2fvARB");
|
||||
#endif
|
||||
|
||||
shadersAvailable = YES;
|
||||
|
@ -194,9 +194,7 @@ typedef enum
|
||||
|
||||
BEHAVIOUR_ENERGY_BOMB_COUNTDOWN = 601,
|
||||
|
||||
BEHAVIOUR_TRACTORED = 701,
|
||||
|
||||
BEHAVIOUR_EXPERIMENTAL = 54321
|
||||
BEHAVIOUR_TRACTORED = 701
|
||||
} OOBehaviour;
|
||||
|
||||
|
||||
|
@ -84,6 +84,7 @@ OOINLINE Vector fast_vector_normal(Vector vec) INLINE_CONST_FUNC;
|
||||
OOINLINE Vector unit_vector(const Vector *vec) NONNULL_FUNC INLINE_CONST_FUNC;
|
||||
/* Normalize vector, returning fallback if zero vector. */
|
||||
OOINLINE Vector vector_normal_or_fallback(Vector vec, Vector fallback) INLINE_CONST_FUNC;
|
||||
OOINLINE Vector vector_normal_or_zbasis(Vector vec) INLINE_CONST_FUNC;
|
||||
OOINLINE Vector fast_vector_normal_or_fallback(Vector vec, Vector fallback) INLINE_CONST_FUNC;
|
||||
|
||||
/* Square of distance between vectors */
|
||||
@ -229,6 +230,12 @@ OOINLINE Vector vector_normal_or_fallback(Vector vec, Vector fallback)
|
||||
}
|
||||
|
||||
|
||||
OOINLINE Vector vector_normal_or_zbasis(Vector vec)
|
||||
{
|
||||
return vector_normal_or_fallback(vec, kBasisZVector);
|
||||
}
|
||||
|
||||
|
||||
OOINLINE Vector vector_normal(Vector vec)
|
||||
{
|
||||
return vector_normal_or_fallback(vec, kZeroVector);
|
||||
|
@ -33,7 +33,7 @@ MA 02110-1301, USA.
|
||||
|
||||
@implementation Entity (OOJavaScriptExtensions)
|
||||
|
||||
- (BOOL)isVisibleToScripts
|
||||
- (BOOL) isVisibleToScripts
|
||||
{
|
||||
return self->isShip ||
|
||||
// self->isStation || // Stations are always ships
|
||||
@ -42,13 +42,13 @@ MA 02110-1301, USA.
|
||||
}
|
||||
|
||||
|
||||
- (NSString *)jsClassName
|
||||
- (NSString *) jsClassName
|
||||
{
|
||||
return @"Entity";
|
||||
}
|
||||
|
||||
|
||||
- (jsval)javaScriptValueInContext:(JSContext *)context
|
||||
- (jsval) javaScriptValueInContext:(JSContext *)context
|
||||
{
|
||||
JSClass *class = NULL;
|
||||
JSObject *prototype = NULL;
|
||||
@ -74,14 +74,14 @@ MA 02110-1301, USA.
|
||||
}
|
||||
|
||||
|
||||
- (void)getJSClass:(JSClass **)outClass andPrototype:(JSObject **)outPrototype
|
||||
- (void) getJSClass:(JSClass **)outClass andPrototype:(JSObject **)outPrototype
|
||||
{
|
||||
*outClass = JSEntityClass();
|
||||
*outPrototype = JSEntityPrototype();
|
||||
}
|
||||
|
||||
|
||||
- (void)deleteJSSelf
|
||||
- (void) deleteJSSelf
|
||||
{
|
||||
if (jsSelf != NULL)
|
||||
{
|
||||
@ -95,44 +95,26 @@ MA 02110-1301, USA.
|
||||
|
||||
@implementation ShipEntity (OOJavaScriptExtensions)
|
||||
|
||||
- (void)getJSClass:(JSClass **)outClass andPrototype:(JSObject **)outPrototype
|
||||
- (void) getJSClass:(JSClass **)outClass andPrototype:(JSObject **)outPrototype
|
||||
{
|
||||
*outClass = JSShipClass();
|
||||
*outPrototype = JSShipPrototype();
|
||||
}
|
||||
|
||||
|
||||
- (NSString *)jsClassName
|
||||
- (NSString *) jsClassName
|
||||
{
|
||||
return @"Ship";
|
||||
}
|
||||
|
||||
|
||||
- (NSArray *)subEntitiesForScript
|
||||
- (NSArray *) subEntitiesForScript
|
||||
{
|
||||
unsigned i, count;
|
||||
NSMutableArray *result = nil;
|
||||
id object = nil;
|
||||
|
||||
count = [sub_entities count];
|
||||
if (count == 0) return nil;
|
||||
|
||||
result = [NSMutableArray arrayWithCapacity:count];
|
||||
for (i = 0; i != count; ++i)
|
||||
{
|
||||
object = [sub_entities objectAtIndex:i];
|
||||
if ([object isKindOfClass:[ShipEntity class]])
|
||||
{
|
||||
[result addObject:object];
|
||||
}
|
||||
}
|
||||
|
||||
if ([result count] == 0) result = nil;
|
||||
return result;
|
||||
return [[self shipSubEntityEnumerator] allObjects];
|
||||
}
|
||||
|
||||
|
||||
- (NSArray *)escorts
|
||||
- (NSArray *) escorts
|
||||
{
|
||||
unsigned i;
|
||||
NSMutableArray *result = nil;
|
||||
@ -155,7 +137,7 @@ MA 02110-1301, USA.
|
||||
}
|
||||
|
||||
|
||||
- (void)setTargetForScript:(ShipEntity *)target
|
||||
- (void) setTargetForScript:(ShipEntity *)target
|
||||
{
|
||||
ShipEntity *me = self;
|
||||
|
||||
|
@ -367,8 +367,8 @@ enum
|
||||
- (Entity*) hazardOnRouteFromEntity:(Entity *) e1 toDistance:(double)dist fromPoint:(Vector) p2;
|
||||
- (Vector) getSafeVectorFromEntity:(Entity *) e1 toDistance:(double)dist fromPoint:(Vector) p2;
|
||||
|
||||
- (int) getFirstEntityHitByLaserFromEntity:(Entity *) e1 inView:(int) viewdir offset:(Vector) offset rangeFound:(GLfloat*)range_ptr;
|
||||
- (int) getFirstEntityTargettedByPlayer:(PlayerEntity*) player;
|
||||
- (OOUniversalID) getFirstEntityHitByLaserFromEntity:(ShipEntity *)srcEntity inView:(OOViewID)viewdir offset:(Vector)offset rangeFound:(GLfloat*)range_ptr;
|
||||
- (OOUniversalID) getFirstEntityTargettedByPlayer:(PlayerEntity *)player;
|
||||
|
||||
- (NSArray *) getEntitiesWithinRange:(double)range ofEntity:(Entity *)entity;
|
||||
- (unsigned) countShipsWithRole:(NSString *)role inRange:(double)range ofEntity:(Entity *)entity;
|
||||
|
@ -4401,58 +4401,58 @@ static BOOL MaintainLinkedLists(Universe* uni)
|
||||
}
|
||||
|
||||
|
||||
- (int) getFirstEntityHitByLaserFromEntity:(Entity *) e1 inView:(int) viewdir offset:(Vector) offset rangeFound:(GLfloat*)range_ptr
|
||||
- (OOUniversalID) getFirstEntityHitByLaserFromEntity:(ShipEntity *)srcEntity inView:(OOViewID)viewdir offset:(Vector)offset rangeFound:(GLfloat*)range_ptr
|
||||
{
|
||||
if (!e1)
|
||||
return NO_TARGET;
|
||||
if (srcEntity == nil) return NO_TARGET;
|
||||
|
||||
BOOL debug_laser = e1->isPlayer;
|
||||
|
||||
BOOL isSubentity = NO;
|
||||
ShipEntity *hit_entity = nil;
|
||||
ShipEntity *hit_subentity = nil;
|
||||
BOOL isSubentity = NO;
|
||||
ShipEntity *hit_entity = nil;
|
||||
ShipEntity *hit_subentity = nil;
|
||||
Vector p0 = [srcEntity position];
|
||||
Quaternion q1 = [srcEntity orientation];
|
||||
|
||||
Vector p0 = e1->position;
|
||||
Quaternion q1 = e1->orientation;
|
||||
if (e1->isPlayer)
|
||||
q1.w = -q1.w; // reverse for player viewpoint
|
||||
if ([srcEntity isPlayer]) q1.w = -q1.w; // reverse for player viewpoint
|
||||
|
||||
ShipEntity* parent = (ShipEntity*)[e1 owner];
|
||||
if ((e1->isShip)&&(parent)&&(parent != e1)&&(parent->isShip)&&([parent->sub_entities containsObject:e1]))
|
||||
{ // we're a subentity!
|
||||
BoundingBox bbox = [e1 boundingBox];
|
||||
ShipEntity *parent = [srcEntity owner];
|
||||
|
||||
if ([parent isShipWithSubEntityShip:srcEntity])
|
||||
{
|
||||
// we're a subentity!
|
||||
BoundingBox bbox = [srcEntity boundingBox];
|
||||
Vector midfrontplane = make_vector(0.5 * (bbox.max.x + bbox.min.x), 0.5 * (bbox.max.y + bbox.min.y), bbox.max.z);
|
||||
p0 = [(ShipEntity*)e1 absolutePositionForSubentityOffset:midfrontplane];
|
||||
q1 = parent->orientation;
|
||||
if (parent->isPlayer)
|
||||
q1.w = -q1.w;
|
||||
p0 = [srcEntity absolutePositionForSubentityOffset:midfrontplane];
|
||||
q1 = [parent orientation];
|
||||
if ([parent isPlayer]) q1.w = -q1.w;
|
||||
isSubentity = YES;
|
||||
}
|
||||
|
||||
int result = NO_TARGET;
|
||||
double nearest;
|
||||
if (e1->isShip)
|
||||
nearest = [(ShipEntity *)e1 weaponRange];
|
||||
else
|
||||
nearest = PARTICLE_LASER_LENGTH;
|
||||
int result = NO_TARGET;
|
||||
double nearest;
|
||||
|
||||
nearest = [srcEntity weaponRange];
|
||||
|
||||
int i;
|
||||
int ent_count = n_entities;
|
||||
int ship_count = 0;
|
||||
ShipEntity *my_entities[ent_count];
|
||||
|
||||
int i;
|
||||
int ent_count = n_entities;
|
||||
int ship_count = 0;
|
||||
ShipEntity* my_entities[ent_count];
|
||||
for (i = 0; i < ent_count; i++)
|
||||
{
|
||||
Entity* ent = sortedEntities[i];
|
||||
if ((ent->isShip) && (ent != e1) && (ent != parent) && [ent canCollide])
|
||||
my_entities[ship_count++] = [ent retain]; // retained
|
||||
if (ent != srcEntity && ent != parent && [ent isShip] && [ent canCollide])
|
||||
{
|
||||
my_entities[ship_count++] = [ent retain];
|
||||
}
|
||||
}
|
||||
|
||||
Vector u1 = vector_up_from_quaternion(q1);
|
||||
Vector f1 = vector_forward_from_quaternion(q1);
|
||||
Vector r1 = vector_right_from_quaternion(q1);
|
||||
Vector u1 = vector_up_from_quaternion(q1);
|
||||
Vector f1 = vector_forward_from_quaternion(q1);
|
||||
Vector r1 = vector_right_from_quaternion(q1);
|
||||
|
||||
p0.x += offset.x * r1.x + offset.y * u1.x + offset.z * f1.x;
|
||||
p0.y += offset.x * r1.y + offset.y * u1.y + offset.z * f1.y;
|
||||
p0.z += offset.x * r1.z + offset.y * u1.z + offset.z * f1.z;
|
||||
|
||||
switch (viewdir)
|
||||
{
|
||||
case VIEW_AFT :
|
||||
@ -4464,17 +4464,19 @@ static BOOL MaintainLinkedLists(Universe* uni)
|
||||
case VIEW_STARBOARD :
|
||||
quaternion_rotate_about_axis(&q1, u1, -M_PI/2.0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
f1 = vector_forward_from_quaternion(q1);
|
||||
r1 = vector_right_from_quaternion(q1);
|
||||
|
||||
Vector p1 = make_vector(p0.x + nearest *f1.x, p0.y + nearest *f1.y, p0.z + nearest *f1.z); //endpoint
|
||||
|
||||
for (i = 0; i < ship_count; i++)
|
||||
{
|
||||
ShipEntity *e2 = my_entities[i];
|
||||
|
||||
debug_laser = ((e1->isPlayer) && ([(ShipEntity*)e1 primaryTargetID] == [e2 universalID]));
|
||||
|
||||
// check outermost bounding sphere
|
||||
GLfloat cr = e2->collision_radius;
|
||||
Vector rpos = vector_between(p0, e2->position);
|
||||
@ -4494,8 +4496,10 @@ static BOOL MaintainLinkedLists(Universe* uni)
|
||||
|
||||
if ((hit > 0.0)&&(hit < nearest))
|
||||
{
|
||||
if (entHit->isSubentity)
|
||||
if ([entHit isSubEntity])
|
||||
{
|
||||
hit_subentity = entHit;
|
||||
}
|
||||
hit_entity = e2;
|
||||
nearest = hit;
|
||||
p1 = make_vector(p0.x + nearest *f1.x, p0.y + nearest *f1.y, p0.z + nearest *f1.z);
|
||||
@ -4504,25 +4508,25 @@ static BOOL MaintainLinkedLists(Universe* uni)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (hit_entity)
|
||||
{
|
||||
result = [hit_entity universalID];
|
||||
if ((hit_subentity)&&[hit_entity->sub_entities containsObject:hit_subentity])
|
||||
hit_entity->subentity_taking_damage = hit_subentity;
|
||||
if (range_ptr != (GLfloat *)nil)
|
||||
if (hit_subentity) [hit_entity setSubEntityTakingDamage:hit_subentity];
|
||||
|
||||
if (range_ptr != NULL)
|
||||
{
|
||||
range_ptr[0] = (GLfloat)nearest;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < ship_count; i++)
|
||||
[my_entities[i] release]; // released
|
||||
for (i = 0; i < ship_count; i++) [my_entities[i] release]; // released
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
- (int) getFirstEntityTargettedByPlayer:(PlayerEntity*) player
|
||||
- (OOUniversalID) getFirstEntityTargettedByPlayer:(PlayerEntity*) player
|
||||
{
|
||||
if ((!player)||(!player->isPlayer))
|
||||
return NO_TARGET;
|
||||
@ -7935,7 +7939,10 @@ static NSComparisonResult comparePrice(NSDictionary *dict1, NSDictionary *dict2,
|
||||
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
|
||||
/* 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"])
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user