author | ekku |
Sat, 06 Dec 2008 19:38:01 +0000 | |
changeset 225 | 22ecb9cb9245 |
parent 222 | 293ddf4c067d |
child 255 | 99431fdb0dc8 |
permissions | -rw-r--r-- |
197 | 1 |
|
2 |
#include "PhysicsWorld.hh" |
|
3 |
#include "Engine.hh" |
|
4 |
||
222
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
208
diff
changeset
|
5 |
#include <functional> |
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
208
diff
changeset
|
6 |
|
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
208
diff
changeset
|
7 |
PhysicsWorld::PhysicsWorld (Vector gravity, Vector dimensions) : |
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
208
diff
changeset
|
8 |
Terrain(1337), tick_timer(PHYSICS_TICK_MS), dimensions(dimensions), gravity(gravity) |
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
208
diff
changeset
|
9 |
{ |
205 | 10 |
slots.connect(tick_timer.sig_tick(), this, &PhysicsWorld::tick); |
11 |
tick_timer.start(); |
|
197 | 12 |
} |
13 |
||
222
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
208
diff
changeset
|
14 |
void PhysicsWorld::addPhysicsObject (PhysicsObject *po) { |
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
208
diff
changeset
|
15 |
objects.push_back(po); |
197 | 16 |
} |
17 |
||
225 | 18 |
void PhysicsWorld::removePhysicsObject (PhysicsObject *po) { |
19 |
objects.remove(po); |
|
20 |
} |
|
197 | 21 |
|
205 | 22 |
void PhysicsWorld::tick (TimeMS tick_length) { |
222
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
208
diff
changeset
|
23 |
for (std::list<PhysicsObject*>::iterator i = objects.begin(); i != objects.end(); i++) { |
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
208
diff
changeset
|
24 |
// Engine::log(DEBUG, "PhysicsWorld.tick") << (*i); |
205 | 25 |
(*i)->tick(tick_length); |
197 | 26 |
} |
27 |
||
222
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
208
diff
changeset
|
28 |
// Delete destroyed objects |
293ddf4c067d
reorganize PhysicsObject/Player/Projectile lists so that PhysicsObject doesn't need to know about its subclasses anymore, and PhysicsWorld doesn't need to know about GameState
ekku
parents:
208
diff
changeset
|
29 |
objects.remove_if(std::mem_fun(&PhysicsObject::removeIfDestroyed)); |
197 | 30 |
} |
31 |