Пример #1
0
        /// <summary>
        /// 获取文件系统集合。
        /// </summary>
        /// <param name="name">要获取的文件系统的名称。</param>
        /// <param name="access">要获取的文件系统的访问方式。</param>
        /// <param name="results">获取的文件系统集合。</param>
        public void GetFileSystems(string name, FileSystemAccess access, List <IFileSystem> results)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new GameFrameworkException("Name is invalid.");
            }

            if (results == null)
            {
                throw new GameFrameworkException("Results is invalid.");
            }

            results.Clear();
            GameFrameworkLinkedListRange <FileSystem> range = default(GameFrameworkLinkedListRange <FileSystem>);

            if (m_RegisteredFileSystems.TryGetValue(name, out range))
            {
                foreach (FileSystem fileSystem in range)
                {
                    if (access != FileSystemAccess.Unspecified && (fileSystem.Access & access) != access)
                    {
                        continue;
                    }

                    results.Add(fileSystem);
                }
            }
        }
            /// <summary>
            /// 获取对象。
            /// </summary>
            /// <param name="name">对象名称。</param>
            /// <returns>要获取的对象。</returns>
            public T Spawn(string name)
            {
                GameFrameworkLinkedListRange <Object <T> > objectRange = default(GameFrameworkLinkedListRange <Object <T> >);

                if (m_Objects.TryGetValue(name, out objectRange))
                {
                    foreach (Object <T> internalObject in objectRange)
                    {
                        if (m_AllowMultiSpawn || !internalObject.IsInUse)
                        {
                            return(internalObject.Spawn());
                        }
                    }
                }

                return(null);
            }
Пример #3
0
        private int GetEmptyBlockIndex()
        {
            GameFrameworkLinkedListRange <int> lengthRange = default(GameFrameworkLinkedListRange <int>);

            if (m_FreeBlockIndexes.TryGetValue(0, out lengthRange))
            {
                int blockIndex = lengthRange.First.Value;
                m_FreeBlockIndexes.Remove(0, blockIndex);
                return(blockIndex);
            }

            if (m_BlockDatas.Count < m_HeaderData.MaxBlockCount)
            {
                int blockIndex = m_BlockDatas.Count;
                m_BlockDatas.Add(BlockData.Empty);
                WriteHeaderData();
                return(blockIndex);
            }

            return(-1);
        }
Пример #4
0
            /// <summary>
            /// 获取对象。
            /// </summary>
            /// <param name="name">对象名称。</param>
            /// <returns>要获取的对象。</returns>
            public T Spawn(string name)
            {
                if (name == null)
                {
                    throw new GameFrameworkException("Name is invalid.");
                }

                GameFrameworkLinkedListRange <Object <T> > objectRange = default(GameFrameworkLinkedListRange <Object <T> >);

                if (m_Objects.TryGetValue(name, out objectRange))
                {
                    foreach (Object <T> internalObject in objectRange)
                    {
                        if (m_AllowMultiSpawn || !internalObject.IsInUse)
                        {
                            return(internalObject.Spawn());
                        }
                    }
                }

                return(null);
            }
Пример #5
0
        /// <summary>
        /// 获取文件系统。
        /// </summary>
        /// <param name="name">要获取的文件系统的名称。</param>
        /// <param name="access">要获取的文件系统的访问方式。</param>
        /// <returns>获取的文件系统。</returns>
        public IFileSystem GetFileSystem(string name, FileSystemAccess access)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new GameFrameworkException("Name is invalid.");
            }

            GameFrameworkLinkedListRange <FileSystem> range = default(GameFrameworkLinkedListRange <FileSystem>);

            if (m_RegisteredFileSystems.TryGetValue(name, out range))
            {
                foreach (FileSystem fileSystem in range)
                {
                    if (access != FileSystemAccess.Unspecified && (fileSystem.Access & access) != access)
                    {
                        continue;
                    }

                    return(fileSystem);
                }
            }

            return(null);
        }
Пример #6
0
        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);
            }
        }