Commits

Cat's Eye Technologies  committed ad1fdb5

Basic support for running at full speed as opposed to animating.

  • Participants
  • Parent commits 13046d6

Comments (0)

Files changed (3)

File make-cygwin.sh

 # Helper script for compiling yoob under Cygwin.
 # The contents of this file have been placed in the public domain.
 
-make \
-    JAVAC='"/cygdrive/c/Program Files/Java/jdk1.6.0_22/bin/javac"' \
-    JAVA='"/cygdrive/c/Program Files/Java/jre6/bin/java"' \
-    PATHSEP=';' \
-    $*
+make PATHSEP=';' $*

File src/ContentPane.java

     private JPanel buttonPanel;
     private final JApplet plet;
 
-    private JButton buttonReset, buttonStep, buttonRun, buttonStop, buttonEdit;
+    private JButton buttonReset, buttonStop, buttonEdit;
+    private JButton buttonStep, buttonWalk, buttonRun;
     private JButton buttonAbout;
     private JButton buttonEsowiki;
     private JSlider sliderRunSpeed;
         buttonStep.setToolTipText("Execute one step of the program.");
         buttonStep.setEnabled(false);
 
+        buttonWalk = new JButton("Walk");
+        buttonWalk.setMnemonic(KeyEvent.VK_W);
+        buttonWalk.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                walk();
+            }
+        });
+        buttonWalk.setToolTipText("Walk through (animate the execution of) the program.");
+        buttonWalk.setEnabled(false);
+
         buttonRun = new JButton("Run");
         buttonRun.setMnemonic(KeyEvent.VK_R);
         buttonRun.addActionListener(new ActionListener() {
                 run();
             }
         });
-        buttonRun.setToolTipText("Run the program.");
+        buttonRun.setToolTipText("Run the program (full speed, no animation.)");
         buttonRun.setEnabled(false);
 
         buttonStop = new JButton("Stop");
         buttonPanel.add(buttonEdit);
         buttonPanel.add(buttonReset);
         buttonPanel.add(buttonStep);
+        buttonPanel.add(buttonWalk);
         buttonPanel.add(buttonRun);
         buttonPanel.add(buttonStop);
         buttonPanel.add(sliderRunSpeed);
         // We just selected a language, but we don't have a program yet
         buttonReset.setEnabled(false);
         buttonStep.setEnabled(false);
+        buttonWalk.setEnabled(false);
         buttonRun.setEnabled(false);
         buttonEdit.setEnabled(false);
         buttonAbout.setText("About " + language.getName() + "...");
         }
     }
 
+    protected void walk() {
+        disableButtonsPerRun();
+        runThread.setTurbo(false);
+        runThread.proceed();
+    }
+
     protected void run() {
+        disableButtonsPerRun();
+        runThread.setTurbo(true);
+        runThread.proceed();
+    }
+
+    protected void disableButtonsPerRun() {
         languageMenu.setEnabled(false);
         examplesMenu.setEnabled(false);
         optionsMenu.setEnabled(false);
         buttonEdit.setEnabled(false);
         buttonReset.setEnabled(false);
         buttonStep.setEnabled(false);
+        buttonWalk.setEnabled(false);
         buttonRun.setEnabled(false);
         buttonAbout.setEnabled(false);
         buttonStop.setEnabled(true);
-        runThread.proceed();
     }
 
     protected void stop() {
         buttonAbout.setEnabled(true);
         if (!currentState.hasHalted()) {
             buttonStep.setEnabled(true);
+            buttonWalk.setEnabled(true);
             buttonRun.setEnabled(true);
         }
         runThread.halt();
         refreshDepictions();
         if (currentState.hasHalted()) {
             buttonStep.setEnabled(false);
+            buttonWalk.setEnabled(false);
             buttonRun.setEnabled(false);
         }
         if (currentState.needsInput()) {
     protected void reset() {
         currentState = initialState.clone();
         buttonEdit.setEnabled(true);
+        buttonWalk.setEnabled(true);
         buttonRun.setEnabled(true);
         buttonStep.setEnabled(true);
         buttonStop.setEnabled(false);

File src/RunThread.java

     private ContentPane cp;
     private EsolangLoader loader;
     private int cyclesPerSecond;
-    private boolean proceed;
+    private boolean proceed, turbo;
 
     public RunThread(ContentPane cp, int cyclesPerSecond, EsolangLoader loader) {
         this.cp = cp;
         this.loader = loader;
+        this.turbo = false;
         setRunSpeed(cyclesPerSecond);
         mailbox = new SynchronousQueue<RunThreadMessage>();
     }
         }
     }
 
+    public void setTurbo(boolean turbo) {
+        // XXX maybe this should be a message?  I don't remember
+        this.turbo = turbo;
+    }
+
     public void proceed() {
         try {
             mailbox.put(new ProceedMessage());
         long delay;
         for (;;) {
             if (proceed) {
-                if (cyclesPerSecond > 0) {
+                if (turbo) {
+                    int counter = 100;
+                    while (proceed && counter > 0) {
+                        proceed = cp.step();
+                        counter++;
+                    }
+                    delay = 0;
+                } else if (cyclesPerSecond > 0) {
                     delay = (long)(1000 / cyclesPerSecond);
                     proceed = cp.step();
                 } else {