Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/lib/physics/physics_engine.cc @ 4558

Last change on this file since 4558 was 4558, checked in by bensch, 19 years ago

orxonox/trunk: PhysicsEngine looks better (it speeds up things… but i do not exactly know if it works

File size: 4.0 KB
Line 
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
24using namespace std;
25
26
27/**
28   \brief standard constructor
29*/
30PhysicsEngine::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*/
42PhysicsEngine* PhysicsEngine::singletonRef = NULL;
43
44/**
45   \brief standard deconstructor
46
47*/
48PhysicsEngine::~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*/
60void 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*/
71void 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*/
82void 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*/
93void 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*/
104void 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*/
115void 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*/
130void PhysicsEngine::tick(float dt)
131{
132  /* go through all the PhysicsInterface(s) and tick them,
133  meaning let the fields work */
134  tIterator<PhysicsConnection>* itPC = this->connections->getIterator();
135  PhysicsConnection* enumPC = itPC->nextElement();
136  while (enumPC)
137    {
138      enumPC->apply();
139
140      enumPC = itPC->nextElement();
141    }
142  delete itPC;
143
144  /* actually tick all the PhysicsInterfaces. Move the objects around */
145  tIterator<PhysicsInterface>* itPI = this->interfaces->getIterator();
146  PhysicsInterface* enumPI = itPI->nextElement();
147  while (enumPI)
148    {
149      enumPI->tickPhys(dt);
150
151      enumPI = itPI->nextElement();
152    }
153  delete itPI;
154}
155
156
157
158/**
159   \brief print out interesting debug information of this class
160*/
161void PhysicsEngine::debug(void) const
162{
163  PRINT(0)("====================================\n");
164  PRINT(0)("= Physics-Engine debug information =\n");
165  PRINT(0)("====================================\n");
166  PRINT(0)(" reference: %p\n", this);
167  PRINT(0)(" number of Interfaces: %d\n", this->interfaces->getSize());
168  PRINT(0)(" number of Connections: %d\n", this->connections->getSize());
169
170  PRINT(0)("==============================PHYS==\n");
171}
Note: See TracBrowser for help on using the repository browser.