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 | this->interfaces = new tList<PhysicsInterface>; |
---|
36 | this->fields = new tList<Field>; |
---|
37 | } |
---|
38 | |
---|
39 | /** |
---|
40 | \brief the singleton reference to this class |
---|
41 | */ |
---|
42 | PhysicsEngine* PhysicsEngine::singletonRef = NULL; |
---|
43 | |
---|
44 | /** |
---|
45 | \brief standard deconstructor |
---|
46 | |
---|
47 | */ |
---|
48 | PhysicsEngine::~PhysicsEngine () |
---|
49 | { |
---|
50 | PhysicsEngine::singletonRef = NULL; |
---|
51 | } |
---|
52 | |
---|
53 | |
---|
54 | /** |
---|
55 | \brief adds a PhysicsInterface to the list of handeled physicsInterfaces |
---|
56 | \param physicsInterface the interface to add |
---|
57 | |
---|
58 | this is normally done in the constructor of any PhysicsInterface |
---|
59 | */ |
---|
60 | void PhysicsEngine::addPhysicsInterface(PhysicsInterface* physicsInterface) |
---|
61 | { |
---|
62 | this->interfaces->add(physicsInterface); |
---|
63 | } |
---|
64 | |
---|
65 | /** |
---|
66 | \brief removes a PhysicsInterface from the list of handeled physicsInterfaces |
---|
67 | \param physicsInterface the interface to remove |
---|
68 | |
---|
69 | this is normally done in the destructor of any PhysicsInterface |
---|
70 | */ |
---|
71 | void PhysicsEngine::removePhysicsInterface(PhysicsInterface* physicsInterface) |
---|
72 | { |
---|
73 | this->interfaces->remove(physicsInterface); |
---|
74 | } |
---|
75 | |
---|
76 | /** |
---|
77 | \brief adds a Field to the list of handeled fields |
---|
78 | \param field the field to add |
---|
79 | |
---|
80 | this is normally done in the constructor of any Field |
---|
81 | */ |
---|
82 | void PhysicsEngine::addField(Field* field) |
---|
83 | { |
---|
84 | this->fields->add(field); |
---|
85 | } |
---|
86 | |
---|
87 | /** |
---|
88 | \brief removes a Field from the list of handeled fields |
---|
89 | \param field the field to remove |
---|
90 | |
---|
91 | this is normally done in the destructor of any Field |
---|
92 | */ |
---|
93 | void PhysicsEngine::removeField(Field* field) |
---|
94 | { |
---|
95 | this->fields->remove(field); |
---|
96 | } |
---|
97 | |
---|
98 | /** |
---|
99 | \brief adds A Physical Connection to the List of Connections |
---|
100 | \param connection the Connection to add |
---|
101 | |
---|
102 | Usually this is done through the constructor of PhysicshConnections |
---|
103 | */ |
---|
104 | void PhysicsEngine::addConnection(PhysicsConnection* connection) |
---|
105 | { |
---|
106 | this->connections->add(connection); |
---|
107 | } |
---|
108 | |
---|
109 | /** |
---|
110 | \brief removes A Physical Connection from the List of Connections |
---|
111 | \param connection the Connection to remove |
---|
112 | |
---|
113 | Usually this is done through the destructor of PhysicsConnections |
---|
114 | */ |
---|
115 | void PhysicsEngine::removeConnection(PhysicsConnection* connection) |
---|
116 | { |
---|
117 | this->connections->remove(connection); |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | |
---|
122 | |
---|
123 | |
---|
124 | /** |
---|
125 | \brief Steps through all the Connections and Ticks them |
---|
126 | \param dt The time Passed in Seconds |
---|
127 | |
---|
128 | This function brings a flow into the whole animation |
---|
129 | */ |
---|
130 | void PhysicsEngine::tick(float dt) |
---|
131 | { |
---|
132 | tIterator<PhysicsConnection>* itPC = this->connections->getIterator(); |
---|
133 | PhysicsConnection* enumPC = itPC->nextElement(); |
---|
134 | while (enumPC) |
---|
135 | { |
---|
136 | enumPC->apply(); |
---|
137 | enumPC = itPC->nextElement(); |
---|
138 | } |
---|
139 | delete itPC; |
---|
140 | |
---|
141 | |
---|
142 | tIterator<PhysicsInterface>* itPI = this->interfaces->getIterator(); |
---|
143 | PhysicsInterface* enumPI = itPI->nextElement(); |
---|
144 | while (enumPI) |
---|
145 | { |
---|
146 | enumPI->tickPhys(dt); |
---|
147 | enumPI = itPI->nextElement(); |
---|
148 | } |
---|
149 | delete itPI; |
---|
150 | } |
---|
151 | |
---|
152 | |
---|
153 | |
---|
154 | /** |
---|
155 | \brief print out interesting debug information of this class |
---|
156 | */ |
---|
157 | void PhysicsEngine::debug(void) const |
---|
158 | { |
---|
159 | PRINT(0)("====================================\n"); |
---|
160 | PRINT(0)("= Physics-Engine debug information =\n"); |
---|
161 | PRINT(0)("====================================\n"); |
---|
162 | PRINT(0)(" reference: %p\n", this); |
---|
163 | PRINT(0)(" number of Interfaces: %d\n", this->interfaces->getSize()); |
---|
164 | PRINT(0)(" number of Connections: %d\n", this->connections->getSize()); |
---|
165 | |
---|
166 | PRINT(0)("==============================PHYS==\n"); |
---|
167 | } |
---|