예제 #1
0
            private static void ExpandSide(TrixelCluster.Box box, ICollection <TrixelEmplacement> subChunk, List <TrixelEmplacement> boxTrixels, Vector3 normal)
            {
                int  trixelsToRollback = 0;
                bool flag = (double)Vector3.Dot(normal, Vector3.One) > 0.0;

                if (flag)
                {
                    box.End += normal;
                }
                else
                {
                    box.Start += normal;
                }
                for (; TrixelCluster.Chunk.TestFace(subChunk, (ICollection <TrixelEmplacement>)boxTrixels, normal, false, box, ref trixelsToRollback); trixelsToRollback = 0)
                {
                    if (flag)
                    {
                        box.End += normal;
                    }
                    else
                    {
                        box.Start += normal;
                    }
                }
                boxTrixels.RemoveRange(boxTrixels.Count - trixelsToRollback, trixelsToRollback);
                if (flag)
                {
                    box.End -= normal;
                }
                else
                {
                    box.Start -= normal;
                }
            }
예제 #2
0
            private static List <TrixelEmplacement> FindBiggestBox(TrixelEmplacement center, ICollection <TrixelEmplacement> subChunk, out TrixelCluster.Box box)
            {
                List <TrixelEmplacement> boxTrixels = new List <TrixelEmplacement>()
                {
                    center
                };

                box = new TrixelCluster.Box()
                {
                    Start = center,
                    End   = center
                };
                int trixelsToRollback;

                do
                {
                    box.Start        -= Vector3.One;
                    box.End          += Vector3.One;
                    trixelsToRollback = 0;
                }while (TrixelCluster.Chunk.TestFace(subChunk, (ICollection <TrixelEmplacement>)boxTrixels, Vector3.UnitZ, false, box, ref trixelsToRollback) && TrixelCluster.Chunk.TestFace(subChunk, (ICollection <TrixelEmplacement>)boxTrixels, -Vector3.UnitZ, false, box, ref trixelsToRollback) && (TrixelCluster.Chunk.TestFace(subChunk, (ICollection <TrixelEmplacement>)boxTrixels, Vector3.UnitX, true, box, ref trixelsToRollback) && TrixelCluster.Chunk.TestFace(subChunk, (ICollection <TrixelEmplacement>)boxTrixels, -Vector3.UnitX, true, box, ref trixelsToRollback)) && (TrixelCluster.Chunk.TestFace(subChunk, (ICollection <TrixelEmplacement>)boxTrixels, Vector3.UnitY, true, box, ref trixelsToRollback) && TrixelCluster.Chunk.TestFace(subChunk, (ICollection <TrixelEmplacement>)boxTrixels, -Vector3.UnitY, true, box, ref trixelsToRollback)));
                boxTrixels.RemoveRange(boxTrixels.Count - trixelsToRollback, trixelsToRollback);
                box.Start += Vector3.One;
                box.End   -= Vector3.One;
                if (boxTrixels.Count < subChunk.Count)
                {
                    foreach (Vector3 normal in TrixelCluster.Directions)
                    {
                        TrixelCluster.Chunk.ExpandSide(box, subChunk, boxTrixels, normal);
                    }
                }
                box.End += Vector3.One;
                return(boxTrixels);
            }
예제 #3
0
 internal bool IsNeighbor(TrixelCluster.Box box)
 {
     if (Enumerable.Any <TrixelCluster.Box>((IEnumerable <TrixelCluster.Box>) this.Boxes, (Func <TrixelCluster.Box, bool>)(b => b.IsNeighbor(box))))
     {
         return(true);
     }
     else
     {
         return(Enumerable.Any <TrixelEmplacement>((IEnumerable <TrixelEmplacement>) this.Trixels, new Func <TrixelEmplacement, bool>(box.IsNeighbor)));
     }
 }
예제 #4
0
 private void Dismantle(TrixelCluster.Box box)
 {
     for (int x = box.Start.X; x < box.End.X; ++x)
     {
         for (int y = box.Start.Y; y < box.End.Y; ++y)
         {
             for (int z = box.Start.Z; z < box.End.Z; ++z)
             {
                 this.Trixels.Add(new TrixelEmplacement(x, y, z));
             }
         }
     }
 }
예제 #5
0
 public void OnDeserialization()
 {
     if (this.deserializedOrphans != null)
     {
         using (List <TrixelEmplacement> .Enumerator enumerator = this.deserializedOrphans.GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 TrixelEmplacement   trixel = enumerator.Current;
                 TrixelCluster.Chunk chunk  = Enumerable.FirstOrDefault <TrixelCluster.Chunk>((IEnumerable <TrixelCluster.Chunk>) this.Chunks, (Func <TrixelCluster.Chunk, bool>)(c => c.IsNeighbor(trixel)));
                 if (chunk == null)
                 {
                     this.Chunks.Add(chunk = new TrixelCluster.Chunk());
                 }
                 chunk.Trixels.Add(trixel);
             }
         }
         this.deserializedOrphans = (List <TrixelEmplacement>)null;
     }
     if (this.deserializedBoxes == null)
     {
         return;
     }
     using (List <TrixelCluster.Box> .Enumerator enumerator = this.deserializedBoxes.GetEnumerator())
     {
         while (enumerator.MoveNext())
         {
             TrixelCluster.Box   box   = enumerator.Current;
             TrixelCluster.Chunk chunk = Enumerable.FirstOrDefault <TrixelCluster.Chunk>((IEnumerable <TrixelCluster.Chunk>) this.Chunks, (Func <TrixelCluster.Chunk, bool>)(c => c.IsNeighbor(box)));
             if (chunk == null)
             {
                 this.Chunks.Add(chunk = new TrixelCluster.Chunk());
             }
             chunk.Boxes.Add(box);
         }
     }
     this.deserializedBoxes = (List <TrixelCluster.Box>)null;
 }
예제 #6
0
 internal bool IsNeighbor(TrixelCluster.Box other)
 {
     return(new BoundingBox(this.Start.Position, this.End.Position).Intersects(new BoundingBox(other.Start.Position, other.End.Position)));
 }
예제 #7
0
            private static bool TestFace(ICollection <TrixelEmplacement> subChunk, ICollection <TrixelEmplacement> boxTrixels, Vector3 normal, bool partial, TrixelCluster.Box box, ref int trixelsToRollback)
            {
                Vector3 vector3_1 = FezMath.Abs(normal);
                Vector3 vector2_1 = (double)normal.Z != 0.0 ? Vector3.UnitX : Vector3.UnitZ;
                Vector3 vector2_2 = (double)normal.Z != 0.0 ? Vector3.UnitY : new Vector3(1f, 1f, 0.0f) - vector3_1;
                Vector3 vector3_2 = ((double)Vector3.Dot(normal, Vector3.One) > 0.0 ? box.End.Position : box.Start.Position) * vector3_1;
                int     num1      = (int)Vector3.Dot(box.Start.Position, vector2_1);
                int     num2      = (int)Vector3.Dot(box.End.Position, vector2_1);
                int     num3      = (int)Vector3.Dot(box.Start.Position, vector2_2);
                int     num4      = (int)Vector3.Dot(box.End.Position, vector2_2);

                if (partial)
                {
                    ++num1;
                    --num2;
                }
                for (int index1 = num1; index1 <= num2; ++index1)
                {
                    for (int index2 = num3; index2 <= num4; ++index2)
                    {
                        TrixelEmplacement trixelEmplacement = new TrixelEmplacement((float)index1 * vector2_1 + (float)index2 * vector2_2 + vector3_2);
                        if (!subChunk.Contains(trixelEmplacement))
                        {
                            return(false);
                        }
                        ++trixelsToRollback;
                        boxTrixels.Add(trixelEmplacement);
                    }
                }
                return(true);
            }