diff options
author | UbitUmarov | 2019-04-04 18:55:40 +0100 |
---|---|---|
committer | UbitUmarov | 2019-04-04 18:55:40 +0100 |
commit | a56f40470efd0b3ca6000cb4561efc59c6b3c25e (patch) | |
tree | 27e006f9b9a87fa94a0f04a793b8890df2b95f8a /OpenSim/Region/CoreModules/Framework | |
parent | change region cacheid on restart. This should not be needed in future if obje... (diff) | |
download | opensim-SC-a56f40470efd0b3ca6000cb4561efc59c6b3c25e.zip opensim-SC-a56f40470efd0b3ca6000cb4561efc59c6b3c25e.tar.gz opensim-SC-a56f40470efd0b3ca6000cb4561efc59c6b3c25e.tar.bz2 opensim-SC-a56f40470efd0b3ca6000cb4561efc59c6b3c25e.tar.xz |
control visible regions by avatar position and view range, first dirty code
Diffstat (limited to 'OpenSim/Region/CoreModules/Framework')
-rw-r--r-- | OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs | 358 |
1 files changed, 276 insertions, 82 deletions
diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs index 6b3e8c4..b4ac968 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs | |||
@@ -1932,12 +1932,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer | |||
1932 | 1932 | ||
1933 | if (seeds.ContainsKey(regionhandler)) | 1933 | if (seeds.ContainsKey(regionhandler)) |
1934 | seeds.Remove(regionhandler); | 1934 | seeds.Remove(regionhandler); |
1935 | /* | ||
1936 | List<ulong> oldregions = new List<ulong>(seeds.Keys); | ||
1937 | 1935 | ||
1938 | if (oldregions.Contains(currentRegionHandler)) | ||
1939 | oldregions.Remove(currentRegionHandler); | ||
1940 | */ | ||
1941 | if (!seeds.ContainsKey(currentRegionHandler)) | 1936 | if (!seeds.ContainsKey(currentRegionHandler)) |
1942 | seeds.Add(currentRegionHandler, sp.ControllingClient.RequestClientInfo().CapsPath); | 1937 | seeds.Add(currentRegionHandler, sp.ControllingClient.RequestClientInfo().CapsPath); |
1943 | 1938 | ||
@@ -1975,24 +1970,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer | |||
1975 | agent.Mac = currentAgentCircuit.Mac; | 1970 | agent.Mac = currentAgentCircuit.Mac; |
1976 | agent.Id0 = currentAgentCircuit.Id0; | 1971 | agent.Id0 = currentAgentCircuit.Id0; |
1977 | } | 1972 | } |
1978 | /* | ||
1979 | AgentPosition agentpos = null; | ||
1980 | 1973 | ||
1981 | if (oldregions.Count > 0) | ||
1982 | { | ||
1983 | agentpos = new AgentPosition(); | ||
1984 | agentpos.AgentID = new UUID(sp.UUID.Guid); | ||
1985 | agentpos.SessionID = sp.ControllingClient.SessionId; | ||
1986 | agentpos.Size = sp.Appearance.AvatarSize; | ||
1987 | agentpos.Center = sp.CameraPosition; | ||
1988 | agentpos.Far = sp.DrawDistance; | ||
1989 | agentpos.Position = sp.AbsolutePosition; | ||
1990 | agentpos.Velocity = sp.Velocity; | ||
1991 | agentpos.RegionHandle = currentRegionHandler; | ||
1992 | agentpos.Throttles = sp.ControllingClient.GetThrottlesPacked(1); | ||
1993 | agentpos.ChildrenCapSeeds = seeds; | ||
1994 | } | ||
1995 | */ | ||
1996 | IPEndPoint external = region.ExternalEndPoint; | 1974 | IPEndPoint external = region.ExternalEndPoint; |
1997 | if (external != null) | 1975 | if (external != null) |
1998 | { | 1976 | { |
@@ -2001,20 +1979,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer | |||
2001 | InformClientOfNeighbourCompleted, | 1979 | InformClientOfNeighbourCompleted, |
2002 | d); | 1980 | d); |
2003 | } | 1981 | } |
2004 | /* | ||
2005 | if(oldregions.Count >0) | ||
2006 | { | ||
2007 | uint neighbourx; | ||
2008 | uint neighboury; | ||
2009 | UUID scope = sp.Scene.RegionInfo.ScopeID; | ||
2010 | foreach (ulong handler in oldregions) | ||
2011 | { | ||
2012 | Utils.LongToUInts(handler, out neighbourx, out neighboury); | ||
2013 | GridRegion neighbour = sp.Scene.GridService.GetRegionByPosition(scope, (int)neighbourx, (int)neighboury); | ||
2014 | sp.Scene.SimulationService.UpdateAgent(neighbour, agentpos); | ||
2015 | } | ||
2016 | } | ||
2017 | */ | ||
2018 | } | 1982 | } |
2019 | 1983 | ||
2020 | #endregion | 1984 | #endregion |
@@ -2024,6 +1988,44 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer | |||
2024 | private delegate void InformClientOfNeighbourDelegate( | 1988 | private delegate void InformClientOfNeighbourDelegate( |
2025 | ScenePresence avatar, AgentCircuitData a, GridRegion reg, IPEndPoint endPoint, bool newAgent); | 1989 | ScenePresence avatar, AgentCircuitData a, GridRegion reg, IPEndPoint endPoint, bool newAgent); |
2026 | 1990 | ||
1991 | List<GridRegion> RegionsInView(Vector3 pos, RegionInfo curregion, List<GridRegion> fullneighbours, float viewrange) | ||
1992 | { | ||
1993 | List<GridRegion> ret = new List<GridRegion>(); | ||
1994 | if(fullneighbours.Count == 0) | ||
1995 | return ret; | ||
1996 | |||
1997 | int curX = (int)Util.RegionToWorldLoc(curregion.RegionLocX) + (int)pos.X; | ||
1998 | int minX = curX - (int)viewrange; | ||
1999 | int maxX = curX + (int)viewrange; | ||
2000 | int curY = (int)Util.RegionToWorldLoc(curregion.RegionLocY) + (int)pos.Y; | ||
2001 | int minY = curY - (int)viewrange; | ||
2002 | int maxY = curY + (int)viewrange; | ||
2003 | int rtmp; | ||
2004 | |||
2005 | foreach (GridRegion r in fullneighbours) | ||
2006 | { | ||
2007 | OpenSim.Framework.RegionFlags? regionFlags = r.RegionFlags; | ||
2008 | if (regionFlags != null) | ||
2009 | { | ||
2010 | if ((regionFlags & OpenSim.Framework.RegionFlags.RegionOnline) == 0) | ||
2011 | continue; | ||
2012 | } | ||
2013 | |||
2014 | rtmp = r.RegionLocX; | ||
2015 | if (maxX < rtmp) | ||
2016 | continue; | ||
2017 | if (minX > rtmp + r.RegionSizeX) | ||
2018 | continue; | ||
2019 | rtmp = r.RegionLocY; | ||
2020 | if (maxY < rtmp) | ||
2021 | continue; | ||
2022 | if (minY > rtmp + r.RegionSizeY) | ||
2023 | continue; | ||
2024 | ret.Add(r); | ||
2025 | } | ||
2026 | return ret; | ||
2027 | } | ||
2028 | |||
2027 | /// <summary> | 2029 | /// <summary> |
2028 | /// This informs all neighbouring regions about agent "avatar". | 2030 | /// This informs all neighbouring regions about agent "avatar". |
2029 | /// and as important informs the avatar about then | 2031 | /// and as important informs the avatar about then |
@@ -2033,20 +2035,16 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer | |||
2033 | { | 2035 | { |
2034 | // assumes that out of view range regions are disconnected by the previus region | 2036 | // assumes that out of view range regions are disconnected by the previus region |
2035 | 2037 | ||
2036 | List<GridRegion> neighbours = new List<GridRegion>(); | ||
2037 | Scene spScene = sp.Scene; | 2038 | Scene spScene = sp.Scene; |
2038 | RegionInfo m_regionInfo = spScene.RegionInfo; | 2039 | RegionInfo regionInfo = spScene.RegionInfo; |
2039 | 2040 | ||
2040 | if (m_regionInfo != null) | 2041 | if (regionInfo == null) |
2041 | { | 2042 | return; |
2042 | neighbours = GetNeighbors(sp, m_regionInfo.RegionLocX, m_regionInfo.RegionLocY); | 2043 | |
2043 | } | 2044 | ulong currentRegionHandler = regionInfo.RegionHandle; |
2044 | else | ||
2045 | { | ||
2046 | m_log.Debug("[ENTITY TRANSFER MODULE]: m_regionInfo was null in EnableChildAgents, is this a NPC?"); | ||
2047 | } | ||
2048 | 2045 | ||
2049 | ulong currentRegionHandler = m_regionInfo.RegionHandle; | 2046 | List<GridRegion> fullneighbours = GetNeighbors(sp); |
2047 | List<GridRegion> neighbours = RegionsInView(sp.AbsolutePosition, regionInfo, fullneighbours, sp.RegionViewDistance); | ||
2050 | 2048 | ||
2051 | LinkedList<ulong> previousRegionNeighbourHandles; | 2049 | LinkedList<ulong> previousRegionNeighbourHandles; |
2052 | Dictionary<ulong, string> seeds; | 2050 | Dictionary<ulong, string> seeds; |
@@ -2082,13 +2080,11 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer | |||
2082 | List<AgentCircuitData> cagents = new List<AgentCircuitData>(); | 2080 | List<AgentCircuitData> cagents = new List<AgentCircuitData>(); |
2083 | List<ulong> newneighbours = new List<ulong>(); | 2081 | List<ulong> newneighbours = new List<ulong>(); |
2084 | 2082 | ||
2085 | bool notHG = (sp.TeleportFlags & Constants.TeleportFlags.ViaHGLogin) == 0; | ||
2086 | |||
2087 | foreach (GridRegion neighbour in neighbours) | 2083 | foreach (GridRegion neighbour in neighbours) |
2088 | { | 2084 | { |
2089 | ulong handler = neighbour.RegionHandle; | 2085 | ulong handler = neighbour.RegionHandle; |
2090 | 2086 | ||
2091 | if (notHG && previousRegionNeighbourHandles.Contains(handler)) | 2087 | if (previousRegionNeighbourHandles.Contains(handler)) |
2092 | { | 2088 | { |
2093 | // agent already knows this region | 2089 | // agent already knows this region |
2094 | previousRegionNeighbourHandles.Remove(handler); | 2090 | previousRegionNeighbourHandles.Remove(handler); |
@@ -2135,13 +2131,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer | |||
2135 | foreach (ulong handler in previousRegionNeighbourHandles) | 2131 | foreach (ulong handler in previousRegionNeighbourHandles) |
2136 | seeds.Remove(handler); | 2132 | seeds.Remove(handler); |
2137 | 2133 | ||
2138 | if(notHG) // does not work on HG | 2134 | toclose = new List<ulong>(previousRegionNeighbourHandles); |
2139 | { | ||
2140 | toclose = new List<ulong>(previousRegionNeighbourHandles); | ||
2141 | // sp.CloseChildAgents(toclose); | ||
2142 | } | ||
2143 | else | ||
2144 | toclose = new List<ulong>(); | ||
2145 | } | 2135 | } |
2146 | else | 2136 | else |
2147 | toclose = new List<ulong>(); | 2137 | toclose = new List<ulong>(); |
@@ -2173,7 +2163,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer | |||
2173 | 2163 | ||
2174 | Util.FireAndForget(delegate | 2164 | Util.FireAndForget(delegate |
2175 | { | 2165 | { |
2176 | Thread.Sleep(500); // the original delay that was at InformClientOfNeighbourAsync start | ||
2177 | int count = 0; | 2166 | int count = 0; |
2178 | IPEndPoint ipe; | 2167 | IPEndPoint ipe; |
2179 | 2168 | ||
@@ -2196,10 +2185,12 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer | |||
2196 | } | 2185 | } |
2197 | count++; | 2186 | count++; |
2198 | } | 2187 | } |
2199 | else if (notHG && !previousRegionNeighbourHandles.Contains(handler)) | 2188 | else if (!previousRegionNeighbourHandles.Contains(handler)) |
2200 | { | 2189 | { |
2201 | spScene.SimulationService.UpdateAgent(neighbour, agentpos); | 2190 | spScene.SimulationService.UpdateAgent(neighbour, agentpos); |
2202 | } | 2191 | } |
2192 | if (sp.IsDeleted) | ||
2193 | return; | ||
2203 | } | 2194 | } |
2204 | catch (Exception e) | 2195 | catch (Exception e) |
2205 | { | 2196 | { |
@@ -2216,6 +2207,202 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer | |||
2216 | } | 2207 | } |
2217 | } | 2208 | } |
2218 | 2209 | ||
2210 | public void CheckChildAgents(ScenePresence sp) | ||
2211 | { | ||
2212 | // assumes that out of view range regions are disconnected by the previus region | ||
2213 | |||
2214 | Scene spScene = sp.Scene; | ||
2215 | RegionInfo regionInfo = spScene.RegionInfo; | ||
2216 | |||
2217 | if (regionInfo == null) | ||
2218 | return; | ||
2219 | |||
2220 | ulong currentRegionHandler = regionInfo.RegionHandle; | ||
2221 | |||
2222 | List<GridRegion> fullneighbours = GetNeighbors(sp); | ||
2223 | List<GridRegion> neighbours = RegionsInView(sp.AbsolutePosition, regionInfo, fullneighbours, sp.RegionViewDistance); | ||
2224 | |||
2225 | LinkedList<ulong> previousRegionNeighbourHandles = new LinkedList<ulong>(sp.KnownRegions.Keys); | ||
2226 | |||
2227 | IClientAPI spClient = sp.ControllingClient; | ||
2228 | |||
2229 | AgentCircuitData currentAgentCircuit = | ||
2230 | spScene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode); | ||
2231 | |||
2232 | List<AgentCircuitData> cagents = new List<AgentCircuitData>(); | ||
2233 | List<GridRegion> newneighbours = new List<GridRegion>(); | ||
2234 | |||
2235 | foreach (GridRegion neighbour in neighbours) | ||
2236 | { | ||
2237 | ulong handler = neighbour.RegionHandle; | ||
2238 | |||
2239 | if (previousRegionNeighbourHandles.Contains(handler)) | ||
2240 | { | ||
2241 | // agent already knows this region | ||
2242 | previousRegionNeighbourHandles.Remove(handler); | ||
2243 | continue; | ||
2244 | } | ||
2245 | |||
2246 | if (handler == currentRegionHandler) | ||
2247 | continue; | ||
2248 | |||
2249 | // a new region to add | ||
2250 | AgentCircuitData agent = spClient.RequestClientInfo(); | ||
2251 | agent.BaseFolder = UUID.Zero; | ||
2252 | agent.InventoryFolder = UUID.Zero; | ||
2253 | agent.startpos = sp.AbsolutePosition + CalculateOffset(sp, neighbour); | ||
2254 | agent.child = true; | ||
2255 | agent.Appearance = new AvatarAppearance(); | ||
2256 | agent.Appearance.AvatarHeight = sp.Appearance.AvatarHeight; | ||
2257 | agent.startfar = sp.DrawDistance; | ||
2258 | if (currentAgentCircuit != null) | ||
2259 | { | ||
2260 | agent.ServiceURLs = currentAgentCircuit.ServiceURLs; | ||
2261 | agent.IPAddress = currentAgentCircuit.IPAddress; | ||
2262 | agent.Viewer = currentAgentCircuit.Viewer; | ||
2263 | agent.Channel = currentAgentCircuit.Channel; | ||
2264 | agent.Mac = currentAgentCircuit.Mac; | ||
2265 | agent.Id0 = currentAgentCircuit.Id0; | ||
2266 | } | ||
2267 | |||
2268 | newneighbours.Add(neighbour); | ||
2269 | agent.CapsPath = CapsUtil.GetRandomCapsObjectPath(); | ||
2270 | sp.AddNeighbourRegion(neighbour, agent.CapsPath); | ||
2271 | |||
2272 | agent.ChildrenCapSeeds = null; | ||
2273 | cagents.Add(agent); | ||
2274 | } | ||
2275 | |||
2276 | List<ulong> toclose; | ||
2277 | // previousRegionNeighbourHandles now contains regions to forget | ||
2278 | if (previousRegionNeighbourHandles.Count > 0) | ||
2279 | { | ||
2280 | if (previousRegionNeighbourHandles.Contains(currentRegionHandler)) | ||
2281 | previousRegionNeighbourHandles.Remove(currentRegionHandler); | ||
2282 | |||
2283 | foreach (ulong handler in previousRegionNeighbourHandles) | ||
2284 | sp.KnownRegions.Remove(handler); | ||
2285 | |||
2286 | toclose = new List<ulong>(previousRegionNeighbourHandles); | ||
2287 | } | ||
2288 | else | ||
2289 | toclose = new List<ulong>(); | ||
2290 | |||
2291 | ICapabilitiesModule capsModule = spScene.CapsModule; | ||
2292 | if (capsModule != null) | ||
2293 | capsModule.SetChildrenSeed(sp.UUID, sp.KnownRegions); | ||
2294 | |||
2295 | if (toclose.Count > 0) | ||
2296 | sp.CloseChildAgents(toclose); | ||
2297 | |||
2298 | if (newneighbours.Count > 0) | ||
2299 | { | ||
2300 | int count = 0; | ||
2301 | IPEndPoint ipe; | ||
2302 | |||
2303 | foreach (GridRegion neighbour in newneighbours) | ||
2304 | { | ||
2305 | try | ||
2306 | { | ||
2307 | ipe = neighbour.ExternalEndPoint; | ||
2308 | if (ipe != null) | ||
2309 | InformClientOfNeighbourAsync(sp, cagents[count], neighbour, ipe, true); | ||
2310 | else | ||
2311 | { | ||
2312 | m_log.DebugFormat("[ENTITY TRANSFER MODULE]: lost DNS resolution for neighbour {0}", neighbour.ExternalHostName); | ||
2313 | } | ||
2314 | count++; | ||
2315 | if (sp.IsDeleted) | ||
2316 | return; | ||
2317 | } | ||
2318 | catch (Exception e) | ||
2319 | { | ||
2320 | m_log.ErrorFormat( | ||
2321 | "[ENTITY TRANSFER MODULE]: Error creating child agent at {0} ({1} ({2}, {3}). {4}", | ||
2322 | neighbour.ExternalHostName, | ||
2323 | neighbour.RegionHandle, | ||
2324 | neighbour.RegionLocX, | ||
2325 | neighbour.RegionLocY, | ||
2326 | e); | ||
2327 | } | ||
2328 | } | ||
2329 | } | ||
2330 | } | ||
2331 | |||
2332 | public void CloseOldChildAgents(ScenePresence sp) | ||
2333 | { | ||
2334 | Scene spScene = sp.Scene; | ||
2335 | RegionInfo regionInfo = spScene.RegionInfo; | ||
2336 | |||
2337 | if (regionInfo == null) | ||
2338 | return; | ||
2339 | |||
2340 | ulong currentRegionHandler = regionInfo.RegionHandle; | ||
2341 | |||
2342 | List<GridRegion> fullneighbours = GetNeighbors(sp); | ||
2343 | List<GridRegion> neighbours = RegionsInView(sp.AbsolutePosition, regionInfo, fullneighbours, sp.RegionViewDistance); | ||
2344 | |||
2345 | LinkedList<ulong> previousRegionNeighbourHandles; | ||
2346 | Dictionary<ulong, string> seeds; | ||
2347 | ICapabilitiesModule capsModule = spScene.CapsModule; | ||
2348 | |||
2349 | if (capsModule != null) | ||
2350 | { | ||
2351 | seeds = new Dictionary<ulong, string>(capsModule.GetChildrenSeeds(sp.UUID)); | ||
2352 | previousRegionNeighbourHandles = new LinkedList<ulong>(seeds.Keys); | ||
2353 | } | ||
2354 | else | ||
2355 | { | ||
2356 | seeds = new Dictionary<ulong, string>(); | ||
2357 | previousRegionNeighbourHandles = new LinkedList<ulong>(); | ||
2358 | } | ||
2359 | |||
2360 | IClientAPI spClient = sp.ControllingClient; | ||
2361 | |||
2362 | // This will fail if the user aborts login | ||
2363 | try | ||
2364 | { | ||
2365 | if (!seeds.ContainsKey(currentRegionHandler)) | ||
2366 | seeds.Add(currentRegionHandler, spClient.RequestClientInfo().CapsPath); | ||
2367 | } | ||
2368 | catch | ||
2369 | { | ||
2370 | return; | ||
2371 | } | ||
2372 | |||
2373 | foreach (GridRegion neighbour in neighbours) | ||
2374 | { | ||
2375 | ulong handler = neighbour.RegionHandle; | ||
2376 | |||
2377 | if (previousRegionNeighbourHandles.Contains(handler)) | ||
2378 | previousRegionNeighbourHandles.Remove(handler); | ||
2379 | } | ||
2380 | |||
2381 | List<ulong> toclose; | ||
2382 | // previousRegionNeighbourHandles now contains regions to forget | ||
2383 | if (previousRegionNeighbourHandles.Count == 0) | ||
2384 | return; | ||
2385 | |||
2386 | if (previousRegionNeighbourHandles.Contains(currentRegionHandler)) | ||
2387 | previousRegionNeighbourHandles.Remove(currentRegionHandler); | ||
2388 | |||
2389 | foreach (ulong handler in previousRegionNeighbourHandles) | ||
2390 | seeds.Remove(handler); | ||
2391 | |||
2392 | toclose = new List<ulong>(previousRegionNeighbourHandles); | ||
2393 | |||
2394 | if (capsModule != null) | ||
2395 | capsModule.SetChildrenSeed(sp.UUID, seeds); | ||
2396 | |||
2397 | sp.KnownRegions = seeds; | ||
2398 | sp.SetNeighbourRegionSizeInfo(neighbours); | ||
2399 | |||
2400 | Util.FireAndForget(delegate | ||
2401 | { | ||
2402 | sp.CloseChildAgents(toclose); | ||
2403 | }); | ||
2404 | } | ||
2405 | |||
2219 | // Computes the difference between two region bases. | 2406 | // Computes the difference between two region bases. |
2220 | // Returns a vector of world coordinates (meters) from base of first region to the second. | 2407 | // Returns a vector of world coordinates (meters) from base of first region to the second. |
2221 | // The first region is the home region of the passed scene presence. | 2408 | // The first region is the home region of the passed scene presence. |
@@ -2416,6 +2603,11 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer | |||
2416 | 2603 | ||
2417 | } | 2604 | } |
2418 | 2605 | ||
2606 | // all this code should be moved to scene replacing the now bad one there | ||
2607 | // cache Neighbors | ||
2608 | List<GridRegion> Neighbors = null; | ||
2609 | DateTime LastNeighborsTime = DateTime.MinValue; | ||
2610 | |||
2419 | /// <summary> | 2611 | /// <summary> |
2420 | /// Return the list of online regions that are considered to be neighbours to the given scene. | 2612 | /// Return the list of online regions that are considered to be neighbours to the given scene. |
2421 | /// </summary> | 2613 | /// </summary> |
@@ -2423,39 +2615,41 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer | |||
2423 | /// <param name="pRegionLocX"></param> | 2615 | /// <param name="pRegionLocX"></param> |
2424 | /// <param name="pRegionLocY"></param> | 2616 | /// <param name="pRegionLocY"></param> |
2425 | /// <returns></returns> | 2617 | /// <returns></returns> |
2426 | protected List<GridRegion> GetNeighbors(ScenePresence avatar, uint pRegionLocX, uint pRegionLocY) | 2618 | protected List<GridRegion> GetNeighbors(ScenePresence avatar) |
2427 | { | 2619 | { |
2428 | Scene pScene = avatar.Scene; | 2620 | Scene pScene = avatar.Scene; |
2429 | RegionInfo m_regionInfo = pScene.RegionInfo; | ||
2430 | List<GridRegion> neighbours; | ||
2431 | 2621 | ||
2432 | uint dd = (uint)avatar.RegionViewDistance; | 2622 | uint dd = (uint)pScene.MaxRegionViewDistance; |
2623 | if(dd <= 1) | ||
2624 | return new List<GridRegion>(); | ||
2625 | |||
2626 | if (Neighbors != null && (DateTime.UtcNow - LastNeighborsTime).TotalSeconds < 30) | ||
2627 | { | ||
2628 | return Neighbors; | ||
2629 | } | ||
2433 | 2630 | ||
2434 | // until avatar movement updates client connections, we need to send at least this current region immediate neighbors | 2631 | RegionInfo regionInfo = pScene.RegionInfo; |
2435 | uint ddX = Math.Max(dd, Constants.RegionSize); | 2632 | List<GridRegion> neighbours; |
2436 | uint ddY = Math.Max(dd, Constants.RegionSize); | ||
2437 | 2633 | ||
2438 | ddX--; | 2634 | dd--; |
2439 | ddY--; | ||
2440 | 2635 | ||
2441 | // reference to region edges. Should be avatar position | 2636 | uint startX = Util.RegionToWorldLoc(regionInfo.RegionLocX); |
2442 | uint startX = Util.RegionToWorldLoc(pRegionLocX); | 2637 | uint endX = startX + regionInfo.RegionSizeX; |
2443 | uint endX = startX + m_regionInfo.RegionSizeX; | 2638 | uint startY = Util.RegionToWorldLoc(regionInfo.RegionLocY); |
2444 | uint startY = Util.RegionToWorldLoc(pRegionLocY); | 2639 | uint endY = startY + regionInfo.RegionSizeY; |
2445 | uint endY = startY + m_regionInfo.RegionSizeY; | ||
2446 | 2640 | ||
2447 | startX -= ddX; | 2641 | startX -= dd; |
2448 | startY -= ddY; | 2642 | startY -= dd; |
2449 | endX += ddX; | 2643 | endX += dd; |
2450 | endY += ddY; | 2644 | endY += dd; |
2451 | 2645 | ||
2452 | neighbours | 2646 | neighbours = avatar.Scene.GridService.GetRegionRange( |
2453 | = avatar.Scene.GridService.GetRegionRange( | 2647 | regionInfo.ScopeID, (int)startX, (int)endX, (int)startY, (int)endY); |
2454 | m_regionInfo.ScopeID, (int)startX, (int)endX, (int)startY, (int)endY); | ||
2455 | 2648 | ||
2456 | // The r.RegionFlags == null check only needs to be made for simulators before 2015-01-14 (pre 0.8.1). | 2649 | // The r.RegionFlags == null check only needs to be made for simulators before 2015-01-14 (pre 0.8.1). |
2457 | neighbours.RemoveAll( r => r.RegionID == m_regionInfo.RegionID ); | 2650 | neighbours.RemoveAll( r => r.RegionID == regionInfo.RegionID ); |
2458 | 2651 | Neighbors = neighbours; | |
2652 | LastNeighborsTime = DateTime.UtcNow; | ||
2459 | return neighbours; | 2653 | return neighbours; |
2460 | } | 2654 | } |
2461 | #endregion | 2655 | #endregion |