示例#1
0
        public void TestAStarLinearPath()
        {
            var world = new TrueCraft.Core.World.World("default", new FlatlandGenerator());
            var astar = new AStarPathFinder();

            var watch = new Stopwatch();

            watch.Start();
            var path = astar.FindPath(world, new BoundingBox(),
                                      new Coordinates3D(0, 4, 0), new Coordinates3D(5, 4, 0));

            watch.Stop();
            DrawGrid(path, world);
            Console.WriteLine(watch.ElapsedMilliseconds + "ms");

            var expected = new[]
            {
                new Coordinates3D(0, 4, 0),
                new Coordinates3D(1, 4, 0),
                new Coordinates3D(2, 4, 0),
                new Coordinates3D(3, 4, 0),
                new Coordinates3D(4, 4, 0),
                new Coordinates3D(5, 4, 0)
            };

            for (int i = 0; i < path.Waypoints.Count; i++)
            {
                Assert.AreEqual(expected[i], path.Waypoints[i]);
            }
        }
示例#2
0
 public void SetUp()
 {
     var world = new TrueCraft.Core.World.World();
     var assemblyDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
     Region = new Region(Coordinates2D.Zero, world,
         Path.Combine(assemblyDir, "Files", "r.0.0.mca"));
 }
示例#3
0
        public void TestAStarLinearPath()
        {
            var world = new TrueCraft.Core.World.World("default", new FlatlandGenerator());
            var astar = new AStarPathFinder();

            var watch = new Stopwatch();
            watch.Start();
            var path = astar.FindPath(world, new BoundingBox(),
               new Coordinates3D(0, 4, 0), new Coordinates3D(5, 4, 0));
            watch.Stop();
            DrawGrid(path, world);
            Console.WriteLine(watch.ElapsedMilliseconds + "ms");

            var expected = new[]
            {
                new Coordinates3D(0, 4, 0),
                new Coordinates3D(1, 4, 0),
                new Coordinates3D(2, 4, 0),
                new Coordinates3D(3, 4, 0),
                new Coordinates3D(4, 4, 0),
                new Coordinates3D(5, 4, 0)
            };
            for (int i = 0; i < path.Waypoints.Count; i++)
                Assert.AreEqual(expected[i], path.Waypoints[i]);
        }
示例#4
0
        public void TestShortPropegation()
        {
            var repository = new BlockRepository();
            repository.RegisterBlockProvider(new GrassBlock());
            repository.RegisterBlockProvider(new DirtBlock());
            repository.RegisterBlockProvider(new AirBlock());
            repository.RegisterBlockProvider(new BedrockBlock());
            var world = new TrueCraft.Core.World.World("TEST", new FlatlandGenerator());
            world.BlockRepository = repository;
            var lighter = new WorldLighting(world, repository);
            world.GetBlockID(Coordinates3D.Zero); // Generate a chunk
            lighter.InitialLighting(world.GetChunk(Coordinates2D.Zero));

            world.SetBlockID(new Coordinates3D(5, 3, 5), 0); // Create area that looks like so:
            world.SetBlockID(new Coordinates3D(5, 2, 5), 0); // x x  Light goes like so: |
            world.SetBlockID(new Coordinates3D(5, 1, 5), 0); // x x                      |
            world.SetBlockID(new Coordinates3D(4, 1, 5), 0); //   x                     -/

            lighter.EnqueueOperation(new BoundingBox(new Vector3(5, 2, 5),
                new Vector3(6, 4, 6)), true);

            while (lighter.TryLightNext()) // Test lighting
            {
            }

            Console.WriteLine("Testing {0}", new Coordinates3D(5, 3, 5));
            Assert.AreEqual(15, world.GetSkyLight(new Coordinates3D(5, 3, 5)));
            Console.WriteLine("Testing {0}", new Coordinates3D(5, 2, 5));
            Assert.AreEqual(15, world.GetSkyLight(new Coordinates3D(5, 2, 5)));
            Console.WriteLine("Testing {0}", new Coordinates3D(5, 1, 5));
            Assert.AreEqual(15, world.GetSkyLight(new Coordinates3D(5, 1, 5)));
            Console.WriteLine("Testing {0}", new Coordinates3D(4, 1, 5));
            Assert.AreEqual(14, world.GetSkyLight(new Coordinates3D(4, 1, 5)));
        }
示例#5
0
        public void SetUp()
        {
            var world       = new TrueCraft.Core.World.World();
            var assemblyDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            Region = new Region(Coordinates2D.Zero, world,
                                Path.Combine(assemblyDir, "Files", "r.0.0.mca"));
        }
示例#6
0
 /// <summary>
 /// Creates a region from the given region file.
 /// </summary>
 public Region(Coordinates2D position, World world, string file) : this(position, world)
 {
     if (File.Exists(file))
         regionFile = File.Open(file, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
     else
     {
         regionFile = File.Open(file, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
         CreateRegionHeader();
     }
 }
示例#7
0
        public void TestFarPropegation()
        {
            var repository = new BlockRepository();
            repository.RegisterBlockProvider(new GrassBlock());
            repository.RegisterBlockProvider(new DirtBlock());
            repository.RegisterBlockProvider(new AirBlock());
            repository.RegisterBlockProvider(new BedrockBlock());
            var world = new TrueCraft.Core.World.World("TEST", new FlatlandGenerator());
            world.BlockRepository = repository;
            var lighter = new WorldLighting(world, repository);
            world.GetBlockID(Coordinates3D.Zero); // Generate a chunk
            lighter.EnqueueOperation(new BoundingBox(
                    new Vector3(0, 0, 0),
                    new Vector3(16, 128, 16)), true, true);
            while (lighter.TryLightNext()) // Initial lighting
            {
            }

            world.SetBlockID(new Coordinates3D(5, 3, 5), 0); // Create area that looks like so:
            world.SetBlockID(new Coordinates3D(5, 2, 5), 0); // x x  Light goes like so: |
            world.SetBlockID(new Coordinates3D(5, 1, 5), 0); // x x                      |
            world.SetBlockID(new Coordinates3D(4, 1, 5), 0); //   x                     -/

            for (int x = 0; x < 4; x++)
            {
                world.SetBlockID(new Coordinates3D(x, 1, 5), 0); // Dig a tunnel
                // xxxxx x ish
                // x     x
                // xxxxxxx
            }

            lighter.EnqueueOperation(new BoundingBox(new Vector3(5, 2, 5),
                    new Vector3(6, 4, 6)), true);

            while (lighter.TryLightNext()) // Test lighting
            {
            }

            Console.WriteLine("Testing {0}", new Coordinates3D(5, 3, 5));
            Assert.AreEqual(15, world.GetSkyLight(new Coordinates3D(5, 3, 5)));
            Console.WriteLine("Testing {0}", new Coordinates3D(5, 2, 5));
            Assert.AreEqual(15, world.GetSkyLight(new Coordinates3D(5, 2, 5)));
            Console.WriteLine("Testing {0}", new Coordinates3D(5, 1, 5));
            Assert.AreEqual(15, world.GetSkyLight(new Coordinates3D(5, 1, 5)));

            byte expected = 15;
            for (int x = 5; x >= 0; x--)
            {
                Console.WriteLine("Testing {0}", new Coordinates3D(x, 1, 5));
                Assert.AreEqual(expected, world.GetSkyLight(new Coordinates3D(x, 1, 5)));
                expected--;
            }
        }
示例#8
0
 public void TestAStarDiagonalPath()
 {
     var world = new TrueCraft.Core.World.World("default", new FlatlandGenerator());
     var astar = new AStarPathFinder();
     var start = new Coordinates3D(0, 4, 0);
     var end = new Coordinates3D(5, 4, 5);
     var path = astar.FindPath(world, new BoundingBox(), start, end);
     DrawGrid(path, world);
     // Just test the start and end, the exact results need to be eyeballed
     Assert.AreEqual(start, path.Waypoints[0]);
     Assert.AreEqual(end, path.Waypoints[path.Waypoints.Count - 1]);
 }
示例#9
0
        public void TestFarPropegation()
        {
            var repository = new BlockRepository();

            repository.RegisterBlockProvider(new GrassBlock());
            repository.RegisterBlockProvider(new DirtBlock());
            repository.RegisterBlockProvider(new AirBlock());
            repository.RegisterBlockProvider(new BedrockBlock());
            var world = new TrueCraft.Core.World.World("TEST", new FlatlandGenerator());

            world.BlockRepository = repository;
            var lighter = new WorldLighting(world, repository);

            world.GetBlockID(Coordinates3D.Zero); // Generate a chunk
            lighter.InitialLighting(world.GetChunk(Coordinates2D.Zero));

            world.SetBlockID(new Coordinates3D(5, 3, 5), 0); // Create area that looks like so:
            world.SetBlockID(new Coordinates3D(5, 2, 5), 0); // x x  Light goes like so: |
            world.SetBlockID(new Coordinates3D(5, 1, 5), 0); // x x                      |
            world.SetBlockID(new Coordinates3D(4, 1, 5), 0); //   x                     -/

            for (int x = 0; x < 4; x++)
            {
                world.SetBlockID(new Coordinates3D(x, 1, 5), 0); // Dig a tunnel
                // xxxxx x ish
                // x     x
                // xxxxxxx
            }

            lighter.EnqueueOperation(new BoundingBox(new Vector3(5, 2, 5),
                                                     new Vector3(6, 4, 6)), true);

            while (lighter.TryLightNext()) // Test lighting
            {
            }

            Console.WriteLine("Testing {0}", new Coordinates3D(5, 3, 5));
            Assert.AreEqual(15, world.GetSkyLight(new Coordinates3D(5, 3, 5)));
            Console.WriteLine("Testing {0}", new Coordinates3D(5, 2, 5));
            Assert.AreEqual(15, world.GetSkyLight(new Coordinates3D(5, 2, 5)));
            Console.WriteLine("Testing {0}", new Coordinates3D(5, 1, 5));
            Assert.AreEqual(15, world.GetSkyLight(new Coordinates3D(5, 1, 5)));

            byte expected = 15;

            for (int x = 5; x >= 0; x--)
            {
                Console.WriteLine("Testing {0}", new Coordinates3D(x, 1, 5));
                Assert.AreEqual(expected, world.GetSkyLight(new Coordinates3D(x, 1, 5)));
                expected--;
            }
        }
示例#10
0
 public SingleplayerServer(World world)
 {
     World = world;
     Server = new MultiplayerServer();
     TrueCraft.Program.ServerConfiguration = new ServerConfiguration()
     {
         MOTD = null,
         Singleplayer = true
     };
     world.BlockRepository = Server.BlockRepository;
     Server.AddWorld(world);
     Server.AddLogProvider(new ConsoleLogProvider());
 }
示例#11
0
        public void TestBasicLighting()
        {
            var repository = new BlockRepository();

            repository.RegisterBlockProvider(new GrassBlock());
            repository.RegisterBlockProvider(new DirtBlock());
            repository.RegisterBlockProvider(new AirBlock());
            repository.RegisterBlockProvider(new BedrockBlock());
            var world = new TrueCraft.Core.World.World("TEST", new FlatlandGenerator());

            world.BlockRepository = repository;
            var lighter = new WorldLighting(world, repository);

            world.GetBlockID(Coordinates3D.Zero); // Generate a chunk
            lighter.InitialLighting(world.GetChunk(Coordinates2D.Zero));

            for (int y = 5; y >= 0; y--)
            {
                Console.Write("Y: {0} ", y);
                Console.Write(world.GetBlockID(new Coordinates3D(0, y, 0)));
                Console.Write(" -> ");
                Console.WriteLine(world.GetSkyLight(new Coordinates3D(0, y, 0)));
            }

            // Validate behavior
            for (int y = 0; y < Chunk.Height; y++)
            {
                for (int x = 0; x < Chunk.Width; x++)
                {
                    for (int z = 0; z < Chunk.Depth; z++)
                    {
                        var coords = new Coordinates3D(x, y, z);
                        var sky    = world.GetSkyLight(coords);
                        if (y < 4)
                        {
                            Assert.AreEqual(0, sky, coords.ToString());
                        }
                        else
                        {
                            Assert.AreEqual(15, sky, coords.ToString());
                        }
                    }
                }
            }
        }
示例#12
0
 public World CreateNewWorld(string name, string seed)
 {
     int s;
     if (!int.TryParse(seed, out s))
     {
         // TODO: Hash seed string
         s = MathHelper.Random.Next();
     }
     var world = new World(name, s, new StandardGenerator());
     world.BlockRepository = BlockRepository;
     var safeName = name;
     foreach (var c in Path.GetInvalidFileNameChars())
         safeName = safeName.Replace(c.ToString(), "");
     world.Name = name;
     world.Save(Path.Combine(WorldsPath, safeName));
     Saves = Saves.Concat(new[] { world }).ToArray();
     return world;
 }
示例#13
0
        public void TestBasicLighting()
        {
            var repository = new BlockRepository();
            repository.RegisterBlockProvider(new GrassBlock());
            repository.RegisterBlockProvider(new DirtBlock());
            repository.RegisterBlockProvider(new AirBlock());
            repository.RegisterBlockProvider(new BedrockBlock());
            var world = new TrueCraft.Core.World.World("TEST", new FlatlandGenerator());
            world.BlockRepository = repository;
            var lighter = new WorldLighting(world, repository);
            world.GetBlockID(Coordinates3D.Zero); // Generate a chunk
            lighter.EnqueueOperation(new BoundingBox(
                    new Vector3(0, 0, 0),
                    new Vector3(16, 128, 16)), true, true);
            while (lighter.TryLightNext())
            {
            }

            for (int y = 5; y >= 0; y--)
            {
                Console.Write(world.GetBlockID(new Coordinates3D(0, y, 0)));
                Console.Write(" ");
                Console.WriteLine(world.GetSkyLight(new Coordinates3D(0, y, 0)));
            }

            // Validate behavior
            for (int y = 0; y < Chunk.Height; y++)
            {
                for (int x = 0; x < Chunk.Width; x++)
                {
                    for (int z = 0; z < Chunk.Depth; z++)
                    {
                        var coords = new Coordinates3D(x, y, z);
                        var sky = world.GetSkyLight(coords);
                        if (y < 4)
                            Assert.AreEqual(0, sky);
                        else
                            Assert.AreEqual(15, sky);
                    }
                }
            }
        }
示例#14
0
        public void TestAStarDiagonalPath()
        {
            var world = new TrueCraft.Core.World.World("default", new FlatlandGenerator());
            var astar = new AStarPathFinder();
            var start = new Coordinates3D(0, 4, 0);
            var end   = new Coordinates3D(5, 4, 5);

            var watch = new Stopwatch();

            watch.Start();
            var path = astar.FindPath(world, new BoundingBox(), start, end);

            watch.Stop();
            DrawGrid(path, world);
            Console.WriteLine(watch.ElapsedMilliseconds + "ms");

            // Just test the start and end, the exact results need to be eyeballed
            Assert.AreEqual(start, path.Waypoints[0]);
            Assert.AreEqual(end, path.Waypoints[path.Waypoints.Count - 1]);
        }
示例#15
0
        public void TestAStarImpossible()
        {
            var world = new TrueCraft.Core.World.World("default", new FlatlandGenerator());
            var astar = new AStarPathFinder();
            var start = new Coordinates3D(0, 4, 0);
            var end   = new Coordinates3D(5, 4, 0);

            world.SetBlockID(start + Coordinates3D.East, 1);
            world.SetBlockID(start + Coordinates3D.West, 1);
            world.SetBlockID(start + Coordinates3D.North, 1);
            world.SetBlockID(start + Coordinates3D.South, 1);

            var watch = new Stopwatch();

            watch.Start();
            var path = astar.FindPath(world, new BoundingBox(), start, end);

            watch.Stop();
            Console.WriteLine(watch.ElapsedMilliseconds + "ms");

            Assert.IsNull(path);
        }
示例#16
0
        public void TestBasicLighting()
        {
            var repository = new BlockRepository();
            repository.RegisterBlockProvider(new GrassBlock());
            repository.RegisterBlockProvider(new DirtBlock());
            repository.RegisterBlockProvider(new AirBlock());
            repository.RegisterBlockProvider(new BedrockBlock());
            var world = new TrueCraft.Core.World.World("TEST", new FlatlandGenerator());
            world.BlockRepository = repository;
            var lighter = new WorldLighting(world, repository);
            world.GetBlockID(Coordinates3D.Zero); // Generate a chunk
            lighter.InitialLighting(world.GetChunk(Coordinates2D.Zero));

            for (int y = 5; y >= 0; y--)
            {
                Console.Write("Y: {0} ", y);
                Console.Write(world.GetBlockID(new Coordinates3D(0, y, 0)));
                Console.Write(" -> ");
                Console.WriteLine(world.GetSkyLight(new Coordinates3D(0, y, 0)));
            }

            // Validate behavior
            for (int y = 0; y < Chunk.Height; y++)
            {
                for (int x = 0; x < Chunk.Width; x++)
                {
                    for (int z = 0; z < Chunk.Depth; z++)
                    {
                        var coords = new Coordinates3D(x, y, z);
                        var sky = world.GetSkyLight(coords);
                        if (y < 4)
                            Assert.AreEqual(0, sky, coords.ToString());
                        else
                            Assert.AreEqual(15, sky, coords.ToString());
                    }
                }
            }
        }
示例#17
0
        public void TestAStarAvoidRoom()
        {
            var world = new TrueCraft.Core.World.World("default", new FlatlandGenerator());
            var astar = new AStarPathFinder();
            var start = new Coordinates3D(-5, 4, 0);
            var end   = new Coordinates3D(5, 4, 0);

            // North wall
            for (int x = -4; x < 4; x++)
            {
                world.SetBlockID(new Coordinates3D(x, 4, -4), 1);
            }
            // East wall
            for (int z = -4; z < 4; z++)
            {
                world.SetBlockID(new Coordinates3D(3, 4, z), 1);
            }
            // South wall
            for (int x = -4; x < 4; x++)
            {
                world.SetBlockID(new Coordinates3D(x, 4, 4), 1);
            }

            var watch = new Stopwatch();

            watch.Start();
            var path = astar.FindPath(world, new BoundingBox(), start, end);

            watch.Stop();
            DrawGrid(path, world);
            Console.WriteLine(watch.ElapsedMilliseconds + "ms");

            // Just test the start and end, the exact results need to be eyeballed
            Assert.AreEqual(start, path.Waypoints[0]);
            Assert.AreEqual(end, path.Waypoints[path.Waypoints.Count - 1]);
        }
示例#18
0
        public void TestAStarExitRoom()
        {
            var world = new TrueCraft.Core.World.World("default", new FlatlandGenerator());
            var astar = new AStarPathFinder();
            var start = new Coordinates3D(0, 4, 0);
            var end = new Coordinates3D(5, 4, 0);

            // North wall
            for (int x = -4; x < 4; x++)
                world.SetBlockID(new Coordinates3D(x, 4, -4), 1);
            // East wall
            for (int z = -4; z < 4; z++)
                world.SetBlockID(new Coordinates3D(3, 4, z), 1);
            // South wall
            for (int x = -4; x < 4; x++)
                world.SetBlockID(new Coordinates3D(x, 4, 4), 1);

            var path = astar.FindPath(world, new BoundingBox(), start, end);
            DrawGrid(path, world);

            // Just test the start and end, the exact results need to be eyeballed
            Assert.AreEqual(start, path.Waypoints[0]);
            Assert.AreEqual(end, path.Waypoints[path.Waypoints.Count - 1]);
        }
示例#19
0
        public void TestLeavesAndEtc()
        {
            var repository = new BlockRepository();

            repository.RegisterBlockProvider(new GrassBlock());
            repository.RegisterBlockProvider(new DirtBlock());
            repository.RegisterBlockProvider(new AirBlock());
            repository.RegisterBlockProvider(new BedrockBlock());
            repository.RegisterBlockProvider(new LeavesBlock());
            var world = new TrueCraft.Core.World.World("TEST", new FlatlandGenerator());

            world.BlockRepository = repository;
            var lighter = new WorldLighting(world, repository);

            world.GetBlockID(Coordinates3D.Zero); // Generate a chunk

            for (int y = 1; y <= 16; y++)
            {
                var coords = new Coordinates3D(5, y, 5);
                world.SetBlockID(coords, 0);
                world.SetBlockID(coords + Coordinates3D.East, DirtBlock.BlockID);
                world.SetBlockID(coords + Coordinates3D.West, DirtBlock.BlockID);
                world.SetBlockID(coords + Coordinates3D.North, DirtBlock.BlockID);
                world.SetBlockID(coords + Coordinates3D.South, DirtBlock.BlockID);
            }
            world.GetChunk(Coordinates2D.Zero).UpdateHeightMap();

            lighter.InitialLighting(world.GetChunk(Coordinates2D.Zero));

            // Test this layout:
            // xox      o == leaves
            // x x
            // xox
            // x x
            // xox ...

            for (int y = 1; y <= 16; y++)
            {
                if (y % 2 == 1)
                {
                    world.SetBlockID(new Coordinates3D(5, y, 5), LeavesBlock.BlockID);
                }
            }
            world.GetChunk(Coordinates2D.Zero).UpdateHeightMap();

            lighter.EnqueueOperation(new BoundingBox(new Vector3(5, 0, 5),
                                                     new Vector3(6, 16, 6)), true);

            while (lighter.TryLightNext()) // Test lighting
            {
            }

            // Output lighting
            for (int y = 16; y >= 0; y--)
            {
                Console.Write(world.GetBlockID(new Coordinates3D(5, y, 5)).ToString("D2"));
                Console.Write(" " + world.GetSkyLight(new Coordinates3D(5, y, 5)).ToString("D2"));
                Console.WriteLine("   Y={0}", y);
            }

            var expected = new byte[]
            {
                15, // air
                13, // leaves
                12, // air
                10, // leaves
                9,  // air
                7,  // leaves
                6,  // air
                4,  // leaves
                3,  // air
                1,  // leaves
                0,  // air
                0,  // leaves
            };

            for (int y = 16, i = 0; y >= 0; y--, i++)
            {
                byte ex;
                if (i < expected.Length)
                {
                    ex = expected[i];
                }
                else
                {
                    ex = 0;
                }
                Assert.AreEqual(ex, world.GetSkyLight(new Coordinates3D(5, y, 5)));
            }
        }
示例#20
0
        public void TestFarPropegationx2()
        {
            var repository = new BlockRepository();

            repository.RegisterBlockProvider(new GrassBlock());
            repository.RegisterBlockProvider(new DirtBlock());
            repository.RegisterBlockProvider(new AirBlock());
            repository.RegisterBlockProvider(new BedrockBlock());
            var world = new TrueCraft.Core.World.World("TEST", new FlatlandGenerator());

            world.BlockRepository = repository;
            var lighter = new WorldLighting(world, repository);

            world.GetBlockID(Coordinates3D.Zero); // Generate a chunk
            lighter.InitialLighting(world.GetChunk(Coordinates2D.Zero));

            // Test this layout:
            // xxx x    y=3
            // x   x    y=2
            // x   x    y=1
            // xxxxx    y=0
            //
            //    ^ x,z = 5

            for (int y = 1; y <= 3; y++) // Dig hole
            {
                world.SetBlockID(new Coordinates3D(5, y, 5), 0);
            }

            for (int x = 0; x <= 4; x++)                         // Dig outwards
            {
                world.SetBlockID(new Coordinates3D(x, 2, 5), 0); // Dig a tunnel
                world.SetBlockID(new Coordinates3D(x, 1, 5), 0); // Dig a tunnel
            }

            var watch = new Stopwatch();

            watch.Start();

            lighter.EnqueueOperation(new BoundingBox(new Vector3(5, 2, 5),
                                                     new Vector3(6, 4, 6)), true);

            while (lighter.TryLightNext()) // Test lighting
            {
            }

            watch.Stop();

            // Output lighting
            for (int y = 3; y >= 0; y--)
            {
                for (int x = 0; x <= 5; x++)
                {
                    Console.Write(world.GetBlockID(new Coordinates3D(x, y, 5)).ToString("D2") + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
            for (int y = 3; y >= 0; y--)
            {
                for (int x = 0; x <= 5; x++)
                {
                    Console.Write(world.GetSkyLight(new Coordinates3D(x, y, 5)).ToString("D2") + " ");
                }
                Console.WriteLine();
            }

            Console.WriteLine("Testing {0}", new Coordinates3D(5, 3, 5));
            Assert.AreEqual(15, world.GetSkyLight(new Coordinates3D(5, 3, 5)));
            Console.WriteLine("Testing {0}", new Coordinates3D(5, 2, 5));
            Assert.AreEqual(15, world.GetSkyLight(new Coordinates3D(5, 2, 5)));
            Console.WriteLine("Testing {0}", new Coordinates3D(5, 1, 5));
            Assert.AreEqual(15, world.GetSkyLight(new Coordinates3D(5, 1, 5)));

            byte expected = 15;

            for (int x = 5; x >= 0; x--)
            {
                Console.WriteLine("Testing {0}", new Coordinates3D(x, 2, 5));
                Assert.AreEqual(expected, world.GetSkyLight(new Coordinates3D(x, 2, 5)));
                expected--;
            }
            expected = 15;
            for (int x = 5; x >= 0; x--)
            {
                Console.WriteLine("Testing {0}", new Coordinates3D(x, 1, 5));
                Assert.AreEqual(expected, world.GetSkyLight(new Coordinates3D(x, 1, 5)));
                expected--;
            }

            Console.WriteLine("{0}ms", watch.ElapsedMilliseconds);
        }
示例#21
0
        public void TestAStarImpossible()
        {
            var world = new TrueCraft.Core.World.World("default", new FlatlandGenerator());
            var astar = new AStarPathFinder();
            var start = new Coordinates3D(0, 4, 0);
            var end = new Coordinates3D(5, 4, 0);

            world.SetBlockID(start + Coordinates3D.East, 1);
            world.SetBlockID(start + Coordinates3D.West, 1);
            world.SetBlockID(start + Coordinates3D.North, 1);
            world.SetBlockID(start + Coordinates3D.South, 1);

            var watch = new Stopwatch();
            watch.Start();
            var path = astar.FindPath(world, new BoundingBox(), start, end);
            watch.Stop();
            Console.WriteLine(watch.ElapsedMilliseconds + "ms");

            Assert.IsNull(path);
        }
示例#22
0
 public void SetUp()
 {
     World = TrueCraft.Core.World.World.LoadWorld("Files");
 }
示例#23
0
 public void SetUp()
 {
     World = TrueCraft.Core.World.World.LoadWorld("Files");
 }
示例#24
0
        public void TestLeavesAndEtc()
        {
            var repository = new BlockRepository();
            repository.RegisterBlockProvider(new GrassBlock());
            repository.RegisterBlockProvider(new DirtBlock());
            repository.RegisterBlockProvider(new AirBlock());
            repository.RegisterBlockProvider(new BedrockBlock());
            repository.RegisterBlockProvider(new LeavesBlock());
            var world = new TrueCraft.Core.World.World("TEST", new FlatlandGenerator());
            world.BlockRepository = repository;
            var lighter = new WorldLighting(world, repository);
            world.GetBlockID(Coordinates3D.Zero); // Generate a chunk

            for (int y = 1; y <= 16; y++)
            {
                var coords = new Coordinates3D(5, y, 5);
                world.SetBlockID(coords, 0);
                world.SetBlockID(coords + Coordinates3D.East, DirtBlock.BlockID);
                world.SetBlockID(coords + Coordinates3D.West, DirtBlock.BlockID);
                world.SetBlockID(coords + Coordinates3D.North, DirtBlock.BlockID);
                world.SetBlockID(coords + Coordinates3D.South, DirtBlock.BlockID);
            }
            world.GetChunk(Coordinates2D.Zero).UpdateHeightMap();

            lighter.InitialLighting(world.GetChunk(Coordinates2D.Zero));

            // Test this layout:
            // xox      o == leaves
            // x x
            // xox
            // x x
            // xox ...

            for (int y = 1; y <= 16; y++)
            {
                if (y % 2 == 1)
                    world.SetBlockID(new Coordinates3D(5, y, 5), LeavesBlock.BlockID);
            }
            world.GetChunk(Coordinates2D.Zero).UpdateHeightMap();

            lighter.EnqueueOperation(new BoundingBox(new Vector3(5, 0, 5),
                    new Vector3(6, 16, 6)), true);

            while (lighter.TryLightNext()) // Test lighting
            {
            }

            // Output lighting
            for (int y = 16; y >= 0; y--)
            {
                Console.Write(world.GetBlockID(new Coordinates3D(5, y, 5)).ToString("D2"));
                Console.Write(" " + world.GetSkyLight(new Coordinates3D(5, y, 5)).ToString("D2"));
                Console.WriteLine("   Y={0}", y);
            }                

            var expected = new byte[]
            {
                15, // air
                13, // leaves
                12, // air
                10, // leaves
                9, // air
                7,  // leaves
                6,  // air
                4,  // leaves
                3,  // air
                1,  // leaves
                0,  // air
                0,  // leaves
            };

            for (int y = 16, i = 0; y >= 0; y--, i++)
            {
                byte ex;
                if (i < expected.Length)
                    ex = expected[i];
                else
                    ex = 0;
                Assert.AreEqual(ex, world.GetSkyLight(new Coordinates3D(5, y, 5)));
            }
        }
示例#25
0
 public void SetUp()
 {
     var world = new TrueCraft.Core.World.World();
     Region = new Region(Coordinates2D.Zero, world, "Files/r.0.0.mca");
 }
示例#26
0
 internal ReadOnlyWorld()
 {
     World = new World("default");
     UnloadChunks = true;
 }
示例#27
0
        public void TestFarPropegationx2()
        {
            var repository = new BlockRepository();
            repository.RegisterBlockProvider(new GrassBlock());
            repository.RegisterBlockProvider(new DirtBlock());
            repository.RegisterBlockProvider(new AirBlock());
            repository.RegisterBlockProvider(new BedrockBlock());
            var world = new TrueCraft.Core.World.World("TEST", new FlatlandGenerator());
            world.BlockRepository = repository;
            var lighter = new WorldLighting(world, repository);
            world.GetBlockID(Coordinates3D.Zero); // Generate a chunk
            lighter.InitialLighting(world.GetChunk(Coordinates2D.Zero));

            // Test this layout:
            // xxx x    y=3
            // x   x    y=2
            // x   x    y=1
            // xxxxx    y=0
            //
            //    ^ x,z = 5

            for (int y = 1; y <= 3; y++) // Dig hole
            {
                world.SetBlockID(new Coordinates3D(5, y, 5), 0);
            }

            for (int x = 0; x <= 4; x++) // Dig outwards
            {
                world.SetBlockID(new Coordinates3D(x, 2, 5), 0); // Dig a tunnel
                world.SetBlockID(new Coordinates3D(x, 1, 5), 0); // Dig a tunnel
            }

            var watch = new Stopwatch();
            watch.Start();

            lighter.EnqueueOperation(new BoundingBox(new Vector3(5, 2, 5),
                    new Vector3(6, 4, 6)), true);

            while (lighter.TryLightNext()) // Test lighting
            {
            }

            watch.Stop();

            // Output lighting
            for (int y = 3; y >= 0; y--)
            {
                for (int x = 0; x <= 5; x++)
                {
                    Console.Write(world.GetBlockID(new Coordinates3D(x, y, 5)).ToString("D2") + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
            for (int y = 3; y >= 0; y--)
            {
                for (int x = 0; x <= 5; x++)
                {
                    Console.Write(world.GetSkyLight(new Coordinates3D(x, y, 5)).ToString("D2") + " ");
                }
                Console.WriteLine();
            }

            Console.WriteLine("Testing {0}", new Coordinates3D(5, 3, 5));
            Assert.AreEqual(15, world.GetSkyLight(new Coordinates3D(5, 3, 5)));
            Console.WriteLine("Testing {0}", new Coordinates3D(5, 2, 5));
            Assert.AreEqual(15, world.GetSkyLight(new Coordinates3D(5, 2, 5)));
            Console.WriteLine("Testing {0}", new Coordinates3D(5, 1, 5));
            Assert.AreEqual(15, world.GetSkyLight(new Coordinates3D(5, 1, 5)));

            byte expected = 15;
            for (int x = 5; x >= 0; x--)
            {
                Console.WriteLine("Testing {0}", new Coordinates3D(x, 2, 5));
                Assert.AreEqual(expected, world.GetSkyLight(new Coordinates3D(x, 2, 5)));
                expected--;
            }
            expected = 15;
            for (int x = 5; x >= 0; x--)
            {
                Console.WriteLine("Testing {0}", new Coordinates3D(x, 1, 5));
                Assert.AreEqual(expected, world.GetSkyLight(new Coordinates3D(x, 1, 5)));
                expected--;
            }

            Console.WriteLine("{0}ms", watch.ElapsedMilliseconds);
        }
示例#28
0
        public static World LoadWorld(string baseDirectory)
        {
            if (!Directory.Exists(baseDirectory))
                throw new DirectoryNotFoundException();

            var world = new World(Path.GetFileName(baseDirectory));
            world.BaseDirectory = baseDirectory;

            if (File.Exists(Path.Combine(baseDirectory, "manifest.nbt")))
            {
                var file = new NbtFile(Path.Combine(baseDirectory, "manifest.nbt"));
                world.SpawnPoint = new Coordinates3D(file.RootTag["SpawnPoint"]["X"].IntValue,
                    file.RootTag["SpawnPoint"]["Y"].IntValue,
                    file.RootTag["SpawnPoint"]["Z"].IntValue);
                world.Seed = file.RootTag["Seed"].IntValue;
                var providerName = file.RootTag["ChunkProvider"].StringValue;
                var provider = (IChunkProvider)Activator.CreateInstance(Type.GetType(providerName), world);
                if (file.RootTag.Contains("Name"))
                    world.Name = file.RootTag["Name"].StringValue;
                world.ChunkProvider = provider;
            }

            return world;
        }
示例#29
0
 /// <summary>
 /// Creates a new Region for server-side use at the given position using
 /// the provided terrain generator.
 /// </summary>
 public Region(Coordinates2D position, World world)
 {
     Chunks = new Dictionary<Coordinates2D, IChunk>();
     Position = position;
     World = world;
 }
示例#30
0
        public void TestAStarImpossible()
        {
            var world = new TrueCraft.Core.World.World("default", new FlatlandGenerator());
            var astar = new AStarPathFinder();
            var start = new Coordinates3D(0, 4, 0);
            var end = new Coordinates3D(5, 4, 0);

            world.SetBlockID(start + Coordinates3D.East, 1);
            world.SetBlockID(start + Coordinates3D.West, 1);
            world.SetBlockID(start + Coordinates3D.North, 1);
            world.SetBlockID(start + Coordinates3D.South, 1);

            var path = astar.FindPath(world, new BoundingBox(), start, end);
            Assert.IsNull(path);
        }
示例#31
0
 public void SetUp()
 {
     var assemblyDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
     World = TrueCraft.Core.World.World.LoadWorld(Path.Combine(assemblyDir, "Files"));
 }
示例#32
0
        public void TestAStarObstacle()
        {
            var world = new TrueCraft.Core.World.World("default", new FlatlandGenerator());
            var astar = new AStarPathFinder();
            var start = new Coordinates3D(0, 4, 0);
            var end = new Coordinates3D(5, 4, 0);
            world.SetBlockID(new Coordinates3D(3, 4, 0), 1); // Obstacle

            var watch = new Stopwatch();
            watch.Start();
            var path = astar.FindPath(world, new BoundingBox(), start, end);
            watch.Stop();
            DrawGrid(path, world);
            Console.WriteLine(watch.ElapsedMilliseconds + "ms");

            // Just test the start and end, the exact results need to be eyeballed
            Assert.AreEqual(start, path.Waypoints[0]);
            Assert.AreEqual(end, path.Waypoints[path.Waypoints.Count - 1]);
            Assert.IsFalse(path.Waypoints.Contains(new Coordinates3D(3, 4, 0)));
        }
示例#33
0
 public StandardGenerator(TrueCraft.Core.World.World world) : this()
 {
     // TODO: Do we want to do anything with that world?
 }
示例#34
0
        public void SetUp()
        {
            var assemblyDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            World = TrueCraft.Core.World.World.LoadWorld(Path.Combine(assemblyDir, "Files"));
        }
示例#35
0
        public static void Main(string[] args)
        {
            Server = new MultiplayerServer();

            Server.AddLogProvider(new ConsoleLogProvider(LogCategory.Notice | LogCategory.Warning | LogCategory.Error | LogCategory.Debug));
#if DEBUG
            Server.AddLogProvider(new FileLogProvider(new StreamWriter("packets.log", false), LogCategory.Packets));
#endif

            ServerConfiguration = Configuration.LoadConfiguration<ServerConfiguration>("config.yaml");

            var buckets = ServerConfiguration.Debug?.Profiler?.Buckets?.Split(',');
            if (buckets != null)
            {
                foreach (var bucket in buckets)
                {
                    Profiler.EnableBucket(bucket.Trim());
                }
            }

            if (ServerConfiguration.Debug.DeleteWorldOnStartup)
            {
                if (Directory.Exists("world"))
                    Directory.Delete("world", true);
            }
            if (ServerConfiguration.Debug.DeletePlayersOnStartup)
            {
                if (Directory.Exists("players"))
                    Directory.Delete("players", true);
            }
            IWorld world;
            try
            {
                world = World.LoadWorld("world");
                Server.AddWorld(world);
            }
            catch
            {
                world = new World("default", new StandardGenerator());
                world.BlockRepository = Server.BlockRepository;
                world.Save("world");
                Server.AddWorld(world);
                Server.Log(LogCategory.Notice, "Generating world around spawn point...");
                for (int x = -5; x < 5; x++)
                {
                    for (int z = -5; z < 5; z++)
                        world.GetChunk(new Coordinates2D(x, z));
                    int progress = (int)(((x + 5) / 10.0) * 100);
                    if (progress % 10 == 0)
                        Server.Log(LogCategory.Notice, "{0}% complete", progress + 10);
                }
                Server.Log(LogCategory.Notice, "Simulating the world for a moment...");
                for (int x = -5; x < 5; x++)
                {
                    for (int z = -5; z < 5; z++)
                    {
                        var chunk = world.GetChunk(new Coordinates2D(x, z));
                        for (byte _x = 0; _x < Chunk.Width; _x++)
                        {
                            for (byte _z = 0; _z < Chunk.Depth; _z++)
                            {
                                for (int _y = 0; _y < chunk.GetHeight(_x, _z); _y++)
                                {
                                    var coords = new Coordinates3D(x + _x, _y, z + _z);
                                    var data = world.GetBlockData(coords);
                                    var provider = world.BlockRepository.GetBlockProvider(data.ID);
                                    provider.BlockUpdate(data, data, Server, world);
                                }
                            }
                        }
                    }
                    int progress = (int)(((x + 5) / 10.0) * 100);
                    if (progress % 10 == 0)
                        Server.Log(LogCategory.Notice, "{0}% complete", progress + 10);
                }
            }
            world.Save();
            CommandManager = new CommandManager();
            Server.ChatMessageReceived += HandleChatMessageReceived;
            Server.Start(new IPEndPoint(IPAddress.Parse(ServerConfiguration.ServerAddress), ServerConfiguration.ServerPort));
            Console.CancelKeyPress += HandleCancelKeyPress;
            while (true)
            {
                Thread.Sleep(1000 * ServerConfiguration.WorldSaveInterval);
                foreach (var w in Server.Worlds)
                {
                    w.Save();
                }
            }
        }
示例#36
0
        public void SetUp()
        {
            var world = new TrueCraft.Core.World.World();

            Region = new Region(Coordinates2D.Zero, world, "Files/r.0.0.mca");
        }