ChunkBatchSizeCalculator .java

net.minecraft.client.multiplayer.ChunkBatchSizeCalculator (class, 34 lines): members: aggregatedNanosPerChunk, getDesiredChunksPerTick, CLAMP_COEFFICIENT.

net.minecraft.client.multiplayerclass34 linesclient1.2 KB

API Surface (3)

void onBatchStart()
void onBatchFinished(final int batchSize)
float getDesiredChunksPerTick()

Fields & Constants (5)

MAX_OLD_SAMPLES_WEIGHT
CLAMP_COEFFICIENT
aggregatedNanosPerChunk
oldSamplesWeight
chunkBatchStartTime

Code Graph: Dependencies (2)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

ChunkBatchSizeCalculator.java34 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.multiplayer;
2
3
import net.fabricmc.api.EnvType;
4
import net.fabricmc.api.Environment;
5
import net.minecraft.util.Mth;
6
import net.minecraft.util.Util;
7
8
@Environment(EnvType.CLIENT)
9
public class ChunkBatchSizeCalculator {
10
	private static final int MAX_OLD_SAMPLES_WEIGHT = 49;
11
	private static final int CLAMP_COEFFICIENT = 3;
12
	private double aggregatedNanosPerChunk = 2000000.0;
13
	private int oldSamplesWeight = 1;
14
	private volatile long chunkBatchStartTime = Util.getNanos();
15
16
	public void onBatchStart() {
17
		this.chunkBatchStartTime = Util.getNanos();
18
	}
19
20
	public void onBatchFinished(final int batchSize) {
21
		if (batchSize > 0) {
22
			double batchDuration = Util.getNanos() - this.chunkBatchStartTime;
23
			double nanosPerChunk = batchDuration / batchSize;
24
			double clampedNanosPerChunk = Mth.clamp(nanosPerChunk, this.aggregatedNanosPerChunk / 3.0, this.aggregatedNanosPerChunk * 3.0);
25
			this.aggregatedNanosPerChunk = (this.aggregatedNanosPerChunk * this.oldSamplesWeight + clampedNanosPerChunk) / (this.oldSamplesWeight + 1);
26
			this.oldSamplesWeight = Math.min(49, this.oldSamplesWeight + 1);
27
		}
28
	}
29
30
	public float getDesiredChunksPerTick() {
31
		return (float)(7000000.0 / this.aggregatedNanosPerChunk);
32
	}
33
}
34

Decompiled Minecraft 26.3 source of ChunkBatchSizeCalculator (net/minecraft/client/multiplayer/ChunkBatchSizeCalculator.java) with Mojang official mappings, stored verbatim on the site.