Special Method Names

Certain method names have special meaning in steve, in that they are called automatically by the simulation at special times. These methods, in particular init and iterate are critical, as they are the entry-point into how your agents are initialized and how they will behave. These special method names are outlined below:

  • init, if it exists, is called automatically when a class is instantiated. The method is called not only for the class being instantiated, but also for its superclass and all other ancestors up to the root object. Though you should implement an init method for your class which will set up the instance when the class is instantiated, the init method should never be called manually.

  • iterate, if it exists, is called automatically during every iteration of the breve engine. If your class must perform a task during each iteration, then you may choose to implement an iterate method. The order in which the objects in the simulation are iterated cannot be controlled—if you need to control the order in which actions are performed, consider using iterate in conjunction with the post-iterate method described below.

    Unlike the init and destroy methods, iterate is not automatically called for the superclasses of an instance. This means that your iterate method must call super iterate if you wish to incorporate the parent's iterate method. This is absolutely necessary for subclasses of Control.

  • post-iterate, if it exists, is called automatically during every iteration of the breve engine after the iterate methods for all objects have been called. It is occasionally desirable to perform an action during each iteration, which requires data produced during that very same iteration from other objects. If this action is to be performed in the iterate method, than object A cannot be certain that object B has been iterated yet (and vice-versa). To solve this problem, objects may implement a post-iterate method which is automatically called after all objects have been iterated. The PatchLife demo uses this technique.

  • destroy, if it exists, is called automatically when a class is being freed. However, unlike init, and like iterate, you must explicitly call the super class destroy method if you need it to be called as well. If your class needs to perform certain tasks before being destroyed, you should implement this method. Be warned the you need to be carefull not to free an object referenced in the base class if it is needed for the base class destroy method.