Example #1
0
        internal WorldHost()
        {
            PerformanceHost.OnHalfSecondElapsed += PerformanceHost_OnHalfSecondElapsed;

            for (var i = 0; i < Math.Max(1, Environment.ProcessorCount / 2); i++)
            {
                var buildChunkThread = new Thread(BuildChunksThread) { IsBackground = true, Priority = ThreadPriority.Lowest, Name = "Chunk Builder " + i}; //Lowest priority makes it noticeably less choppy when working through the queue (startup)
                buildChunkThread.Start();
            }

            FogColorUnderWater = new ColorRgb(51, 128, 204);
        }
Example #2
0
        private static void AddBlockFaceToVbo(ChunkVbo chunkVbo, Face face, float x0, float y0, float z0, ColorRgb[] colors)
        {
            //position calculations
            float x1 = x0 + 1f;             //x starting left at 0 in block
            float y1 = y0 + 1f;             //y starting bottom at 0 in block
            float z1 = z0 + 1f;             //z starting back at 0 in block

            switch (face)
            {
            case Face.Front:
                // v0-v1-v2-v3 (front)
                chunkVbo.Positions.Add(new Vector3(x1, y1, z1));
                chunkVbo.Positions.Add(new Vector3(x0, y1, z1));
                chunkVbo.Positions.Add(new Vector3(x0, y0, z1));
                chunkVbo.Positions.Add(new Vector3(x1, y0, z1));
                break;

            case Face.Right:
                // v5-v0-v3-v4 (right)
                chunkVbo.Positions.Add(new Vector3(x1, y1, z0));
                chunkVbo.Positions.Add(new Vector3(x1, y1, z1));
                chunkVbo.Positions.Add(new Vector3(x1, y0, z1));
                chunkVbo.Positions.Add(new Vector3(x1, y0, z0));
                break;

            case Face.Top:
                // v5-v6-v1-v0 (top)
                chunkVbo.Positions.Add(new Vector3(x1, y1, z0));
                chunkVbo.Positions.Add(new Vector3(x0, y1, z0));
                chunkVbo.Positions.Add(new Vector3(x0, y1, z1));
                chunkVbo.Positions.Add(new Vector3(x1, y1, z1));
                break;

            case Face.Left:
                // v1-v6-v7-v2 (left)
                chunkVbo.Positions.Add(new Vector3(x0, y1, z1));
                chunkVbo.Positions.Add(new Vector3(x0, y1, z0));
                chunkVbo.Positions.Add(new Vector3(x0, y0, z0));
                chunkVbo.Positions.Add(new Vector3(x0, y0, z1));
                break;

            case Face.Bottom:
                // v3-v2-v7-v4 (bottom)
                chunkVbo.Positions.Add(new Vector3(x1, y0, z1));
                chunkVbo.Positions.Add(new Vector3(x0, y0, z1));
                chunkVbo.Positions.Add(new Vector3(x0, y0, z0));
                chunkVbo.Positions.Add(new Vector3(x1, y0, z0));
                break;

            case Face.Back:
                // v6-v5-v4-v7 (back)
                chunkVbo.Positions.Add(new Vector3(x0, y1, z0));
                chunkVbo.Positions.Add(new Vector3(x1, y1, z0));
                chunkVbo.Positions.Add(new Vector3(x1, y0, z0));
                chunkVbo.Positions.Add(new Vector3(x0, y0, z0));
                break;
            }

            if (Settings.OutlineChunks)             //highlights chunk edges in yellow, the actual chunk edge line is the line between the 2 yellow block strips (use /outline to toggle)
            {
                var rgbYellow = new ColorRgb(255, 255, 50);
                chunkVbo.Colors.AddRange(WorldData.IsOnChunkBorder((int)x0, (int)z0) ? new[] { rgbYellow, rgbYellow, rgbYellow, rgbYellow } : colors);
            }
            else
            {
                chunkVbo.Colors.AddRange(colors);
            }
            chunkVbo.TexCoords.AddRange(TexCoords);
        }
Example #3
0
        private static void AddBlockFaceToVbo(ChunkVbo chunkVbo, Face face, float x0, float y0, float z0, ColorRgb[] colors)
        {
            //position calculations
            float x1 = x0 + 1f; //x starting left at 0 in block
            float y1 = y0 + 1f; //y starting bottom at 0 in block
            float z1 = z0 + 1f; //z starting back at 0 in block

            switch (face)
            {
                case Face.Front:
                    // v0-v1-v2-v3 (front)
                    chunkVbo.Positions.Add(new Vector3(x1, y1, z1));
                    chunkVbo.Positions.Add(new Vector3(x0, y1, z1));
                    chunkVbo.Positions.Add(new Vector3(x0, y0, z1));
                    chunkVbo.Positions.Add(new Vector3(x1, y0, z1));
                    break;
                case Face.Right:
                    // v5-v0-v3-v4 (right)
                    chunkVbo.Positions.Add(new Vector3(x1, y1, z0));
                    chunkVbo.Positions.Add(new Vector3(x1, y1, z1));
                    chunkVbo.Positions.Add(new Vector3(x1, y0, z1));
                    chunkVbo.Positions.Add(new Vector3(x1, y0, z0));
                    break;
                case Face.Top:
                    // v5-v6-v1-v0 (top)
                    chunkVbo.Positions.Add(new Vector3(x1, y1, z0));
                    chunkVbo.Positions.Add(new Vector3(x0, y1, z0));
                    chunkVbo.Positions.Add(new Vector3(x0, y1, z1));
                    chunkVbo.Positions.Add(new Vector3(x1, y1, z1));
                    break;
                case Face.Left:
                    // v1-v6-v7-v2 (left)
                    chunkVbo.Positions.Add(new Vector3(x0, y1, z1));
                    chunkVbo.Positions.Add(new Vector3(x0, y1, z0));
                    chunkVbo.Positions.Add(new Vector3(x0, y0, z0));
                    chunkVbo.Positions.Add(new Vector3(x0, y0, z1));
                    break;
                case Face.Bottom:
                    // v3-v2-v7-v4 (bottom)
                    chunkVbo.Positions.Add(new Vector3(x1, y0, z1));
                    chunkVbo.Positions.Add(new Vector3(x0, y0, z1));
                    chunkVbo.Positions.Add(new Vector3(x0, y0, z0));
                    chunkVbo.Positions.Add(new Vector3(x1, y0, z0));
                    break;
                case Face.Back:
                    // v6-v5-v4-v7 (back)
                    chunkVbo.Positions.Add(new Vector3(x0, y1, z0));
                    chunkVbo.Positions.Add(new Vector3(x1, y1, z0));
                    chunkVbo.Positions.Add(new Vector3(x1, y0, z0));
                    chunkVbo.Positions.Add(new Vector3(x0, y0, z0));
                    break;
            }

            if (Settings.OutlineChunks) //highlights chunk edges in yellow, the actual chunk edge line is the line between the 2 yellow block strips (use /outline to toggle)
            {
                var rgbYellow = new ColorRgb(255, 255, 50);
                chunkVbo.Colors.AddRange(WorldData.IsOnChunkBorder((int)x0, (int)z0) ? new[] {rgbYellow, rgbYellow, rgbYellow, rgbYellow} : colors);
            }
            else
            {
                chunkVbo.Colors.AddRange(colors);
            }
            chunkVbo.TexCoords.AddRange(TexCoords);
        }
Example #4
0
        /// <summary>Add a block face to a VBO using flat lighting. Same light color is used for all 4 vertices.</summary>
        public static void AddBlockFaceToVbo(ChunkVbo chunkVbo, Face face, float x, float y, float z, byte lightColor)
        {
            var colorRgb = new ColorRgb(lightColor, lightColor, lightColor);

            AddBlockFaceToVbo(chunkVbo, face, x, y, z, new[] { colorRgb, colorRgb, colorRgb, colorRgb });
        }
Example #5
0
 /// <summary>Add a block face to a VBO using flat lighting. Same light color is used for all 4 vertices.</summary>
 public static void AddBlockFaceToVbo(ChunkVbo chunkVbo, Face face, float x, float y, float z, byte lightColor)
 {
     var colorRgb = new ColorRgb(lightColor, lightColor, lightColor);
     AddBlockFaceToVbo(chunkVbo, face, x, y, z, new[] {colorRgb, colorRgb, colorRgb, colorRgb});
 }