Exemple #1
0
  /**
   * Connect to the server and execute the initial data exchange. Returns when the connection is
   * successfully established
   *
   * @return false if the connection failed and the game should quit (or go back to the menu)
   */
  public boolean loop() {
    networkedGame = new NetworkedGame(loop, httpUrl, nickname);

    loadingCamera = new Camera(resourceDB);
    loadingStarfield = new StarField(SwissArmyKnife.random.nextInt(), resourceDB);

    loadingCamera.setScreenPosition(0, 0);
    loadingCamera.setPosition(0, loadingCameraY);

    connection = new SingleGameConnection(wsUri, loop);
    connection.addListener(networkedGame);
    connection.connect();

    loop.addTickEvent(this);

    try {
      while (!loop.isInterruped() && networkedGame.isConnecting()) {
        Display.update();

        if (Display.isCloseRequested()) {
          log.log(Level.WARNING, "Close requested in connect loop");
          return false;
        }

        loadingCamera.setDimension(Display.getWidth(), Display.getHeight());

        Graph.graphicsLoop();

        Client.initGL();

        loop.loop();

        loadingStarfield.render(loadingCamera);

        String line = "Connecting...";
        int line_width = Graph.g.getFont().getWidth(line);
        Graph.g.setColor(Color.white);
        Graph.g.drawString(
            line,
            loadingCamera.dimensionHalf.x - line_width / 2,
            loadingCamera.dimension.y * 0.75f);

        loadingCamera.setPosition(0, loadingCameraY);

        Display.sync(60);
      }

      if (loop.isInterruped()) {
        log.log(Level.WARNING, "Connect loop interrupted");
        return false;
      }

      return !networkedGame.isConnecting() && !networkedGame.isDisconnected();
    } finally {
      loop.removeTickEvent(this);
    }
  }
Exemple #2
0
 public ClockSource getSyncedClockSource() {
   return networkedGame.getSyncedClockSource();
 }