Beispiel #1
0
 static byte[] encode(char[] cc, Charset cs, boolean testDirect, Time t) throws Exception {
   ByteBuffer bbf;
   CharBuffer cbf;
   CharsetEncoder enc = cs.newEncoder();
   String csn = cs.name();
   if (testDirect) {
     bbf = ByteBuffer.allocateDirect(cc.length * 4);
     cbf = ByteBuffer.allocateDirect(cc.length * 2).asCharBuffer();
     cbf.put(cc).flip();
   } else {
     bbf = ByteBuffer.allocate(cc.length * 4);
     cbf = CharBuffer.wrap(cc);
   }
   CoderResult cr = null;
   long t1 = System.nanoTime() / 1000;
   for (int i = 0; i < iteration; i++) {
     cbf.rewind();
     bbf.clear();
     enc.reset();
     cr = enc.encode(cbf, bbf, true);
   }
   long t2 = System.nanoTime() / 1000;
   t.t = (t2 - t1) / iteration;
   if (cr != CoderResult.UNDERFLOW) {
     System.out.println("ENC-----------------");
     int pos = cbf.position();
     System.out.printf("  cr=%s, cbf.pos=%d, cc[pos]=%x%n", cr.toString(), pos, cc[pos] & 0xffff);
     throw new RuntimeException("Encoding err: " + csn);
   }
   byte[] bb = new byte[bbf.position()];
   bbf.flip();
   bbf.get(bb);
   return bb;
 }
Beispiel #2
0
  /**
   * Sets one or more icons for the Display.
   *
   * <ul>
   *   <li>On Windows you should supply at least one 16x16 icon and one 32x32.
   *   <li>Linux (and similar platforms) expect one 32x32 icon.
   *   <li>Mac OS X should be supplied one 128x128 icon
   * </ul>
   *
   * The implementation will use the supplied ByteBuffers with image data in RGBA and perform any
   * conversions nescesarry for the specific platform.
   *
   * @param icons Array of icons in RGBA mode
   * @return number of icons used.
   */
  public int setIcon(ByteBuffer[] icons) {
    boolean done_small = false;
    boolean done_large = false;
    int used = 0;

    int small_icon_size = 16;
    int large_icon_size = 32;
    for (ByteBuffer icon : icons) {
      int size = icon.limit() / 4;

      if ((((int) Math.sqrt(size)) == small_icon_size) && (!done_small)) {
        long small_new_icon = createIcon(small_icon_size, small_icon_size, icon.asIntBuffer());
        sendMessage(hwnd, WM_SETICON, ICON_SMALL, small_new_icon);
        freeSmallIcon();
        small_icon = small_new_icon;
        used++;
        done_small = true;
      }
      if ((((int) Math.sqrt(size)) == large_icon_size) && (!done_large)) {
        long large_new_icon = createIcon(large_icon_size, large_icon_size, icon.asIntBuffer());
        sendMessage(hwnd, WM_SETICON, ICON_BIG, large_new_icon);
        freeLargeIcon();
        large_icon = large_new_icon;
        used++;
        done_large = true;

        // Problem: The taskbar icon won't update until Windows sends a WM_GETICON to our window
        // proc and we reply. But this method is usually called
        // on init and it might take a while before the next call to nUpdate (because of resources
        // being loaded, etc). So we wait for the next
        // WM_GETICON message (usually received about 100ms after WM_SETICON) to make sure the
        // taskbar icon has updated before we return to the user.
        // (We wouldn't need to do this if the event loop was running continuously on its own
        // thread.)
        iconsLoaded = false;

        // Track how long the wait takes and give up at 500ms, just in case.
        long time = System.nanoTime();
        long MAX_WAIT = 500L * 1000L * 1000L;
        while (true) {
          nUpdate();
          if (iconsLoaded || MAX_WAIT < System.nanoTime() - time) break;

          Thread.yield();
        }
      }
    }

    return used;
  }
Beispiel #3
0
 static char[] decode(byte[] bb, Charset cs, boolean testDirect, Time t) throws Exception {
   String csn = cs.name();
   CharsetDecoder dec = cs.newDecoder();
   ByteBuffer bbf;
   CharBuffer cbf;
   if (testDirect) {
     bbf = ByteBuffer.allocateDirect(bb.length);
     cbf = ByteBuffer.allocateDirect(bb.length * 2).asCharBuffer();
     bbf.put(bb);
   } else {
     bbf = ByteBuffer.wrap(bb);
     cbf = CharBuffer.allocate(bb.length);
   }
   CoderResult cr = null;
   long t1 = System.nanoTime() / 1000;
   for (int i = 0; i < iteration; i++) {
     bbf.rewind();
     cbf.clear();
     dec.reset();
     cr = dec.decode(bbf, cbf, true);
   }
   long t2 = System.nanoTime() / 1000;
   t.t = (t2 - t1) / iteration;
   if (cr != CoderResult.UNDERFLOW) {
     System.out.println("DEC-----------------");
     int pos = bbf.position();
     System.out.printf(
         "  cr=%s, bbf.pos=%d, bb[pos]=%x,%x,%x,%x%n",
         cr.toString(),
         pos,
         bb[pos++] & 0xff,
         bb[pos++] & 0xff,
         bb[pos++] & 0xff,
         bb[pos++] & 0xff);
     throw new RuntimeException("Decoding err: " + csn);
   }
   char[] cc = new char[cbf.position()];
   cbf.flip();
   cbf.get(cc);
   return cc;
 }
Beispiel #4
0
  public void run() {
    init();
    engine = new Engine();

    long lastTime = System.nanoTime();
    double delta = 0.0;
    // Amout of nanoseconds in 1/60th of a second
    double ns = 1000000000.0 / 60.0;
    long timer = System.currentTimeMillis();
    int updates = 0;
    int frames = 0;
    while (running) {
      long now = System.nanoTime();
      delta += (now - lastTime) / ns;
      lastTime = now;
      // if delta >= than one then the amount of time >= 1/60th of a second
      if (delta >= 1.0) {
        update();
        updates++;
        delta--;
      }
      render();
      frames++;
      // If a second has passed, we print the stats
      if (System.currentTimeMillis() - timer > 1000) {
        timer += 1000;
        System.out.println(updates + " ups, " + frames + " fps");
        updates = 0;
        frames = 0;
      }
      if (glfwWindowShouldClose(window) == GL_TRUE) running = false;
    }
    engine.CleanUp();
    keyCallback.release();
    sizeCallback.release();
    mouseCallback.release();
    focusCallback.release();
    glfwDestroyWindow(window);
    glfwTerminate();
  }
Beispiel #5
0
  static void checkInit(String csn) throws Exception {
    System.out.printf("Check init <%s>...%n", csn);
    Charset.forName("Big5"); // load in the ExtendedCharsets
    long t1 = System.nanoTime() / 1000;
    Charset cs = Charset.forName(csn);
    long t2 = System.nanoTime() / 1000;
    System.out.printf("    charset     :%d%n", t2 - t1);
    t1 = System.nanoTime() / 1000;
    cs.newDecoder();
    t2 = System.nanoTime() / 1000;
    System.out.printf("    new Decoder :%d%n", t2 - t1);

    t1 = System.nanoTime() / 1000;
    cs.newEncoder();
    t2 = System.nanoTime() / 1000;
    System.out.printf("    new Encoder :%d%n", t2 - t1);
  }
Beispiel #6
0
 private static double getTime() {
   return (double) System.nanoTime() / 1.0e9;
 }