aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/SceneManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/SceneManager.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneManager.cs247
1 files changed, 89 insertions, 158 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneManager.cs b/OpenSim/Region/Framework/Scenes/SceneManager.cs
index 780bd01..c307f7a 100644
--- a/OpenSim/Region/Framework/Scenes/SceneManager.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneManager.cs
@@ -99,11 +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 104
104 public List<Scene> Scenes 105 public List<Scene> Scenes
105 { 106 {
106 get { return new List<Scene>(m_localScenes); } 107 get { return new List<Scene>(m_localScenes.FindAll(delegate(Scene s) { return true; })); }
107 } 108 }
108 109
109 /// <summary> 110 /// <summary>
@@ -120,13 +121,10 @@ namespace OpenSim.Region.Framework.Scenes
120 { 121 {
121 if (CurrentScene == null) 122 if (CurrentScene == null)
122 { 123 {
123 lock (m_localScenes) 124 List<Scene> sceneList = Scenes;
124 { 125 if (sceneList.Count == 0)
125 if (m_localScenes.Count > 0) 126 return null;
126 return m_localScenes[0]; 127 return sceneList[0];
127 else
128 return null;
129 }
130 } 128 }
131 else 129 else
132 { 130 {
@@ -138,41 +136,35 @@ namespace OpenSim.Region.Framework.Scenes
138 public SceneManager() 136 public SceneManager()
139 { 137 {
140 m_instance = this; 138 m_instance = this;
141 m_localScenes = new List<Scene>(); 139 m_localScenes = new DoubleDictionary<UUID, string, Scene>();
142 } 140 }
143 141
144 public void Close() 142 public void Close()
145 { 143 {
144 List<Scene> localScenes = null;
145
146 lock (m_localScenes) 146 lock (m_localScenes)
147 { 147 {
148 for (int i = 0; i < m_localScenes.Count; i++) 148 localScenes = Scenes;
149 { 149 }
150 m_localScenes[i].Close(); 150
151 } 151 for (int i = 0; i < localScenes.Count; i++)
152 {
153 localScenes[i].Close();
152 } 154 }
153 } 155 }
154 156
155 public void Close(Scene cscene) 157 public void Close(Scene cscene)
156 { 158 {
157 lock (m_localScenes) 159 if (!m_localScenes.ContainsKey(cscene.RegionInfo.RegionID))
158 { 160 return;
159 if (m_localScenes.Contains(cscene)) 161 cscene.Close();
160 {
161 for (int i = 0; i < m_localScenes.Count; i++)
162 {
163 if (m_localScenes[i].Equals(cscene))
164 {
165 m_localScenes[i].Close();
166 }
167 }
168 }
169 }
170 } 162 }
171 163
172 public void Add(Scene scene) 164 public void Add(Scene scene)
173 { 165 {
174 lock (m_localScenes) 166 lock (m_localScenes)
175 m_localScenes.Add(scene); 167 m_localScenes.Add(scene.RegionInfo.RegionID, scene.RegionInfo.RegionName, scene);
176 168
177 scene.OnRestart += HandleRestart; 169 scene.OnRestart += HandleRestart;
178 scene.EventManager.OnRegionReadyStatusChange += HandleRegionReadyStatusChange; 170 scene.EventManager.OnRegionReadyStatusChange += HandleRegionReadyStatusChange;
@@ -184,15 +176,8 @@ namespace OpenSim.Region.Framework.Scenes
184 176
185 lock (m_localScenes) 177 lock (m_localScenes)
186 { 178 {
187 for (int i = 0; i < m_localScenes.Count; i++) 179 m_localScenes.TryGetValue(rdata.RegionID, out restartedScene);
188 { 180 m_localScenes.Remove(rdata.RegionID);
189 if (rdata.RegionName == m_localScenes[i].RegionInfo.RegionName)
190 {
191 restartedScene = m_localScenes[i];
192 m_localScenes.RemoveAt(i);
193 break;
194 }
195 }
196 } 181 }
197 182
198 // If the currently selected scene has been restarted, then we can't reselect here since we the scene 183 // If the currently selected scene has been restarted, then we can't reselect here since we the scene
@@ -207,39 +192,36 @@ namespace OpenSim.Region.Framework.Scenes
207 private void HandleRegionReadyStatusChange(IScene scene) 192 private void HandleRegionReadyStatusChange(IScene scene)
208 { 193 {
209 lock (m_localScenes) 194 lock (m_localScenes)
210 AllRegionsReady = m_localScenes.TrueForAll(s => s.Ready); 195 AllRegionsReady = m_localScenes.FindAll(s => !s.Ready).Count == 0;
211 } 196 }
212 197
213 public void SendSimOnlineNotification(ulong regionHandle) 198 public void SendSimOnlineNotification(ulong regionHandle)
214 { 199 {
215 RegionInfo Result = null; 200 RegionInfo Result = null;
216 201
217 lock (m_localScenes) 202 Scene s = m_localScenes.FindValue(delegate(Scene x)
218 {
219 for (int i = 0; i < m_localScenes.Count; i++)
220 {
221 if (m_localScenes[i].RegionInfo.RegionHandle == regionHandle)
222 { 203 {
223 // Inform other regions to tell their avatar about me 204 if (x.RegionInfo.RegionHandle == regionHandle)
224 Result = m_localScenes[i].RegionInfo; 205 return true;
225 } 206 return false;
226 } 207 });
208
209 if (s != null)
210 {
211 List<Scene> sceneList = Scenes;
227 212
228 if (Result != null) 213 for (int i = 0; i < sceneList.Count; i++)
229 { 214 {
230 for (int i = 0; i < m_localScenes.Count; i++) 215 if (sceneList[i]!= s)
231 { 216 {
232 if (m_localScenes[i].RegionInfo.RegionHandle != regionHandle) 217 // Inform other regions to tell their avatar about me
233 { 218 //sceneList[i].OtherRegionUp(Result);
234 // Inform other regions to tell their avatar about me
235 //m_localScenes[i].OtherRegionUp(Result);
236 }
237 } 219 }
238 } 220 }
239 else 221 }
240 { 222 else
241 m_log.Error("[REGION]: Unable to notify Other regions of this Region coming up"); 223 {
242 } 224 m_log.Error("[REGION]: Unable to notify Other regions of this Region coming up");
243 } 225 }
244 } 226 }
245 227
@@ -368,16 +350,12 @@ namespace OpenSim.Region.Framework.Scenes
368 } 350 }
369 else 351 else
370 { 352 {
371 lock (m_localScenes) 353 Scene s;
354
355 if (m_localScenes.TryGetValue(regionName, out s))
372 { 356 {
373 foreach (Scene scene in m_localScenes) 357 m_currentScene = s;
374 { 358 return true;
375 if (String.Compare(scene.RegionInfo.RegionName, regionName, true) == 0)
376 {
377 CurrentScene = scene;
378 return true;
379 }
380 }
381 } 359 }
382 360
383 return false; 361 return false;
@@ -386,18 +364,14 @@ namespace OpenSim.Region.Framework.Scenes
386 364
387 public bool TrySetCurrentScene(UUID regionID) 365 public bool TrySetCurrentScene(UUID regionID)
388 { 366 {
389 m_log.Debug("Searching for Region: '" + regionID + "'"); 367// m_log.Debug("Searching for Region: '" + regionID + "'");
390 368
391 lock (m_localScenes) 369 Scene s;
370
371 if (m_localScenes.TryGetValue(regionID, out s))
392 { 372 {
393 foreach (Scene scene in m_localScenes) 373 m_currentScene = s;
394 { 374 return true;
395 if (scene.RegionInfo.RegionID == regionID)
396 {
397 CurrentScene = scene;
398 return true;
399 }
400 }
401 } 375 }
402 376
403 return false; 377 return false;
@@ -405,52 +379,24 @@ namespace OpenSim.Region.Framework.Scenes
405 379
406 public bool TryGetScene(string regionName, out Scene scene) 380 public bool TryGetScene(string regionName, out Scene scene)
407 { 381 {
408 lock (m_localScenes) 382 return m_localScenes.TryGetValue(regionName, out scene);
409 {
410 foreach (Scene mscene in m_localScenes)
411 {
412 if (String.Compare(mscene.RegionInfo.RegionName, regionName, true) == 0)
413 {
414 scene = mscene;
415 return true;
416 }
417 }
418 }
419
420 scene = null;
421 return false;
422 } 383 }
423 384
424 public bool TryGetScene(UUID regionID, out Scene scene) 385 public bool TryGetScene(UUID regionID, out Scene scene)
425 { 386 {
426 lock (m_localScenes) 387 return m_localScenes.TryGetValue(regionID, out scene);
427 {
428 foreach (Scene mscene in m_localScenes)
429 {
430 if (mscene.RegionInfo.RegionID == regionID)
431 {
432 scene = mscene;
433 return true;
434 }
435 }
436 }
437
438 scene = null;
439 return false;
440 } 388 }
441 389
442 public bool TryGetScene(uint locX, uint locY, out Scene scene) 390 public bool TryGetScene(uint locX, uint locY, out Scene scene)
443 { 391 {
444 lock (m_localScenes) 392 List<Scene> sceneList = Scenes;
393 foreach (Scene mscene in sceneList)
445 { 394 {
446 foreach (Scene mscene in m_localScenes) 395 if (mscene.RegionInfo.RegionLocX == locX &&
396 mscene.RegionInfo.RegionLocY == locY)
447 { 397 {
448 if (mscene.RegionInfo.RegionLocX == locX && 398 scene = mscene;
449 mscene.RegionInfo.RegionLocY == locY) 399 return true;
450 {
451 scene = mscene;
452 return true;
453 }
454 } 400 }
455 } 401 }
456 402
@@ -460,16 +406,14 @@ namespace OpenSim.Region.Framework.Scenes
460 406
461 public bool TryGetScene(IPEndPoint ipEndPoint, out Scene scene) 407 public bool TryGetScene(IPEndPoint ipEndPoint, out Scene scene)
462 { 408 {
463 lock (m_localScenes) 409 List<Scene> sceneList = Scenes;
410 foreach (Scene mscene in sceneList)
464 { 411 {
465 foreach (Scene mscene in m_localScenes) 412 if ((mscene.RegionInfo.InternalEndPoint.Equals(ipEndPoint.Address)) &&
413 (mscene.RegionInfo.InternalEndPoint.Port == ipEndPoint.Port))
466 { 414 {
467 if ((mscene.RegionInfo.InternalEndPoint.Equals(ipEndPoint.Address)) && 415 scene = mscene;
468 (mscene.RegionInfo.InternalEndPoint.Port == ipEndPoint.Port)) 416 return true;
469 {
470 scene = mscene;
471 return true;
472 }
473 } 417 }
474 } 418 }
475 419
@@ -534,15 +478,10 @@ namespace OpenSim.Region.Framework.Scenes
534 478
535 public RegionInfo GetRegionInfo(UUID regionID) 479 public RegionInfo GetRegionInfo(UUID regionID)
536 { 480 {
537 lock (m_localScenes) 481 Scene s;
482 if (m_localScenes.TryGetValue(regionID, out s))
538 { 483 {
539 foreach (Scene scene in m_localScenes) 484 return s.RegionInfo;
540 {
541 if (scene.RegionInfo.RegionID == regionID)
542 {
543 return scene.RegionInfo;
544 }
545 }
546 } 485 }
547 486
548 return null; 487 return null;
@@ -560,14 +499,12 @@ namespace OpenSim.Region.Framework.Scenes
560 499
561 public bool TryGetScenePresence(UUID avatarId, out ScenePresence avatar) 500 public bool TryGetScenePresence(UUID avatarId, out ScenePresence avatar)
562 { 501 {
563 lock (m_localScenes) 502 List<Scene> sceneList = Scenes;
503 foreach (Scene scene in sceneList)
564 { 504 {
565 foreach (Scene scene in m_localScenes) 505 if (scene.TryGetScenePresence(avatarId, out avatar))
566 { 506 {
567 if (scene.TryGetScenePresence(avatarId, out avatar)) 507 return true;
568 {
569 return true;
570 }
571 } 508 }
572 } 509 }
573 510
@@ -577,15 +514,13 @@ namespace OpenSim.Region.Framework.Scenes
577 514
578 public bool TryGetRootScenePresence(UUID avatarId, out ScenePresence avatar) 515 public bool TryGetRootScenePresence(UUID avatarId, out ScenePresence avatar)
579 { 516 {
580 lock (m_localScenes) 517 List<Scene> sceneList = Scenes;
518 foreach (Scene scene in sceneList)
581 { 519 {
582 foreach (Scene scene in m_localScenes) 520 avatar = scene.GetScenePresence(avatarId);
583 {
584 avatar = scene.GetScenePresence(avatarId);
585 521
586 if (avatar != null && !avatar.IsChildAgent) 522 if (avatar != null && !avatar.IsChildAgent)
587 return true; 523 return true;
588 }
589 } 524 }
590 525
591 avatar = null; 526 avatar = null;
@@ -595,21 +530,19 @@ namespace OpenSim.Region.Framework.Scenes
595 public void CloseScene(Scene scene) 530 public void CloseScene(Scene scene)
596 { 531 {
597 lock (m_localScenes) 532 lock (m_localScenes)
598 m_localScenes.Remove(scene); 533 m_localScenes.Remove(scene.RegionInfo.RegionID);
599 534
600 scene.Close(); 535 scene.Close();
601 } 536 }
602 537
603 public bool TryGetAvatarByName(string avatarName, out ScenePresence avatar) 538 public bool TryGetAvatarByName(string avatarName, out ScenePresence avatar)
604 { 539 {
605 lock (m_localScenes) 540 List<Scene> sceneList = Scenes;
541 foreach (Scene scene in sceneList)
606 { 542 {
607 foreach (Scene scene in m_localScenes) 543 if (scene.TryGetAvatarByName(avatarName, out avatar))
608 { 544 {
609 if (scene.TryGetAvatarByName(avatarName, out avatar)) 545 return true;
610 {
611 return true;
612 }
613 } 546 }
614 } 547 }
615 548
@@ -619,14 +552,12 @@ namespace OpenSim.Region.Framework.Scenes
619 552
620 public bool TryGetRootScenePresenceByName(string firstName, string lastName, out ScenePresence sp) 553 public bool TryGetRootScenePresenceByName(string firstName, string lastName, out ScenePresence sp)
621 { 554 {
622 lock (m_localScenes) 555 List<Scene> sceneList = Scenes;
556 foreach (Scene scene in sceneList)
623 { 557 {
624 foreach (Scene scene in m_localScenes) 558 sp = scene.GetScenePresence(firstName, lastName);
625 { 559 if (sp != null && !sp.IsChildAgent)
626 sp = scene.GetScenePresence(firstName, lastName); 560 return true;
627 if (sp != null && !sp.IsChildAgent)
628 return true;
629 }
630 } 561 }
631 562
632 sp = null; 563 sp = null;
@@ -635,8 +566,8 @@ namespace OpenSim.Region.Framework.Scenes
635 566
636 public void ForEachScene(Action<Scene> action) 567 public void ForEachScene(Action<Scene> action)
637 { 568 {
638 lock (m_localScenes) 569 List<Scene> sceneList = Scenes;
639 m_localScenes.ForEach(action); 570 sceneList.ForEach(action);
640 } 571 }
641 } 572 }
642} 573}