author | terom |
Sun, 07 Dec 2008 21:10:04 +0000 | |
changeset 263 | 8c999cf4c182 |
parent 255 | 99431fdb0dc8 |
child 282 | e0e4dfc3e528 |
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) : |
255
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
225
diff
changeset
|
8 |
Terrain(dimensions.x, dimensions.y, 1337), tick_timer(PHYSICS_TICK_MS), dimensions(dimensions), gravity(gravity) |
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
|
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) { |
255
99431fdb0dc8
add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents:
225
diff
changeset
|
23 |
// tick each object in turn |
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
|
24 |
for (std::list<PhysicsObject*>::iterator i = objects.begin(); i != objects.end(); 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 |