示例#1
0
  private void setupLoop() {
    // setup modules
    try {
      graphics = new GwtGraphics(root, config);
    } catch (Throwable e) {
      root.clear();
      root.add(new Label("Sorry, your browser doesn't seem to support WebGL"));
      return;
    }
    lastWidth = graphics.getWidth();
    lastHeight = graphics.getHeight();
    Gdx.app = this;
    Gdx.audio = new GwtAudio();
    Gdx.graphics = graphics;
    Gdx.gl20 = graphics.getGL20();
    Gdx.gl = graphics.getGLCommon();
    Gdx.files = new GwtFiles(preloader);
    this.input = new GwtInput(graphics.canvas);
    Gdx.input = this.input;
    this.net = new GwtNet();
    Gdx.net = this.net;

    // tell listener about app creation
    try {
      listener.create();
      listener.resize(graphics.getWidth(), graphics.getHeight());
    } catch (Throwable t) {
      error("GwtApplication", "exception: " + t.getMessage(), t);
      t.printStackTrace();
      throw new RuntimeException(t);
    }

    // setup rendering timer
    new Timer() {
      @Override
      public void run() {
        try {
          graphics.update();
          if (Gdx.graphics.getWidth() != lastWidth || Gdx.graphics.getHeight() != lastHeight) {
            GwtApplication.this.listener.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
            lastWidth = graphics.getWidth();
            lastHeight = graphics.getHeight();
            Gdx.gl.glViewport(0, 0, lastWidth, lastHeight);
          }
          for (int i = 0; i < runnables.size; i++) {
            runnables.get(i).run();
          }
          runnables.clear();
          listener.render();
          input.justTouched = false;
        } catch (Throwable t) {
          error("GwtApplication", "exception: " + t.getMessage(), t);
          throw new RuntimeException(t);
        }
      }
    }.scheduleRepeating((int) ((1f / config.fps) * 1000));
  }
示例#2
0
  void setupLoop() {
    // setup modules
    try {
      graphics = new GwtGraphics(root, config);
    } catch (Throwable e) {
      root.clear();
      root.add(getNoWebGLSupportWidget());
      return;
    }
    lastWidth = graphics.getWidth();
    lastHeight = graphics.getHeight();
    Gdx.app = this;
    Gdx.audio = new GwtAudio();
    Gdx.graphics = graphics;
    Gdx.gl20 = graphics.getGL20();
    Gdx.gl = Gdx.gl20;
    Gdx.files = new GwtFiles(preloader);
    this.input = new GwtInput(graphics.canvas);
    Gdx.input = this.input;
    this.net = new GwtNet();
    Gdx.net = this.net;
    this.clipboard = new GwtClipboard();
    updateLogLabelSize();

    // tell listener about app creation
    try {
      listener.create();
      listener.resize(graphics.getWidth(), graphics.getHeight());
    } catch (Throwable t) {
      error("GwtApplication", "exception: " + t.getMessage(), t);
      t.printStackTrace();
      throw new RuntimeException(t);
    }

    AnimationScheduler.get()
        .requestAnimationFrame(
            new AnimationCallback() {
              @Override
              public void execute(double timestamp) {
                try {
                  mainLoop();
                } catch (Throwable t) {
                  error("GwtApplication", "exception: " + t.getMessage(), t);
                  throw new RuntimeException(t);
                }
                AnimationScheduler.get().requestAnimationFrame(this, graphics.canvas);
              }
            },
            graphics.canvas);
  }
示例#3
0
 private void checkLogLabel() {
   if (log == null) {
     log = new TextArea();
     log.setSize(graphics.getWidth() + "px", "200px");
     log.setReadOnly(true);
     root.add(log);
   }
 }
示例#4
0
 private void updateLogLabelSize() {
   if (log != null) {
     if (graphics != null) {
       log.setSize(graphics.getWidth() + "px", "200px");
     } else {
       log.setSize("400px", "200px"); // Should not happen at this point, use dummy value
     }
   }
 }
示例#5
0
 void mainLoop() {
   graphics.update();
   if (Gdx.graphics.getWidth() != lastWidth || Gdx.graphics.getHeight() != lastHeight) {
     GwtApplication.this.listener.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
     lastWidth = graphics.getWidth();
     lastHeight = graphics.getHeight();
     Gdx.gl.glViewport(0, 0, lastWidth, lastHeight);
   }
   runnablesHelper.addAll(runnables);
   runnables.clear();
   for (int i = 0; i < runnablesHelper.size; i++) {
     runnablesHelper.get(i).run();
   }
   runnablesHelper.clear();
   graphics.frameId++;
   listener.render();
   input.reset();
 }