Dragonfly 4.20
A text-based game engine
Public Member Functions | Private Attributes | List of all members
df::Grid Class Reference

Public Member Functions

 Grid ()
 
 ~Grid ()
 
void setDimensions (int new_width, int new_height)
 
int getHeight () const
 
int getWidth () const
 
int insertObject (Object *p_o)
 
int removeObject (Object *p_o)
 
Cell positionToCell (Vector where) const
 
std::set< Cell > positionToCells (Object *p_o, Vector where) const
 
ObjectList getCollisions (Object *p_o, Vector where) const
 
int updatePosition (Object *p_o, Vector where)
 
ObjectList getObjects (Cell cell) const
 
std::string toString () const
 
int startUp ()
 
void shutDown ()
 
void printLog () const
 

Private Attributes

ObjectList ** m_p_grid
 
ObjectList m_out_of_bounds
 
int m_num_cols
 
int m_num_rows
 
int m_width
 
int m_height
 

Constructor & Destructor Documentation

◆ Grid()

df::Grid::Grid ( )

Constructor.

◆ ~Grid()

df::Grid::~Grid ( )

Destructor.

Member Function Documentation

◆ getCollisions()

ObjectList df::Grid::getCollisions ( Object p_o,
Vector  where 
) const

Return all Objects that collide at given location.

List is empty if none.

◆ getHeight()

int df::Grid::getHeight ( ) const

Get height.

◆ getObjects()

ObjectList df::Grid::getObjects ( Cell  cell) const

Get Objects in a given Cell.

◆ getWidth()

int df::Grid::getWidth ( ) const

Get width.

◆ insertObject()

int df::Grid::insertObject ( Object p_o)

Insert Object into grid.

Return 0 if ok, else -1.

◆ positionToCell()

Cell df::Grid::positionToCell ( Vector  where) const

Return Cell (x,y) for given location.

◆ positionToCells()

std::set< Cell > df::Grid::positionToCells ( Object p_o,
Vector  where 
) const

Return list of Cells for given Object at given location.

Out of bounds cell is (-1, -1).

◆ printLog()

void df::Grid::printLog ( ) const

Print grid cell count to logfile.

◆ removeObject()

int df::Grid::removeObject ( Object p_o)

Remove Object from grid.

Return 0 if ok, else -1.

◆ setDimensions()

void df::Grid::setDimensions ( int  new_width,
int  new_height 
)

Set dimensions. Deletes and re-creates grid.

◆ shutDown()

void df::Grid::shutDown ( )

Shutdown (delete grid).

◆ startUp()

int df::Grid::startUp ( )

Startup (create grid).

Return 0 if ok, else -1.

◆ toString()

std::string df::Grid::toString ( ) const

Return grid as string.

◆ updatePosition()

int df::Grid::updatePosition ( Object p_o,
Vector  where 
)

Move Object from old position, add to new position.

Return 0 if ok, else -1.

Member Data Documentation

◆ m_height

int df::Grid::m_height
private

Grid cell height.

◆ m_num_cols

int df::Grid::m_num_cols
private

Number of columns in grid.

◆ m_num_rows

int df::Grid::m_num_rows
private

Number of rows in grid.

◆ m_out_of_bounds

ObjectList df::Grid::m_out_of_bounds
private

All out of bounds objects.

◆ m_p_grid

ObjectList** df::Grid::m_p_grid
private

The grid.

◆ m_width

int df::Grid::m_width
private

Grid cell width.