#include <obstacle_grid.h>
Inherited by _classes_ [private]
.
Inheritance diagram for ObstacleGrid:
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< Obstacle > | getDrawObstacleList (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 |
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
|
|
|
|
|
00175 { 00176 // for (iterator iter= 00177 //FIXME PATRICK 00178 } |
|
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 } |
|
This function returns the end of the Drawing map. This is used to compare with the returned iterator from GetByDraw .
00187 {return drawObst.end();} |
|
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 } |
|
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 } |
|
The getByDraw function returns an iterator starting with the first item with the specified model.
00080 { 00081 return drawObst.find (model); 00082 } |
|
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.
00157 { 00158 return collObst.GetAll(VectorHash (coord)); 00159 } |
|
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.
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 } |
|
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 } |
|
|
|
|
|
|
|
This map contains all Obstacle s in order by their VectorHash . This map is used for quick collision detections.
|
|
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. |