AstarManhattanCache.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using CommonAI.Data;
  2. using CommonAI.RTS.Manhattan;
  3. using CommonAI.Zone;
  4. using CommonAI.Zone.Helper;
  5. using CommonLang;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. //using System.Threading.Tasks;
  11. namespace CommonAI.ZoneServer.JSGModule
  12. {
  13. class AstarManhattanCache
  14. {
  15. public class AStartCacheData
  16. {
  17. public ZoneManhattanMap mManhattanMap;
  18. public AstarManhattan mAstartManhattan;
  19. }
  20. private static readonly HashMap<int, List<AStartCacheData>> mCacheAstar = new HashMap<int, List<AStartCacheData>>();
  21. public static void CacheSceneAstart(int sceneID, ZoneInfo info, TerrainDefinitionMap terrainMap, SceneType type)
  22. {
  23. List<AStartCacheData> astarList = mCacheAstar.Get(sceneID);
  24. if(astarList == null)
  25. {
  26. astarList = new List<AStartCacheData>(1);
  27. mCacheAstar.Put(sceneID, astarList);
  28. }
  29. AStartCacheData cacheTemp = new AStartCacheData();
  30. cacheTemp.mManhattanMap = new ZoneManhattanMap(info.Clone() as ZoneInfo, terrainMap);
  31. cacheTemp.mAstartManhattan = new AstarManhattan(cacheTemp.mManhattanMap, true, JSGModule.GetSpaceDiveSize(type));
  32. astarList.Add(cacheTemp);
  33. }
  34. public static AStartCacheData GetCacheAStart(int sceneID)
  35. {
  36. List<AStartCacheData> astarList = mCacheAstar.Get(sceneID);
  37. if (astarList != null && astarList.Count > 0)
  38. {
  39. AStartCacheData result = astarList[0];
  40. astarList.RemoveAt(0);
  41. if(astarList.Count <= 0)
  42. {
  43. mCacheAstar.Remove(sceneID);
  44. }
  45. return result;
  46. }
  47. return null;
  48. }
  49. }
  50. }