Beispiel #1
0
        public void LoadFullAnvilRegionLoadTest()
        {
            int width = 32;
            int depth = 32;

            int regionX = 5;
            int regionZ = 25;

            string basePath  = @"D:\Downloads\KingsLanding1\KingsLanding1";
            var    generator = new FlatlandWorldProvider();

            Stopwatch sw = new Stopwatch();

            sw.Start();
            int noChunksRead = 0;

            for (int x = 1; x < 32; x++)
            {
                for (int z = 1; z < 32; z++)
                {
                    noChunksRead++;
                    int cx = (width * regionX) + x;
                    int cz = (depth * regionZ) + z;

                    ChunkCoordinates coordinates = new ChunkCoordinates(cx, cz);
                    ChunkColumn      chunk       = new AnvilWorldProvider().GetChunk(coordinates, basePath, null, 0);
                    Assert.NotNull(chunk, $"Expected chunk at {x}, {z}");
                }
            }
            Console.WriteLine("Read {0} chunks in {1}ms", noChunksRead, sw.ElapsedMilliseconds);
        }
Beispiel #2
0
        public virtual Level GetLevel(Player player, string name)
        {
            Level level = Levels.FirstOrDefault(l => l.LevelId.Equals(name, StringComparison.InvariantCultureIgnoreCase));

            if (level == null)
            {
                GameMode   gameMode     = Config.GetProperty("GameMode", GameMode.Survival);
                Difficulty difficulty   = Config.GetProperty("Difficulty", Difficulty.Peaceful);
                int        viewDistance = Config.GetProperty("ViewDistance", 250);

                IWorldProvider worldProvider = null;

                switch (Config.GetProperty("WorldProvider", "flat").ToLower().Trim())
                {
                case "flat":
                case "flatland":
                    worldProvider = new FlatlandWorldProvider();
                    break;

                case "cool":
                    worldProvider = new CoolWorldProvider();
                    break;

                case "experimental":
                    worldProvider = new ExperimentalWorldProvider();
                    break;

                case "anvil":
                    worldProvider = new AnvilWorldProvider();
                    break;

                default:
                    worldProvider = new FlatlandWorldProvider();
                    break;
                }

                level = new Level(name, worldProvider, gameMode, difficulty, viewDistance);
                level.Initialize();
                Levels.Add(level);

                OnLevelCreated(new LevelEventArgs(null, level));
            }

            return(level);
        }
Beispiel #3
0
        public void LoadAnvilChunkLoadTest()
        {
            int width = 32;
            int depth = 32;

            int cx = (width * 4) + 3;
            int cz = (depth * 25) + 0;

            ChunkCoordinates coordinates = new ChunkCoordinates(cx, cz);

            int rx = coordinates.X >> 5;
            int rz = coordinates.Z >> 5;

            Assert.AreEqual(4, rx);
            Assert.AreEqual(25, rz);

            string basePath  = @"D:\Downloads\KingsLanding1";
            var    generator = new FlatlandWorldProvider();

            Stopwatch sw = new Stopwatch();

            sw.Start();

            int iterations = 1024;

            for (int i = 0; i < iterations; i++)
            {
                AnvilWorldProvider.GetChunk(coordinates, basePath, generator, 30);
            }

            long ticks = sw.ElapsedTicks;
            long ms    = sw.ElapsedMilliseconds;

            //Assert.Less(ticks/iterations, 100);

            Console.WriteLine("Read {0} chunk-columns in {1}ns ({3}ms) at a rate of {2}ns/col", iterations, ticks, ticks / iterations, ms);
        }
Beispiel #4
0
        public virtual Level GetLevel(Player player, string name)
        {
            Level level = Levels.FirstOrDefault(l => l.LevelId.Equals(name, StringComparison.InvariantCultureIgnoreCase));

            if (level == null)
            {
                GameMode   gameMode     = Config.GetProperty("GameMode", GameMode.Survival);
                Difficulty difficulty   = Config.GetProperty("Difficulty", Difficulty.Normal);
                int        viewDistance = Config.GetProperty("ViewDistance", 11);

                IWorldProvider worldProvider = null;

                switch (Config.GetProperty("WorldProvider", "flat").ToLower().Trim())
                {
                case "flat":
                case "flatland":
                    worldProvider = new FlatlandWorldProvider();
                    break;

                case "cool":
                    worldProvider = new CoolWorldProvider();
                    break;

                case "experimental":
                    worldProvider = new ExperimentalWorldProvider();
                    break;

                case "anvil":
                    worldProvider = new AnvilWorldProvider()
                    {
                        MissingChunkProvider = new FlatlandWorldProvider()
                    };
                    break;

                default:
                    worldProvider = new FlatlandWorldProvider();
                    break;
                }

                level = new Level(name, worldProvider, EntityManager, gameMode, difficulty, viewDistance);
                level.Initialize();

                if (Config.GetProperty("CalculateLights", false))
                {
                    {
                        AnvilWorldProvider wp = level._worldProvider as AnvilWorldProvider;
                        if (wp != null)
                        {
                            //wp.PruneAir();
                            //wp.MakeAirChunksAroundWorldToCompensateForBadRendering();

                            SkyLightCalculations.Calculate(level);

                            Stopwatch sw = new Stopwatch();

                            int count = wp.LightSources.Count;
                            sw.Restart();
                            RecalculateLight(level, wp);

                            var chunkCount = wp._chunkCache.Where(chunk => chunk.Value != null).ToArray().Length;
                            Log.Debug($"Recalc light for {chunkCount} chunks, {chunkCount*16*16*256} blocks and {count} light sources. Time {sw.ElapsedMilliseconds}ms");
                        }
                    }

                    {
                        FlatlandWorldProvider wp = level._worldProvider as FlatlandWorldProvider;
                        if (wp != null)
                        {
                            SkyLightCalculations.Calculate(level);
                        }
                    }
                }
                Levels.Add(level);

                OnLevelCreated(new LevelEventArgs(null, level));
            }

            return(level);
        }