aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/world/World.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/world/World.cs')
-rw-r--r--src/world/World.cs208
1 files changed, 0 insertions, 208 deletions
diff --git a/src/world/World.cs b/src/world/World.cs
deleted file mode 100644
index e1c84bc..0000000
--- a/src/world/World.cs
+++ /dev/null
@@ -1,208 +0,0 @@
1using System;
2using libsecondlife;
3using libsecondlife.Packets;
4using System.Collections.Generic;
5using System.Text;
6using System.Reflection;
7using System.IO;
8using PhysicsSystem;
9using GridInterfaces;
10
11namespace OpenSim.world
12{
13 public class World : ILocalStorageReceiver
14 {
15 public Dictionary<libsecondlife.LLUUID, Entity> Entities;
16 public float[] LandMap;
17 public ScriptEngine Scripts;
18 public uint _localNumber=0;
19 private PhysicsScene phyScene;
20 private float timeStep= 0.1f;
21 private libsecondlife.TerrainManager TerrainManager;
22 public ILocalStorage localStorage;
23 private Random Rand = new Random();
24 private uint _primCount = 702000;
25 private int storageCount;
26
27 public World()
28 {
29 ServerConsole.MainConsole.Instance.WriteLine("World.cs - creating new entitities instance");
30 Entities = new Dictionary<libsecondlife.LLUUID, Entity>();
31
32 ServerConsole.MainConsole.Instance.WriteLine("World.cs - creating LandMap");
33 TerrainManager = new TerrainManager(new SecondLife());
34 Avatar.SetupTemplate("avatar-template.dat");
35 // ServerConsole.MainConsole.Instance.WriteLine("World.cs - Creating script engine instance");
36 // Initialise this only after the world has loaded
37 // Scripts = new ScriptEngine(this);
38 }
39
40 public PhysicsScene PhysScene
41 {
42 set
43 {
44 this.phyScene = value;
45 }
46 get
47 {
48 return(this.phyScene);
49 }
50 }
51
52 public void Update()
53 {
54 if(this.phyScene.IsThreaded)
55 {
56 this.phyScene.GetResults();
57
58 }
59
60 foreach (libsecondlife.LLUUID UUID in Entities.Keys)
61 {
62 Entities[UUID].addForces();
63 }
64
65 this.phyScene.Simulate(timeStep);
66
67 foreach (libsecondlife.LLUUID UUID in Entities.Keys)
68 {
69 Entities[UUID].update();
70 }
71
72 //backup world data
73 this.storageCount++;
74 if(storageCount> 300) //set to how often you want to backup
75 {
76 this.Backup();
77 storageCount =0;
78 }
79 }
80
81 public bool LoadStorageDLL(string dllName)
82 {
83 Assembly pluginAssembly = Assembly.LoadFrom(dllName);
84 ILocalStorage store = null;
85
86 foreach (Type pluginType in pluginAssembly.GetTypes())
87 {
88 if (pluginType.IsPublic)
89 {
90 if (!pluginType.IsAbstract)
91 {
92 Type typeInterface = pluginType.GetInterface("ILocalStorage", true);
93
94 if (typeInterface != null)
95 {
96 ILocalStorage plug = (ILocalStorage)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
97 store = plug;
98 break;
99 }
100
101 typeInterface = null;
102 }
103 }
104 }
105 pluginAssembly = null;
106 this.localStorage = store;
107 return(store == null);
108 }
109
110 public void RegenerateTerrain()
111 {
112 HeightmapGenHills hills = new HeightmapGenHills();
113 this.LandMap = hills.GenerateHeightmap(200, 4.0f, 80.0f, false);
114 this.phyScene.SetTerrain(this.LandMap);
115 OpenSim_Main.cfg.SaveMap();
116
117 foreach(OpenSimClient client in OpenSim_Main.sim.ClientThreads.Values) {
118 this.SendLayerData(client);
119 }
120 }
121 public void LoadPrimsFromStorage()
122 {
123 ServerConsole.MainConsole.Instance.WriteLine("World.cs: LoadPrimsFromStorage() - Loading primitives");
124 this.localStorage.LoadPrimitives(this);
125 }
126
127 public void PrimFromStorage(PrimData prim)
128 {
129 if(prim.LocalID >= this._primCount)
130 {
131 _primCount = prim.LocalID + 1;
132 }
133 ServerConsole.MainConsole.Instance.WriteLine("World.cs: PrimFromStorage() - Reloading prim (localId "+ prim.LocalID+ " ) from storage");
134 Primitive nPrim = new Primitive();
135 nPrim.CreateFromStorage(prim);
136 this.Entities.Add(nPrim.uuid, nPrim);
137 }
138
139 public void Close()
140 {
141 this.localStorage.ShutDown();
142 }
143
144 public void SendLayerData(OpenSimClient RemoteClient) {
145 int[] patches = new int[4];
146
147 for (int y = 0; y < 16; y++)
148 {
149 for (int x = 0; x < 16; x = x + 4)
150 {
151 patches[0] = x + 0 + y * 16;
152 patches[1] = x + 1 + y * 16;
153 patches[2] = x + 2 + y * 16;
154 patches[3] = x + 3 + y * 16;
155
156 Packet layerpack = TerrainManager.CreateLandPacket(LandMap, patches);
157 RemoteClient.OutPacket(layerpack);
158 }
159 }
160 }
161
162 public void GetInitialPrims(OpenSimClient RemoteClient)
163 {
164 foreach (libsecondlife.LLUUID UUID in Entities.Keys)
165 {
166 if(Entities[UUID].ToString()== "OpenSim.world.Primitive")
167 {
168 ((OpenSim.world.Primitive)Entities[UUID]).UpdateClient(RemoteClient);
169 }
170 }
171 }
172
173 public void AddViewerAgent(OpenSimClient AgentClient) {
174 ServerConsole.MainConsole.Instance.WriteLine("World.cs:AddViewerAgent() - Creating new avatar for remote viewer agent");
175 Avatar NewAvatar = new Avatar(AgentClient);
176 ServerConsole.MainConsole.Instance.WriteLine("World.cs:AddViewerAgent() - Adding new avatar to world");
177 ServerConsole.MainConsole.Instance.WriteLine("World.cs:AddViewerAgent() - Starting RegionHandshake ");
178 NewAvatar.SendRegionHandshake(this);
179 PhysicsVector pVec = new PhysicsVector(NewAvatar.position.X, NewAvatar.position.Y, NewAvatar.position.Z);
180 NewAvatar.PhysActor = this.phyScene.AddAvatar(pVec);
181 this.Entities.Add(AgentClient.AgentID, NewAvatar);
182 }
183
184 public void AddNewPrim(ObjectAddPacket addPacket, OpenSimClient AgentClient)
185 {
186 ServerConsole.MainConsole.Instance.WriteLine("World.cs: AddNewPrim() - Creating new prim");
187 Primitive prim = new Primitive();
188 prim.CreateFromPacket(addPacket, AgentClient.AgentID, this._primCount);
189 PhysicsVector pVec = new PhysicsVector(prim.position.X, prim.position.Y, prim.position.Z);
190 PhysicsVector pSize = new PhysicsVector( 0.25f, 0.25f, 0.25f);
191 //prim.PhysActor = this.phyScene.AddPrim(pVec, pSize );
192 //prim.PhysicsEnabled = true;
193 this.Entities.Add(prim.uuid, prim);
194 this._primCount++;
195 }
196
197 public bool Backup() {
198 /* TODO: Save the current world entities state. */
199 ServerConsole.MainConsole.Instance.WriteLine("World.cs: Backup() - Backing up Primitives");
200 foreach (libsecondlife.LLUUID UUID in Entities.Keys)
201 {
202 Entities[UUID].BackUp();
203 }
204 return true;
205 }
206
207 }
208}