GraphPositionProvider class

Пакет: com.hypixel.hytale.builtin.hytalegenerator.positionproviders

Файл: com/hypixel/hytale/builtin/hytalegenerator/positionproviders/GraphPositionProvider.java

extends: PositionProvider

Поля (13)

МодификаторыТипИмя
public static final GraphPositionProvider.PositionsContent EMPTY
public final PositionProvider positions
public final double radius
public final double rangeSquared
return
GraphSpace.ReadOnly var2
double var3
double var4
var4
GraphSpace.Node var4
int var4
GraphPositionProvider.PositionsContent var5
GraphPositionProvider.PositionsContent var7

Методы (13)

МодификаторыВозвратСигнатура
public PositionsContentpublic PositionsContent(@Nonnull PositionProvider var1, double var2)
for for(this.rCellIndex.y = this.rMinCellIndex.y; this.rCellIndex.y < this.rMaxCellIndex.y; this.rCellIndex.y++)
for for(this.rCellIndex.z = this.rMinCellIndex.z; this.rCellIndex.z < this.rMaxCellIndex.z; this.rCellIndex.z++)
abstract for for(int var6 = 0; var6 < var3.size()
abstract for for(int var3 = 0; var3 < this.rResultList.size()
if if(!this.isEmpty)
if if(var2 != null)
if if(this.rControl.stop)
if if(var4 != -1)
if if(var5 != null)
private void pipevoid pipe(@Nonnull Vector3d var1, @Nonnull Control var2)
private void runOnNodevoid runOnNode(@Nonnull GraphSpace.Node var1, @Nonnull Control var2, @Nonnull PositionProvider.Context var3)
while while(this.rCellIndex.x < this.rMaxCellIndex.x)

Исходный код

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

class="kw">import com.hypixel.hytale.builtin.hytalegenerator.GridCache;
class="kw">import com.hypixel.hytale.builtin.hytalegenerator.VectorUtil;
class="kw">import com.hypixel.hytale.builtin.hytalegenerator.bounds.Bounds3d;
class="kw">import com.hypixel.hytale.builtin.hytalegenerator.graph.GraphGenerator;
class="kw">import com.hypixel.hytale.builtin.hytalegenerator.graph.GraphSpace;
class="kw">import com.hypixel.hytale.builtin.hytalegenerator.pipe.Control;
class="kw">import com.hypixel.hytale.builtin.hytalegenerator.pipe.Pipe;
class="kw">import java.util.ArrayList;
class="kw">import java.util.Comparator;
class="kw">import java.util.List;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3d;
class="kw">import org.joml.Vector3dc;
class="kw">import org.joml.Vector3i;

class="kw">public class GraphPositionProvider class="kw">extends PositionProvider {
   @Nonnull
   class="kw">private class="kw">static class="kw">final Comparator<GraphSpace.Node> nodeComparator = Comparator.comparingInt(GraphSpace.Node::hashCode);
   @Nonnull
   class="kw">private class="kw">final GraphGenerator graphGenerator;
   @Nonnull
   class="kw">private class="kw">final GridCache<GraphSpace.ReadOnly> grid;
   class="kw">private class="kw">final double contentRadius;
   class="kw">private double contentRadiusSquared;
   @Nonnull
   class="kw">private class="kw">final List<GraphPositionProvider.PositionsContent> indexedContent;
   class="kw">private class="kw">final boolean isEmpty;
   @Nonnull
   class="kw">private class="kw">final List<GraphSpace.Node> rResultList;
   @Nonnull
   class="kw">private class="kw">final Bounds3d rGraphBounds;
   @Nonnull
   class="kw">private class="kw">final Bounds3d rIntersectingCellBounds;
   @Nonnull
   class="kw">private class="kw">final Bounds3d rContentBounds;
   @Nonnull
   class="kw">private class="kw">final Vector3d rBoundsMaxInclusive;
   @Nonnull
   class="kw">private class="kw">final Vector3i rMinCellIndex;
   @Nonnull
   class="kw">private class="kw">final Vector3i rMaxCellIndex;
   @Nonnull
   class="kw">private class="kw">final Vector3i rCellIndex;
   @Nonnull
   class="kw">private class="kw">final Control rControl;
   @Nonnull
   class="kw">private class="kw">final PositionProvider.Context rChildContext;
   @Nonnull
   class="kw">private class="kw">final Vector3d rAnchor;
   @Nullable
   class="kw">private Vector3dc rNodePosition;
   @Nullable
   class="kw">private Pipe.One<Vector3d> rContextPipe;
   @Nonnull
   class="kw">private class="kw">final Pipe.One<Vector3d> rChildPipe;

   class="kw">public GraphPositionProvider(
      @Nonnull GraphGenerator var1, @Nonnull GridCache<GraphSpace.ReadOnly> var2, @Nonnull List<GraphPositionProvider.PositionsContent> var3
   ) {
      this.graphGenerator = var1;
      this.grid = var2;
      this.indexedContent = new ArrayList<>(var3);
      double var4 = 0.0;

      for (int var6 = 0; var6 < var3.size(); var6++) {
         GraphPositionProvider.PositionsContent var7 = var3.get(var6);
         var4 = Math.max(var7.radius, var4);
      }

      this.contentRadius = var4;
      this.isEmpty = var4 == 0.0;
      this.rResultList = new ArrayList<>();
      this.rGraphBounds = new Bounds3d();
      this.rIntersectingCellBounds = new Bounds3d();
      this.rContentBounds = new Bounds3d();
      this.rBoundsMaxInclusive = new Vector3d();
      this.rAnchor = new Vector3d();
      this.rMinCellIndex = new Vector3i();
      this.rMaxCellIndex = new Vector3i();
      this.rCellIndex = new Vector3i();
      this.rControl = new Control();
      this.rChildContext = new PositionProvider.Context();
      this.rChildPipe = this::pipe;
   }

   @Override
   class="kw">public void generate(@Nonnull PositionProvider.Context var1) {
      if (!this.isEmpty) {
         this.rGraphBounds.assign(var1.bounds).expand(this.contentRadius);
         this.rBoundsMaxInclusive.set(this.rGraphBounds.max);
         VectorUtil.nextDown(this.rBoundsMaxInclusive);
         this.grid.toCellIndex(this.rGraphBounds.min, this.rMinCellIndex);
         this.grid.toCellIndex(this.rBoundsMaxInclusive, this.rMaxCellIndex);
         this.rMaxCellIndex.x++;
         this.rMaxCellIndex.y++;
         this.rMaxCellIndex.z++;
         this.rControl.reset();
         this.rCellIndex.set(this.rMinCellIndex);

         while (this.rCellIndex.x < this.rMaxCellIndex.x) {
            for (this.rCellIndex.y = this.rMinCellIndex.y; this.rCellIndex.y < this.rMaxCellIndex.y; this.rCellIndex.y++) {
               for (this.rCellIndex.z = this.rMinCellIndex.z; this.rCellIndex.z < this.rMaxCellIndex.z; this.rCellIndex.z++) {
                  GraphSpace.ReadOnly var2 = this.grid.getCell(this.rCellIndex, this.graphGenerator);
                  assert var2 != null;
                  if (var2 != null) {
                     this.grid.toCellBounds(this.rCellIndex, this.rIntersectingCellBounds);
                     this.rIntersectingCellBounds.intersect(this.rGraphBounds);
                     VectorUtil.nextDown(this.rIntersectingCellBounds.max);
                     this.rResultList.clear();
                     var2.getNodes(this.rIntersectingCellBounds, this.rResultList);
                     this.rResultList.sort(nodeComparator);

                     for (int var3 = 0; var3 < this.rResultList.size(); var3++) {
                        GraphSpace.Node var4 = this.rResultList.get(var3);
                        if (this.rControl.stop) {
                           this.rResultList.clear();
                           class="kw">return;
                        }

                        this.runOnNode(var4, this.rControl, var1);
                     }

                     this.rResultList.clear();
                  }
               }
            }

            this.rCellIndex.x++;
         }
      }
   }

   class="kw">private void runOnNode(@Nonnull GraphSpace.Node var1, @Nonnull Control var2, @Nonnull PositionProvider.Context var3) {
      int var4 = var1.content().index;
      if (var4 != -1) {
         GraphPositionProvider.PositionsContent var5 = this.indexedContent.get(var4);
         if (var5 != null) {
            this.rContentBounds.min.set(-var5.radius);
            this.rContentBounds.max.set(var5.radius);
            this.rContentBounds.offset(var1.position());
            if (this.rContentBounds.intersects(var3.bounds)) {
               this.rChildContext.assign(var3);
               this.rChildContext.bounds = this.rContentBounds;
               this.rAnchor.set(var1.position());
               this.rChildContext.anchor = this.rAnchor;
               this.rChildContext.graphNode = var1;
               this.contentRadiusSquared = var5.rangeSquared;
               this.rNodePosition = var1.position();
               this.rContextPipe = var3.pipe;
               this.rChildContext.pipe = this.rChildPipe;
               var5.positions.generate(this.rChildContext);
               this.rChildContext.clearReferences();
               this.rNodePosition = null;
               this.rContextPipe = null;
            }
         }
      }
   }

   class="kw">private void pipe(@Nonnull Vector3d var1, @Nonnull Control var2) {
      double var3 = var1.distanceSquared(this.rNodePosition);
      if (!(var3 >= this.contentRadiusSquared)) {
         assert this.rContextPipe != null;
         this.rContextPipe.accept(var1, var2);
      }
   }

   class="kw">public class="kw">static class PositionsContent {
      class="kw">public class="kw">static class="kw">final GraphPositionProvider.PositionsContent EMPTY = new GraphPositionProvider.PositionsContent(EmptyPositionProvider.INSTANCE, 0.0);
      @Nonnull
      class="kw">public class="kw">final PositionProvider positions;
      class="kw">public class="kw">final double radius;
      class="kw">public class="kw">final double rangeSquared;

      class="kw">public PositionsContent(@Nonnull PositionProvider var1, double var2) {
         assert var2 >= 9.0;
         this.positions = var1;
         this.radius = var2;
         this.rangeSquared = var2 * var2;
      }
   }
}