PropDistributionContent class

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

Файл: com/hypixel/hytale/builtin/hytalegenerator/propdistributions/GraphPropDistribution.java

Поля (4)

МодификаторыТипИмя
public static final GraphPropDistribution.PropDistributionContent EMPTY
public final PropDistribution propDistribution
public final double radius
public final double rangeSquared

Исходный код

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

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 com.hypixel.hytale.builtin.hytalegenerator.props.Prop;
class="kw">import java.util.ArrayList;
class="kw">import java.util.Comparator;
class="kw">import java.util.List;
class="kw">import java.util.function.Consumer;
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 GraphPropDistribution class="kw">extends PropDistribution {
   @Nonnull
   class="kw">private class="kw">static class="kw">final Comparator<GraphSpace.Node> nodeComparator = Comparator.comparingInt(GraphSpace.Node::hashCode);
   @Nonnull
   class="kw">private 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<GraphPropDistribution.PropDistributionContent> 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 PropDistribution.Context rChildContext;
   @Nonnull
   class="kw">private class="kw">final Vector3d rAnchor;
   @Nullable
   class="kw">private Vector3dc rNodePosition;
   @Nullable
   class="kw">private Pipe.Two<Vector3d, Prop> rContextPipe;
   @Nonnull
   class="kw">private class="kw">final Pipe.Two<Vector3d, Prop> rChildPipe;

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

      for (int var6 = 0; var6 < var3.size(); var6++) {
         GraphPropDistribution.PropDistributionContent 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 PropDistribution.Context();
      this.rChildPipe = this::pipe;
   }

   @Override
   class="kw">public void distribute(@Nonnull PropDistribution.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();
                           this.rContextPipe = null;
                           this.rChildContext.clearReferences();
                           class="kw">return;
                        }

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

                     this.rResultList.clear();
                  }
               }
            }

            this.rCellIndex.x++;
         }

         this.rContextPipe = null;
         this.rChildContext.clearReferences();
      }
   }

   class="kw">private void runOnNode(@Nonnull GraphSpace.Node var1, @Nonnull Control var2, @Nonnull PropDistribution.Context var3) {
      int var4 = var1.content().index;
      if (var4 != -1) {
         GraphPropDistribution.PropDistributionContent 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.propDistribution.distribute(this.rChildContext);
               this.rNodePosition = null;
               this.rContextPipe = null;
            }
         }
      }
   }

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

   @Override
   class="kw">public void forEachPossibleProp(@Nonnull Consumer<Prop> var1) {
      for (int var2 = 0; var2 < this.indexedContent.size(); var2++) {
         GraphPropDistribution.PropDistributionContent var3 = this.indexedContent.get(var2);
         var3.propDistribution.forEachPossibleProp(var1);
      }
   }

   class="kw">public class="kw">static class PropDistributionContent {
      class="kw">public class="kw">static class="kw">final GraphPropDistribution.PropDistributionContent EMPTY = new GraphPropDistribution.PropDistributionContent(
         EmptyPropDistribution.INSTANCE, 0.0
      );
      @Nonnull
      class="kw">public class="kw">final PropDistribution propDistribution;
      class="kw">public class="kw">final double radius;
      class="kw">public class="kw">final double rangeSquared;

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