MSpaceNodeCache.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using CommonAI.Data;
  2. using CommonAI.RTS;
  3. using CommonAI.RTS.Manhattan;
  4. using CommonAI.Zone;
  5. using CommonAI.Zone.Helper;
  6. using CommonLang;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using static CommonAI.RTS.Manhattan.AstarManhattan;
  12. using static CommonAI.RTS.Manhattan.AstarManhattan.MSpaceAStar;
  13. //using System.Threading.Tasks;
  14. namespace CommonAI.ZoneServer.JSGModule
  15. {
  16. class MSpaceNodeCache
  17. {
  18. public class MSpaceNodeItem
  19. {
  20. public MSpaceNode[,] data;
  21. public void Clone(MSpaceNodeItem cacheItem, MSpaceMap map, SpaceDivision space)
  22. {
  23. int XCount = data.GetLength(0);
  24. int YCount = data.GetLength(1);
  25. for (int cx = 0; cx < XCount; cx++)
  26. {
  27. for (int cy = 0; cy < YCount; cy++)
  28. {
  29. this.data[cx, cy] = new MSpaceNode(map, space.GetSpaceCellNodeByBlock(cx, cy));
  30. }
  31. }
  32. for (int cx = 0; cx < space.SpaceXCount; cx++)
  33. {
  34. for (int cy = 0; cy < space.SpaceYCount; cy++)
  35. {
  36. this.data[cx, cy].Clone(cacheItem.data[cx, cy]);
  37. }
  38. }
  39. }
  40. }
  41. private static readonly HashMap<int, MSpaceAStar> mCacheAstar = new HashMap<int, MSpaceAStar>();
  42. /** 获取缓存中的Astart节点数据,如果不想使用缓存sceneID=0 */
  43. public static MSpaceAStar GetCacheAStart(int uniqueID, AstarManhattan map, int space_size)
  44. {
  45. if (uniqueID <= 0)
  46. {
  47. return new MSpaceAStar(uniqueID, map, space_size);
  48. }
  49. else
  50. {
  51. MSpaceAStar cacheItem = mCacheAstar.Get(uniqueID);
  52. if (cacheItem == null)
  53. {
  54. cacheItem = new MSpaceAStar(uniqueID, map, space_size);
  55. mCacheAstar.Put(uniqueID, cacheItem);
  56. }
  57. return cacheItem;
  58. }
  59. }
  60. }
  61. }