diff options
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/SceneManager.cs')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/SceneManager.cs | 267 |
1 files changed, 92 insertions, 175 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneManager.cs b/OpenSim/Region/Framework/Scenes/SceneManager.cs index cb5b2ba..dba3a61 100644 --- a/OpenSim/Region/Framework/Scenes/SceneManager.cs +++ b/OpenSim/Region/Framework/Scenes/SceneManager.cs | |||
@@ -99,12 +99,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
99 | } | 99 | } |
100 | } | 100 | } |
101 | 101 | ||
102 | private readonly List<Scene> m_localScenes = new List<Scene>(); | 102 | private readonly DoubleDictionary<UUID, string, Scene> m_localScenes = new DoubleDictionary<UUID, string, Scene>(); |
103 | private Scene m_currentScene = null; | 103 | private Scene m_currentScene = null; |
104 | 104 | ||
105 | public List<Scene> Scenes | 105 | public List<Scene> Scenes |
106 | { | 106 | { |
107 | get { return new List<Scene>(m_localScenes); } | 107 | get { return new List<Scene>(m_localScenes.FindAll(delegate(Scene s) { return true; })); } |
108 | } | 108 | } |
109 | 109 | ||
110 | public Scene CurrentScene | 110 | public Scene CurrentScene |
@@ -118,13 +118,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
118 | { | 118 | { |
119 | if (m_currentScene == null) | 119 | if (m_currentScene == null) |
120 | { | 120 | { |
121 | lock (m_localScenes) | 121 | List<Scene> sceneList = Scenes; |
122 | { | 122 | if (sceneList.Count == 0) |
123 | if (m_localScenes.Count > 0) | 123 | return null; |
124 | return m_localScenes[0]; | 124 | return sceneList[0]; |
125 | else | ||
126 | return null; | ||
127 | } | ||
128 | } | 125 | } |
129 | else | 126 | else |
130 | { | 127 | { |
@@ -136,7 +133,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
136 | public SceneManager() | 133 | public SceneManager() |
137 | { | 134 | { |
138 | m_instance = this; | 135 | m_instance = this; |
139 | m_localScenes = new List<Scene>(); | 136 | m_localScenes = new DoubleDictionary<UUID, string, Scene>(); |
140 | } | 137 | } |
141 | 138 | ||
142 | public void Close() | 139 | public void Close() |
@@ -144,20 +141,18 @@ namespace OpenSim.Region.Framework.Scenes | |||
144 | // collect known shared modules in sharedModules | 141 | // collect known shared modules in sharedModules |
145 | Dictionary<string, IRegionModule> sharedModules = new Dictionary<string, IRegionModule>(); | 142 | Dictionary<string, IRegionModule> sharedModules = new Dictionary<string, IRegionModule>(); |
146 | 143 | ||
147 | lock (m_localScenes) | 144 | List<Scene> sceneList = Scenes; |
145 | for (int i = 0; i < sceneList.Count; i++) | ||
148 | { | 146 | { |
149 | for (int i = 0; i < m_localScenes.Count; i++) | 147 | // extract known shared modules from scene |
148 | foreach (string k in sceneList[i].Modules.Keys) | ||
150 | { | 149 | { |
151 | // extract known shared modules from scene | 150 | if (sceneList[i].Modules[k].IsSharedModule && |
152 | foreach (string k in m_localScenes[i].Modules.Keys) | 151 | !sharedModules.ContainsKey(k)) |
153 | { | 152 | sharedModules[k] = sceneList[i].Modules[k]; |
154 | if (m_localScenes[i].Modules[k].IsSharedModule && | ||
155 | !sharedModules.ContainsKey(k)) | ||
156 | sharedModules[k] = m_localScenes[i].Modules[k]; | ||
157 | } | ||
158 | // close scene/region | ||
159 | m_localScenes[i].Close(); | ||
160 | } | 153 | } |
154 | // close scene/region | ||
155 | sceneList[i].Close(); | ||
161 | } | 156 | } |
162 | 157 | ||
163 | // all regions/scenes are now closed, we can now safely | 158 | // all regions/scenes are now closed, we can now safely |
@@ -166,29 +161,21 @@ namespace OpenSim.Region.Framework.Scenes | |||
166 | { | 161 | { |
167 | mod.Close(); | 162 | mod.Close(); |
168 | } | 163 | } |
164 | |||
165 | m_localScenes.Clear(); | ||
169 | } | 166 | } |
170 | 167 | ||
171 | public void Close(Scene cscene) | 168 | public void Close(Scene cscene) |
172 | { | 169 | { |
173 | lock (m_localScenes) | 170 | if (!m_localScenes.ContainsKey(cscene.RegionInfo.RegionID)) |
174 | { | 171 | return; |
175 | if (m_localScenes.Contains(cscene)) | 172 | cscene.Close(); |
176 | { | ||
177 | for (int i = 0; i < m_localScenes.Count; i++) | ||
178 | { | ||
179 | if (m_localScenes[i].Equals(cscene)) | ||
180 | { | ||
181 | m_localScenes[i].Close(); | ||
182 | } | ||
183 | } | ||
184 | } | ||
185 | } | ||
186 | } | 173 | } |
187 | 174 | ||
188 | public void Add(Scene scene) | 175 | public void Add(Scene scene) |
189 | { | 176 | { |
190 | lock (m_localScenes) | 177 | lock (m_localScenes) |
191 | m_localScenes.Add(scene); | 178 | m_localScenes.Add(scene.RegionInfo.RegionID, scene.RegionInfo.RegionName, scene); |
192 | 179 | ||
193 | scene.OnRestart += HandleRestart; | 180 | scene.OnRestart += HandleRestart; |
194 | scene.EventManager.OnRegionReadyStatusChange += HandleRegionReadyStatusChange; | 181 | scene.EventManager.OnRegionReadyStatusChange += HandleRegionReadyStatusChange; |
@@ -200,23 +187,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
200 | int RegionSceneElement = -1; | 187 | int RegionSceneElement = -1; |
201 | 188 | ||
202 | lock (m_localScenes) | 189 | lock (m_localScenes) |
203 | { | 190 | m_localScenes.Remove(rdata.RegionID); |
204 | for (int i = 0; i < m_localScenes.Count; i++) | ||
205 | { | ||
206 | if (rdata.RegionName == m_localScenes[i].RegionInfo.RegionName) | ||
207 | { | ||
208 | RegionSceneElement = i; | ||
209 | } | ||
210 | } | ||
211 | |||
212 | // Now we make sure the region is no longer known about by the SceneManager | ||
213 | // Prevents duplicates. | ||
214 | |||
215 | if (RegionSceneElement >= 0) | ||
216 | { | ||
217 | m_localScenes.RemoveAt(RegionSceneElement); | ||
218 | } | ||
219 | } | ||
220 | 191 | ||
221 | // Send signal to main that we're restarting this sim. | 192 | // Send signal to main that we're restarting this sim. |
222 | OnRestartSim(rdata); | 193 | OnRestartSim(rdata); |
@@ -225,39 +196,36 @@ namespace OpenSim.Region.Framework.Scenes | |||
225 | private void HandleRegionReadyStatusChange(IScene scene) | 196 | private void HandleRegionReadyStatusChange(IScene scene) |
226 | { | 197 | { |
227 | lock (m_localScenes) | 198 | lock (m_localScenes) |
228 | AllRegionsReady = m_localScenes.TrueForAll(s => s.Ready); | 199 | AllRegionsReady = m_localScenes.FindAll(s => !s.Ready).Count == 0; |
229 | } | 200 | } |
230 | 201 | ||
231 | public void SendSimOnlineNotification(ulong regionHandle) | 202 | public void SendSimOnlineNotification(ulong regionHandle) |
232 | { | 203 | { |
233 | RegionInfo Result = null; | 204 | RegionInfo Result = null; |
234 | 205 | ||
235 | lock (m_localScenes) | 206 | Scene s = m_localScenes.FindValue(delegate(Scene x) |
236 | { | ||
237 | for (int i = 0; i < m_localScenes.Count; i++) | ||
238 | { | ||
239 | if (m_localScenes[i].RegionInfo.RegionHandle == regionHandle) | ||
240 | { | 207 | { |
241 | // Inform other regions to tell their avatar about me | 208 | if (x.RegionInfo.RegionHandle == regionHandle) |
242 | Result = m_localScenes[i].RegionInfo; | 209 | return true; |
243 | } | 210 | return false; |
244 | } | 211 | }); |
245 | 212 | ||
246 | if (Result != null) | 213 | if (s != null) |
214 | { | ||
215 | List<Scene> sceneList = Scenes; | ||
216 | |||
217 | for (int i = 0; i < sceneList.Count; i++) | ||
247 | { | 218 | { |
248 | for (int i = 0; i < m_localScenes.Count; i++) | 219 | if (sceneList[i]!= s) |
249 | { | 220 | { |
250 | if (m_localScenes[i].RegionInfo.RegionHandle != regionHandle) | 221 | // Inform other regions to tell their avatar about me |
251 | { | 222 | //sceneList[i].OtherRegionUp(Result); |
252 | // Inform other regions to tell their avatar about me | ||
253 | //m_localScenes[i].OtherRegionUp(Result); | ||
254 | } | ||
255 | } | 223 | } |
256 | } | 224 | } |
257 | else | 225 | } |
258 | { | 226 | else |
259 | m_log.Error("[REGION]: Unable to notify Other regions of this Region coming up"); | 227 | { |
260 | } | 228 | m_log.Error("[REGION]: Unable to notify Other regions of this Region coming up"); |
261 | } | 229 | } |
262 | } | 230 | } |
263 | 231 | ||
@@ -361,8 +329,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
361 | { | 329 | { |
362 | if (m_currentScene == null) | 330 | if (m_currentScene == null) |
363 | { | 331 | { |
364 | lock (m_localScenes) | 332 | List<Scene> sceneList = Scenes; |
365 | m_localScenes.ForEach(func); | 333 | sceneList.ForEach(func); |
366 | } | 334 | } |
367 | else | 335 | else |
368 | { | 336 | { |
@@ -391,16 +359,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
391 | } | 359 | } |
392 | else | 360 | else |
393 | { | 361 | { |
394 | lock (m_localScenes) | 362 | Scene s; |
363 | |||
364 | if (m_localScenes.TryGetValue(regionName, out s)) | ||
395 | { | 365 | { |
396 | foreach (Scene scene in m_localScenes) | 366 | m_currentScene = s; |
397 | { | 367 | return true; |
398 | if (String.Compare(scene.RegionInfo.RegionName, regionName, true) == 0) | ||
399 | { | ||
400 | m_currentScene = scene; | ||
401 | return true; | ||
402 | } | ||
403 | } | ||
404 | } | 368 | } |
405 | 369 | ||
406 | return false; | 370 | return false; |
@@ -409,18 +373,14 @@ namespace OpenSim.Region.Framework.Scenes | |||
409 | 373 | ||
410 | public bool TrySetCurrentScene(UUID regionID) | 374 | public bool TrySetCurrentScene(UUID regionID) |
411 | { | 375 | { |
412 | m_log.Debug("Searching for Region: '" + regionID + "'"); | 376 | // m_log.Debug("Searching for Region: '" + regionID + "'"); |
413 | 377 | ||
414 | lock (m_localScenes) | 378 | Scene s; |
379 | |||
380 | if (m_localScenes.TryGetValue(regionID, out s)) | ||
415 | { | 381 | { |
416 | foreach (Scene scene in m_localScenes) | 382 | m_currentScene = s; |
417 | { | 383 | return true; |
418 | if (scene.RegionInfo.RegionID == regionID) | ||
419 | { | ||
420 | m_currentScene = scene; | ||
421 | return true; | ||
422 | } | ||
423 | } | ||
424 | } | 384 | } |
425 | 385 | ||
426 | return false; | 386 | return false; |
@@ -428,52 +388,24 @@ namespace OpenSim.Region.Framework.Scenes | |||
428 | 388 | ||
429 | public bool TryGetScene(string regionName, out Scene scene) | 389 | public bool TryGetScene(string regionName, out Scene scene) |
430 | { | 390 | { |
431 | lock (m_localScenes) | 391 | return m_localScenes.TryGetValue(regionName, out scene); |
432 | { | ||
433 | foreach (Scene mscene in m_localScenes) | ||
434 | { | ||
435 | if (String.Compare(mscene.RegionInfo.RegionName, regionName, true) == 0) | ||
436 | { | ||
437 | scene = mscene; | ||
438 | return true; | ||
439 | } | ||
440 | } | ||
441 | } | ||
442 | |||
443 | scene = null; | ||
444 | return false; | ||
445 | } | 392 | } |
446 | 393 | ||
447 | public bool TryGetScene(UUID regionID, out Scene scene) | 394 | public bool TryGetScene(UUID regionID, out Scene scene) |
448 | { | 395 | { |
449 | lock (m_localScenes) | 396 | return m_localScenes.TryGetValue(regionID, out scene); |
450 | { | ||
451 | foreach (Scene mscene in m_localScenes) | ||
452 | { | ||
453 | if (mscene.RegionInfo.RegionID == regionID) | ||
454 | { | ||
455 | scene = mscene; | ||
456 | return true; | ||
457 | } | ||
458 | } | ||
459 | } | ||
460 | |||
461 | scene = null; | ||
462 | return false; | ||
463 | } | 397 | } |
464 | 398 | ||
465 | public bool TryGetScene(uint locX, uint locY, out Scene scene) | 399 | public bool TryGetScene(uint locX, uint locY, out Scene scene) |
466 | { | 400 | { |
467 | lock (m_localScenes) | 401 | List<Scene> sceneList = Scenes; |
402 | foreach (Scene mscene in sceneList) | ||
468 | { | 403 | { |
469 | foreach (Scene mscene in m_localScenes) | 404 | if (mscene.RegionInfo.RegionLocX == locX && |
405 | mscene.RegionInfo.RegionLocY == locY) | ||
470 | { | 406 | { |
471 | if (mscene.RegionInfo.RegionLocX == locX && | 407 | scene = mscene; |
472 | mscene.RegionInfo.RegionLocY == locY) | 408 | return true; |
473 | { | ||
474 | scene = mscene; | ||
475 | return true; | ||
476 | } | ||
477 | } | 409 | } |
478 | } | 410 | } |
479 | 411 | ||
@@ -483,16 +415,14 @@ namespace OpenSim.Region.Framework.Scenes | |||
483 | 415 | ||
484 | public bool TryGetScene(IPEndPoint ipEndPoint, out Scene scene) | 416 | public bool TryGetScene(IPEndPoint ipEndPoint, out Scene scene) |
485 | { | 417 | { |
486 | lock (m_localScenes) | 418 | List<Scene> sceneList = Scenes; |
419 | foreach (Scene mscene in sceneList) | ||
487 | { | 420 | { |
488 | foreach (Scene mscene in m_localScenes) | 421 | if ((mscene.RegionInfo.InternalEndPoint.Equals(ipEndPoint.Address)) && |
422 | (mscene.RegionInfo.InternalEndPoint.Port == ipEndPoint.Port)) | ||
489 | { | 423 | { |
490 | if ((mscene.RegionInfo.InternalEndPoint.Equals(ipEndPoint.Address)) && | 424 | scene = mscene; |
491 | (mscene.RegionInfo.InternalEndPoint.Port == ipEndPoint.Port)) | 425 | return true; |
492 | { | ||
493 | scene = mscene; | ||
494 | return true; | ||
495 | } | ||
496 | } | 426 | } |
497 | } | 427 | } |
498 | 428 | ||
@@ -557,15 +487,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
557 | 487 | ||
558 | public RegionInfo GetRegionInfo(UUID regionID) | 488 | public RegionInfo GetRegionInfo(UUID regionID) |
559 | { | 489 | { |
560 | lock (m_localScenes) | 490 | Scene s; |
491 | if (m_localScenes.TryGetValue(regionID, out s)) | ||
561 | { | 492 | { |
562 | foreach (Scene scene in m_localScenes) | 493 | return s.RegionInfo; |
563 | { | ||
564 | if (scene.RegionInfo.RegionID == regionID) | ||
565 | { | ||
566 | return scene.RegionInfo; | ||
567 | } | ||
568 | } | ||
569 | } | 494 | } |
570 | 495 | ||
571 | return null; | 496 | return null; |
@@ -583,14 +508,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
583 | 508 | ||
584 | public bool TryGetScenePresence(UUID avatarId, out ScenePresence avatar) | 509 | public bool TryGetScenePresence(UUID avatarId, out ScenePresence avatar) |
585 | { | 510 | { |
586 | lock (m_localScenes) | 511 | List<Scene> sceneList = Scenes; |
512 | foreach (Scene scene in sceneList) | ||
587 | { | 513 | { |
588 | foreach (Scene scene in m_localScenes) | 514 | if (scene.TryGetScenePresence(avatarId, out avatar)) |
589 | { | 515 | { |
590 | if (scene.TryGetScenePresence(avatarId, out avatar)) | 516 | return true; |
591 | { | ||
592 | return true; | ||
593 | } | ||
594 | } | 517 | } |
595 | } | 518 | } |
596 | 519 | ||
@@ -600,15 +523,13 @@ namespace OpenSim.Region.Framework.Scenes | |||
600 | 523 | ||
601 | public bool TryGetRootScenePresence(UUID avatarId, out ScenePresence avatar) | 524 | public bool TryGetRootScenePresence(UUID avatarId, out ScenePresence avatar) |
602 | { | 525 | { |
603 | lock (m_localScenes) | 526 | List<Scene> sceneList = Scenes; |
527 | foreach (Scene scene in sceneList) | ||
604 | { | 528 | { |
605 | foreach (Scene scene in m_localScenes) | 529 | avatar = scene.GetScenePresence(avatarId); |
606 | { | ||
607 | avatar = scene.GetScenePresence(avatarId); | ||
608 | 530 | ||
609 | if (avatar != null && !avatar.IsChildAgent) | 531 | if (avatar != null && !avatar.IsChildAgent) |
610 | return true; | 532 | return true; |
611 | } | ||
612 | } | 533 | } |
613 | 534 | ||
614 | avatar = null; | 535 | avatar = null; |
@@ -618,21 +539,19 @@ namespace OpenSim.Region.Framework.Scenes | |||
618 | public void CloseScene(Scene scene) | 539 | public void CloseScene(Scene scene) |
619 | { | 540 | { |
620 | lock (m_localScenes) | 541 | lock (m_localScenes) |
621 | m_localScenes.Remove(scene); | 542 | m_localScenes.Remove(scene.RegionInfo.RegionID); |
622 | 543 | ||
623 | scene.Close(); | 544 | scene.Close(); |
624 | } | 545 | } |
625 | 546 | ||
626 | public bool TryGetAvatarByName(string avatarName, out ScenePresence avatar) | 547 | public bool TryGetAvatarByName(string avatarName, out ScenePresence avatar) |
627 | { | 548 | { |
628 | lock (m_localScenes) | 549 | List<Scene> sceneList = Scenes; |
550 | foreach (Scene scene in sceneList) | ||
629 | { | 551 | { |
630 | foreach (Scene scene in m_localScenes) | 552 | if (scene.TryGetAvatarByName(avatarName, out avatar)) |
631 | { | 553 | { |
632 | if (scene.TryGetAvatarByName(avatarName, out avatar)) | 554 | return true; |
633 | { | ||
634 | return true; | ||
635 | } | ||
636 | } | 555 | } |
637 | } | 556 | } |
638 | 557 | ||
@@ -642,14 +561,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
642 | 561 | ||
643 | public bool TryGetRootScenePresenceByName(string firstName, string lastName, out ScenePresence sp) | 562 | public bool TryGetRootScenePresenceByName(string firstName, string lastName, out ScenePresence sp) |
644 | { | 563 | { |
645 | lock (m_localScenes) | 564 | List<Scene> sceneList = Scenes; |
565 | foreach (Scene scene in sceneList) | ||
646 | { | 566 | { |
647 | foreach (Scene scene in m_localScenes) | 567 | sp = scene.GetScenePresence(firstName, lastName); |
648 | { | 568 | if (sp != null && !sp.IsChildAgent) |
649 | sp = scene.GetScenePresence(firstName, lastName); | 569 | return true; |
650 | if (sp != null && !sp.IsChildAgent) | ||
651 | return true; | ||
652 | } | ||
653 | } | 570 | } |
654 | 571 | ||
655 | sp = null; | 572 | sp = null; |
@@ -658,8 +575,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
658 | 575 | ||
659 | public void ForEachScene(Action<Scene> action) | 576 | public void ForEachScene(Action<Scene> action) |
660 | { | 577 | { |
661 | lock (m_localScenes) | 578 | List<Scene> sceneList = Scenes; |
662 | m_localScenes.ForEach(action); | 579 | sceneList.ForEach(action); |
663 | } | 580 | } |
664 | } | 581 | } |
665 | } | 582 | } |