diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim.RegionServer/world/World.cs | 302 |
1 files changed, 119 insertions, 183 deletions
diff --git a/OpenSim.RegionServer/world/World.cs b/OpenSim.RegionServer/world/World.cs index 640ab81..72214d4 100644 --- a/OpenSim.RegionServer/world/World.cs +++ b/OpenSim.RegionServer/world/World.cs | |||
@@ -18,33 +18,39 @@ using OpenSim.Terrain; | |||
18 | 18 | ||
19 | namespace OpenSim.world | 19 | namespace OpenSim.world |
20 | { | 20 | { |
21 | public partial class World : ILocalStorageReceiver, IScriptAPI | 21 | public partial class World : WorldBase, ILocalStorageReceiver, IScriptAPI |
22 | { | 22 | { |
23 | public object LockPhysicsEngine = new object(); | 23 | public object LockPhysicsEngine = new object(); |
24 | public Dictionary<libsecondlife.LLUUID, Entity> Entities; | ||
25 | public Dictionary<libsecondlife.LLUUID, Avatar> Avatars; | 24 | public Dictionary<libsecondlife.LLUUID, Avatar> Avatars; |
26 | public Dictionary<libsecondlife.LLUUID, Primitive> Prims; | 25 | public Dictionary<libsecondlife.LLUUID, Primitive> Prims; |
27 | //public ScriptEngine Scripts; | 26 | //public ScriptEngine Scripts; |
28 | public TerrainEngine Terrain; //TODO: Replace TerrainManager with this. | ||
29 | public uint _localNumber = 0; | 27 | public uint _localNumber = 0; |
30 | private PhysicsScene phyScene; | 28 | private PhysicsScene phyScene; |
31 | private float timeStep = 0.1f; | 29 | private float timeStep = 0.1f; |
32 | private libsecondlife.TerrainManager TerrainManager; // To be referenced via TerrainEngine | ||
33 | public ILocalStorage localStorage; | 30 | public ILocalStorage localStorage; |
34 | private Random Rand = new Random(); | 31 | private Random Rand = new Random(); |
35 | private uint _primCount = 702000; | 32 | private uint _primCount = 702000; |
36 | private int storageCount; | 33 | private int storageCount; |
37 | private Dictionary<uint, SimClient> m_clientThreads; | ||
38 | private Dictionary<LLUUID, ScriptHandler> m_scriptHandlers; | 34 | private Dictionary<LLUUID, ScriptHandler> m_scriptHandlers; |
39 | private Dictionary<string, ScriptFactory> m_scripts; | 35 | private Dictionary<string, ScriptFactory> m_scripts; |
40 | private ulong m_regionHandle; | ||
41 | private string m_regionName; | ||
42 | private InventoryCache _inventoryCache; | ||
43 | private AssetCache _assetCache; | ||
44 | private Mutex updateLock; | 36 | private Mutex updateLock; |
45 | private RegionInfo m_regInfo; | ||
46 | public string m_datastore; | 37 | public string m_datastore; |
47 | 38 | ||
39 | #region Properties | ||
40 | public PhysicsScene PhysScene | ||
41 | { | ||
42 | set | ||
43 | { | ||
44 | this.phyScene = value; | ||
45 | } | ||
46 | get | ||
47 | { | ||
48 | return (this.phyScene); | ||
49 | } | ||
50 | } | ||
51 | #endregion | ||
52 | |||
53 | #region Constructors | ||
48 | /// <summary> | 54 | /// <summary> |
49 | /// Creates a new World class, and a region to go with it. | 55 | /// Creates a new World class, and a region to go with it. |
50 | /// </summary> | 56 | /// </summary> |
@@ -85,7 +91,9 @@ namespace OpenSim.world | |||
85 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.CRITICAL,"World.cs: Constructor failed with exception " + e.ToString()); | 91 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.CRITICAL,"World.cs: Constructor failed with exception " + e.ToString()); |
86 | } | 92 | } |
87 | } | 93 | } |
94 | #endregion | ||
88 | 95 | ||
96 | #region Script Methods | ||
89 | /// <summary> | 97 | /// <summary> |
90 | /// Loads a new script into the specified entity | 98 | /// Loads a new script into the specified entity |
91 | /// </summary> | 99 | /// </summary> |
@@ -156,37 +164,13 @@ namespace OpenSim.world | |||
156 | } | 164 | } |
157 | } | 165 | } |
158 | 166 | ||
159 | public InventoryCache InventoryCache | 167 | #endregion |
160 | { | ||
161 | set | ||
162 | { | ||
163 | this._inventoryCache = value; | ||
164 | } | ||
165 | } | ||
166 | |||
167 | public AssetCache AssetCache | ||
168 | { | ||
169 | set | ||
170 | { | ||
171 | this._assetCache = value; | ||
172 | } | ||
173 | } | ||
174 | public PhysicsScene PhysScene | ||
175 | { | ||
176 | set | ||
177 | { | ||
178 | this.phyScene = value; | ||
179 | } | ||
180 | get | ||
181 | { | ||
182 | return (this.phyScene); | ||
183 | } | ||
184 | } | ||
185 | 168 | ||
169 | #region Update Methods | ||
186 | /// <summary> | 170 | /// <summary> |
187 | /// Performs per-frame updates on the world, this should be the central world loop | 171 | /// Performs per-frame updates on the world, this should be the central world loop |
188 | /// </summary> | 172 | /// </summary> |
189 | public void Update() | 173 | public override void Update() |
190 | { | 174 | { |
191 | updateLock.WaitOne(); | 175 | updateLock.WaitOne(); |
192 | try | 176 | try |
@@ -235,6 +219,40 @@ namespace OpenSim.world | |||
235 | updateLock.ReleaseMutex(); | 219 | updateLock.ReleaseMutex(); |
236 | } | 220 | } |
237 | 221 | ||
222 | public bool Backup() | ||
223 | { | ||
224 | try | ||
225 | { | ||
226 | // Terrain backup routines | ||
227 | if (Terrain.tainted > 0) | ||
228 | { | ||
229 | Terrain.tainted = 0; | ||
230 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs: Backup() - Terrain tainted, saving."); | ||
231 | localStorage.SaveMap(Terrain.getHeights1D()); | ||
232 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs: Backup() - Terrain saved, informing Physics."); | ||
233 | phyScene.SetTerrain(Terrain.getHeights1D()); | ||
234 | } | ||
235 | |||
236 | // Primitive backup routines | ||
237 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs: Backup() - Backing up Primitives"); | ||
238 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | ||
239 | { | ||
240 | Entities[UUID].BackUp(); | ||
241 | } | ||
242 | |||
243 | // Backup successful | ||
244 | return true; | ||
245 | } | ||
246 | catch (Exception e) | ||
247 | { | ||
248 | // Backup failed | ||
249 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH, "World.cs: Backup() - Backup Failed with exception " + e.ToString()); | ||
250 | return false; | ||
251 | } | ||
252 | } | ||
253 | #endregion | ||
254 | |||
255 | #region Setup Methods | ||
238 | /// <summary> | 256 | /// <summary> |
239 | /// Loads a new storage subsystem from a named library | 257 | /// Loads a new storage subsystem from a named library |
240 | /// </summary> | 258 | /// </summary> |
@@ -279,6 +297,16 @@ namespace OpenSim.world | |||
279 | } | 297 | } |
280 | } | 298 | } |
281 | 299 | ||
300 | public void SetDefaultScripts() | ||
301 | { | ||
302 | this.m_scripts.Add("FollowRandomAvatar", delegate() | ||
303 | { | ||
304 | return new OpenSim.RegionServer.world.scripting.FollowRandomAvatar(); | ||
305 | }); | ||
306 | } | ||
307 | |||
308 | #endregion | ||
309 | |||
282 | #region Regenerate Terrain | 310 | #region Regenerate Terrain |
283 | 311 | ||
284 | /// <summary> | 312 | /// <summary> |
@@ -375,10 +403,11 @@ namespace OpenSim.world | |||
375 | 403 | ||
376 | #endregion | 404 | #endregion |
377 | 405 | ||
406 | #region Load Terrain | ||
378 | /// <summary> | 407 | /// <summary> |
379 | /// Loads the World heightmap | 408 | /// Loads the World heightmap |
380 | /// </summary> | 409 | /// </summary> |
381 | public void LoadWorldMap() | 410 | public override void LoadWorldMap() |
382 | { | 411 | { |
383 | try | 412 | try |
384 | { | 413 | { |
@@ -400,6 +429,32 @@ namespace OpenSim.world | |||
400 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM,"World.cs: LoadWorldMap() - Failed with exception " + e.ToString()); | 429 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM,"World.cs: LoadWorldMap() - Failed with exception " + e.ToString()); |
401 | } | 430 | } |
402 | } | 431 | } |
432 | #endregion | ||
433 | |||
434 | #region Primitives Methods | ||
435 | |||
436 | /// <summary> | ||
437 | /// Sends prims to a client | ||
438 | /// </summary> | ||
439 | /// <param name="RemoteClient">Client to send to</param> | ||
440 | public void GetInitialPrims(SimClient RemoteClient) | ||
441 | { | ||
442 | try | ||
443 | { | ||
444 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | ||
445 | { | ||
446 | if (Entities[UUID] is Primitive) | ||
447 | { | ||
448 | Primitive primitive = Entities[UUID] as Primitive; | ||
449 | primitive.UpdateClient(RemoteClient); | ||
450 | } | ||
451 | } | ||
452 | } | ||
453 | catch (Exception e) | ||
454 | { | ||
455 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: GetInitialPrims() - Failed with exception " + e.ToString()); | ||
456 | } | ||
457 | } | ||
403 | 458 | ||
404 | /// <summary> | 459 | /// <summary> |
405 | /// Loads the World's objects | 460 | /// Loads the World's objects |
@@ -440,108 +495,37 @@ namespace OpenSim.world | |||
440 | } | 495 | } |
441 | } | 496 | } |
442 | 497 | ||
443 | /// <summary> | 498 | public void AddNewPrim(ObjectAddPacket addPacket, SimClient AgentClient) |
444 | /// Tidy before shutdown | ||
445 | /// </summary> | ||
446 | public void Close() | ||
447 | { | ||
448 | try | ||
449 | { | ||
450 | this.localStorage.ShutDown(); | ||
451 | } | ||
452 | catch (Exception e) | ||
453 | { | ||
454 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH,"World.cs: Close() - Failed with exception " + e.ToString()); | ||
455 | } | ||
456 | } | ||
457 | |||
458 | /// <summary> | ||
459 | /// Send the region heightmap to the client | ||
460 | /// </summary> | ||
461 | /// <param name="RemoteClient">Client to send to</param> | ||
462 | public void SendLayerData(SimClient RemoteClient) | ||
463 | { | 499 | { |
464 | try | 500 | try |
465 | { | 501 | { |
466 | int[] patches = new int[4]; | 502 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs: AddNewPrim() - Creating new prim"); |
467 | 503 | Primitive prim = new Primitive(m_clientThreads, m_regionHandle, this); | |
468 | for (int y = 0; y < 16; y++) | 504 | prim.CreateFromPacket(addPacket, AgentClient.AgentID, this._primCount); |
505 | PhysicsVector pVec = new PhysicsVector(prim.Pos.X, prim.Pos.Y, prim.Pos.Z); | ||
506 | PhysicsVector pSize = new PhysicsVector(0.255f, 0.255f, 0.255f); | ||
507 | if (OpenSim.world.Avatar.PhysicsEngineFlying) | ||
469 | { | 508 | { |
470 | for (int x = 0; x < 16; x = x + 4) | 509 | lock (this.LockPhysicsEngine) |
471 | { | 510 | { |
472 | patches[0] = x + 0 + y * 16; | 511 | prim.PhysActor = this.phyScene.AddPrim(pVec, pSize); |
473 | patches[1] = x + 1 + y * 16; | ||
474 | patches[2] = x + 2 + y * 16; | ||
475 | patches[3] = x + 3 + y * 16; | ||
476 | |||
477 | Packet layerpack = TerrainManager.CreateLandPacket(Terrain.getHeights1D(), patches); | ||
478 | RemoteClient.OutPacket(layerpack); | ||
479 | } | 512 | } |
480 | } | 513 | } |
481 | } | ||
482 | catch (Exception e) | ||
483 | { | ||
484 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM,"World.cs: SendLayerData() - Failed with exception " + e.ToString()); | ||
485 | } | ||
486 | } | ||
487 | |||
488 | /// <summary> | ||
489 | /// Sends a specified patch to a client | ||
490 | /// </summary> | ||
491 | /// <param name="px">Patch coordinate (x) 0..16</param> | ||
492 | /// <param name="py">Patch coordinate (y) 0..16</param> | ||
493 | /// <param name="RemoteClient">The client to send to</param> | ||
494 | public void SendLayerData(int px, int py, SimClient RemoteClient) | ||
495 | { | ||
496 | try | ||
497 | { | ||
498 | int[] patches = new int[1]; | ||
499 | int patchx, patchy; | ||
500 | patchx = px / 16; | ||
501 | /* if (patchx > 12) | ||
502 | { | ||
503 | patchx = 12; | ||
504 | }*/ | ||
505 | patchy = py / 16; | ||
506 | 514 | ||
507 | patches[0] = patchx + 0 + patchy * 16; | 515 | this.Entities.Add(prim.uuid, prim); |
508 | //patches[1] = patchx + 1 + patchy * 16; | 516 | this._primCount++; |
509 | //patches[2] = patchx + 2 + patchy * 16; | ||
510 | //patches[3] = patchx + 3 + patchy * 16; | ||
511 | |||
512 | Packet layerpack = TerrainManager.CreateLandPacket(Terrain.getHeights1D(), patches); | ||
513 | RemoteClient.OutPacket(layerpack); | ||
514 | } | 517 | } |
515 | catch (Exception e) | 518 | catch (Exception e) |
516 | { | 519 | { |
517 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM,"World.cs: SendLayerData() - Failed with exception " + e.ToString()); | 520 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: AddNewPrim() - Failed with exception " + e.ToString()); |
518 | } | 521 | } |
519 | } | 522 | } |
520 | 523 | ||
521 | /// <summary> | 524 | #endregion |
522 | /// Sends prims to a client | 525 | |
523 | /// </summary> | 526 | #region Add/Remove Avatar Methods |
524 | /// <param name="RemoteClient">Client to send to</param> | ||
525 | public void GetInitialPrims(SimClient RemoteClient) | ||
526 | { | ||
527 | try | ||
528 | { | ||
529 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | ||
530 | { | ||
531 | if (Entities[UUID] is Primitive) | ||
532 | { | ||
533 | Primitive primitive = Entities[UUID] as Primitive; | ||
534 | primitive.UpdateClient(RemoteClient); | ||
535 | } | ||
536 | } | ||
537 | } | ||
538 | catch (Exception e) | ||
539 | { | ||
540 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM,"World.cs: GetInitialPrims() - Failed with exception " + e.ToString()); | ||
541 | } | ||
542 | } | ||
543 | 527 | ||
544 | public void AddViewerAgent(SimClient agentClient) | 528 | public override void AddViewerAgent(SimClient agentClient) |
545 | { | 529 | { |
546 | try | 530 | try |
547 | { | 531 | { |
@@ -587,7 +571,7 @@ namespace OpenSim.world | |||
587 | } | 571 | } |
588 | } | 572 | } |
589 | 573 | ||
590 | public void RemoveViewerAgent(SimClient agentClient) | 574 | public override void RemoveViewerAgent(SimClient agentClient) |
591 | { | 575 | { |
592 | try | 576 | try |
593 | { | 577 | { |
@@ -609,72 +593,24 @@ namespace OpenSim.world | |||
609 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM,"World.cs: RemoveViewerAgent() - Failed with exception " + e.ToString()); | 593 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM,"World.cs: RemoveViewerAgent() - Failed with exception " + e.ToString()); |
610 | } | 594 | } |
611 | } | 595 | } |
596 | #endregion | ||
612 | 597 | ||
613 | public void AddNewPrim(ObjectAddPacket addPacket, SimClient AgentClient) | 598 | #region ShutDown |
614 | { | 599 | /// <summary> |
615 | try | 600 | /// Tidy before shutdown |
616 | { | 601 | /// </summary> |
617 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"World.cs: AddNewPrim() - Creating new prim"); | 602 | public override void Close() |
618 | Primitive prim = new Primitive(m_clientThreads, m_regionHandle, this); | ||
619 | prim.CreateFromPacket(addPacket, AgentClient.AgentID, this._primCount); | ||
620 | PhysicsVector pVec = new PhysicsVector(prim.Pos.X, prim.Pos.Y, prim.Pos.Z); | ||
621 | PhysicsVector pSize = new PhysicsVector(0.255f, 0.255f, 0.255f); | ||
622 | if (OpenSim.world.Avatar.PhysicsEngineFlying) | ||
623 | { | ||
624 | lock (this.LockPhysicsEngine) | ||
625 | { | ||
626 | prim.PhysActor = this.phyScene.AddPrim(pVec, pSize); | ||
627 | } | ||
628 | } | ||
629 | |||
630 | this.Entities.Add(prim.uuid, prim); | ||
631 | this._primCount++; | ||
632 | } | ||
633 | catch (Exception e) | ||
634 | { | ||
635 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM,"World.cs: AddNewPrim() - Failed with exception " + e.ToString()); | ||
636 | } | ||
637 | } | ||
638 | |||
639 | public bool Backup() | ||
640 | { | 603 | { |
641 | try | 604 | try |
642 | { | 605 | { |
643 | // Terrain backup routines | 606 | this.localStorage.ShutDown(); |
644 | if (Terrain.tainted > 0) | ||
645 | { | ||
646 | Terrain.tainted = 0; | ||
647 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"World.cs: Backup() - Terrain tainted, saving."); | ||
648 | localStorage.SaveMap(Terrain.getHeights1D()); | ||
649 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"World.cs: Backup() - Terrain saved, informing Physics."); | ||
650 | phyScene.SetTerrain(Terrain.getHeights1D()); | ||
651 | } | ||
652 | |||
653 | // Primitive backup routines | ||
654 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"World.cs: Backup() - Backing up Primitives"); | ||
655 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | ||
656 | { | ||
657 | Entities[UUID].BackUp(); | ||
658 | } | ||
659 | |||
660 | // Backup successful | ||
661 | return true; | ||
662 | } | 607 | } |
663 | catch (Exception e) | 608 | catch (Exception e) |
664 | { | 609 | { |
665 | // Backup failed | 610 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH, "World.cs: Close() - Failed with exception " + e.ToString()); |
666 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH,"World.cs: Backup() - Backup Failed with exception " + e.ToString()); | ||
667 | return false; | ||
668 | } | 611 | } |
669 | } | 612 | } |
670 | 613 | #endregion | |
671 | public void SetDefaultScripts() | ||
672 | { | ||
673 | this.m_scripts.Add("FollowRandomAvatar", delegate() | ||
674 | { | ||
675 | return new OpenSim.RegionServer.world.scripting.FollowRandomAvatar(); | ||
676 | }); | ||
677 | } | ||
678 | 614 | ||
679 | } | 615 | } |
680 | } | 616 | } |