Data class

Пакет: com.hypixel.hytale.server.core.universe.world.storage.component

Файл: com/hypixel/hytale/server/core/universe/world/storage/component/SectionUnloadingSystem.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.NonTicking;
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.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.section.BlockComponentSection;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.section.ChunkSection;
class="kw">import com.hypixel.hytale.server.core.universe.world.chunk.section.EntitySection;
class="kw">import com.hypixel.hytale.server.core.universe.world.events.ecs.SectionUnloadEvent;
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 javax.annotation.Nonnull;

class="kw">public class SectionUnloadingSystem 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 SectionUnloadingSystem() {
   }

   @Override
   class="kw">public void tick(float var1, int var2, @Nonnull Store<ChunkStore> var3) {
      SectionUnloadingSystem.Data var4 = var3.getResource(ChunkStore.SECTION_UNLOAD_RESOURCE);
      World var5 = var3.getExternalData().getWorld();
      if (var5.getWorldConfig().canUnloadChunks()) {
         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(), SectionUnloadingSystem::collectTrackers);
            var3.forEachEntityParallel(ChunkSection.getComponentType(), SectionUnloadingSystem::tryUnload);
         }
      }
   }

   class="kw">public class="kw">static void tryUnload(int var0, @Nonnull ArchetypeChunk<ChunkStore> var1, @Nonnull CommandBuffer<ChunkStore> var2) {
      ChunkSection var3 = var1.getComponent(var0, ChunkSection.getComponentType());
      assert var3 != null;
      int var4 = var3.getX();
      int var5 = var3.getY();
      int var6 = var3.getZ();
      if (var5 < 0 || var5 >= 10) {
         SectionUnloadingSystem.Data var7 = var2.getResource(ChunkStore.SECTION_UNLOAD_RESOURCE);
         ChunkTracker.ChunkVisibility var8 = getSectionVisibility(var7.chunkTrackers, var4, var5, var6);
         if (var8 == ChunkTracker.ChunkVisibility.HOT) {
            var3.resetKeepAlive();
            var3.resetActiveTimer();
         } else {
            EntitySection var9 = var1.getComponent(var0, EntitySection.getComponentType());
            BlockComponentSection var10 = var1.getComponent(var0, BlockComponentSection.getComponentType());
            boolean var11 = var3.needsSaving()
               || var3.isSaving()
               || var9 != null && (var9.needsSaving() || var9.isSaving())
               || var10 != null && (var10.needsSaving() || var10.isSaving());
            int var12 = var7.pollCount;
            if (var8 == ChunkTracker.ChunkVisibility.COLD || var11) {
               var3.resetKeepAlive();
               Ref var15 = var1.getReferenceTo(var0);
               boolean var16 = var1.<NonTicking<ChunkStore>>getComponent(var0, ChunkStore.REGISTRY.getNonTickingComponentType()) == null;
               if (var16 && var3.pollActiveTimer(var12) <= 0) {
                  var2.run(var1x -> var1x.ensureComponent(var15, ChunkStore.REGISTRY.getNonTickingComponentType()));
               }
            } else if (var3.pollKeepAlive(var12) <= 0) {
               Ref var13 = var1.getReferenceTo(var0);
               SectionUnloadEvent var14 = new SectionUnloadEvent(var3);
               var2.invoke(var13, var14);
               if (var14.isCancelled()) {
                  if (var14.willResetKeepAlive()) {
                     var3.resetKeepAlive();
                  }
               } else {
                  var2.run(var1x -> var1x.getExternalData().removeSection(var13, RemoveReason.UNLOAD));
               }
            }
         }
      }
   }

   class="kw">public class="kw">static ChunkTracker.ChunkVisibility getSectionVisibility(@Nonnull List<ChunkTracker> var0, int var1, int var2, int var3) {
      boolean var4 = false;

      for (ChunkTracker var6 : var0) {
         class="kw">switch (var6.getSectionVisibility(var1, var2, var3)) {
            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 void collectTrackers(@Nonnull ArchetypeChunk<EntityStore> var0, @Nonnull CommandBuffer<EntityStore> var1) {
      Store var2 = var1.getExternalData().getWorld().getChunkStore().getStore();
      SectionUnloadingSystem.Data var3 = var2.getResource(ChunkStore.SECTION_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 SectionUnloadingSystem.Data(this.time);
      }
   }
}