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


C# IGridService.GetRegionByPosition方法代码示例

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


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

示例1: GetRegionContainingWorldLocation

        // Given a world position (fractional meter coordinate), get the GridRegion info for
        //   the region containing that point.
        // Someday this should be a method on GridService.
        // 'pSizeHint' is the size of the source region but since the destination point can be anywhere
        //     the size of the target region is unknown thus the search area might have to be very large.
        // Return 'null' if no such region exists.
        public GridRegion GetRegionContainingWorldLocation(IGridService pGridService, UUID pScopeID,
                            double px, double py, uint pSizeHint)
        {
            m_log.DebugFormat("{0} GetRegionContainingWorldLocation: query, loc=<{1},{2}>", LogHeader, px, py);
            GridRegion ret = null;
            const double fudge = 2.0;

            // One problem with this routine is negative results. That is, this can be called lots of times
            //   for regions that don't exist. m_notFoundLocationCache remembers 'not found' results so they
            //   will be quick 'not found's next time.
            // NotFoundLocationCache is an expiring cache so it will eventually forget about 'not found' and
            //   thus re-ask the GridService about the location.
            if (m_notFoundLocationCache.Contains(px, py))
            {
                m_log.DebugFormat("{0} GetRegionContainingWorldLocation: Not found via cache. loc=<{1},{2}>", LogHeader, px, py);
                return null;
            }

            // As an optimization, since most regions will be legacy sized regions (256x256), first try to get
            //   the region at the appropriate legacy region location.
            uint possibleX = (uint)Math.Floor(px);
            possibleX -= possibleX % Constants.RegionSize;
            uint possibleY = (uint)Math.Floor(py);
            possibleY -= possibleY % Constants.RegionSize;
            ret = pGridService.GetRegionByPosition(pScopeID, (int)possibleX, (int)possibleY);
            if (ret != null)
            {
                m_log.DebugFormat("{0} GetRegionContainingWorldLocation: Found region using legacy size. rloc=<{1},{2}>. Rname={3}",
                                    LogHeader, possibleX, possibleY, ret.RegionName);
            }

            if (ret == null)
            {
                // If the simple lookup failed, search the larger area for a region that contains this point
                double range = (double)pSizeHint + fudge;
                while (ret == null && range <= (Constants.MaximumRegionSize + Constants.RegionSize))
                {
                    // Get from the grid service a list of regions that might contain this point.
                    // The region origin will be in the zero direction so only subtract the range.
                    List<GridRegion> possibleRegions = pGridService.GetRegionRange(pScopeID,
                                        (int)(px - range), (int)(px),
                                        (int)(py - range), (int)(py));
                    m_log.DebugFormat("{0} GetRegionContainingWorldLocation: possibleRegions cnt={1}, range={2}",
                                        LogHeader, possibleRegions.Count, range);
                    if (possibleRegions != null && possibleRegions.Count > 0)
                    {
                        // If we found some regions, check to see if the point is within
                        foreach (GridRegion gr in possibleRegions)
                        {
                            m_log.DebugFormat("{0} GetRegionContainingWorldLocation: possibleRegion nm={1}, regionLoc=<{2},{3}>, regionSize=<{4},{5}>",
                                                LogHeader, gr.RegionName, gr.RegionLocX, gr.RegionLocY, gr.RegionSizeX, gr.RegionSizeY);
                            if (px >= (double)gr.RegionLocX && px < (double)(gr.RegionLocX + gr.RegionSizeX)
                                && py >= (double)gr.RegionLocY && py < (double)(gr.RegionLocY + gr.RegionSizeY))
                            {
                                // Found a region that contains the point
                                ret = gr;
                                m_log.DebugFormat("{0} GetRegionContainingWorldLocation: found. RegionName={1}", LogHeader, ret.RegionName);
                                break;
                            }
                        }
                    }
                    // Larger search area for next time around if not found
                    range *= 2;
                }
            }

            if (ret == null)
            {
                // remember this location was not found so we can quickly not find it next time
                m_notFoundLocationCache.Add(px, py);
                m_log.DebugFormat("{0} GetRegionContainingWorldLocation: Not found. Remembering loc=<{1},{2}>", LogHeader, px, py);
            }

            return ret;
        }
开发者ID:Kubwa,项目名称:opensim,代码行数:81,代码来源:EntityTransferModule.cs


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