Пример #1
0
 public void Flush(IChunkStorage <T> chunkStorage)
 {
     if (_chunkStorage != chunkStorage)
     {
         _chunkStorage.CopyTo(chunkStorage);
     }
 }
Пример #2
0
 public void Flush(IChunkStorage <T> chunkStorage)
 {
     using (var writer = chunkStorage.OpenForWrite())
     {
         writer.Write(_array);
         writer.Complete();
     }
 }
Пример #3
0
 public void CopyTo(IChunkStorage <T> chunkStorage)
 {
     if (chunkStorage is ChunkFileStorage <T> chunkFileStorage)
     {
         File.Delete(chunkFileStorage._fileName);
         File.Move(_fileName, chunkFileStorage._fileName);
     }
 }
Пример #4
0
 /// <summary>
 /// ChunkStack constructor
 /// </summary>
 /// <param name="bufferSize">Memory limit for stored data</param>
 /// <param name="sizeCalculator">Calculator for data size calculation</param>
 /// <param name="chunkStorage">External data storage</param>
 public ChunkStack(
     long bufferSize,
     ISizeCalculator <T> sizeCalculator,
     IChunkStorage <T> chunkStorage)
 {
     _bufferSize    = bufferSize;
     _sizeCalcuator = sizeCalculator;
     _chunkStorage  = chunkStorage;
 }
Пример #5
0
        /// <summary>
        /// Initializes a new <see cref="Map"/> using the specified
        /// <see cref="IChunkStorage"/> to load and save chunks.
        /// </summary>
        /// <param name="storage">The chunk storage</param>
        public Map(IChunkStorage storage)
        {
            ChunkLoader = new ChunkLoader(storage);
            ChunkLoader.Chunks.ItemAdded += OnChunkLoaded;
            ChunkLoader.Chunks.ItemRemoved += OnChunkUnloaded;

            _eventSource = new Subject<IGameEvent>();

            // TODO: LoadMetadataAsync() should be treated like async!
            Metadata = storage.LoadMetadataAsync().Result;
        }
Пример #6
0
            public FileChunkReference(long size, int count, IChunkStorage <T> chunkStorage, bool chunkWriter = false)
            {
                _chunkStorage = chunkStorage;
                TotalSize     = size;
                Count         = count;

                if (chunkWriter)
                {
                    _chunkStorageWriter = chunkStorage.OpenForWrite();
                }
            }
Пример #7
0
        /// <summary>
        /// Initializes the statistics service.
        /// </summary>
        public override void Initialize()
        {
            Logger.Trace("init()");

            // import required services.
            this._player       = (IPlayer)this.Game.Services.GetService(typeof(IPlayer));
            this._fogger       = (IFogger)this.Game.Services.GetService(typeof(IFogger));
            this._world        = (IWorld)this.Game.Services.GetService(typeof(IWorld));
            this._chunkStorage = (IChunkStorage)this.Game.Services.GetService(typeof(IChunkStorage));
            this._chunkCache   = (IChunkCache)this.Game.Services.GetService(typeof(IChunkCache));

            base.Initialize();
        }
Пример #8
0
        public override void Initialize()
        {
            Logger.Trace("init()");

            _spriteBatch = new SpriteBatch(Game.GraphicsDevice);
            _spriteFont  = AssetManager.Instance.Verdana;

            // import service.
            this._camera       = (ICamera)this.Game.Services.GetService(typeof(ICamera));
            this._world        = (IWorld)this.Game.Services.GetService(typeof(IWorld));
            this._player       = (IPlayer)this.Game.Services.GetService(typeof(IPlayer));
            this._chunkStorage = (IChunkStorage)this.Game.Services.GetService(typeof(IChunkStorage));
        }
Пример #9
0
        public override void Initialize()
        {
            Logger.Trace("init()");

            // import required services.
            this._chunkStorage = (IChunkStorage)this.Game.Services.GetService(typeof(IChunkStorage));
            this._camera       = (ICamera)this.Game.Services.GetService(typeof(ICamera));
            this._player       = (IPlayer)this.Game.Services.GetService(typeof(IPlayer));
            this._fogger       = (IFogger)this.Game.Services.GetService(typeof(IFogger));
            this.VertexBuilder = (IVertexBuilder)this.Game.Services.GetService(typeof(IVertexBuilder));
            this._timeRuler    = (TimeRuler)this.Game.Services.GetService(typeof(TimeRuler));

            this.Generator = new BiomedTerrain(new RainForest());
            base.Initialize();
        }
Пример #10
0
        public override void Initialize()
        {
            Logger.Trace("init()");

            // import required service.
            this._camera = (ICamera) this.Game.Services.GetService(typeof (ICamera));
            this._world = (IWorld) this.Game.Services.GetService(typeof (IWorld));
            this._player = (IPlayer) this.Game.Services.GetService(typeof (IPlayer));
            this._chunkStorage = (IChunkStorage) this.Game.Services.GetService(typeof (IChunkStorage));
            this._assetManager = (IAssetManager)this.Game.Services.GetService(typeof(IAssetManager));
            
            if (this._assetManager == null)
                throw new NullReferenceException("Can not find asset manager component.");

            _spriteFont = this._assetManager.Verdana;
            _spriteBatch = new SpriteBatch(Game.GraphicsDevice);
        }
Пример #11
0
        /// <summary>
        /// Initializes the debug-bar service.
        /// </summary>
        public override void Initialize()
        {
            Logger.Trace("init()");

            // import required services.
            this._player       = (IPlayer)this.Game.Services.GetService(typeof(IPlayer));
            this._fogger       = (IFogger)this.Game.Services.GetService(typeof(IFogger));
            this._world        = (IWorld)this.Game.Services.GetService(typeof(IWorld));
            this._chunkStorage = (IChunkStorage)this.Game.Services.GetService(typeof(IChunkStorage));
            this._chunkCache   = (IChunkCache)this.Game.Services.GetService(typeof(IChunkCache));
            this._assetManager = (IAssetManager)this.Game.Services.GetService(typeof(IAssetManager));

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

            base.Initialize();
        }
Пример #12
0
        public override void Initialize()
        {
            Logger.Trace("init()");

            // import required services.
            this._chunkStorage = (IChunkStorage) this.Game.Services.GetService(typeof (IChunkStorage));
            this._camera = (ICamera) this.Game.Services.GetService(typeof (ICamera));
            this._player = (IPlayer) this.Game.Services.GetService(typeof (IPlayer));
            this._fogger = (IFogger) this.Game.Services.GetService(typeof (IFogger));
            this.VertexBuilder = (IVertexBuilder) this.Game.Services.GetService(typeof (IVertexBuilder));            
            this._timeRuler = (TimeRuler) this.Game.Services.GetService(typeof (TimeRuler));

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

            this.Generator = new BiomedTerrain(new RainForest());
            base.Initialize();
        }
Пример #13
0
        public override void Initialize()
        {
            Logger.Trace("init()");

            // import required service.
            this._camera       = (ICamera)this.Game.Services.GetService(typeof(ICamera));
            this._world        = (IWorld)this.Game.Services.GetService(typeof(IWorld));
            this._player       = (IPlayer)this.Game.Services.GetService(typeof(IPlayer));
            this._chunkStorage = (IChunkStorage)this.Game.Services.GetService(typeof(IChunkStorage));
            this._assetManager = (IAssetManager)this.Game.Services.GetService(typeof(IAssetManager));

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

            _spriteFont  = this._assetManager.Verdana;
            _spriteBatch = new SpriteBatch(Game.GraphicsDevice);
        }
        public SimpleMapLoader(IMapEditor map, IServer server, IChunkFactory chunkFactory, IPlayer player,
                               IChunkStorage chunkStorage)
        {
            if (map == null)
            {
                throw new ArgumentNullException("map");
            }
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }
            if (chunkFactory == null)
            {
                throw new ArgumentNullException("chunkFactory");
            }
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }

            _map    = map;
            _server = server;
            _server.ClientConnection.ChunkReceived += ClientConnectionOnChunkReceived;
            _chunkFactory            = chunkFactory;
            _player                  = player;
            _chunkStorage            = chunkStorage;
            _chunkStorage.Retrieved += ChunkStorageOnRetrieved;

            _player.Moved += OnPlayerMoved;

            _oldPlayerChunkPosition = Chunk.ToChunkPosition(_player.Position.ToMapPosition());

            foreach (var chunkPos in _map.Bounds)
            {
                if (!_map.IsChunkPresent(chunkPos))
                {
                    _server.ServerConnection.GetChunk(chunkPos);
                }
            }
        }
Пример #15
0
        /// <summary>
        /// Initializes the debug-bar service.
        /// </summary>
        public override void Initialize()
        {
            Logger.Trace("init()");

            // import required services.            
            this._player = (IPlayer)this.Game.Services.GetService(typeof(IPlayer));
            this._fogger = (IFogger)this.Game.Services.GetService(typeof(IFogger));
            this._world = (IWorld)this.Game.Services.GetService(typeof(IWorld));
            this._chunkStorage = (IChunkStorage)this.Game.Services.GetService(typeof(IChunkStorage));
            this._chunkCache = (IChunkCache)this.Game.Services.GetService(typeof(IChunkCache));
            this._assetManager = (IAssetManager)this.Game.Services.GetService(typeof(IAssetManager));

            if (this._assetManager == null)
                throw new NullReferenceException("Can not find asset manager component.");

            base.Initialize();
        }
Пример #16
0
 public ChunkServer(IChunkStorage chunkStorage, ILogger logger = null)
 {
     ChunkStorage = chunkStorage;
     Logger       = logger ?? Log.Default;
 }
Пример #17
0
        public override void Initialize()
        {
            Logger.Trace("init()");

            _spriteBatch = new SpriteBatch(Game.GraphicsDevice);
            _spriteFont = Game.Content.Load<SpriteFont>("Fonts//CalibriDebug");

            // import service.
            this._camera = (ICamera) this.Game.Services.GetService(typeof (ICamera));
            this._world = (IWorld) this.Game.Services.GetService(typeof (IWorld));
            this._player = (IPlayer) this.Game.Services.GetService(typeof (IPlayer));
            this._chunkStorage = (IChunkStorage) this.Game.Services.GetService(typeof (IChunkStorage));
        }
Пример #18
0
        /// <summary>
        /// Initializes the statistics service.
        /// </summary>
        public override void Initialize()
        {
            Logger.Trace("init()");

            // import required services.
            this._player = (IPlayer) this.Game.Services.GetService(typeof (IPlayer));
            this._fogger = (IFogger) this.Game.Services.GetService(typeof (IFogger));
            this._world = (IWorld) this.Game.Services.GetService(typeof (IWorld));
            this._chunkStorage = (IChunkStorage) this.Game.Services.GetService(typeof (IChunkStorage));
            this._chunkCache = (IChunkCache) this.Game.Services.GetService(typeof (IChunkCache));

            base.Initialize();
        }
Пример #19
0
 void ReopenStorage()
 {
     _kvdb.Dispose();
     _kvdb = new KeyValueDB(_fileCollection);
     _cs   = _kvdb.GetSubDB <IChunkStorage>(1);
 }
Пример #20
0
 public ChunkStorageTest()
 {
     _fileCollection = new InMemoryFileCollection();
     _kvdb           = new KeyValueDB(_fileCollection);
     _cs             = _kvdb.GetSubDB <IChunkStorage>(1);
 }
Пример #21
0
 public void CreateChunkStorageSubDB()
 {
     _fileCollection = new InMemoryFileCollection();
     _kvdb = new KeyValueDB(_fileCollection);
     _cs = _kvdb.GetSubDB<IChunkStorage>(1);
 }
Пример #22
0
 void ReopenStorage()
 {
     _kvdb.Dispose();
     _kvdb = new KeyValueDB(_fileCollection);
     _cs = _kvdb.GetSubDB<IChunkStorage>(1);
 }
Пример #23
0
 public void AddStorage(IChunkStorage storage)
 {
     Secondary.Add(storage);
 }
Пример #24
0
 /// <summary>
 /// Initializes a new ChunkLoader utilizing the specified
 /// IChunkStorage to load and save chunks.
 /// </summary>
 /// <param name="storage">Chunk Storage</param>
 /// 
 public ChunkLoader(IChunkStorage storage)
 {
     Storage = storage;
 }
Пример #25
0
 public ChunkProvider(IChunkStorage chunkStorage, IChunkCreator chunkCreator)
 {
     _chunkStorage = chunkStorage;
     _chunkCreator = chunkCreator;
 }
Пример #26
0
        public override void Initialize()
        {
            Logger.Trace("init()");

            // import required services.
            this._chunkStorage = (IChunkStorage) this.Game.Services.GetService(typeof (IChunkStorage));
            this._camera = (ICamera) this.Game.Services.GetService(typeof (ICamera));
            this._player = (IPlayer) this.Game.Services.GetService(typeof (IPlayer));
            this._fogger = (IFogger) this.Game.Services.GetService(typeof (IFogger));
            this.VertexBuilder = (IVertexBuilder) this.Game.Services.GetService(typeof (IVertexBuilder));
            this._timeRuler = (TimeRuler) this.Game.Services.GetService(typeof (TimeRuler));

            this.Generator = new BiomedTerrain(new RainForest());
            base.Initialize();
        }
Пример #27
0
        public override void Initialize()
        {
            Logger.Trace("init()");

            _spriteBatch = new SpriteBatch(Game.GraphicsDevice);
            _spriteFont = AssetManager.Instance.Verdana;

            // import service.
            this._camera = (ICamera) this.Game.Services.GetService(typeof (ICamera));
            this._world = (IWorld) this.Game.Services.GetService(typeof (IWorld));
            this._player = (IPlayer) this.Game.Services.GetService(typeof (IPlayer));
            this._chunkStorage = (IChunkStorage) this.Game.Services.GetService(typeof (IChunkStorage));
        }