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_PHYSICS |
---|
17 | |
---|
18 | #include "physics_engine.h" |
---|
19 | |
---|
20 | #include "debug.h" |
---|
21 | |
---|
22 | #include "list.h" |
---|
23 | |
---|
24 | using namespace std; |
---|
25 | |
---|
26 | |
---|
27 | /** |
---|
28 | \brief standard constructor |
---|
29 | */ |
---|
30 | PhysicsEngine::PhysicsEngine() |
---|
31 | { |
---|
32 | this->setClassName ("PhysicsEngine"); |
---|
33 | |
---|
34 | this->connections = new tList<PhysicsConnection>; |
---|
35 | } |
---|
36 | |
---|
37 | /** |
---|
38 | \brief the singleton reference to this class |
---|
39 | */ |
---|
40 | PhysicsEngine* PhysicsEngine::singletonRef = NULL; |
---|
41 | |
---|
42 | /** |
---|
43 | \returns a Pointer to this Class |
---|
44 | */ |
---|
45 | PhysicsEngine* PhysicsEngine::getInstance(void) |
---|
46 | { |
---|
47 | if (!PhysicsEngine::singletonRef) |
---|
48 | PhysicsEngine::singletonRef = new PhysicsEngine(); |
---|
49 | return PhysicsEngine::singletonRef; |
---|
50 | } |
---|
51 | |
---|
52 | /** |
---|
53 | \brief standard deconstructor |
---|
54 | |
---|
55 | */ |
---|
56 | PhysicsEngine::~PhysicsEngine () |
---|
57 | { |
---|
58 | PhysicsEngine::singletonRef = NULL; |
---|
59 | } |
---|
60 | |
---|
61 | /** |
---|
62 | \brief adds A Physical Connection to the List of Connections |
---|
63 | \param connection the Connection to add |
---|
64 | |
---|
65 | Usually this is done through the constructor of PhysicshConnections |
---|
66 | */ |
---|
67 | void PhysicsEngine::addConnection(PhysicsConnection* connection) |
---|
68 | { |
---|
69 | this->connections->add(connection); |
---|
70 | } |
---|
71 | |
---|
72 | /** |
---|
73 | \brief removes A Physical Connection from the List of Connections |
---|
74 | \param connection the Connection to remove |
---|
75 | |
---|
76 | Usually this is done through the destructor of PhysicsConnections |
---|
77 | */ |
---|
78 | void PhysicsEngine::removeConnection(PhysicsConnection* connection) |
---|
79 | { |
---|
80 | this->connections->remove(connection); |
---|
81 | } |
---|
82 | |
---|
83 | |
---|
84 | |
---|
85 | |
---|
86 | |
---|
87 | /** |
---|
88 | \brief Steps through all the Connections and Ticks them |
---|
89 | \param dt The time Passed in Seconds |
---|
90 | |
---|
91 | This function brings a flow into the whole animation |
---|
92 | */ |
---|
93 | void PhysicsEngine::tick(float dt) |
---|
94 | { |
---|
95 | tIterator<PhysicsConnection>* iterator = this->connections->getIterator(); |
---|
96 | PhysicsConnection* enumConn = iterator->nextElement(); |
---|
97 | while (enumConn) |
---|
98 | { |
---|
99 | enumConn->apply(dt); |
---|
100 | enumConn = iterator->nextElement(); |
---|
101 | } |
---|
102 | delete iterator; |
---|
103 | } |
---|
104 | |
---|
105 | |
---|
106 | |
---|
107 | /** |
---|
108 | \brief print out interesting debug information of this class |
---|
109 | */ |
---|
110 | void PhysicsEngine::debug(void) const |
---|
111 | { |
---|
112 | PRINT(0)("====================================\n"); |
---|
113 | PRINT(0)("= Physics-Engine debug information =\n"); |
---|
114 | PRINT(0)("====================================\n"); |
---|
115 | PRINT(0)(" reference: %p\n", this); |
---|
116 | PRINT(0)(" numbers of Connections: %d\n", this->connections->getSize()); |
---|
117 | |
---|
118 | PRINT(0)("==============================PHYS==\n"); |
---|
119 | } |
---|