World.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System;
  2. using libsecondlife;
  3. using libsecondlife.Packets;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. using PhysicsSystem;
  7. namespace OpenSim.world
  8. {
  9. public class World
  10. {
  11. public Dictionary<libsecondlife.LLUUID, Entity> Entities;
  12. public float[] LandMap;
  13. public ScriptEngine Scripts;
  14. public TerrainDecode terrainengine = new TerrainDecode();
  15. public uint _localNumber=0;
  16. private PhysicsScene phyScene;
  17. private float timeStep= 0.1f;
  18. private Random Rand = new Random();
  19. public World()
  20. {
  21. Console.WriteLine("World.cs - creating new entitities instance");
  22. Entities = new Dictionary<libsecondlife.LLUUID, Entity>();
  23. Console.WriteLine("World.cs - creating LandMap");
  24. terrainengine = new TerrainDecode();
  25. LandMap = new float[65536];
  26. for(int i =0; i < 65536; i++) {
  27. LandMap[i] = 21.4989f;
  28. }
  29. Console.WriteLine("World.cs - Creating script engine instance");
  30. // Initialise this only after the world has loaded
  31. Scripts = new ScriptEngine(this);
  32. }
  33. public PhysicsScene PhysScene
  34. {
  35. set
  36. {
  37. this.phyScene = value;
  38. }
  39. }
  40. public void Update()
  41. {
  42. if(this.phyScene.IsThreaded)
  43. {
  44. this.phyScene.GetResults();
  45. }
  46. foreach (libsecondlife.LLUUID UUID in Entities.Keys)
  47. {
  48. Entities[UUID].addFroces();
  49. }
  50. this.phyScene.Simulate(timeStep);
  51. foreach (libsecondlife.LLUUID UUID in Entities.Keys)
  52. {
  53. Entities[UUID].update();
  54. }
  55. }
  56. public void SendLayerData(OpenSimClient RemoteClient) {
  57. for(int x=0; x<16; x=x+4) for(int y=0; y<16; y++){
  58. Packet layerpack=this.terrainengine.CreateLayerPacket(LandMap, x,y,x+4,y+1);
  59. RemoteClient.OutPacket(layerpack);
  60. }
  61. }
  62. public void AddViewerAgent(OpenSimClient AgentClient) {
  63. Console.WriteLine("World.cs:AddViewerAgent() - Creating new avatar for remote viewer agent");
  64. Avatar NewAvatar = new Avatar(AgentClient);
  65. Console.WriteLine("World.cs:AddViewerAgent() - Adding new avatar to world");
  66. this.Entities.Add(AgentClient.AgentID, NewAvatar);
  67. Console.WriteLine("World.cs:AddViewerAgent() - Starting RegionHandshake ");
  68. NewAvatar.SendRegionHandshake(this);
  69. NewAvatar.PhysActor = this.phyScene.AddAvatar(new PhysicsVector(NewAvatar.position.X, NewAvatar.position.Y, NewAvatar.position.Z));
  70. //this.Update(); // will work for now, but needs to be optimised so we don't update everything in the sim for each new user
  71. }
  72. public bool Backup() {
  73. /* TODO: Save the current world entities state. */
  74. return false;
  75. }
  76. }
  77. }