src/PhysicsObject.cc
changeset 273 eeb699e1d908
parent 272 97de051edbcf
child 275 fa44b905bc2e
--- a/src/PhysicsObject.cc	Sun Dec 07 23:27:20 2008 +0000
+++ b/src/PhysicsObject.cc	Mon Dec 08 00:05:45 2008 +0000
@@ -1,8 +1,9 @@
-
 #include "PhysicsObject.hh"
 #include "Engine.hh"
 
 #include <cmath>
+#include <utility>
+#include <queue>
 
 PhysicsObject::PhysicsObject (PhysicsWorld &world, float mass, Vector position, Vector velocity, ObjectType type, bool enabled) :
     world(world), position(position), velocity(velocity), mass(mass), inAir(true), aim(0), facing(FACING_RIGHT), 
@@ -113,7 +114,7 @@
  */   
 void PhysicsObject::updatePosition (TimeMS dt) {
     // Add gravity to the force queue
-    forceq.push(world.gravity);
+    applyForce(world.gravity);
     
     // If the object (practically player) has a pivot point add
     // a force towards that
@@ -123,14 +124,23 @@
         float length = direction.length();
         if (length > 0) {
             direction = direction / length * magnitude;
-            forceq.push(direction);
+            applyForce(direction);
         }
     }
+
+    std::pair<Force, TimeMS> force;
+    std::queue<std::pair<Force, TimeMS> > newfq;
     Force total;
     while (!forceq.empty()) {
-        total += forceq.front();
+        force = forceq.front();
+        if (force.second > PHYSICS_TICK_MS) {
+            force.second -= PHYSICS_TICK_MS;
+            newfq.push(force);
+        }
+        total += force.first;
         forceq.pop();
     }
+    forceq = newfq;
 
     // If the player has stopped and there's some ground under some of the 3 some of the 3t
     // set inAir false
@@ -286,9 +296,9 @@
     return (force/mass);
 }
 
-void PhysicsObject::applyForce (Force force) {
+void PhysicsObject::applyForce (Force force, TimeMS dt) {
     // Add applied force to the queue
-    forceq.push(force);
+    forceq.push(std::make_pair(force, dt));
 }
 
 void PhysicsObject::changeAim(float da) {