public AgentCell AcquireViewportCell() { if (this._viewportCell == null) { this._viewportCell = this.CreateViewportCell(); } return(this._viewportCell); }
public static void Update(PhysicalAgent agent) { if (!Map.m_Locked) { AgentCell agentCell = agent.AcquireViewportCell(); agentCell.Update(); ArrayList owner = agentCell.Owner; ArrayList arrayList = agent.InWorld ? Map.GetList(agent.X, agent.Y) : (ArrayList)null; if (arrayList != owner) { if (owner != null) { owner.Remove((object)agentCell); } if (arrayList != null) { int index = arrayList.BinarySearch((object)agentCell, TileSorter.Comparer); if (index < 0) { index = ~index; } arrayList.Insert(index, (object)agentCell); } agentCell.Owner = arrayList; } else { if (arrayList == null) { return; } arrayList.Sort(TileSorter.Comparer); } } else { Map.m_LockQueue.Enqueue((object)new UpdateAgentLock(agent)); } }
public static MapPackage GetMap(int X, int Y, int W, int H) { if (Map.m_X == X && Map.m_Y == Y && (Map.m_Width == W && Map.m_Height == H) && (Map.m_World == Engine.m_World && Map.m_IsCached && !Map.m_QueueInvalidate)) { return(Map.m_Cached); } Map.m_QueueInvalidate = false; if (Map.m_Cached.cells != null) { int length1 = Map.m_Cached.cells.GetLength(0); int length2 = Map.m_Cached.cells.GetLength(1); for (int index1 = 0; index1 < length1; ++index1) { for (int index2 = 0; index2 < length2; ++index2) { ArrayList arrayList = Map.m_Cached.cells[index1, index2]; if (arrayList != null) { int count = arrayList.Count; for (int index3 = 0; index3 < count; ++index3) { ((IDisposable)arrayList[index3]).Dispose(); } } } } } Map.m_X = X; Map.m_Y = Y; Map.m_Width = W; Map.m_Height = H; Map.m_World = Engine.m_World; if (Map.m_StrongReferences == null) { Map.m_StrongReferences = new MapBlock[W * H]; } int length3 = W << 3; int length4 = H << 3; if (Map.m_CellPool == null) { Map.m_CellPool = new ArrayList[length3, length4]; for (int index1 = 0; index1 < length3; ++index1) { for (int index2 = 0; index2 < length4; ++index2) { Map.m_CellPool[index1, index2] = new ArrayList(4); } } } else { for (int index1 = 0; index1 < length3; ++index1) { for (int index2 = 0; index2 < length4; ++index2) { ArrayList arrayList = Map.m_CellPool[index1, index2]; for (int index3 = 0; index3 < arrayList.Count; ++index3) { AgentCell agentCell = arrayList[index3] as AgentCell; if (agentCell != null) { agentCell.Owner = (ArrayList)null; } } arrayList.Clear(); } } } if (Map.m_LandTiles == null) { Map.m_LandTiles = new LandTile[length3, length4]; for (int index1 = 0; index1 < length3; ++index1) { for (int index2 = 0; index2 < length4; ++index2) { Map.m_LandTiles[index1, index2] = new LandTile(); Map.m_LandTiles[index1, index2].x = index1; Map.m_LandTiles[index1, index2].y = index2; } } } if (Map.m_IndexPool == null) { Map.m_IndexPool = new byte[length3, length4]; } if (Map.m_FlagPool == null) { Map.m_FlagPool = new byte[length3, length4]; } ArrayList[,] arrayListArray = Map.m_CellPool; IComparer comparer = TileSorter.Comparer; Engine.Multis.Update(new MapPackage() { cells = arrayListArray, CellX = X << 3, CellY = Y << 3 }); int num1 = Engine.m_World; TileMatrix matrix = Map.GetMatrix(num1); Viewport viewport = World.Viewport; int num2 = 0; int x1 = X; while (num2 < W) { int num3 = 0; int y1 = Y; while (num3 < H) { MapBlock block = matrix.GetBlock(x1, y1); Map.m_StrongReferences[num3 * W + num2] = block; HuedTile[][][] huedTileArray1 = block == null ? matrix.EmptyStaticBlock : block.m_StaticTiles; if (block != null) { Tile[] tileArray = block.m_LandTiles; } else { Tile[] invalidLandBlock = matrix.InvalidLandBlock; } int index1 = 0; int x2 = x1 << 3; int index2 = num2 << 3; while (index1 < 8) { int index3 = 0; int y2 = y1 << 3; int index4 = num3 << 3; while (index3 < 8) { HuedTile[] huedTileArray2 = huedTileArray1[index1][index3]; for (int influence = 0; influence < huedTileArray2.Length; ++influence) { arrayListArray[index2, index4].Add((object)StaticItem.Instantiate(huedTileArray2[influence], influence, x2 * matrix.Height + y2 | influence << 25)); } LandTile landTile = viewport.GetLandTile(x2, y2, num1); landTile.x = index2; landTile.y = index4; arrayListArray[index2, index4].Add((object)landTile); ++index3; ++y2; ++index4; } ++index1; ++x2; ++index2; } ++num3; ++y1; } ++num2; ++x1; } int num4 = X << 3; int num5 = Y << 3; foreach (Item obj in World.Items.Values) { if (obj.InWorld && obj.Visible && !obj.IsMulti) { int index1 = obj.X - num4; int index2 = obj.Y - num5; if (index1 >= 0 && index1 < length3 && (index2 >= 0 && index2 < length4)) { AgentCell agentCell = obj.AcquireViewportCell(); arrayListArray[index1, index2].Add((object)agentCell); agentCell.Owner = arrayListArray[index1, index2]; } } } foreach (Mobile mobile in World.Mobiles.Values) { if (mobile.InWorld && mobile.Visible) { int index1 = mobile.X - num4; int index2 = mobile.Y - num5; if (index1 >= 0 && index1 < length3 && (index2 >= 0 && index2 < length4)) { AgentCell agentCell = mobile.AcquireViewportCell(); arrayListArray[index1, index2].Add((object)agentCell); agentCell.Owner = arrayListArray[index1, index2]; } } } for (int index1 = 0; index1 < length3; ++index1) { for (int index2 = 0; index2 < length4; ++index2) { ArrayList arrayList = arrayListArray[index1, index2]; if (arrayList.Count > 1) { arrayList.Sort(comparer); } } } MapPackage mapPackage = new MapPackage(); mapPackage.cells = arrayListArray; mapPackage.CellX = X << 3; mapPackage.CellY = Y << 3; Map.m_Cached = mapPackage; Map.m_IsCached = true; for (int index = -1; index <= H; ++index) { Engine.QueueMapLoad(X - 1, Y + index, matrix); } for (int index = 0; index < W; ++index) { Engine.QueueMapLoad(X + index, Y - 1, matrix); Engine.QueueMapLoad(X + index, Y + H, matrix); } for (int index = -1; index <= H; ++index) { Engine.QueueMapLoad(X + W, Y + index, matrix); } return(mapPackage); }