Beispiel #1
0
 public override void OnLoad()
 {
     if (layerMap == null || original == null)
     {
         return;
     }
     if (!original.GetRectBox().Contains(endLocation.X(), endLocation.Y()))
     {
         if (useCache)
         {
             lock (pathCache)
             {
                 if (pathCache.Count > Loon.Core.LSystem.DEFAULT_MAX_CACHE_SIZE * 10)
                 {
                     pathCache.Clear();
                 }
                 Int32           key        = GetHashCode();
                 List <Vector2f> final_path = (List <Vector2f>)CollectionUtils.Get(pathCache, key);
                 if (final_path == null)
                 {
                     final_path = AStarFinder.Find(heuristic,
                                                   layerMap,
                                                   layerMap.PixelsToTilesWidth(startLocation
                                                                               .X()),
                                                   layerMap.PixelsToTilesHeight(startLocation
                                                                                .Y()),
                                                   layerMap.PixelsToTilesWidth(endLocation
                                                                               .X()),
                                                   layerMap.PixelsToTilesHeight(endLocation
                                                                                .Y()), flag);
                     CollectionUtils.Put(pathCache, key, final_path);
                 }
                 pActorPath = new List <Vector2f>();
                 CollectionUtils.AddAll(final_path, pActorPath);
             }
         }
         else
         {
             pActorPath = Loon.Action.Map.AStarFinder.Find(heuristic, layerMap,
                                                           layerMap.PixelsToTilesWidth(startLocation.X()),
                                                           layerMap.PixelsToTilesHeight(startLocation.Y()),
                                                           layerMap.PixelsToTilesWidth(endLocation.X()),
                                                           layerMap.PixelsToTilesHeight(endLocation.Y()), flag);
         }
     }
 }