Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/coll_rect/src/lib/collision_reaction/cr_engine.cc @ 9984

Last change on this file since 9984 was 9984, checked in by patrick, 17 years ago

freeing collision reaction engine from unused functions

File size: 4.5 KB
RevLine 
[7819]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: Patrick Boenzli
13   co-programmer: ...
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_REACTION
17
[8190]18
19
20#include "collision.h"
21#include "collision_event.h"
[9895]22#include "collision_filter.h"
[8190]23#include "cr_defs.h"
24
[7819]25#include "cr_engine.h"
26
[8362]27#include "debug.h"
28
[9889]29namespace CoRe
30{
[7819]31
[9889]32  ObjectListDefinition(CREngine);
[9890]33
34
[9889]35  /**
36   * standard constructor
37   */
38  CREngine::CREngine ()
39      : BaseObject()
40  {
41    this->registerObject(this, CREngine::_objectList);
42    this->setName("CREngine");
[7819]43
[9889]44    this->init();
45  }
[7819]46
[9889]47  /**
48   *  the singleton reference to this class
49   */
50  CREngine* CREngine::singletonRef = NULL;
[7819]51
[9889]52  /**
53     @brief standard deconstructor
54   */
55  CREngine::~CREngine ()
56  {
57    CREngine::singletonRef = NULL;
[7819]58
[9889]59    if( this->collisionsUnused.size() != CR_MAX_COLLISIONS)
60      PRINTF(0)("CollisionReaction Error: Collision cache size missmatch: %i of %i\n", this->collisionsUnused.size(), CR_MAX_COLLISIONS);
61    if( this->collisionEventsUnused.size() != CR_MAX_COLLISION_EVENTS)
62      PRINTF(0)("CollisionReaction Error: CollisionEvent cache size missmatch: %i of %i\n", this->collisionEventsUnused.size(), CR_MAX_COLLISION_EVENTS);
[8190]63
[9889]64    this->reset();
[8190]65
[9889]66    std::vector<Collision*>::iterator it1 = this->collisionsUnused.begin();
67    for(; it1 < this->collisionsUnused.end(); it1++)
68      delete *it1;
69    std::vector<CollisionEvent*>::iterator it2 = this->collisionEventsUnused.begin();
70    for(; it2 < this->collisionEventsUnused.end(); it2++)
71      delete *it2;
[8190]72
[9889]73    this->collisionsUnused.clear();
74    this->collisionEventsUnused.clear();
75  }
[8190]76
[9889]77  /**
78   * inits the CREngine to a working state
79   */
80  void CREngine::init()
81  {
82    // create a list of Collision events (precaching)
83    for( int i = 0; i < CR_MAX_COLLISIONS; i++)
84      this->collisionsUnused.push_back(new Collision());
85    for( int i = 0; i < CR_MAX_COLLISION_EVENTS; i++)
86      this->collisionEventsUnused.push_back(new CollisionEvent());
87  }
[7841]88
89
[9889]90  /**
[9892]91   * @returns an instance to a collision object. instead of creating new object this ones can be resycled
92   */
93  Collision* CREngine::popCollisionObject()
94  {
95    if( !this->collisionsUnused.empty())
96    {
97      this->collisionsUsed.push_back(this->collisionsUnused.back());
98      this->collisionsUnused.pop_back();
99      return this->collisionsUsed.back();
100    }
101    else return NULL;
102  }
103
104  /**
105   * @return an instanco of a CollisionEvent object. instead of creating a new object this ones can be used and resycled
106   */
107  CollisionEvent* CREngine::popCollisionEventObject()
108  {
109    if( !this->collisionEventsUnused.empty())
110    {
111      this->collisionEventsUsed.push_back(this->collisionEventsUnused.back());
112      this->collisionEventsUnused.pop_back();
113      return this->collisionEventsUsed.back();
114    }
115    else return NULL;
116  }
117
118
119  /**
[9889]120   * flushes the CollisionHandles and restores the CREngine to the initial state
121   */
122  void CREngine::reset()
123  {
[9895]124//     // first clear all CollisionHandles
125//     std::vector<CollisionHandle*>::iterator it = this->collisionHandles.begin();
126//     for(; it < this->collisionHandles.end(); it++)
127//     {
128//       (*it)->reset();
129//       delete *it;
130//     }
131//
132//     this->collisionHandles.clear();
[8190]133  }
134
135
136
[7927]137
[7841]138
[9889]139  /**
140   * processes the collisions by calling the EventHandlers
141   */
142  void CREngine::handleCollisions()
[8190]143  {
[9895]144//     std::vector<CollisionHandle*>::iterator it;
145//     for( it = this->collisionHandles.begin(); it != this->collisionHandles.end(); it++)
146//     {
147//       if( !(*it)->isDispatched() || (*it)->isContinuousPoll())  //does it have any collisions to report at all
148//       {
149//         (*it)->handleCollisions();
150//       }
151//     }
152//     this->flushCollisions();
[8190]153  }
154
155
[9889]156  /**
157   * flushes all the collision lists and puts them to their initial state
158   */
159  void CREngine::flushCollisions()
160  {
161    std::vector<Collision*>::iterator it1 = this->collisionsUsed.begin();
162    for(; it1 < this->collisionsUsed.end(); it1++)
163      this->collisionsUnused.push_back(*it1);
[8190]164
[9889]165    std::vector<CollisionEvent*>::iterator it2 = this->collisionEventsUsed.begin();
166    for(; it2 < this->collisionEventsUsed.end(); it2++)
167      this->collisionEventsUnused.push_back(*it2);
[8190]168
[9889]169    this->collisionsUsed.clear();
170    this->collisionEventsUsed.clear();
171  }
[8190]172
173
[9889]174  void CREngine::debug()
175  {
176  }
[8190]177
178}
Note: See TracBrowser for help on using the repository browser.