Fio:Iterators

From Fio

(Difference between revisions)
Line 21: Line 21:
we can call first() to position an iterator to its beginning; next() to step to the next element in current iterating order. And when isDone() returns true, there's no element left to iterate. current() returns the element the iterator points to.
we can call first() to position an iterator to its beginning; next() to step to the next element in current iterating order. And when isDone() returns true, there's no element left to iterate. current() returns the element the iterator points to.
 +
To draw the game, we just create an inorder itor then iterat on the game world to draw each element in the viewport. A render itor begins from the root of the world.
===Root of The World===
===Root of The World===

Revision as of 15:51, 30 August 2006

"To iterate is humane, to recurse - divine!"

Iterator

Contents

One Design Principle of Fio is:

  • Rendering is an inorder iterating process; Picking is a postorder one.

while rendering is to draw the game world and picking is to dispatch mouse event so that the player can interact with the game.

In Fio we use a typical GoF Iterator:

template<typename T>
class Iterator{
public:
	virtual ~Iterator(){}
	virtual void first() = 0;
	virtual void next() = 0;
	virtual bool isDone() = 0;
	virtual T current() = 0;
};

we can call first() to position an iterator to its beginning; next() to step to the next element in current iterating order. And when isDone() returns true, there's no element left to iterate. current() returns the element the iterator points to.

To draw the game, we just create an inorder itor then iterat on the game world to draw each element in the viewport. A render itor begins from the root of the world.

Root of The World

Iterators: Policy & Mechanism

Isometric Iterator for Layer

Personal tools