// Copyright 1999 Regents of The University of Michigan // This file just contains a method extracted from a java class. // It is only meant to be used for instruction. /** This method starts and runs the main control loop of the simulator. */ public void StartSimulator() { ListElement elem; // for walking through linked lists DecisionMaker dm; // temporary variable for accessing a decision maker int i; stopRequested = false; // control loop quits when set to true frame.show(); // display the simulator window // Control Loop do { // don't take a step when stopped or paused if (!paused && !stopRequested) { // walk through the decision makers connected to the simulator for (elem = decisionMakers.head; elem != null; elem = elem.next) { dm = (DecisionMaker) elem.data; // if the decision maker was not in the middle of thinking, let it take a step // and attempt actions if (dm.thinkTimeLeft == 0.0) dm.TakeStep(); // otherwise, just decrement the tie left remaining to think else { dm.thinkTimeLeft -= 1.0; if (dm.thinkTimeLeft < 0.0) dm.thinkTimeLeft = 0.0; } } // update the states of entities by processing their action queues UpdateState(); // redraw the graphics frame.repaintPanel(); // increment the clock on each step clock += 1.0; } // slow control loop down by making the process sleep for a short time try { Thread.sleep(200); } catch (InterruptedException e) { } // if the clock is past its limit, stop the simulator if (clock > clockStop) stopRequested = true; } while (true); }