simtools
Simtools is the current catch-all library for the miscellaneous things
needed to run a Swarm simulation. Simtools is where the control panel
is defined, as well as where certain useful global variables are set.
global.h
global.h contains various global definitions of interest to Swarm
programmers.
void initSwarm(int argc, char ** argv)
- initialize the Swarm libraries to be ready to be used.
This should be the first line of code you call in any Swarm
application. argc and argv are the input parameters to
main()
.
ProbeDisplayManager * probeDisplayManager
- a global instance of a ProbeDisplayManager object. You can use
this object to create new probe displays, and should schedule an
update
message to it in your display schedule to have probe
displays update.
ProbeLibrary * probeLibrary
- the global probeLibrary keeps ProbeMaps for all the classes in
the system.
PMMLCG * randomGenerator
,
UniformRandom * uniformRandom
- A global random number generator is defined for your
convenience. It is seeded randomly everytime the system starts.
For more sophisticated simulation you should use the random
number library to its full potential: see the
documentation on random for more
detail.
int swarmGUIMode
- a flag that indicates whether graphics are enabled. Set
automatically based on whether the
DISPLAY
environment variable is set. If it is false, then
globalTkInterp
(from libtkobjc) is set to be a
normal Tcl interpreter instead of a Tcl/Tk/BLT interpreter.
GUISwarm
GUISwarm is a subclass of Swarm that is used as a toplevel Swarm for
simulations running with a graphical user interface. The GUISwarm
creates a ControlPanel automatically for you and defines a "go" method
that interprets the state of the ControlPanel to keep things running
in response to user input. Users subclass GUISwarm much like they
subclass a normal Swarm, implementing the same kind of buildObjects,
buildActions, and activateIn methods. When you are done building your
Observer Swarm, start it as a toplevel via
[myGUISwarm go]
.
The control panel places a few responsibilities on the GUISwarm
subclass author. In particular, a message to
[controlPanel doTkEvents
should be scheduled fairly
frequently - only when that method is executed will the user interface
update (and the stop button be checked). Also, it is often useful
to use [controlPanel waitForControlEvent]
to wait for the
user to indicate they're ready for execution to proceed.
-go
- Start the activity running, and also handle user requests via
the control panel. Returns either
Completed
(the
model ran until requested to terminate) or
ControlStateQuit
(the user pressed the quit button).
ControlPanel
ControlPanel keeps track of the users requests to run, stop, quit, or
time step the simulation. It cooperates with the GUISwarm to control
the execution of activities in Swarm.
-waitForControlEvent
- wait until the control panel is not in state
ControlStateStopped
-getState
- get the current button state of the control panel. Is one of
ControlStateRunning
, ControlStateStopped
,
ControlStateStepping
, ControlStateNextTime
,
or ControlStateQuit
.
-setStateRunning
, -setStateStopped
,
-setStateStepping
, -setStateQuit
,
-setStateNextTime
- sets the state to the indicated value, and also sends the
appropriate stop or terminate message to the running activity tree.
Nelson Minar <nelson@santafe.edu>
Last modified: Sun May 12 18:39:33 MDT 1996