|
AndroMeta
2.0.0
|
A grid of light-weight cells and agents. More...
#include <MMLGrid.h>
Public Types | |
| enum | BoundaryRule { BoundaryError, BoundaryClamp, BoundaryWrap } |
Public Member Functions | |
| MMLGrid (const mvec &dimensions, const mvar &locality) | |
| MMLGrid (const mstr &dataPath) | |
| ~MMLGrid () | |
| mnode | process (mnode n, uint32_t flags=0) |
| void | setBoundaryRule (size_t dimension, BoundaryRule rule) |
| void | setBoundaryRule (size_t dimension, const mstr &rule) |
| void | createAgent (const mvar &agent) |
| virtual mvar | initAgent (mvar &agent) |
| virtual mvar | initCell (mvar &cell) |
| virtual mvar | runAgent (mvar &agent, mvar &cell) |
| void | selectAgents (const mvar ¶ms=undef) |
| virtual mvar | selectAgent (const mvar ¶ms, const mvar &cell, const mvar &agent, const mvar &selectCell, const mvar &selectAgent) |
| void | applyAgents (const mvar ¶ms=undef) |
| virtual mvar | applyAgent (const mvar ¶ms, mvar &cell, mvar &agent) |
| void | selectCells (const mvar ¶ms=undef) |
| virtual mvar | selectCell (const mvar ¶ms, const mvar &cell, const mvar &selectCell) |
| void | applyCells (const mvar ¶ms=undef) |
| virtual mvar | applyCell (const mvar ¶ms, mvar &cell) |
| void | moveTo (const mvec &pos) |
| void | die () |
| mvar | run () |
| void | setRunCycles (size_t cycles) |
| const mvec & | dimensions () const |
| const mvar & | data () const |
A grid of light-weight cells and agents.
The MMLGrid allows for the construction of a grid in an arbitrary number of dimensions and for light-weight agents positioned on it. A grid defines a locality which determines how agents interact with cells and other agents. Boundary rules may be specified which effect locality and control what happens when agents attempt to cross over a boundary, and in this way, the grid may be configured such that it is toroidal, either partially or completely. Agents may select other cells or agents in their locality which meet an application-specific criteria defined by selectCell() or selectAgent(), then, this selection may have an operation applied to it via applyCells() or applyAgents(). The grid is designed for high-performance, allowing it to scale to a large number of cells and agents.
The following cues(see MObject) are emitted:
redraw() - emitted when the scene needs to be redrawn.
mouseDown(mvec pos, int button) - emitted when a mouse down event is received within one of the cells at pos.
mouseUp(mvec pos, int button) - emitted when a mouse up event is received wihtin one of the cells at pos.
mouseMoved(mvec pos) - emitted when a mouse movement event is received within a cell at pos.
Grid Boundary rules determine what happens when an agent attempts to cross a boundary in a specified dimension. The default is BoundaryError which throws an MError when a boundary cross is attempted. BoundaryClamp clamps the agent to the edge of boundary on a boundary crossing attempt. BoundaryWrap allows the grid to act as Toroidal in the specified dimensions, wrapping the agent around to the opposite side when the boundary is crossed.
| Meta::MMLGrid::MMLGrid | ( | const mvec & | dimensions, |
| const mvar & | locality | ||
| ) |
Constructor.
| Meta::MMLGrid::MMLGrid | ( | const mstr & | dataPath | ) |
Constructor.
| dataPath | Path to the data file. See examples/grid3/data.mml for an example of the data file format. |
Destructor.
| virtual mvar Meta::MMLGrid::applyAgent | ( | const mvar & | params, |
| mvar & | cell, | ||
| mvar & | agent | ||
| ) | [virtual] |
Application-specific method to perform an operation on selected agents.
| cell | The cell that the agent occupies. |
| agent | The data defining the agent. |
| void Meta::MMLGrid::applyAgents | ( | const mvar & | params = undef | ) |
Iterates through the currently selected agents calling applyAgent() on each. Must be called from within the context of runAgent().
| params | The application-specific parameters passed to applyAgent(). |
| virtual mvar Meta::MMLGrid::applyCell | ( | const mvar & | params, |
| mvar & | cell | ||
| ) | [virtual] |
Application-specific method to perform an operation on a selected cell.
| void Meta::MMLGrid::applyCells | ( | const mvar & | params = undef | ) |
Iterates through the currently selected cells calling applyCell() on each. Must be called from within the context of runAgent().
| params | The application specific parameters passed to applyCell(). |
| void Meta::MMLGrid::createAgent | ( | const mvar & | agent | ) |
Create an agent and add it to the grid.
| agent | Data defining the agent which must include a "pos" field in the proper dimensions. |
| const mvar& Meta::MMLGrid::data | ( | ) | const |
| void Meta::MMLGrid::die | ( | ) |
Remove an agent from the grid. Must be called from within the context of runAgent().
| const mvec& Meta::MMLGrid::dimensions | ( | ) | const |
| virtual mvar Meta::MMLGrid::initAgent | ( | mvar & | agent | ) | [virtual] |
Application-specific method called to initialize an agent. Default is no-op.
| virtual mvar Meta::MMLGrid::initCell | ( | mvar & | cell | ) | [virtual] |
Application-specific method called to initialize a cell. Default is no-op.
| void Meta::MMLGrid::moveTo | ( | const mvec & | pos | ) |
Moves the agent to the specified position, enforcing boundary rules. Must be called from within the context of runAgent().
| mnode Meta::MMLGrid::process | ( | mnode | n, |
| uint32_t | flags = 0 |
||
| ) | [virtual] |
Process method.
Reimplemented from Meta::MMLEntity.
| mvar Meta::MMLGrid::run | ( | ) | [virtual] |
Do not call directly.
Reimplemented from Meta::MMLEntity.
| virtual mvar Meta::MMLGrid::runAgent | ( | mvar & | agent, |
| mvar & | cell | ||
| ) | [virtual] |
Called when it is time for an agent to run, passing its data and the cell it occupies.
| virtual mvar Meta::MMLGrid::selectAgent | ( | const mvar & | params, |
| const mvar & | cell, | ||
| const mvar & | agent, | ||
| const mvar & | selectCell, | ||
| const mvar & | selectAgent | ||
| ) | [virtual] |
Used to determine an application-specific method of selecting agents in the grid via selectAgents(). Default behavior is simply to return true.
| void Meta::MMLGrid::selectAgents | ( | const mvar & | params = undef | ) |
Iterates through all agents in the calling agents locality, calling selectAgent() on each. Must be called from within the context of runAgent().
| params | The application-specific parameters passed to selectAgent(). |
| virtual mvar Meta::MMLGrid::selectCell | ( | const mvar & | params, |
| const mvar & | cell, | ||
| const mvar & | selectCell | ||
| ) | [virtual] |
Used to determine an application-specific method of selecting cells via selectCells(). Default behavior is to return true.
| void Meta::MMLGrid::selectCells | ( | const mvar & | params = undef | ) |
Iterates through all cells in an agent's locality, calling selectCell() on each. Must be called from within the context of runAgent().
| params | The application-specific parameters passed to selectCell(). |
| void Meta::MMLGrid::setBoundaryRule | ( | size_t | dimension, |
| BoundaryRule | rule | ||
| ) |
Set a grid dimension to use the specified boundary rule.
| void Meta::MMLGrid::setBoundaryRule | ( | size_t | dimension, |
| const mstr & | rule | ||
| ) |
Set a grid dimension to use the specified boundary rule.
| rule | A stringified version of the enum BoundaryRule, e.g: "BoundaryWrap" |
| void Meta::MMLGrid::setRunCycles | ( | size_t | cycles | ) |
Set the number of run cycles internally performed when the MMLGrid entity runs. Default is 1.
1.7.6.1