aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.RegionServer/world
diff options
context:
space:
mode:
authorgareth2007-03-22 10:11:15 +0000
committergareth2007-03-22 10:11:15 +0000
commit7daa3955bc3a1918e40962851f9e8d38597a245e (patch)
treebee3e1372a7eed0c1b220a8a49f7bee7d29a6b91 /OpenSim.RegionServer/world
parentLoad XML for neighbourinfo from grid (diff)
downloadopensim-SC_OLD-7daa3955bc3a1918e40962851f9e8d38597a245e.zip
opensim-SC_OLD-7daa3955bc3a1918e40962851f9e8d38597a245e.tar.gz
opensim-SC_OLD-7daa3955bc3a1918e40962851f9e8d38597a245e.tar.bz2
opensim-SC_OLD-7daa3955bc3a1918e40962851f9e8d38597a245e.tar.xz
brought zircon branch into trunk
Diffstat (limited to 'OpenSim.RegionServer/world')
-rw-r--r--OpenSim.RegionServer/world/Avatar.cs501
-rw-r--r--OpenSim.RegionServer/world/Entity.cs67
-rw-r--r--OpenSim.RegionServer/world/Primitive.cs485
-rw-r--r--OpenSim.RegionServer/world/ScriptEngine.cs18
-rw-r--r--OpenSim.RegionServer/world/SurfacePatch.cs22
-rw-r--r--OpenSim.RegionServer/world/World.cs213
-rw-r--r--OpenSim.RegionServer/world/scripting/IScript.cs16
7 files changed, 1322 insertions, 0 deletions
diff --git a/OpenSim.RegionServer/world/Avatar.cs b/OpenSim.RegionServer/world/Avatar.cs
new file mode 100644
index 0000000..b4a3b82
--- /dev/null
+++ b/OpenSim.RegionServer/world/Avatar.cs
@@ -0,0 +1,501 @@
1using System;
2using System.Collections.Generic;
3using System.IO;
4using System.Text;
5using libsecondlife;
6using libsecondlife.Packets;
7using OpenSim.Physics.Manager;
8using Axiom.MathLib;
9
10namespace OpenSim.world
11{
12 public class Avatar : Entity
13 {
14 public static bool PhysicsEngineFlying = false;
15 public string firstname;
16 public string lastname;
17 public SimClient ControllingClient;
18 private PhysicsActor _physActor;
19 private static libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock AvatarTemplate;
20 private bool updateflag = false;
21 private byte movementflag = 0;
22 private List<NewForce> forcesList = new List<NewForce>();
23 private short _updateCount = 0;
24 private Axiom.MathLib.Quaternion bodyRot;
25
26 public Avatar(SimClient TheClient)
27 {
28 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Avatar.cs - Loading details from grid (DUMMY)");
29 ControllingClient = TheClient;
30 localid = 8880000 + (OpenSimRoot.Instance.LocalWorld._localNumber++);
31 position = new LLVector3(100.0f, 100.0f, 30.0f);
32 position.Z = OpenSimRoot.Instance.LocalWorld.LandMap[(int)position.Y * 256 + (int)position.X] + 1;
33 }
34
35 public PhysicsActor PhysActor
36 {
37 set
38 {
39 this._physActor = value;
40 }
41 }
42
43 public override void addForces()
44 {
45 lock (this.forcesList)
46 {
47 if (this.forcesList.Count > 0)
48 {
49 for (int i = 0; i < this.forcesList.Count; i++)
50 {
51 NewForce force = this.forcesList[i];
52 PhysicsVector phyVector = new PhysicsVector(force.X, force.Y, force.Z);
53 this._physActor.Velocity = phyVector;
54 this.updateflag = true;
55 this.velocity = new LLVector3(force.X, force.Y, force.Z); //shouldn't really be doing this
56 // but as we are setting the velocity (rather than using real forces) at the moment it is okay.
57 }
58 for (int i = 0; i < this.forcesList.Count; i++)
59 {
60 this.forcesList.RemoveAt(0);
61 }
62 }
63 }
64 }
65
66 public override void update()
67 {
68
69 if (this.updateflag)
70 {
71 //need to send movement info
72 //so create the improvedterseobjectupdate packet
73 //use CreateTerseBlock()
74 ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = CreateTerseBlock();
75 ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
76 terse.RegionData.RegionHandle = OpenSimRoot.Instance.Cfg.RegionHandle; // FIXME
77 terse.RegionData.TimeDilation = 64096;
78 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
79 terse.ObjectData[0] = terseBlock;
80 foreach (SimClient client in OpenSimRoot.Instance.ClientThreads.Values)
81 {
82 client.OutPacket(terse);
83 }
84
85 updateflag = false;
86 //this._updateCount = 0;
87 }
88 else
89 {
90 //if((movementflag & 1) !=0)
91 //{
92 _updateCount++;
93 if (((!PhysicsEngineFlying) && (_updateCount > 3)) || (_updateCount > 0))
94 {
95 //It has been a while since last update was sent so lets send one.
96 ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = CreateTerseBlock();
97 ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
98 terse.RegionData.RegionHandle = OpenSimRoot.Instance.Cfg.RegionHandle; // FIXME
99 terse.RegionData.TimeDilation = 64096;
100 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
101 terse.ObjectData[0] = terseBlock;
102 foreach (SimClient client in OpenSimRoot.Instance.ClientThreads.Values)
103 {
104 client.OutPacket(terse);
105 }
106 _updateCount = 0;
107 }
108 //}
109 }
110 }
111
112 public static void SetupTemplate(string name)
113 {
114 int i = 0;
115 FileInfo fInfo = new FileInfo(name);
116 long numBytes = fInfo.Length;
117 FileStream fStream = new FileStream(name, FileMode.Open, FileAccess.Read);
118 BinaryReader br = new BinaryReader(fStream);
119 byte[] data1 = br.ReadBytes((int)numBytes);
120 br.Close();
121 fStream.Close();
122
123 libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock objdata = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock(data1, ref i);
124
125 System.Text.Encoding enc = System.Text.Encoding.ASCII;
126 libsecondlife.LLVector3 pos = new LLVector3(objdata.ObjectData, 16);
127 pos.X = 100f;
128 objdata.ID = 8880000;
129 objdata.NameValue = enc.GetBytes("FirstName STRING RW SV Test \nLastName STRING RW SV User \0");
130 libsecondlife.LLVector3 pos2 = new LLVector3(100f, 100f, 23f);
131 //objdata.FullID=user.AgentID;
132 byte[] pb = pos.GetBytes();
133 Array.Copy(pb, 0, objdata.ObjectData, 16, pb.Length);
134
135 Avatar.AvatarTemplate = objdata;
136 }
137
138 public void CompleteMovement(World RegionInfo)
139 {
140 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Avatar.cs:CompleteMovement() - Constructing AgentMovementComplete packet");
141 AgentMovementCompletePacket mov = new AgentMovementCompletePacket();
142 mov.AgentData.SessionID = this.ControllingClient.SessionID;
143 mov.AgentData.AgentID = this.ControllingClient.AgentID;
144 mov.Data.RegionHandle = OpenSimRoot.Instance.Cfg.RegionHandle;
145 // TODO - dynamicalise this stuff
146 mov.Data.Timestamp = 1172750370;
147 mov.Data.Position = new LLVector3(100f, 100f, 23f);
148 mov.Data.LookAt = new LLVector3(0.99f, 0.042f, 0);
149
150 ControllingClient.OutPacket(mov);
151 }
152
153 public void SendInitialPosition()
154 {
155
156 System.Text.Encoding _enc = System.Text.Encoding.ASCII;
157 //send a objectupdate packet with information about the clients avatar
158 ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
159 objupdate.RegionData.RegionHandle = OpenSimRoot.Instance.Cfg.RegionHandle;
160 objupdate.RegionData.TimeDilation = 64096;
161 objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
162
163 objupdate.ObjectData[0] = AvatarTemplate;
164 //give this avatar object a local id and assign the user a name
165 objupdate.ObjectData[0].ID = this.localid;
166 this.uuid = objupdate.ObjectData[0].FullID = ControllingClient.AgentID;
167 objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0");
168
169 libsecondlife.LLVector3 pos2 = new LLVector3((float)this.position.X, (float)this.position.Y, (float)this.position.Z);
170
171 byte[] pb = pos2.GetBytes();
172
173 Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length);
174 OpenSimRoot.Instance.LocalWorld._localNumber++;
175
176 foreach (SimClient client in OpenSimRoot.Instance.ClientThreads.Values)
177 {
178 client.OutPacket(objupdate);
179 if (client.AgentID != ControllingClient.AgentID)
180 {
181 SendAppearanceToOtherAgent(client);
182 }
183 }
184 //this.ControllingClient.OutPacket(objupdate);
185 }
186
187 public void SendInitialAppearance()
188 {
189 AgentWearablesUpdatePacket aw = new AgentWearablesUpdatePacket();
190 aw.AgentData.AgentID = this.ControllingClient.AgentID;
191 aw.AgentData.SerialNum = 0;
192 aw.AgentData.SessionID = ControllingClient.SessionID;
193
194 aw.WearableData = new AgentWearablesUpdatePacket.WearableDataBlock[13];
195 AgentWearablesUpdatePacket.WearableDataBlock awb = new AgentWearablesUpdatePacket.WearableDataBlock();
196 awb.WearableType = (byte)0;
197 awb.AssetID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73");
198 awb.ItemID = LLUUID.Random();
199 aw.WearableData[0] = awb;
200
201 for (int i = 1; i < 13; i++)
202 {
203 awb = new AgentWearablesUpdatePacket.WearableDataBlock();
204 awb.WearableType = (byte)i;
205 awb.AssetID = new LLUUID("00000000-0000-0000-0000-000000000000");
206 awb.ItemID = new LLUUID("00000000-0000-0000-0000-000000000000");
207 aw.WearableData[i] = awb;
208 }
209
210 ControllingClient.OutPacket(aw);
211 }
212
213 public ObjectUpdatePacket CreateUpdatePacket()
214 {
215 System.Text.Encoding _enc = System.Text.Encoding.ASCII;
216 //send a objectupdate packet with information about the clients avatar
217 ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
218 objupdate.RegionData.RegionHandle = OpenSimRoot.Instance.Cfg.RegionHandle;
219 objupdate.RegionData.TimeDilation = 64096;
220 objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
221
222 objupdate.ObjectData[0] = AvatarTemplate;
223 //give this avatar object a local id and assign the user a name
224 objupdate.ObjectData[0].ID = this.localid;
225 objupdate.ObjectData[0].FullID = ControllingClient.AgentID;
226 objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0");
227
228 libsecondlife.LLVector3 pos2 = new LLVector3((float)this._physActor.Position.X, (float)this._physActor.Position.Y, (float)this._physActor.Position.Z);
229
230 byte[] pb = pos2.GetBytes();
231
232 Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length);
233 return objupdate;
234 }
235
236 public void SendAppearanceToOtherAgent(SimClient userInfo)
237 {
238 AvatarAppearancePacket avp = new AvatarAppearancePacket();
239
240
241 avp.VisualParam = new AvatarAppearancePacket.VisualParamBlock[218];
242 //avp.ObjectData.TextureEntry=this.avatar_template.TextureEntry;// br.ReadBytes((int)numBytes);
243
244 LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-0000-000000000005"));
245 avp.ObjectData.TextureEntry = ntex.ToBytes();
246
247 AvatarAppearancePacket.VisualParamBlock avblock = null;
248 for (int i = 0; i < 218; i++)
249 {
250 avblock = new AvatarAppearancePacket.VisualParamBlock();
251 avblock.ParamValue = (byte)100;
252 avp.VisualParam[i] = avblock;
253 }
254
255 avp.Sender.IsTrial = false;
256 avp.Sender.ID = ControllingClient.AgentID;
257 userInfo.OutPacket(avp);
258
259 }
260
261 public void HandleUpdate(AgentUpdatePacket pack)
262 {
263 if (((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.AgentUpdateFlags.AGENT_CONTROL_FLY) != 0)
264 {
265 this._physActor.Flying = true;
266 }
267 else
268 {
269 this._physActor.Flying = false;
270 }
271 if (((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.AgentUpdateFlags.AGENT_CONTROL_AT_POS) != 0)
272 {
273 Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z);
274 if (((movementflag & 1) == 0) || (q != this.bodyRot))
275 {
276 //we should add a new force to the list
277 // but for now we will deal with velocities
278 NewForce newVelocity = new NewForce();
279 Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(1, 0, 0);
280 Axiom.MathLib.Vector3 direc = q * v3;
281 direc.Normalize();
282
283 //work out velocity for sim physics system
284 direc = direc * ((0.03f) * 128f);
285 if (this._physActor.Flying)
286 direc *= 2;
287
288 newVelocity.X = direc.x;
289 newVelocity.Y = direc.y;
290 newVelocity.Z = direc.z;
291 this.forcesList.Add(newVelocity);
292 movementflag = 1;
293 this.bodyRot = q;
294 }
295 }
296 else if ((((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.AgentUpdateFlags.AGENT_CONTROL_UP_POS) != 0) && (PhysicsEngineFlying))
297 {
298 if (((movementflag & 2) == 0) && this._physActor.Flying)
299 {
300 //we should add a new force to the list
301 // but for now we will deal with velocities
302 NewForce newVelocity = new NewForce();
303 Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(0, 0, 1);
304 Axiom.MathLib.Vector3 direc = v3;
305 direc.Normalize();
306
307 //work out velocity for sim physics system
308 direc = direc * ((0.03f) * 128f * 2);
309 newVelocity.X = direc.x;
310 newVelocity.Y = direc.y;
311 newVelocity.Z = direc.z;
312 this.forcesList.Add(newVelocity);
313 movementflag = 2;
314 }
315 }
316 else if ((((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.AgentUpdateFlags.AGENT_CONTROL_UP_NEG) != 0) && (PhysicsEngineFlying))
317 {
318 if (((movementflag & 4) == 0) && this._physActor.Flying)
319 {
320 //we should add a new force to the list
321 // but for now we will deal with velocities
322 NewForce newVelocity = new NewForce();
323 Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(0, 0, -1);
324 //Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z);
325 Axiom.MathLib.Vector3 direc = v3;
326 direc.Normalize();
327
328 //work out velocity for sim physics system
329 direc = direc * ((0.03f) * 128f * 2);
330 newVelocity.X = direc.x;
331 newVelocity.Y = direc.y;
332 newVelocity.Z = direc.z;
333 this.forcesList.Add(newVelocity);
334 movementflag = 4;
335 }
336 }
337 else if (((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.AgentUpdateFlags.AGENT_CONTROL_AT_NEG) != 0)
338 {
339 Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z);
340 if (((movementflag & 8) == 0) || (q != this.bodyRot))
341 {
342 //we should add a new force to the list
343 // but for now we will deal with velocities
344 NewForce newVelocity = new NewForce();
345 Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(-1, 0, 0);
346 Axiom.MathLib.Vector3 direc = q * v3;
347 direc.Normalize();
348
349 //work out velocity for sim physics system
350 direc = direc * ((0.03f) * 128f);
351 if (this._physActor.Flying)
352 direc *= 2;
353
354 newVelocity.X = direc.x;
355 newVelocity.Y = direc.y;
356 newVelocity.Z = direc.z;
357 this.forcesList.Add(newVelocity);
358 movementflag = 8;
359 this.bodyRot = q;
360 }
361 }
362 else
363 {
364 if ((movementflag) != 0)
365 {
366 NewForce newVelocity = new NewForce();
367 newVelocity.X = 0;
368 newVelocity.Y = 0;
369 newVelocity.Z = 0;
370 this.forcesList.Add(newVelocity);
371 movementflag = 0;
372 }
373 }
374 }
375
376 //should be moved somewhere else
377 public void SendRegionHandshake(World RegionInfo)
378 {
379 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Avatar.cs:SendRegionHandshake() - Creating empty RegionHandshake packet");
380 System.Text.Encoding _enc = System.Text.Encoding.ASCII;
381 RegionHandshakePacket handshake = new RegionHandshakePacket();
382
383 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Avatar.cs:SendRegionhandshake() - Filling in RegionHandshake details");
384 handshake.RegionInfo.BillableFactor = 0;
385 handshake.RegionInfo.IsEstateManager = false;
386 handshake.RegionInfo.TerrainHeightRange00 = 60;
387 handshake.RegionInfo.TerrainHeightRange01 = 60;
388 handshake.RegionInfo.TerrainHeightRange10 = 60;
389 handshake.RegionInfo.TerrainHeightRange11 = 60;
390 handshake.RegionInfo.TerrainStartHeight00 = 10;
391 handshake.RegionInfo.TerrainStartHeight01 = 10;
392 handshake.RegionInfo.TerrainStartHeight10 = 10;
393 handshake.RegionInfo.TerrainStartHeight11 = 10;
394 handshake.RegionInfo.SimAccess = 13;
395 handshake.RegionInfo.WaterHeight = 20;
396 handshake.RegionInfo.RegionFlags = 72458694;
397 handshake.RegionInfo.SimName = _enc.GetBytes(OpenSimRoot.Instance.Cfg.RegionName + "\0");
398 handshake.RegionInfo.SimOwner = new LLUUID("00000000-0000-0000-0000-000000000000");
399 handshake.RegionInfo.TerrainBase0 = new LLUUID("b8d3965a-ad78-bf43-699b-bff8eca6c975");
400 handshake.RegionInfo.TerrainBase1 = new LLUUID("abb783e6-3e93-26c0-248a-247666855da3");
401 handshake.RegionInfo.TerrainBase2 = new LLUUID("179cdabd-398a-9b6b-1391-4dc333ba321f");
402 handshake.RegionInfo.TerrainBase3 = new LLUUID("beb169c7-11ea-fff2-efe5-0f24dc881df2");
403 handshake.RegionInfo.TerrainDetail0 = new LLUUID("00000000-0000-0000-0000-000000000000");
404 handshake.RegionInfo.TerrainDetail1 = new LLUUID("00000000-0000-0000-0000-000000000000");
405 handshake.RegionInfo.TerrainDetail2 = new LLUUID("00000000-0000-0000-0000-000000000000");
406 handshake.RegionInfo.TerrainDetail3 = new LLUUID("00000000-0000-0000-0000-000000000000");
407 handshake.RegionInfo.CacheID = new LLUUID("545ec0a5-5751-1026-8a0b-216e38a7ab37");
408
409 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Avatar.cs:SendRegionHandshake() - Sending RegionHandshake packet");
410 this.ControllingClient.OutPacket(handshake);
411 }
412
413 public ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateTerseBlock()
414 {
415 byte[] bytes = new byte[60];
416 int i = 0;
417 ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
418
419 dat.TextureEntry = AvatarTemplate.TextureEntry;
420 libsecondlife.LLVector3 pos2 = new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z);
421
422 uint ID = this.localid;
423
424 bytes[i++] = (byte)(ID % 256);
425 bytes[i++] = (byte)((ID >> 8) % 256);
426 bytes[i++] = (byte)((ID >> 16) % 256);
427 bytes[i++] = (byte)((ID >> 24) % 256);
428 bytes[i++] = 0;
429 bytes[i++] = 1;
430 i += 14;
431 bytes[i++] = 128;
432 bytes[i++] = 63;
433
434 byte[] pb = pos2.GetBytes();
435 Array.Copy(pb, 0, bytes, i, pb.Length);
436 i += 12;
437 ushort InternVelocityX;
438 ushort InternVelocityY;
439 ushort InternVelocityZ;
440
441 Axiom.MathLib.Vector3 internDirec = new Axiom.MathLib.Vector3(this._physActor.Velocity.X, this._physActor.Velocity.Y, this._physActor.Velocity.Z);
442 internDirec = internDirec / 128.0f;
443 internDirec.x += 1;
444 internDirec.y += 1;
445 internDirec.z += 1;
446
447 InternVelocityX = (ushort)(32768 * internDirec.x);
448 InternVelocityY = (ushort)(32768 * internDirec.y);
449 InternVelocityZ = (ushort)(32768 * internDirec.z);
450
451 ushort ac = 32767;
452 bytes[i++] = (byte)(InternVelocityX % 256);
453 bytes[i++] = (byte)((InternVelocityX >> 8) % 256);
454 bytes[i++] = (byte)(InternVelocityY % 256);
455 bytes[i++] = (byte)((InternVelocityY >> 8) % 256);
456 bytes[i++] = (byte)(InternVelocityZ % 256);
457 bytes[i++] = (byte)((InternVelocityZ >> 8) % 256);
458
459 //accel
460 bytes[i++] = (byte)(ac % 256);
461 bytes[i++] = (byte)((ac >> 8) % 256);
462 bytes[i++] = (byte)(ac % 256);
463 bytes[i++] = (byte)((ac >> 8) % 256);
464 bytes[i++] = (byte)(ac % 256);
465 bytes[i++] = (byte)((ac >> 8) % 256);
466
467 //rot
468 bytes[i++] = (byte)(ac % 256);
469 bytes[i++] = (byte)((ac >> 8) % 256);
470 bytes[i++] = (byte)(ac % 256);
471 bytes[i++] = (byte)((ac >> 8) % 256);
472 bytes[i++] = (byte)(ac % 256);
473 bytes[i++] = (byte)((ac >> 8) % 256);
474 bytes[i++] = (byte)(ac % 256);
475 bytes[i++] = (byte)((ac >> 8) % 256);
476
477 //rotation vel
478 bytes[i++] = (byte)(ac % 256);
479 bytes[i++] = (byte)((ac >> 8) % 256);
480 bytes[i++] = (byte)(ac % 256);
481 bytes[i++] = (byte)((ac >> 8) % 256);
482 bytes[i++] = (byte)(ac % 256);
483 bytes[i++] = (byte)((ac >> 8) % 256);
484
485 dat.Data = bytes;
486 return (dat);
487 }
488 }
489
490 public class NewForce
491 {
492 public float X;
493 public float Y;
494 public float Z;
495
496 public NewForce()
497 {
498
499 }
500 }
501}
diff --git a/OpenSim.RegionServer/world/Entity.cs b/OpenSim.RegionServer/world/Entity.cs
new file mode 100644
index 0000000..780f3a0
--- /dev/null
+++ b/OpenSim.RegionServer/world/Entity.cs
@@ -0,0 +1,67 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using Axiom.MathLib;
5using OpenSim.types;
6using libsecondlife;
7
8namespace OpenSim.world
9{
10 public class Entity
11 {
12 public libsecondlife.LLUUID uuid;
13 public uint localid;
14 public LLVector3 position;
15 public LLVector3 velocity;
16 public Quaternion rotation;
17 protected string name;
18 protected List<Entity> children;
19
20 public Entity()
21 {
22 uuid = new libsecondlife.LLUUID();
23 localid = 0;
24 position = new LLVector3();
25 velocity = new LLVector3();
26 rotation = new Quaternion();
27 name = "(basic entity)";
28 children = new List<Entity>();
29 }
30 public virtual void addForces()
31 {
32 foreach (Entity child in children)
33 {
34 child.addForces();
35 }
36 }
37 public virtual void update() {
38 // Do any per-frame updates needed that are applicable to every type of entity
39 foreach (Entity child in children)
40 {
41 child.update();
42 }
43 }
44
45 public virtual string getName()
46 {
47 return name;
48 }
49
50 public virtual Mesh getMesh()
51 {
52 Mesh mesh = new Mesh();
53
54 foreach (Entity child in children)
55 {
56 mesh += child.getMesh();
57 }
58
59 return mesh;
60 }
61
62 public virtual void BackUp()
63 {
64
65 }
66 }
67}
diff --git a/OpenSim.RegionServer/world/Primitive.cs b/OpenSim.RegionServer/world/Primitive.cs
new file mode 100644
index 0000000..b190d81
--- /dev/null
+++ b/OpenSim.RegionServer/world/Primitive.cs
@@ -0,0 +1,485 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using OpenSim.types;
5using libsecondlife;
6using libsecondlife.Packets;
7using OpenSim.Framework.Interfaces;
8using OpenSim.Physics.Manager;
9using OpenSim.Framework.Assets;
10
11namespace OpenSim.world
12{
13 public class Primitive : Entity
14 {
15 protected float mesh_cutbegin;
16 protected float mesh_cutend;
17 protected PrimData primData;
18 protected bool newPrimFlag = false;
19 protected bool updateFlag = false;
20 protected bool dirtyFlag = false;
21 private ObjectUpdatePacket OurPacket;
22 private PhysicsActor _physActor;
23 private bool physicsEnabled = false;
24 private bool physicstest = false; //just added for testing
25
26 public bool PhysicsEnabled
27 {
28 get
29 {
30 return physicsEnabled;
31 }
32 set
33 {
34 physicsEnabled = value;
35 }
36 }
37 public bool UpdateFlag
38 {
39 get
40 {
41 return updateFlag;
42 }
43 set
44 {
45 updateFlag = value;
46 }
47 }
48 public LLVector3 Scale
49 {
50 set
51 {
52 this.primData.Scale = value;
53 this.dirtyFlag = true;
54 }
55 get
56 {
57 return this.primData.Scale;
58 }
59 }
60 public PhysicsActor PhysActor
61 {
62 set
63 {
64 this._physActor = value;
65 }
66 }
67
68 public Primitive()
69 {
70 mesh_cutbegin = 0.0f;
71 mesh_cutend = 1.0f;
72 }
73
74 public override Mesh getMesh()
75 {
76 Mesh mesh = new Mesh();
77 Triangle tri = new Triangle(
78 new Axiom.MathLib.Vector3(0.0f, 1.0f, 1.0f),
79 new Axiom.MathLib.Vector3(1.0f, 0.0f, 1.0f),
80 new Axiom.MathLib.Vector3(1.0f, 1.0f, 0.0f));
81
82 mesh.AddTri(tri);
83 mesh += base.getMesh();
84
85 return mesh;
86 }
87
88 public void UpdatePosition(LLVector3 pos)
89 {
90 this.position = pos;
91 if (this._physActor != null) // && this.physicsEnabled)
92 {
93 this._physActor.Position = new PhysicsVector(pos.X, pos.Y, pos.Z);
94 }
95 this.updateFlag = true;
96 }
97
98 public override void update()
99 {
100 if (this.newPrimFlag)
101 {
102 foreach (SimClient client in OpenSimRoot.Instance.ClientThreads.Values)
103 {
104 client.OutPacket(OurPacket);
105 }
106 this.newPrimFlag = false;
107 }
108 else if (this.updateFlag)
109 {
110 ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
111 terse.RegionData.RegionHandle = OpenSimRoot.Instance.Cfg.RegionHandle; // FIXME
112 terse.RegionData.TimeDilation = 64096;
113 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
114 terse.ObjectData[0] = this.CreateImprovedBlock();
115 foreach (SimClient client in OpenSimRoot.Instance.ClientThreads.Values)
116 {
117 client.OutPacket(terse);
118 }
119 this.updateFlag = false;
120 }
121 else if (this.dirtyFlag)
122 {
123 foreach (SimClient client in OpenSimRoot.Instance.ClientThreads.Values)
124 {
125 UpdateClient(client);
126 }
127 this.dirtyFlag = false;
128 }
129 else
130 {
131 if (this._physActor != null && this.physicsEnabled)
132 {
133 ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
134 terse.RegionData.RegionHandle = OpenSimRoot.Instance.Cfg.RegionHandle; // FIXME
135 terse.RegionData.TimeDilation = 64096;
136 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
137 terse.ObjectData[0] = this.CreateImprovedBlock();
138 foreach (SimClient client in OpenSimRoot.Instance.ClientThreads.Values)
139 {
140 client.OutPacket(terse);
141 }
142 }
143 }
144
145 if (this.physicstest)
146 {
147 LLVector3 pos = this.position;
148 pos.Z += 0.0001f;
149 this.UpdatePosition(pos);
150 this.physicstest = false;
151 }
152 }
153
154 public void UpdateClient(SimClient RemoteClient)
155 {
156
157 LLVector3 lPos;
158 if (this._physActor != null && this.physicsEnabled)
159 {
160 PhysicsVector pPos = this._physActor.Position;
161 lPos = new LLVector3(pPos.X, pPos.Y, pPos.Z);
162 }
163 else
164 {
165 lPos = this.position;
166 }
167 byte[] pb = lPos.GetBytes();
168 Array.Copy(pb, 0, OurPacket.ObjectData[0].ObjectData, 0, pb.Length);
169
170 // OurPacket should be update with the follwing in updateShape() rather than having to do it here
171 OurPacket.ObjectData[0].OwnerID = this.primData.OwnerID;
172 OurPacket.ObjectData[0].PCode = this.primData.PCode;
173 OurPacket.ObjectData[0].PathBegin = this.primData.PathBegin;
174 OurPacket.ObjectData[0].PathEnd = this.primData.PathEnd;
175 OurPacket.ObjectData[0].PathScaleX = this.primData.PathScaleX;
176 OurPacket.ObjectData[0].PathScaleY = this.primData.PathScaleY;
177 OurPacket.ObjectData[0].PathShearX = this.primData.PathShearX;
178 OurPacket.ObjectData[0].PathShearY = this.primData.PathShearY;
179 OurPacket.ObjectData[0].PathSkew = this.primData.PathSkew;
180 OurPacket.ObjectData[0].ProfileBegin = this.primData.ProfileBegin;
181 OurPacket.ObjectData[0].ProfileEnd = this.primData.ProfileEnd;
182 OurPacket.ObjectData[0].Scale = this.primData.Scale;
183 OurPacket.ObjectData[0].PathCurve = this.primData.PathCurve;
184 OurPacket.ObjectData[0].ProfileCurve = this.primData.ProfileCurve;
185 OurPacket.ObjectData[0].ParentID = 0;
186 OurPacket.ObjectData[0].ProfileHollow = this.primData.ProfileHollow;
187 //finish off copying rest of shape data
188 OurPacket.ObjectData[0].PathRadiusOffset = this.primData.PathRadiusOffset;
189 OurPacket.ObjectData[0].PathRevolutions = this.primData.PathRevolutions;
190 OurPacket.ObjectData[0].PathTaperX = this.primData.PathTaperX;
191 OurPacket.ObjectData[0].PathTaperY = this.primData.PathTaperY;
192 OurPacket.ObjectData[0].PathTwist = this.primData.PathTwist;
193 OurPacket.ObjectData[0].PathTwistBegin = this.primData.PathTwistBegin;
194
195 RemoteClient.OutPacket(OurPacket);
196 }
197
198 public void UpdateShape(ObjectShapePacket.ObjectDataBlock addPacket)
199 {
200 this.primData.PathBegin = addPacket.PathBegin;
201 this.primData.PathEnd = addPacket.PathEnd;
202 this.primData.PathScaleX = addPacket.PathScaleX;
203 this.primData.PathScaleY = addPacket.PathScaleY;
204 this.primData.PathShearX = addPacket.PathShearX;
205 this.primData.PathShearY = addPacket.PathShearY;
206 this.primData.PathSkew = addPacket.PathSkew;
207 this.primData.ProfileBegin = addPacket.ProfileBegin;
208 this.primData.ProfileEnd = addPacket.ProfileEnd;
209 this.primData.PathCurve = addPacket.PathCurve;
210 this.primData.ProfileCurve = addPacket.ProfileCurve;
211 this.primData.ProfileHollow = addPacket.ProfileHollow;
212 this.primData.PathRadiusOffset = addPacket.PathRadiusOffset;
213 this.primData.PathRevolutions = addPacket.PathRevolutions;
214 this.primData.PathTaperX = addPacket.PathTaperX;
215 this.primData.PathTaperY = addPacket.PathTaperY;
216 this.primData.PathTwist = addPacket.PathTwist;
217 this.primData.PathTwistBegin = addPacket.PathTwistBegin;
218 this.dirtyFlag = true;
219 }
220
221 public void UpdateTexture(byte[] tex)
222 {
223 this.primData.Texture = this.OurPacket.ObjectData[0].TextureEntry = tex;
224 this.dirtyFlag = true;
225 }
226
227 public void UpdateObjectFlags(ObjectFlagUpdatePacket pack)
228 {
229 if (this._physActor != null)
230 {
231 if (this._physActor.Kinematic == pack.AgentData.UsePhysics)
232 {
233 this._physActor.Kinematic = !pack.AgentData.UsePhysics; //if Usephysics = true, then Kinematic should = false
234 }
235 this.physicsEnabled = pack.AgentData.UsePhysics;
236 if (this._physActor.Kinematic == false)
237 {
238 LLVector3 pos = this.position;
239 this.UpdatePosition(pos);
240 pos.Z += 0.000001f;
241 this.UpdatePosition(pos);
242 this.physicstest = true;
243 }
244 else
245 {
246 PhysicsVector vec = this._physActor.Position;
247 LLVector3 pos = new LLVector3(vec.X, vec.Y, vec.Z);
248 this.position = pos;
249 this.updateFlag = true;
250 }
251 }
252 }
253
254 public void CreateFromPacket(ObjectAddPacket addPacket, LLUUID agentID, uint localID)
255 {
256 ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
257 objupdate.RegionData.RegionHandle = OpenSimRoot.Instance.Cfg.RegionHandle;
258 objupdate.RegionData.TimeDilation = 64096;
259
260 objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
261 PrimData PData = new PrimData();
262 this.primData = PData;
263 objupdate.ObjectData[0] = new ObjectUpdatePacket.ObjectDataBlock();
264 objupdate.ObjectData[0].PSBlock = new byte[0];
265 objupdate.ObjectData[0].ExtraParams = new byte[1];
266 objupdate.ObjectData[0].MediaURL = new byte[0];
267 objupdate.ObjectData[0].NameValue = new byte[0];
268 objupdate.ObjectData[0].Text = new byte[0];
269 objupdate.ObjectData[0].TextColor = new byte[4];
270 objupdate.ObjectData[0].JointAxisOrAnchor = new LLVector3(0, 0, 0);
271 objupdate.ObjectData[0].JointPivot = new LLVector3(0, 0, 0);
272 objupdate.ObjectData[0].Material = 3;
273 objupdate.ObjectData[0].UpdateFlags = 32 + 65536 + 131072 + 256 + 4 + 8 + 2048 + 524288 + 268435456;
274 objupdate.ObjectData[0].TextureAnim = new byte[0];
275 objupdate.ObjectData[0].Sound = LLUUID.Zero;
276 LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
277 objupdate.ObjectData[0].TextureEntry = ntex.ToBytes();
278 objupdate.ObjectData[0].State = 0;
279 objupdate.ObjectData[0].Data = new byte[0];
280 PData.OwnerID = objupdate.ObjectData[0].OwnerID = agentID;
281 PData.PCode = objupdate.ObjectData[0].PCode = addPacket.ObjectData.PCode;
282 PData.PathBegin = objupdate.ObjectData[0].PathBegin = addPacket.ObjectData.PathBegin;
283 PData.PathEnd = objupdate.ObjectData[0].PathEnd = addPacket.ObjectData.PathEnd;
284 PData.PathScaleX = objupdate.ObjectData[0].PathScaleX = addPacket.ObjectData.PathScaleX;
285 PData.PathScaleY = objupdate.ObjectData[0].PathScaleY = addPacket.ObjectData.PathScaleY;
286 PData.PathShearX = objupdate.ObjectData[0].PathShearX = addPacket.ObjectData.PathShearX;
287 PData.PathShearY = objupdate.ObjectData[0].PathShearY = addPacket.ObjectData.PathShearY;
288 PData.PathSkew = objupdate.ObjectData[0].PathSkew = addPacket.ObjectData.PathSkew;
289 PData.ProfileBegin = objupdate.ObjectData[0].ProfileBegin = addPacket.ObjectData.ProfileBegin;
290 PData.ProfileEnd = objupdate.ObjectData[0].ProfileEnd = addPacket.ObjectData.ProfileEnd;
291 PData.Scale = objupdate.ObjectData[0].Scale = addPacket.ObjectData.Scale;
292 PData.PathCurve = objupdate.ObjectData[0].PathCurve = addPacket.ObjectData.PathCurve;
293 PData.ProfileCurve = objupdate.ObjectData[0].ProfileCurve = addPacket.ObjectData.ProfileCurve;
294 PData.ParentID = objupdate.ObjectData[0].ParentID = 0;
295 PData.ProfileHollow = objupdate.ObjectData[0].ProfileHollow = addPacket.ObjectData.ProfileHollow;
296
297 PData.PathRadiusOffset = objupdate.ObjectData[0].PathRadiusOffset = addPacket.ObjectData.PathRadiusOffset;
298 PData.PathRevolutions = objupdate.ObjectData[0].PathRevolutions = addPacket.ObjectData.PathRevolutions;
299 PData.PathTaperX = objupdate.ObjectData[0].PathTaperX = addPacket.ObjectData.PathTaperX;
300 PData.PathTaperY = objupdate.ObjectData[0].PathTaperY = addPacket.ObjectData.PathTaperY;
301 PData.PathTwist = objupdate.ObjectData[0].PathTwist = addPacket.ObjectData.PathTwist;
302 PData.PathTwistBegin = objupdate.ObjectData[0].PathTwistBegin = addPacket.ObjectData.PathTwistBegin;
303
304 objupdate.ObjectData[0].ID = (uint)(localID);
305 objupdate.ObjectData[0].FullID = new LLUUID("edba7151-5857-acc5-b30b-f01efef" + (localID - 702000).ToString("00000"));
306 objupdate.ObjectData[0].ObjectData = new byte[60];
307 objupdate.ObjectData[0].ObjectData[46] = 128;
308 objupdate.ObjectData[0].ObjectData[47] = 63;
309 LLVector3 pos1 = addPacket.ObjectData.RayEnd;
310 //update position
311 byte[] pb = pos1.GetBytes();
312 Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 0, pb.Length);
313
314 this.newPrimFlag = true;
315 this.uuid = objupdate.ObjectData[0].FullID;
316 this.localid = objupdate.ObjectData[0].ID;
317 this.position = pos1;
318 this.OurPacket = objupdate;
319 }
320
321 public void CreateFromStorage(PrimData store)
322 {
323 //need to clean this up as it shares a lot of code with CreateFromPacket()
324 ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
325 objupdate.RegionData.RegionHandle = OpenSimRoot.Instance.Cfg.RegionHandle;
326 objupdate.RegionData.TimeDilation = 64096;
327 objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
328
329 this.primData = store;
330 objupdate.ObjectData[0] = new ObjectUpdatePacket.ObjectDataBlock();
331 objupdate.ObjectData[0].PSBlock = new byte[0];
332 objupdate.ObjectData[0].ExtraParams = new byte[1];
333 objupdate.ObjectData[0].MediaURL = new byte[0];
334 objupdate.ObjectData[0].NameValue = new byte[0];
335 objupdate.ObjectData[0].Text = new byte[0];
336 objupdate.ObjectData[0].TextColor = new byte[4];
337 objupdate.ObjectData[0].JointAxisOrAnchor = new LLVector3(0, 0, 0);
338 objupdate.ObjectData[0].JointPivot = new LLVector3(0, 0, 0);
339 objupdate.ObjectData[0].Material = 3;
340 objupdate.ObjectData[0].UpdateFlags = 32 + 65536 + 131072 + 256 + 4 + 8 + 2048 + 524288 + 268435456;
341 objupdate.ObjectData[0].TextureAnim = new byte[0];
342 objupdate.ObjectData[0].Sound = LLUUID.Zero;
343
344 if (store.Texture == null)
345 {
346 LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
347 objupdate.ObjectData[0].TextureEntry = ntex.ToBytes();
348 }
349 else
350 {
351 objupdate.ObjectData[0].TextureEntry = store.Texture;
352 }
353
354 objupdate.ObjectData[0].State = 0;
355 objupdate.ObjectData[0].Data = new byte[0];
356 objupdate.ObjectData[0].OwnerID = this.primData.OwnerID;
357 objupdate.ObjectData[0].PCode = this.primData.PCode;
358 objupdate.ObjectData[0].PathBegin = this.primData.PathBegin;
359 objupdate.ObjectData[0].PathEnd = this.primData.PathEnd;
360 objupdate.ObjectData[0].PathScaleX = this.primData.PathScaleX;
361 objupdate.ObjectData[0].PathScaleY = this.primData.PathScaleY;
362 objupdate.ObjectData[0].PathShearX = this.primData.PathShearX;
363 objupdate.ObjectData[0].PathShearY = this.primData.PathShearY;
364 objupdate.ObjectData[0].PathSkew = this.primData.PathSkew;
365 objupdate.ObjectData[0].ProfileBegin = this.primData.ProfileBegin;
366 objupdate.ObjectData[0].ProfileEnd = this.primData.ProfileEnd;
367 objupdate.ObjectData[0].Scale = this.primData.Scale;
368 objupdate.ObjectData[0].PathCurve = this.primData.PathCurve;
369 objupdate.ObjectData[0].ProfileCurve = this.primData.ProfileCurve;
370 objupdate.ObjectData[0].ParentID = 0;
371 objupdate.ObjectData[0].ProfileHollow = this.primData.ProfileHollow;
372 //finish off copying rest of shape data
373 objupdate.ObjectData[0].PathRadiusOffset = this.primData.PathRadiusOffset;
374 objupdate.ObjectData[0].PathRevolutions = this.primData.PathRevolutions;
375 objupdate.ObjectData[0].PathTaperX = this.primData.PathTaperX;
376 objupdate.ObjectData[0].PathTaperY = this.primData.PathTaperY;
377 objupdate.ObjectData[0].PathTwist = this.primData.PathTwist;
378 objupdate.ObjectData[0].PathTwistBegin = this.primData.PathTwistBegin;
379
380 objupdate.ObjectData[0].ID = (uint)store.LocalID;
381 objupdate.ObjectData[0].FullID = store.FullID;
382
383 objupdate.ObjectData[0].ObjectData = new byte[60];
384 objupdate.ObjectData[0].ObjectData[46] = 128;
385 objupdate.ObjectData[0].ObjectData[47] = 63;
386 LLVector3 pos1 = store.Position;
387 //update position
388 byte[] pb = pos1.GetBytes();
389 Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 0, pb.Length);
390
391 this.uuid = objupdate.ObjectData[0].FullID;
392 this.localid = objupdate.ObjectData[0].ID;
393 this.position = pos1;
394 this.OurPacket = objupdate;
395
396 }
397 public ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateImprovedBlock()
398 {
399 uint ID = this.localid;
400 byte[] bytes = new byte[60];
401
402 int i = 0;
403 ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
404 dat.TextureEntry = this.OurPacket.ObjectData[0].TextureEntry;
405
406 bytes[i++] = (byte)(ID % 256);
407 bytes[i++] = (byte)((ID >> 8) % 256);
408 bytes[i++] = (byte)((ID >> 16) % 256);
409 bytes[i++] = (byte)((ID >> 24) % 256);
410 bytes[i++] = 0;
411 bytes[i++] = 0;
412
413 LLVector3 lPos;
414 Axiom.MathLib.Quaternion lRot;
415 if (this._physActor != null && this.physicsEnabled)
416 {
417 PhysicsVector pPos = this._physActor.Position;
418 lPos = new LLVector3(pPos.X, pPos.Y, pPos.Z);
419 lRot = this._physActor.Orientation;
420 }
421 else
422 {
423 lPos = this.position;
424 lRot = this.rotation;
425 }
426 byte[] pb = lPos.GetBytes();
427 Array.Copy(pb, 0, bytes, i, pb.Length);
428 i += 12;
429 ushort ac = 32767;
430
431 //vel
432 bytes[i++] = (byte)(ac % 256);
433 bytes[i++] = (byte)((ac >> 8) % 256);
434 bytes[i++] = (byte)(ac % 256);
435 bytes[i++] = (byte)((ac >> 8) % 256);
436 bytes[i++] = (byte)(ac % 256);
437 bytes[i++] = (byte)((ac >> 8) % 256);
438
439 //accel
440 bytes[i++] = (byte)(ac % 256);
441 bytes[i++] = (byte)((ac >> 8) % 256);
442 bytes[i++] = (byte)(ac % 256);
443 bytes[i++] = (byte)((ac >> 8) % 256);
444 bytes[i++] = (byte)(ac % 256);
445 bytes[i++] = (byte)((ac >> 8) % 256);
446
447 ushort rw, rx, ry, rz;
448 rw = (ushort)(32768 * (lRot.w + 1));
449 rx = (ushort)(32768 * (lRot.x + 1));
450 ry = (ushort)(32768 * (lRot.y + 1));
451 rz = (ushort)(32768 * (lRot.z + 1));
452
453 //rot
454 bytes[i++] = (byte)(rx % 256);
455 bytes[i++] = (byte)((rx >> 8) % 256);
456 bytes[i++] = (byte)(ry % 256);
457 bytes[i++] = (byte)((ry >> 8) % 256);
458 bytes[i++] = (byte)(rz % 256);
459 bytes[i++] = (byte)((rz >> 8) % 256);
460 bytes[i++] = (byte)(rw % 256);
461 bytes[i++] = (byte)((rw >> 8) % 256);
462
463 //rotation vel
464 bytes[i++] = (byte)(ac % 256);
465 bytes[i++] = (byte)((ac >> 8) % 256);
466 bytes[i++] = (byte)(ac % 256);
467 bytes[i++] = (byte)((ac >> 8) % 256);
468 bytes[i++] = (byte)(ac % 256);
469 bytes[i++] = (byte)((ac >> 8) % 256);
470
471 dat.Data = bytes;
472 return dat;
473 }
474
475 public override void BackUp()
476 {
477 this.primData.FullID = this.uuid;
478 this.primData.LocalID = this.localid;
479 this.primData.Position = this.position;
480 this.primData.Rotation = new LLQuaternion(this.rotation.x, this.rotation.y, this.rotation.z, this.rotation.w);
481 OpenSimRoot.Instance.LocalWorld.localStorage.StorePrim(this.primData);
482 }
483 }
484
485}
diff --git a/OpenSim.RegionServer/world/ScriptEngine.cs b/OpenSim.RegionServer/world/ScriptEngine.cs
new file mode 100644
index 0000000..f20a08e
--- /dev/null
+++ b/OpenSim.RegionServer/world/ScriptEngine.cs
@@ -0,0 +1,18 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.world
6{
7 public class ScriptEngine
8 {
9 public ScriptEngine(World env)
10 {
11 }
12
13 public void LoadScript()
14 {
15
16 }
17 }
18}
diff --git a/OpenSim.RegionServer/world/SurfacePatch.cs b/OpenSim.RegionServer/world/SurfacePatch.cs
new file mode 100644
index 0000000..71e4116
--- /dev/null
+++ b/OpenSim.RegionServer/world/SurfacePatch.cs
@@ -0,0 +1,22 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.world
6{
7 public class SurfacePatch
8 {
9 public float[] HeightMap;
10
11 public SurfacePatch() {
12 HeightMap = new float[16*16];
13
14 int xinc;
15 int yinc;
16 for(xinc=0; xinc<16; xinc++) for(yinc=0; yinc<16; yinc++) {
17 HeightMap[xinc+(yinc*16)]=100.0f;
18 }
19
20 }
21 }
22}
diff --git a/OpenSim.RegionServer/world/World.cs b/OpenSim.RegionServer/world/World.cs
new file mode 100644
index 0000000..ba99233
--- /dev/null
+++ b/OpenSim.RegionServer/world/World.cs
@@ -0,0 +1,213 @@
1using System;
2using libsecondlife;
3using libsecondlife.Packets;
4using System.Collections.Generic;
5using System.Text;
6using System.Reflection;
7using System.IO;
8using OpenSim.Physics.Manager;
9using OpenSim.Framework.Interfaces;
10using OpenSim.Framework.Assets;
11using OpenSim.Framework.Terrain;
12
13namespace OpenSim.world
14{
15 public class World : ILocalStorageReceiver
16 {
17 public Dictionary<libsecondlife.LLUUID, Entity> Entities;
18 public float[] LandMap;
19 public ScriptEngine Scripts;
20 public uint _localNumber=0;
21 private PhysicsScene phyScene;
22 private float timeStep= 0.1f;
23 private libsecondlife.TerrainManager TerrainManager;
24 public ILocalStorage localStorage;
25 private Random Rand = new Random();
26 private uint _primCount = 702000;
27 private int storageCount;
28
29 public World()
30 {
31 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs - creating new entitities instance");
32 Entities = new Dictionary<libsecondlife.LLUUID, Entity>();
33
34 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs - creating LandMap");
35 TerrainManager = new TerrainManager(new SecondLife());
36 Avatar.SetupTemplate("avatar-template.dat");
37 // ServerConsole.MainConsole.Instance.WriteLine("World.cs - Creating script engine instance");
38 // Initialise this only after the world has loaded
39 // Scripts = new ScriptEngine(this);
40 }
41
42 public PhysicsScene PhysScene
43 {
44 set
45 {
46 this.phyScene = value;
47 }
48 get
49 {
50 return(this.phyScene);
51 }
52 }
53
54 public void Update()
55 {
56 if(this.phyScene.IsThreaded)
57 {
58 this.phyScene.GetResults();
59
60 }
61
62 foreach (libsecondlife.LLUUID UUID in Entities.Keys)
63 {
64 Entities[UUID].addForces();
65 }
66
67 this.phyScene.Simulate(timeStep);
68
69 foreach (libsecondlife.LLUUID UUID in Entities.Keys)
70 {
71 Entities[UUID].update();
72 }
73
74 //backup world data
75 this.storageCount++;
76 if(storageCount> 1200) //set to how often you want to backup
77 {
78 this.Backup();
79 storageCount =0;
80 }
81 }
82
83 public bool LoadStorageDLL(string dllName)
84 {
85 Assembly pluginAssembly = Assembly.LoadFrom(dllName);
86 ILocalStorage store = null;
87
88 foreach (Type pluginType in pluginAssembly.GetTypes())
89 {
90 if (pluginType.IsPublic)
91 {
92 if (!pluginType.IsAbstract)
93 {
94 Type typeInterface = pluginType.GetInterface("ILocalStorage", true);
95
96 if (typeInterface != null)
97 {
98 ILocalStorage plug = (ILocalStorage)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
99 store = plug;
100 break;
101 }
102
103 typeInterface = null;
104 }
105 }
106 }
107 pluginAssembly = null;
108 this.localStorage = store;
109 return(store == null);
110 }
111
112 public void RegenerateTerrain()
113 {
114 HeightmapGenHills hills = new HeightmapGenHills();
115 this.LandMap = hills.GenerateHeightmap(200, 4.0f, 80.0f, false);
116 this.phyScene.SetTerrain(this.LandMap);
117 OpenSimRoot.Instance.Cfg.SaveMap(this.LandMap);
118
119 foreach(SimClient client in OpenSimRoot.Instance.ClientThreads.Values) {
120 this.SendLayerData(client);
121 }
122 }
123 public void LoadPrimsFromStorage()
124 {
125 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: LoadPrimsFromStorage() - Loading primitives");
126 this.localStorage.LoadPrimitives(this);
127 }
128
129 public void PrimFromStorage(PrimData prim)
130 {
131 if(prim.LocalID >= this._primCount)
132 {
133 _primCount = prim.LocalID + 1;
134 }
135 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: PrimFromStorage() - Reloading prim (localId "+ prim.LocalID+ " ) from storage");
136 Primitive nPrim = new Primitive();
137 nPrim.CreateFromStorage(prim);
138 this.Entities.Add(nPrim.uuid, nPrim);
139 }
140
141 public void Close()
142 {
143 this.localStorage.ShutDown();
144 }
145
146 public void SendLayerData(SimClient RemoteClient) {
147 int[] patches = new int[4];
148
149 for (int y = 0; y < 16; y++)
150 {
151 for (int x = 0; x < 16; x = x + 4)
152 {
153 patches[0] = x + 0 + y * 16;
154 patches[1] = x + 1 + y * 16;
155 patches[2] = x + 2 + y * 16;
156 patches[3] = x + 3 + y * 16;
157
158 Packet layerpack = TerrainManager.CreateLandPacket(LandMap, patches);
159 RemoteClient.OutPacket(layerpack);
160 }
161 }
162 }
163
164 public void GetInitialPrims(SimClient RemoteClient)
165 {
166 foreach (libsecondlife.LLUUID UUID in Entities.Keys)
167 {
168 if(Entities[UUID].ToString()== "OpenSim.world.Primitive")
169 {
170 ((OpenSim.world.Primitive)Entities[UUID]).UpdateClient(RemoteClient);
171 }
172 }
173 }
174
175 public void AddViewerAgent(SimClient AgentClient) {
176 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs:AddViewerAgent() - Creating new avatar for remote viewer agent");
177 Avatar NewAvatar = new Avatar(AgentClient);
178 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs:AddViewerAgent() - Adding new avatar to world");
179 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs:AddViewerAgent() - Starting RegionHandshake ");
180 NewAvatar.SendRegionHandshake(this);
181 PhysicsVector pVec = new PhysicsVector(NewAvatar.position.X, NewAvatar.position.Y, NewAvatar.position.Z);
182 NewAvatar.PhysActor = this.phyScene.AddAvatar(pVec);
183 this.Entities.Add(AgentClient.AgentID, NewAvatar);
184 }
185
186 public void AddNewPrim(ObjectAddPacket addPacket, SimClient AgentClient)
187 {
188 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: AddNewPrim() - Creating new prim");
189 Primitive prim = new Primitive();
190 prim.CreateFromPacket(addPacket, AgentClient.AgentID, this._primCount);
191 PhysicsVector pVec = new PhysicsVector(prim.position.X, prim.position.Y, prim.position.Z);
192 PhysicsVector pSize = new PhysicsVector( 0.255f, 0.255f, 0.255f);
193 if(OpenSim.world.Avatar.PhysicsEngineFlying)
194 {
195 prim.PhysActor = this.phyScene.AddPrim(pVec, pSize );
196 }
197 //prim.PhysicsEnabled = true;
198 this.Entities.Add(prim.uuid, prim);
199 this._primCount++;
200 }
201
202 public bool Backup() {
203
204 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: Backup() - Backing up Primitives");
205 foreach (libsecondlife.LLUUID UUID in Entities.Keys)
206 {
207 Entities[UUID].BackUp();
208 }
209 return true;
210 }
211
212 }
213}
diff --git a/OpenSim.RegionServer/world/scripting/IScript.cs b/OpenSim.RegionServer/world/scripting/IScript.cs
new file mode 100644
index 0000000..550594d
--- /dev/null
+++ b/OpenSim.RegionServer/world/scripting/IScript.cs
@@ -0,0 +1,16 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.world.scripting
6{
7 public interface IScriptHost {
8 bool Register(IScript iscript);
9 }
10 public interface IScript
11 {
12 string Name{get;set;}
13 IScriptHost Host{get;set;}
14 void Show();
15 }
16}