Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

ObstacleGrid Class Reference

this constant is one divided by the width/height of each 'square' used for collisions with Obstacle s. ObstacleGrid is a class in each Surface that keeps track of every Obstacle on that Surface. More...

#include <obstacle_grid.h>

Inherited by _classes_ [private].

Inheritance diagram for ObstacleGrid:

Inheritance graph
[legend]
Collaboration diagram for ObstacleGrid:

Collaboration graph
[legend]
List of all members.

Public Types

typedef Hashtable< class VectorHash,
Obstacle *, 65535 > 
ObstMap
typedef std::multimap< Obstacle::ModelRef,
Obstacle
MeshSortedObstMap

Public Methods

ObstMap::iterator getByColl (const Vector &coord)
 The getByColl function returns an iterator starting with the first item in the square described by coord. More...

MeshSortedObstMap::iterator getByDraw (const Obstacle::ModelRef &model)
 The getByDraw function returns an iterator starting with the first item with the specified model. More...

MeshSortedObstMap::iterator put (const Obstacle &o)
 Puts an Obstacle in both maps to be found again by a call to Get (). Returns a MeshSortedObstmap::iterator only because the ObstMap may have multiple iterator s for the one object. More...

void erase (Obstacle &obst)
 Removes an obstacle from both maps and deletes (and calls the destructor of) the Obstacle . More...

ObstMap::vector_type & getCollObstacleList (const Vector &coord)
 This function returns a vector of possible obstacles given a Vector (coordinate). More...

std::vector< ObstaclegetDrawObstacleList (Collidable::ModelRef ref)
 This function returns a vector of possible obstacles given a Model. More...

void collideWithSpectres ()
ObstMap::iterator::it_type endByColl (ObstMap::iterator tablenum)
 This function returns the end of the Colliding map. This is used to compare with the returned iterator from GetByColl . More...

const MeshSortedObstMap::iterator endByDraw ()
 This function returns the end of the Drawing map. This is used to compare with the returned iterator from GetByDraw . More...


Private Attributes

ObstMap collObst
 This map contains all Obstacle s in order by their VectorHash . This map is used for quick collision detections. More...

MeshSortedObstMap drawObst
 This map contains all Obstacle s in order by their Obstacle::ModelRef hash value. More...


Friends

class MyFuncBase
class PutFunc
class EraseFunc

Detailed Description

this constant is one divided by the width/height of each 'square' used for collisions with Obstacle s. ObstacleGrid is a class in each Surface that keeps track of every Obstacle on that Surface.

This class uses two different types of map s: First is the collide map. This map sorts Obstacle s in order by which square of the grid they are in. Each Obstacle in the Surface is then placed into this vector by going across row by row. The disadvantage to this system is the fact that no Obstacle can not easily move from square to another square, which is actually fine because they cannot move. Since we do not want to store data many times, each square (index in the map ) contains a POINTER to the corresponding Obstacle in the next map . Next is the draw map. This map simply sorts the Obstacle s by Model instead and stores the data


Member Typedef Documentation

typedef std::multimap<Obstacle::ModelRef, Obstacle> ObstacleGrid::MeshSortedObstMap
 

typedef Hashtable<class VectorHash, Obstacle *, 65535> ObstacleGrid::ObstMap
 


Member Function Documentation

void ObstacleGrid::collideWithSpectres   [inline]
 

00175                                 {
00176 //      for (iterator iter=
00177         //FIXME PATRICK
00178     }

ObstMap::iterator::it_type ObstacleGrid::endByColl ObstMap::iterator    tablenum [inline]
 

This function returns the end of the Colliding map. This is used to compare with the returned iterator from GetByColl .

This function is here for compatibility. Use iter.end() instead.

00182                                                                 {
00183         return tablenum.end();
00184     }

const MeshSortedObstMap::iterator ObstacleGrid::endByDraw   [inline]
 

This function returns the end of the Drawing map. This is used to compare with the returned iterator from GetByDraw .

00187 {return drawObst.end();} 

void ObstacleGrid::erase Obstacle   obst [inline]
 

Removes an obstacle from both maps and deletes (and calls the destructor of) the Obstacle .

00137                                 {
00138         {
00139             const Vector fudgeFactor (.05/VectorHash::ScaleAmt,.05/VectorHash::ScaleAmt,.05/VectorHash::ScaleAmt);
00140             Vector firstcoord (obst.getPosition()+obst.getMin()-fudgeFactor);
00141             Vector lastcoord (obst.getPosition()+obst.getMax()+fudgeFactor);
00142             printf("ERASE %X (%f,%f),(%f,%f)\n",&obst,firstcoord.i,firstcoord.j,lastcoord.i,lastcoord.j);
00143             forEach2dVector (firstcoord, lastcoord, EraseFunc(this, &obst),Vector(1/VectorHash::ScaleAmt,1/VectorHash::ScaleAmt,1/VectorHash::ScaleAmt));
00144         }{
00145             for (MeshSortedObstMap::iterator miter=drawObst.find(obst.model);miter!=drawObst.end()&&(*miter).first==obst.model;++miter) {
00146                 if (&(*miter).second==(&obst)) {
00147                     drawObst.erase(miter);
00148                     break;
00149                 }
00150             }
00151         }
00152         
00153     }

ObstMap::iterator ObstacleGrid::getByColl const Vector   coord [inline]
 

The getByColl function returns an iterator starting with the first item in the square described by coord.

00075                                                     {
00076         VectorHash hash (coord);
00077         return collObst.find (hash);
00078     }

MeshSortedObstMap::iterator ObstacleGrid::getByDraw const Obstacle::ModelRef   model [inline]
 

The getByDraw function returns an iterator starting with the first item with the specified model.

00080                                                                         {
00081         return drawObst.find (model);
00082     }

ObstMap::vector_type& ObstacleGrid::getCollObstacleList const Vector   coord [inline]
 

This function returns a vector of possible obstacles given a Vector (coordinate).

The function calls ObstacleGrid 's getByColl and goes through every possible item in the returned iterator and then returns a vector of the found Obstacles.
Surprizingly, this function will take less time than Getting a single item.

00157                                                                   {
00158         return collObst.GetAll(VectorHash (coord));
00159     }

std::vector<Obstacle> ObstacleGrid::getDrawObstacleList Collidable::ModelRef    ref [inline]
 

This function returns a vector of possible obstacles given a Model.

The function calls ObstacleGrid 's getByDraw and goes through every possible item in the returned iterator and then returns a vector of the found Obstacles.
WARNING: This operation is slow and WILL call the copy constructor on EVERY object returned. Refrain from using.

00163                                                                       {
00164         using std::vector;
00165         MeshSortedObstMap::iterator iter=getByDraw (ref);
00166         Collidable::ModelRef hash ((*iter).first);
00167         vector <Obstacle> obstvec;
00168         while (iter!=endByDraw()&&(*iter).first==hash) {
00169             obstvec.push_back ((*iter).second);
00170             iter++;
00171         }
00172         return obstvec;
00173     }

MeshSortedObstMap::iterator ObstacleGrid::put const Obstacle   o [inline]
 

Puts an Obstacle in both maps to be found again by a call to Get (). Returns a MeshSortedObstmap::iterator only because the ObstMap may have multiple iterator s for the one object.

00125                                                       {
00126         MeshSortedObstMap::value_type v(o.model,o);
00127         MeshSortedObstMap::iterator i = drawObst.insert (v);
00128         Obstacle * obst = &(*i).second;
00129         const Vector fudgeFactor (0,0,0);//.01/VectorHash::ScaleAmt,.01/VectorHash::ScaleAmt,.01/VectorHash::ScaleAmt);
00130         Vector firstcoord (obst->getPosition()+obst->getMin()-fudgeFactor);
00131         Vector lastcoord (obst->getPosition()+obst->getMax()+fudgeFactor);
00132         printf("ADD %X (%f,%f),(%f,%f)\n",obst,firstcoord.i,firstcoord.j,lastcoord.i,lastcoord.j);
00133         forEach2dVector (firstcoord, lastcoord, PutFunc(this, obst),Vector(1/VectorHash::ScaleAmt,1/VectorHash::ScaleAmt,1/VectorHash::ScaleAmt));
00134         return i;
00135     }


Friends And Related Function Documentation

friend class EraseFunc [friend]
 

friend class MyFuncBase [friend]
 

friend class PutFunc [friend]
 


Member Data Documentation

ObstMap ObstacleGrid::collObst [private]
 

This map contains all Obstacle s in order by their VectorHash . This map is used for quick collision detections.

MeshSortedObstMap ObstacleGrid::drawObst [private]
 

This map contains all Obstacle s in order by their Obstacle::ModelRef hash value.

This map is instead used for drawing, so that two objects with the same mesh can be drawn at the same time. This map contains POINTERS to the same Obstacle s in the obst variable. This means that Obstacles here must be popped at the same time as obstacles in the collObst member.


The documentation for this class was generated from the following file:
Generated on Mon Jul 7 21:13:54 2003 for Ethereal by doxygen1.2.15