Ejemplo n.º 1
0
 public BlockStorage()
 {
     m_arrStorage   = new BlockStorageArray();
     m_rleStorage   = new BlockStorageRLE();
     m_currStorage  = m_arrStorage;
     m_isCompressed = false;
 }
Ejemplo n.º 2
0
 public override void Initialize()
 {
     this._player = (IPlayer) this.Game.Services.GetService(typeof (IPlayer));
     this._world = (IWorld) this.Game.Services.GetService(typeof (IWorld));
     this._chunkCache = (IChunkCache) this.Game.Services.GetService(typeof (IChunkCache));
     this._blockStorage = (IBlockStorage) this.Game.Services.GetService(typeof (IBlockStorage));
 }
Ejemplo n.º 3
0
 public override void Initialize()
 {
     this._player       = (IPlayer)this.Game.Services.GetService(typeof(IPlayer));
     this._world        = (IWorld)this.Game.Services.GetService(typeof(IWorld));
     this._chunkCache   = (IChunkCache)this.Game.Services.GetService(typeof(IChunkCache));
     this._blockStorage = (IBlockStorage)this.Game.Services.GetService(typeof(IBlockStorage));
 }
 /// <summary>
 /// Generate the given set of blockdata at the given location offset
 /// </summary>
 /// <param name="location">The xyz to use as an offset for generating these blocks</param>
 /// <param name="blockData">The block data to populate</param>
 public void generateAllAt(Coordinate location, IBlockStorage blockData)
 {
     isoSurfaceLevel = getIsoSurfaceLevel();
     Coordinate.Zero.until(blockData.bounds, (coordinate) => {
         Coordinate globalLocation    = coordinate + (location * blockData.bounds);
         float isoSurfaceDensityValue = getNoiseValueAt(globalLocation);
         blockData.updateBlock(coordinate, getBlockTypeFor(isoSurfaceDensityValue), isoSurfaceDensityValue);
     });
 }
Ejemplo n.º 5
0
        public RecordStorage(IBlockStorage storage)
        {
            _storage = storage ?? throw new ArgumentNullException("storage");

            if (storage.BlockHeaderSize < 48)
            {
                throw new ArgumentException("Record storage needs at least 48 header bytes");
            }
        }
Ejemplo n.º 6
0
		//
		// Constructors
		//

		public RecordStorage (IBlockStorage storage)
		{
			if (storage == null)
				throw new ArgumentNullException ("storage");

			this.storage = storage;

			if (storage.BlockHeaderSize < 48) {
				throw new ArgumentException ("Record storage needs at least 48 header bytes");
			}
		}
        // Deserialize constructor
        public BlockCollection(IBlockStorage <T> storage, BinaryReader reader)
        {
            _storage = storage;

            for (int i = 0; i < _blocksWithDepths.Length; ++i)
            {
                int count = _blocksWithDepths[i] = reader.ReadInt32();
                if (count < 0 || count > storage.Count)
                {
                    throw new IOException();
                }
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Generate the given set of blockdata at the given location offset
 /// </summary>
 /// <param name="location">The xyz to use as an offset for generating these blocks</param>
 /// <param name="blockData">The block data to populate</param>
 public void generateAllAt(Coordinate location, IBlockStorage blockData)
 {
     isoSurfaceLevel = getIsoSurfaceLevel();
     Coordinate.Zero.until(blockData.bounds, (coordinate) => {
         BlocksGenerated++;
         Coordinate globalLocation    = coordinate + (location * blockData.bounds);
         float isoSurfaceDensityValue = getNoiseValueAt(globalLocation);
         Block.Type newBlockType      = getBlockTypeFor(isoSurfaceDensityValue);
         if (newBlockType != Block.Types.Air)
         {
             blockData.setBlock(coordinate, newBlockType);
         }
     });
 }
        public ExtendibleHashSet(string dataFilePath, IBlockSerializer <T> valueSerializer, int maxBlockValues,
                                 int maxSiblingMergeBlockValues, int maxTableDepth, int maxUnusedTableDepth)
        {
            if (maxBlockValues <= 0 ||
                maxSiblingMergeBlockValues < 0 ||
                maxTableDepth <= 0 ||
                maxUnusedTableDepth < 0)
            {
                throw new InvalidOperationException();
            }

            if (maxSiblingMergeBlockValues > maxBlockValues)
            {
                throw new InvalidOperationException();
            }
            // Create index stream now just to lock file.
            _indexFileStream = new FileStream
                               (
                dataFilePath + IndexFilePostfix,
                FileMode.Create,
                FileAccess.ReadWrite,
                FileShare.None
                               );

            _blockFileStream = new FileStream
                               (
                dataFilePath + BlockFilePostfix,
                FileMode.Create,
                FileAccess.ReadWrite,
                FileShare.None
                               );

            _blockStorage = new StreamBlockStorage <T>(
                _blockFileStream,
                valueSerializer,
                UpdateIndices,
                blocksCount: 0,
                maxBlockValues: maxBlockValues);

            _tableContext = new TableData <T>
                            (
                new BlockCollection <T>(_blockStorage),
                maxBlockValues: maxBlockValues,
                maxSiblingMergeBlockValues: maxSiblingMergeBlockValues,
                maxDepth: maxTableDepth,
                maxUnusedDepth: maxUnusedTableDepth
                            );
        }
Ejemplo n.º 10
0
        public void Dispose()
        {
            if (!isDisposed && isOpened)
            {
                Flush();
            }

            isDisposed = true;

            DirectoryCache?.Dispose();
            storage.Dispose();

            DirectoryCache    = null;
            allocationManager = null;
            storage           = null;
        }
Ejemplo n.º 11
0
        public RecordStorage(IBlockStorage blockStorage)
        {
            if (blockStorage == null)
            {
                throw new ArgumentNullException("blockStorage");
            }
            if (blockStorage.BlockHeaderSize < BlockFields.TotalHeaderSize)
            {
                throw new ArgumentException(string.Format(
                                                "RecordStorage requires at least {0} bytes for header size.",
                                                BlockFields.TotalHeaderSize
                                                ));
            }

            this.blockStorage = blockStorage;
        }
Ejemplo n.º 12
0
        public Block(IBlockStorage storage, uint id, byte[] firstSector, Stream stream)
        {
            if (firstSector == null)
            {
                throw new ArgumentNullException(nameof(firstSector));
            }

            if (firstSector.Length != storage.DiskSectorSize)
            {
                throw new ArgumentException("firstSector length must be " + storage.DiskSectorSize);
            }

            _storage     = storage;
            Id           = id;
            _stream      = stream ?? throw new ArgumentNullException(nameof(stream));
            _firstSector = firstSector;
        }
Ejemplo n.º 13
0
        private void InitializeFromHeader(IBlockStorage blockStorage, FSHeader header)
        {
            var allocationIndexFactory = new GenericFactory <IIndex <int>, IAllocationManager>(
                m =>
            {
                var accessParameters        = new CommonAccessParameters(blockStorage, m);
                var allocationIndexProvider =
                    indexBlockProviderFactory.Create(header.AllocationBlock, accessParameters);
                return(indexFactory.Create(allocationIndexProvider, accessParameters));
            });

            allocationManager = allocationManagerFactory.Create(allocationIndexFactory, blockStorage, header.FreeBlockCount);

            var dictionaryCache = directoryCacheFactory.Create(new CommonAccessParameters(blockStorage, allocationManager));
            var rootDirectory   = dictionaryCache.ReadDirectory(header.RootDirectoryBlock);

            RootDirectory  = rootDirectory;
            DirectoryCache = dictionaryCache;
        }
Ejemplo n.º 14
0
        public Blockchain(Wallet miningWallet, IWalletManager walletManager, IHashFactory transactionHashFactory, ISignatureFactory signatureFactory, IMiningFactory miningFactory, IBlockStorage storage)
        {
            SignatureFactory = signatureFactory;
            Verifier         = signatureFactory.GetSignatureVerifier();

            MiningFactory = miningFactory;

            TransactionHashFactory = transactionHashFactory;
            Digest = TransactionHashFactory.GetDigest();

            MiningWallet  = miningWallet;
            WalletManager = walletManager;

            pendingTransactions = new LinkedList <Transaction>();
            storedChain         = storage;

            foreach (Block block in storedChain)
            {
                WalletManager.AcceptTransactions(block.Transactions);
            }
        }
Ejemplo n.º 15
0
        public override void Initialize()
        {
            Logger.Trace("init()");

            this.FlyingEnabled = true;
            this.Weapon        = new Shovel(Game);

            // import required services.
            this._camera       = (ICamera)this.Game.Services.GetService(typeof(ICamera));
            this._chunkCache   = (IChunkCache)this.Game.Services.GetService(typeof(IChunkCache));
            this._blockStorage = (IBlockStorage)this.Game.Services.GetService(typeof(IBlockStorage));

            this._assetManager = (IAssetManager)this.Game.Services.GetService(typeof(IAssetManager));
            if (this._assetManager == null)
            {
                throw new NullReferenceException("Can not find asset manager component.");
            }

            this.LoadContent();

            this.Weapon.Initialize();
        }
Ejemplo n.º 16
0
        public CoreStorage(IStorageManager storageManager, Logger logger)
        {
            for (var i = 0; i < this.presentBlockTxesLocks.Length; i++)
            {
                presentBlockTxesLocks[i] = new object();
            }

            this.logger           = logger;
            this.storageManager   = storageManager;
            this.blockStorage     = storageManager.BlockStorage;
            this.blockTxesStorage = storageManager.BlockTxesStorage;

            this.cachedHeaders = new ConcurrentDictionary <UInt256, ChainedHeader>();

            this.missingHeaders   = new ConcurrentSetBuilder <UInt256>();
            this.missingBlockTxes = new ConcurrentSetBuilder <UInt256>();

            foreach (var chainedHeader in this.blockStorage.ReadChainedHeaders())
            {
                this.cachedHeaders[chainedHeader.Hash] = chainedHeader;
            }
        }
Ejemplo n.º 17
0
        public AllocationManager(
            IFactory <IIndex <int>, IAllocationManager> indexFactory,
            IFactory <IBlockStream <int>, IBlockProvider <int> > blockStreamFactory,
            IBlockStorage storage,
            int freeSpaceBlocksCount)
        {
            if (indexFactory == null)
            {
                throw new ArgumentNullException(nameof(indexFactory));
            }

            if (blockStreamFactory == null)
            {
                throw new ArgumentNullException(nameof(blockStreamFactory));
            }

            this.storage = storage ?? throw new ArgumentNullException(nameof(storage));

            index              = indexFactory.Create(this);
            blockStream        = blockStreamFactory.Create(index);
            ReleasedBlockCount = freeSpaceBlocksCount;
        }
Ejemplo n.º 18
0
        public void Open(string fileName, OpenMode openMode)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            if (isOpened)
            {
                throw new InvalidOperationException("File system is already opened");
            }

            storage = blockStorageFactory.Create(fileName);
            storage.Open(openMode);

            try
            {
                FSHeader header;
                if (openMode == OpenMode.Create)
                {
                    header = CreateFile();
                }
                else
                {
                    var headers = new FSHeader[1];
                    storage.ReadBlock(0, headers);
                    header = headers[0];
                }

                InitializeFromHeader(storage, header);
            }
            catch
            {
                storage.Dispose();
            }

            isOpened = true;
        }
Ejemplo n.º 19
0
 public EmptyBlock(IBlockStorage storage, BlockPos pos)
 {
     this.storage = storage;
     this.position = pos;
 }
 public PutBlockRequestHandler(IBlockStorage blockStorage)
 {
     _blockStorage = blockStorage;
 }
Ejemplo n.º 21
0
 public CommonAccessParameters(IBlockStorage storage, IAllocationManager allocationManager)
 {
     Storage           = storage ?? throw new ArgumentNullException(nameof(storage));
     AllocationManager = allocationManager ?? throw new ArgumentNullException(nameof(allocationManager));
 }
        /// <summary>
        /// Nacitanie dat o tabulkach a indexe zo suborov
        /// Deserializacny konstruktor
        /// </summary>
        /// <param name="dataFilePath"></param>
        /// <param name="valueSerializer"></param>
        public ExtendibleHashSet(
            string dataFilePath,
            IBlockSerializer <T> valueSerializer)
        {
            _indexFileStream = new FileStream
                               (
                dataFilePath + IndexFilePostfix,
                FileMode.Open,
                FileAccess.ReadWrite,
                FileShare.None
                               );

            _blockFileStream = new FileStream
                               (
                dataFilePath + BlockFilePostfix,
                FileMode.Open,
                FileAccess.ReadWrite,
                FileShare.None
                               );

            var indexReader = new BinaryReader(_indexFileStream);

            // Table context

            int maxBucketValues             = indexReader.ReadInt32();
            int maxSiblingMergeBucketValues = indexReader.ReadInt32();
            int maxTableDepth       = indexReader.ReadInt32();
            int maxUnusedTableDepth = indexReader.ReadInt32();

            if (maxBucketValues <= 0 ||
                maxSiblingMergeBucketValues < 0 ||
                maxTableDepth <= 0 ||
                maxUnusedTableDepth < 0)
            {
                throw new IOException();
            }

            if (maxSiblingMergeBucketValues > maxBucketValues)
            {
                throw new IOException();
            }

            // Block storage info

            int blocksCount = indexReader.ReadInt32();

            if (blocksCount < 0)
            {
                throw new IOException();
            }

            _blockStorage = new StreamBlockStorage <T>(
                _blockFileStream,
                valueSerializer,
                UpdateIndices,
                blocksCount: blocksCount,
                maxBlockValues: maxBucketValues);

            // Block collection

            var blockCollection = new BlockCollection <T>(_blockStorage, indexReader);

            // Tables

            _tableContext = new TableData <T>
                            (
                blockCollection,
                maxBlockValues: maxBucketValues,
                maxSiblingMergeBlockValues: maxSiblingMergeBucketValues,
                maxDepth: maxTableDepth,
                maxUnusedDepth: maxUnusedTableDepth
                            );

            int tablesCount = indexReader.ReadInt32();

            if (tablesCount < 0)
            {
                throw new IOException();
            }

            if (tablesCount == 0 ? blocksCount > 0 : blocksCount == 0)
            {
                throw new IOException();
            }

            for (int i = 0; i < tablesCount; ++i)
            {
                _tables.Add(new Table <T>(indexReader, _tableContext, blocksCount));
            }
        }
Ejemplo n.º 23
0
 public override void Initialize()
 {
     // import required services.
     this._chunkCache   = (IChunkCache)this.Game.Services.GetService(typeof(IChunkCache));
     this._blockStorage = (IBlockStorage)this.Game.Services.GetService(typeof(IBlockStorage));
 }
Ejemplo n.º 24
0
 public BlockCollection(IBlockStorage <T> storage)
 {
     _storage = storage;
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Generate all the blocks in the given collection with this source
 /// </summary>
 /// <param name="blockData"></param>
 public void generateAll(IBlockStorage blockData)
 {
     generateAllAt(Coordinate.Zero, blockData);
 }
Ejemplo n.º 26
0
 public RecordStorage(IBlockStorage blockStorage)
 {
     _blockStorage = blockStorage ?? throw new ArgumentNullException(nameof(blockStorage));
 }
Ejemplo n.º 27
0
 public override void Initialize()
 {
     // import required services.
     this._chunkCache = (IChunkCache) this.Game.Services.GetService(typeof (IChunkCache));
     this._blockStorage = (IBlockStorage)this.Game.Services.GetService(typeof(IBlockStorage));
 }
Ejemplo n.º 28
0
 public BlockStream(IBlockStorage storage, StorageDirection storageDirection)
 {
     this.storage          = storage;
     this.storageDirection = storageDirection;
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Make a chunk out of block data
 /// </summary>
 /// <param name="blocks">the block data of this chunk</param>
 /// <param name="neighbors">the other chunks to link to</param>
 public Chunk(IBlockStorage blocks, IBlockChunk[] neighbors = null)
 {
     this.blocks    = blocks;
     this.neighbors = neighbors;
 }
Ejemplo n.º 30
0
 public ChunkSection(IBlockPalette globalPalette)
 {
     BlockStorage = new BlockStorage(globalPalette);
 }
Ejemplo n.º 31
0
        public override void Initialize()
        {
            Logger.Trace("init()");

            this.FlyingEnabled = true;
            this.Weapon = new Shovel(Game);

            // import required services.
            this._camera = (ICamera) this.Game.Services.GetService(typeof (ICamera));
            this._chunkCache = (IChunkCache) this.Game.Services.GetService(typeof (IChunkCache));
            this._blockStorage = (IBlockStorage) this.Game.Services.GetService(typeof (IBlockStorage));

            this._assetManager = (IAssetManager)this.Game.Services.GetService(typeof(IAssetManager));
            if (this._assetManager == null)
                throw new NullReferenceException("Can not find asset manager component.");

            this.LoadContent();

            this.Weapon.Initialize();
        }