/**
   * Create a new panel
   *
   * @param game The game being held
   * @param shared True if shared GL context should be enabled. This allows multiple panels to share
   *     textures and other GL resources.
   * @throws org.newdawn.slick.SlickException Indicates a failure during creation of the container
   */
  public CanvasGameContainer(Game game, boolean shared) throws SlickException {
    super();

    this.game = game;
    setIgnoreRepaint(true);
    requestFocus();
    setSize(500, 500);

    container = new Container(game, shared);
    container.setForceExit(false);
  }
Example #2
0
  /** Launches opsu!. */
  public static void main(String[] args) {
    // log all errors to a file
    Log.setVerbose(false);
    try {
      DefaultLogSystem.out = new PrintStream(new FileOutputStream(Options.LOG_FILE, true));
    } catch (FileNotFoundException e) {
      Log.error(e);
    }
    Thread.setDefaultUncaughtExceptionHandler(
        new Thread.UncaughtExceptionHandler() {
          @Override
          public void uncaughtException(Thread t, Throwable e) {
            ErrorHandler.error("** Uncaught Exception! **", e, true);
          }
        });

    // parse configuration file
    Options.parseOptions();

    // only allow a single instance
    try {
      SERVER_SOCKET = new ServerSocket(Options.getPort(), 1, InetAddress.getLocalHost());
    } catch (UnknownHostException e) {
      // shouldn't happen
    } catch (IOException e) {
      ErrorHandler.error(
          String.format(
              "opsu! could not be launched for one of these reasons:\n"
                  + "- An instance of opsu! is already running.\n"
                  + "- Another program is bound to port %d. "
                  + "You can change the port opsu! uses by editing the \"Port\" field in the configuration file.",
              Options.getPort()),
          null,
          false);
      System.exit(1);
    }

    // set path for lwjgl natives - NOT NEEDED if using JarSplice
    File nativeDir = new File("./target/natives/");
    if (nativeDir.isDirectory())
      System.setProperty("org.lwjgl.librarypath", nativeDir.getAbsolutePath());

    // set the resource paths
    ResourceLoader.addResourceLocation(new FileSystemLocation(new File("./res/")));

    // initialize databases
    try {
      DBController.init();
    } catch (UnsatisfiedLinkError e) {
      errorAndExit(e, "The databases could not be initialized.");
    }

    // check if just updated
    if (args.length >= 2) Updater.get().setUpdateInfo(args[0], args[1]);

    // check for updates
    if (!Options.isUpdaterDisabled()) {
      new Thread() {
        @Override
        public void run() {
          try {
            Updater.get().checkForUpdates();
          } catch (IOException e) {
            Log.warn("Check for updates failed.", e);
          }
        }
      }.start();
    }

    // start the game
    try {
      // loop until force exit
      while (true) {
        Opsu opsu = new Opsu("opsu!");
        Container app = new Container(opsu);

        // basic game settings
        Options.setDisplayMode(app);
        String[] icons = {"icon16.png", "icon32.png"};
        app.setIcons(icons);
        app.setForceExit(true);

        app.start();

        // run update if available
        if (Updater.get().getStatus() == Updater.Status.UPDATE_FINAL) {
          close();
          Updater.get().runUpdate();
          break;
        }
      }
    } catch (SlickException e) {
      errorAndExit(e, "An error occurred while creating the game container.");
    }
  }