示例#1
0
        /// <summary> Constructor. </summary>
        /// <param name="position"> The position of the given chunk. </param>
        /// <param name="storage"> The storage location of entities belonging to this chunk. </param>
        public Chunk(ChunkCoordinate position, AspectStorageContainer storage)
        {
            Storage  = storage;
            Position = position;
            _items   = new GridItem[NumberOfGridItemsWide * NumberOfGridItemsHigh];

            AbsoluteIndex = Position.GetAbsoluteIndex();
        }
        /// <summary> Constructor. </summary>
        /// <param name="engine"> The EntityComponentEngine for the current game. </param>
        public WorldGrid(AspectStorageContainer worldStorage)
        {
            WorldStorage = worldStorage;
            WorldStorage.AddHook(this);

            _chunks = new Chunk[NumberOfChunksHigh * NumberOfChunksWide];

            InitializeChunks(WorldStorage);
        }
        /// <summary> Creates and initializes each chunk with data. </summary>
        /// <param name="worldStorage"> The container that stores the data for each chunk. </param>
        private void InitializeChunks(AspectStorageContainer worldStorage)
        {
            for (int y = 0; y < NumberOfChunksHigh; y++)
            {
                for (int x = 0; x < NumberOfChunksWide; x++)
                {
                    var chunk = new Chunk(new ChunkCoordinate(x, y), worldStorage);

                    // TODO UNITY
                    // load this data from elsewhere
                    ChunkInitializer.InitializeChunk(chunk, new PerlinNoiseProvider());
                    _chunks[CalculateIndex(x, y)] = chunk;
                }
            }
        }