Removed one memory leak.
authorsaiam
Thu, 04 Dec 2008 22:59:13 +0000
changeset 204 4c386e9c950f
parent 203 3ec7ab40755f
child 205 905028e58ed1
Removed one memory leak.
src/PhysicsWorld.cc
src/Player.cc
src/Projectile.cc
src/Projectile.hh
src/Terrain.cc
--- a/src/PhysicsWorld.cc	Thu Dec 04 22:33:43 2008 +0000
+++ b/src/PhysicsWorld.cc	Thu Dec 04 22:59:13 2008 +0000
@@ -22,7 +22,16 @@
  * Function pointer used to clear the projectile list
  * from those that have already been destroyd.
  */
-bool isDestroyedProjectile (Projectile* po) { return (*po).isDestroyed(); }
+bool isDestroyedProjectile (Projectile* po) { 
+    //    return po->isDestroyed();
+    if (po->isDestroyed()) {
+        Engine::log(DEBUG, "PhysicsWorld.isDestroyedProjectile") << "Destroying projectile: " << po;
+        delete po;
+        return true;
+    } else {
+        return false;
+    }
+}
 
 void PhysicsWorld::tick () {
     //    Engine::log(DEBUG, "physics.apply_force") << "*tick*";
--- a/src/Player.cc	Thu Dec 04 22:33:43 2008 +0000
+++ b/src/Player.cc	Thu Dec 04 22:59:13 2008 +0000
@@ -29,7 +29,7 @@
     float shotspeed = 100*PHYSICS_TICK_MS;
     Vector shotRelativeVelocity = unitVectorAim * shotspeed;
     Vector shotVelocity = this->velocity + shotRelativeVelocity;
-    world.addProjectile(new Projectile(this->state, this->position, shotVelocity, true));
+    new Projectile(this->state, this->position, shotVelocity, true);
 }
 
 void Player::handleMove (PlayerInput_Move input) {
--- a/src/Projectile.cc	Thu Dec 04 22:33:43 2008 +0000
+++ b/src/Projectile.cc	Thu Dec 04 22:59:13 2008 +0000
@@ -26,7 +26,7 @@
 
 void Projectile::draw(CL_GraphicContext *gc) {
 
-
+  
     CL_Quad player(
                    (int)((position).x+1), (int)((position).y+1),
                    (int)((position).x-1), (int)((position).y+1),
--- a/src/Projectile.hh	Thu Dec 04 22:33:43 2008 +0000
+++ b/src/Projectile.hh	Thu Dec 04 22:59:13 2008 +0000
@@ -16,6 +16,7 @@
     bool destroyed;
 public:
     Projectile(GameState &state, Vector position, Vector velocity, bool visible);
+    ~Projectile() {};
 
     bool isDestroyed (void);
     virtual void draw(CL_GraphicContext *gc);
--- a/src/Terrain.cc	Thu Dec 04 22:33:43 2008 +0000
+++ b/src/Terrain.cc	Thu Dec 04 22:59:13 2008 +0000
@@ -61,8 +61,7 @@
 }
 
 bool Terrain::collides(const Vector &point) const {
-    Vector coor = getPixelLocation(point);
-    return (getType(coor.x, coor.y) != EMPTY);
+    return (getType(point) != EMPTY);
 }
 
 bool Terrain::collides(const Vector &begin, const Vector &end) const {