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.cs245
1 files changed, 81 insertions, 164 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneManager.cs b/OpenSim/Region/Framework/Scenes/SceneManager.cs
index 9bd27d3..89e3ac5 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()
@@ -145,25 +142,15 @@ namespace OpenSim.Region.Framework.Scenes
145 142
146 public void Close(Scene cscene) 143 public void Close(Scene cscene)
147 { 144 {
148 lock (m_localScenes) 145 if (!m_localScenes.ContainsKey(cscene.RegionInfo.RegionID))
149 { 146 return;
150 if (m_localScenes.Contains(cscene)) 147 cscene.Close();
151 {
152 for (int i = 0; i < m_localScenes.Count; i++)
153 {
154 if (m_localScenes[i].Equals(cscene))
155 {
156 m_localScenes[i].Close();
157 }
158 }
159 }
160 }
161 } 148 }
162 149
163 public void Add(Scene scene) 150 public void Add(Scene scene)
164 { 151 {
165 lock (m_localScenes) 152 lock (m_localScenes)
166 m_localScenes.Add(scene); 153 m_localScenes.Add(scene.RegionInfo.RegionID, scene.RegionInfo.RegionName, scene);
167 154
168 scene.OnRestart += HandleRestart; 155 scene.OnRestart += HandleRestart;
169 scene.EventManager.OnRegionReadyStatusChange += HandleRegionReadyStatusChange; 156 scene.EventManager.OnRegionReadyStatusChange += HandleRegionReadyStatusChange;
@@ -175,23 +162,7 @@ namespace OpenSim.Region.Framework.Scenes
175 int RegionSceneElement = -1; 162 int RegionSceneElement = -1;
176 163
177 lock (m_localScenes) 164 lock (m_localScenes)
178 { 165 m_localScenes.Remove(rdata.RegionID);
179 for (int i = 0; i < m_localScenes.Count; i++)
180 {
181 if (rdata.RegionName == m_localScenes[i].RegionInfo.RegionName)
182 {
183 RegionSceneElement = i;
184 }
185 }
186
187 // Now we make sure the region is no longer known about by the SceneManager
188 // Prevents duplicates.
189
190 if (RegionSceneElement >= 0)
191 {
192 m_localScenes.RemoveAt(RegionSceneElement);
193 }
194 }
195 166
196 // Send signal to main that we're restarting this sim. 167 // Send signal to main that we're restarting this sim.
197 OnRestartSim(rdata); 168 OnRestartSim(rdata);
@@ -200,39 +171,36 @@ namespace OpenSim.Region.Framework.Scenes
200 private void HandleRegionReadyStatusChange(IScene scene) 171 private void HandleRegionReadyStatusChange(IScene scene)
201 { 172 {
202 lock (m_localScenes) 173 lock (m_localScenes)
203 AllRegionsReady = m_localScenes.TrueForAll(s => s.Ready); 174 AllRegionsReady = m_localScenes.FindAll(s => !s.Ready).Count == 0;
204 } 175 }
205 176
206 public void SendSimOnlineNotification(ulong regionHandle) 177 public void SendSimOnlineNotification(ulong regionHandle)
207 { 178 {
208 RegionInfo Result = null; 179 RegionInfo Result = null;
209 180
210 lock (m_localScenes) 181 Scene s = m_localScenes.FindValue(delegate(Scene x)
211 {
212 for (int i = 0; i < m_localScenes.Count; i++)
213 {
214 if (m_localScenes[i].RegionInfo.RegionHandle == regionHandle)
215 { 182 {
216 // Inform other regions to tell their avatar about me 183 if (x.RegionInfo.RegionHandle == regionHandle)
217 Result = m_localScenes[i].RegionInfo; 184 return true;
218 } 185 return false;
219 } 186 });
187
188 if (s != null)
189 {
190 List<Scene> sceneList = Scenes;
220 191
221 if (Result != null) 192 for (int i = 0; i < sceneList.Count; i++)
222 { 193 {
223 for (int i = 0; i < m_localScenes.Count; i++) 194 if (sceneList[i]!= s)
224 { 195 {
225 if (m_localScenes[i].RegionInfo.RegionHandle != regionHandle) 196 // Inform other regions to tell their avatar about me
226 { 197 //sceneList[i].OtherRegionUp(Result);
227 // Inform other regions to tell their avatar about me
228 //m_localScenes[i].OtherRegionUp(Result);
229 }
230 } 198 }
231 } 199 }
232 else 200 }
233 { 201 else
234 m_log.Error("[REGION]: Unable to notify Other regions of this Region coming up"); 202 {
235 } 203 m_log.Error("[REGION]: Unable to notify Other regions of this Region coming up");
236 } 204 }
237 } 205 }
238 206
@@ -336,8 +304,8 @@ namespace OpenSim.Region.Framework.Scenes
336 { 304 {
337 if (m_currentScene == null) 305 if (m_currentScene == null)
338 { 306 {
339 lock (m_localScenes) 307 List<Scene> sceneList = Scenes;
340 m_localScenes.ForEach(func); 308 sceneList.ForEach(func);
341 } 309 }
342 else 310 else
343 { 311 {
@@ -366,16 +334,12 @@ namespace OpenSim.Region.Framework.Scenes
366 } 334 }
367 else 335 else
368 { 336 {
369 lock (m_localScenes) 337 Scene s;
338
339 if (m_localScenes.TryGetValue(regionName, out s))
370 { 340 {
371 foreach (Scene scene in m_localScenes) 341 m_currentScene = s;
372 { 342 return true;
373 if (String.Compare(scene.RegionInfo.RegionName, regionName, true) == 0)
374 {
375 m_currentScene = scene;
376 return true;
377 }
378 }
379 } 343 }
380 344
381 return false; 345 return false;
@@ -384,18 +348,14 @@ namespace OpenSim.Region.Framework.Scenes
384 348
385 public bool TrySetCurrentScene(UUID regionID) 349 public bool TrySetCurrentScene(UUID regionID)
386 { 350 {
387 m_log.Debug("Searching for Region: '" + regionID + "'"); 351// m_log.Debug("Searching for Region: '" + regionID + "'");
388 352
389 lock (m_localScenes) 353 Scene s;
354
355 if (m_localScenes.TryGetValue(regionID, out s))
390 { 356 {
391 foreach (Scene scene in m_localScenes) 357 m_currentScene = s;
392 { 358 return true;
393 if (scene.RegionInfo.RegionID == regionID)
394 {
395 m_currentScene = scene;
396 return true;
397 }
398 }
399 } 359 }
400 360
401 return false; 361 return false;
@@ -403,52 +363,24 @@ namespace OpenSim.Region.Framework.Scenes
403 363
404 public bool TryGetScene(string regionName, out Scene scene) 364 public bool TryGetScene(string regionName, out Scene scene)
405 { 365 {
406 lock (m_localScenes) 366 return m_localScenes.TryGetValue(regionName, out scene);
407 {
408 foreach (Scene mscene in m_localScenes)
409 {
410 if (String.Compare(mscene.RegionInfo.RegionName, regionName, true) == 0)
411 {
412 scene = mscene;
413 return true;
414 }
415 }
416 }
417
418 scene = null;
419 return false;
420 } 367 }
421 368
422 public bool TryGetScene(UUID regionID, out Scene scene) 369 public bool TryGetScene(UUID regionID, out Scene scene)
423 { 370 {
424 lock (m_localScenes) 371 return m_localScenes.TryGetValue(regionID, out scene);
425 {
426 foreach (Scene mscene in m_localScenes)
427 {
428 if (mscene.RegionInfo.RegionID == regionID)
429 {
430 scene = mscene;
431 return true;
432 }
433 }
434 }
435
436 scene = null;
437 return false;
438 } 372 }
439 373
440 public bool TryGetScene(uint locX, uint locY, out Scene scene) 374 public bool TryGetScene(uint locX, uint locY, out Scene scene)
441 { 375 {
442 lock (m_localScenes) 376 List<Scene> sceneList = Scenes;
377 foreach (Scene mscene in sceneList)
443 { 378 {
444 foreach (Scene mscene in m_localScenes) 379 if (mscene.RegionInfo.RegionLocX == locX &&
380 mscene.RegionInfo.RegionLocY == locY)
445 { 381 {
446 if (mscene.RegionInfo.RegionLocX == locX && 382 scene = mscene;
447 mscene.RegionInfo.RegionLocY == locY) 383 return true;
448 {
449 scene = mscene;
450 return true;
451 }
452 } 384 }
453 } 385 }
454 386
@@ -458,16 +390,14 @@ namespace OpenSim.Region.Framework.Scenes
458 390
459 public bool TryGetScene(IPEndPoint ipEndPoint, out Scene scene) 391 public bool TryGetScene(IPEndPoint ipEndPoint, out Scene scene)
460 { 392 {
461 lock (m_localScenes) 393 List<Scene> sceneList = Scenes;
394 foreach (Scene mscene in sceneList)
462 { 395 {
463 foreach (Scene mscene in m_localScenes) 396 if ((mscene.RegionInfo.InternalEndPoint.Equals(ipEndPoint.Address)) &&
397 (mscene.RegionInfo.InternalEndPoint.Port == ipEndPoint.Port))
464 { 398 {
465 if ((mscene.RegionInfo.InternalEndPoint.Equals(ipEndPoint.Address)) && 399 scene = mscene;
466 (mscene.RegionInfo.InternalEndPoint.Port == ipEndPoint.Port)) 400 return true;
467 {
468 scene = mscene;
469 return true;
470 }
471 } 401 }
472 } 402 }
473 403
@@ -532,15 +462,10 @@ namespace OpenSim.Region.Framework.Scenes
532 462
533 public RegionInfo GetRegionInfo(UUID regionID) 463 public RegionInfo GetRegionInfo(UUID regionID)
534 { 464 {
535 lock (m_localScenes) 465 Scene s;
466 if (m_localScenes.TryGetValue(regionID, out s))
536 { 467 {
537 foreach (Scene scene in m_localScenes) 468 return s.RegionInfo;
538 {
539 if (scene.RegionInfo.RegionID == regionID)
540 {
541 return scene.RegionInfo;
542 }
543 }
544 } 469 }
545 470
546 return null; 471 return null;
@@ -558,14 +483,12 @@ namespace OpenSim.Region.Framework.Scenes
558 483
559 public bool TryGetScenePresence(UUID avatarId, out ScenePresence avatar) 484 public bool TryGetScenePresence(UUID avatarId, out ScenePresence avatar)
560 { 485 {
561 lock (m_localScenes) 486 List<Scene> sceneList = Scenes;
487 foreach (Scene scene in sceneList)
562 { 488 {
563 foreach (Scene scene in m_localScenes) 489 if (scene.TryGetScenePresence(avatarId, out avatar))
564 { 490 {
565 if (scene.TryGetScenePresence(avatarId, out avatar)) 491 return true;
566 {
567 return true;
568 }
569 } 492 }
570 } 493 }
571 494
@@ -575,15 +498,13 @@ namespace OpenSim.Region.Framework.Scenes
575 498
576 public bool TryGetRootScenePresence(UUID avatarId, out ScenePresence avatar) 499 public bool TryGetRootScenePresence(UUID avatarId, out ScenePresence avatar)
577 { 500 {
578 lock (m_localScenes) 501 List<Scene> sceneList = Scenes;
502 foreach (Scene scene in sceneList)
579 { 503 {
580 foreach (Scene scene in m_localScenes) 504 avatar = scene.GetScenePresence(avatarId);
581 {
582 avatar = scene.GetScenePresence(avatarId);
583 505
584 if (avatar != null && !avatar.IsChildAgent) 506 if (avatar != null && !avatar.IsChildAgent)
585 return true; 507 return true;
586 }
587 } 508 }
588 509
589 avatar = null; 510 avatar = null;
@@ -593,21 +514,19 @@ namespace OpenSim.Region.Framework.Scenes
593 public void CloseScene(Scene scene) 514 public void CloseScene(Scene scene)
594 { 515 {
595 lock (m_localScenes) 516 lock (m_localScenes)
596 m_localScenes.Remove(scene); 517 m_localScenes.Remove(scene.RegionInfo.RegionID);
597 518
598 scene.Close(); 519 scene.Close();
599 } 520 }
600 521
601 public bool TryGetAvatarByName(string avatarName, out ScenePresence avatar) 522 public bool TryGetAvatarByName(string avatarName, out ScenePresence avatar)
602 { 523 {
603 lock (m_localScenes) 524 List<Scene> sceneList = Scenes;
525 foreach (Scene scene in sceneList)
604 { 526 {
605 foreach (Scene scene in m_localScenes) 527 if (scene.TryGetAvatarByName(avatarName, out avatar))
606 { 528 {
607 if (scene.TryGetAvatarByName(avatarName, out avatar)) 529 return true;
608 {
609 return true;
610 }
611 } 530 }
612 } 531 }
613 532
@@ -617,14 +536,12 @@ namespace OpenSim.Region.Framework.Scenes
617 536
618 public bool TryGetRootScenePresenceByName(string firstName, string lastName, out ScenePresence sp) 537 public bool TryGetRootScenePresenceByName(string firstName, string lastName, out ScenePresence sp)
619 { 538 {
620 lock (m_localScenes) 539 List<Scene> sceneList = Scenes;
540 foreach (Scene scene in sceneList)
621 { 541 {
622 foreach (Scene scene in m_localScenes) 542 sp = scene.GetScenePresence(firstName, lastName);
623 { 543 if (sp != null && !sp.IsChildAgent)
624 sp = scene.GetScenePresence(firstName, lastName); 544 return true;
625 if (sp != null && !sp.IsChildAgent)
626 return true;
627 }
628 } 545 }
629 546
630 sp = null; 547 sp = null;
@@ -633,8 +550,8 @@ namespace OpenSim.Region.Framework.Scenes
633 550
634 public void ForEachScene(Action<Scene> action) 551 public void ForEachScene(Action<Scene> action)
635 { 552 {
636 lock (m_localScenes) 553 List<Scene> sceneList = Scenes;
637 m_localScenes.ForEach(action); 554 sceneList.ForEach(action);
638 } 555 }
639 } 556 }
640} 557}