Ejemplo n.º 1
0
 public void stopEvaluate() {
   // user requested run be stopped so tell
   // run thread to stop
   Thread tmp = runThread;
   runThread = null;
   tmp.interrupt();
 }
Ejemplo n.º 2
0
 public void run() {
   if (Thread.currentThread() != this.mt)
     throw (new RuntimeException("MainFrame is being run from an invalid context"));
   Thread ui = new HackThread(p, "Haven UI thread");
   ui.start();
   try {
     try {
       Session sess = null;
       while (true) {
         UI.Runner fun;
         if (sess == null) {
           Bootstrap bill = new Bootstrap(Config.defserv, Config.mainport);
           if ((Config.authuser != null) && (Config.authck != null)) {
             bill.setinitcookie(Config.authuser, Config.authck);
             Config.authck = null;
           }
           fun = bill;
           setTitle(String.format("Amish Paradise %s", version));
         } else {
           fun = new RemoteUI(sess);
           setTitle(String.format("Amish Paradise %s \u2013 %s", version, sess.username));
         }
         sess = fun.run(p.newui(sess));
       }
     } catch (InterruptedException e) {
     }
     savewndstate();
   } finally {
     ui.interrupt();
     dispose();
   }
 }
Ejemplo n.º 3
0
 public synchronized void stop() {
   running = false;
   try {
     thread.join();
   } catch (InterruptedException e) {
     thread.interrupt();
   }
 }
Ejemplo n.º 4
0
 /** Request that the loading of the applet be stopped. */
 protected synchronized void stopLoading() {
   // REMIND: fill in the body
   if (loaderThread != null) {
     // System.out.println("Interrupting applet loader thread: " + loaderThread);
     loaderThread.interrupt();
   } else {
     setLoadAbortRequest();
   }
 }
Ejemplo n.º 5
0
 void setMessage(Animator a) {
   anim = a;
   who.setText(a.author());
   ref.setText(a.description());
   pan.remove(last);
   last = a.container();
   pan.add(last, "Center");
   if (T != null) T.interrupt();
 }
Ejemplo n.º 6
0
 public static synchronized void fail(String whyFailed) {
   Sysout.println("The test failed: " + whyFailed);
   Sysout.println("The test is over, hit  Ctl-C to stop Java VM");
   // check if this called from main thread
   if (mainThread == Thread.currentThread()) {
     // If main thread, fail now 'cause not sleeping
     throw new RuntimeException(whyFailed);
   }
   theTestPassed = false;
   testGeneratedInterrupt = true;
   failureMessage = whyFailed;
   mainThread.interrupt();
 } // fail()
Ejemplo n.º 7
0
 public static synchronized void pass() {
   Sysout.println("The test passed.");
   Sysout.println("The test is over, hit  Ctl-C to stop Java VM");
   // first check if this is executing in main thread
   if (mainThread == Thread.currentThread()) {
     // Still in the main thread, so set the flag just for kicks,
     // and throw a test passed exception which will be caught
     // and end the test.
     theTestPassed = true;
     throw new TestPassedException();
   }
   theTestPassed = true;
   testGeneratedInterrupt = true;
   mainThread.interrupt();
 } // pass()
Ejemplo n.º 8
0
 /** Disconnects from running debugged process. */
 public void disconnect() throws DebuggerException {
   if (breakpointMain != null) {
     for (int x = 0; x < breakpointMain.length; x++) breakpointMain[x].remove();
     breakpointMain = null;
   }
   try {
     if (virtualMachine != null) virtualMachine.dispose();
   } catch (VMDisconnectedException e) {
   }
   if (threadManager != null) threadManager.finish();
   if (debuggerThread != null) {
     debuggerThread.interrupt();
     debuggerThread.stop();
   }
   super.finishDebugger();
 }
Ejemplo n.º 9
0
 /**
  * The disconnect method will stop the eventreplayer, and send null to the other peers, to stop
  * their reading from their streams. The GUI-menu is updated appropriately.
  */
 public void disconnect() {
   setTitle("Disconnected");
   active = false;
   if (connected == true) {
     er.stopStreamToQueue();
     ert.interrupt();
     setDocumentFilter(null);
     connected = false;
     setLocked(false);
   }
   deregisterOnPort();
   Disconnect.setEnabled(false);
   Connect.setEnabled(true);
   Listen.setEnabled(true);
   Save.setEnabled(true);
   SaveAs.setEnabled(true);
 }
Ejemplo n.º 10
0
  public void run() {
    long start, end, sleepTime;

    while (running) {
      start = System.currentTimeMillis();
      if (gridSet) {
        grid.scanStep();
      }
      repaint();
      end = System.currentTimeMillis();
      // Sleep to match FPS limit
      sleepTime = (1000 / framerate) - (end - start);
      if (sleepTime > 0) {
        try {
          Thread.sleep(sleepTime);
        } catch (InterruptedException e) {
          thread.interrupt();
        }
      }
    }
  }
Ejemplo n.º 11
0
  public void run() {
    try {
      Thread drawthread = new HackThread(drawfun, "Render thread");
      drawthread.start();
      synchronized (drawfun) {
        while (state == null) drawfun.wait();
      }
      try {
        long now, then;
        long frames[] = new long[128];
        int framep = 0, waited[] = new int[128];
        while (true) {
          int fwaited = 0;
          Debug.cycle();
          UI ui = this.ui;
          then = System.currentTimeMillis();
          CPUProfile.Frame curf = null;
          if (Config.profile) curf = uprof.new Frame();
          synchronized (ui) {
            if (ui.sess != null) ui.sess.glob.ctick();
            dispatch();
            ui.tick();
            if ((ui.root.sz.x != w) || (ui.root.sz.y != h)) ui.root.resize(new Coord(w, h));
          }
          if (curf != null) curf.tick("dsp");

          BGL buf = new BGL();
          GLState.Applier state = this.state;
          rootdraw(state, ui, buf);
          if (curf != null) curf.tick("draw");
          synchronized (drawfun) {
            now = System.currentTimeMillis();
            while (bufdraw != null) drawfun.wait();
            bufdraw = new Frame(buf, state.cgl);
            drawfun.notifyAll();
            fwaited += System.currentTimeMillis() - now;
          }

          ui.audio.cycle();
          if (curf != null) curf.tick("aux");

          now = System.currentTimeMillis();
          long fd = bgmode ? this.bgfd : this.fd;
          if (now - then < fd) {
            synchronized (events) {
              events.wait(fd - (now - then));
            }
            fwaited += System.currentTimeMillis() - now;
          }

          frames[framep] = now;
          waited[framep] = fwaited;
          for (int i = 0, ckf = framep, twait = 0; i < frames.length; i++) {
            ckf = (ckf - 1 + frames.length) % frames.length;
            twait += waited[ckf];
            if (now - frames[ckf] > 1000) {
              fps = i;
              uidle = ((double) twait) / ((double) (now - frames[ckf]));
              break;
            }
          }
          framep = (framep + 1) % frames.length;

          if (curf != null) curf.tick("wait");
          if (curf != null) curf.fin();
          if (Thread.interrupted()) throw (new InterruptedException());
        }
      } finally {
        drawthread.interrupt();
        drawthread.join();
      }
    } catch (InterruptedException e) {
    } finally {
      ui.destroy();
    }
  }
Ejemplo n.º 12
0
 public void stop() {
   if (thd != null) thd.interrupt();
   thd = null;
 }
Ejemplo n.º 13
0
  public void buttonPressed(Button button) {
    if (button.getId() == TitleMenu.RESTART_GAME_ID) {
      clearMenus();
      TitleMenu menu = new TitleMenu(GAME_WIDTH, GAME_HEIGHT);
      addMenu(menu);

    } else if (button.getId() == TitleMenu.START_GAME_ID) {
      clearMenus();
      isMultiplayer = false;

      localId = 0;
      synchronizer = new TurnSynchronizer(this, null, 0, 1);
      synchronizer.setStarted(true);

      createLevel(TitleMenu.level);
    } else if (button.getId() == TitleMenu.SELECT_LEVEL_ID) {
      addMenu(new LevelSelect(false));
    } else if (button.getId() == TitleMenu.SELECT_HOST_LEVEL_ID) {
      addMenu(new LevelSelect(true));
    } else if (button.getId() == TitleMenu.HOST_GAME_ID) {
      addMenu(new HostingWaitMenu());
      isMultiplayer = true;
      isServer = true;
      try {
        if (isServer) {
          localId = 0;
          serverSocket = new ServerSocket(3000);
          serverSocket.setSoTimeout(1000);

          hostThread =
              new Thread() {

                public void run() {
                  boolean fail = true;
                  try {
                    while (!isInterrupted()) {
                      Socket socket = null;
                      try {
                        socket = serverSocket.accept();
                      } catch (SocketTimeoutException e) {

                      }
                      if (socket == null) {
                        System.out.println("asdf");
                        continue;
                      }
                      fail = false;

                      packetLink = new NetworkPacketLink(socket);

                      createServerState = 1;
                      break;
                    }
                  } catch (Exception e) {
                    e.printStackTrace();
                  }
                  if (fail) {
                    try {
                      serverSocket.close();
                    } catch (IOException e) {
                    }
                  }
                };
              };
          hostThread.start();
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    } else if (button.getId() == TitleMenu.JOIN_GAME_ID) {
      addMenu(new JoinGameMenu());
    } else if (button.getId() == TitleMenu.CANCEL_JOIN_ID) {
      popMenu();
      if (hostThread != null) {
        hostThread.interrupt();
        hostThread = null;
      }
    } else if (button.getId() == TitleMenu.PERFORM_JOIN_ID) {
      menuStack.clear();
      isMultiplayer = true;
      isServer = false;

      try {
        localId = 1;
        packetLink = new ClientSidePacketLink(TitleMenu.ip, 3000);
        synchronizer = new TurnSynchronizer(this, packetLink, localId, 2);
        packetLink.setPacketListener(this);
      } catch (Exception e) {
        e.printStackTrace();
        // System.exit(1);
        addMenu(new TitleMenu(GAME_WIDTH, GAME_HEIGHT));
      }
    } else if (button.getId() == TitleMenu.SELECT_DIFFICULTY_ID) {
      addMenu(new DifficultySelect());
    } else if (button.getId() == TitleMenu.EXIT_GAME_ID) {
      System.exit(0);
    }
  }