Exemple #1
0
 static {
   String system = System.getProperty("os.name").toLowerCase();
   OSX = system.indexOf("mac") >= 0;
   WIN = system.indexOf("win") >= 0;
   LINUX = system.indexOf("nux") >= 0 | system.indexOf("nix") >= 0 | system.indexOf("aix") >= 0;
   assert ((WIN && !OSX && !LINUX) || (!WIN && OSX && !LINUX) || (!WIN && !OSX && LINUX));
 }
Exemple #2
0
  public void run() {
    init();
    engine = new Engine();

    long lastTime = System.nanoTime();
    double delta = 0.0;
    // Amout of nanoseconds in 1/60th of a second
    double ns = 1000000000.0 / 60.0;
    long timer = System.currentTimeMillis();
    int updates = 0;
    int frames = 0;
    while (running) {
      long now = System.nanoTime();
      delta += (now - lastTime) / ns;
      lastTime = now;
      // if delta >= than one then the amount of time >= 1/60th of a second
      if (delta >= 1.0) {
        update();
        updates++;
        delta--;
      }
      render();
      frames++;
      // If a second has passed, we print the stats
      if (System.currentTimeMillis() - timer > 1000) {
        timer += 1000;
        System.out.println(updates + " ups, " + frames + " fps");
        updates = 0;
        frames = 0;
      }
      if (glfwWindowShouldClose(window) == GL_TRUE) running = false;
    }
    engine.CleanUp();
    keyCallback.release();
    sizeCallback.release();
    mouseCallback.release();
    focusCallback.release();
    glfwDestroyWindow(window);
    glfwTerminate();
  }
Exemple #3
0
  void renderLoop() {
    long startTime = System.currentTimeMillis() + 5000;
    long fps = 0;

    while (glfwWindowShouldClose(window.handle) == GLFW_FALSE) {
      Runnable event;
      while ((event = events.poll()) != null) event.run();

      try {
        display();
      } catch (Exception e) {
        e.printStackTrace();
        break;
      }

      glfwSwapBuffers(window.handle);

      if (startTime > System.currentTimeMillis()) {
        fps++;
      } else {
        long timeUsed = 5000 + (startTime - System.currentTimeMillis());
        startTime = System.currentTimeMillis() + 5000;
        log(
            String.format(
                "%s: %d frames in 5 seconds = %.2f",
                getPlatformInfoStringUTF8(platform, CL_PLATFORM_VENDOR),
                fps,
                fps / (timeUsed / 1000f)));
        fps = 0;
      }
    }

    cleanup();

    window.signal.countDown();
  }