コード例 #1
0
        public byte[] GetCurrentState()
        {
            List <byte> bytes = new List <byte>();

            foreach (var file in Files)
            {
                bytes.AddRange(Encoding.UTF8.GetBytes(file.Key.PadRight(100)));
                bytes.Add((byte)((file.Value.Readable ? 1 : 0) + (file.Value.Writeable ? 2 : 0)));
                bytes.AddRange(BitConverter.GetBytes(
                                   (int)((file.Value.Sectors.Count - 1) * _sectorSize + file.Value.Sectors.Last().Size)));
                foreach (var sector in file.Value.Sectors)
                {
                    bytes.AddRange(BitConverter.GetBytes((int)sector.Id));
                }
            }

            bytes.AddRange(new byte[2 * _sectorSize - bytes.Count]);

            for (int i = 2; i < _numberOfSectors; i++)
            {
                if (Sectors.ContainsKey(i))
                {
                    bytes.AddRange(Sectors[i].Bytes);
                }
                else
                {
                    bytes.AddRange(new byte[_sectorSize]);
                }
            }

            return(bytes.ToArray());
        }
コード例 #2
0
        public Sector GetFreeSector()
        {
            for (int i = 2; i < _numberOfSectors; i++)
            {
                if (!Sectors.ContainsKey(i))
                {
                    Sectors[i] = new Sector(new byte[_sectorSize], i);
                    return(Sectors[i]);
                }
            }

            throw new OutOfMemoryException();
        }
コード例 #3
0
        /// <summary>
        /// Creates a new node and adds it to its corresponding sector.
        /// If that sector does not yet exist, it will be created automatically.
        /// </summary>
        /// <param name="position">The position of the node.</param>
        /// <param name="isRed">Whether or not the node is red.</param>
        /// <returns>The new node.</returns>
        public Node AddNode(Vector3 position, bool isRed)
        {
            var sectorIdx = GetSectorOfCoordinate(position);

            if (!Sectors.ContainsKey(sectorIdx))
            {
                AddSector(sectorIdx.X, sectorIdx.Z);
            }

            var node = new Node();

            node.Sectors  = node.Sectors.Push(Sectors[sectorIdx]);
            node.Position = position;
            node.IsRed    = isRed;
            Nodes.Add(node.Uid, node);
            return(node);
        }