diff options
author | Adam Frisby | 2007-07-11 08:02:47 +0000 |
---|---|---|
committer | Adam Frisby | 2007-07-11 08:02:47 +0000 |
commit | 5c7ffdde0b9642a42e8f5987e06eb01220ff7776 (patch) | |
tree | 4b825dc642cb6eb9a060e54bf8d69288fbee4904 /OpenSim/OpenSim.RegionServer/Simulator/World.cs | |
parent | Who would have known that the only way of specifying utf-8 without preamble, ... (diff) | |
download | opensim-SC_OLD-5c7ffdde0b9642a42e8f5987e06eb01220ff7776.zip opensim-SC_OLD-5c7ffdde0b9642a42e8f5987e06eb01220ff7776.tar.gz opensim-SC_OLD-5c7ffdde0b9642a42e8f5987e06eb01220ff7776.tar.bz2 opensim-SC_OLD-5c7ffdde0b9642a42e8f5987e06eb01220ff7776.tar.xz |
* Wiping trunk in prep for Sugilite
Diffstat (limited to 'OpenSim/OpenSim.RegionServer/Simulator/World.cs')
-rw-r--r-- | OpenSim/OpenSim.RegionServer/Simulator/World.cs | 737 |
1 files changed, 0 insertions, 737 deletions
diff --git a/OpenSim/OpenSim.RegionServer/Simulator/World.cs b/OpenSim/OpenSim.RegionServer/Simulator/World.cs deleted file mode 100644 index ac64c79..0000000 --- a/OpenSim/OpenSim.RegionServer/Simulator/World.cs +++ /dev/null | |||
@@ -1,737 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using System; | ||
29 | using libsecondlife; | ||
30 | using libsecondlife.Packets; | ||
31 | using System.Collections.Generic; | ||
32 | using System.Text; | ||
33 | using System.Reflection; | ||
34 | using System.IO; | ||
35 | using System.Threading; | ||
36 | using OpenSim.Physics.Manager; | ||
37 | using OpenSim.Framework.Interfaces; | ||
38 | using OpenSim.Framework.Types; | ||
39 | using OpenSim.Framework.Terrain; | ||
40 | using OpenSim.Framework.Inventory; | ||
41 | using OpenSim.RegionServer.Assets; | ||
42 | |||
43 | using OpenSim.RegionServer.Scripting; | ||
44 | using OpenSim.Terrain; | ||
45 | using OpenSim.Framework.Console; | ||
46 | using OpenSim.RegionServer.Client; | ||
47 | |||
48 | |||
49 | namespace OpenSim.RegionServer.Simulator | ||
50 | { | ||
51 | public partial class World : WorldBase, ILocalStorageReceiver, IScriptAPI | ||
52 | { | ||
53 | public object LockPhysicsEngine = new object(); | ||
54 | public Dictionary<libsecondlife.LLUUID, Avatar> Avatars; | ||
55 | public Dictionary<libsecondlife.LLUUID, Primitive> Prims; | ||
56 | //public ScriptEngine Scripts; | ||
57 | public uint _localNumber = 0; | ||
58 | private PhysicsScene phyScene; | ||
59 | private float timeStep = 0.1f; | ||
60 | public ILocalStorage localStorage; | ||
61 | private Random Rand = new Random(); | ||
62 | private uint _primCount = 702000; | ||
63 | private int storageCount; | ||
64 | private Dictionary<LLUUID, ScriptHandler> m_scriptHandlers; | ||
65 | private Dictionary<string, ScriptFactory> m_scripts; | ||
66 | private Mutex updateLock; | ||
67 | public string m_datastore; | ||
68 | public OpenSim.RegionServer.Simulator.ParcelManager parcelManager; | ||
69 | public OpenSim.RegionServer.Estate.EstateManager estateManager; | ||
70 | |||
71 | #region Properties | ||
72 | public PhysicsScene PhysScene | ||
73 | { | ||
74 | set | ||
75 | { | ||
76 | this.phyScene = value; | ||
77 | } | ||
78 | get | ||
79 | { | ||
80 | return (this.phyScene); | ||
81 | } | ||
82 | } | ||
83 | #endregion | ||
84 | |||
85 | #region Constructors | ||
86 | /// <summary> | ||
87 | /// Creates a new World class, and a region to go with it. | ||
88 | /// </summary> | ||
89 | /// <param name="clientThreads">Dictionary to contain client threads</param> | ||
90 | /// <param name="regionHandle">Region Handle for this region</param> | ||
91 | /// <param name="regionName">Region Name for this region</param> | ||
92 | public World(Dictionary<uint, ClientView> clientThreads, RegionInfo regInfo, ulong regionHandle, string regionName) | ||
93 | { | ||
94 | try | ||
95 | { | ||
96 | updateLock = new Mutex(false); | ||
97 | m_clientThreads = clientThreads; | ||
98 | m_regionHandle = regionHandle; | ||
99 | m_regionName = regionName; | ||
100 | m_regInfo = regInfo; | ||
101 | |||
102 | m_scriptHandlers = new Dictionary<LLUUID, ScriptHandler>(); | ||
103 | m_scripts = new Dictionary<string, ScriptFactory>(); | ||
104 | |||
105 | MainConsole.Instance.Notice("World.cs - creating new entitities instance"); | ||
106 | Entities = new Dictionary<libsecondlife.LLUUID, Entity>(); | ||
107 | Avatars = new Dictionary<LLUUID, Avatar>(); | ||
108 | Prims = new Dictionary<LLUUID, Primitive>(); | ||
109 | |||
110 | MainConsole.Instance.Notice("World.cs - creating LandMap"); | ||
111 | TerrainManager = new TerrainManager(new SecondLife()); | ||
112 | Terrain = new TerrainEngine(); | ||
113 | Avatar.SetupTemplate("avatar-texture.dat"); | ||
114 | // MainConsole.Instance.WriteLine("World.cs - Creating script engine instance"); | ||
115 | // Initialise this only after the world has loaded | ||
116 | // Scripts = new ScriptEngine(this); | ||
117 | Avatar.LoadAnims(); | ||
118 | this.SetDefaultScripts(); | ||
119 | this.LoadScriptEngines(); | ||
120 | |||
121 | } | ||
122 | catch (Exception e) | ||
123 | { | ||
124 | OpenSim.Framework.Console.MainConsole.Instance.Error("World.cs: Constructor failed with exception " + e.ToString()); | ||
125 | } | ||
126 | } | ||
127 | #endregion | ||
128 | |||
129 | #region Script Methods | ||
130 | /// <summary> | ||
131 | /// Loads a new script into the specified entity | ||
132 | /// </summary> | ||
133 | /// <param name="entity">Entity to be scripted</param> | ||
134 | /// <param name="script">The script to load</param> | ||
135 | public void AddScript(Entity entity, Script script) | ||
136 | { | ||
137 | try | ||
138 | { | ||
139 | ScriptHandler scriptHandler = new ScriptHandler(script, entity, this); | ||
140 | m_scriptHandlers.Add(scriptHandler.ScriptId, scriptHandler); | ||
141 | } | ||
142 | catch (Exception e) | ||
143 | { | ||
144 | MainConsole.Instance.Warn("World.cs: AddScript() - Failed with exception " + e.ToString()); | ||
145 | } | ||
146 | } | ||
147 | |||
148 | /// <summary> | ||
149 | /// Loads a new script into the specified entity, using a script loaded from a string. | ||
150 | /// </summary> | ||
151 | /// <param name="entity">The entity to be scripted</param> | ||
152 | /// <param name="scriptData">The string containing the script</param> | ||
153 | public void AddScript(Entity entity, string scriptData) | ||
154 | { | ||
155 | try | ||
156 | { | ||
157 | int scriptstart = 0; | ||
158 | int scriptend = 0; | ||
159 | string substring; | ||
160 | scriptstart = scriptData.LastIndexOf("<Script>"); | ||
161 | scriptend = scriptData.LastIndexOf("</Script>"); | ||
162 | substring = scriptData.Substring(scriptstart + 8, scriptend - scriptstart - 8); | ||
163 | substring = substring.Trim(); | ||
164 | //Console.WriteLine("searching for script to add: " + substring); | ||
165 | |||
166 | ScriptFactory scriptFactory; | ||
167 | //Console.WriteLine("script string is " + substring); | ||
168 | if (substring.StartsWith("<ScriptEngine:")) | ||
169 | { | ||
170 | string substring1 = ""; | ||
171 | string script = ""; | ||
172 | // Console.WriteLine("searching for script engine"); | ||
173 | substring1 = substring.Remove(0, 14); | ||
174 | int dev = substring1.IndexOf(','); | ||
175 | string sEngine = substring1.Substring(0, dev); | ||
176 | substring1 = substring1.Remove(0, dev + 1); | ||
177 | int end = substring1.IndexOf('>'); | ||
178 | string sName = substring1.Substring(0, end); | ||
179 | //Console.WriteLine(" script info : " + sEngine + " , " + sName); | ||
180 | int startscript = substring.IndexOf('>'); | ||
181 | script = substring.Remove(0, startscript + 1); | ||
182 | // Console.WriteLine("script data is " + script); | ||
183 | if (this.scriptEngines.ContainsKey(sEngine)) | ||
184 | { | ||
185 | this.scriptEngines[sEngine].LoadScript(script, sName, entity.localid); | ||
186 | } | ||
187 | } | ||
188 | else if (this.m_scripts.TryGetValue(substring, out scriptFactory)) | ||
189 | { | ||
190 | //Console.WriteLine("added script"); | ||
191 | this.AddScript(entity, scriptFactory()); | ||
192 | } | ||
193 | } | ||
194 | catch (Exception e) | ||
195 | { | ||
196 | MainConsole.Instance.Warn("World.cs: AddScript() - Failed with exception " + e.ToString()); | ||
197 | } | ||
198 | } | ||
199 | |||
200 | #endregion | ||
201 | |||
202 | #region Update Methods | ||
203 | /// <summary> | ||
204 | /// Performs per-frame updates on the world, this should be the central world loop | ||
205 | /// </summary> | ||
206 | public override void Update() | ||
207 | { | ||
208 | updateLock.WaitOne(); | ||
209 | try | ||
210 | { | ||
211 | if (this.phyScene.IsThreaded) | ||
212 | { | ||
213 | this.phyScene.GetResults(); | ||
214 | |||
215 | } | ||
216 | |||
217 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | ||
218 | { | ||
219 | Entities[UUID].addForces(); | ||
220 | } | ||
221 | |||
222 | lock (this.LockPhysicsEngine) | ||
223 | { | ||
224 | this.phyScene.Simulate(timeStep); | ||
225 | } | ||
226 | |||
227 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | ||
228 | { | ||
229 | Entities[UUID].update(); | ||
230 | } | ||
231 | |||
232 | foreach (ScriptHandler scriptHandler in m_scriptHandlers.Values) | ||
233 | { | ||
234 | scriptHandler.OnFrame(); | ||
235 | } | ||
236 | foreach (IScriptEngine scripteng in this.scriptEngines.Values) | ||
237 | { | ||
238 | scripteng.OnFrame(); | ||
239 | } | ||
240 | //backup world data | ||
241 | this.storageCount++; | ||
242 | if (storageCount > 1200) //set to how often you want to backup | ||
243 | { | ||
244 | this.Backup(); | ||
245 | storageCount = 0; | ||
246 | } | ||
247 | } | ||
248 | catch (Exception e) | ||
249 | { | ||
250 | MainConsole.Instance.Warn("World.cs: Update() - Failed with exception " + e.ToString()); | ||
251 | } | ||
252 | updateLock.ReleaseMutex(); | ||
253 | } | ||
254 | |||
255 | public bool Backup() | ||
256 | { | ||
257 | try | ||
258 | { | ||
259 | // Terrain backup routines | ||
260 | if (Terrain.tainted > 0) | ||
261 | { | ||
262 | Terrain.tainted = 0; | ||
263 | MainConsole.Instance.Notice("World.cs: Backup() - Terrain tainted, saving."); | ||
264 | localStorage.SaveMap(Terrain.getHeights1D()); | ||
265 | MainConsole.Instance.Notice("World.cs: Backup() - Rebuilding world map image."); | ||
266 | Terrain.exportImage("map_" + m_regInfo.RegionName.ToLower() + ".png", "defaultstripe.png"); | ||
267 | MainConsole.Instance.Notice("World.cs: Backup() - Terrain saved, informing Physics."); | ||
268 | phyScene.SetTerrain(Terrain.getHeights1D()); | ||
269 | |||
270 | // Needs optimising to just send patches which have changed. | ||
271 | MainConsole.Instance.Notice("World.cs: Backup() - Terrain changed, informing Clients."); | ||
272 | foreach (ClientView client in m_clientThreads.Values) | ||
273 | { | ||
274 | this.SendLayerData(client); | ||
275 | } | ||
276 | } | ||
277 | |||
278 | // Primitive backup routines -- should only do if there's been a change. | ||
279 | MainConsole.Instance.Notice("World.cs: Backup() - Backing up Primitives"); | ||
280 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | ||
281 | { | ||
282 | Entities[UUID].BackUp(); | ||
283 | } | ||
284 | |||
285 | |||
286 | //Parcel backup routines. Yay! | ||
287 | ParcelData[] parcels = new ParcelData[parcelManager.parcelList.Count]; | ||
288 | int i = 0; | ||
289 | foreach(OpenSim.RegionServer.Simulator.Parcel parcel in parcelManager.parcelList.Values) | ||
290 | { | ||
291 | parcels[i] = parcel.parcelData; | ||
292 | i++; | ||
293 | } | ||
294 | localStorage.SaveParcels(parcels); | ||
295 | |||
296 | |||
297 | // Backup successful | ||
298 | return true; | ||
299 | } | ||
300 | catch (Exception e) | ||
301 | { | ||
302 | // Backup failed | ||
303 | OpenSim.Framework.Console.MainConsole.Instance.Error("World.cs: Backup() - Backup Failed with exception " + e.ToString()); | ||
304 | return false; | ||
305 | } | ||
306 | } | ||
307 | #endregion | ||
308 | |||
309 | #region Setup Methods | ||
310 | /// <summary> | ||
311 | /// Loads a new storage subsystem from a named library | ||
312 | /// </summary> | ||
313 | /// <param name="dllName">Storage Library</param> | ||
314 | /// <returns>Successful or not</returns> | ||
315 | public bool LoadStorageDLL(string dllName) | ||
316 | { | ||
317 | try | ||
318 | { | ||
319 | Assembly pluginAssembly = Assembly.LoadFrom(dllName); | ||
320 | ILocalStorage store = null; | ||
321 | |||
322 | foreach (Type pluginType in pluginAssembly.GetTypes()) | ||
323 | { | ||
324 | if (pluginType.IsPublic) | ||
325 | { | ||
326 | if (!pluginType.IsAbstract) | ||
327 | { | ||
328 | Type typeInterface = pluginType.GetInterface("ILocalStorage", true); | ||
329 | |||
330 | if (typeInterface != null) | ||
331 | { | ||
332 | ILocalStorage plug = (ILocalStorage)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); | ||
333 | store = plug; | ||
334 | |||
335 | store.Initialise(this.m_datastore); | ||
336 | break; | ||
337 | } | ||
338 | |||
339 | typeInterface = null; | ||
340 | } | ||
341 | } | ||
342 | } | ||
343 | pluginAssembly = null; | ||
344 | this.localStorage = store; | ||
345 | return (store == null); | ||
346 | } | ||
347 | catch (Exception e) | ||
348 | { | ||
349 | MainConsole.Instance.Warn("World.cs: LoadStorageDLL() - Failed with exception " + e.ToString()); | ||
350 | return false; | ||
351 | } | ||
352 | } | ||
353 | |||
354 | public void SetDefaultScripts() | ||
355 | { | ||
356 | this.m_scripts.Add("FollowRandomAvatar", delegate() | ||
357 | { | ||
358 | return new OpenSim.RegionServer.Scripting.FollowRandomAvatar(); | ||
359 | }); | ||
360 | } | ||
361 | |||
362 | #endregion | ||
363 | |||
364 | #region Regenerate Terrain | ||
365 | |||
366 | /// <summary> | ||
367 | /// Rebuilds the terrain using a procedural algorithm | ||
368 | /// </summary> | ||
369 | public void RegenerateTerrain() | ||
370 | { | ||
371 | try | ||
372 | { | ||
373 | Terrain.hills(); | ||
374 | |||
375 | lock (this.LockPhysicsEngine) | ||
376 | { | ||
377 | this.phyScene.SetTerrain(Terrain.getHeights1D()); | ||
378 | } | ||
379 | this.localStorage.SaveMap(this.Terrain.getHeights1D()); | ||
380 | |||
381 | foreach (ClientView client in m_clientThreads.Values) | ||
382 | { | ||
383 | this.SendLayerData(client); | ||
384 | } | ||
385 | |||
386 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | ||
387 | { | ||
388 | Entities[UUID].LandRenegerated(); | ||
389 | } | ||
390 | } | ||
391 | catch (Exception e) | ||
392 | { | ||
393 | MainConsole.Instance.Warn("World.cs: RegenerateTerrain() - Failed with exception " + e.ToString()); | ||
394 | } | ||
395 | } | ||
396 | |||
397 | /// <summary> | ||
398 | /// Rebuilds the terrain using a 2D float array | ||
399 | /// </summary> | ||
400 | /// <param name="newMap">256,256 float array containing heights</param> | ||
401 | public void RegenerateTerrain(float[,] newMap) | ||
402 | { | ||
403 | try | ||
404 | { | ||
405 | this.Terrain.setHeights2D(newMap); | ||
406 | lock (this.LockPhysicsEngine) | ||
407 | { | ||
408 | this.phyScene.SetTerrain(this.Terrain.getHeights1D()); | ||
409 | } | ||
410 | this.localStorage.SaveMap(this.Terrain.getHeights1D()); | ||
411 | |||
412 | foreach (ClientView client in m_clientThreads.Values) | ||
413 | { | ||
414 | this.SendLayerData(client); | ||
415 | } | ||
416 | |||
417 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | ||
418 | { | ||
419 | Entities[UUID].LandRenegerated(); | ||
420 | } | ||
421 | } | ||
422 | catch (Exception e) | ||
423 | { | ||
424 | MainConsole.Instance.Warn("World.cs: RegenerateTerrain() - Failed with exception " + e.ToString()); | ||
425 | } | ||
426 | } | ||
427 | |||
428 | /// <summary> | ||
429 | /// Rebuilds the terrain assuming changes occured at a specified point[?] | ||
430 | /// </summary> | ||
431 | /// <param name="changes">???</param> | ||
432 | /// <param name="pointx">???</param> | ||
433 | /// <param name="pointy">???</param> | ||
434 | public void RegenerateTerrain(bool changes, int pointx, int pointy) | ||
435 | { | ||
436 | try | ||
437 | { | ||
438 | if (changes) | ||
439 | { | ||
440 | /* Dont save here, rely on tainting system instead */ | ||
441 | |||
442 | foreach (ClientView client in m_clientThreads.Values) | ||
443 | { | ||
444 | this.SendLayerData(pointx, pointy, client); | ||
445 | } | ||
446 | } | ||
447 | } | ||
448 | catch (Exception e) | ||
449 | { | ||
450 | MainConsole.Instance.Warn("World.cs: RegenerateTerrain() - Failed with exception " + e.ToString()); | ||
451 | } | ||
452 | } | ||
453 | |||
454 | #endregion | ||
455 | |||
456 | #region Load Terrain | ||
457 | /// <summary> | ||
458 | /// Loads the World heightmap | ||
459 | /// </summary> | ||
460 | public override void LoadWorldMap() | ||
461 | { | ||
462 | try | ||
463 | { | ||
464 | float[] map = this.localStorage.LoadWorld(); | ||
465 | if (map == null) | ||
466 | { | ||
467 | if (string.IsNullOrEmpty(this.m_regInfo.estateSettings.terrainFile)) | ||
468 | { | ||
469 | Console.WriteLine("No default terrain, procedurally generating..."); | ||
470 | this.Terrain.hills(); | ||
471 | |||
472 | this.localStorage.SaveMap(this.Terrain.getHeights1D()); | ||
473 | } | ||
474 | else | ||
475 | { | ||
476 | try | ||
477 | { | ||
478 | this.Terrain.loadFromFileF32(this.m_regInfo.estateSettings.terrainFile); | ||
479 | this.Terrain *= this.m_regInfo.estateSettings.terrainMultiplier; | ||
480 | } | ||
481 | catch | ||
482 | { | ||
483 | Console.WriteLine("Unable to load default terrain, procedurally generating instead..."); | ||
484 | Terrain.hills(); | ||
485 | } | ||
486 | this.localStorage.SaveMap(this.Terrain.getHeights1D()); | ||
487 | } | ||
488 | } | ||
489 | else | ||
490 | { | ||
491 | this.Terrain.setHeights1D(map); | ||
492 | } | ||
493 | } | ||
494 | catch (Exception e) | ||
495 | { | ||
496 | MainConsole.Instance.Warn("World.cs: LoadWorldMap() - Failed with exception " + e.ToString()); | ||
497 | } | ||
498 | } | ||
499 | #endregion | ||
500 | |||
501 | #region Primitives Methods | ||
502 | |||
503 | /// <summary> | ||
504 | /// Sends prims to a client | ||
505 | /// </summary> | ||
506 | /// <param name="RemoteClient">Client to send to</param> | ||
507 | public void GetInitialPrims(ClientView RemoteClient) | ||
508 | { | ||
509 | try | ||
510 | { | ||
511 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | ||
512 | { | ||
513 | if (Entities[UUID] is Primitive) | ||
514 | { | ||
515 | Primitive primitive = Entities[UUID] as Primitive; | ||
516 | primitive.UpdateClient(RemoteClient); | ||
517 | } | ||
518 | } | ||
519 | } | ||
520 | catch (Exception e) | ||
521 | { | ||
522 | MainConsole.Instance.Warn("World.cs: GetInitialPrims() - Failed with exception " + e.ToString()); | ||
523 | } | ||
524 | } | ||
525 | |||
526 | /// <summary> | ||
527 | /// Loads the World's objects | ||
528 | /// </summary> | ||
529 | public void LoadPrimsFromStorage() | ||
530 | { | ||
531 | try | ||
532 | { | ||
533 | MainConsole.Instance.Notice("World.cs: LoadPrimsFromStorage() - Loading primitives"); | ||
534 | this.localStorage.LoadPrimitives(this); | ||
535 | } | ||
536 | catch (Exception e) | ||
537 | { | ||
538 | MainConsole.Instance.Warn("World.cs: LoadPrimsFromStorage() - Failed with exception " + e.ToString()); | ||
539 | } | ||
540 | } | ||
541 | |||
542 | /// <summary> | ||
543 | /// Loads a specific object from storage | ||
544 | /// </summary> | ||
545 | /// <param name="prim">The object to load</param> | ||
546 | public void PrimFromStorage(PrimData prim) | ||
547 | { | ||
548 | try | ||
549 | { | ||
550 | if (prim.LocalID >= this._primCount) | ||
551 | { | ||
552 | _primCount = prim.LocalID + 1; | ||
553 | } | ||
554 | MainConsole.Instance.Notice("World.cs: PrimFromStorage() - Reloading prim (localId " + prim.LocalID + " ) from storage"); | ||
555 | Primitive nPrim = new Primitive(m_clientThreads, m_regionHandle, this); | ||
556 | nPrim.CreateFromStorage(prim); | ||
557 | this.Entities.Add(nPrim.uuid, nPrim); | ||
558 | } | ||
559 | catch (Exception e) | ||
560 | { | ||
561 | MainConsole.Instance.Warn("World.cs: PrimFromStorage() - Failed with exception " + e.ToString()); | ||
562 | } | ||
563 | } | ||
564 | |||
565 | public void AddNewPrim(Packet addPacket, ClientView agentClient) | ||
566 | { | ||
567 | AddNewPrim((ObjectAddPacket)addPacket, agentClient.AgentID); | ||
568 | } | ||
569 | |||
570 | public void AddNewPrim(ObjectAddPacket addPacket, LLUUID ownerID) | ||
571 | { | ||
572 | try | ||
573 | { | ||
574 | MainConsole.Instance.Notice("World.cs: AddNewPrim() - Creating new prim"); | ||
575 | Primitive prim = new Primitive(m_clientThreads, m_regionHandle, this); | ||
576 | prim.CreateFromPacket(addPacket, ownerID, this._primCount); | ||
577 | PhysicsVector pVec = new PhysicsVector(prim.Pos.X, prim.Pos.Y, prim.Pos.Z); | ||
578 | PhysicsVector pSize = new PhysicsVector(0.255f, 0.255f, 0.255f); | ||
579 | if (OpenSim.RegionServer.Simulator.Avatar.PhysicsEngineFlying) | ||
580 | { | ||
581 | lock (this.LockPhysicsEngine) | ||
582 | { | ||
583 | prim.PhysActor = this.phyScene.AddPrim(pVec, pSize); | ||
584 | } | ||
585 | } | ||
586 | |||
587 | this.Entities.Add(prim.uuid, prim); | ||
588 | this._primCount++; | ||
589 | } | ||
590 | catch (Exception e) | ||
591 | { | ||
592 | MainConsole.Instance.Warn("World.cs: AddNewPrim() - Failed with exception " + e.ToString()); | ||
593 | } | ||
594 | } | ||
595 | |||
596 | #endregion | ||
597 | |||
598 | #region Add/Remove Avatar Methods | ||
599 | |||
600 | public override Avatar AddViewerAgent(ClientView agentClient) | ||
601 | { | ||
602 | //register for events | ||
603 | agentClient.OnChatFromViewer += new ChatFromViewer(this.SimChat); | ||
604 | agentClient.OnRezObject += new RezObject(this.RezObject); | ||
605 | agentClient.OnModifyTerrain += new ModifyTerrain(this.ModifyTerrain); | ||
606 | agentClient.OnRegionHandShakeReply += new ClientView.GenericCall(this.SendLayerData); | ||
607 | agentClient.OnRequestWearables += new ClientView.GenericCall(this.GetInitialPrims); | ||
608 | agentClient.OnRequestAvatarsData += new ClientView.GenericCall(this.SendAvatarsToClient); | ||
609 | agentClient.OnLinkObjects += new LinkObjects(this.LinkObjects); | ||
610 | agentClient.OnAddPrim += new ClientView.GenericCall4(this.AddNewPrim); | ||
611 | agentClient.OnUpdatePrimShape += new ClientView.UpdateShape(this.UpdatePrimShape); | ||
612 | |||
613 | agentClient.OnObjectSelect += new ClientView.ObjectSelect(this.SelectPrim); | ||
614 | agentClient.OnUpdatePrimFlags += new ClientView.UpdatePrimFlags(this.UpdatePrimFlags); | ||
615 | agentClient.OnUpdatePrimTexture += new ClientView.UpdatePrimTexture(this.UpdatePrimTexture); | ||
616 | agentClient.OnUpdatePrimPosition += new ClientView.UpdatePrimVector(this.UpdatePrimPosition); | ||
617 | agentClient.OnUpdatePrimRotation += new ClientView.UpdatePrimRotation(this.UpdatePrimRotation); | ||
618 | agentClient.OnUpdatePrimScale += new ClientView.UpdatePrimVector(this.UpdatePrimScale); | ||
619 | agentClient.OnDeRezObject += new ClientView.GenericCall4(this.DeRezObject); | ||
620 | |||
621 | agentClient.OnParcelPropertiesRequest += new OpenSim.RegionServer.Simulator.ParcelPropertiesRequest(ParcelPropertiesRequest); | ||
622 | agentClient.OnParcelDivideRequest += new OpenSim.RegionServer.Simulator.ParcelDivideRequest(ParcelDivideRequest); | ||
623 | agentClient.OnParcelJoinRequest+=new OpenSim.RegionServer.Simulator.ParcelJoinRequest(ParcelJoinRequest); | ||
624 | agentClient.OnParcelPropertiesUpdateRequest += new OpenSim.RegionServer.Simulator.ParcelPropertiesUpdateRequest(ParcelPropertiesUpdateRequest); | ||
625 | |||
626 | Avatar newAvatar = null; | ||
627 | try | ||
628 | { | ||
629 | MainConsole.Instance.Notice("World.cs:AddViewerAgent() - Creating new avatar for remote viewer agent"); | ||
630 | newAvatar = new Avatar(agentClient, this); | ||
631 | MainConsole.Instance.Notice("World.cs:AddViewerAgent() - Adding new avatar to world"); | ||
632 | MainConsole.Instance.Notice("World.cs:AddViewerAgent() - Starting RegionHandshake "); | ||
633 | estateManager.sendRegionHandshake(newAvatar.ControllingClient); | ||
634 | |||
635 | PhysicsVector pVec = new PhysicsVector(newAvatar.Pos.X, newAvatar.Pos.Y, newAvatar.Pos.Z); | ||
636 | lock (this.LockPhysicsEngine) | ||
637 | { | ||
638 | newAvatar.PhysActor = this.phyScene.AddAvatar(pVec); | ||
639 | } | ||
640 | |||
641 | |||
642 | lock (Entities) | ||
643 | { | ||
644 | if (!Entities.ContainsKey(agentClient.AgentID)) | ||
645 | { | ||
646 | this.Entities.Add(agentClient.AgentID, newAvatar); | ||
647 | } | ||
648 | else | ||
649 | { | ||
650 | Entities[agentClient.AgentID] = newAvatar; | ||
651 | } | ||
652 | } | ||
653 | lock (Avatars) | ||
654 | { | ||
655 | if (Avatars.ContainsKey(agentClient.AgentID)) | ||
656 | { | ||
657 | Avatars[agentClient.AgentID] = newAvatar; | ||
658 | } | ||
659 | else | ||
660 | { | ||
661 | this.Avatars.Add(agentClient.AgentID, newAvatar); | ||
662 | } | ||
663 | } | ||
664 | } | ||
665 | catch (Exception e) | ||
666 | { | ||
667 | MainConsole.Instance.Warn("World.cs: AddViewerAgent() - Failed with exception " + e.ToString()); | ||
668 | } | ||
669 | return newAvatar; | ||
670 | } | ||
671 | |||
672 | |||
673 | |||
674 | |||
675 | |||
676 | |||
677 | |||
678 | public override void RemoveViewerAgent(ClientView agentClient) | ||
679 | { | ||
680 | try | ||
681 | { | ||
682 | lock (Entities) | ||
683 | { | ||
684 | Entities.Remove(agentClient.AgentID); | ||
685 | } | ||
686 | lock (Avatars) | ||
687 | { | ||
688 | Avatars.Remove(agentClient.AgentID); | ||
689 | } | ||
690 | if (agentClient.ClientAvatar.PhysActor != null) | ||
691 | { | ||
692 | this.phyScene.RemoveAvatar(agentClient.ClientAvatar.PhysActor); | ||
693 | } | ||
694 | } | ||
695 | catch (Exception e) | ||
696 | { | ||
697 | MainConsole.Instance.Warn("World.cs: RemoveViewerAgent() - Failed with exception " + e.ToString()); | ||
698 | } | ||
699 | } | ||
700 | #endregion | ||
701 | |||
702 | #region Request Avatars List Methods | ||
703 | //The idea is to have a group of method that return a list of avatars meeting some requirement | ||
704 | // ie it could be all Avatars within a certain range of the calling prim/avatar. | ||
705 | |||
706 | public List<Avatar> RequestAvatarList() | ||
707 | { | ||
708 | List<Avatar> result = new List<Avatar>(); | ||
709 | |||
710 | foreach (Avatar avatar in Avatars.Values) | ||
711 | { | ||
712 | result.Add(avatar); | ||
713 | } | ||
714 | |||
715 | return result; | ||
716 | } | ||
717 | #endregion | ||
718 | |||
719 | #region ShutDown | ||
720 | /// <summary> | ||
721 | /// Tidy before shutdown | ||
722 | /// </summary> | ||
723 | public override void Close() | ||
724 | { | ||
725 | try | ||
726 | { | ||
727 | this.localStorage.ShutDown(); | ||
728 | } | ||
729 | catch (Exception e) | ||
730 | { | ||
731 | OpenSim.Framework.Console.MainConsole.Instance.Error("World.cs: Close() - Failed with exception " + e.ToString()); | ||
732 | } | ||
733 | } | ||
734 | #endregion | ||
735 | |||
736 | } | ||
737 | } | ||