Ejemplo n.º 1
0
        public void CalculateHeightIndexes()
        {
            for (byte x = 0; x < Chunk.WidthInBlocks; x++)
            {
                var worldPositionX = this.WorldPosition.X + x;

                for (byte z = 0; z < Chunk.LengthInBlocks; z++)
                {
                    int worldPositionZ = this.WorldPosition.Z + z;

                    var offset = BlockStorage.BlockIndexByWorldPosition(worldPositionX, worldPositionZ);
                    for (int y = Chunk.MaxHeightIndexInBlocks; y >= 0; y--)
                    {
                        if ((y > this.HighestSolidBlockOffset) && (BlockStorage.Blocks[offset + y].Exists))
                        {
                            this.HighestSolidBlockOffset = (byte)y;
                        }
                        else if ((this.LowestEmptyBlockOffset > y) && (!BlockStorage.Blocks[offset + y].Exists))
                        {
                            this.LowestEmptyBlockOffset = (byte)y;
                        }
                    }
                }
            }

            this.LowestEmptyBlockOffset--;
        }
Ejemplo n.º 2
0
        public ChunkSection(ChunkColumn owner, bool storeSkylight, int sections = 2)
        {
            Owner = owner;
            if (sections <= 0)
            {
                sections = 1;
            }

            //Data = new BlockStorage();
            _blockStorages = new BlockStorage[sections];
            for (int i = 0; i < sections; i++)
            {
                _blockStorages[i] = new BlockStorage();
            }

            this.BlockLight = new NibbleArray(new byte[2048]);
            MiNET.Worlds.ChunkColumn.Fill <byte>(BlockLight.Data, 0);

            //	if (storeSkylight)
            {
                this.SkyLight = new NibbleArray(new byte[2048]);
                MiNET.Worlds.ChunkColumn.Fill <byte>(SkyLight.Data, 0x00);
            }

            ScheduledUpdates           = new System.Collections.BitArray(new byte[(16 * 16 * 16) / 8]);
            ScheduledSkylightUpdates   = new System.Collections.BitArray(new byte[(16 * 16 * 16) / 8]);
            ScheduledBlocklightUpdates = new System.Collections.BitArray(new byte[(16 * 16 * 16) / 8]);
        }
Ejemplo n.º 3
0
        private void TryMove(Vector3 moveVector)
        {
            // build a test move-vector slightly longer than moveVector.
            Vector3 testVector = moveVector;

            testVector.Normalize();
            testVector *= moveVector.Length() + 0.3f;
            var     footPosition = Position + new Vector3(0f, -0.5f, 0f);
            Vector3 testPosition = footPosition + testVector;

            if (BlockStorage.BlockAt(testPosition).Exists)
            {
                return;
            }

            // There should be some bounding box so his head does not enter a block above ;) /fasbat
            testPosition -= 2 * new Vector3(0f, -0.5f, 0f);
            if (BlockStorage.BlockAt(testPosition).Exists)
            {
                return;
            }


            this.Position += moveVector;
        }
Ejemplo n.º 4
0
        protected virtual void GenerateBlocks(Chunk chunk, int worldPositionX, int worldPositionZ)
        {
            var rockHeight = this.GetRockHeight(worldPositionX, worldPositionZ);
            var dirtHeight = this.GetDirtHeight(worldPositionX, worldPositionZ, rockHeight);

            var offset = BlockStorage.BlockIndexByWorldPosition(worldPositionX, worldPositionZ);

            for (int y = Chunk.MaxHeightIndexInBlocks; y >= 0; y--)
            {
                if (y > dirtHeight) // air
                {
                    BlockStorage.Blocks[offset + y] = new Block(BlockType.None);
                }
                else if (y > rockHeight) // dirt level
                {
                    BlockStorage.Blocks[offset + y] = new Block(BlockType.Dirt);
                }
                else // rock level
                {
                    BlockStorage.Blocks[offset + y] = new Block(BlockType.Rock);
                }
            }

            // apply the biome generator on x-z column.
            this.BiomeGenerator.ApplyBiome(chunk, dirtHeight, offset + dirtHeight, worldPositionX, worldPositionZ);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Clears all lighting and then applies sun-lighting.
        /// </summary>
        /// <param name="chunk"></param>
        private static void SetInitialLighting(Chunk chunk)
        {
            byte sunValue = Chunk.MaxSunValue;

            for (byte x = 0; x < Chunk.WidthInBlocks; x++)
            {
                for (byte z = 0; z < Chunk.LengthInBlocks; z++)
                {
                    int  offset  = BlockStorage.BlockIndexByRelativePosition(chunk, x, z);
                    bool inShade = false; // if we get direct sunlight, inShade will be set to false.

                    for (byte y = Chunk.MaxHeightIndexInBlocks; y > 0; y--)
                    {
                        if (!inShade && BlockStorage.Blocks[offset + y].Type != BlockType.None) // if we're under direct sunlight and just hit a solid block.
                        {
                            inShade = true;                                                     // set inShade to true;
                        }
                        BlockStorage.Blocks[offset + y].Sun = inShade ? (byte)0 : sunValue;
                        BlockStorage.Blocks[offset + y].R   = 0;
                        BlockStorage.Blocks[offset + y].G   = 0;
                        BlockStorage.Blocks[offset + y].B   = 0;
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public void TestBlockStoragePersistent()
        {
            using (var ms = new MemoryStream())
            {
                var storage = new BlockStorage(ms);

                using (var firstBlock = storage.CreateNew())
                    using (var secondBlock = storage.CreateNew())
                        using (var thirdBlock = storage.CreateNew())
                        {
                            Assert.AreEqual(0, firstBlock.Id);
                            Assert.AreEqual(1, secondBlock.Id);

                            secondBlock.SetHeader(1, 100);
                            secondBlock.SetHeader(2, 200);

                            Assert.AreEqual(2, thirdBlock.Id);
                            Assert.AreEqual(storage.BlockSize * 3, ms.Length);
                        }

                // Test to make sure our creation persists
                var storage2 = new BlockStorage(ms);
                Assert.AreEqual(0, storage2.Find(0).Id);
                Assert.AreEqual(1, storage2.Find(1).Id);
                Assert.AreEqual(2, storage2.Find(2).Id);

                Assert.AreEqual(100, storage2.Find(1).GetHeader(1));
                Assert.AreEqual(200, storage2.Find(1).GetHeader(2));
            }
        }
Ejemplo n.º 7
0
        private static void FluidFillSunLight(Chunk chunk)
        {
            for (byte x = 0; x < Chunk.WidthInBlocks; x++)
            {
                for (byte z = 0; z < Chunk.LengthInBlocks; z++)
                {
                    int offset = BlockStorage.BlockIndexByRelativePosition(chunk, x, z);

                    for (byte y = Chunk.MaxHeightIndexInBlocks; y > 0; y--)
                    {
                        var blockIndex = offset + y;

                        if (BlockStorage.Blocks[blockIndex].Type != BlockType.None) // solid blocks can't propagate light.
                        {
                            continue;
                        }

                        var blockLight = BlockStorage.Blocks[blockIndex].Sun;
                        if (blockLight <= 1) // if block's light value is too low (dark),
                        {
                            continue;        // just skip it.
                        }
                        var propagatedLight = (byte)((blockLight * 9) / 10);

                        PropagateSunLight(blockIndex + BlockStorage.XStep, propagatedLight); // propagate light to block in east.
                        PropagateSunLight(blockIndex - BlockStorage.XStep, propagatedLight); // propagate light to block in west.
                        PropagateSunLight(blockIndex + BlockStorage.ZStep, propagatedLight); // propagate light to block in north.
                        PropagateSunLight(blockIndex - BlockStorage.ZStep, propagatedLight); // propagate light to block in south.
                        // DO NOT repropagete to upper block which we don't need to do so and may cause loops!
                        PropagateSunLight(blockIndex - 1, propagatedLight);                  // propagate light to block down.
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public ChunkSection(bool storeSkylight, int sections = 2)
        {
            if (sections <= 0)
            {
                sections = 1;
            }

            //Data = new BlockStorage();
            BlockStorages = new BlockStorage[sections];
            for (int i = 0; i < sections; i++)
            {
                BlockStorages[i] = new BlockStorage();
            }

            this.BlockLight = new NibbleArray(new byte[2048]);

            //	if (storeSkylight)
            {
                this.SkyLight = new NibbleArray(new byte[2048]);
            }

            ResetLight(true, true);

            _scheduledUpdates           = new System.Collections.BitArray(new byte[(16 * 16 * 16) / 8]);
            _scheduledSkylightUpdates   = new System.Collections.BitArray(new byte[(16 * 16 * 16) / 8]);
            _scheduledBlocklightUpdates = new System.Collections.BitArray(new byte[(16 * 16 * 16) / 8]);
        }
Ejemplo n.º 9
0
        public CacheContext(IStorageContext storageContext)
        {
            this._storageContext = storageContext;

            this._blockStorage = new BlockStorage(this);
            this._blockCache = new BlockCache
            (
                cacheContext: this,
                maxFlushMemorySize: 10.MILLION(),
                maxCacheMemorySize: 1.MILLION()
            );

            this._blockHeaderCache = new BlockHeaderCache
            (
                cacheContext: this,
                maxFlushMemorySize: 10.MILLION(),
                maxCacheMemorySize: 1.MILLION()
            );

            this._chainedBlockCache = new ChainedBlockCache
            (
                cacheContext: this,
                maxFlushMemorySize: 1.MILLION(),
                maxCacheMemorySize: 100.MILLION()
            );

            this._transactionCache = new TransactionCache
            (
                cacheContext: this,
                maxCacheMemorySize: 1.MILLION()
            );
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Adds game-components.
        /// </summary>
        private void AddComponents()
        {
            this.Rasterizer = new Rasterizer();

            this.Game.Components.Add(new InputManager(this.Game));

            this.Game.Components.Add(new AssetManager(this.Game));

#if XNA
            //this.Game.Components.Add(new Sky(this.Game));
#endif

            this.Game.Components.Add(new NewSky(this.Game));

            this.Game.Components.Add(new Fogger(this.Game));

            var chunkStorage = new ChunkStorage(this.Game);
            this.Game.Components.Add(chunkStorage);

            var vertexBuilder = new VertexBuilder(this.Game);
            this.Game.Components.Add(vertexBuilder);

            var chunkCache = new ChunkCache(this.Game);
            this.Game.Components.Add(chunkCache);

            var blockStorage = new BlockStorage(this.Game);
            this.Game.Components.Add(blockStorage);

            var world = new World(this.Game, chunkStorage, chunkCache);
            this.Game.Components.Add(world);

            this.Game.Components.Add(new Player(this.Game, world));

            this.Game.Components.Add(new Camera(this.Game));
            this.Game.Components.Add(new UserInterface(this.Game));

            this.Game.Components.Add(new InGameDebugger(this.Game));
            this.Game.Components.Add(new DebugBar(this.Game));
            this.Game.Components.Add(new GraphManager(this.Game));

#if XNA
            this.Game.Components.Add(new AudioManager(this.Game));
#endif

            var spriteBatch = new SpriteBatch(this.Game.GraphicsDevice);
            Console = new GameConsole(this.Game, spriteBatch, new GameConsoleOptions
            {
                Font                   = Game.Content.Load <SpriteFont>(@"Fonts/Verdana"),
                FontColor              = Color.LawnGreen,
                Prompt                 = ">",
                PromptColor            = Color.Crimson,
                CursorColor            = Color.OrangeRed,
                BackgroundColor        = Color.Black * 0.8f,
                PastCommandOutputColor = Color.Aqua,
                BufferColor            = Color.Gold
            });
        }
Ejemplo n.º 11
0
        public int getBlock(int x, int y, int z)
        {
            if (y < 0 || y > 255)
            {
                return(0);
            }
            BlockStorage var4 = this.storageArrays[y >> 4];

            return(var4 != null?var4.getExtBlockID(x, y& 15, z) : 0);
        }
Ejemplo n.º 12
0
        public void BlockStorageTests()
        {
            BlockStorage blockStorage = new BlockStorage(5);

            blockStorage.SetBlock(2, 1);
            blockStorage.SetBlock(4, 4);

            Assert.AreEqual(1, blockStorage.GetBlock(2));
            Assert.AreEqual(4, blockStorage.GetBlock(4));
        }
Ejemplo n.º 13
0
 public int getBlockMetadata(int x, int y, int z)
 {
     if (y >> 4 >= this.storageArrays.Length)
     {
         return(0);
     }
     else
     {
         BlockStorage var4 = this.storageArrays[y >> 4];
         return(var4 != null?var4.getExtBlockMetadata(x, y& 15, z) : 0);
     }
 }
Ejemplo n.º 14
0
        public void TestManangingBlockInstances()
        {
            var manager = new BlockStorage(new MemoryStream());
            var a       = manager.CreateNew();
            var b       = manager.CreateNew();

            Assert.AreSame(a, manager.Find(0));
            Assert.AreSame(b, manager.Find(1));
            Assert.AreNotSame(a, b);

            a.Dispose();
            Assert.AreNotSame(a, manager.Find(0));
        }
Ejemplo n.º 15
0
        public ContentStorage(string basePath, BufferPool bufferPool)
        {
            var settingsPath = Path.Combine(basePath, "Settings");
            var childrenPath = Path.Combine(basePath, "Children");

            _bufferPool             = bufferPool;
            _blockStorage           = new BlockStorage(Path.Combine(childrenPath, nameof(ContentStorage)), _bufferPool);
            _contentMetadataStorage = new ContentMetadataStorage();

            _settings = new SettingsDatabase(settingsPath);

            _checkEventScheduler = new EventScheduler(this.CheckThread);
        }
Ejemplo n.º 16
0
        public Chunk() :
            base(6)
        {
            Blocks = new BlockStorage();

            m_threadID = Globals.WorkPool.GetThreadIDFromIndex(s_id++);
            Pools      = Globals.WorkPool.GetPool(m_threadID);

            m_drawCallBatcher       = new DrawCallBatcher(Globals.CubeMeshBuilder, this);
            BBoxVertices            = new List <Vector3>();
            BBoxVerticesTransformed = new List <Vector3>();

            Reset();
        }
Ejemplo n.º 17
0
        protected Council(Node.Node node, ChainType chainType, int chainId, uint chainIndex, short keyIndex, Key key)
        {
            ChainType  = chainType;
            ChainId    = chainId;
            ChainIndex = chainIndex;

            RequiresChainVoteKeyFlags = Block.GetRequiredChainVoteKeyFlags(ChainType);
            RequiresChainKeyFlags     = Block.GetRequiredChainKeyFlags(ChainType);
            LocalKeyIndex             = keyIndex;
            _localKey = key;

            _node         = node;
            _coreChain    = node.ChainManager.CoreChain;
            _blockStorage = node.ChainManager.GetChain(ChainType, ChainId, chainIndex).BlockStorage;
        }
Ejemplo n.º 18
0
        public Chunk()
        {
            Blocks = new BlockStorage();

            // Associate Chunk with a certain thread and make use of its memory pool
            // This is necessary in order to have lock-free caches
            ThreadID = Globals.WorkPool.GetThreadIDFromIndex(s_id++);
            Pools    = Globals.WorkPool.GetPool(ThreadID);

            RenderGeometryBatcher   = new RenderGeometryBatcher(Globals.CubeMeshGeometryBuilder, this);
            BBoxVertices            = new List <Vector3>();
            BBoxVerticesTransformed = new List <Vector3>();

            StateManager = new ChunkStateManagerClient(this);
        }
Ejemplo n.º 19
0
        public void Jump()
        {
            var   footPosition  = Position + new Vector3(0f, -1.5f, 0f);
            Block standingBlock = BlockStorage.BlockAt(footPosition);

            if (!standingBlock.Exists && this.Velocity.Y != 0)
            {
                return;
            }
            float amountBelowSurface = ((ushort)footPosition.Y) + 1 - footPosition.Y;

            Position += new Vector3(0, amountBelowSurface + 0.01f, 0);

            this.Velocity.Y = JumpVelocity;
        }
Ejemplo n.º 20
0
        public void TestBlockGetSetHeader()
        {
            using (var ms = new MemoryStream())
            {
                var storage    = new BlockStorage(new MemoryStream());
                var blockStart = storage.BlockSize * 22;

                ms.Write(new byte[blockStart], 0, blockStart);

                ms.Write(LittleEndianByteOrder.GetBytes(11L), 0, 8);
                ms.Write(LittleEndianByteOrder.GetBytes(22L), 0, 8);
                ms.Write(LittleEndianByteOrder.GetBytes(33L), 0, 8);
                ms.Write(LittleEndianByteOrder.GetBytes(44L), 0, 8);

                var firstSector = new byte[storage.DiskSectorSize];
                ms.Position = ms.Position - 4 * 8;
                ms.Read(firstSector);
                using (var block = new Block(storage, 22, firstSector, ms))
                {
                    block.GetHeader(0);

                    Assert.AreEqual(11L, block.GetHeader(0));
                    Assert.AreEqual(22L, block.GetHeader(1));
                    Assert.AreEqual(33L, block.GetHeader(2));
                    Assert.AreEqual(44L, block.GetHeader(3));

                    // Change header
                    block.SetHeader(1, 33L);

                    // Changed in memory
                    Assert.AreEqual(33L, block.GetHeader(1));

                    // Should not be changed in actual stream
                    var buffer = new byte[8];
                    ms.Position = blockStart + 8;
                    ms.Read(buffer, 0, 8);
                    Assert.AreEqual(22L, LittleEndianByteOrder.GetInt64(buffer));
                }

                // Until we flush
                {
                    var buffer = new byte[8];
                    ms.Position = blockStart + 8;
                    ms.Read(buffer, 0, 8);
                    Assert.AreEqual(33L, LittleEndianByteOrder.GetInt64(buffer));
                }
            }
        }
Ejemplo n.º 21
0
        private void ProcessPosition(GameTime gameTime)
        {
            if (FlyingEnabled)
            {
                return;
            }

            this.Velocity.Y += Gravity * (float)gameTime.ElapsedGameTime.TotalSeconds;
            var   footPosition  = Position + new Vector3(0f, -1.5f, 0f);
            Block standingBlock = BlockStorage.BlockAt(footPosition);

            if (standingBlock.Exists)
            {
                this.Velocity.Y = 0;
            }
            this.Position += Velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Builds vertex list for chunk.
        /// </summary>
        /// <param name="chunk"></param>
        private void BuildVertexList(Chunk chunk)
        {
            if (chunk.Disposed)
            {
                return;
            }

            Clear(chunk);

            for (byte x = 0; x < Chunk.WidthInBlocks; x++)
            {
                for (byte z = 0; z < Chunk.LenghtInBlocks; z++)
                {
                    int offset = BlockStorage.BlockIndexByRelativePosition(chunk, x, z);

                    for (byte y = chunk.LowestEmptyBlockOffset; y < chunk.HighestSolidBlockOffset; y++)
                    {
                        var blockIndex = offset + y;

                        var block = BlockStorage.Blocks[blockIndex];

                        if (block.Type == BlockType.None)
                        {
                            continue;
                        }

                        var position = new Vector3Int(chunk.WorldPosition.X + x, y, chunk.WorldPosition.Z + z);
                        this.BuildBlockVertices(chunk, blockIndex, position);
                    }
                }
            }

            var vertices = chunk.VertexList.ToArray();
            var indices  = chunk.IndexList.ToArray();

            if (vertices.Length == 0 || indices.Length == 0)
            {
                return;
            }

            chunk.VertexBuffer = new VertexBuffer(this.Game.GraphicsDevice, typeof(BlockVertex), vertices.Length, BufferUsage.WriteOnly);
            chunk.VertexBuffer.SetData(vertices);

            chunk.IndexBuffer = new IndexBuffer(this.Game.GraphicsDevice, IndexElementSize.SixteenBits, indices.Length, BufferUsage.WriteOnly);
            chunk.IndexBuffer.SetData(indices);
        }
Ejemplo n.º 23
0
        static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Usage: dotnet run <part1|part2> <puzzleInputFile>");
                return;
            }

            var data  = File.ReadAllText(args[1]);
            var block = new BlockStorage(data, new [] { " ", "\t" });

            Console.WriteLine(block.ToString());

            var previousBlocks = new List <BlockStorage>();
            var cycles         = 0;

            while (!previousBlocks.Where(x => x.Equals(block)).Any())
            {
                previousBlocks.Add(block);
                block = block.Redistribute();
                Console.WriteLine(block.ToString());
                cycles++;
            }

            switch (args[0])
            {
            case "part1":
                Console.WriteLine($"Redistribution matched after {cycles} cycles.");
                break;

            case "part2":
                var matchingBlockIndex = -1;
                var i = previousBlocks.Count() - 1;
                while (matchingBlockIndex == -1)
                {
                    if (previousBlocks[i].Equals(block))
                    {
                        matchingBlockIndex = i;
                    }
                    i--;
                }

                Console.WriteLine($"Count between matching distributions: {previousBlocks.Count() - matchingBlockIndex}.");
                break;
            }
        }
Ejemplo n.º 24
0
        protected override void GenerateBlocks(Chunk chunk, int worldPositionX, int worldPositionZ)
        {
            var offset = BlockStorage.BlockIndexByWorldPosition(worldPositionX, worldPositionZ);

            for (int y = Chunk.MaxHeightIndexInBlocks; y >= 0; y--)
            {
                if (y >= DirtHeight)
                {
                    BlockStorage.Blocks[offset + y] = new Block(BlockType.None);
                }
                else
                {
                    BlockStorage.Blocks[offset + y] = new Block(BlockType.Dirt);
                }
            }

            // apply the biome generator on x-z column.
            this.BiomeGenerator.ApplyBiome(chunk, DirtHeight - 1, offset + DirtHeight - 1, worldPositionX + this.Seed, worldPositionZ);
        }
Ejemplo n.º 25
0
        private void FindAimedBlock()
        {
            for (float x = 0.5f; x < 8f; x += 0.1f)
            {
                Vector3 target = this._camera.Position + (LookVector * x);
                var     block  = BlockStorage.BlockAt(target);
                if (!block.Exists)
                {
                    this.AimedEmptyBlock = new PositionedBlock(new Vector3Int(target), block);
                }
                else
                {
                    this.AimedSolidBlock = new PositionedBlock(new Vector3Int(target), block);
                    return;
                }
            }

            this.AimedSolidBlock = null;
        }
Ejemplo n.º 26
0
        private void PlantTree(Chunk chunk, int grassLevel, int grassOffset, int worldPositionX, int worldPositionZ)
        {
            // based on: http://techcraft.codeplex.com/SourceControl/changeset/view/5c1888588e5d#TechCraft%2fNewTake%2fNewTake%2fmodel%2fterrain%2fSimpleTerrain.cs

            var trunkHeight = (byte)(5 + (byte)_treePlanter.Next(10));

            Console.WriteLine("tree location: {0},{1},{2}", worldPositionX, grassLevel, worldPositionZ);
            // trunk
            for (byte y = 1; y <= trunkHeight; y++)
            {
                BlockStorage.Blocks[grassOffset + y].Type = BlockType.Tree;

                // set the foliage.
                int radius = 2;


                Console.WriteLine("foliage: {0}-{1}, {2}, {3}", worldPositionX - radius, worldPositionX + radius, grassLevel + y, worldPositionZ);
                for (int x = worldPositionX - radius; x <= worldPositionX + radius; x++)
                {
                    //for (int z = worldPositionZ - radius; z <= worldPositionZ + radius; z++)
                    //{
                    if (!BlockStorage.BlockAt(x, grassLevel + y, worldPositionZ).Exists)
                    {
                        Console.Write("leave ");
                        BlockStorage.SetBlockAt(x, grassLevel + y, worldPositionZ, new Block(BlockType.Leaves));
                    }
                    else
                    {
                        Console.Write("solid ");
                    }
                    //}
                }

                Console.WriteLine();
            }

            if (grassLevel + trunkHeight > chunk.HighestSolidBlockOffset)
            {
                chunk.HighestSolidBlockOffset = (byte)(grassLevel + trunkHeight + 1);
            }
        }
Ejemplo n.º 27
0
        public ChunkSection(ChunkColumn owner, int y, bool storeSkylight, int sections = 2)
        {
            Owner = owner;
            if (sections <= 0)
            {
                sections = 1;
            }

            this._yBase = y;
            //Data = new BlockStorage();
            _blockStorages = new BlockStorage[sections];
            for (int i = 0; i < sections; i++)
            {
                _blockStorages[i] = new BlockStorage();
            }

            this.BlockLight = new NibbleArray(new byte[2048]);
            MiNET.Worlds.ChunkColumn.Fill <byte>(BlockLight.Data, 0);

            //	if (storeSkylight)
            {
                this.SkyLight = new NibbleArray(new byte[2048]);
                MiNET.Worlds.ChunkColumn.Fill <byte>(SkyLight.Data, (byte)(storeSkylight ? 0xff : 0x00));
            }
//System.Collections.BitArray a = new System.Collections.BitArray(new byte[(16 * 16 * 16) / 8]);

            TransparentBlocks          = new System.Collections.BitArray(new byte[(16 * 16 * 16) / 8]);
            SolidBlocks                = new System.Collections.BitArray(new byte[(16 * 16 * 16) / 8]);
            ScheduledUpdates           = new System.Collections.BitArray(new byte[(16 * 16 * 16) / 8]);
            ScheduledSkylightUpdates   = new System.Collections.BitArray(new byte[(16 * 16 * 16) / 8]);
            ScheduledBlocklightUpdates = new System.Collections.BitArray(new byte[(16 * 16 * 16) / 8]);
            RenderedBlocks             = new System.Collections.BitArray(new byte[(16 * 16 * 16) / 8]);

            for (int i = 0; i < TransparentBlocks.Length; i++)
            {
                TransparentBlocks[i] = true;
                SolidBlocks[i]       = false;
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Sets block at given relative position.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <param name="block"></param>
        public void FastSetBlockAt(byte x, byte y, byte z, Block block)
        {
            switch (block.Exists)
            {
            case false:
                if (this.LowestEmptyBlockOffset > y && y > 0)
                {
                    this.LowestEmptyBlockOffset = (byte)(y - 1);
                }
                break;

            case true:
                if (y > this.HighestSolidBlockOffset && y < MaxHeightIndexInBlocks)
                {
                    this.HighestSolidBlockOffset = (byte)(y + 1);
                }
                break;
            }

            BlockStorage.FastSetBlockAt(this.WorldPosition.X + x, y, this.WorldPosition.Z + z, block);
            this.ChunkState = ChunkState.AwaitingRelighting;
        }
Ejemplo n.º 29
0
        protected override void GenerateBlocks(Chunk chunk, int worldPositionX, int worldPositionZ)
        {
            var rockHeight = this.GetRockHeight(worldPositionX, worldPositionZ);
            var dirtHeight = this.GetDirtHeight(worldPositionX, worldPositionZ, rockHeight);

            var offset = BlockStorage.BlockIndexByWorldPosition(worldPositionX, worldPositionZ);

            for (int y = Chunk.MaxHeightIndexInBlocks; y >= 0; y--)
            {
                if (y > dirtHeight) // air
                {
                    BlockStorage.Blocks[offset + y] = new Block(BlockType.None);
                    if (chunk.LowestEmptyBlockOffset > y)
                    {
                        chunk.LowestEmptyBlockOffset = (byte)y;
                    }
                }
                else if (y > rockHeight) // dirt
                {
                    var valleyNoise = this.GenerateValleyNoise(worldPositionX, worldPositionZ, y);
                    BlockStorage.Blocks[offset + y] = new Block(valleyNoise > 0.2f ? BlockType.None : BlockType.Dirt);
                    if (y > chunk.HighestSolidBlockOffset)
                    {
                        chunk.HighestSolidBlockOffset = (byte)y;
                    }
                }
                else // rock level
                {
                    BlockStorage.Blocks[offset + y] = new Block(BlockType.Rock);
                    if (y > chunk.HighestSolidBlockOffset)
                    {
                        chunk.HighestSolidBlockOffset = (byte)y;
                    }
                }
            }

            // apply the biome generator on x-z column.
            this.BiomeGenerator.ApplyBiome(chunk, dirtHeight, offset + dirtHeight, worldPositionX + this.Seed, worldPositionZ);
        }
Ejemplo n.º 30
0
 public static ChunkColumn ReadColumnData(byte[] data, int chunkX, int chunkZ, bool chunksContinuous, bool hasSkyLight, int chunkMask)
 {
     using (MemoryStream memstream = new MemoryStream(data, false))
     {
         InputBuffer input  = new InputBuffer(memstream);
         ChunkColumn column = new ChunkColumn(chunkX, chunkZ);
         for (int chunkY = 0; chunkY < 16; chunkY++)
         {
             if ((chunkMask & (1 << chunkY)) != 0)
             {
                 BlockStorage blocks = new BlockStorage(input);
                 input.ReadData(2048);
                 if (hasSkyLight)
                 {
                     input.ReadData(2048);
                 }
                 column[chunkY] = new ChunkData(blocks);
             }
         }
         return(column);
     }
 }
Ejemplo n.º 31
0
        public void Init()
        {
            _game        = new GameClient();
            this._config = new EngineConfig();
            this._engine = new Engine.Core.Engine(this._game, this._config);

            var cacheWidthInBlocks  = ((_config.Cache.CacheRange * 2) + 1) * _config.Chunk.WidthInBlocks;
            var cacheLenghtInBlocks = ((_config.Cache.CacheRange * 2) + 1) * _config.Chunk.LengthInBlocks;

            this._cacheXStartIndex = -cacheWidthInBlocks / 2;
            this._cacheXEndIndex   = cacheWidthInBlocks / 2;

            this._cacheZStartIndex = -cacheLenghtInBlocks / 2;
            this._cacheZEndIndex   = cacheLenghtInBlocks / 2;

            this._directlyIndexedValidationDictionary = new Dictionary <int, BlockType>();

            // set the initial values.
            for (var x = this._cacheXStartIndex; x < this._cacheXEndIndex; x++)
            {
                for (var z = this._cacheZStartIndex; z < this._cacheZEndIndex; z++)
                {
                    var offset = BlockStorage.BlockIndexByWorldPosition(x, z);

                    for (var y = 0; y < _config.Chunk.HeightInBlocks; y++)
                    {
                        var index = offset + y;
                        var block = new Block().RandomizeType();

                        this._directlyIndexedValidationDictionary.Add(index, block.Type);

                        BlockStorage.Blocks[index] = block;
                    }
                }
            }

            // check if validationDictionaries item count is equal to CacheRange's volume.
            Assert.AreEqual(this._directlyIndexedValidationDictionary.Values.Count, _config.Cache.CacheRangeVolume);
        }