| 1 | /* |
|---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
|---|
| 3 | |
|---|
| 4 | Copyright (C) 2004 orx |
|---|
| 5 | |
|---|
| 6 | This program is free software; you can redistribute it and/or modify |
|---|
| 7 | it under the terms of the GNU General Public License as published by |
|---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
|---|
| 9 | any later version. |
|---|
| 10 | |
|---|
| 11 | ### File Specific: |
|---|
| 12 | main-programmer: ... |
|---|
| 13 | co-programmer: ... |
|---|
| 14 | */ |
|---|
| 15 | |
|---|
| 16 | //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY |
|---|
| 17 | |
|---|
| 18 | #include "physics_engine.h" |
|---|
| 19 | |
|---|
| 20 | #include "list.h" |
|---|
| 21 | |
|---|
| 22 | using namespace std; |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | /** |
|---|
| 26 | \brief standard constructor |
|---|
| 27 | */ |
|---|
| 28 | PhysicsEngine::PhysicsEngine() |
|---|
| 29 | { |
|---|
| 30 | this->setClassName ("PhysicsEngine"); |
|---|
| 31 | |
|---|
| 32 | this->connections = new tList<PhysicsConnection>; |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | /** |
|---|
| 36 | \brief the singleton reference to this class |
|---|
| 37 | */ |
|---|
| 38 | PhysicsEngine* PhysicsEngine::singletonRef = NULL; |
|---|
| 39 | |
|---|
| 40 | /** |
|---|
| 41 | \returns a Pointer to this Class |
|---|
| 42 | */ |
|---|
| 43 | PhysicsEngine* PhysicsEngine::getInstance(void) |
|---|
| 44 | { |
|---|
| 45 | if (!PhysicsEngine::singletonRef) |
|---|
| 46 | PhysicsEngine::singletonRef = new PhysicsEngine(); |
|---|
| 47 | return PhysicsEngine::singletonRef; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | /** |
|---|
| 51 | \brief standard deconstructor |
|---|
| 52 | |
|---|
| 53 | */ |
|---|
| 54 | PhysicsEngine::~PhysicsEngine () |
|---|
| 55 | { |
|---|
| 56 | PhysicsEngine::singletonRef = NULL; |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | /** |
|---|
| 60 | \brief adds A Physical Connection to the List of Connections |
|---|
| 61 | \param connection the Connection to add |
|---|
| 62 | |
|---|
| 63 | Usually this is done through the constructor of PhysicshConnections |
|---|
| 64 | */ |
|---|
| 65 | void PhysicsEngine::addConnection(PhysicsConnection* connection) |
|---|
| 66 | { |
|---|
| 67 | this->connections->add(connection); |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | /** |
|---|
| 71 | \brief removes A Physical Connection from the List of Connections |
|---|
| 72 | \param connection the Connection to remove |
|---|
| 73 | |
|---|
| 74 | Usually this is done through the destructor of PhysicsConnections |
|---|
| 75 | */ |
|---|
| 76 | void PhysicsEngine::removeConnection(PhysicsConnection* connection) |
|---|
| 77 | { |
|---|
| 78 | this->connections->remove(connection); |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | /** |
|---|
| 86 | \brief Steps through all the Connections and Ticks them |
|---|
| 87 | \param dt The time Passed in Seconds |
|---|
| 88 | |
|---|
| 89 | This function brings a flow into the whole animation |
|---|
| 90 | */ |
|---|
| 91 | void PhysicsEngine::tick(float dt) |
|---|
| 92 | { |
|---|
| 93 | tIterator<PhysicsConnection>* iterator = this->connections->getIterator(); |
|---|
| 94 | PhysicsConnection* enumConn = iterator->nextElement(); |
|---|
| 95 | while (enumConn) |
|---|
| 96 | { |
|---|
| 97 | enumConn->apply(dt); |
|---|
| 98 | enumConn = iterator->nextElement(); |
|---|
| 99 | } |
|---|
| 100 | delete iterator; |
|---|
| 101 | } |
|---|