/// <summary> /// 释放对象。 /// </summary> /// <param name="target">要释放的对象。</param> /// <returns>释放对象是否成功。</returns> public bool ReleaseObject(object target) { if (target == null) { throw new GameFrameworkException("Target is invalid."); } Object <T> internalObject = GetObject(target); if (internalObject == null) { return(false); } if (internalObject.IsInUse || internalObject.Locked || !internalObject.CustomCanReleaseFlag) { return(false); } m_Objects.Remove(internalObject.Name, internalObject); m_ObjectMap.Remove(internalObject.Peek().Target); internalObject.Release(false); ReferencePool.Release(internalObject); return(true); }
public void UnSubscribe(int id, EventHandler <GameEventArgs> handler) { if (!dicEventHandler.Remove(id, handler)) { throw new Exception(Utility.Text.Format("Event '{0}' not exists specified handler.", id.ToString())); } GameEntry.Event.Unsubscribe(id, handler); }
private void ReleaseObject(T obj) { if (obj == null) { throw new GameFrameworkException("Object is invalid."); } Object <T> internalObject = GetObject(obj.Target); if (internalObject == null) { throw new GameFrameworkException("Can not release object which is not found."); } m_Objects.Remove(obj.Name, internalObject); m_ObjectMap.Remove(obj.Target); internalObject.Release(false); ReferencePool.Release(internalObject); }
/// <summary> /// 解除注册文件系统。 /// </summary> /// <param name="name">要解除注册的文件系统的名称。</param> /// <param name="fileSystem">要解除注册的文件系统。</param> /// <returns>是否解除注册文件系统成功。</returns> public bool UnregisterFileSystem(string name, IFileSystem fileSystem) { if (string.IsNullOrEmpty(name)) { throw new GameFrameworkException("Name is invalid."); } if (fileSystem == null) { throw new GameFrameworkException("File system is invalid."); } FileSystem fileSystemImpl = (FileSystem)fileSystem; if (!fileSystemImpl.RemoveName(name)) { return(false); } return(m_RegisteredFileSystems.Remove(name, fileSystemImpl)); }
private int AllocBlock(int length) { length = (int)GetUpBoundClusterOffset(length); int lengthFound = -1; GameFrameworkLinkedListRange <int> lengthRange = default(GameFrameworkLinkedListRange <int>); foreach (KeyValuePair <int, GameFrameworkLinkedListRange <int> > i in m_FreeBlockIndexes) { if (i.Key < length) { continue; } if (lengthFound >= 0 && lengthFound < i.Key) { continue; } lengthFound = i.Key; lengthRange = i.Value; } if (lengthFound >= 0) { if (lengthFound > length && m_BlockDatas.Count >= m_HeaderData.MaxBlockCount) { return(-1); } LinkedListNode <int> blockIndexNode = lengthRange.First; int blockIndex = blockIndexNode.Value; m_FreeBlockIndexes.Remove(lengthFound, blockIndex); if (lengthFound > length) { BlockData blockData = m_BlockDatas[blockIndex]; m_BlockDatas[blockIndex] = new BlockData(blockData.ClusterIndex, length); WriteBlockData(blockIndex); int deltaLength = lengthFound - length; int anotherBlockIndex = m_BlockDatas.Count; BlockData anotherBlockData = new BlockData(blockData.ClusterIndex + GetUpBoundClusterCount(length), deltaLength); m_BlockDatas.Add(anotherBlockData); m_FreeBlockIndexes.Add(deltaLength, anotherBlockIndex); WriteBlockData(anotherBlockIndex); WriteHeaderData(); } return(blockIndex); } else { if (m_BlockDatas.Count >= m_HeaderData.MaxBlockCount) { return(-1); } long fileLength = m_Stream.Length; try { m_Stream.SetLength(fileLength + length); } catch { return(-1); } int blockIndex = m_BlockDatas.Count; BlockData blockData = new BlockData(GetUpBoundClusterCount(fileLength), length); m_BlockDatas.Add(blockData); WriteBlockData(blockIndex); WriteHeaderData(); return(blockIndex); } }
private bool TryCombineFreeBlocks(int freeBlockIndex) { BlockData freeBlockData = m_BlockDatas[freeBlockIndex]; if (freeBlockData.Length <= 0) { return(false); } int previousFreeBlockIndex = -1; int nextFreeBlockIndex = -1; int nextBlockDataClusterIndex = freeBlockData.ClusterIndex + GetUpBoundClusterCount(freeBlockData.Length); foreach (KeyValuePair <int, GameFrameworkLinkedListRange <int> > blockIndexes in m_FreeBlockIndexes) { if (blockIndexes.Key <= 0) { continue; } int blockDataClusterCount = GetUpBoundClusterCount(blockIndexes.Key); foreach (int blockIndex in blockIndexes.Value) { BlockData blockData = m_BlockDatas[blockIndex]; if (blockData.ClusterIndex + blockDataClusterCount == freeBlockData.ClusterIndex) { previousFreeBlockIndex = blockIndex; } else if (blockData.ClusterIndex == nextBlockDataClusterIndex) { nextFreeBlockIndex = blockIndex; } } } if (previousFreeBlockIndex < 0 && nextFreeBlockIndex < 0) { return(false); } m_FreeBlockIndexes.Remove(freeBlockData.Length, freeBlockIndex); if (previousFreeBlockIndex >= 0) { BlockData previousFreeBlockData = m_BlockDatas[previousFreeBlockIndex]; m_FreeBlockIndexes.Remove(previousFreeBlockData.Length, previousFreeBlockIndex); freeBlockData = new BlockData(previousFreeBlockData.ClusterIndex, previousFreeBlockData.Length + freeBlockData.Length); m_BlockDatas[previousFreeBlockIndex] = BlockData.Empty; m_FreeBlockIndexes.Add(0, previousFreeBlockIndex); WriteBlockData(previousFreeBlockIndex); } if (nextFreeBlockIndex >= 0) { BlockData nextFreeBlockData = m_BlockDatas[nextFreeBlockIndex]; m_FreeBlockIndexes.Remove(nextFreeBlockData.Length, nextFreeBlockIndex); freeBlockData = new BlockData(freeBlockData.ClusterIndex, freeBlockData.Length + nextFreeBlockData.Length); m_BlockDatas[nextFreeBlockIndex] = BlockData.Empty; m_FreeBlockIndexes.Add(0, nextFreeBlockIndex); WriteBlockData(nextFreeBlockIndex); } m_BlockDatas[freeBlockIndex] = freeBlockData; m_FreeBlockIndexes.Add(freeBlockData.Length, freeBlockIndex); WriteBlockData(freeBlockIndex); return(true); }