Ejemplo n.º 1
0
  /**
   * Special version of changeGLController(), won't call pause() or dispose() in old GLController.
   * Can for example be used if assets are transferred between GLController's. Can be called from
   * anywhere within a GLController. Will pause and dispose of old GLController.
   *
   * @throws IllegalArgumentException if new GLController is null
   * @param glController the new GLController
   */
  public void changeGLControllerDontDispose(GLController glController) {
    if (glController == null) {
      throw new IllegalArgumentException("New GLController is null, not allowed.");
    }

    // Resumes new GLController
    glController.onResume();
    this.glController = glController;

    catchBackKey(glController.catchBackKey());
  }
Ejemplo n.º 2
0
  @Override
  public void onDrawFrame(GL10 unused) {
    // Stores state in local variable to avoid synchronizing bugs.
    State localState = null;
    synchronized (this) {
      localState = this.state;
    }

    switch (localState) {
      case RUNNING:
        // Calculates delta.
        deltaTime = (System.nanoTime() - startTime) / 1000000000.0;
        startTime = System.nanoTime();

        // Calculates current fps.
        frameCount++;
        if (startTime - lastFPSCount >= 1000000000.0) {
          fps = frameCount;
          fpsBuilder.delete(5, fpsBuilder.length());
          fpsBuilder.append(fps);
          if (fps < 30) { // TODO: To be removed. Only log fps if it falls below 30.
            Log.d("FPS", fpsBuilder.toString());
          }
          frameCount = 0;
          lastFPSCount = System.nanoTime();
        }

        // Updates current GLController and GLView
        glController.update(deltaTime, fps);
        break;

      case PAUSING:
        glController.onPause();
        synchronized (this) {
          this.state = State.SLEEPING;
          this.notifyAll();
        }
        break;

      case FINISHING:
        glController.onPause();
        glController.dispose();
        synchronized (this) {
          this.state = State.SLEEPING;
          this.notifyAll();
        }
        break;

      case STARTING:
      case SLEEPING:
      default:
        throw new AssertionError("Illegal state in GLActivity");
    }
  }
Ejemplo n.º 3
0
  /**
   * Changes GLController Can be called from anywhere within a GLController. Will pause and dipose
   * of old GLController.
   *
   * @throws IllegalArgumentException if new GLController is null
   * @param glController the new GLController
   */
  @Deprecated // TODO: Not really deprecated, but is needed to make sure people don't use wrong
              // method in project.
  public void changeGLController(GLController glController) {
    if (glController == null) {
      throw new IllegalArgumentException("New GLController is null, not allowed.");
    }

    // Dispose of old GLController
    this.glController.onPause();
    this.glController.dispose();

    // Resumes new GLController
    glController.onResume();
    this.glController = glController;

    catchBackKey(glController.catchBackKey());
  }
Ejemplo n.º 4
0
  @Override
  public void onSurfaceCreated(GL10 unused, EGLConfig config) {
    // Resets fps counter.
    startTime = System.nanoTime();
    lastFPSCount = startTime;
    frameCount = 0;
    fps = 0;
    deltaTime = 0;

    synchronized (this) {
      if (state == State.STARTING) { // Gets initial GLController if program is starting up.
        glController = getInitialGLController(this);
      }
      state = State.RUNNING; // Surface was created, so program is running.
      glController.onResume();
    }
  }