Data class
Пакет: com.hypixel.hytale.server.core.universe.world.storage.component
Файл: com/hypixel/hytale/server/core/universe/world/storage/component/ChunkUnloadingSystem.java
extends: UnloadingSystemData
Методы (2)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
|
public Resource<ChunkStore> |
clonepublic Resource<ChunkStore> clone() |
abstract |
|
super super(var1) |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.universe.world.storage.component;
class="kw">import com.hypixel.hytale.component.ArchetypeChunk;
class="kw">import com.hypixel.hytale.component.CommandBuffer;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.component.RemoveReason;
class="kw">import com.hypixel.hytale.component.Resource;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.component.system.tick.RunWhenPausedSystem;
class="kw">import com.hypixel.hytale.component.system.tick.TickingSystem;
class="kw">import com.hypixel.hytale.math.shape.Box2D;
class="kw">import com.hypixel.hytale.math.util.ChunkUtil;
class="kw">import com.hypixel.hytale.math.util.MathUtil;
class="kw">import com.hypixel.hytale.server.core.modules.entity.player.ChunkTracker;
class="kw">import com.hypixel.hytale.server.core.universe.world.World;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.ChunkColumn;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.ChunkFlag;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.WorldChunk;
class="kw">import com.hypixel.hytale.server.core.universe.world.events.ecs.ChunkUnloadEvent;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import java.util.List;
class="kw">import java.util.logging.Level;
class="kw">import javax.annotation.Nonnull;
class="kw">public class ChunkUnloadingSystem class="kw">extends TickingSystem<ChunkStore> class="kw">implements RunWhenPausedSystem<ChunkStore> {
class="kw">public class="kw">static class="kw">final double DESPERATE_UNLOAD_RAM_USAGE_THRESHOLD = 0.85;
class="kw">public class="kw">static class="kw">final int DESPERATE_UNLOAD_MAX_POLL_COUNT = 3;
class="kw">public class="kw">static class="kw">final int TICKS_BEFORE_CHUNK_UNLOADING_REMINDER = 5000;
class="kw">public int ticksUntilUnloadingReminder = 5000;
class="kw">public ChunkUnloadingSystem() {
}
@Override
class="kw">public void tick(float var1, int var2, @Nonnull Store<ChunkStore> var3) {
ChunkUnloadingSystem.Data var4 = var3.getResource(ChunkStore.UNLOAD_RESOURCE);
World var5 = var3.getExternalData().getWorld();
if (!var5.getWorldConfig().canUnloadChunks()) {
this.ticksUntilUnloadingReminder--;
if (this.ticksUntilUnloadingReminder <= 0) {
var5.getLogger().at(Level.INFO).log("This world has disabled chunk unloading");
this.ticksUntilUnloadingReminder = 5000;
}
} else {
int var6 = 1;
Runtime var7 = Runtime.getRuntime();
double var8 = (double)(var7.totalMemory() - var7.freeMemory()) / var7.maxMemory();
if (var8 > 0.85) {
double var10 = (var8 - 0.85) / 0.15000000000000002;
var6 = Math.max(MathUtil.ceil(var10 * 3.0), 1);
}
var4.pollCount = var6;
if (var4.tick(var1)) {
var4.chunkTrackers.clear();
var5.getEntityStore().getStore().forEachChunk(ChunkTracker.getComponentType(), ChunkUnloadingSystem::collectTrackers);
var3.forEachEntityParallel(WorldChunk.getComponentType(), ChunkUnloadingSystem::tryUnload);
}
}
}
class="kw">public class="kw">static void tryUnload(int var0, @Nonnull ArchetypeChunk<ChunkStore> var1, @Nonnull CommandBuffer<ChunkStore> var2) {
Store var3 = var2.getStore();
World var4 = var3.getExternalData().getWorld();
WorldChunk var5 = var1.getComponent(var0, WorldChunk.getComponentType());
assert var5 != null;
ChunkUnloadingSystem.Data var6 = var2.getResource(ChunkStore.UNLOAD_RESOURCE);
ChunkTracker.ChunkVisibility var7 = getChunkVisibility(var3.getExternalData(), var6.chunkTrackers, var5.getIndex());
if (var7 == ChunkTracker.ChunkVisibility.HOT) {
var5.resetKeepAlive();
var5.resetActiveTimer();
} else {
Box2D var8 = var4.getWorldConfig().getChunkConfig().getKeepLoadedRegion();
boolean var9 = var5.shouldKeepLoaded() || var8 != null && isChunkInBox(var8, var5.getX(), var5.getZ());
boolean var10 = var5.getNeedsSaving();
if (!var10) {
var10 = ChunkSavingSystems.collectSectionDirtiness(var1.getComponent(var0, ChunkColumn.getComponentType()), var2, true);
}
int var11 = var6.pollCount;
if (var7 == ChunkTracker.ChunkVisibility.COLD || var10 || var9) {
var5.resetKeepAlive();
if (var5.is(ChunkFlag.TICKING) && var5.pollActiveTimer(var11) <= 0) {
var2.run(var1x -> var5.setFlag(ChunkFlag.TICKING, false));
}
} else if (var5.pollKeepAlive(var11) <= 0) {
Ref var12 = var1.getReferenceTo(var0);
ChunkUnloadEvent var13 = new ChunkUnloadEvent(var5);
var2.invoke(var12, var13);
if (var13.isCancelled()) {
if (var13.willResetKeepAlive()) {
var5.resetKeepAlive();
}
} else {
var2.run(var1x -> var1x.getExternalData().remove(var12, RemoveReason.UNLOAD));
}
}
}
}
class="kw">public class="kw">static ChunkTracker.ChunkVisibility getChunkVisibility(@Nonnull ChunkStore var0, @Nonnull List<ChunkTracker> var1, long var2) {
boolean var4 = var0.hasLoadedSections(var2);
for (ChunkTracker var6 : var1) {
class="kw">switch (var6.getChunkVisibility(var2)) {
case NONE:
class="kw">default:
break;
case HOT:
class="kw">return ChunkTracker.ChunkVisibility.HOT;
case COLD:
var4 = true;
}
}
class="kw">return var4 ? ChunkTracker.ChunkVisibility.COLD : ChunkTracker.ChunkVisibility.NONE;
}
class="kw">private class="kw">static boolean isChunkInBox(@Nonnull Box2D var0, int var1, int var2) {
int var3 = ChunkUtil.minBlock(var1);
int var4 = ChunkUtil.minBlock(var2);
int var5 = ChunkUtil.maxBlock(var1);
int var6 = ChunkUtil.maxBlock(var2);
class="kw">return var5 >= var0.min.x && var3 <= var0.max.x && var6 >= var0.min.y && var4 <= var0.max.y;
}
class="kw">private class="kw">static void collectTrackers(@Nonnull ArchetypeChunk<EntityStore> var0, @Nonnull CommandBuffer<EntityStore> var1) {
Store var2 = var1.getExternalData().getWorld().getChunkStore().getStore();
ChunkUnloadingSystem.Data var3 = var2.getResource(ChunkStore.UNLOAD_RESOURCE);
for (int var4 = 0; var4 < var0.size(); var4++) {
ChunkTracker var5 = var0.getComponent(var4, ChunkTracker.getComponentType());
var3.chunkTrackers.add(var5);
}
}
class="kw">public class="kw">static class Data class="kw">extends UnloadingSystemData {
class="kw">public Data() {
}
class="kw">public Data(float var1) {
super(var1);
}
@Nonnull
@Override
class="kw">public Resource<ChunkStore> clone() {
class="kw">return new ChunkUnloadingSystem.Data(this.time);
}
}
}