diff options
author | Adam Frisby | 2007-04-22 03:15:22 +0000 |
---|---|---|
committer | Adam Frisby | 2007-04-22 03:15:22 +0000 |
commit | c6b1dd0fac3ab030c17fa638279b6fcb31b25a1b (patch) | |
tree | 6a5d651806e9e6d95c3cac478c7a84de61423c5d /OpenSim.RegionServer/world | |
parent | Comments (Part 2/2) (diff) | |
download | opensim-SC_OLD-c6b1dd0fac3ab030c17fa638279b6fcb31b25a1b.zip opensim-SC_OLD-c6b1dd0fac3ab030c17fa638279b6fcb31b25a1b.tar.gz opensim-SC_OLD-c6b1dd0fac3ab030c17fa638279b6fcb31b25a1b.tar.bz2 opensim-SC_OLD-c6b1dd0fac3ab030c17fa638279b6fcb31b25a1b.tar.xz |
Added exception handling to each function in World.cs - code is assumed stable so MSVC debugging of this code should no longer be needed. If however, it is needed, put a breakpoint on the exception handler concerned.
Diffstat (limited to 'OpenSim.RegionServer/world')
-rw-r--r-- | OpenSim.RegionServer/world/World.cs | 593 |
1 files changed, 369 insertions, 224 deletions
diff --git a/OpenSim.RegionServer/world/World.cs b/OpenSim.RegionServer/world/World.cs index 4d57f14..721497a 100644 --- a/OpenSim.RegionServer/world/World.cs +++ b/OpenSim.RegionServer/world/World.cs | |||
@@ -45,75 +45,95 @@ namespace OpenSim.world | |||
45 | 45 | ||
46 | public World(Dictionary<uint, SimClient> clientThreads, ulong regionHandle, string regionName) | 46 | public World(Dictionary<uint, SimClient> clientThreads, ulong regionHandle, string regionName) |
47 | { | 47 | { |
48 | m_clientThreads = clientThreads; | 48 | try |
49 | m_regionHandle = regionHandle; | 49 | { |
50 | m_regionName = regionName; | 50 | m_clientThreads = clientThreads; |
51 | 51 | m_regionHandle = regionHandle; | |
52 | m_scriptHandlers = new Dictionary<LLUUID, ScriptHandler>(); | 52 | m_regionName = regionName; |
53 | m_scripts = new Dictionary<string, ScriptFactory>(); | 53 | |
54 | 54 | m_scriptHandlers = new Dictionary<LLUUID, ScriptHandler>(); | |
55 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs - creating new entitities instance"); | 55 | m_scripts = new Dictionary<string, ScriptFactory>(); |
56 | Entities = new Dictionary<libsecondlife.LLUUID, Entity>(); | 56 | |
57 | Avatars = new Dictionary<LLUUID, Avatar>(); | 57 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs - creating new entitities instance"); |
58 | Prims = new Dictionary<LLUUID, Primitive>(); | 58 | Entities = new Dictionary<libsecondlife.LLUUID, Entity>(); |
59 | 59 | Avatars = new Dictionary<LLUUID, Avatar>(); | |
60 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs - creating LandMap"); | 60 | Prims = new Dictionary<LLUUID, Primitive>(); |
61 | TerrainManager = new TerrainManager(new SecondLife()); | 61 | |
62 | Terrain = new TerrainEngine(); | 62 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs - creating LandMap"); |
63 | Avatar.SetupTemplate("avatar-template.dat"); | 63 | TerrainManager = new TerrainManager(new SecondLife()); |
64 | // MainConsole.Instance.WriteLine("World.cs - Creating script engine instance"); | 64 | Terrain = new TerrainEngine(); |
65 | // Initialise this only after the world has loaded | 65 | Avatar.SetupTemplate("avatar-template.dat"); |
66 | // Scripts = new ScriptEngine(this); | 66 | // MainConsole.Instance.WriteLine("World.cs - Creating script engine instance"); |
67 | Avatar.LoadAnims(); | 67 | // Initialise this only after the world has loaded |
68 | this.SetDefaultScripts(); | 68 | // Scripts = new ScriptEngine(this); |
69 | this.LoadScriptEngines(); | 69 | Avatar.LoadAnims(); |
70 | this.SetDefaultScripts(); | ||
71 | this.LoadScriptEngines(); | ||
72 | } | ||
73 | catch (Exception e) | ||
74 | { | ||
75 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: Constructor failed with exception " + e.ToString()); | ||
76 | } | ||
70 | } | 77 | } |
71 | 78 | ||
72 | public void AddScript(Entity entity, Script script) | 79 | public void AddScript(Entity entity, Script script) |
73 | { | 80 | { |
74 | ScriptHandler scriptHandler = new ScriptHandler(script, entity, this); | 81 | try |
75 | m_scriptHandlers.Add(scriptHandler.ScriptId, scriptHandler); | 82 | { |
83 | ScriptHandler scriptHandler = new ScriptHandler(script, entity, this); | ||
84 | m_scriptHandlers.Add(scriptHandler.ScriptId, scriptHandler); | ||
85 | } | ||
86 | catch (Exception e) | ||
87 | { | ||
88 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: AddScript() - Failed with exception " + e.ToString()); | ||
89 | } | ||
76 | } | 90 | } |
77 | 91 | ||
78 | public void AddScript(Entity entity, string scriptData) | 92 | public void AddScript(Entity entity, string scriptData) |
79 | { | 93 | { |
80 | int scriptstart = 0; | 94 | try |
81 | int scriptend = 0; | 95 | { |
82 | string substring; | 96 | int scriptstart = 0; |
83 | scriptstart = scriptData.LastIndexOf("<Script>"); | 97 | int scriptend = 0; |
84 | scriptend = scriptData.LastIndexOf("</Script>"); | 98 | string substring; |
85 | substring = scriptData.Substring(scriptstart + 8, scriptend - scriptstart - 8); | 99 | scriptstart = scriptData.LastIndexOf("<Script>"); |
86 | substring = substring.Trim(); | 100 | scriptend = scriptData.LastIndexOf("</Script>"); |
87 | //Console.WriteLine("searching for script to add: " + substring); | 101 | substring = scriptData.Substring(scriptstart + 8, scriptend - scriptstart - 8); |
88 | 102 | substring = substring.Trim(); | |
89 | ScriptFactory scriptFactory; | 103 | //Console.WriteLine("searching for script to add: " + substring); |
90 | //Console.WriteLine("script string is " + substring); | 104 | |
91 | if (substring.StartsWith("<ScriptEngine:")) | 105 | ScriptFactory scriptFactory; |
92 | { | 106 | //Console.WriteLine("script string is " + substring); |
93 | string substring1 = ""; | 107 | if (substring.StartsWith("<ScriptEngine:")) |
94 | string script = ""; | 108 | { |
95 | // Console.WriteLine("searching for script engine"); | 109 | string substring1 = ""; |
96 | substring1 = substring.Remove(0, 14); | 110 | string script = ""; |
97 | int dev = substring1.IndexOf(','); | 111 | // Console.WriteLine("searching for script engine"); |
98 | string sEngine = substring1.Substring(0, dev); | 112 | substring1 = substring.Remove(0, 14); |
99 | substring1 = substring1.Remove(0, dev + 1); | 113 | int dev = substring1.IndexOf(','); |
100 | int end = substring1.IndexOf('>'); | 114 | string sEngine = substring1.Substring(0, dev); |
101 | string sName = substring1.Substring(0, end); | 115 | substring1 = substring1.Remove(0, dev + 1); |
102 | //Console.WriteLine(" script info : " + sEngine + " , " + sName); | 116 | int end = substring1.IndexOf('>'); |
103 | int startscript = substring.IndexOf('>'); | 117 | string sName = substring1.Substring(0, end); |
104 | script = substring.Remove(0, startscript + 1); | 118 | //Console.WriteLine(" script info : " + sEngine + " , " + sName); |
105 | // Console.WriteLine("script data is " + script); | 119 | int startscript = substring.IndexOf('>'); |
106 | if (this.scriptEngines.ContainsKey(sEngine)) | 120 | script = substring.Remove(0, startscript + 1); |
121 | // Console.WriteLine("script data is " + script); | ||
122 | if (this.scriptEngines.ContainsKey(sEngine)) | ||
123 | { | ||
124 | this.scriptEngines[sEngine].LoadScript(script, sName, entity.localid); | ||
125 | } | ||
126 | } | ||
127 | else if (this.m_scripts.TryGetValue(substring, out scriptFactory)) | ||
107 | { | 128 | { |
108 | this.scriptEngines[sEngine].LoadScript(script, sName, entity.localid); | 129 | //Console.WriteLine("added script"); |
130 | this.AddScript(entity, scriptFactory()); | ||
109 | } | 131 | } |
110 | } | 132 | } |
111 | else if (this.m_scripts.TryGetValue(substring, out scriptFactory)) | 133 | catch (Exception e) |
112 | { | 134 | { |
113 | //Console.WriteLine("added script"); | 135 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: AddScript() - Failed with exception " + e.ToString()); |
114 | this.AddScript(entity, scriptFactory()); | ||
115 | } | 136 | } |
116 | |||
117 | } | 137 | } |
118 | 138 | ||
119 | public InventoryCache InventoryCache | 139 | public InventoryCache InventoryCache |
@@ -145,306 +165,431 @@ namespace OpenSim.world | |||
145 | 165 | ||
146 | public void Update() | 166 | public void Update() |
147 | { | 167 | { |
148 | if (this.phyScene.IsThreaded) | 168 | try |
149 | { | 169 | { |
150 | this.phyScene.GetResults(); | 170 | if (this.phyScene.IsThreaded) |
171 | { | ||
172 | this.phyScene.GetResults(); | ||
151 | 173 | ||
152 | } | 174 | } |
153 | 175 | ||
154 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | 176 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) |
155 | { | 177 | { |
156 | Entities[UUID].addForces(); | 178 | Entities[UUID].addForces(); |
157 | } | 179 | } |
158 | 180 | ||
159 | lock (this.LockPhysicsEngine) | 181 | lock (this.LockPhysicsEngine) |
160 | { | 182 | { |
161 | this.phyScene.Simulate(timeStep); | 183 | this.phyScene.Simulate(timeStep); |
162 | } | 184 | } |
163 | 185 | ||
164 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | 186 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) |
165 | { | 187 | { |
166 | Entities[UUID].update(); | 188 | Entities[UUID].update(); |
167 | } | 189 | } |
168 | 190 | ||
169 | foreach (ScriptHandler scriptHandler in m_scriptHandlers.Values) | 191 | foreach (ScriptHandler scriptHandler in m_scriptHandlers.Values) |
170 | { | 192 | { |
171 | scriptHandler.OnFrame(); | 193 | scriptHandler.OnFrame(); |
172 | } | 194 | } |
173 | foreach (IScriptEngine scripteng in this.scriptEngines.Values) | 195 | foreach (IScriptEngine scripteng in this.scriptEngines.Values) |
174 | { | 196 | { |
175 | scripteng.OnFrame(); | 197 | scripteng.OnFrame(); |
198 | } | ||
199 | //backup world data | ||
200 | this.storageCount++; | ||
201 | if (storageCount > 1200) //set to how often you want to backup | ||
202 | { | ||
203 | this.Backup(); | ||
204 | storageCount = 0; | ||
205 | } | ||
176 | } | 206 | } |
177 | //backup world data | 207 | catch (Exception e) |
178 | this.storageCount++; | ||
179 | if (storageCount > 1200) //set to how often you want to backup | ||
180 | { | 208 | { |
181 | this.Backup(); | 209 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: Update() - Failed with exception " + e.ToString()); |
182 | storageCount = 0; | ||
183 | } | 210 | } |
184 | } | 211 | } |
185 | 212 | ||
186 | public bool LoadStorageDLL(string dllName) | 213 | public bool LoadStorageDLL(string dllName) |
187 | { | 214 | { |
188 | Assembly pluginAssembly = Assembly.LoadFrom(dllName); | 215 | try |
189 | ILocalStorage store = null; | ||
190 | |||
191 | foreach (Type pluginType in pluginAssembly.GetTypes()) | ||
192 | { | 216 | { |
193 | if (pluginType.IsPublic) | 217 | Assembly pluginAssembly = Assembly.LoadFrom(dllName); |
218 | ILocalStorage store = null; | ||
219 | |||
220 | foreach (Type pluginType in pluginAssembly.GetTypes()) | ||
194 | { | 221 | { |
195 | if (!pluginType.IsAbstract) | 222 | if (pluginType.IsPublic) |
196 | { | 223 | { |
197 | Type typeInterface = pluginType.GetInterface("ILocalStorage", true); | 224 | if (!pluginType.IsAbstract) |
198 | |||
199 | if (typeInterface != null) | ||
200 | { | 225 | { |
201 | ILocalStorage plug = (ILocalStorage)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); | 226 | Type typeInterface = pluginType.GetInterface("ILocalStorage", true); |
202 | store = plug; | 227 | |
203 | break; | 228 | if (typeInterface != null) |
204 | } | 229 | { |
230 | ILocalStorage plug = (ILocalStorage)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); | ||
231 | store = plug; | ||
232 | break; | ||
233 | } | ||
205 | 234 | ||
206 | typeInterface = null; | 235 | typeInterface = null; |
236 | } | ||
207 | } | 237 | } |
208 | } | 238 | } |
239 | pluginAssembly = null; | ||
240 | this.localStorage = store; | ||
241 | return (store == null); | ||
242 | } | ||
243 | catch (Exception e) | ||
244 | { | ||
245 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: LoadStorageDLL() - Failed with exception " + e.ToString()); | ||
209 | } | 246 | } |
210 | pluginAssembly = null; | ||
211 | this.localStorage = store; | ||
212 | return (store == null); | ||
213 | } | 247 | } |
214 | 248 | ||
215 | #region Regenerate Terrain | 249 | #region Regenerate Terrain |
216 | 250 | ||
217 | public void RegenerateTerrain() | 251 | public void RegenerateTerrain() |
218 | { | 252 | { |
219 | Terrain.hills(); | 253 | try |
220 | |||
221 | lock (this.LockPhysicsEngine) | ||
222 | { | 254 | { |
223 | this.phyScene.SetTerrain(Terrain.getHeights1D()); | 255 | Terrain.hills(); |
224 | } | ||
225 | this.localStorage.SaveMap(this.Terrain.getHeights1D()); | ||
226 | 256 | ||
227 | foreach (SimClient client in m_clientThreads.Values) | 257 | lock (this.LockPhysicsEngine) |
228 | { | 258 | { |
229 | this.SendLayerData(client); | 259 | this.phyScene.SetTerrain(Terrain.getHeights1D()); |
230 | } | 260 | } |
261 | this.localStorage.SaveMap(this.Terrain.getHeights1D()); | ||
231 | 262 | ||
232 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | 263 | foreach (SimClient client in m_clientThreads.Values) |
264 | { | ||
265 | this.SendLayerData(client); | ||
266 | } | ||
267 | |||
268 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | ||
269 | { | ||
270 | Entities[UUID].LandRenegerated(); | ||
271 | } | ||
272 | } | ||
273 | catch (Exception e) | ||
233 | { | 274 | { |
234 | Entities[UUID].LandRenegerated(); | 275 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: RegenerateTerrain() - Failed with exception " + e.ToString()); |
235 | } | 276 | } |
236 | } | 277 | } |
237 | 278 | ||
238 | public void RegenerateTerrain(float[,] newMap) | 279 | public void RegenerateTerrain(float[,] newMap) |
239 | { | 280 | { |
240 | this.Terrain.setHeights2D(newMap); | 281 | try |
241 | lock (this.LockPhysicsEngine) | ||
242 | { | 282 | { |
243 | this.phyScene.SetTerrain(this.Terrain.getHeights1D()); | 283 | this.Terrain.setHeights2D(newMap); |
244 | } | 284 | lock (this.LockPhysicsEngine) |
245 | this.localStorage.SaveMap(this.Terrain.getHeights1D()); | 285 | { |
286 | this.phyScene.SetTerrain(this.Terrain.getHeights1D()); | ||
287 | } | ||
288 | this.localStorage.SaveMap(this.Terrain.getHeights1D()); | ||
246 | 289 | ||
247 | foreach (SimClient client in m_clientThreads.Values) | 290 | foreach (SimClient client in m_clientThreads.Values) |
248 | { | 291 | { |
249 | this.SendLayerData(client); | 292 | this.SendLayerData(client); |
250 | } | 293 | } |
251 | 294 | ||
252 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | 295 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) |
296 | { | ||
297 | Entities[UUID].LandRenegerated(); | ||
298 | } | ||
299 | } | ||
300 | catch (Exception e) | ||
253 | { | 301 | { |
254 | Entities[UUID].LandRenegerated(); | 302 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: RegenerateTerrain() - Failed with exception " + e.ToString()); |
255 | } | 303 | } |
256 | } | 304 | } |
257 | 305 | ||
258 | public void RegenerateTerrain(bool changes, int pointx, int pointy) | 306 | public void RegenerateTerrain(bool changes, int pointx, int pointy) |
259 | { | 307 | { |
260 | if (changes) | 308 | try |
261 | { | 309 | { |
262 | lock (this.LockPhysicsEngine) | 310 | if (changes) |
263 | { | 311 | { |
264 | this.phyScene.SetTerrain(this.Terrain.getHeights1D()); | 312 | lock (this.LockPhysicsEngine) |
265 | } | 313 | { |
266 | this.localStorage.SaveMap(this.Terrain.getHeights1D()); | 314 | this.phyScene.SetTerrain(this.Terrain.getHeights1D()); |
315 | } | ||
316 | this.localStorage.SaveMap(this.Terrain.getHeights1D()); | ||
267 | 317 | ||
268 | foreach (SimClient client in m_clientThreads.Values) | 318 | foreach (SimClient client in m_clientThreads.Values) |
269 | { | 319 | { |
270 | this.SendLayerData(pointx, pointy, client); | 320 | this.SendLayerData(pointx, pointy, client); |
321 | } | ||
271 | } | 322 | } |
272 | } | 323 | } |
324 | catch (Exception e) | ||
325 | { | ||
326 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: RegenerateTerrain() - Failed with exception " + e.ToString()); | ||
327 | } | ||
273 | } | 328 | } |
274 | 329 | ||
275 | #endregion | 330 | #endregion |
276 | 331 | ||
277 | public void LoadWorldMap() | 332 | public void LoadWorldMap() |
278 | { | 333 | { |
279 | float[] map = this.localStorage.LoadWorld(); | 334 | try |
280 | if (map == null) | ||
281 | { | 335 | { |
282 | Console.WriteLine("creating new terrain"); | 336 | float[] map = this.localStorage.LoadWorld(); |
283 | this.Terrain.hills(); | 337 | if (map == null) |
338 | { | ||
339 | Console.WriteLine("creating new terrain"); | ||
340 | this.Terrain.hills(); | ||
284 | 341 | ||
285 | this.localStorage.SaveMap(this.Terrain.getHeights1D()); | 342 | this.localStorage.SaveMap(this.Terrain.getHeights1D()); |
343 | } | ||
344 | else | ||
345 | { | ||
346 | this.Terrain.setHeights1D(map); | ||
347 | } | ||
286 | } | 348 | } |
287 | else | 349 | catch (Exception e) |
288 | { | 350 | { |
289 | this.Terrain.setHeights1D(map); | 351 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: LoadWorldMap() - Failed with exception " + e.ToString()); |
290 | } | 352 | } |
291 | } | 353 | } |
292 | 354 | ||
293 | public void LoadPrimsFromStorage() | 355 | public void LoadPrimsFromStorage() |
294 | { | 356 | { |
295 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: LoadPrimsFromStorage() - Loading primitives"); | 357 | try |
296 | this.localStorage.LoadPrimitives(this); | 358 | { |
359 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: LoadPrimsFromStorage() - Loading primitives"); | ||
360 | this.localStorage.LoadPrimitives(this); | ||
361 | } | ||
362 | catch (Exception e) | ||
363 | { | ||
364 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: LoadPrimsFromStorage() - Failed with exception " + e.ToString()); | ||
365 | } | ||
297 | } | 366 | } |
298 | 367 | ||
299 | public void PrimFromStorage(PrimData prim) | 368 | public void PrimFromStorage(PrimData prim) |
300 | { | 369 | { |
301 | if (prim.LocalID >= this._primCount) | 370 | try |
371 | { | ||
372 | if (prim.LocalID >= this._primCount) | ||
373 | { | ||
374 | _primCount = prim.LocalID + 1; | ||
375 | } | ||
376 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: PrimFromStorage() - Reloading prim (localId " + prim.LocalID + " ) from storage"); | ||
377 | Primitive nPrim = new Primitive(m_clientThreads, m_regionHandle, this); | ||
378 | nPrim.CreateFromStorage(prim); | ||
379 | this.Entities.Add(nPrim.uuid, nPrim); | ||
380 | } | ||
381 | catch (Exception e) | ||
302 | { | 382 | { |
303 | _primCount = prim.LocalID + 1; | 383 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: PrimFromStorage() - Failed with exception " + e.ToString()); |
304 | } | 384 | } |
305 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: PrimFromStorage() - Reloading prim (localId " + prim.LocalID + " ) from storage"); | ||
306 | Primitive nPrim = new Primitive(m_clientThreads, m_regionHandle, this); | ||
307 | nPrim.CreateFromStorage(prim); | ||
308 | this.Entities.Add(nPrim.uuid, nPrim); | ||
309 | } | 385 | } |
310 | 386 | ||
311 | public void Close() | 387 | public void Close() |
312 | { | 388 | { |
313 | this.localStorage.ShutDown(); | 389 | try |
390 | { | ||
391 | this.localStorage.ShutDown(); | ||
392 | } | ||
393 | catch (Exception e) | ||
394 | { | ||
395 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: Close() - Failed with exception " + e.ToString()); | ||
396 | } | ||
314 | } | 397 | } |
315 | 398 | ||
316 | public void SendLayerData(SimClient RemoteClient) | 399 | public void SendLayerData(SimClient RemoteClient) |
317 | { | 400 | { |
318 | int[] patches = new int[4]; | 401 | try |
319 | |||
320 | for (int y = 0; y < 16; y++) | ||
321 | { | 402 | { |
322 | for (int x = 0; x < 16; x = x + 4) | 403 | int[] patches = new int[4]; |
404 | |||
405 | for (int y = 0; y < 16; y++) | ||
323 | { | 406 | { |
324 | patches[0] = x + 0 + y * 16; | 407 | for (int x = 0; x < 16; x = x + 4) |
325 | patches[1] = x + 1 + y * 16; | 408 | { |
326 | patches[2] = x + 2 + y * 16; | 409 | patches[0] = x + 0 + y * 16; |
327 | patches[3] = x + 3 + y * 16; | 410 | patches[1] = x + 1 + y * 16; |
411 | patches[2] = x + 2 + y * 16; | ||
412 | patches[3] = x + 3 + y * 16; | ||
328 | 413 | ||
329 | Packet layerpack = TerrainManager.CreateLandPacket(Terrain.getHeights1D(), patches); | 414 | Packet layerpack = TerrainManager.CreateLandPacket(Terrain.getHeights1D(), patches); |
330 | RemoteClient.OutPacket(layerpack); | 415 | RemoteClient.OutPacket(layerpack); |
416 | } | ||
331 | } | 417 | } |
332 | } | 418 | } |
419 | catch (Exception e) | ||
420 | { | ||
421 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: SendLayerData() - Failed with exception " + e.ToString()); | ||
422 | } | ||
333 | } | 423 | } |
334 | 424 | ||
335 | public void SendLayerData(int px, int py, SimClient RemoteClient) | 425 | public void SendLayerData(int px, int py, SimClient RemoteClient) |
336 | { | 426 | { |
337 | int[] patches = new int[1]; | 427 | try |
338 | int patchx, patchy; | 428 | { |
339 | patchx = px / 16; | 429 | int[] patches = new int[1]; |
340 | /* if (patchx > 12) | 430 | int patchx, patchy; |
341 | { | 431 | patchx = px / 16; |
342 | patchx = 12; | 432 | /* if (patchx > 12) |
343 | }*/ | 433 | { |
344 | patchy = py / 16; | 434 | patchx = 12; |
345 | 435 | }*/ | |
346 | patches[0] = patchx + 0 + patchy * 16; | 436 | patchy = py / 16; |
347 | //patches[1] = patchx + 1 + patchy * 16; | 437 | |
348 | //patches[2] = patchx + 2 + patchy * 16; | 438 | patches[0] = patchx + 0 + patchy * 16; |
349 | //patches[3] = patchx + 3 + patchy * 16; | 439 | //patches[1] = patchx + 1 + patchy * 16; |
350 | 440 | //patches[2] = patchx + 2 + patchy * 16; | |
351 | Packet layerpack = TerrainManager.CreateLandPacket(Terrain.getHeights1D(), patches); | 441 | //patches[3] = patchx + 3 + patchy * 16; |
352 | RemoteClient.OutPacket(layerpack); | 442 | |
443 | Packet layerpack = TerrainManager.CreateLandPacket(Terrain.getHeights1D(), patches); | ||
444 | RemoteClient.OutPacket(layerpack); | ||
445 | } | ||
446 | catch (Exception e) | ||
447 | { | ||
448 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: SendLayerData() - Failed with exception " + e.ToString()); | ||
449 | } | ||
353 | } | 450 | } |
354 | 451 | ||
355 | public void GetInitialPrims(SimClient RemoteClient) | 452 | public void GetInitialPrims(SimClient RemoteClient) |
356 | { | 453 | { |
357 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | 454 | try |
358 | { | 455 | { |
359 | if (Entities[UUID] is Primitive) | 456 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) |
360 | { | 457 | { |
361 | Primitive primitive = Entities[UUID] as Primitive; | 458 | if (Entities[UUID] is Primitive) |
362 | primitive.UpdateClient(RemoteClient); | 459 | { |
460 | Primitive primitive = Entities[UUID] as Primitive; | ||
461 | primitive.UpdateClient(RemoteClient); | ||
462 | } | ||
363 | } | 463 | } |
364 | } | 464 | } |
465 | catch (Exception e) | ||
466 | { | ||
467 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: GetInitialPrims() - Failed with exception " + e.ToString()); | ||
468 | } | ||
365 | } | 469 | } |
366 | 470 | ||
367 | public void AddViewerAgent(SimClient agentClient) | 471 | public void AddViewerAgent(SimClient agentClient) |
368 | { | 472 | { |
369 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs:AddViewerAgent() - Creating new avatar for remote viewer agent"); | 473 | try |
370 | Avatar newAvatar = new Avatar(agentClient, this, m_regionName, m_clientThreads, m_regionHandle); | 474 | { |
371 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs:AddViewerAgent() - Adding new avatar to world"); | 475 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs:AddViewerAgent() - Creating new avatar for remote viewer agent"); |
372 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs:AddViewerAgent() - Starting RegionHandshake "); | 476 | Avatar newAvatar = new Avatar(agentClient, this, m_regionName, m_clientThreads, m_regionHandle); |
373 | newAvatar.SendRegionHandshake(this); | 477 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs:AddViewerAgent() - Adding new avatar to world"); |
374 | if (!agentClient.m_child) | 478 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs:AddViewerAgent() - Starting RegionHandshake "); |
375 | { | 479 | newAvatar.SendRegionHandshake(this); |
376 | PhysicsVector pVec = new PhysicsVector(newAvatar.Pos.X, newAvatar.Pos.Y, newAvatar.Pos.Z); | 480 | if (!agentClient.m_child) |
377 | lock (this.LockPhysicsEngine) | ||
378 | { | 481 | { |
379 | newAvatar.PhysActor = this.phyScene.AddAvatar(pVec); | 482 | PhysicsVector pVec = new PhysicsVector(newAvatar.Pos.X, newAvatar.Pos.Y, newAvatar.Pos.Z); |
483 | lock (this.LockPhysicsEngine) | ||
484 | { | ||
485 | newAvatar.PhysActor = this.phyScene.AddAvatar(pVec); | ||
486 | } | ||
487 | } | ||
488 | lock (Entities) | ||
489 | { | ||
490 | this.Entities.Add(agentClient.AgentID, newAvatar); | ||
491 | } | ||
492 | lock (Avatars) | ||
493 | { | ||
494 | this.Avatars.Add(agentClient.AgentID, newAvatar); | ||
380 | } | 495 | } |
381 | } | 496 | } |
382 | lock (Entities) | 497 | catch (Exception e) |
383 | { | ||
384 | this.Entities.Add(agentClient.AgentID, newAvatar); | ||
385 | } | ||
386 | lock (Avatars) | ||
387 | { | 498 | { |
388 | this.Avatars.Add(agentClient.AgentID, newAvatar); | 499 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: AddViewerAgent() - Failed with exception " + e.ToString()); |
389 | } | 500 | } |
390 | |||
391 | } | 501 | } |
392 | 502 | ||
393 | public void RemoveViewerAgent(SimClient agentClient) | 503 | public void RemoveViewerAgent(SimClient agentClient) |
394 | { | 504 | { |
395 | lock (Entities) | 505 | try |
396 | { | 506 | { |
397 | Entities.Remove(agentClient.AgentID); | 507 | lock (Entities) |
508 | { | ||
509 | Entities.Remove(agentClient.AgentID); | ||
510 | } | ||
511 | lock (Avatars) | ||
512 | { | ||
513 | Avatars.Remove(agentClient.AgentID); | ||
514 | } | ||
398 | } | 515 | } |
399 | lock (Avatars) | 516 | catch (Exception e) |
400 | { | 517 | { |
401 | Avatars.Remove(agentClient.AgentID); | 518 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: RemoveViewerAgent() - Failed with exception " + e.ToString()); |
402 | } | 519 | } |
403 | } | 520 | } |
404 | 521 | ||
405 | public void AddNewPrim(ObjectAddPacket addPacket, SimClient AgentClient) | 522 | public void AddNewPrim(ObjectAddPacket addPacket, SimClient AgentClient) |
406 | { | 523 | { |
407 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: AddNewPrim() - Creating new prim"); | 524 | try |
408 | Primitive prim = new Primitive(m_clientThreads, m_regionHandle, this); | 525 | { |
409 | prim.CreateFromPacket(addPacket, AgentClient.AgentID, this._primCount); | 526 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: AddNewPrim() - Creating new prim"); |
410 | PhysicsVector pVec = new PhysicsVector(prim.Pos.X, prim.Pos.Y, prim.Pos.Z); | 527 | Primitive prim = new Primitive(m_clientThreads, m_regionHandle, this); |
411 | PhysicsVector pSize = new PhysicsVector(0.255f, 0.255f, 0.255f); | 528 | prim.CreateFromPacket(addPacket, AgentClient.AgentID, this._primCount); |
412 | if (OpenSim.world.Avatar.PhysicsEngineFlying) | 529 | PhysicsVector pVec = new PhysicsVector(prim.Pos.X, prim.Pos.Y, prim.Pos.Z); |
413 | { | 530 | PhysicsVector pSize = new PhysicsVector(0.255f, 0.255f, 0.255f); |
414 | lock (this.LockPhysicsEngine) | 531 | if (OpenSim.world.Avatar.PhysicsEngineFlying) |
415 | { | 532 | { |
416 | prim.PhysActor = this.phyScene.AddPrim(pVec, pSize); | 533 | lock (this.LockPhysicsEngine) |
534 | { | ||
535 | prim.PhysActor = this.phyScene.AddPrim(pVec, pSize); | ||
536 | } | ||
417 | } | 537 | } |
418 | } | ||
419 | 538 | ||
420 | this.Entities.Add(prim.uuid, prim); | 539 | this.Entities.Add(prim.uuid, prim); |
421 | this._primCount++; | 540 | this._primCount++; |
541 | } | ||
542 | catch (Exception e) | ||
543 | { | ||
544 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: AddNewPrim() - Failed with exception " + e.ToString()); | ||
545 | } | ||
422 | } | 546 | } |
423 | 547 | ||
424 | public bool Backup() | 548 | public bool Backup() |
425 | { | 549 | { |
426 | if (Terrain.tainted > 0) | 550 | try |
427 | { | 551 | { |
428 | Terrain.tainted = 0; | 552 | // Terrain backup routines |
429 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: Backup() - Terrain tainted, saving."); | 553 | if (Terrain.tainted > 0) |
430 | localStorage.SaveMap(Terrain.getHeights1D()); | 554 | { |
431 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: Backup() - Terrain saved, informing Physics."); | 555 | Terrain.tainted = 0; |
432 | phyScene.SetTerrain(Terrain.getHeights1D()); | 556 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: Backup() - Terrain tainted, saving."); |
557 | localStorage.SaveMap(Terrain.getHeights1D()); | ||
558 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: Backup() - Terrain saved, informing Physics."); | ||
559 | phyScene.SetTerrain(Terrain.getHeights1D()); | ||
560 | } | ||
561 | |||
562 | // Primitive backup routines | ||
563 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: Backup() - Backing up Primitives"); | ||
564 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | ||
565 | { | ||
566 | Entities[UUID].BackUp(); | ||
567 | } | ||
568 | |||
569 | // Backup successful | ||
570 | return true; | ||
433 | } | 571 | } |
434 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: Backup() - Backing up Primitives"); | 572 | catch (Exception e) |
435 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | ||
436 | { | 573 | { |
437 | Entities[UUID].BackUp(); | 574 | // Backup failed |
575 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: Backup() - Backup Failed with exception " + e.ToString()); | ||
576 | return false; | ||
438 | } | 577 | } |
439 | return true; | ||
440 | } | 578 | } |
441 | 579 | ||
442 | public void SetDefaultScripts() | 580 | public void SetDefaultScripts() |
443 | { | 581 | { |
444 | this.m_scripts.Add("FollowRandomAvatar", delegate() | 582 | try |
445 | { | 583 | { |
446 | return new FollowRandomAvatar(); | 584 | this.m_scripts.Add("FollowRandomAvatar", delegate() |
447 | }); | 585 | { |
586 | return new FollowRandomAvatar(); | ||
587 | }); | ||
588 | } | ||
589 | catch (Exception e) | ||
590 | { | ||
591 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: SetDefaultScripts() - Failed with exception " + e.ToString()); | ||
592 | } | ||
448 | } | 593 | } |
449 | 594 | ||
450 | } | 595 | } |