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


C# Server.mapsizeychunks方法代码示例

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


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

示例1: Update

    public override void Update(Server server, float dt)
    {
        int sizexchunks = server.mapsizexchunks();
        int sizeychunks = server.mapsizeychunks();
        int sizezchunks = server.mapsizezchunks();

        for (int i = 0; i < 100; i++)
        {
            MapUtilCi.PosInt(CompressUnusedIteration, sizexchunks, sizeychunks, chunkpos);
            ServerChunk c = server.d_Map.GetChunkValid(chunkpos.X, chunkpos.Y, chunkpos.Z);
            bool stop = false;
            if (c != null)
            {
                var globalpos = new Vector3i(chunkpos.X * Server.chunksize, chunkpos.Y * Server.chunksize, chunkpos.Z * Server.chunksize);
                bool unload = true;
                foreach (var k in server.clients)
                {
                    if (k.Value.IsBot)
                    {
                        // don't hold chunks in memory for bots
                        continue;
                    }
                    // unload distance = view distance + 60% (prevents chunks from being unloaded too early (square loading vs. circular unloading))
                    int viewdist = (int)(server.chunkdrawdistance * Server.chunksize * 1.8f);
                    if (server.DistanceSquared(server.PlayerBlockPosition(k.Value), globalpos) <= viewdist * viewdist)
                    {
                        //System.Console.WriteLine("No Unload:   {0},{1},{2}", chunkpos.X, chunkpos.Y, chunkpos.Z);
                        unload = false;
                    }
                }
                if (unload)
                {
                    // unload if chunk isn't seen by anyone
                    if (c.DirtyForSaving)
                    {
                        // save changes to disk if necessary
                        server.DoSaveChunk(chunkpos.X, chunkpos.Y, chunkpos.Z, c);
                    }
                    server.d_Map.SetChunkValid(chunkpos.X, chunkpos.Y, chunkpos.Z, null);
                    foreach (var client in server.clients)
                    {
                        // mark chunks unseen for all players
                        server.ClientSeenChunkRemove(client.Key, chunkpos.X, chunkpos.Y, chunkpos.Z);
                    }
                    stop = true;
                }
            }
            CompressUnusedIteration++;
            if (CompressUnusedIteration >= sizexchunks * sizeychunks * sizezchunks)
            {
                CompressUnusedIteration = 0;
            }
            if (stop)
            {
                // only unload one chunk at a time
                return;
            }
        }
    }
开发者ID:MagistrAVSH,项目名称:manicdigger,代码行数:59,代码来源:UnloadUnusedChunks.cs

示例2: NearestDirty

    void NearestDirty(Server server, int clientid, int playerx, int playery, int playerz, int[] retNearest)
    {
        int nearestdist = intMaxValue;
        retNearest[0] = -1;
        retNearest[1] = -1;
        retNearest[2] = -1;
        int px = (int)(playerx) / Server.chunksize;
        int py = (int)(playery) / Server.chunksize;
        int pz = (int)(playerz) / Server.chunksize;

        int chunksxy = mapAreaSize(server) / Server.chunksize / 2;
        int chunksz = mapAreaSizeZ(server) / Server.chunksize / 2;

        int startx = px - chunksxy;
        int endx = px + chunksxy;
        int starty = py - chunksxy;
        int endy = py + chunksxy;
        int startz = pz - chunksz;
        int endz = pz + chunksz;

        if (startx < 0) { startx = 0; }
        if (starty < 0) { starty = 0; }
        if (startz < 0) { startz = 0; }
        if (endx >= server.mapsizexchunks()) { endx = server.mapsizexchunks() - 1; }
        if (endy >= server.mapsizeychunks()) { endy = server.mapsizeychunks() - 1; }
        if (endz >= server.mapsizezchunks()) { endz = server.mapsizezchunks() - 1; }

        for (int x = startx; x <= endx; x++)
        {
            for (int y = starty; y <= endy; y++)
            {
                for (int z = startz; z <= endz; z++)
                {
                    if (server.ClientSeenChunk(clientid, x, y, z))
                    {
                        continue;
                    }
                    {
                        int dx = px - x;
                        int dy = py - y;
                        int dz = pz - z;
                        int dist = dx * dx + dy * dy + dz * dz;
                        if (dist < nearestdist)
                        {
                            nearestdist = dist;
                            retNearest[0] = x;
                            retNearest[1] = y;
                            retNearest[2] = z;
                        }
                    }
                }
            }
        }
    }
开发者ID:MagistrAVSH,项目名称:manicdigger,代码行数:54,代码来源:NotifyMap.cs


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