VolumeSpatialIndex class

Пакет: com.hypixel.hytale.builtin.triggervolumes.system

Файл: com/hypixel/hytale/builtin/triggervolumes/system/VolumeSpatialIndex.java

Поля (29)

МодификаторыТипИмя
final int DEFAULT_CELL_SIZE
int var10
long var10
int var11
List var13
var13
List var15
Vector3d var2
VolumeEntry var3
List var3
Vector3d var3
double var3
SpatialSnapshot var4
Vector3d var4
int var4
Vector3d var4
Vector3d var5
int var5
Vector3d var5
int var6
int var6
long var6
int var7
int var7
int var8
int var8
long var8
int var9
int var9

Методы (33)

МодификаторыВозвратСигнатура
abstract throw new IllegalArgumentExceptionthrow new IllegalArgumentException("cellSize must be a positive multiple of 2, got " + var1)
abstract throw new IllegalArgumentExceptionthrow new IllegalArgumentException("maxCellsPerVolume must be positive, got " + var1)
abstract throw new IllegalStateExceptionthrow new IllegalStateException("cellSize cannot change while the index holds volumes")
abstract throw new IllegalStateExceptionthrow new IllegalStateException("maxCellsPerVolume cannot change while the index holds volumes")
public void applyPendingChangesvoid applyPendingChanges()
private int cellCoordint cellCoord(double var1)
public void clearvoid clear()
public void collectCandidatesvoid collectCandidates(@Nonnull Vector3d var1, @Nonnull List<VolumeEntry> var2)
static long footprintCellCountlong footprintCellCount(int var0, int var1, int var2, int var3, int var4, int var5)
for for(VolumeEntry var3 : var1)
for for(VolumeEntry var6 : this.removed)
for for(VolumeEntry var7 : this.largeVolumes)
for for(int var10 = var4; var10 <= var5; var10++)
for for(int var11 = var6; var11 <= var7; var11++)
for for(int var12 = var8; var12 <= var9; var12++)
for for(int var12 = var6; var12 <= var7; var12++)
for for(int var13 = var8; var13 <= var9; var13++)
for for(int var14 = var10; var14 <= var11; var14++)
public int getCellSizeint getCellSize()
public int getMaxCellsPerVolumeint getMaxCellsPerVolume()
if if(var1 <= 0)
if if(var3 != null)
if if(var13 == null)
if if(var15 != null)
public boolean isEmptyboolean isEmpty()
int largeVolumeCountint largeVolumeCount()
public void markChangedvoid markChanged(@Nonnull VolumeEntry var1, @Nonnull SpatialSnapshot var2)
public void markRemovedvoid markRemoved(@Nonnull VolumeEntry var1, @Nonnull SpatialSnapshot var2)
public void rebuildvoid rebuild(@Nonnull Collection<VolumeEntry> var1)
public void setCellSizevoid setCellSize(int var1)
public void setMaxCellsPerVolumevoid setMaxCellsPerVolume(int var1)
private void stampvoid stamp(@Nonnull VolumeEntry var1)
private void unstampvoid unstamp(@Nonnull VolumeEntry var1, @Nonnull Vector3d var2, @Nonnull TriggerVolumeShape var3)

Исходный код

Показать/скрыть
class="kw">package com.hypixel.hytale.builtin.triggervolumes.system;

class="kw">import com.hypixel.hytale.builtin.triggervolumes.manager.SpatialSnapshot;
class="kw">import com.hypixel.hytale.builtin.triggervolumes.manager.VolumeEntry;
class="kw">import com.hypixel.hytale.builtin.triggervolumes.shape.TriggerVolumeShape;
class="kw">import com.hypixel.hytale.math.data.Int3ObjectOpenHashMap;
class="kw">import java.util.ArrayList;
class="kw">import java.util.Collection;
class="kw">import java.util.List;
class="kw">import java.util.Map;
class="kw">import java.util.Set;
class="kw">import java.util.Map.Entry;
class="kw">import java.util.concurrent.ConcurrentHashMap;
class="kw">import javax.annotation.Nonnull;
class="kw">import org.joml.Vector3d;

class="kw">public class VolumeSpatialIndex {
   class="kw">private class="kw">static class="kw">final int DEFAULT_CELL_SIZE = 16;
   class="kw">private class="kw">static class="kw">final int DEFAULT_MAX_CELLS_PER_VOLUME = 27;
   class="kw">private class="kw">static class="kw">final int MAX_CELL_COORD = 16777216;
   @Nonnull
   class="kw">private class="kw">final Int3ObjectOpenHashMap<List<VolumeEntry>> cells = new Int3ObjectOpenHashMap<>();
   @Nonnull
   class="kw">private class="kw">final List<VolumeEntry> largeVolumes = new ArrayList<>();
   @Nonnull
   class="kw">private class="kw">final Map<VolumeEntry, SpatialSnapshot> pending = new ConcurrentHashMap<>();
   @Nonnull
   class="kw">private class="kw">final Set<VolumeEntry> removed = ConcurrentHashMap.newKeySet();
   class="kw">private int cellSize = 16;
   class="kw">private int maxCellsPerVolume = 27;

   class="kw">public VolumeSpatialIndex() {
   }

   class="kw">public int getCellSize() {
      class="kw">return this.cellSize;
   }

   class="kw">public void setCellSize(int var1) {
      if (var1 <= 0 || (var1 & 1) != 0) {
         throw new IllegalArgumentException("cellSize must be a positive multiple of 2, got " + var1);
      }

      if (this.cells.isEmpty() && this.largeVolumes.isEmpty()) {
         this.cellSize = var1;
      } else {
         throw new IllegalStateException("cellSize cannot change while the index holds volumes");
      }
   }

   class="kw">public int getMaxCellsPerVolume() {
      class="kw">return this.maxCellsPerVolume;
   }

   class="kw">public void setMaxCellsPerVolume(int var1) {
      if (var1 <= 0) {
         throw new IllegalArgumentException("maxCellsPerVolume must be positive, got " + var1);
      }

      if (this.cells.isEmpty() && this.largeVolumes.isEmpty()) {
         this.maxCellsPerVolume = var1;
      } else {
         throw new IllegalStateException("maxCellsPerVolume cannot change while the index holds volumes");
      }
   }

   class="kw">public void markChanged(@Nonnull VolumeEntry var1, @Nonnull SpatialSnapshot var2) {
      this.pending.putIfAbsent(var1, var2);
   }

   class="kw">public void markRemoved(@Nonnull VolumeEntry var1, @Nonnull SpatialSnapshot var2) {
      this.pending.putIfAbsent(var1, var2);
      this.removed.add(var1);
   }

   class="kw">public void clear() {
      this.cells.clear();
      this.largeVolumes.clear();
      this.pending.clear();
      this.removed.clear();
   }

   class="kw">public void rebuild(@Nonnull Collection<VolumeEntry> var1) {
      this.clear();

      for (VolumeEntry var3 : var1) {
         if (var3.isEnabled()) {
            this.stamp(var3);
         }
      }
   }

   class="kw">public boolean isEmpty() {
      class="kw">return this.cells.isEmpty() && this.largeVolumes.isEmpty();
   }

   int largeVolumeCount() {
      class="kw">return this.largeVolumes.size();
   }

   class="kw">public void applyPendingChanges() {
      if (!this.pending.isEmpty() || !this.removed.isEmpty()) {
         for (Entry var2 : this.pending.entrySet()) {
            VolumeEntry var3 = var2.getKey();
            SpatialSnapshot var4 = var2.getValue();
            this.unstamp(var3, var4.position(), var4.shape());
            if (!this.removed.contains(var3) && var3.isEnabled()) {
               this.stamp(var3);
            }
         }

         for (VolumeEntry var6 : this.removed) {
            if (!this.pending.containsKey(var6)) {
               this.unstamp(var6, var6.getPosition(), var6.getShape());
            }
         }

         this.pending.clear();
         this.removed.clear();
      }
   }

   class="kw">public void collectCandidates(@Nonnull Vector3d var1, @Nonnull List<VolumeEntry> var2) {
      List var3 = this.cells.get(this.cellCoord(var1.x()), this.cellCoord(var1.y()), this.cellCoord(var1.z()));
      if (var3 != null) {
         var2.addAll(var3);
      }

      if (!this.largeVolumes.isEmpty()) {
         Vector3d var4 = new Vector3d();
         Vector3d var5 = new Vector3d();

         for (VolumeEntry var7 : this.largeVolumes) {
            var7.getShape().getWorldAABB(var7.getPosition(), var4, var5);
            if (var1.x() >= var4.x() && var1.x() <= var5.x() && var1.y() >= var4.y() && var1.y() <= var5.y() && var1.z() >= var4.z() && var1.z() <= var5.z()) {
               var2.add(var7);
            }
         }
      }
   }

   class="kw">private void stamp(@Nonnull VolumeEntry var1) {
      Vector3d var2 = new Vector3d();
      Vector3d var3 = new Vector3d();
      var1.getShape().getWorldAABB(var1.getPosition(), var2, var3);
      int var4 = this.cellCoord(var2.x());
      int var5 = this.cellCoord(var3.x());
      int var6 = this.cellCoord(var2.y());
      int var7 = this.cellCoord(var3.y());
      int var8 = this.cellCoord(var2.z());
      int var9 = this.cellCoord(var3.z());
      if (footprintCellCount(var4, var5, var6, var7, var8, var9) > this.maxCellsPerVolume) {
         this.largeVolumes.add(var1);
      } else {
         for (int var10 = var4; var10 <= var5; var10++) {
            for (int var11 = var6; var11 <= var7; var11++) {
               for (int var12 = var8; var12 <= var9; var12++) {
                  List var13 = this.cells.get(var10, var11, var12);
                  if (var13 == null) {
                     var13 = new ArrayList<>();
                     this.cells.put(var10, var11, var12, var13);
                  }

                  var13.add(var1);
               }
            }
         }
      }
   }

   class="kw">private void unstamp(@Nonnull VolumeEntry var1, @Nonnull Vector3d var2, @Nonnull TriggerVolumeShape var3) {
      Vector3d var4 = new Vector3d();
      Vector3d var5 = new Vector3d();
      var3.getWorldAABB(var2, var4, var5);
      int var6 = this.cellCoord(var4.x());
      int var7 = this.cellCoord(var5.x());
      int var8 = this.cellCoord(var4.y());
      int var9 = this.cellCoord(var5.y());
      int var10 = this.cellCoord(var4.z());
      int var11 = this.cellCoord(var5.z());
      if (footprintCellCount(var6, var7, var8, var9, var10, var11) > this.maxCellsPerVolume) {
         this.largeVolumes.remove(var1);
      } else {
         for (int var12 = var6; var12 <= var7; var12++) {
            for (int var13 = var8; var13 <= var9; var13++) {
               for (int var14 = var10; var14 <= var11; var14++) {
                  List var15 = this.cells.get(var12, var13, var14);
                  if (var15 != null) {
                     var15.remove(var1);
                     if (var15.isEmpty()) {
                        this.cells.remove(var12, var13, var14);
                     }
                  }
               }
            }
         }
      }
   }

   class="kw">private class="kw">static long footprintCellCount(int var0, int var1, int var2, int var3, int var4, int var5) {
      long var6 = (long)var1 - var0 + 1L;
      long var8 = (long)var3 - var2 + 1L;
      long var10 = (long)var5 - var4 + 1L;
      class="kw">return var6 * var8 * var10;
   }

   class="kw">private int cellCoord(double var1) {
      double var3 = Math.floor(var1 / this.cellSize);
      class="kw">return Math.clamp((long)var3, -16777216, 16777216);
   }
}