reached += ++
authornireco
Tue, 02 Dec 2008 00:20:58 +0000
changeset 173 4251f8fa447d
parent 172 51b470384ad9
child 174 073f25a84f60
reached += ++
src/proto2/Physics.cc
--- a/src/proto2/Physics.cc	Mon Dec 01 23:58:34 2008 +0000
+++ b/src/proto2/Physics.cc	Tue Dec 02 00:20:58 2008 +0000
@@ -98,6 +98,10 @@
     return true;
 }
 
+void func1() {
+
+}
+
 /**
  * Updates object speed and position. This function organises force
  * integration and collision detection.
@@ -128,6 +132,10 @@
 //        return;
     }
 
+    if(!possibleLocation(position)) {
+        Engine::log(DEBUG, "great failure") << "great failure";
+        func1();
+    }
     if (!this->inAir) {
         if (total.x != 0)
             this->position = walk(total.x > 0);
@@ -135,6 +143,10 @@
         //total.x = 0;
     }
 
+    if(!possibleLocation(position)) {
+        Engine::log(DEBUG, "great failure") << "great failure";
+        func1();
+    }
     Vector newPosition;
     Vector velAfterTick;
     integrate(total, PHYSICS_TICK_MS, newPosition, velAfterTick);
@@ -149,6 +161,7 @@
     Vector reached = position;
 
     while ((position-reached).sqrLength() < diffVec.sqrLength()) {
+        reached += unitVector;
         // Check if any of the shapes points collide
         for (uint64_t i = 0; i < shape.size(); i++) {
             if (world.getType(reached+shape[i]) != EMPTY) {  // Collision
@@ -172,10 +185,14 @@
         }
         if (collided)
             break;
-        reached += unitVector;
+//        reached += unitVector;
     }
    
     
+    if(!possibleLocation(reached)) {
+        Engine::log(DEBUG, "PhysicsObject.updatePosition") << "logic error reached should not be possible to be impossible.. diffVec: " << diffVec;
+        func1();
+    }
 
     // In case of some float error check the final coordinate
     if(!collided) {
@@ -190,7 +207,15 @@
         //this->velocity = Vector(0, 0);
         //TODO: it shouldn't just stop on collision
     }
+    if(!possibleLocation(newPosition)) {
+        Engine::log(DEBUG, "great failure") << "great failure";
+        func1();
+    }
     this->position = newPosition;
+    if(!possibleLocation(position)) {
+        Engine::log(DEBUG, "great failure") << "great failure";
+        func1();
+    }
 //    Engine::log(DEBUG, "PhysicsObject.updatePosition") << "Pos: " << this->position;
 }