/** * Render overlay icons * * @param world * @param chunky * @param g * @param renderBuffer */ public void renderHUD(World world, Chunky chunky, Graphics g, RenderBuffer renderBuffer) { boolean loadIndicator = chunky.isLoading(); Chunk.Renderer renderer = chunky.getChunkRenderer(); ChunkView view = renderBuffer.getView(); if (loadIndicator) { g.drawImage(MiscImages.clock, view.width - 32, 0, 32, 32, null); } if (world.havePlayerPos()) { renderPlayer( world, g, view, renderer == Chunk.surfaceRenderer || world.playerLocY() == world.currentLayer()); } if (world.haveSpawnPos()) { renderSpawn( world, g, view, renderer == Chunk.surfaceRenderer || world.spawnPosY() == world.currentLayer()); } Chunk hoveredChunk = chunky.getHoveredChunk(); if (!hoveredChunk.isEmpty()) { g.setFont(font); g.setColor(Color.white); g.drawString("Chunk: " + hoveredChunk.getPosition(), 5, view.height - 5); } }
public void save(Chunk chunk) { ChunkPosition pos = chunk.getPosition(); CompressedChunk c = chunks.get(pos); if (c == null) { c = new CompressedChunk(pos); chunks.put(pos, c); c.setVersion(~chunk.getVersion()); } if (c.getVersion() != chunk.getVersion()) { if (c.getData() != null) { approxSize.addAndGet(-c.getData().length); } long start = TimeStatistics.TIME_STATISTICS.start(); // ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); // DataOutputStream dataOut = new DataOutputStream(byteOut); // compressor.compress(dataOut, chunk.getDataXZY()); try { c.setData(DeflaterWrapper.compress(chunk.getDataXZY())); // c.setData(DeflaterWrapper.compress(byteOut.toByteArray())); } catch (IOException ex) { throw new RuntimeException(ex); } c.setVersion(chunk.getVersion()); TimeStatistics.TIME_STATISTICS.end(start, "save"); approxSize.addAndGet(-c.getData().length); if (chunks.size() % 1000 == 0) { System.out.println( Util.humanReadableByteCount(approxSize.get()) + ", " + Util.humanReadableByteCount(approxSize.get() / chunks.size()) + "/chunk"); } } }
public boolean tryLoad(Chunk chunk) { CompressedChunk c = chunks.get(chunk.getPosition()); if (c != null) { long start = TimeStatistics.TIME_STATISTICS.start(); try { // byteIn = new // ByteArrayInputStream(DeflaterWrapper.decompress(c.getData())); DeflaterWrapper.decompress(c.getData(), chunk.getDataXZY()); } catch (IOException | DataFormatException ex) { throw new RuntimeException(ex); } // DataInputStream dataIn = new DataInputStream(byteIn); // compressor.decompress(dataIn, chunk.getDataXZY()); chunk.setVersion(c.getVersion()); TimeStatistics.TIME_STATISTICS.end(start, "load"); return true; } return false; }