diff --git a/src/main/java/me/cortex/voxy/client/VoxyClientInstance.java b/src/main/java/me/cortex/voxy/client/VoxyClientInstance.java index 48168fba..8fdb668f 100644 --- a/src/main/java/me/cortex/voxy/client/VoxyClientInstance.java +++ b/src/main/java/me/cortex/voxy/client/VoxyClientInstance.java @@ -157,96 +157,4 @@ public class VoxyClientInstance extends VoxyInstance { } return basePath.toAbsolutePath(); } - - /* - private static void testDbPerformance(WorldEngine engine) { - Random r = new Random(123456); - r.nextLong(); - long start = System.currentTimeMillis(); - int c = 0; - long tA = 0; - long tR = 0; - for (int i = 0; i < 1_000_000; i++) { - if (i == 20_000) { - c = 0; - start = System.currentTimeMillis(); - } - c++; - int x = (r.nextInt(256*2+2)-256);//-32 - int z = (r.nextInt(256*2+2)-256);//-32 - int y = r.nextInt(2)-1; - int lvl = 0;//r.nextInt(5); - long t = System.nanoTime(); - var sec = engine.acquire(WorldEngine.getWorldSectionId(lvl, x>>lvl, y>>lvl, z>>lvl)); - tA += System.nanoTime()-t; - t = System.nanoTime(); - sec.release(); - tR += System.nanoTime()-t; - } - long delta = System.currentTimeMillis() - start; - System.out.println("Total "+delta+"ms " + ((double)delta/c) + "ms average tA: " + tA + " tR: " + tR); - } - private static void testDbPerformance2(WorldEngine engine) { - Random r = new Random(123456); - r.nextLong(); - ConcurrentLinkedDeque queue = new ConcurrentLinkedDeque<>(); - var ser = engine.instanceIn.getThreadPool().createServiceNoCleanup("aa", 1, ()-> () ->{ - var sec = engine.acquire(queue.poll()); - sec.release(); - }); - int priming = 1_000_000; - for (int i = 0; i < 2_000_000+priming; i++) { - int x = (r.nextInt(256*2+2)-256)>>2;//-32 - int z = (r.nextInt(256*2+2)-256)>>2;//-32 - int y = r.nextInt(2)-1; - int lvl = 0;//r.nextInt(5); - queue.add(WorldEngine.getWorldSectionId(lvl, x>>lvl, y>>lvl, z>>lvl)); - } - for (int i = 0; i < priming; i++) { - ser.execute(); - } - ser.blockTillEmpty(); - int c = queue.size(); - long start = System.currentTimeMillis(); - for (int i = 0; i < c; i++) { - ser.execute(); - } - ser.blockTillEmpty(); - long delta = System.currentTimeMillis() - start; - ser.shutdown(); - System.out.println("Total "+delta+"ms " + ((double)delta/c) + "ms average total, avg wrt threads: " + (((double)delta/c)*engine.instanceIn.getThreadPool().getThreadCount()) + "ms"); - } - - - private void verifyTopNodeChildren(int X, int Y, int Z) { - var world = this.getOrMakeRenderWorld(MinecraftClient.getInstance().world); - for (int lvl = 0; lvl < 5; lvl++) { - for (int y = (Y<<5)>>lvl; y < ((Y+1)<<5)>>lvl; y++) { - for (int x = (X<<5)>>lvl; x < ((X+1)<<5)>>lvl; x++) { - for (int z = (Z<<5)>>lvl; z < ((Z+1)<<5)>>lvl; z++) { - if (lvl == 0) { - var own = world.acquire(lvl, x, y, z); - if ((own.getNonEmptyChildren() != 0) ^ (own.getNonEmptyBlockCount() != 0)) { - Logger.error("Lvl 0 node not marked correctly " + WorldEngine.pprintPos(own.key)); - } - own.release(); - } else { - byte msk = 0; - for (int child = 0; child < 8; child++) { - var section = world.acquire(lvl-1, (child&1)+(x<<1), ((child>>2)&1)+(y<<1), ((child>>1)&1)+(z<<1)); - msk |= (byte) (section.getNonEmptyBlockCount()!=0?(1< sections = new ArrayList<>(); - - System.out.println("Loading sections"); - for (int x = -17; x <= 17; x++) { - for (int z = -17; z <= 17; z++) { - for (int y = -1; y <= 4; y++) { - var section = this.worldIn.acquire(0, x, y, z); - - int nonAir = 0; - for (long state : section.copyData()) { - nonAir += Mapper.isAir(state)?0:1; - modelService.requestBlockBake(Mapper.getBlockId(state)); - } - - if (nonAir > 500 && Math.abs(x) <= 16 && Math.abs(z) <= 16) { - sections.add(section); - } else { - section.release(); - } - } - } - } - - System.out.println("Baking models"); - { - //Bake everything - while (!modelService.areQueuesEmpty()) { - modelService.tick(5_000_000); - glFinish(); - } - } - - System.out.println("Ready!"); - - { - int iteration = 0; - while (true) { - long start = System.currentTimeMillis(); - for (var section : sections) { - var mesh = factory.generateMesh(section); - - mesh.free(); - } - long delta = System.currentTimeMillis() - start; - System.out.println("Iteration: " + (iteration++) + " took " + delta + "ms, for an average of " + ((float)delta/sections.size()) + "ms per section"); - //System.out.println("Quad count: " + factory.quadCount); - } - } - } - - private void testFullMesh() { - var modelService = new ModelBakerySubsystem(this.worldIn.getMapper()); - var completedCounter = new AtomicInteger(); - var generationService = new RenderGenerationService(this.worldIn, modelService, VoxyCommon.getInstance().getThreadPool(), false); - generationService.setResultConsumer(a-> {completedCounter.incrementAndGet(); a.free();}); - - var r = new Random(12345); - { - for (int i = 0; i < 10_000; i++) { - int x = (r.nextInt(256*2+2)-256)>>1;//-32 - int z = (r.nextInt(256*2+2)-256)>>1;//-32 - int y = r.nextInt(10)-2; - int lvl = 0;//r.nextInt(5); - long key = WorldEngine.getWorldSectionId(lvl, x>>lvl, y>>lvl, z>>lvl); - generationService.enqueueTask(key); - } - int i = 0; - while (true) { - modelService.tick(5_000_000); - if (i++%5000==0) - System.out.println(completedCounter.get()); - glFinish(); - List a = new ArrayList<>(); - generationService.addDebugData(a); - if (a.getFirst().endsWith(" 0")) { - break; - } - } - } - - System.out.println("Running benchmark"); - while (true) - { - completedCounter.set(0); - long start = System.currentTimeMillis(); - int C = 200_000; - for (int i = 0; i < C; i++) { - int x = (r.nextInt(256 * 2 + 2) - 256) >> 1;//-32 - int z = (r.nextInt(256 * 2 + 2) - 256) >> 1;//-32 - int y = r.nextInt(10) - 2; - int lvl = 0;//r.nextInt(5); - long key = WorldEngine.getWorldSectionId(lvl, x >> lvl, y >> lvl, z >> lvl); - generationService.enqueueTask(key); - } - //int i = 0; - while (true) { - //if (i++%5000==0) - // System.out.println(completedCounter.get()); - modelService.tick(5_000_000); - glFinish(); - List a = new ArrayList<>(); - generationService.addDebugData(a); - if (a.getFirst().endsWith(" 0")) { - break; - } - } - long delta = (System.currentTimeMillis()-start); - System.out.println("Time "+delta+"ms count: " + completedCounter.get() + " avg per mesh: " + ((double)delta/completedCounter.get()) + "ms"); - if (false) - break; - } - generationService.shutdown(); - modelService.shutdown(); - } }