示例#1
0
  public synchronized void setRenderOptions() {
    if (canvas != null) {
      this.remove(canvas);
    }
    screenScaleFactor = PrefsSingleton.get().getInt("screenScaling", 2);
    smoothScale = PrefsSingleton.get().getBoolean("smoothScaling", false);
    if (PrefsSingleton.get().getBoolean("TVEmulation", false)) {
      renderer = new NTSCRenderer();
      NES_WIDTH = 302;
    } else {
      renderer = new RGBRenderer();
      NES_WIDTH = 256;
    }
    if (PrefsSingleton.get().getInt("region", 0) > 1) {
      NES_HEIGHT = 240;
      renderer.setClip(0);
    } else {
      NES_HEIGHT = 224;
      renderer.setClip(8);
    }

    // Create canvas for painting
    canvas = new Canvas();
    canvas.setSize(NES_WIDTH * screenScaleFactor, NES_HEIGHT * screenScaleFactor);
    canvas.setEnabled(false); // otherwise it steals input events.
    // Add canvas to game window
    this.add(canvas);
    this.pack();
    canvas.createBufferStrategy(2);
    buffer = canvas.getBufferStrategy();
  }
示例#2
0
  @Override
  public final synchronized void setFrame(
      final int[] nextframe, final int[] bgcolors, boolean dotcrawl) {
    // todo: stop running video filters while paused!
    // also move video filters into a worker thread because they
    // don't really depend on emulation state at all. Yes this is going to
    // cause more lag but it will hopefully get back up to playable speed with NTSC filter

    frametimes[frametimeptr] = nes.getFrameTime();
    ++frametimeptr;
    frametimeptr %= frametimes.length;

    if (frametimeptr == 0) {
      long averageframes = 0;
      for (long l : frametimes) {
        averageframes += l;
      }
      averageframes /= frametimes.length;
      fps = 1E9 / averageframes;
      this.setTitle(
          String.format(
              "HalfNES %s - %s, %2.2f fps" + ((frameskip > 0) ? " frameskip " + frameskip : ""),
              NES.VERSION,
              nes.getCurrentRomName(),
              fps));
    }
    if (nes.framecount % (frameskip + 1) == 0) {
      frame = renderer.render(nextframe, bgcolors, dotcrawl);
      render();
    }
  }