1#ifndef PLUGIN2DGRID_HPP
2#define PLUGIN2DGRID_HPP
27 template<
typename cell_t>
43 int x = c->getBody().get2DPosition().x();
44 int y = c->getBody().get2DPosition().y();
47 if ((x == 0 || x ==
cellGrid.width - 1) && (y == 0 || y ==
cellGrid.height - 1)) {
48 c->getBody().setNbNeighbouringLocations(4);
49 }
else if (x == 0 || x ==
cellGrid.width - 1 || y == 0 || y ==
cellGrid.height - 1) {
50 c->getBody().setNbNeighbouringLocations(6);
52 c->getBody().setNbNeighbouringLocations(9);
55 c->getBody().setNbNeighbouringLocations(9);
65 int x = c->getBody().get2DPosition().x();
66 int y = c->getBody().get2DPosition().y();
67 c->clearConnectedCells();
68 for (
int i = -1; i <= 1; ++i) {
69 for (
int j = -1; j <= 1; ++j) {
72 if ((xi >= 0) && (xi <
cellGrid.width) && (yj >= 0) && (yj <
cellGrid.height)) {
73 for(
auto cell :
cellGrid.grid[xi][yj]){
74 if(cell != c) c->addConnectedCell(cell);
81 for(
auto cell :
cellGrid.grid[xi][yj]){
82 if(cell != c) c->addConnectedCell(cell);
87 for(
auto cell :
cellGrid.grid[xi][yj]){
88 if(cell != c) c->addConnectedCell(cell);
93 for(
auto cell :
cellGrid.grid[xi][yj]){
94 if(cell != c) c->addConnectedCell(cell);
99 c->getBody().setNbNeighbouringCells(c->getConnectedCells().size());
173 template<
typename world_t>
189 template<
typename world_t>
191 for (cell_t *c : w->newCells) {
192 int x = c->getBody().get2DPosition().x();
193 int y = c->getBody().get2DPosition().y();
203 template<
typename world_t>
206 for (cell_t *c : w->cells) {
216 template<
typename world_t>
218 for (cell_t *c : w->cells) {
220 int x = c->getBody().get2DPosition().x();
221 int y = c->getBody().get2DPosition().y();
222 for (
int i = 0; i <
cellGrid.grid[x][y].size(); ++i) {
Defines the Body2DGrid class for 2D grid physics-based bodies.
Template class for a 2D grid physics-based plugin.
double getOccupationSurfaceRatio() const
Gets the occupation surface ratio.
void computeNeighbouringCells(cell_t *c)
Computes the neighbouring cells for a given cell.
double nbOccupiedPositions
void resizeCellGrid(int w, int h)
Resizes the cell grid to the given width and height.
double getGlobalDensity(world_t *w) const
Gets the global density of the grid.
void onAddCell(world_t *w)
Hook called when cells is added to the world.
double getNbOccupiedPositions() const
Gets the number of occupied positions.
void setToreX(bool b)
Sets the toric property on the X-axis.
void preDeleteDeadCellsUpdate(world_t *w)
Hook called before deleting dead cells from the world.
void resizeCellGrid(int size)
Resizes the cell grid to a square of the given size.
void setTore(bool x, bool y)
Sets the toric properties on both X and Y axes.
CellGrid< cell_t > * getCellGrid()
Gets the cell grid.
void updateNeighbouringLocation(cell_t *c)
Updates the number of neighbouring locations for a cell.
CellGrid< cell_t > cellGrid
Plugin2DGrid()
Default constructor.
void setToreY(bool b)
Sets the toric property on the Y-axis.
void preBehaviorUpdate(world_t *w)
Hook called before the behavior update of the world.
Namespace for 2D grid-related structures and classes.
Template class representing a 2D grid of cell pointers.