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.cs233
1 files changed, 146 insertions, 87 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneManager.cs b/OpenSim/Region/Framework/Scenes/SceneManager.cs
index 86ba2aa..7fada4b 100644
--- a/OpenSim/Region/Framework/Scenes/SceneManager.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneManager.cs
@@ -47,12 +47,18 @@ namespace OpenSim.Region.Framework.Scenes
47 47
48 public event RestartSim OnRestartSim; 48 public event RestartSim OnRestartSim;
49 49
50 private readonly List<Scene> m_localScenes; 50 private static SceneManager m_instance = null;
51 public static SceneManager Instance
52 {
53 get { return m_instance; }
54 }
55
56 private readonly List<Scene> m_localScenes = new List<Scene>();
51 private Scene m_currentScene = null; 57 private Scene m_currentScene = null;
52 58
53 public List<Scene> Scenes 59 public List<Scene> Scenes
54 { 60 {
55 get { return m_localScenes; } 61 get { return new List<Scene>(m_localScenes); }
56 } 62 }
57 63
58 public Scene CurrentScene 64 public Scene CurrentScene
@@ -66,13 +72,12 @@ namespace OpenSim.Region.Framework.Scenes
66 { 72 {
67 if (m_currentScene == null) 73 if (m_currentScene == null)
68 { 74 {
69 if (m_localScenes.Count > 0) 75 lock (m_localScenes)
70 { 76 {
71 return m_localScenes[0]; 77 if (m_localScenes.Count > 0)
72 } 78 return m_localScenes[0];
73 else 79 else
74 { 80 return null;
75 return null;
76 } 81 }
77 } 82 }
78 else 83 else
@@ -84,6 +89,7 @@ namespace OpenSim.Region.Framework.Scenes
84 89
85 public SceneManager() 90 public SceneManager()
86 { 91 {
92 m_instance = this;
87 m_localScenes = new List<Scene>(); 93 m_localScenes = new List<Scene>();
88 } 94 }
89 95
@@ -91,17 +97,21 @@ namespace OpenSim.Region.Framework.Scenes
91 { 97 {
92 // collect known shared modules in sharedModules 98 // collect known shared modules in sharedModules
93 Dictionary<string, IRegionModule> sharedModules = new Dictionary<string, IRegionModule>(); 99 Dictionary<string, IRegionModule> sharedModules = new Dictionary<string, IRegionModule>();
94 for (int i = 0; i < m_localScenes.Count; i++) 100
101 lock (m_localScenes)
95 { 102 {
96 // extract known shared modules from scene 103 for (int i = 0; i < m_localScenes.Count; i++)
97 foreach (string k in m_localScenes[i].Modules.Keys)
98 { 104 {
99 if (m_localScenes[i].Modules[k].IsSharedModule && 105 // extract known shared modules from scene
100 !sharedModules.ContainsKey(k)) 106 foreach (string k in m_localScenes[i].Modules.Keys)
101 sharedModules[k] = m_localScenes[i].Modules[k]; 107 {
108 if (m_localScenes[i].Modules[k].IsSharedModule &&
109 !sharedModules.ContainsKey(k))
110 sharedModules[k] = m_localScenes[i].Modules[k];
111 }
112 // close scene/region
113 m_localScenes[i].Close();
102 } 114 }
103 // close scene/region
104 m_localScenes[i].Close();
105 } 115 }
106 116
107 // all regions/scenes are now closed, we can now safely 117 // all regions/scenes are now closed, we can now safely
@@ -114,13 +124,16 @@ namespace OpenSim.Region.Framework.Scenes
114 124
115 public void Close(Scene cscene) 125 public void Close(Scene cscene)
116 { 126 {
117 if (m_localScenes.Contains(cscene)) 127 lock (m_localScenes)
118 { 128 {
119 for (int i = 0; i < m_localScenes.Count; i++) 129 if (m_localScenes.Contains(cscene))
120 { 130 {
121 if (m_localScenes[i].Equals(cscene)) 131 for (int i = 0; i < m_localScenes.Count; i++)
122 { 132 {
123 m_localScenes[i].Close(); 133 if (m_localScenes[i].Equals(cscene))
134 {
135 m_localScenes[i].Close();
136 }
124 } 137 }
125 } 138 }
126 } 139 }
@@ -129,27 +142,33 @@ namespace OpenSim.Region.Framework.Scenes
129 public void Add(Scene scene) 142 public void Add(Scene scene)
130 { 143 {
131 scene.OnRestart += HandleRestart; 144 scene.OnRestart += HandleRestart;
132 m_localScenes.Add(scene); 145
146 lock (m_localScenes)
147 m_localScenes.Add(scene);
133 } 148 }
134 149
135 public void HandleRestart(RegionInfo rdata) 150 public void HandleRestart(RegionInfo rdata)
136 { 151 {
137 m_log.Error("[SCENEMANAGER]: Got Restart message for region:" + rdata.RegionName + " Sending up to main"); 152 m_log.Error("[SCENEMANAGER]: Got Restart message for region:" + rdata.RegionName + " Sending up to main");
138 int RegionSceneElement = -1; 153 int RegionSceneElement = -1;
139 for (int i = 0; i < m_localScenes.Count; i++) 154
155 lock (m_localScenes)
140 { 156 {
141 if (rdata.RegionName == m_localScenes[i].RegionInfo.RegionName) 157 for (int i = 0; i < m_localScenes.Count; i++)
142 { 158 {
143 RegionSceneElement = i; 159 if (rdata.RegionName == m_localScenes[i].RegionInfo.RegionName)
160 {
161 RegionSceneElement = i;
162 }
144 } 163 }
145 }
146 164
147 // Now we make sure the region is no longer known about by the SceneManager 165 // Now we make sure the region is no longer known about by the SceneManager
148 // Prevents duplicates. 166 // Prevents duplicates.
149 167
150 if (RegionSceneElement >= 0) 168 if (RegionSceneElement >= 0)
151 { 169 {
152 m_localScenes.RemoveAt(RegionSceneElement); 170 m_localScenes.RemoveAt(RegionSceneElement);
171 }
153 } 172 }
154 173
155 // Send signal to main that we're restarting this sim. 174 // Send signal to main that we're restarting this sim.
@@ -160,28 +179,32 @@ namespace OpenSim.Region.Framework.Scenes
160 { 179 {
161 RegionInfo Result = null; 180 RegionInfo Result = null;
162 181
163 for (int i = 0; i < m_localScenes.Count; i++) 182 lock (m_localScenes)
164 {
165 if (m_localScenes[i].RegionInfo.RegionHandle == regionHandle)
166 {
167 // Inform other regions to tell their avatar about me
168 Result = m_localScenes[i].RegionInfo;
169 }
170 }
171 if (Result != null)
172 { 183 {
173 for (int i = 0; i < m_localScenes.Count; i++) 184 for (int i = 0; i < m_localScenes.Count; i++)
174 { 185 {
175 if (m_localScenes[i].RegionInfo.RegionHandle != regionHandle) 186 if (m_localScenes[i].RegionInfo.RegionHandle == regionHandle)
176 { 187 {
177 // Inform other regions to tell their avatar about me 188 // Inform other regions to tell their avatar about me
178 //m_localScenes[i].OtherRegionUp(Result); 189 Result = m_localScenes[i].RegionInfo;
179 } 190 }
180 } 191 }
181 } 192
182 else 193 if (Result != null)
183 { 194 {
184 m_log.Error("[REGION]: Unable to notify Other regions of this Region coming up"); 195 for (int i = 0; i < m_localScenes.Count; i++)
196 {
197 if (m_localScenes[i].RegionInfo.RegionHandle != regionHandle)
198 {
199 // Inform other regions to tell their avatar about me
200 //m_localScenes[i].OtherRegionUp(Result);
201 }
202 }
203 }
204 else
205 {
206 m_log.Error("[REGION]: Unable to notify Other regions of this Region coming up");
207 }
185 } 208 }
186 } 209 }
187 210
@@ -285,7 +308,8 @@ namespace OpenSim.Region.Framework.Scenes
285 { 308 {
286 if (m_currentScene == null) 309 if (m_currentScene == null)
287 { 310 {
288 m_localScenes.ForEach(func); 311 lock (m_localScenes)
312 m_localScenes.ForEach(func);
289 } 313 }
290 else 314 else
291 { 315 {
@@ -314,12 +338,15 @@ namespace OpenSim.Region.Framework.Scenes
314 } 338 }
315 else 339 else
316 { 340 {
317 foreach (Scene scene in m_localScenes) 341 lock (m_localScenes)
318 { 342 {
319 if (String.Compare(scene.RegionInfo.RegionName, regionName, true) == 0) 343 foreach (Scene scene in m_localScenes)
320 { 344 {
321 m_currentScene = scene; 345 if (String.Compare(scene.RegionInfo.RegionName, regionName, true) == 0)
322 return true; 346 {
347 m_currentScene = scene;
348 return true;
349 }
323 } 350 }
324 } 351 }
325 352
@@ -331,12 +358,15 @@ namespace OpenSim.Region.Framework.Scenes
331 { 358 {
332 m_log.Debug("Searching for Region: '" + regionID + "'"); 359 m_log.Debug("Searching for Region: '" + regionID + "'");
333 360
334 foreach (Scene scene in m_localScenes) 361 lock (m_localScenes)
335 { 362 {
336 if (scene.RegionInfo.RegionID == regionID) 363 foreach (Scene scene in m_localScenes)
337 { 364 {
338 m_currentScene = scene; 365 if (scene.RegionInfo.RegionID == regionID)
339 return true; 366 {
367 m_currentScene = scene;
368 return true;
369 }
340 } 370 }
341 } 371 }
342 372
@@ -345,26 +375,33 @@ namespace OpenSim.Region.Framework.Scenes
345 375
346 public bool TryGetScene(string regionName, out Scene scene) 376 public bool TryGetScene(string regionName, out Scene scene)
347 { 377 {
348 foreach (Scene mscene in m_localScenes) 378 lock (m_localScenes)
349 { 379 {
350 if (String.Compare(mscene.RegionInfo.RegionName, regionName, true) == 0) 380 foreach (Scene mscene in m_localScenes)
351 { 381 {
352 scene = mscene; 382 if (String.Compare(mscene.RegionInfo.RegionName, regionName, true) == 0)
353 return true; 383 {
384 scene = mscene;
385 return true;
386 }
354 } 387 }
355 } 388 }
389
356 scene = null; 390 scene = null;
357 return false; 391 return false;
358 } 392 }
359 393
360 public bool TryGetScene(UUID regionID, out Scene scene) 394 public bool TryGetScene(UUID regionID, out Scene scene)
361 { 395 {
362 foreach (Scene mscene in m_localScenes) 396 lock (m_localScenes)
363 { 397 {
364 if (mscene.RegionInfo.RegionID == regionID) 398 foreach (Scene mscene in m_localScenes)
365 { 399 {
366 scene = mscene; 400 if (mscene.RegionInfo.RegionID == regionID)
367 return true; 401 {
402 scene = mscene;
403 return true;
404 }
368 } 405 }
369 } 406 }
370 407
@@ -374,13 +411,16 @@ namespace OpenSim.Region.Framework.Scenes
374 411
375 public bool TryGetScene(uint locX, uint locY, out Scene scene) 412 public bool TryGetScene(uint locX, uint locY, out Scene scene)
376 { 413 {
377 foreach (Scene mscene in m_localScenes) 414 lock (m_localScenes)
378 { 415 {
379 if (mscene.RegionInfo.RegionLocX == locX && 416 foreach (Scene mscene in m_localScenes)
380 mscene.RegionInfo.RegionLocY == locY)
381 { 417 {
382 scene = mscene; 418 if (mscene.RegionInfo.RegionLocX == locX &&
383 return true; 419 mscene.RegionInfo.RegionLocY == locY)
420 {
421 scene = mscene;
422 return true;
423 }
384 } 424 }
385 } 425 }
386 426
@@ -390,13 +430,16 @@ namespace OpenSim.Region.Framework.Scenes
390 430
391 public bool TryGetScene(IPEndPoint ipEndPoint, out Scene scene) 431 public bool TryGetScene(IPEndPoint ipEndPoint, out Scene scene)
392 { 432 {
393 foreach (Scene mscene in m_localScenes) 433 lock (m_localScenes)
394 { 434 {
395 if ((mscene.RegionInfo.InternalEndPoint.Equals(ipEndPoint.Address)) && 435 foreach (Scene mscene in m_localScenes)
396 (mscene.RegionInfo.InternalEndPoint.Port == ipEndPoint.Port))
397 { 436 {
398 scene = mscene; 437 if ((mscene.RegionInfo.InternalEndPoint.Equals(ipEndPoint.Address)) &&
399 return true; 438 (mscene.RegionInfo.InternalEndPoint.Port == ipEndPoint.Port))
439 {
440 scene = mscene;
441 return true;
442 }
400 } 443 }
401 } 444 }
402 445
@@ -465,11 +508,14 @@ namespace OpenSim.Region.Framework.Scenes
465 508
466 public RegionInfo GetRegionInfo(UUID regionID) 509 public RegionInfo GetRegionInfo(UUID regionID)
467 { 510 {
468 foreach (Scene scene in m_localScenes) 511 lock (m_localScenes)
469 { 512 {
470 if (scene.RegionInfo.RegionID == regionID) 513 foreach (Scene scene in m_localScenes)
471 { 514 {
472 return scene.RegionInfo; 515 if (scene.RegionInfo.RegionID == regionID)
516 {
517 return scene.RegionInfo;
518 }
473 } 519 }
474 } 520 }
475 521
@@ -488,11 +534,14 @@ namespace OpenSim.Region.Framework.Scenes
488 534
489 public bool TryGetScenePresence(UUID avatarId, out ScenePresence avatar) 535 public bool TryGetScenePresence(UUID avatarId, out ScenePresence avatar)
490 { 536 {
491 foreach (Scene scene in m_localScenes) 537 lock (m_localScenes)
492 { 538 {
493 if (scene.TryGetScenePresence(avatarId, out avatar)) 539 foreach (Scene scene in m_localScenes)
494 { 540 {
495 return true; 541 if (scene.TryGetScenePresence(avatarId, out avatar))
542 {
543 return true;
544 }
496 } 545 }
497 } 546 }
498 547
@@ -503,12 +552,16 @@ namespace OpenSim.Region.Framework.Scenes
503 public bool TryGetAvatarsScene(UUID avatarId, out Scene scene) 552 public bool TryGetAvatarsScene(UUID avatarId, out Scene scene)
504 { 553 {
505 ScenePresence avatar = null; 554 ScenePresence avatar = null;
506 foreach (Scene mScene in m_localScenes) 555
556 lock (m_localScenes)
507 { 557 {
508 if (mScene.TryGetScenePresence(avatarId, out avatar)) 558 foreach (Scene mScene in m_localScenes)
509 { 559 {
510 scene = mScene; 560 if (mScene.TryGetScenePresence(avatarId, out avatar))
511 return true; 561 {
562 scene = mScene;
563 return true;
564 }
512 } 565 }
513 } 566 }
514 567
@@ -518,17 +571,22 @@ namespace OpenSim.Region.Framework.Scenes
518 571
519 public void CloseScene(Scene scene) 572 public void CloseScene(Scene scene)
520 { 573 {
521 m_localScenes.Remove(scene); 574 lock (m_localScenes)
575 m_localScenes.Remove(scene);
576
522 scene.Close(); 577 scene.Close();
523 } 578 }
524 579
525 public bool TryGetAvatarByName(string avatarName, out ScenePresence avatar) 580 public bool TryGetAvatarByName(string avatarName, out ScenePresence avatar)
526 { 581 {
527 foreach (Scene scene in m_localScenes) 582 lock (m_localScenes)
528 { 583 {
529 if (scene.TryGetAvatarByName(avatarName, out avatar)) 584 foreach (Scene scene in m_localScenes)
530 { 585 {
531 return true; 586 if (scene.TryGetAvatarByName(avatarName, out avatar))
587 {
588 return true;
589 }
532 } 590 }
533 } 591 }
534 592
@@ -538,7 +596,8 @@ namespace OpenSim.Region.Framework.Scenes
538 596
539 public void ForEachScene(Action<Scene> action) 597 public void ForEachScene(Action<Scene> action)
540 { 598 {
541 m_localScenes.ForEach(action); 599 lock (m_localScenes)
600 m_localScenes.ForEach(action);
542 } 601 }
543 } 602 }
544} 603}