using CommonAI.Data; using CommonAI.RTS; using CommonAI.RTS.Manhattan; using CommonAI.Zone; using CommonAI.Zone.Helper; using CommonLang; using System; using System.Collections.Generic; using System.Linq; using System.Text; using static CommonAI.RTS.Manhattan.AstarManhattan; using static CommonAI.RTS.Manhattan.AstarManhattan.MSpaceAStar; //using System.Threading.Tasks; namespace CommonAI.ZoneServer.JSGModule { class MSpaceNodeCache { public class MSpaceNodeItem { public MSpaceNode[,] data; public void Clone(MSpaceNodeItem cacheItem, MSpaceMap map, SpaceDivision space) { int XCount = data.GetLength(0); int YCount = data.GetLength(1); for (int cx = 0; cx < XCount; cx++) { for (int cy = 0; cy < YCount; cy++) { this.data[cx, cy] = new MSpaceNode(map, space.GetSpaceCellNodeByBlock(cx, cy)); } } for (int cx = 0; cx < space.SpaceXCount; cx++) { for (int cy = 0; cy < space.SpaceYCount; cy++) { this.data[cx, cy].Clone(cacheItem.data[cx, cy]); } } } } private static readonly HashMap mCacheAstar = new HashMap(); /** 获取缓存中的Astart节点数据,如果不想使用缓存sceneID=0 */ public static MSpaceAStar GetCacheAStart(int uniqueID, AstarManhattan map, int space_size) { if (uniqueID <= 0) { return new MSpaceAStar(uniqueID, map, space_size); } else { MSpaceAStar cacheItem = mCacheAstar.Get(uniqueID); if (cacheItem == null) { cacheItem = new MSpaceAStar(uniqueID, map, space_size); mCacheAstar.Put(uniqueID, cacheItem); } return cacheItem; } } } }