Exemple #1
0
  void rootdraw(GLState.Applier state, UI ui, BGL gl) {
    GLState.Buffer ibuf = new GLState.Buffer(state.cfg);
    gstate.prep(ibuf);
    ostate.prep(ibuf);
    GOut g = new GOut(gl, state.cgl, state.cfg, state, ibuf, new Coord(w, h));
    state.set(ibuf);

    g.state(ostate);
    g.apply();
    gl.glClearColor(0, 0, 0, 1);
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);
    synchronized (ui) {
      ui.draw(g);
    }

    if (Config.dbtext) {
      int y = h - 150;
      FastText.aprintf(
          g,
          new Coord(10, y -= 15),
          0,
          1,
          "FPS: %d (%d%%, %d%% idle)",
          fps,
          (int) (uidle * 100.0),
          (int) (ridle * 100.0));
      Runtime rt = Runtime.getRuntime();
      long free = rt.freeMemory(), total = rt.totalMemory();
      FastText.aprintf(
          g,
          new Coord(10, y -= 15),
          0,
          1,
          "Mem: %,011d/%,011d/%,011d/%,011d",
          free,
          total - free,
          total,
          rt.maxMemory());
      FastText.aprintf(g, new Coord(10, y -= 15), 0, 1, "Tex-current: %d", TexGL.num());
      FastText.aprintf(g, new Coord(10, y -= 15), 0, 1, "GL progs: %d", g.st.numprogs());
      GameUI gi = ui.root.findchild(GameUI.class);
      if ((gi != null) && (gi.map != null)) {
        try {
          FastText.aprintf(
              g, new Coord(10, y -= 15), 0, 1, "MV pos: %s (%s)", gi.map.getcc(), gi.map.camera);
        } catch (Loading e) {
        }
        if (gi.map.rls != null)
          FastText.aprintf(
              g,
              new Coord(10, y -= 15),
              0,
              1,
              "Rendered: %,d+%,d(%,d)",
              gi.map.rls.drawn,
              gi.map.rls.instanced,
              gi.map.rls.instancified);
      }
      if (Resource.remote().qdepth() > 0)
        FastText.aprintf(
            g,
            new Coord(10, y -= 15),
            0,
            1,
            "RQ depth: %d (%d)",
            Resource.remote().qdepth(),
            Resource.remote().numloaded());
    }
    Object tooltip;
    try {
      synchronized (ui) {
        tooltip = ui.root.tooltip(mousepos, ui.root);
      }
    } catch (Loading e) {
      tooltip = "...";
    }
    Tex tt = null;
    if (tooltip != null) {
      if (tooltip instanceof Text) {
        tt = ((Text) tooltip).tex();
      } else if (tooltip instanceof Tex) {
        tt = (Tex) tooltip;
      } else if (tooltip instanceof Indir<?>) {
        Indir<?> t = (Indir<?>) tooltip;
        Object o = t.get();
        if (o instanceof Tex) tt = (Tex) o;
      } else if (tooltip instanceof String) {
        if (((String) tooltip).length() > 0) tt = (Text.render((String) tooltip)).tex();
      }
    }
    if (tt != null) {
      Coord sz = tt.sz();
      Coord pos = mousepos.add(sz.inv());
      if (pos.x < 0) pos.x = 0;
      if (pos.y < 0) pos.y = 0;
      g.chcolor(244, 247, 21, 192);
      g.rect(pos.add(-3, -3), sz.add(6, 6));
      g.chcolor(35, 35, 35, 192);
      g.frect(pos.add(-2, -2), sz.add(4, 4));
      g.chcolor();
      g.image(tt, pos);
    }
    ui.lasttip = tooltip;
    Resource curs = ui.root.getcurs(mousepos);
    if (curs != null) {
      if (cursmode == "awt") {
        if (curs != lastcursor) {
          try {
            setCursor(makeawtcurs(curs.layer(Resource.imgc).img, curs.layer(Resource.negc).cc));
            lastcursor = curs;
          } catch (Exception e) {
            cursmode = "tex";
          }
        }
      } else if (cursmode == "tex") {
        Coord dc = mousepos.add(curs.layer(Resource.negc).cc.inv());
        g.image(curs.layer(Resource.imgc), dc);
      }
    }
    state.clean();
    GLObject.disposeall(state.cgl, gl);
  }
  void redraw(GL gl) {
    GOut g = new GOut(gl, getContext(), MainFrame.getInnerSize());
    synchronized (ui) {
      ui.update();
    }
    if (Config.render_enable) {
      gl.glMatrixMode(GL.GL_PROJECTION);
      gl.glLoadIdentity();
      gl.glOrtho(0, getWidth(), 0, getHeight(), -1, 1);
      TexRT.renderall(g);
      if (curf != null) curf.tick("texrt");

      gl.glMatrixMode(GL.GL_PROJECTION);
      gl.glLoadIdentity();
      gl.glOrtho(0, getWidth(), getHeight(), 0, -1, 1);
      gl.glClearColor(0, 0, 0, 1);
      gl.glClear(GL.GL_COLOR_BUFFER_BIT);
      if (curf != null) curf.tick("cls");
      synchronized (ui) {
        ui.draw(g);
      }
      if (curf != null) curf.tick("draw");

      if (Config.dbtext) {
        g.atext("FPS: " + fps, new Coord(10, 545), 0, 1);
        g.atext("Texhit: " + dth, new Coord(10, 530), 0, 1);
        g.atext("Texmiss: " + dtm, new Coord(10, 515), 0, 1);
        Runtime rt = Runtime.getRuntime();
        long free = rt.freeMemory(), total = rt.totalMemory();
        g.atext(
            String.format(
                "Mem: %,011d/%,011d/%,011d/%,011d", free, total - free, total, rt.maxMemory()),
            new Coord(10, 500),
            0,
            1);
        g.atext(
            String.format("LCache: %d/%d", Layered.cache.size(), Layered.cache.cached()),
            new Coord(10, 485),
            0,
            1);
        g.atext(
            String.format("RT-current: %d", TexRT.current.get(gl).size()),
            new Coord(10, 470),
            0,
            1);
        if (Resource.qdepth() > 0)
          g.atext(
              String.format("RQ depth: %d (%d)", Resource.qdepth(), Resource.numloaded()),
              new Coord(10, 455),
              0,
              1);
      }
      Object tooltip = ui.root.tooltip(mousepos, true);
      Tex tt = null;
      if (tooltip != null) {
        if (tooltip instanceof Text) {
          tt = ((Text) tooltip).tex();
        } else if (tooltip instanceof Tex) {
          tt = (Tex) tooltip;
        } else if (tooltip instanceof String) {
          if (((String) tooltip).length() > 0) tt = (Text.render((String) tooltip)).tex();
        }
      }
      if (tt != null) {
        Coord sz = tt.sz();
        Coord pos = mousepos.add(sz.inv());
        if (pos.x < 0) pos.x = 0;
        if (pos.y < 0) pos.y = 0;
        g.chcolor(244, 247, 21, 192);
        g.rect(pos.add(-3, -3), sz.add(6, 6));
        g.chcolor(35, 35, 35, 192);
        g.frect(pos.add(-2, -2), sz.add(4, 4));
        g.chcolor();
        g.image(tt, pos);
      }
    }
    Resource curs = ui.root.getcurs(mousepos);
    if (!curs.loading) {
      if (cursmode == "awt") {
        if (curs != lastcursor) {
          try {
            setCursor(makeawtcurs(curs.layer(Resource.imgc).img, curs.layer(Resource.negc).cc));
            ark.bot.cursor_name = curs.name;
            ark.bot.cursor_name = ark.bot.cursor_name.replace("gfx/hud/curs/", "");
            lastcursor = curs;
          } catch (Exception e) {
            cursmode = "tex";
          }
        }
      } else if (cursmode == "tex") {
        Coord dc = mousepos.add(curs.layer(Resource.negc).cc.inv());
        g.image(curs.layer(Resource.imgc), dc);
      }
    }
  }