Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/coll_rect/src/lib/collision_reaction/collision_filter.cc @ 9988

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

removed most of the compiler bugs. more to come

File size: 4.6 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollersf
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*/
14
15#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_REACTION
16
17#include "collision_filter.h"
18
19#include "world_entity.h"
20
21#include "collision.h"
22#include "collision_event.h"
23
24
25#include "debug.h"
26
27#include <vector>
28
29
30namespace CoRe
31{
32
33  ObjectListDefinition(CollisionFilter);
34
35  /**
36   * standard constructor
37   * @todo this constructor is not jet implemented - do it
38  */
39  CollisionFilter::CollisionFilter (WorldEntity* owner)
40  {
41    this->registerObject(this, CollisionFilter::_objectList);
42
43    this->_owner = owner;
44
45    this->_bContinuousPoll = false;
46    this->_bStopOnFirstCollision = false;
47    this->_bReactive = false;
48  }
49
50
51  /**
52   * standard deconstructor
53  */
54  CollisionFilter::~CollisionFilter ()
55  {
56    this->unsubscribeReactions();
57  }
58
59
60  /**
61   * subscribe reaction
62   */
63  void CollisionFilter::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1)
64  {
65    // check if its a valid type
66    if( likely(this->validCRType( type)))
67    {
68      //check if this class isn't already registered
69      TargetIterator it = this->_filters[type].begin();
70      for(; it != this->_filters[type].end(); it++)
71      {
72        if( unlikely(*it == target1))
73          return;
74      }
75
76      // so subscribe the reaction finally
77      this->_filters[type].push_back(target1);
78      this->_bReactive = true;
79    }
80  }
81
82
83  /**
84   * subscribe for a reaction
85   */
86  void CollisionFilter::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2)
87  {
88    this->subscribeReaction(type, target1);
89    this->subscribeReaction(type, target2);
90  }
91
92
93  /**
94   * subscribe for a reaction
95   */
96  void CollisionFilter::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2, const ClassID& target3)
97  {
98    this->subscribeReaction(type, target1);
99    this->subscribeReaction(type, target2);
100    this->subscribeReaction(type, target3);
101  }
102
103  /**
104   * unsubscribe from a specific collision reaction
105   */
106  void CollisionFilter::unsubscribeReaction(CoRe::CREngine::ReactionType type)
107  {
108    if( likely(this->validCRType( type)))
109      this->_filters[type].clear();
110
111    for( int i = 0; i < CREngine::CR_NUMBER; i++)
112    {
113      if( this->_filters[i].size() > 0)
114      {
115        this->_bReactive = true;
116        break;
117      }
118    }
119
120  }
121
122  /**
123   * unsubscribe from all collision reactions
124   */
125  void CollisionFilter::unsubscribeReactions()
126  {
127    for(int i = 0; i < CREngine::CR_NUMBER; i++)
128      this->_filters[i].clear();
129
130    this->_bReactive = false;
131  }
132
133
134
135  /**
136   * tests if the owner WorldEntity is listening to collisions from another specif WorldEntity entity
137   *  @param entity WorldEntity to test against
138   *
139   * This is the most important interface function of this class: it performs a check and returns true
140   * if the WorldEntity entity is actualy responsive for a certain other WorldEntity
141   */
142  bool CollisionFilter::operator()(const WorldEntity& entity) const
143  {
144    // if there are no installed criterions just ommit and
145    if( this->isReactive())
146      return false;
147
148    // goes through all registered filter criterions and looks for matches
149    for( int i = 0; i < CREngine::CR_NUMBER; i++ )
150    {
151      TargetIterator it = this->_filters[i].begin();
152
153
154//       for(; it != this->_filters[i].end(); i++ )
155//         if( unlikely(entity.isA(*it) ) )
156//           return true;
157    }
158
159    return false;
160  }
161
162
163  /**
164  * tests if the owner WorldEntity is listening to collisions from another specif WorldEntity entity
165  *  @param entity WorldEntity to test against
166  *
167  * This is the most important interface function of this class: it performs a check and returns true
168  * if the WorldEntity entity is actualy responsive for a certain other WorldEntity
169   */
170  bool CollisionFilter::operator()(const WorldEntity& entity, const CREngine::ReactionType type) const
171  {
172    // if there are no installed criterions just omit and return
173    if( !this->isReactive())
174      return false;
175
176    // goes through all registered filter criterions and looks for matches
177    TargetIterator it = this->_filters[type].begin();
178    for(; it != this->_filters[type].end(); it++ )
179      if( unlikely(entity.isA(*it)))
180        return true;
181
182    return false;
183  }
184
185
186
187} // namespace end
188
189
190
Note: See TracBrowser for help on using the repository browser.