当前位置: 首页>>代码示例>>C#>>正文


C# World.LoadChunk方法代码示例

本文整理汇总了C#中SMP.World.LoadChunk方法的典型用法代码示例。如果您正苦于以下问题:C# World.LoadChunk方法的具体用法?C# World.LoadChunk怎么用?C# World.LoadChunk使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SMP.World的用法示例。


在下文中一共展示了World.LoadChunk方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoadLVL


//.........这里部分代码省略.........
                                    w.chunkData.Add(new Point(x, z), c);
                        }
                        catch (Exception ex)
                        {
                            Logger.Log(ex.ToString());
                        }
                    });
                }
                else{
                    for (int i = 0; i < chunkcount; i++)
                    {
                        try
                        {
                            int block = (int)i * 32776;
                            int x = BitConverter.ToInt32(bytes, 0 + block);
                            int z = BitConverter.ToInt32(bytes, 4 + block);
                            Chunk c = new Chunk(x, z);
                            Array.Copy(bytes, 8 + block, c.blocks, 0, 32768);
                            c.RecalculateLight();
                            c.SpreadLight();
                            lock (w.chunkData)
                                if (!w.chunkData.ContainsKey(new Point(x, z)))
                                    w.chunkData.Add(new Point(x, z), c);
                        }
                        catch (Exception ex)
                        {
                            Logger.Log(ex.ToString());
                        }
                    }
                }
            }*/

            try
            {
                using (StreamReader sw = new StreamReader(filename + "/" + filename + ".ini"))
                {
                    w.seed = long.Parse(sw.ReadLine());
                    w.SpawnX = int.Parse(sw.ReadLine());
                    w.SpawnY = int.Parse(sw.ReadLine());
                    w.SpawnZ = int.Parse(sw.ReadLine());
                    w.ChunkLimit = int.Parse(sw.ReadLine());
                    w.time = long.Parse(sw.ReadLine());
                    w.dimension = sbyte.Parse(sw.ReadLine());
                    w.moonPhase = byte.Parse(sw.ReadLine());
                }
            }
            catch { /*Logger.Log("Error loading world configuration!");*/ }

            w.physics = new Physics(w);
            w.generator = new GenStandard(w, true);
            w.chunkManager = new WorldChunkManager(w);

            int cursorH = 22 + w.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
            {
                Parallel.For(((int)w.SpawnX >> 4) - Server.ViewDistance, ((int)w.SpawnX >> 4) + Server.ViewDistance + 1, x =>
                {
                    Parallel.For(((int)w.SpawnZ >> 4) - Server.ViewDistance, ((int)w.SpawnZ >> 4) + Server.ViewDistance + 1, z =>
                    {
                        w.LoadChunk(x, z, false, false);
                        lock (derpLock)
                        {
                            Console.SetCursorPosition(cursorH, Console.CursorTop);
                            count++; Console.Write((int)((count / total) * 100) + "%");
                        }
                    });
                });
            }
            catch (NotImplementedException)
            {
                for (int x = ((int)w.SpawnX >> 4) - Server.ViewDistance; x < ((int)w.SpawnX >> 4) + Server.ViewDistance + 1; x++)
                {
                    for (int z = ((int)w.SpawnZ >> 4) - Server.ViewDistance; z < ((int)w.SpawnZ >> 4) + Server.ViewDistance + 1; z++)
                    {
                        w.LoadChunk(x, z, false, false);
                        Console.SetCursorPosition(cursorH, Console.CursorTop);
                        count++; Console.Write((int)((count / total) * 100) + "%");
                    }
                }
            }

            Console.WriteLine();

            World.worlds.Add(w);
            Logger.Log(filename + " Loaded.");
            Logger.Log("Look distance = " + Server.ViewDistance);

            w.Init();
            w.physics.Start();

            if (World.WorldLoad != null)
                World.WorldLoad(w);

            return w;
        }
开发者ID:Nerketur,项目名称:ForgeCraft,代码行数:101,代码来源:World.cs

示例2: GetChunk

        //We should never default
        //public static Chunk GetChunk(int x, int z)
        //{
        //        return Server.mainlevel.chunkData[new Point(x, z)];
        //}
        public static Chunk GetChunk(int x, int z, World world, bool overRide = false)
        {
            Point po = new Point(x, z);

            if (overRide && !world.chunkData.ContainsKey(po))
                world.LoadChunk(z, z, false, false);
            if (world.chunkData.ContainsKey(po))
                return world.chunkData[po];
            return null;
        }
开发者ID:Cazzar,项目名称:ForgeCraft,代码行数:15,代码来源:Chunk.cs

示例3: LoadLVL

        public static World LoadLVL(string filename)
        {
            //TODO make loading/saving better.
            //if (WorldLoad != null)
            //	WorldLoad(this);
            World w = new World() { chunkData = new Dictionary<Point, Chunk>(), name = filename };
            Server.Log("Loading...");

            /*using (MemoryStream ms = new MemoryStream())
            {
                using (FileStream fs = new FileStream(filename + "/" + filename + ".blocks", FileMode.Open))
                {
                    byte[] comp;
                    ms.SetLength(fs.Length);
                    fs.Read(ms.GetBuffer(), 0, (int)fs.Length);
                    DecompressData(ms.GetBuffer(), out comp);
                    ms.Write(comp, 0, comp.Length);
                }
                byte[] bytes = ms.ToArray();
                long chunkcount = ms.Length / 32776;

                if(!Program.RunningInMono()) //mono doesn't have Parallel.For(long, long, Syatem.Action<long>) implemented
                {
                    Parallel.For(0, chunkcount, i =>
                    {
                        try
                        {
                            int block = (int)i * 32776;
                            int x = BitConverter.ToInt32(bytes, 0 + block);
                            int z = BitConverter.ToInt32(bytes, 4 + block);
                            Chunk c = new Chunk(x, z);
                            Array.Copy(bytes, 8 + block, c.blocks, 0, 32768);
                            c.RecalculateLight();
                            c.SpreadLight();
                            lock (w.chunkData)
                                if (!w.chunkData.ContainsKey(new Point(x, z)))
                                    w.chunkData.Add(new Point(x, z), c);
                        }
                        catch (Exception ex)
                        {
                            Server.Log(ex.ToString());
                        }
                    });
                }
                else{
                    for (int i = 0; i < chunkcount; i++)
                    {
                        try
                        {
                            int block = (int)i * 32776;
                            int x = BitConverter.ToInt32(bytes, 0 + block);
                            int z = BitConverter.ToInt32(bytes, 4 + block);
                            Chunk c = new Chunk(x, z);
                            Array.Copy(bytes, 8 + block, c.blocks, 0, 32768);
                            c.RecalculateLight();
                            c.SpreadLight();
                            lock (w.chunkData)
                                if (!w.chunkData.ContainsKey(new Point(x, z)))
                                    w.chunkData.Add(new Point(x, z), c);
                        }
                        catch (Exception ex)
                        {
                            Server.Log(ex.ToString());
                        }
                    }
                }
            }*/

            using (StreamReader sw = new StreamReader(filename + "/" + filename + ".ini"))
            {
                w.seed = long.Parse(sw.ReadLine());
                w.SpawnX = int.Parse(sw.ReadLine());
                w.SpawnY = int.Parse(sw.ReadLine());
                w.SpawnZ = int.Parse(sw.ReadLine());
                w.ChunkLimit = int.Parse(sw.ReadLine());
                w.time = long.Parse(sw.ReadLine());
            }

            w.generator = new GenStandard(w, true);
            w.physics = new Physics(w);

            try
            {
                Parallel.For(-3, 4, x =>
                {
                    Parallel.For(-3, 4, z =>
                    {
                        w.LoadChunk(x, z, false);
                    });
                });
            }
            catch (NotImplementedException)
            {
                for (int x = -3; x < 4; x++)
                {
                    for (int z = -3; z < 4; z++)
                    {
                        w.LoadChunk(x, z, false);
                    }
                }
//.........这里部分代码省略.........
开发者ID:eszanto8,项目名称:ForgeCraft,代码行数:101,代码来源:World.cs


注:本文中的SMP.World.LoadChunk方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。