Class Grid
raft.kilavuz.grid
java.lang.Object
  raft.kilavuz.grid.Grid
All Implemented Interfaces:

public class Grid
extends Object
implements Serializable

raw path finding information consists of cells, sectors and portals between sectors. instances of Grid is only created by FloodFill. this a kind of 2d grid in 3d space which can take us up or down slopes, across bridges and over and under overpasses.

grid is the raw format of path finding information. geometry customizations (creating custom sectors and portals) are only possible on grid instances. floodfilling to construct a grid is a quite time consuming process especially on large maps. it's impossible to create custom sectors once grid is sectorized. hence it's strongly recommended to backup your grid instances before sectorizing them.

grid storage depends on java serialization and future versions may not be compatible with current version. hence it's also recommended to backup code or script pieces which creates the grid

See Also:
FloodFill, Land

Nested Class Summary
class
Grid.Cell
a cell in grid.
class
Grid.Portal
a portal is a line of (generally) border cells which leads to same sector with same action
class
Grid.Sector
a rectangular region which is freely traversable with simple steps
Field Summary
float
cellHeight
height of a cell
float
cellWidth
width of a cell
Method Summary
int
cellCount()
returns number of cells
createPortal(Grid.Cell from, Grid.Cell to, short action)
creates a special portal between given cells.
createSector(Collection<Grid.Cell> cells)
creates a sector from given cells.
getCell(int cellId)
returns the cell with given id
getCellAt(SimpleVector v)
returns the cell which contains the given location.
getCellAt(float x, float y, float z)
returns the cell which contains the given location.
getCells()
returns an unmodifiable view of cells
getCellsAt(float minX, float maxX, float minY, float maxY, float minZ, float maxZ)
return list of cells which intersects with given bounds in world space
getCellsAt(float[] bounds)
return list of cells which intersects with given bounds in in world space.
getOrigin()
returns origin, first cell 0,0 at world space
getPortals()
returns an unmodifiable view of portals
getSector(int sectorId)
return sector with given id or null of there is no such sector
getSectors()
returns an unmodifiable view of sectors
boolean
isSectorized()
returns true sector and hence portal information is created
static Grid
loadFromStream(InputStream in)
loads serialized Grid from stream and closes stream
int
portalCount()
returns number of portals
void
removeCell(int cellId)
removes a cell from grid.
void
saveToStream(OutputStream out)
serializes this Grid to stream and closes stream
int
sectorCount()
returns number of sectors
void
sectorize()
creates sectors and portals among cells
Field Detail
cellWidth
public final float cellWidth
width of a cell

cellHeight
public final float cellHeight
height of a cell
Method Detail
isSectorized
public boolean isSectorized()
returns true sector and hence portal information is created

getOrigin
public Vector3 getOrigin()
returns origin, first cell 0,0 at world space

cellCount
public int cellCount()
returns number of cells

sectorCount
public int sectorCount()
returns number of sectors

portalCount
public int portalCount()
returns number of portals

getSector
public Grid.Sector getSector(int sectorId)
return sector with given id or null of there is no such sector

getSectors
public Collection<Grid.SectorgetSectors()
returns an unmodifiable view of sectors

getPortals
public Collection<Grid.PortalgetPortals()
returns an unmodifiable view of portals

createPortal
public Grid.Portal createPortal(Grid.Cell from,
                                Grid.Cell to,
                                short action)
creates a special portal between given cells.
Parameters:
from - source cell
to - destination cell
action - action to take to pass through this portal. should be positive
Returns:
the created portal
Throws:
IllegalArgumentException - if any of the arguments are invalid
IllegalStateException - if source or dest cell hasnt assigned a sector yet or a transition with same action is already defined
LicenseException - if maxSpecialPortals are reached

createSector
public Grid.Sector createSector(Collection<Grid.Cell> cells)
creates a sector from given cells. custom secors can be created only before grid is sectorized. the cells must form a rectangular area and all freely traversable: there should be two way transition with no action between all two adjacent pairs
Parameters:
cells - collection of cells to form a sector
Returns:
the created sector
Throws:
IllegalStateException - if this grid is sectorized or any of the cells has been assigned to a sector
IllegalArgumentException - if cells doesnt conform to freely traversable rule
LicenseException - if maxSpecialSectors are reached

getCellsAt
public List<Grid.CellgetCellsAt(float[] bounds)
return list of cells which intersects with given bounds in in world space. order of bounds is minX, maxX, minY, maxY, minZ, maxZ

getCellsAt
public List<Grid.CellgetCellsAt(float minX,
                                  float maxX,
                                  float minY,
                                  float maxY,
                                  float minZ,
                                  float maxZ)
return list of cells which intersects with given bounds in world space

getCellAt
public Grid.Cell getCellAt(SimpleVector v)
returns the cell which contains the given location.
Parameters:
v - location in world space
Returns:
the cell or null if no cell contains that point

getCellAt
public Grid.Cell getCellAt(float x,
                           float y,
                           float z)
returns the cell which contains the given location.
Parameters:
x - x coordinate in world space
y - y coordinate in world space
z - z coordinate in world space
Returns:
the cell or null if no cell contains that point

getCell
public Grid.Cell getCell(int cellId)
returns the cell with given id
Parameters:
cellId - id of cell
Returns:
the cell or null if there is no such cell

getCells
public Collection<Grid.CellgetCells()
returns an unmodifiable view of cells

removeCell
public void removeCell(int cellId)
removes a cell from grid. this can be used for manually correcting some part of grid.
Parameters:
cellId - id of cell to remove
Throws:
NoSuchElementException - if no cell with given id exist
IllegalStateException - if cell is assigned to a sector
Since:
0.91
See Also:

saveToStream
public void saveToStream(OutputStream out)
                  throws IOException
serializes this Grid to stream and closes stream
Throws:

loadFromStream
public static Grid loadFromStream(InputStream in)
                           throws IOException
loads serialized Grid from stream and closes stream
Throws:

sectorize
public void sectorize()
creates sectors and portals among cells
Java API documentation generated with DocFlex/Doclet v1.5.2
DocFlex/Doclet is both a multi-format Javadoc doclet and a free edition of DocFlex/Javadoc. If you need to customize your Javadoc without writing a full-blown doclet from scratch, DocFlex/Javadoc may be the only tool able to help you! Find out more at www.docflex.com