RenderTreeIterator3D

Package: Libraries.Game.Graphics.Trees · Inherits from: Libraries.Language.Object, Libraries.Containers.Iterator

RenderTreeIterator3D visits every item in a RenderTree3D once, in the tree's own order. It walks from leaf to leaf with the tree's GetFirstLeaf and GetNextLeaf actions, which follow the links between the tree's nodes, so each step takes a few moves however many items there are. The iterator always knows the leaf after the one it last returned. Removing the item it just returned is therefore safe. Removing other items, or adding items, can change the tree's shape, so the rest of the walk may miss some items or visit some twice. The order comes from how the tree is built, not from when items were added, and it can change as items move.

Example Code

use Libraries.Game.Graphics.Trees.DynamicVolumeRenderTree3D
use Libraries.Containers.Iterator
use Libraries.Interface.Item3D

DynamicVolumeRenderTree3D tree
Item3D first
first:SetDimensions(1, 1, 1)
Item3D second
second:SetDimensions(1, 1, 1)
second:SetPosition(5, 0, 0)
tree:Add(first)
tree:Add(second)

Iterator<Item3D> iterator = tree:GetIterator()
repeat while iterator:HasNext()
Item3D item = iterator:Next()
output item:GetX()
end

Actions

GetCurrent()

This action returns the item Next last returned, without moving on.

Returns

Item3D: The current item, or undefined before the first call to Next.

HasNext()

This action returns true if there is another item to visit.

Returns

boolean: True if Next will return an item.

Next()

This action moves to the next item and returns it.

Returns

Item3D: The next item, or undefined if there are no more.

Rewind()

This action starts the walk again from the tree's first item.

SetTree(Libraries.Game.Graphics.Trees.RenderTree3D value)

This action sets the tree to walk, and starts at its first item.

Parameters

Inherited Actions

3 actions from Libraries.Language.Object