Пример #1
0
 private Layer redraw(final int z) {
   final ArrayList<Sprite.Part> parts = new ArrayList<Sprite.Part>();
   Sprite.Drawer drw =
       new Sprite.Drawer() {
         public void addpart(Sprite.Part p) {
           if (p.z == z) parts.add(p);
         }
       };
   for (Sprite spr : sprites.values()) {
     if (spr != null) spr.setup(drw, Coord.z, Coord.z);
   }
   Collections.sort(parts, Sprite.partcmp);
   Coord ul = new Coord(0, 0);
   Coord lr = new Coord(0, 0);
   for (Sprite.Part part : parts) {
     if (part.ul.x < ul.x) ul.x = part.ul.x;
     if (part.ul.y < ul.y) ul.y = part.ul.y;
     if (part.lr.x > lr.x) lr.x = part.lr.x;
     if (part.lr.y > lr.y) lr.y = part.lr.y;
   }
   BufferedImage buf = TexI.mkbuf(lr.add(ul.inv()).add(1, 1));
   Graphics g = buf.getGraphics();
   /*
   g.setColor(java.awt.Color.RED);
   g.fillRect(0, 0, buf.getWidth(), buf.getHeight());
   */
   for (Sprite.Part part : parts) {
     part.cc = part.cc.add(ul.inv());
     part.draw(buf, g);
   }
   g.dispose();
   return (new Layer(buf, ul.inv()));
 }
Пример #2
0
    public BufferedImage getGridImage() {
      if (rendered) return gridImage;

      if (!loaded) throw new Loading();

      gridImage = TexI.mkbuf(cmaps);

      BufferedImage[] texes = new BufferedImage[256];

      Coord c = new Coord();
      for (c.y = 0; c.y < cmaps.y; c.y++) {
        for (c.x = 0; c.x < cmaps.x; c.x++) {
          int t = gettile(c);
          BufferedImage tex = tileimg(t, texes);
          if (tex != null)
            gridImage.setRGB(
                c.x,
                c.y,
                tex.getRGB(
                    Utils.floormod(c.x, tex.getWidth()), Utils.floormod(c.y, tex.getHeight())));
        }
      }
      for (c.y = 1; c.y < cmaps.y - 1; c.y++) {
        for (c.x = 1; c.x < cmaps.x - 1; c.x++) {
          int t = gettile(c);
          if ((gettile(c.add(-1, 0)) > t)
              || (gettile(c.add(1, 0)) > t)
              || (gettile(c.add(0, -1)) > t)
              || (gettile(c.add(0, 1)) > t)) gridImage.setRGB(c.x, c.y, Color.BLACK.getRGB());
        }
      }
      rendered = true;
      return gridImage;
    }
Пример #3
0
 public BufferedImage drawmap(Coord ul, Coord sz) {
   BufferedImage[] texes = new BufferedImage[256];
   MCache m = ui.sess.glob.map;
   BufferedImage buf = TexI.mkbuf(sz);
   Coord c = new Coord();
   for (c.y = 0; c.y < sz.y; c.y++) {
     for (c.x = 0; c.x < sz.x; c.x++) {
       int t = m.gettile(ul.add(c));
       BufferedImage tex = tileimg(t, texes);
       int rgb = 0;
       if (tex != null)
         rgb =
             tex.getRGB(
                 Utils.floormod(c.x + ul.x, tex.getWidth()),
                 Utils.floormod(c.y + ul.y, tex.getHeight()));
       buf.setRGB(c.x, c.y, rgb);
     }
   }
   for (c.y = 1; c.y < sz.y - 1; c.y++) {
     for (c.x = 1; c.x < sz.x - 1; c.x++) {
       int t = m.gettile(ul.add(c));
       Tiler tl = m.tiler(t);
       if (tl instanceof Ridges.RidgeTile) {
         if (Ridges.brokenp(m, ul.add(c))) {
           for (int y = c.y - 1; y <= c.y + 1; y++) {
             for (int x = c.x - 1; x <= c.x + 1; x++) {
               Color cc = new Color(buf.getRGB(x, y));
               buf.setRGB(
                   x,
                   y,
                   Utils.blendcol(cc, Color.BLACK, ((x == c.x) && (y == c.y)) ? 1 : 0.1).getRGB());
             }
           }
         }
       }
     }
   }
   for (c.y = 0; c.y < sz.y; c.y++) {
     for (c.x = 0; c.x < sz.x; c.x++) {
       int t = m.gettile(ul.add(c));
       if ((m.gettile(ul.add(c).add(-1, 0)) > t)
           || (m.gettile(ul.add(c).add(1, 0)) > t)
           || (m.gettile(ul.add(c).add(0, -1)) > t)
           || (m.gettile(ul.add(c).add(0, 1)) > t)) buf.setRGB(c.x, c.y, Color.BLACK.getRGB());
     }
   }
   return (buf);
 }
Пример #4
0
 private void makeflavor() {
   @SuppressWarnings("unchecked")
   Collection<Gob>[] fo = (Collection<Gob>[]) new Collection[cutn.x * cutn.y];
   for (int i = 0; i < fo.length; i++) fo[i] = new LinkedList<Gob>();
   Coord c = new Coord(0, 0);
   Coord tc = gc.mul(cmaps);
   int i = 0;
   Random rnd = new Random(id);
   for (c.y = 0; c.y < cmaps.x; c.y++) {
     for (c.x = 0; c.x < cmaps.y; c.x++, i++) {
       Tileset set = tileset(tiles[i]);
       if (set.flavobjs.size() > 0) {
         if (rnd.nextInt(set.flavprob) == 0) {
           Resource r = set.flavobjs.pick(rnd);
           double a = rnd.nextDouble() * 2 * Math.PI;
           Gob g = new Flavobj(c.add(tc).mul(tilesz).add(tilesz.div(2)), a);
           g.setattr(new ResDrawable(g, r));
           Coord cc = c.div(cutsz);
           fo[cc.x + (cc.y * cutn.x)].add(g);
         }
       }
     }
   }
   this.fo = fo;
 }
Пример #5
0
 public Coord contentsz() {
   Coord max = new Coord(0, 0);
   for (Widget wdg = child; wdg != null; wdg = wdg.next) {
     if (!wdg.visible) continue;
     Coord br = wdg.c.add(wdg.sz);
     if (br.x > max.x) max.x = br.x;
     if (br.y > max.y) max.y = br.y;
   }
   return (max);
 }
Пример #6
0
 public void reqarea(Coord ul, Coord br) {
   ul = ul.div(cutsz);
   br = br.div(cutsz);
   Coord rc = new Coord();
   for (rc.y = ul.y; rc.y <= br.y; rc.y++) {
     for (rc.x = ul.x; rc.x <= br.x; rc.x++) {
       try {
         getcut(new Coord(rc));
       } catch (Loading e) {
       }
     }
   }
 }
Пример #7
0
 public void ivneigh(Coord nc) {
   Coord cc = new Coord();
   for (cc.y = 0; cc.y < cutn.y; cc.y++) {
     for (cc.x = 0; cc.x < cutn.x; cc.x++) {
       if ((((nc.x < 0) && (cc.x == 0)) || ((nc.x > 0) && (cc.x == cutn.x - 1)) || (nc.x == 0))
           && (((nc.y < 0) && (cc.y == 0))
               || ((nc.y > 0) && (cc.y == cutn.y - 1))
               || (nc.y == 0))) {
         buildcut(new Coord(cc));
       }
     }
   }
 }
Пример #8
0
  public MainFrame(Coord isz) {
    super("Haven and Hearth");
    version = "1.6 (12.22.2015)";
    Coord sz;
    if (isz == null) {
      sz = Utils.getprefc("wndsz", new Coord(800, 600));
      if (sz.x < 640) sz.x = 640;
      if (sz.y < 480) sz.y = 480;
    } else {
      sz = isz;
    }
    this.g = new ThreadGroup(HackThread.tg(), "Haven client");
    this.mt = new HackThread(this.g, this, "Haven main thread");
    p = new HavenPanel(sz.x, sz.y);
    if (fsmode == null) {
      Coord pfm = Utils.getprefc("fsmode", null);
      if (pfm != null) fsmode = findmode(pfm.x, pfm.y);
    }
    if (fsmode == null) {
      DisplayMode cm = getGraphicsConfiguration().getDevice().getDisplayMode();
      fsmode = findmode(cm.getWidth(), cm.getHeight());
    }
    if (fsmode == null) fsmode = findmode(800, 600);
    add(p);
    pack();
    setResizable(!Utils.getprefb("wndlock", false));
    p.requestFocusInWindow();
    seticon();
    setVisible(true);
    p.init();
    addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            g.interrupt();
          }

          public void windowActivated(WindowEvent e) {
            p.bgmode = false;
          }

          public void windowDeactivated(WindowEvent e) {
            p.bgmode = true;
          }
        });
    if ((isz == null) && Utils.getprefb("wndmax", false))
      setExtendedState(getExtendedState() | MAXIMIZED_BOTH);
  }
Пример #9
0
 public Message messageat(Coord c, Coord hc) {
   int y = -sb.val;
   synchronized (msgs) {
     for (Message msg : msgs) {
       Coord sz = msg.sz();
       if ((c.y >= y) && (c.y < y + sz.y)) {
         if (hc != null) {
           hc.x = c.x;
           hc.y = c.y - y;
         }
         return (msg);
       }
       y += sz.y;
     }
   }
   return (null);
 }
Пример #10
0
  public void drawsmall(GOut g, Coord br, int h) {
    Coord c;
    if (qline != null) {
      if ((rqline == null) || !rqline.text.equals(qline.line)) {
        String pre = String.format("%s> ", qline.chan.name());
        rqline = qfnd.render(pre + qline.line);
        rqpre = pre.length();
      }
      c = br.sub(0, 20);
      g.chcolor(24, 24, 16, 200);
      g.frect(c, rqline.tex().sz());
      g.chcolor();
      g.image(rqline.tex(), c);
      int lx = rqline.advance(qline.point + rqpre);
      g.line(new Coord(br.x + lx + 1, br.y - 18), new Coord(br.x + lx + 1, br.y - 6), 1);
    } else {
      c = br.sub(0, 5);
    }
    long now = System.currentTimeMillis();
    synchronized (notifs) {
      for (Iterator<Notification> i = notifs.iterator(); i.hasNext(); ) {
        Notification n = i.next();
        if (now - n.time > 5000) {
          i.remove();
          continue;
        }
        if ((c.y -= n.msg.sz().y) < br.y - h) break;

        g.chcolor(24, 24, 16, 200);
        g.frect(c, n.chnm.tex().sz().add(n.msg.tex().sz().x + selw, 0));
        g.chcolor();
        g.image(n.chnm.tex(), c, br.sub(0, h), br.add(selw - 10, 0));
        g.image(n.msg.tex(), c.add(selw, 0));
      }
    }
  }
Пример #11
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);
  }