Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SMP.World"/> class and generates 49 chunks.
        /// </summary>
        /// <param name='spawnx'>
        /// Spawnx. The x spawn pos.
        /// </param>
        /// <param name='spawny'>
        /// Spawny. The y spawn pos.
        /// </param>
        /// <param name='spawnz'>
        /// Spawnz. The z spawn pos.
        /// </param>
        public World(double spawnx, double spawny, double spawnz, string name, long seed)
            : this()
        {
            this.name = name;
            this.seed = seed;
            this.SpawnX = spawnx; this.SpawnY = spawny; this.SpawnZ = spawnz;
            chunkData = new Dictionary<Point, Chunk>();
            physics = new Physics(this);
            generator = new GenStandard(this, true);
            chunkManager = new WorldChunkManager(this);
            Logger.Log("Generating " + this.name + "...");

            int cursorH = 25 + this.name.Length;
            float count = 0, total = (Server.ViewDistance * 2 + 1) * (Server.ViewDistance * 2 + 1);
            Console.SetCursorPosition(cursorH, Console.CursorTop - 1);
            Console.Write("0%");

            object derpLock = new object();
            try  // Mono 2.10.2 has Parallel.For(int) and Parallel.ForEach implemented, not sure about 2.8 though. Any version less does not support .NET 4.0
            {
                Parallel.For(((int)SpawnX >> 4) - Server.ViewDistance, ((int)SpawnX >> 4) + Server.ViewDistance + 1, delegate(int x)
                {
                    Parallel.For(((int)SpawnZ >> 4) - Server.ViewDistance, ((int)SpawnZ >> 4) + Server.ViewDistance + 1, delegate(int z)
                    {
                        LoadChunk(x, z, false, false);
                        lock (derpLock)
                        {
                            Console.SetCursorPosition(cursorH, Console.CursorTop);
                            count++; Console.Write((int)((count / total) * 100) + "%");
                        }
                    });
                    //Logger.Log(x + " Row Generated.");
                });
            }
            catch (NotImplementedException)
            {
                for (int x = ((int)SpawnX >> 4) - Server.ViewDistance; x < ((int)SpawnX >> 4) + Server.ViewDistance + 1; x++)
                {
                    for (int z = ((int)SpawnZ >> 4) - Server.ViewDistance; z < ((int)SpawnZ >> 4) + Server.ViewDistance + 1; z++)
                    {
                        LoadChunk(x, z, false, false);
                        Console.SetCursorPosition(cursorH, Console.CursorTop);
                        count++; Console.Write((int)((count / total) * 100) + "%");
                    }
                    //Logger.Log(x + " Row Generated.");
                }
            }

            Console.Write("\r");

            Logger.Log("Look distance = " + Server.ViewDistance);

            Init();
            physics.Start();

            if (World.WorldLoad != null)
                World.WorldLoad(this);
        }