コード例 #1
0
ファイル: Path.cs プロジェクト: NerdDev/Hackmobile
 void Prune()
 {
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGen) && BigBoss.Debug.Flag(DebugManager.DebugFlag.LevelGen_Path_Simplify_Prune))
     {
         BigBoss.Debug.printHeader(Logs.LevelGen, "Prune");
     }
     #endregion
     Bounding bounds = new Bounding();
     foreach (Value2D <GenSpace> g in List)
     {
         bounds.Absorb(g);
     }
     Array2D <int> indexes          = new Array2D <int>(bounds);
     List <Value2D <GenSpace> > tmp = new List <Value2D <GenSpace> >(List);
     int index = 0;
     foreach (Value2D <GenSpace> val in tmp)
     { // For each point on the path
         int           lastDiff = 0;
         Value2D <int> neighbor = null;
         indexes.DrawAround(val.x, val.y, false, (arr2, x, y) =>
         { // Find neighboring point on path with the largest distance from current
             if (arr2[x, y] == 0)
             {
                 return(true);
             }
             int valDiff = Mathf.Abs(index - arr2[x, y]);
             if (valDiff > 1 && // Diff meets requirements
                 (neighbor == null || lastDiff < valDiff))    // Larger than last found diff
             {
                 lastDiff = valDiff;
                 neighbor = new Value2D <int>(x, y, arr2[x, y]);
             }
             return(true);
         });
         #region DEBUG
         if (BigBoss.Debug.logging(Logs.LevelGen) && BigBoss.Debug.Flag(DebugManager.DebugFlag.LevelGen_Path_Simplify_Prune))
         {
             BigBoss.Debug.w(Logs.LevelGen, "Evaluating " + val);
             if (neighbor != null)
             {
                 BigBoss.Debug.w(Logs.LevelGen, "Found Neighbor " + neighbor);
             }
         }
         #endregion
         if (neighbor != null)
         { // If point of interest exists, prune
             int fromIndex = neighbor.val + 1;
             int count     = index - neighbor.val - 1;
             // Set indices to 0
             List <Value2D <GenSpace> > toRemove = List.GetRange(fromIndex, count);
             foreach (Value2D <GenSpace> r in toRemove)
             {
                 indexes[r.x, r.y] = 0;
             }
             // Remove
             List.RemoveRange(fromIndex, count);
             // Set next index to proper number
             index = neighbor.val + 1;
             #region DEBUG
             if (BigBoss.Debug.logging(Logs.LevelGen) && BigBoss.Debug.Flag(DebugManager.DebugFlag.LevelGen_Path_Simplify_Prune))
             {
                 BigBoss.Debug.w(Logs.LevelGen, "Removed index: " + fromIndex + " count: " + count);
                 MultiMap <GridType> map = new MultiMap <GridType>();
                 foreach (var v in List)
                 {
                     map[v] = v.val.Type;
                 }
                 map.ToLog(Logs.LevelGen);
             }
             #endregion
         }
         indexes[val.x, val.y] = index;
         index++;
     }
     #region DEBUG
     if (BigBoss.Debug.logging(Logs.LevelGen) && BigBoss.Debug.Flag(DebugManager.DebugFlag.LevelGen_Path_Simplify_Prune))
     {
         BigBoss.Debug.printFooter(Logs.LevelGen, "Prune");
     }
     #endregion
 }