Made forceq to contain time again.
--- 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) {
--- a/src/PhysicsObject.hh Sun Dec 07 23:27:20 2008 +0000
+++ b/src/PhysicsObject.hh Mon Dec 08 00:05:45 2008 +0000
@@ -2,6 +2,7 @@
#define PHYSICS_OBJECT_HH
#include <ClanLib/display.h>
+#include <utility>
// Forward declares
class PhysicsObject;
@@ -54,7 +55,7 @@
*
* @param force Force vector
*/
- void applyForce(Force force);
+ void applyForce(Force force, TimeMS dt = PHYSICS_TICK_MS);
/**
* Change player aim
@@ -109,7 +110,7 @@
std::vector<Vector> shape;
// Force queue that is emptied on every tick
- std::queue<Force> forceq;
+ std::queue<std::pair<Force, TimeMS> > forceq;
/**
* Handle player movement and apply forces.
--- a/src/Rope.cc Sun Dec 07 23:27:20 2008 +0000
+++ b/src/Rope.cc Mon Dec 08 00:05:45 2008 +0000
@@ -37,7 +37,7 @@
player.handleRopeState(state);
}
-void Rope::onCollision (Vector collisionPoint) {
+void Rope::onCollision (Vector collisionPoint, PhysicsObject *other) {
// attached to something!
state = ROPE_FIXED;
--- a/src/Rope.hh Sun Dec 07 23:27:20 2008 +0000
+++ b/src/Rope.hh Mon Dec 08 00:05:45 2008 +0000
@@ -16,68 +16,68 @@
};
class Rope : public PhysicsObject {
- private:
- // the owner
- Player &player;
-
- // How long is the rope in its unstrected state
- float length;
-
- // basic state
- RopeState state;
-
- protected:
- /**
- * Attach the rope, so disable the PhysicsObject and change state
- * @param collisionPoint Where the rope has hit the ground.
- */
- virtual void onCollision (Vector collisionPoint);
-
- /*
- * If the rope is currently longer than length, this returns ROPE_FORCE, else 0
- */
- virtual float getPivotForce (PhysicsObject *bob);
-
- public:
- Rope(Player &player);
-
- /*
- * Throw the rope, so it flies up and away: o._-*
- */
- void throwRope (void);
+private:
+ // the owner
+ Player &player;
- /*
- * Release the rope, so if it's currently fixed or flying, then fold it
- */
- void release (void);
-
- /*
- * Climb up/down the rope
- */
- void changeLength (float delta);
+ // How long is the rope in its unstrected state
+ float length;
- /*
- * Current state
- */
- RopeState getState (void);
+ // basic state
+ RopeState state;
+
+protected:
+ /**
+ * Attach the rope, so disable the PhysicsObject and change state
+ * @param collisionPoint Where the rope has hit the ground.
+ */
+ virtual void onCollision (Vector collisionPoint, PhysicsObject *other);
- /*
- * Current length
- */
- float getLength (void);
+ /*
+ * If the rope is currently longer than length, this returns ROPE_FORCE, else 0
+ */
+ virtual float getPivotForce (PhysicsObject *bob);
- /*
- * For use by NetworkClient
- */
- void updateState (RopeState state, Vector position, Vector velocity, float length);
- void updateLength (float length);
+public:
+ Rope(Player &player);
- virtual void tick (TimeMS dt);
+ /*
+ * Throw the rope, so it flies up and away: o._-*
+ */
+ void throwRope (void);
- /*
- * Just draws it
- */
- virtual void draw (Graphics *c, PixelCoordinate camera);
+ /*
+ * Release the rope, so if it's currently fixed or flying, then fold it
+ */
+ void release (void);
+
+ /*
+ * Climb up/down the rope
+ */
+ void changeLength (float delta);
+
+ /*
+ * Current state
+ */
+ RopeState getState (void);
+
+ /*
+ * Current length
+ */
+ float getLength (void);
+
+ /*
+ * For use by NetworkClient
+ */
+ void updateState (RopeState state, Vector position, Vector velocity, float length);
+ void updateLength (float length);
+
+ virtual void tick (TimeMS dt);
+
+ /*
+ * Just draws it
+ */
+ virtual void draw (Graphics *c, PixelCoordinate camera);
};
#endif