# ForestCell

Engine/source/forest/forestCell.h

## Public Friends

```
class
```

## Protected Attributes

Vector< ForestCellBatch * >

A vector of the current batches associated with this cell.

```
bool
```

If items have been added or removed the dirty flag is set so that the bounds can be rebuilt on the next request.

```
bool
```

Whether this cell is fully contained inside interior zones.

Vector< ForestItem >

All the items in this cell.

The largest item in this cell.

mPhysicsRep [2]

PhysicsBody for client and server for all trees in this ForestCell, if it is a leaf cell.

mSubCells [4]

The quad tree cells below this one which may contain sub elements.

The zone overlap for this cell.

## Public Static Attributes

## Protected Functions

_getSubCell(F32 x, F32 y)

_makeChildRect(U32 index)

_updateZoning(const SceneZoneSpaceManager * zoneManager)

## Public Functions

ForestCell(const RectF & rect)

buildPhysicsRep(Forest * forest)

clearPhysicsRep(Forest * forest)

```
bool
```

findIndexByKey(ForestItemKey key, U32 * outIndex)

The find function does a binary search thru the sorted item list.

The bounds of the cell generated by combining the bounds of all the contained items or child cells.

getChildAt(const Point3F & pos)

Returns the child cell at the position.

getChildren(Vector< const ForestCell * > * outCells)

getChildren(Vector< ForestCell * > * outCells)

Returns the child cells.

const Vector< ForestItem > &

getItems()

Returns the items from this one cell.

getItems(Vector< ForestItem > * outItems)

Returns the items from this cell and all its sub-cells.

Returns a bit vector of what zones overlap this cell.

```
bool
```

insertItem(ForestItemKey key, ForestItemData * data, const MatrixF & xfm, F32 scale)

Set flag so this cells bounds will be recalculated the next call to getBounds.

```
bool
```

isBranch()

Returns true if this cell has child cells.

```
bool
```

isEmpty()

Returns true if this cell has no items and no child cells.

```
bool
```

isLeaf()

Returns true if this cell does not have child cells.

```
bool
```

removeItem(ForestItemKey key, const Point3F & keyPos, bool deleteIfEmpty)

render(TSRenderState * rdata, const Frustum * culler)

renderBatches(SceneRenderState * state, Frustum * culler)

## Detailed Description

## Public Friends

## Protected Attributes

Vector< ForestCellBatch * > mBatches

A vector of the current batches associated with this cell.

Box3F mBounds

The combined bounding box of all the items in or children of this cell.

bool mIsDirty

If items have been added or removed the dirty flag is set so that the bounds can be rebuilt on the next request.

bool mIsInteriorOnly

Whether this cell is fully contained inside interior zones.

Vector< ForestItem > mItems

All the items in this cell.

ForestItem mLargestItem

The largest item in this cell.

PhysicsBody * mPhysicsRep [2]

PhysicsBody for client and server for all trees in this ForestCell, if it is a leaf cell.

RectF mRect

The area which this cell represents in the world.

ForestCell * mSubCells [4]

The quad tree cells below this one which may contain sub elements.

BitVector mZoneOverlap

The zone overlap for this cell.

note:The bit for the outdoor zone is never set.

## Public Static Attributes

const U32 MaxItems

The maximum amount of objects allowed in a cell before we repartition it.

## Protected Functions

_getSubCell(F32 x, F32 y)

_makeChildRect(U32 index)

_updateBounds()

_updateZoning(const SceneZoneSpaceManager * zoneManager)

## Public Functions

ForestCell(const RectF & rect)

~ForestCell()

buildBatches()

buildPhysicsRep(Forest * forest)

castRay(const Point3F & start, const Point3F & end, RayInfo * outInfo, bool rendered)

clearPhysicsRep(Forest * forest)

findIndexByKey(ForestItemKey key, U32 * outIndex)

The find function does a binary search thru the sorted item list.

If the key is found then the index is the position of the item. If the key is not found the index is the correct insertion position for adding the new item.

**Parameters:**

key | The item key to search for. |

outIndex | The item index or insertion index if the item was not found. |

Returns true if the item index is found.

freeBatches()

getBounds()

The bounds of the cell generated by combining the bounds of all the contained items or child cells.

getChildAt(const Point3F & pos)

Returns the child cell at the position.

The position is assumed to be within this cell.

getChildren(Vector< const ForestCell * > * outCells)

getChildren(Vector< ForestCell * > * outCells)

Returns the child cells.

getItems()

Returns the items from this one cell.

getItems(Vector< ForestItem > * outItems)

Returns the items from this cell and all its sub-cells.

getLargestItem()

getRect()

Returns the 2D rectangle of quad tree bounds for this cell.

It is fixed and does not change during runtime.

getZoneOverlap()

Returns a bit vector of what zones overlap this cell.

hasBatches()

insertItem(ForestItemKey key, ForestItemData * data, const MatrixF & xfm, F32 scale)

invalidateBounds()

Set flag so this cells bounds will be recalculated the next call to getBounds.

isBranch()

Returns true if this cell has child cells.

This is the same as !isLeaf() but exists for clarity.

isEmpty()

Returns true if this cell has no items and no child cells.

isLeaf()

Returns true if this cell does not have child cells.

It should directly contain items.

removeItem(ForestItemKey key, const Point3F & keyPos, bool deleteIfEmpty)

render(TSRenderState * rdata, const Frustum * culler)

renderBatches(SceneRenderState * state, Frustum * culler)