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