Example #1
0
        /// <summary>
        /// Loads the block properties from the world into the chunk properties object.
        /// </summary>
        /// <param name="properties">The chunk properties to write to.</param>
        /// <param name="blockList">The block list to reference.</param>
        /// <param name="world">The world to load from.</param>
        /// <param name="chunkPos">The target chunk.</param>
        internal static void LoadProperties(ChunkProperties properties, BlockList blockList, World world, ChunkPosition chunkPos)
        {
            GetChunkGrid(world, chunkPos);
            properties.ChunkPosition = chunkPos;

            int size         = world.ChunkSize.Value;
            int intBits      = world.ChunkSize.IntBits;
            int extendedSize = size + 2;

            for (int x = -1; x <= size; x++)
            {
                for (int y = -1; y <= size; y++)
                {
                    for (int z = -1; z <= size; z++)
                    {
                        var local = (x & world.ChunkSize.Mask) * size * size
                                    + (y & world.ChunkSize.Mask) * size
                                    + (z & world.ChunkSize.Mask);

                        var chunkIndex = ((x >> intBits) + 1) * 3 * 3
                                         + ((y >> intBits) + 1) * 3
                                         + ((z >> intBits) + 1);

                        var index = (x + 1) * extendedSize * extendedSize
                                    + (y + 1) * extendedSize
                                    + (z + 1);

                        var blockId   = m_ChunkBuffer[chunkIndex]?.Blocks[local] ?? 0;
                        var blockType = blockList.GetBlockType(blockId);
                        properties.Blocks[index] = blockType;
                    }
                }
            }
        }
        /// <summary>
        /// Generates the visual remeshing tasks, as needed.
        /// </summary>
        /// <param name="properties">The chunk properties.</param>
        /// <param name="tasks">The task list to add to.</param>
        private void GenerateVisuals(ChunkProperties properties, RemeshTaskStack taskStack)
        {
            List <int> materials = new List <int>();

            foreach (var pos in BlockIterator(properties.ChunkSize.Value))
            {
                var type = properties.GetBlock(pos);

                if (!type.IsVisible)
                {
                    continue;
                }

                for (int j = 0; j < 6; j++)
                {
                    var material = type.GetMaterialID(j);
                    if (materials.Contains(material))
                    {
                        continue;
                    }

                    materials.Add(material);
                    taskStack.AddTask(new VisualRemeshTask(properties, material));
                }
            }
        }
Example #3
0
        public void TwoInputsMaterials_ThreeOutputTasks()
        {
            // Arrange
            ChunkProperties.SetBlock(Pos(1, 1, 1), NormalBlock);
            ChunkProperties.SetBlock(Pos(2, 2, 2), NormalBlock);
            ChunkProperties.SetBlock(Pos(3, 3, 3), NormalBlock);
            ChunkProperties.SetBlock(Pos(4, 4, 4), NormalBlock);
            ChunkProperties.SetBlock(Pos(5, 5, 5), DifferentMaterialBlock);
            ChunkProperties.SetBlock(Pos(6, 6, 6), DifferentMaterialBlock);
            ChunkProperties.SetBlock(Pos(7, 7, 7), DifferentMaterialBlock);

            var remeshHandler = new RemeshHandler();

            remeshHandler.AddDistributor(new StandardDistributor());

            // Act
            remeshHandler.RemeshChunk(ChunkProperties);
            List <RemeshTaskStack> tasks = new List <RemeshTaskStack>();

            remeshHandler.FinishTasks(tasks);

            // Assert
            Assert.AreEqual(1, tasks.Count);
            Assert.AreEqual(3, tasks[0].TaskCount);
            Assert.IsInstanceOf <VisualRemeshTask>(tasks[0].GetTask(0));
            Assert.IsInstanceOf <VisualRemeshTask>(tasks[0].GetTask(1));
            Assert.IsInstanceOf <CollisionRemeshTask>(tasks[0].GetTask(2));

            Assert.AreEqual(0, (tasks[0].GetTask(0) as VisualRemeshTask).MaterialID);
            Assert.AreEqual(1, (tasks[0].GetTask(1) as VisualRemeshTask).MaterialID);
        }
        public void SetBlock_GetBlock()
        {
            // Arrange
            var blockType1 = new Mock <IMeshBlockDetails>();
            var blockType2 = new Mock <IMeshBlockDetails>();
            var blockType3 = new Mock <IMeshBlockDetails>();
            var blockPos1  = new BlockPosition(1, 1, 4);
            var blockPos2  = new BlockPosition(2, 2, 3);
            var blockPos3  = new BlockPosition(3, 3, 2);
            var blockPos4  = new BlockPosition(4, 4, 1);

            var chunkSize = new GridSize(3);
            var chunkPos  = new ChunkPosition(1, 3, 6);
            var props     = new ChunkProperties();

            // Act
            props.Reset(chunkPos, chunkSize);
            props.SetBlock(blockPos1, blockType1.Object);
            props.SetBlock(blockPos2, blockType2.Object);
            props.SetBlock(blockPos3, blockType3.Object);

            // Assert
            Assert.AreEqual(blockType1.Object, props.GetBlock(blockPos1));
            Assert.AreEqual(blockType2.Object, props.GetBlock(blockPos2));
            Assert.AreEqual(blockType3.Object, props.GetBlock(blockPos3));
            Assert.AreEqual(null, props.GetBlock(blockPos4));
        }
Example #5
0
        void Stylechanged(object sender, EventArgs e)
        {
            Gtk.TreeIter iter;
            if (!this.treeviewColors.Selection.GetSelected(out iter))
            {
                return;
            }
            ChunkProperties prop = ChunkProperties.None;

            if (checkbuttonBold.Active)
            {
                prop |= ChunkProperties.Bold;
            }
            if (checkbuttonItalic.Active)
            {
                prop |= ChunkProperties.Italic;
            }
            ChunkStyle oldStyle   = (ChunkStyle)colorStore.GetValue(iter, 1);
            bool       useBgColor = colorbuttonBg.Alpha > 0 && (colorbuttonBg.Color.Pixel != oldStyle.BackgroundColor.Pixel || oldStyle.GotBackgroundColorAssigned);

            colorStore.SetValue(iter, 1, useBgColor? new ChunkStyle(colorbuttonFg.Color, colorbuttonBg.Color, prop) : new ChunkStyle(colorbuttonFg.Color, prop));

            var newStyle = colorSheme.Clone();

            ApplyStyle(newStyle);
            this.textEditor.TextViewMargin.PurgeLayoutCache();
            this.textEditor.Document.MimeType = "text/x-csharp";
            this.textEditor.GetTextEditorData().ColorStyle = newStyle;
            this.textEditor.QueueDraw();
        }
Example #6
0
        /// <summary>
        /// Creates a new voxel chunk mesher.
        /// </summary>
        /// <param name="chunkProperties">The chunk properties to handle.</param>
        /// <param name="wield">Whether or not to wield vertices after remeshing.</param>
        /// <param name="enableUVs">Whether or not to generate UVs in the mesh.</param>
        public VoxelChunkMesher(ChunkProperties chunkProperties, bool wieldVertices, bool enableUVs)
        {
            m_ChunkProperties = chunkProperties;
            m_GreedyMesher    = new GreedyMesher(chunkProperties.ChunkSize, enableUVs);
            m_WieldVertices   = wieldVertices;

            m_Mesh = new ProcMesh();

            m_Task = Task.Run(Remesh);
        }
        /// <summary>
        /// Generates the collision remesh task, as needed.
        /// </summary>
        /// <param name="properties">The chunk properties.</param>
        /// <param name="tasks">The task list to add to.</param>
        private void GenerateCollision(ChunkProperties properties, RemeshTaskStack taskStack)
        {
            foreach (var pos in BlockIterator(properties.ChunkSize.Value))
            {
                var type = properties.GetBlock(pos);

                if (type.IsSolid)
                {
                    taskStack.AddTask(new CollisionRemeshTask(properties));
                    return;
                }
            }
        }
Example #8
0
        public void BlockFace_DifferentAtlas_IgnoreQuads()
        {
            // Arrange
            ChunkProperties.SetBlock(Pos(0, 0, 0), NormalBlock);
            ChunkProperties.SetBlock(Pos(1, 1, 1), DifferentMaterialBlock);

            // Act
            var task = new VisualRemeshTask(ChunkProperties, 0);
            var mesh = task.Finish();

            // Assert
            Assert.AreEqual(24, mesh.Vertices.Count);
            Assert.AreEqual(24, mesh.Normals.Count);
            Assert.AreEqual(24, mesh.UVs.Count);
            Assert.AreEqual(36, mesh.Triangles.Count);
        }
Example #9
0
        public void RespectNeighborChunks()
        {
            // Arrange
            ChunkProperties.SetBlock(Pos(-1, 0, 0), NormalBlock);
            ChunkProperties.SetBlock(Pos(0, 0, 0), NormalBlock);

            // Act
            var task = new VisualRemeshTask(ChunkProperties, 0);
            var mesh = task.Finish();

            // Assert
            Assert.AreEqual(20, mesh.Vertices.Count);
            Assert.AreEqual(20, mesh.Normals.Count);
            Assert.AreEqual(20, mesh.UVs.Count);
            Assert.AreEqual(30, mesh.Triangles.Count);
        }
Example #10
0
        public void TwoCubes()
        {
            // Arrange
            ChunkProperties.SetBlock(Pos(0, 0, 0), NormalBlock);
            ChunkProperties.SetBlock(Pos(0, 1, 0), NormalBlock);

            // Act
            var task = new VisualRemeshTask(ChunkProperties, 0);
            var mesh = task.Finish();

            // Assert
            Assert.AreEqual(24, mesh.Vertices.Count);
            Assert.AreEqual(24, mesh.Normals.Count);
            Assert.AreEqual(24, mesh.UVs.Count);
            Assert.AreEqual(36, mesh.Triangles.Count);
        }
        public void IgnoreNeighborChunks()
        {
            // Arrange
            ChunkProperties.SetBlock(Pos(-1, 0, 0), NormalBlock);
            ChunkProperties.SetBlock(Pos(0, 0, 0), NormalBlock);

            // Act
            var task = new CollisionRemeshTask(ChunkProperties);
            var mesh = task.Finish();

            // Assert
            Assert.AreEqual(24, mesh.Vertices.Count);
            Assert.AreEqual(24, mesh.Normals.Count);
            Assert.AreEqual(0, mesh.UVs.Count);
            Assert.AreEqual(36, mesh.Triangles.Count);
        }
        public void SetBlock_ResetChunk_GetBlock_ReturnsNull()
        {
            // Arrange
            var blockType = new Mock <IMeshBlockDetails>();
            var blockPos  = new BlockPosition(1, 1, 4);

            var chunkSize = new GridSize(3);
            var chunkPos1 = new ChunkPosition(1, 3, 6);
            var chunkPos2 = new ChunkPosition(17, -123, 12999);
            var props     = new ChunkProperties();

            // Act
            props.Reset(chunkPos1, chunkSize);
            props.SetBlock(blockPos, blockType.Object);
            props.Reset(chunkPos2, chunkSize);

            // Assert
            Assert.AreEqual(null, props.GetBlock(blockPos));
        }
        public void Init()
        {
            var airBlock = new Mock <IMeshBlockDetails>();

            airBlock.Setup(b => b.IsSolid).Returns(false);
            airBlock.Setup(b => b.IsVisible).Returns(false);
            AirBlock = airBlock.Object;

            var noCollisionBlock = new Mock <IMeshBlockDetails>();

            noCollisionBlock.Setup(b => b.IsSolid).Returns(false);
            noCollisionBlock.Setup(b => b.IsVisible).Returns(true);
            NoCollisionBlock = noCollisionBlock.Object;

            var normalBlock = new Mock <IMeshBlockDetails>();

            normalBlock.Setup(b => b.IsSolid).Returns(true);
            normalBlock.Setup(b => b.IsVisible).Returns(true);
            NormalBlock = normalBlock.Object;

            var invisibleBlock = new Mock <IMeshBlockDetails>();

            invisibleBlock.Setup(b => b.IsSolid).Returns(true);
            invisibleBlock.Setup(b => b.IsVisible).Returns(false);
            InvisibleBlock = invisibleBlock.Object;

            var differentMaterialBlock = new Mock <IMeshBlockDetails>();

            differentMaterialBlock.Setup(b => b.IsSolid).Returns(true);
            differentMaterialBlock.Setup(b => b.IsVisible).Returns(true);
            differentMaterialBlock.Setup(b => b.GetMaterialID(It.IsAny <int>())).Returns(1);
            DifferentMaterialBlock = differentMaterialBlock.Object;

            var randomTexturesBlock = new Mock <IMeshBlockDetails>();

            randomTexturesBlock.Setup(b => b.IsSolid).Returns(true);
            randomTexturesBlock.Setup(b => b.IsVisible).Returns(true);
            randomTexturesBlock.Setup(b => b.GetRotation(It.IsAny <int>())).Returns(FaceRotation.Random);
            RandomTexturesBlock = randomTexturesBlock.Object;

            ChunkProperties = new ChunkProperties();
            ChunkProperties.Reset(default, new GridSize(4));
        /// <inheritdoc cref="VoxelChunkMesher"/>
        public override bool CanPlaceQuad(ChunkProperties chunkProperties, BlockPosition pos, int side)
        {
            var block = chunkProperties.GetBlock(pos);

            if (!block.IsSolid)
            {
                return(false);
            }

            var nextPos = pos;

            nextPos = nextPos.ShiftAlongDirection(side);
            if (!nextPos.IsWithinGrid(chunkProperties.ChunkSize))
            {
                return(true);
            }

            var next = chunkProperties.GetBlock(nextPos);

            return(!next.IsSolid);
        }
Example #15
0
        public void SomeSolid_NoVisible()
        {
            // Arrange
            ChunkProperties.SetBlock(Pos(1, 1, 5), InvisibleBlock);
            ChunkProperties.SetBlock(Pos(2, 2, 4), InvisibleBlock);
            ChunkProperties.SetBlock(Pos(3, 3, 3), InvisibleBlock);

            var remeshHandler = new RemeshHandler();

            remeshHandler.AddDistributor(new StandardDistributor());

            // Act
            remeshHandler.RemeshChunk(ChunkProperties);
            List <RemeshTaskStack> tasks = new List <RemeshTaskStack>();

            remeshHandler.FinishTasks(tasks);

            // Assert
            Assert.AreEqual(1, tasks.Count);
            Assert.AreEqual(1, tasks[0].TaskCount);
            Assert.IsInstanceOf <CollisionRemeshTask>(tasks[0].GetTask(0));
        }
Example #16
0
        public void SetChunkStyle(string name, string weight, string foreColor, string backColor)
        {
            Gdk.Color       color      = !String.IsNullOrEmpty(foreColor) ? this.GetColorFromString(foreColor) : Gdk.Color.Zero;
            Gdk.Color       bgColor    = !String.IsNullOrEmpty(backColor) ? this.GetColorFromString(backColor) : Gdk.Color.Zero;
            ChunkProperties properties = ChunkProperties.None;

            if (weight != null)
            {
                if (weight.ToUpper().IndexOf("BOLD") >= 0)
                {
                    properties |= ChunkProperties.Bold;
                }
                if (weight.ToUpper().IndexOf("ITALIC") >= 0)
                {
                    properties |= ChunkProperties.Italic;
                }
                if (weight.ToUpper().IndexOf("UNDERLINE") >= 0)
                {
                    properties |= ChunkProperties.Underline;
                }
            }
            SetStyle(name, new ChunkStyle(color, bgColor, properties));
        }
Example #17
0
        public void StandardChunk()
        {
            // Arrange
            ChunkProperties.SetBlock(Pos(4, 4, 5), NormalBlock);
            ChunkProperties.SetBlock(Pos(4, 5, 5), NormalBlock);
            ChunkProperties.SetBlock(Pos(5, 5, 5), NormalBlock);

            var remeshHandler = new RemeshHandler();

            remeshHandler.AddDistributor(new StandardDistributor());

            // Act
            remeshHandler.RemeshChunk(ChunkProperties);
            List <RemeshTaskStack> tasks = new List <RemeshTaskStack>();

            remeshHandler.FinishTasks(tasks);

            // Assert
            Assert.AreEqual(1, tasks.Count);
            Assert.AreEqual(2, tasks[0].TaskCount);
            Assert.IsInstanceOf <VisualRemeshTask>(tasks[0].GetTask(0));
            Assert.IsInstanceOf <CollisionRemeshTask>(tasks[0].GetTask(1));
        }
Example #18
0
 /// <summary>
 /// Checks whether or not the given quad within the check should be added to the mesh.
 /// </summary>
 /// <param name="chunkProperties">The chunk properties to read from.</param>
 /// <param name="pos">The block position.</param>
 /// <param name="side">The side of the block being checked.</param>
 /// <returns>True if the quad should be placed. False otherwise.</returns>
 public abstract bool CanPlaceQuad(ChunkProperties chunkProperties, BlockPosition pos, int side);
Example #19
0
 /// <inheritdoc cref="VoxelChunkMesher"/>
 internal VisualRemeshTask(ChunkProperties chunkProperties, int materialID, GreedyMesher mesher) :
     base(chunkProperties, mesher) => MaterialID = materialID;
Example #20
0
		public ChunkStyle (Cairo.Color color, Cairo.Color bgColor, ChunkProperties chunkProperties)
		{
			this.CairoColor           = color;
			this.CairoBackgroundColor = bgColor;
			this.ChunkProperties = chunkProperties;
		}
Example #21
0
		public ChunkStyle (Cairo.Color color, ChunkProperties chunkProperties)
		{
			this.CairoColor           = color;
			this.ChunkProperties = chunkProperties;
		}
 /// <inheritdoc cref="IRemeshTask"/>
 public void CreateTasks(ChunkProperties properties, RemeshTaskStack taskStack)
 {
     GenerateVisuals(properties, taskStack);
     GenerateCollision(properties, taskStack);
 }
Example #23
0
 public ChunkStyle(Gdk.Color color, Gdk.Color bgColor, ChunkProperties chunkProperties)
 {
     this.Color           = color;
     this.BackgroundColor = bgColor;
     this.ChunkProperties = chunkProperties;
 }
Example #24
0
		public ChunkStyle (Gdk.Color color, ChunkProperties chunkProperties) : this (color, Gdk.Color.Zero, chunkProperties)
		{
		}
		void SetStyle (string name, byte r, byte g, byte b, ChunkProperties properties)
		{
			SetStyle (name, new ChunkStyle (new Gdk.Color (r, g, b), properties));
		}
Example #26
0
 public ChunkStyle(Cairo.Color color, ChunkProperties chunkProperties)
 {
     this.CairoColor      = color;
     this.ChunkProperties = chunkProperties;
 }
 /// <inheritdoc cref="VoxelChunkMesher"/>
 public CollisionRemeshTask(ChunkProperties chunkProperties) :
     base(chunkProperties, true, false)
 {
 }
Example #28
0
 public ChunkStyle(Cairo.Color color, Cairo.Color bgColor, ChunkProperties chunkProperties)
 {
     this.CairoColor           = color;
     this.CairoBackgroundColor = bgColor;
     this.ChunkProperties      = chunkProperties;
 }
Example #29
0
 public ChunkStyle(Gdk.Color color, Gdk.Color bgColor, ChunkProperties chunkProperties)
 {
     this.CairoColor           = (HslColor)color;
     this.CairoBackgroundColor = (HslColor)bgColor;
     this.ChunkProperties      = chunkProperties;
 }
    void InitializeVariables()
    {
        world = World.currentWorld;
        cubes = new byte[world.chunkLength, world.chunkHeight, world.chunkLength];

        meshRender = GetComponent<MeshRenderer> ();
        meshCollider = GetComponent<MeshCollider> ();
        meshFilter = GetComponent<MeshFilter> ();

        chunkProp = GetComponent<ChunkProperties> ();
        cubeType = CubeProperties.cubeProperties;
    }
Example #31
0
 /// <inheritdoc cref="VoxelChunkMesher"/>
 public VisualRemeshTask(ChunkProperties chunkProperties, int materialID) :
     base(chunkProperties, false, true) => MaterialID = materialID;
Example #32
0
		public ChunkStyle (Gdk.Color color, Gdk.Color bgColor, ChunkProperties chunkProperties)
		{
			this.Color           = color;
			this.BackgroundColor = bgColor;
			this.ChunkProperties = chunkProperties;
		}
Example #33
0
 void SetStyle(string name, byte r, byte g, byte b, ChunkProperties properties)
 {
     SetStyle(name, new ChunkStyle(new Gdk.Color(r, g, b), properties));
 }
Example #34
0
		public ChunkStyle (Gdk.Color color, ChunkProperties chunkProperties)
		{
			this.CairoColor      = (HslColor)color;
			this.ChunkProperties = chunkProperties;
		}
Example #35
0
 /// <inheritdoc cref="VoxelChunkMesher"/>
 internal CollisionRemeshTask(ChunkProperties chunkProperties, GreedyMesher mesher) :
     base(chunkProperties, mesher)
 {
 }
Example #36
0
		public ChunkStyle (Gdk.Color color, Gdk.Color bgColor, ChunkProperties chunkProperties)
		{
			this.CairoColor           = (HslColor)color;
			this.CairoBackgroundColor = (HslColor)bgColor;
			this.ChunkProperties = chunkProperties;
		}
Example #37
0
 public ChunkStyle(Gdk.Color color, ChunkProperties chunkProperties)
 {
     this.CairoColor      = (HslColor)color;
     this.ChunkProperties = chunkProperties;
 }
Example #38
0
 public ChunkStyle(Gdk.Color color, ChunkProperties chunkProperties) : this(color, Gdk.Color.Zero, chunkProperties)
 {
 }