/// <summary> ///Clear 的测试 ///</summary> public void ClearTestHelper <KeyT>() { SafeHashSet <KeyT> target = new SafeHashSet <KeyT>(); // TODO: 初始化为适当的值 target.Clear(); Assert.Inconclusive("无法验证不返回值的方法。"); }
public void SafeHashSet清除所有元素_清除成功_SafeHashSet的長度應為0() { var safeHashSet = new SafeHashSet <int> { 0, 1, 2, 3, 4, 5 }; const int expectedCount = 0; safeHashSet.Clear(); safeHashSet.Count.Should().Be(expectedCount); }
/// <inheritdoc /> public void Dispose() { // remove all registered ids from global list if they are in current registry foreach (var id in _localIds) { GlobalIds.Remove(id); } _localIds.Clear(); IsDisposed = true; }
/// <inheritdoc /> protected virtual void Dispose(bool disposing) { if (disposing) { // remove all registered ids from global list if they are in current registry foreach (var id in _localIds) { GlobalIds.Remove(id); } _localIds.Clear(); } }
public void 繞行SafeHashSet操作集合_不同執行緒同時對SafeHashSet操作新增與刪除_不應擲出例外() { var safeHashSet = new SafeHashSet <int> { 1, 2, 3, 4, 5 }; Task.Run(() => { while (true) { safeHashSet.Add(0); } }); Task.Run(() => { while (true) { safeHashSet.Remove(0); } }); Task.Run(() => { while (true) { safeHashSet.Clear(); } }); Task.Run(() => { while (true) { safeHashSet.IntersectWith(Enumerable.Range(0, 3)); } }); Task.Run(() => { while (true) { safeHashSet.UnionWith(Enumerable.Range(0, 3)); } }); Action action = () => IterateCollection(safeHashSet).Wait(); action.Should().NotThrow(); }
/// <inheritdoc /> public void Dispose() { // notify native code. CancelationToken.SetCancelled(true); IsDisposed = true; // remove all registered ids from global list if they are in current registry foreach (var id in _localIds) { GlobalIds.Remove(id); } _localIds.Clear(); if (GameObject != null) { var transform = GameObject.transform; for (int i = transform.childCount - 1; i >= 0; --i) { GameObject.Destroy(transform.GetChild(i).gameObject); } GameObject.Destroy(GameObject); } }
public void Clear() => listeners.Clear();
/// <summary> /// /// </summary> /// <param name="dt"></param> public virtual void OnUpdate(object sender, ProcessSliceEventArgs eventArgs) { if (m_isInWorld == false) { return; } uint uiUpdateCount = 0; MemoryPacket memoryPacket = new MemoryPacket(); // 把自己改变得值广播到附近 this.BroadcastValueUpdate(); // 开始更新道具 // 开始更新 新的游戏道具 if (m_NewItems.Count > 0) { WowItem[] newItemArray = m_NewItems.ToArrayAndClear(); foreach (var newItem in newItemArray) { //item.OnInsert(); newItem.ObjectCreationUpdate(memoryPacket, true); //obj.m_isInWorld = true; } uiUpdateCount += (uint)newItemArray.Length; } // 结束更新 新的游戏道具 // 开始跟新 存在的游戏道具 WowItem[] ownedItemArray = m_OwnedItemsRequiringUpdates.ToArrayAndClear(); foreach (var ownedItem in ownedItemArray) { ownedItem.BroadcastValueUpdate(); } // 结束跟新 存在的游戏道具 // 检测 if ((eventArgs.UpdateTime - m_PreUpdateTime) < ProcessServer.WowZoneCluster.World.UpdateWorldSpeed && uiUpdateCount > 0) { // 仅仅更新道具,就发送数据 然后退出 // 完成更新 this.AddUpdateData(memoryPacket, uiUpdateCount); this.SendUpdates(); return; } // 如果还需要更新人物等。。。 HashSet <WorldEntity> newWorldEntity = new HashSet <WorldEntity>(); // 获取附近的对象 IEnumerable <WorldEntity> nearbyWorldEntity = this.GetAllEntitysInRange(WowCharacter.BROAD_CAST_RANGE); // 排除已存在的对象 newWorldEntity.AddRange(nearbyWorldEntity); newWorldEntity.ExceptWith(m_KnownEntity); newWorldEntity.Remove(this); // 开始更新 新的游戏物体 foreach (WorldEntity entity in newWorldEntity) { WowCharacter wowCharacter = entity as WowCharacter; if (wowCharacter != null) { m_KnownCharacters.Add(wowCharacter); } IWowUpdate wowUpdate = entity.GetComponent <IWowUpdate>(WowUpdate.WOW_UPDATE_COMPONENT_ID); if (wowUpdate != null) { wowUpdate.ObjectCreationUpdate(memoryPacket, false); } //OnEncountered( obj ); } uiUpdateCount += (uint)newWorldEntity.Count; // 结束更新 新的游戏物体 // 获取已不再附近的对象 HashSet <WorldEntity> outOfRangeWorldEntity = new HashSet <WorldEntity>(); // 排除已不存在的对象 outOfRangeWorldEntity.AddRange(m_KnownEntity); outOfRangeWorldEntity.ExceptWith(nearbyWorldEntity); foreach (WorldEntity entity in outOfRangeWorldEntity) { WowCharacter wowCharacter = entity as WowCharacter; if (wowCharacter != null) { m_KnownCharacters.Remove(wowCharacter); } // m_outOfRange.Add(obj.EntityId); //OnOutOfRange( obj ); } // 添加现在已存在附近的游戏物体 m_KnownEntity.Clear(); m_KnownEntity.AddRange(nearbyWorldEntity); // 完成更新 if (uiUpdateCount > 0) { this.AddUpdateData(memoryPacket, uiUpdateCount); this.SendUpdates(); } foreach (var entity in outOfRangeWorldEntity) { // send the destroy packet IWowUpdate wowUpdate = entity.GetComponent <IWowUpdate>(WowUpdate.WOW_UPDATE_COMPONENT_ID); if (wowUpdate != null) { wowUpdate.SendDestroyToPlayer(this); } } m_PreUpdateTime = eventArgs.UpdateTime; }