From 7da10a764a68fe118ed386dee4dd7cb8565e428e Mon Sep 17 00:00:00 2001 From: Jens Ayton Date: Fri, 4 Feb 2011 20:13:56 +0000 Subject: [PATCH] Cleanup, coupled with complete failure to fix leaks. git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@4229 127b21dd-08f5-0310-b4b7-95ae10353056 --- src/Core/Entities/OOLaserShotEntity.h | 3 ++- src/Core/Entities/OOLaserShotEntity.m | 18 ++++++++++----- src/Core/Entities/ParticleEntity.h | 1 - src/Core/Entities/ShipEntity.m | 13 ++++------- src/Core/Universe.m | 33 ++++++++++++++------------- 5 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/Core/Entities/OOLaserShotEntity.h b/src/Core/Entities/OOLaserShotEntity.h index 8b167d21..2f84ca18 100644 --- a/src/Core/Entities/OOLaserShotEntity.h +++ b/src/Core/Entities/OOLaserShotEntity.h @@ -37,9 +37,10 @@ MA 02110-1301, USA. @private GLfloat _color[4]; OOTimeDelta _lifetime; + GLfloat _range; } -- (id) initLaserFromShip:(ShipEntity *)ship view:(OOViewID)view offset:(Vector)offset; ++ (id) laserFromShip:(ShipEntity *)ship view:(OOViewID)view offset:(Vector)offset; - (void) setColor:(OOColor *)color; diff --git a/src/Core/Entities/OOLaserShotEntity.m b/src/Core/Entities/OOLaserShotEntity.m index a61b763d..80fa04ff 100644 --- a/src/Core/Entities/OOLaserShotEntity.m +++ b/src/Core/Entities/OOLaserShotEntity.m @@ -98,7 +98,7 @@ MA 02110-1301, USA. position = vector_add(pos, viewOffset); [self setOrientation:q]; - [self setCollisionRadius:[srcEntity weaponRange]]; + _range = [srcEntity weaponRange]; [self setOwner:ship]; _color[0] = kLaserRed; @@ -112,6 +112,12 @@ MA 02110-1301, USA. } ++ (id) laserFromShip:(ShipEntity *)ship view:(OOViewID)view offset:(Vector)offset +{ + return [[[self alloc] initLaserFromShip:ship view:view offset:offset] autorelease]; +} + + - (void) dealloc { [self setColor:nil]; @@ -173,15 +179,15 @@ static const GLfloat kLaserVertices[] = OOGL(glEnableClientState(GL_VERTEX_ARRAY)); - /* FIXME: ideally, collision_radius would be updated by tracing along the - initial firing vector. Even ideallier, we should spread damage across - the lifetime of the shot, hurting whatever is hit in a given frame. - Something for EMMSTRAN. + /* FIXME: ideally, _range would be updated by tracing along the initial + firing vector (or the initial vector relative to the owner). Even + ideallier, we should spread damage across the lifetime of the shot, + hurting whatever is hit in a given frame. Something for EMMSTRAN. -- Ahruman 2011-01-31 */ OOGL(glColor4fv(_color)); - glScaled(kLaserHalfWidth, kLaserHalfWidth, collision_radius); + glScaled(kLaserHalfWidth, kLaserHalfWidth, _range); glVertexPointer(3, GL_FLOAT, 0, kLaserVertices); glDrawArrays(GL_QUADS, 0, 8); diff --git a/src/Core/Entities/ParticleEntity.h b/src/Core/Entities/ParticleEntity.h index 73ae3585..9c4f69f8 100644 --- a/src/Core/Entities/ParticleEntity.h +++ b/src/Core/Entities/ParticleEntity.h @@ -57,7 +57,6 @@ MA 02110-1301, USA. NSSize size; } -//- (id) initLaserFromShip:(ShipEntity *) ship view:(OOViewID) view offset:(Vector)offset; - (id) initEnergyMineFromShip:(ShipEntity *) ship; - (id) initHyperringFromShip:(ShipEntity *) ship; - (id) initFragburstSize:(GLfloat) fragSize fromPosition:(Vector) fragPos; diff --git a/src/Core/Entities/ShipEntity.m b/src/Core/Entities/ShipEntity.m index 382de45a..44137241 100644 --- a/src/Core/Entities/ShipEntity.m +++ b/src/Core/Entities/ShipEntity.m @@ -4183,6 +4183,7 @@ static GLfloat scripted_color[4] = { 0.0, 0.0, 0.0, 0.0}; // to be defined by s else [self deactivateCloakingDevice]; } + - (BOOL)hasAutoCloak { return cloakAutomatic; @@ -4225,10 +4226,9 @@ static GLfloat scripted_color[4] = { 0.0, 0.0, 0.0, 0.0}; // to be defined by s setUpShipFromDictionary:, when the mesh is initially set up. -- Ahruman 2008-04-19 */ - OODrawable *drawable_ = [self drawable]; if (isSubEntity) { - [drawable_ setBindingTarget:self]; + [[self drawable] setBindingTarget:self]; } } @@ -7506,7 +7506,7 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q ShipEntity *victim = [UNIVERSE getFirstShipHitByLaserFromShip:self inView:direction offset: make_vector(0,0,0) rangeFound: &hit_at_range]; [self setShipHitByLaser:victim]; - shot = [[OOLaserShotEntity alloc] initLaserFromShip:self view:direction offset:kZeroVector]; + shot = [OOLaserShotEntity laserFromShip:self view:direction offset:kZeroVector]; [shot setColor:laser_color]; [shot setScanClass: CLASS_NO_DRAW]; @@ -7535,7 +7535,6 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q } [UNIVERSE addEntity:shot]; - [shot release]; [self resetShotTime]; @@ -7570,7 +7569,7 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q Vector vel = vector_multiply_scalar(v_forward, flightSpeed); // do special effects laser line - shot = [[OOLaserShotEntity alloc] initLaserFromShip:self view:VIEW_FORWARD offset:kZeroVector]; + shot = [OOLaserShotEntity laserFromShip:self view:VIEW_FORWARD offset:kZeroVector]; [shot setColor:laser_color]; [shot setScanClass: CLASS_NO_DRAW]; [shot setPosition: position]; @@ -7602,7 +7601,6 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q } [UNIVERSE addEntity:shot]; - [shot release]; [self resetShotTime]; @@ -7645,7 +7643,7 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q ShipEntity *victim = [UNIVERSE getFirstShipHitByLaserFromShip:self inView:direction offset:laserPortOffset rangeFound: &hit_at_range]; [self setShipHitByLaser:victim]; - shot = [[OOLaserShotEntity alloc] initLaserFromShip:self view:direction offset:laserPortOffset]; // alloc retains! + shot = [OOLaserShotEntity laserFromShip:self view:direction offset:laserPortOffset]; [shot setColor:laser_color]; [shot setScanClass: CLASS_NO_DRAW]; @@ -7684,7 +7682,6 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q } [UNIVERSE addEntity:shot]; - [shot release]; //release [self resetShotTime]; diff --git a/src/Core/Universe.m b/src/Core/Universe.m index 3c27a356..cfe15743 100644 --- a/src/Core/Universe.m +++ b/src/Core/Universe.m @@ -5007,28 +5007,28 @@ OOINLINE BOOL EntityInRange(Vector p1, Entity *e2, float range) if (!no_update) { + unsigned i, ent_count = n_entities; + Entity *my_entities[ent_count]; + + // use a retained copy so this can't be changed under us. + for (i = 0; i < ent_count; i++) + { + my_entities[i] = [sortedEntities[i] retain]; // explicitly retain each one + } + NSString * volatile update_stage = @"initialisation"; #ifndef NDEBUG id volatile update_stage_param = nil; #endif NS_DURING - int i; - PlayerEntity* player = PLAYER; - int ent_count = n_entities; - Entity* my_entities[ent_count]; + PlayerEntity *player = PLAYER; skyClearColor[0] = 0.0; skyClearColor[1] = 0.0; skyClearColor[2] = 0.0; skyClearColor[3] = 0.0; - // use a retained copy so this can't be changed under us. - for (i = 0; i < ent_count; i++) - { - my_entities[i] = [sortedEntities[i] retain]; // explicitly retain each one - } - time_delta = delta_t; universal_time += delta_t; @@ -5207,12 +5207,6 @@ OOINLINE BOOL EntityInRange(Vector p1, Entity *e2, float range) MaintainLinkedLists(self); doLinkedListMaintenanceThisUpdate = NO; } - - // dispose of the non-mutable copy and everything it references neatly - - update_stage = @"clean up"; - for (i = 0; i < ent_count; i++) - [my_entities[i] release]; // explicitly release each one NS_HANDLER if ([[localException name] hasPrefix:@"Oolite"]) @@ -5226,6 +5220,13 @@ OOINLINE BOOL EntityInRange(Vector p1, Entity *e2, float range) [localException raise]; } NS_ENDHANDLER + + // dispose of the non-mutable copy and everything it references neatly + update_stage = @"clean up"; + for (i = 0; i < ent_count; i++) + { + [my_entities[i] release]; // explicitly release each one + } } [entitiesDeadThisUpdate autorelease];