[3954] | 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 | |
---|
[4183] | 16 | //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY |
---|
[3954] | 17 | |
---|
[4121] | 18 | #include "physics_engine.h" |
---|
[3954] | 19 | |
---|
[4183] | 20 | #include "list.h" |
---|
[3954] | 21 | |
---|
| 22 | using namespace std; |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | /** |
---|
| 26 | \brief standard constructor |
---|
| 27 | */ |
---|
[4183] | 28 | PhysicsEngine::PhysicsEngine() |
---|
[3954] | 29 | { |
---|
[4121] | 30 | this->setClassName ("PhysicsEngine"); |
---|
[4183] | 31 | |
---|
| 32 | this->connections = new tList<PhysicsConnection>; |
---|
[3954] | 33 | } |
---|
| 34 | |
---|
[4183] | 35 | /** |
---|
| 36 | \brief the singleton reference to this class |
---|
| 37 | */ |
---|
| 38 | PhysicsEngine* PhysicsEngine::singletonRef = NULL; |
---|
[3954] | 39 | |
---|
| 40 | /** |
---|
[4183] | 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 | /** |
---|
[3954] | 51 | \brief standard deconstructor |
---|
| 52 | |
---|
| 53 | */ |
---|
[4121] | 54 | PhysicsEngine::~PhysicsEngine () |
---|
[3954] | 55 | { |
---|
[4183] | 56 | PhysicsEngine::singletonRef = NULL; |
---|
[3954] | 57 | } |
---|
| 58 | |
---|
| 59 | /** |
---|
[4183] | 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 | } |
---|
[3954] | 69 | |
---|
[4183] | 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 |
---|
[3954] | 75 | */ |
---|
[4183] | 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 | { |
---|
[4186] | 97 | enumConn->apply(dt); |
---|
[4183] | 98 | enumConn = iterator->nextElement(); |
---|
| 99 | } |
---|
| 100 | delete iterator; |
---|
| 101 | } |
---|
[4378] | 102 | |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | /** |
---|
| 106 | \brief print out interesting debug information of this class |
---|
| 107 | */ |
---|
| 108 | void PhysicsEngine::debug(void) const |
---|
| 109 | { |
---|
| 110 | PRINT(0)("====================================\n"); |
---|
| 111 | PRINT(0)("= Physics-Engine debug information =\n"); |
---|
| 112 | PRINT(0)("====================================\n"); |
---|
| 113 | PRINT(0)(" reference: %p\n", this); |
---|
| 114 | PRINT(0)(" numbers of Connections: %d\n", this->connections->getSize()); |
---|
| 115 | |
---|
| 116 | PRINT(0)("==============================PHYS==\n"); |
---|
| 117 | } |
---|