The
controller object is the foundation of a
breve simulation. The controller
object is a single instance which acts as the "boss" for the
simulation. When the simulation starts, it is the controller object
which is responsible for creating and setting up the rest of the
simulation. The controller object is the
only object which is automatically instantiated when the simulation
begins. If you're used to programming in C or C++, the
controller is like the main
function.
The first step in writing a breve simulation is to create a controller class which will setup and manage the simulation. The controller class you create must be a subclass of the class Control or one of its subclasses. Details on how to do this is described in the rest of this chapter.
As shown in the previous section (the section called “A Simple Example”), the controller object is specified at the top of your simulation file using the word controller:
Controller myControllerClass
.
This tells breve to create an
instance of myControllerClass
when the simulation begins. This controller object will create and
setup the rest of the objects in the simulation. The controller object
does so by implementing the simulation setup code in the init
method. Details on constructing classes and
implementing an init
method are described
in more detail in the rest of this chapter.
In addition to setting up the simulation, the controller object is also used as a liaison between simulation objects, the breve engine and the user. While other instances may come and go, the controller object is forever. The controller class contains a great number of methods for controlling the behavior of simulations, the appearance of the graphical display and interactions with the user interface. See the class documentation on Control for more information. As with some of the other topics covered in this section, the significance of these concepts will become clearer in the rest of the documentation.