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


C# Server.DistanceSquared方法代码示例

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


在下文中一共展示了Server.DistanceSquared方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: FindNearEntities

    void FindNearEntities(Server server, ClientOnServer c, int maxCount, ServerEntityId[] ret)
    {
        List<ServerEntityId> list = new List<ServerEntityId>();
        int playerx = c.PositionMul32GlX / 32;
        int playery = c.PositionMul32GlZ / 32;
        int playerz = c.PositionMul32GlY / 32;
        // Find all entities in 3x3x3 chunks around player.
        for (int xx = -1; xx < 2; xx++)
        {
            for (int yy = -1; yy < 2; yy++)
            {
                for (int zz = -1; zz < 2; zz++)
                {
                    int chunkx = playerx / Server.chunksize + xx;
                    int chunky = playery / Server.chunksize + yy;
                    int chunkz = playerz / Server.chunksize + zz;
                    if (!MapUtil.IsValidChunkPos(server.d_Map, chunkx, chunky, chunkz, Server.chunksize))
                    {
                        continue;
                    }
                    ServerChunk chunk = server.d_Map.GetChunk(chunkx * Server.chunksize, chunky * Server.chunksize, chunkz * Server.chunksize);
                    if (chunk == null)
                    {
                        continue;
                    }
                    if (chunk.Entities == null)
                    {
                        continue;
                    }
                    for (int i = 0; i < chunk.EntitiesCount; i++)
                    {
                        if (chunk.Entities[i] == null)
                        {
                            continue;
                        }
                        if (chunk.Entities[i].position == null)
                        {
                            continue;
                        }
                        ServerEntityId id = new ServerEntityId();
                        id.chunkx = chunkx;
                        id.chunky = chunky;
                        id.chunkz = chunkz;
                        id.id = i;
                        list.Add(id);
                    }
                }
            }
        }
        // Return maxCount of entities nearest to player.

        list.Sort((a, b) =>
        {
            var entityA = server.d_Map.GetChunk(a.chunkx * Server.chunksize, a.chunky * Server.chunksize, a.chunkz * Server.chunksize).Entities[a.id];
            var entityB = server.d_Map.GetChunk(b.chunkx * Server.chunksize, b.chunky * Server.chunksize, b.chunkz * Server.chunksize).Entities[b.id];

            Vector3i posA = new Vector3i((int)entityA.position.x, (int)entityA.position.y, (int)entityA.position.z);
            Vector3i posB = new Vector3i((int)entityB.position.x, (int)entityB.position.y, (int)entityB.position.z);
            Vector3i posPlayer = new Vector3i(c.PositionMul32GlX / 32, c.PositionMul32GlY / 32, c.PositionMul32GlZ / 32);
            return server.DistanceSquared(posA, posPlayer).CompareTo(server.DistanceSquared(posB, posPlayer));
        }
        );

        int retCount = maxCount;
        if (list.Count < maxCount)
        {
            retCount = list.Count;
        }
        for (int i = 0; i < retCount; i++)
        {
            ret[i] = list[i];
        }
    }
开发者ID:MagistrAVSH,项目名称:manicdigger,代码行数:73,代码来源:NotifyEntities.cs

示例3: NotifyPlayerPositions

 // EntityPositionAndOrientation
 void NotifyPlayerPositions(Server server, int clientid, float dt)
 {
     ClientOnServer c = server.clients[clientid];
     c.notifyPlayerPositionsAccum += dt;
     if (c.notifyPlayerPositionsAccum < (one / PlayerPositionUpdatesPerSecond))
     {
         return;
     }
     c.notifyPlayerPositionsAccum = 0;
     foreach (var k in server.clients)
     {
         if (k.Value.state != ClientStateOnServer.Playing)
         {
             continue;
         }
         if (!c.IsSpectator && k.Value.IsSpectator)
         {
             // Do not send position updates for spectating players if player is not spectator himself
             continue;
         }
         if (k.Key == clientid)
         {
             if (k.Value.positionOverride == null)
             {
                 continue;
             }
             else
             {
                 k.Value.entity.position = k.Value.positionOverride;
                 k.Value.positionOverride = null;
             }
         }
         else
         {
             if (server.DistanceSquared(server.PlayerBlockPosition(server.clients[k.Key]), server.PlayerBlockPosition(server.clients[clientid])) > server.config.PlayerDrawDistance * server.config.PlayerDrawDistance)
             {
                 continue;
             }
         }
         Packet_PositionAndOrientation position = ToNetworkEntityPosition(server.serverPlatform, server.clients[k.Key].entity.position);
         server.SendPacket(clientid, ServerPackets.EntityPositionAndOrientation(k.Key, position));
     }
 }
开发者ID:MagistrAVSH,项目名称:manicdigger,代码行数:44,代码来源:NotifyEntities.cs


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