Index: branches/coll_rect.merge/src/world_entities/world_entity.cc
===================================================================
--- branches/coll_rect.merge/src/world_entities/world_entity.cc	(revision 10009)
+++ branches/coll_rect.merge/src/world_entities/world_entity.cc	(revision 10010)
@@ -35,5 +35,5 @@
 #include "camera.h"
 
-#include "collision_handle.h"
+#include "collision_filter.h"
 #include "collision_event.h"
 #include "game_rules.h"
@@ -58,5 +58,5 @@
  */
 WorldEntity::WorldEntity()
-    : Synchronizeable()
+  : Synchronizeable(), _collisionFilter(this)
 {
   this->registerObject(this, WorldEntity::_objectList);
@@ -77,22 +77,18 @@
   this->lastObjectListNumber = OM_INIT;
 
-  // reset all collision handles to NULL == unsubscribed state
-  for(int i = 0; i < CREngine::CR_NUMBER; ++i)
-    this->collisionHandles[i] = NULL;
-  this->bReactive = false;
-  this->bOnGround = false;
+  this->_bOnGround = false;
 
   // registering default reactions:
-  this->subscribeReaction(CREngine::CR_OBJECT_DAMAGE, /* WorldEntity::staticClassID(), */ Projectile::staticClassID());
+  this->subscribeReaction(CoRe::CREngine::CR_OBJECT_DAMAGE, Projectile::staticClassID());
 
   this->toList(OM_NULL);
 
-  registerVar( new SynchronizeableString( &this->md2TextureFileName, &this->md2TextureFileName, "md2TextureFileName", PERMISSION_MASTER_SERVER ) );
-  modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName", PERMISSION_MASTER_SERVER ) );
-  scaling_handle = registerVarId( new SynchronizeableFloat( &scaling, &scaling, "scaling", PERMISSION_MASTER_SERVER ) );
-  list_handle = registerVarId( new SynchronizeableInt( (int*)&objectListNumber, &list_write, "list", PERMISSION_MASTER_SERVER ) );
-
-  health_handle = registerVarId( new SynchronizeableFloat( &this->health, &this->health_write, "health", PERMISSION_MASTER_SERVER ) );
-  healthMax_handle = registerVarId( new SynchronizeableFloat( &this->healthMax, &this->healthMax_write, "maxHealth", PERMISSION_MASTER_SERVER ) );
+  this->registerVar( new SynchronizeableString( &this->md2TextureFileName, &this->md2TextureFileName, "md2TextureFileName", PERMISSION_MASTER_SERVER ) );
+  this->modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName", PERMISSION_MASTER_SERVER ) );
+  this->scaling_handle = registerVarId( new SynchronizeableFloat( &scaling, &scaling, "scaling", PERMISSION_MASTER_SERVER ) );
+  this->list_handle = registerVarId( new SynchronizeableInt( (int*)&objectListNumber, &list_write, "list", PERMISSION_MASTER_SERVER ) );
+
+  this->health_handle = registerVarId( new SynchronizeableFloat( &this->health, &this->health_write, "health", PERMISSION_MASTER_SERVER ) );
+  this->healthMax_handle = registerVarId( new SynchronizeableFloat( &this->healthMax, &this->healthMax_write, "maxHealth", PERMISSION_MASTER_SERVER ) );
 }
 
@@ -115,5 +111,5 @@
     delete this->healthWidget;
 
-  this->unsubscribeReaction();
+  this->unsubscribeReactions();
 }
 
@@ -302,10 +298,7 @@
  *  @param target1 a filter target (classID)
  */
-void WorldEntity::subscribeReaction(CREngine::CRType type, const ClassID& target1)
-{
-  this->subscribeReaction(type);
-
-  // add the target filter
-  this->collisionHandles[type]->addTarget(target1);
+void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1)
+{
+  this->_collisionFilter.subscribeReaction(type, target1);
 }
 
@@ -316,11 +309,7 @@
  *  @param target1 a filter target (classID)
  */
-void WorldEntity::subscribeReaction(CREngine::CRType type, const ClassID& target1, const ClassID& target2)
-{
-  this->subscribeReaction(type);
-
-  // add the target filter
-  this->collisionHandles[type]->addTarget(target1);
-  this->collisionHandles[type]->addTarget(target2);
+void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2)
+{
+  this->_collisionFilter.subscribeReaction(type, target1, target2);
 }
 
@@ -331,50 +320,7 @@
  *  @param target1 a filter target (classID)
  */
-void WorldEntity::subscribeReaction(CREngine::CRType type, const ClassID& target1, const ClassID& target2, const ClassID& target3)
-{
-  this->subscribeReaction(type);
-
-  // add the target filter
-  this->collisionHandles[type]->addTarget(target1);
-  this->collisionHandles[type]->addTarget(target2);
-  this->collisionHandles[type]->addTarget(target3);
-}
-
-
-/**
- * subscribes this world entity to a collision reaction
- *  @param type the type of reaction to subscribe to
- *  @param target1 a filter target (classID)
- */
-void WorldEntity::subscribeReaction(CREngine::CRType type, const ClassID& target1, const ClassID& target2, const ClassID& target3, const ClassID& target4)
-{
-  this->subscribeReaction(type);
-
-  // add the target filter
-  this->collisionHandles[type]->addTarget(target1);
-  this->collisionHandles[type]->addTarget(target2);
-  this->collisionHandles[type]->addTarget(target3);
-  this->collisionHandles[type]->addTarget(target4);
-}
-
-
-/**
- * subscribes this world entity to a collision reaction
- *  @param type the type of reaction to subscribe to
- *  @param nrOfTargets number of target filters
- *  @param ... the targets as classIDs
- */
-void WorldEntity::subscribeReaction(CREngine::CRType type)
-{
-  if( this->collisionHandles[type] != NULL)
-  {
-    PRINTF(2)("Registering for a CollisionReaction already subscribed to! Skipping\n");
-    return;
-  }
-
-  this->collisionHandles[type] = CREngine::getInstance()->subscribeReaction(this, type);
-
-  // now there is at least one collision reaction subscribed
-  this->bReactive = true;
+void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2, const ClassID& target3)
+{
+  this->_collisionFilter.subscribeReaction(type, target1, target2, target3);
 }
 
@@ -384,22 +330,7 @@
  *  @param type the reaction to unsubscribe
  */
-void WorldEntity::unsubscribeReaction(CREngine::CRType type)
-{
-  if( this->collisionHandles[type] == NULL)
-    return;
-
-  CREngine::getInstance()->unsubscribeReaction(this->collisionHandles[type]);
-  this->collisionHandles[type] = NULL;
-
-  // check if there is still any handler registered
-  for(int i = 0; i < CREngine::CR_NUMBER; ++i)
-  {
-    if( this->collisionHandles[i] != NULL)
-    {
-      this->bReactive = true;
-      return;
-    }
-  }
-  this->bReactive = false;
+void WorldEntity::unsubscribeReaction(CoRe::CREngine::ReactionType type)
+{
+  this->_collisionFilter.unsubscribeReaction(type);
 }
 
@@ -408,61 +339,7 @@
  * unsubscribes all collision reactions
  */
-void WorldEntity::unsubscribeReaction()
-{
-  for( int i = 0; i < CREngine::CR_NUMBER; i++)
-    this->unsubscribeReaction((CREngine::CRType)i);
-
-  // there are no reactions subscribed from now on
-  this->bReactive = false;
-}
-
-
-/**
- * registers a new collision event to this world entity
- *  @param entityA entity of the collision
- *  @param entityB entity of the collision
- *  @param bvA colliding bounding volume of entityA
- *  @param bvB colliding bounding volume of entityA
- */
-bool WorldEntity::registerCollision(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB)
-{
-  PRINTF(5)("registering collision of type: %s vs %s\n", entityA->getClassCName(), entityB->getClassCName());
-  // is there any handler listening?
-  if( !this->bReactive)
-    return false;
-
-  // get a collision event
-  CollisionEvent* c = CREngine::getInstance()->popCollisionEventObject();
-  assert(c != NULL); // if this should fail: we got not enough precached CollisionEvents: alter value in cr_defs.h
-  c->collide(COLLISION_TYPE_OBB, entityA, entityB, bvA, bvB);
-
-  for( int i = 0; i < CREngine::CR_NUMBER; ++i)
-    if( this->collisionHandles[i] != NULL)
-      this->collisionHandles[i]->registerCollisionEvent(c);
-  return true;
-}
-
-
-/**
- * registers a new collision event to this woeld entity
- *  @param entity the entity that collides
- *  @param plane it stands on
- *  @param position it collides on the plane
- */
-bool WorldEntity::registerCollision(int type, WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position, bool bInWall)
-{
-  // is there any handler listening?
-  if( !this->bReactive)
-    return false;
-
-  // get a collision event
-  CollisionEvent* c = CREngine::getInstance()->popCollisionEventObject();
-  assert(c != NULL); // if this should fail: we got not enough precached CollisionEvents: alter value in cr_defs.h
-  c->collide(type, entity, groundEntity, normal, position, bInWall);
-
-  for( int i = 0; i < CREngine::CR_NUMBER; ++i)
-    if( this->collisionHandles[i] != NULL)
-      this->collisionHandles[i]->registerCollisionEvent(c);
-  return true;
+void WorldEntity::unsubscribeReactions()
+{
+  this->_collisionFilter.unsubscribeReactions();
 }
 
