diff options
author | mingchen | 2007-06-27 19:43:46 +0000 |
---|---|---|
committer | mingchen | 2007-06-27 19:43:46 +0000 |
commit | 0232f01a58a3c0a88e95c22589efec21f502f081 (patch) | |
tree | ff210fa6750c23972086ebbf816ead0a0a2f412a /OpenSim/Region/Environment/Scenes | |
parent | *Moved VersionInfo.cs to its correct place in OpenSim.csproj (diff) | |
download | opensim-SC-0232f01a58a3c0a88e95c22589efec21f502f081.zip opensim-SC-0232f01a58a3c0a88e95c22589efec21f502f081.tar.gz opensim-SC-0232f01a58a3c0a88e95c22589efec21f502f081.tar.bz2 opensim-SC-0232f01a58a3c0a88e95c22589efec21f502f081.tar.xz |
*Moved all the classes into their own file from LLSDHelpers.cs
*Some folder renaming to follow project Name
*Updated prebuild.xml
Diffstat (limited to 'OpenSim/Region/Environment/Scenes')
18 files changed, 3515 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Scenes/Entity.cs b/OpenSim/Region/Environment/Scenes/Entity.cs new file mode 100644 index 0000000..bbba34d --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/Entity.cs | |||
@@ -0,0 +1,194 @@ | |||
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 System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using Axiom.MathLib; | ||
32 | using OpenSim.Physics.Manager; | ||
33 | using libsecondlife; | ||
34 | using OpenSim.Region.Environment.Scripting; | ||
35 | |||
36 | namespace OpenSim.Region.Environment.Scenes | ||
37 | { | ||
38 | public abstract class Entity : IScriptReadonlyEntity | ||
39 | { | ||
40 | public libsecondlife.LLUUID uuid; | ||
41 | public Quaternion rotation; | ||
42 | protected List<Entity> children; | ||
43 | |||
44 | protected PhysicsActor _physActor; | ||
45 | protected Scene m_world; | ||
46 | protected string m_name; | ||
47 | |||
48 | /// <summary> | ||
49 | /// | ||
50 | /// </summary> | ||
51 | public virtual string Name | ||
52 | { | ||
53 | get { return m_name; } | ||
54 | } | ||
55 | |||
56 | protected LLVector3 m_pos; | ||
57 | /// <summary> | ||
58 | /// | ||
59 | /// </summary> | ||
60 | public virtual LLVector3 Pos | ||
61 | { | ||
62 | get | ||
63 | { | ||
64 | if (this._physActor != null) | ||
65 | { | ||
66 | m_pos.X = _physActor.Position.X; | ||
67 | m_pos.Y = _physActor.Position.Y; | ||
68 | m_pos.Z = _physActor.Position.Z; | ||
69 | } | ||
70 | |||
71 | return m_pos; | ||
72 | } | ||
73 | set | ||
74 | { | ||
75 | if (this._physActor != null) | ||
76 | { | ||
77 | try | ||
78 | { | ||
79 | lock (this.m_world.SyncRoot) | ||
80 | { | ||
81 | |||
82 | this._physActor.Position = new PhysicsVector(value.X, value.Y, value.Z); | ||
83 | } | ||
84 | } | ||
85 | catch (Exception e) | ||
86 | { | ||
87 | Console.WriteLine(e.Message); | ||
88 | } | ||
89 | } | ||
90 | |||
91 | m_pos = value; | ||
92 | } | ||
93 | } | ||
94 | |||
95 | public LLVector3 velocity; | ||
96 | |||
97 | /// <summary> | ||
98 | /// | ||
99 | /// </summary> | ||
100 | public virtual LLVector3 Velocity | ||
101 | { | ||
102 | get | ||
103 | { | ||
104 | if (this._physActor != null) | ||
105 | { | ||
106 | velocity.X = _physActor.Velocity.X; | ||
107 | velocity.Y = _physActor.Velocity.Y; | ||
108 | velocity.Z = _physActor.Velocity.Z; | ||
109 | } | ||
110 | |||
111 | return velocity; | ||
112 | } | ||
113 | set | ||
114 | { | ||
115 | if (this._physActor != null) | ||
116 | { | ||
117 | try | ||
118 | { | ||
119 | lock (this.m_world.SyncRoot) | ||
120 | { | ||
121 | |||
122 | this._physActor.Velocity = new PhysicsVector(value.X, value.Y, value.Z); | ||
123 | } | ||
124 | } | ||
125 | catch (Exception e) | ||
126 | { | ||
127 | Console.WriteLine(e.Message); | ||
128 | } | ||
129 | } | ||
130 | |||
131 | velocity = value; | ||
132 | } | ||
133 | } | ||
134 | |||
135 | protected uint m_localId; | ||
136 | |||
137 | public uint LocalId | ||
138 | { | ||
139 | get { return m_localId; } | ||
140 | } | ||
141 | |||
142 | /// <summary> | ||
143 | /// Creates a new Entity (should not occur on it's own) | ||
144 | /// </summary> | ||
145 | public Entity() | ||
146 | { | ||
147 | uuid = new libsecondlife.LLUUID(); | ||
148 | |||
149 | m_pos = new LLVector3(); | ||
150 | velocity = new LLVector3(); | ||
151 | rotation = new Quaternion(); | ||
152 | m_name = "(basic entity)"; | ||
153 | children = new List<Entity>(); | ||
154 | } | ||
155 | |||
156 | /// <summary> | ||
157 | /// | ||
158 | /// </summary> | ||
159 | public virtual void updateMovement() | ||
160 | { | ||
161 | foreach (Entity child in children) | ||
162 | { | ||
163 | child.updateMovement(); | ||
164 | } | ||
165 | } | ||
166 | |||
167 | /// <summary> | ||
168 | /// Performs any updates that need to be done at each frame. This function is overridable from it's children. | ||
169 | /// </summary> | ||
170 | public virtual void update() { | ||
171 | // Do any per-frame updates needed that are applicable to every type of entity | ||
172 | foreach (Entity child in children) | ||
173 | { | ||
174 | child.update(); | ||
175 | } | ||
176 | } | ||
177 | |||
178 | /// <summary> | ||
179 | /// Called at a set interval to inform entities that they should back themsleves up to the DB | ||
180 | /// </summary> | ||
181 | public virtual void BackUp() | ||
182 | { | ||
183 | |||
184 | } | ||
185 | |||
186 | /// <summary> | ||
187 | /// Infoms the entity that the land (heightmap) has changed | ||
188 | /// </summary> | ||
189 | public virtual void LandRenegerated() | ||
190 | { | ||
191 | |||
192 | } | ||
193 | } | ||
194 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/IScenePresenceBody.cs b/OpenSim/Region/Environment/Scenes/IScenePresenceBody.cs new file mode 100644 index 0000000..36023d0 --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/IScenePresenceBody.cs | |||
@@ -0,0 +1,19 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using libsecondlife; | ||
5 | using libsecondlife.Packets; | ||
6 | using OpenSim.Physics.Manager; | ||
7 | using OpenSim.Framework.Interfaces; | ||
8 | using OpenSim.Framework.Types; | ||
9 | |||
10 | namespace OpenSim.Region.Environment.Scenes | ||
11 | { | ||
12 | public interface IScenePresenceBody | ||
13 | { | ||
14 | void processMovement(IClientAPI remoteClient, uint flags, LLQuaternion bodyRotation); | ||
15 | void SetAppearance(byte[] texture, AgentSetAppearancePacket.VisualParamBlock[] visualParam); | ||
16 | void SendOurAppearance(IClientAPI OurClient); | ||
17 | void SendAppearanceToOtherAgent(ScenePresence avatarInfo); | ||
18 | } | ||
19 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/Primitive.cs b/OpenSim/Region/Environment/Scenes/Primitive.cs new file mode 100644 index 0000000..0f649b2 --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/Primitive.cs | |||
@@ -0,0 +1,582 @@ | |||
1 | |||
2 | /* | ||
3 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
4 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are met: | ||
8 | * * Redistributions of source code must retain the above copyright | ||
9 | * notice, this list of conditions and the following disclaimer. | ||
10 | * * Redistributions in binary form must reproduce the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer in the | ||
12 | * documentation and/or other materials provided with the distribution. | ||
13 | * * Neither the name of the OpenSim Project nor the | ||
14 | * names of its contributors may be used to endorse or promote products | ||
15 | * derived from this software without specific prior written permission. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
18 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
20 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
21 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
23 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
24 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
26 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
27 | * | ||
28 | */ | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | using libsecondlife; | ||
33 | using libsecondlife.Packets; | ||
34 | using OpenSim.Framework.Interfaces; | ||
35 | using OpenSim.Physics.Manager; | ||
36 | using OpenSim.Framework.Types; | ||
37 | using OpenSim.Framework.Inventory; | ||
38 | |||
39 | namespace OpenSim.Region.Environment.Scenes | ||
40 | { | ||
41 | public class Primitive : Entity | ||
42 | { | ||
43 | internal PrimData primData; | ||
44 | private LLVector3 positionLastFrame = new LLVector3(0, 0, 0); | ||
45 | // private Dictionary<uint, IClientAPI> m_clientThreads; | ||
46 | private ulong m_regionHandle; | ||
47 | private const uint FULL_MASK_PERMISSIONS = 2147483647; | ||
48 | private bool physicsEnabled = false; | ||
49 | private byte updateFlag = 0; | ||
50 | private uint flags = 32 + 65536 + 131072 + 256 + 4 + 8 + 2048 + 524288 + 268435456 + 128; | ||
51 | |||
52 | private Dictionary<LLUUID, InventoryItem> inventoryItems; | ||
53 | |||
54 | #region Properties | ||
55 | |||
56 | public LLVector3 Scale | ||
57 | { | ||
58 | set | ||
59 | { | ||
60 | this.primData.Scale = value; | ||
61 | //this.dirtyFlag = true; | ||
62 | } | ||
63 | get | ||
64 | { | ||
65 | return this.primData.Scale; | ||
66 | } | ||
67 | } | ||
68 | |||
69 | public PhysicsActor PhysActor | ||
70 | { | ||
71 | set | ||
72 | { | ||
73 | this._physActor = value; | ||
74 | } | ||
75 | } | ||
76 | |||
77 | public override LLVector3 Pos | ||
78 | { | ||
79 | get | ||
80 | { | ||
81 | return base.Pos; | ||
82 | } | ||
83 | set | ||
84 | { | ||
85 | base.Pos = value; | ||
86 | } | ||
87 | } | ||
88 | #endregion | ||
89 | |||
90 | /// <summary> | ||
91 | /// | ||
92 | /// </summary> | ||
93 | /// <param name="clientThreads"></param> | ||
94 | /// <param name="regionHandle"></param> | ||
95 | /// <param name="world"></param> | ||
96 | public Primitive( ulong regionHandle, Scene world) | ||
97 | { | ||
98 | // m_clientThreads = clientThreads; | ||
99 | m_regionHandle = regionHandle; | ||
100 | m_world = world; | ||
101 | inventoryItems = new Dictionary<LLUUID, InventoryItem>(); | ||
102 | } | ||
103 | |||
104 | /// <summary> | ||
105 | /// | ||
106 | /// </summary> | ||
107 | /// <param name="regionHandle"></param> | ||
108 | /// <param name="world"></param> | ||
109 | /// <param name="addPacket"></param> | ||
110 | /// <param name="ownerID"></param> | ||
111 | /// <param name="localID"></param> | ||
112 | public Primitive(ulong regionHandle, Scene world, ObjectAddPacket addPacket, LLUUID ownerID, uint localID) | ||
113 | { | ||
114 | // m_clientThreads = clientThreads; | ||
115 | m_regionHandle = regionHandle; | ||
116 | m_world = world; | ||
117 | inventoryItems = new Dictionary<LLUUID, InventoryItem>(); | ||
118 | this.CreateFromPacket(addPacket, ownerID, localID); | ||
119 | } | ||
120 | |||
121 | /// <summary> | ||
122 | /// | ||
123 | /// </summary> | ||
124 | /// <param name="clientThreads"></param> | ||
125 | /// <param name="regionHandle"></param> | ||
126 | /// <param name="world"></param> | ||
127 | /// <param name="owner"></param> | ||
128 | /// <param name="fullID"></param> | ||
129 | /// <param name="localID"></param> | ||
130 | public Primitive( ulong regionHandle, Scene world, LLUUID owner, LLUUID fullID, uint localID) | ||
131 | { | ||
132 | // m_clientThreads = clientThreads; | ||
133 | m_regionHandle = regionHandle; | ||
134 | m_world = world; | ||
135 | inventoryItems = new Dictionary<LLUUID, InventoryItem>(); | ||
136 | this.primData = new PrimData(); | ||
137 | this.primData.CreationDate = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; | ||
138 | this.primData.OwnerID = owner; | ||
139 | this.primData.FullID = this.uuid = fullID; | ||
140 | this.primData.LocalID = m_localId = localID; | ||
141 | } | ||
142 | |||
143 | /// <summary> | ||
144 | /// Constructor to create a default cube | ||
145 | /// </summary> | ||
146 | /// <param name="clientThreads"></param> | ||
147 | /// <param name="regionHandle"></param> | ||
148 | /// <param name="world"></param> | ||
149 | /// <param name="owner"></param> | ||
150 | /// <param name="localID"></param> | ||
151 | /// <param name="position"></param> | ||
152 | public Primitive( ulong regionHandle, Scene world, LLUUID owner, uint localID, LLVector3 position) | ||
153 | { | ||
154 | //m_clientThreads = clientThreads; | ||
155 | m_regionHandle = regionHandle; | ||
156 | m_world = world; | ||
157 | inventoryItems = new Dictionary<LLUUID, InventoryItem>(); | ||
158 | this.primData = PrimData.DefaultCube(); | ||
159 | this.primData.OwnerID = owner; | ||
160 | this.primData.LocalID = m_localId = localID; | ||
161 | this.Pos = this.primData.Position = position; | ||
162 | |||
163 | this.updateFlag = 1; | ||
164 | } | ||
165 | |||
166 | /// <summary> | ||
167 | /// | ||
168 | /// </summary> | ||
169 | /// <returns></returns> | ||
170 | public byte[] GetByteArray() | ||
171 | { | ||
172 | byte[] result = null; | ||
173 | List<byte[]> dataArrays = new List<byte[]>(); | ||
174 | dataArrays.Add(primData.ToBytes()); | ||
175 | foreach (Entity child in children) | ||
176 | { | ||
177 | if (child is OpenSim.Region.Environment.Scenes.Primitive) | ||
178 | { | ||
179 | dataArrays.Add(((OpenSim.Region.Environment.Scenes.Primitive)child).GetByteArray()); | ||
180 | } | ||
181 | } | ||
182 | byte[] primstart = Helpers.StringToField("<Prim>"); | ||
183 | byte[] primend = Helpers.StringToField("</Prim>"); | ||
184 | int totalLength = primstart.Length + primend.Length; | ||
185 | for (int i = 0; i < dataArrays.Count; i++) | ||
186 | { | ||
187 | totalLength += dataArrays[i].Length; | ||
188 | } | ||
189 | |||
190 | result = new byte[totalLength]; | ||
191 | int arraypos = 0; | ||
192 | Array.Copy(primstart, 0, result, 0, primstart.Length); | ||
193 | arraypos += primstart.Length; | ||
194 | for (int i = 0; i < dataArrays.Count; i++) | ||
195 | { | ||
196 | Array.Copy(dataArrays[i], 0, result, arraypos, dataArrays[i].Length); | ||
197 | arraypos += dataArrays[i].Length; | ||
198 | } | ||
199 | Array.Copy(primend, 0, result, arraypos, primend.Length); | ||
200 | |||
201 | return result; | ||
202 | } | ||
203 | |||
204 | #region Overridden Methods | ||
205 | |||
206 | /// <summary> | ||
207 | /// | ||
208 | /// </summary> | ||
209 | public override void update() | ||
210 | { | ||
211 | if (this.updateFlag == 1) // is a new prim just been created/reloaded | ||
212 | { | ||
213 | this.SendFullUpdateToAllClients(); | ||
214 | this.updateFlag = 0; | ||
215 | } | ||
216 | if (this.updateFlag == 2) //some change has been made so update the clients | ||
217 | { | ||
218 | this.SendTerseUpdateToALLClients(); | ||
219 | this.updateFlag = 0; | ||
220 | } | ||
221 | } | ||
222 | |||
223 | /// <summary> | ||
224 | /// | ||
225 | /// </summary> | ||
226 | public override void BackUp() | ||
227 | { | ||
228 | |||
229 | } | ||
230 | |||
231 | #endregion | ||
232 | |||
233 | #region Packet handlers | ||
234 | |||
235 | /// <summary> | ||
236 | /// | ||
237 | /// </summary> | ||
238 | /// <param name="pos"></param> | ||
239 | public void UpdatePosition(LLVector3 pos) | ||
240 | { | ||
241 | this.Pos = new LLVector3(pos.X, pos.Y, pos.Z); | ||
242 | this.updateFlag = 2; | ||
243 | } | ||
244 | |||
245 | /// <summary> | ||
246 | /// | ||
247 | /// </summary> | ||
248 | /// <param name="addPacket"></param> | ||
249 | public void UpdateShape(ObjectShapePacket.ObjectDataBlock updatePacket) | ||
250 | { | ||
251 | this.primData.PathBegin = updatePacket.PathBegin; | ||
252 | this.primData.PathEnd = updatePacket.PathEnd; | ||
253 | this.primData.PathScaleX = updatePacket.PathScaleX; | ||
254 | this.primData.PathScaleY = updatePacket.PathScaleY; | ||
255 | this.primData.PathShearX = updatePacket.PathShearX; | ||
256 | this.primData.PathShearY = updatePacket.PathShearY; | ||
257 | this.primData.PathSkew = updatePacket.PathSkew; | ||
258 | this.primData.ProfileBegin = updatePacket.ProfileBegin; | ||
259 | this.primData.ProfileEnd = updatePacket.ProfileEnd; | ||
260 | this.primData.PathCurve = updatePacket.PathCurve; | ||
261 | this.primData.ProfileCurve = updatePacket.ProfileCurve; | ||
262 | this.primData.ProfileHollow = updatePacket.ProfileHollow; | ||
263 | this.primData.PathRadiusOffset = updatePacket.PathRadiusOffset; | ||
264 | this.primData.PathRevolutions = updatePacket.PathRevolutions; | ||
265 | this.primData.PathTaperX = updatePacket.PathTaperX; | ||
266 | this.primData.PathTaperY = updatePacket.PathTaperY; | ||
267 | this.primData.PathTwist = updatePacket.PathTwist; | ||
268 | this.primData.PathTwistBegin = updatePacket.PathTwistBegin; | ||
269 | } | ||
270 | |||
271 | /// <summary> | ||
272 | /// | ||
273 | /// </summary> | ||
274 | /// <param name="tex"></param> | ||
275 | public void UpdateTexture(byte[] tex) | ||
276 | { | ||
277 | this.primData.TextureEntry = tex; | ||
278 | } | ||
279 | |||
280 | /// <summary> | ||
281 | /// | ||
282 | /// </summary> | ||
283 | /// <param name="pack"></param> | ||
284 | public void UpdateObjectFlags(ObjectFlagUpdatePacket pack) | ||
285 | { | ||
286 | |||
287 | } | ||
288 | |||
289 | /// <summary> | ||
290 | /// | ||
291 | /// </summary> | ||
292 | /// <param name="prim"></param> | ||
293 | public void AssignToParent(Primitive prim) | ||
294 | { | ||
295 | |||
296 | } | ||
297 | |||
298 | #endregion | ||
299 | |||
300 | # region Inventory Methods | ||
301 | /// <summary> | ||
302 | /// | ||
303 | /// </summary> | ||
304 | /// <param name="item"></param> | ||
305 | /// <returns></returns> | ||
306 | public bool AddToInventory(InventoryItem item) | ||
307 | { | ||
308 | return false; | ||
309 | } | ||
310 | |||
311 | /// <summary> | ||
312 | /// | ||
313 | /// </summary> | ||
314 | /// <param name="itemID"></param> | ||
315 | /// <returns></returns> | ||
316 | public InventoryItem RemoveFromInventory(LLUUID itemID) | ||
317 | { | ||
318 | return null; | ||
319 | } | ||
320 | |||
321 | /// <summary> | ||
322 | /// | ||
323 | /// </summary> | ||
324 | /// <param name="simClient"></param> | ||
325 | /// <param name="packet"></param> | ||
326 | public void RequestInventoryInfo(IClientAPI simClient, RequestTaskInventoryPacket packet) | ||
327 | { | ||
328 | |||
329 | } | ||
330 | |||
331 | /// <summary> | ||
332 | /// | ||
333 | /// </summary> | ||
334 | /// <param name="simClient"></param> | ||
335 | /// <param name="xferID"></param> | ||
336 | public void RequestXferInventory(IClientAPI simClient, ulong xferID) | ||
337 | { | ||
338 | //will only currently work if the total size of the inventory data array is under about 1000 bytes | ||
339 | SendXferPacketPacket send = new SendXferPacketPacket(); | ||
340 | |||
341 | send.XferID.ID = xferID; | ||
342 | send.XferID.Packet = 1 + 2147483648; | ||
343 | send.DataPacket.Data = this.ConvertInventoryToBytes(); | ||
344 | |||
345 | simClient.OutPacket(send); | ||
346 | } | ||
347 | |||
348 | /// <summary> | ||
349 | /// | ||
350 | /// </summary> | ||
351 | /// <returns></returns> | ||
352 | public byte[] ConvertInventoryToBytes() | ||
353 | { | ||
354 | System.Text.Encoding enc = System.Text.Encoding.ASCII; | ||
355 | byte[] result = new byte[0]; | ||
356 | List<byte[]> inventoryData = new List<byte[]>(); | ||
357 | int totallength = 0; | ||
358 | foreach (InventoryItem invItem in inventoryItems.Values) | ||
359 | { | ||
360 | byte[] data = enc.GetBytes(invItem.ExportString()); | ||
361 | inventoryData.Add(data); | ||
362 | totallength += data.Length; | ||
363 | } | ||
364 | //TODO: copy arrays into the single result array | ||
365 | |||
366 | return result; | ||
367 | } | ||
368 | |||
369 | /// <summary> | ||
370 | /// | ||
371 | /// </summary> | ||
372 | /// <param name="data"></param> | ||
373 | public void CreateInventoryFromBytes(byte[] data) | ||
374 | { | ||
375 | |||
376 | } | ||
377 | |||
378 | #endregion | ||
379 | |||
380 | #region Update viewers Methods | ||
381 | |||
382 | /// <summary> | ||
383 | /// | ||
384 | /// </summary> | ||
385 | /// <param name="remoteClient"></param> | ||
386 | public void SendFullUpdateForAllChildren(IClientAPI remoteClient) | ||
387 | { | ||
388 | this.SendFullUpdateToClient(remoteClient); | ||
389 | for (int i = 0; i < this.children.Count; i++) | ||
390 | { | ||
391 | if (this.children[i] is Primitive) | ||
392 | { | ||
393 | ((Primitive)this.children[i]).SendFullUpdateForAllChildren(remoteClient); | ||
394 | } | ||
395 | } | ||
396 | } | ||
397 | |||
398 | /// <summary> | ||
399 | /// | ||
400 | /// </summary> | ||
401 | /// <param name="remoteClient"></param> | ||
402 | public void SendFullUpdateToClient(IClientAPI remoteClient) | ||
403 | { | ||
404 | LLVector3 lPos; | ||
405 | if (this._physActor != null && this.physicsEnabled) | ||
406 | { | ||
407 | PhysicsVector pPos = this._physActor.Position; | ||
408 | lPos = new LLVector3(pPos.X, pPos.Y, pPos.Z); | ||
409 | } | ||
410 | else | ||
411 | { | ||
412 | lPos = this.Pos; | ||
413 | } | ||
414 | |||
415 | remoteClient.SendPrimitiveToClient(this.m_regionHandle, 64096, this.LocalId, this.primData, lPos, new LLUUID("00000000-0000-0000-9999-000000000005"), this.flags); | ||
416 | } | ||
417 | |||
418 | /// <summary> | ||
419 | /// | ||
420 | /// </summary> | ||
421 | public void SendFullUpdateToAllClients() | ||
422 | { | ||
423 | List<ScenePresence> avatars = this.m_world.RequestAvatarList(); | ||
424 | for (int i = 0; i < avatars.Count; i++) | ||
425 | { | ||
426 | this.SendFullUpdateToClient(avatars[i].ControllingClient); | ||
427 | } | ||
428 | } | ||
429 | |||
430 | /// <summary> | ||
431 | /// | ||
432 | /// </summary> | ||
433 | /// <param name="RemoteClient"></param> | ||
434 | public void SendTerseUpdateToClient(IClientAPI RemoteClient) | ||
435 | { | ||
436 | LLVector3 lPos; | ||
437 | Axiom.MathLib.Quaternion lRot; | ||
438 | if (this._physActor != null && this.physicsEnabled) //is this needed ? doesn't the property fields do this for us? | ||
439 | { | ||
440 | PhysicsVector pPos = this._physActor.Position; | ||
441 | lPos = new LLVector3(pPos.X, pPos.Y, pPos.Z); | ||
442 | lRot = this._physActor.Orientation; | ||
443 | } | ||
444 | else | ||
445 | { | ||
446 | lPos = this.Pos; | ||
447 | lRot = this.rotation; | ||
448 | } | ||
449 | LLQuaternion mRot = new LLQuaternion(lRot.x, lRot.y, lRot.z, lRot.w); | ||
450 | RemoteClient.SendPrimTerseUpdate(this.m_regionHandle, 64096, this.LocalId, lPos, mRot); | ||
451 | } | ||
452 | |||
453 | /// <summary> | ||
454 | /// | ||
455 | /// </summary> | ||
456 | public void SendTerseUpdateToALLClients() | ||
457 | { | ||
458 | List<ScenePresence> avatars = this.m_world.RequestAvatarList(); | ||
459 | for (int i = 0; i < avatars.Count; i++) | ||
460 | { | ||
461 | this.SendTerseUpdateToClient(avatars[i].ControllingClient); | ||
462 | } | ||
463 | } | ||
464 | |||
465 | #endregion | ||
466 | |||
467 | #region Create Methods | ||
468 | |||
469 | /// <summary> | ||
470 | /// | ||
471 | /// </summary> | ||
472 | /// <param name="addPacket"></param> | ||
473 | /// <param name="ownerID"></param> | ||
474 | /// <param name="localID"></param> | ||
475 | public void CreateFromPacket(ObjectAddPacket addPacket, LLUUID ownerID, uint localID) | ||
476 | { | ||
477 | PrimData PData = new PrimData(); | ||
478 | this.primData = PData; | ||
479 | this.primData.CreationDate = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; | ||
480 | |||
481 | PData.OwnerID = ownerID; | ||
482 | PData.PCode = addPacket.ObjectData.PCode; | ||
483 | PData.PathBegin = addPacket.ObjectData.PathBegin; | ||
484 | PData.PathEnd = addPacket.ObjectData.PathEnd; | ||
485 | PData.PathScaleX = addPacket.ObjectData.PathScaleX; | ||
486 | PData.PathScaleY = addPacket.ObjectData.PathScaleY; | ||
487 | PData.PathShearX = addPacket.ObjectData.PathShearX; | ||
488 | PData.PathShearY = addPacket.ObjectData.PathShearY; | ||
489 | PData.PathSkew = addPacket.ObjectData.PathSkew; | ||
490 | PData.ProfileBegin = addPacket.ObjectData.ProfileBegin; | ||
491 | PData.ProfileEnd = addPacket.ObjectData.ProfileEnd; | ||
492 | PData.Scale = addPacket.ObjectData.Scale; | ||
493 | PData.PathCurve = addPacket.ObjectData.PathCurve; | ||
494 | PData.ProfileCurve = addPacket.ObjectData.ProfileCurve; | ||
495 | PData.ParentID = 0; | ||
496 | PData.ProfileHollow = addPacket.ObjectData.ProfileHollow; | ||
497 | PData.PathRadiusOffset = addPacket.ObjectData.PathRadiusOffset; | ||
498 | PData.PathRevolutions = addPacket.ObjectData.PathRevolutions; | ||
499 | PData.PathTaperX = addPacket.ObjectData.PathTaperX; | ||
500 | PData.PathTaperY = addPacket.ObjectData.PathTaperY; | ||
501 | PData.PathTwist = addPacket.ObjectData.PathTwist; | ||
502 | PData.PathTwistBegin = addPacket.ObjectData.PathTwistBegin; | ||
503 | LLVector3 pos1 = addPacket.ObjectData.RayEnd; | ||
504 | this.primData.FullID = this.uuid = LLUUID.Random(); | ||
505 | this.primData.LocalID = m_localId = (uint)(localID); | ||
506 | this.primData.Position = this.Pos = pos1; | ||
507 | |||
508 | this.updateFlag = 1; | ||
509 | } | ||
510 | |||
511 | /// <summary> | ||
512 | /// | ||
513 | /// </summary> | ||
514 | /// <param name="data"></param> | ||
515 | public void CreateFromBytes(byte[] data) | ||
516 | { | ||
517 | |||
518 | } | ||
519 | |||
520 | /// <summary> | ||
521 | /// | ||
522 | /// </summary> | ||
523 | /// <param name="primData"></param> | ||
524 | public void CreateFromPrimData(PrimData primData) | ||
525 | { | ||
526 | this.CreateFromPrimData(primData, primData.Position, primData.LocalID, false); | ||
527 | } | ||
528 | |||
529 | /// <summary> | ||
530 | /// | ||
531 | /// </summary> | ||
532 | /// <param name="primData"></param> | ||
533 | /// <param name="posi"></param> | ||
534 | /// <param name="localID"></param> | ||
535 | /// <param name="newprim"></param> | ||
536 | public void CreateFromPrimData(PrimData primData, LLVector3 posi, uint localID, bool newprim) | ||
537 | { | ||
538 | |||
539 | } | ||
540 | |||
541 | public void GrapMovement(LLVector3 offset, LLVector3 pos, IClientAPI remoteClient) | ||
542 | { | ||
543 | // Console.WriteLine("moving prim to new location " + pos.X + " , " + pos.Y + " , " + pos.Z); | ||
544 | this.Pos = pos; | ||
545 | this.SendTerseUpdateToALLClients(); | ||
546 | } | ||
547 | |||
548 | public void GetProperites(IClientAPI client) | ||
549 | { | ||
550 | //needs changing | ||
551 | ObjectPropertiesPacket proper = new ObjectPropertiesPacket(); | ||
552 | proper.ObjectData = new ObjectPropertiesPacket.ObjectDataBlock[1]; | ||
553 | proper.ObjectData[0] = new ObjectPropertiesPacket.ObjectDataBlock(); | ||
554 | proper.ObjectData[0].ItemID = LLUUID.Zero; | ||
555 | proper.ObjectData[0].CreationDate = (ulong)primData.CreationDate; | ||
556 | proper.ObjectData[0].CreatorID = primData.OwnerID; | ||
557 | proper.ObjectData[0].FolderID = LLUUID.Zero; | ||
558 | proper.ObjectData[0].FromTaskID = LLUUID.Zero; | ||
559 | proper.ObjectData[0].GroupID = LLUUID.Zero; | ||
560 | proper.ObjectData[0].InventorySerial = 0; | ||
561 | proper.ObjectData[0].LastOwnerID = LLUUID.Zero; | ||
562 | proper.ObjectData[0].ObjectID = this.uuid; | ||
563 | proper.ObjectData[0].OwnerID = primData.OwnerID; | ||
564 | proper.ObjectData[0].TouchName = new byte[0]; | ||
565 | proper.ObjectData[0].TextureID = new byte[0]; | ||
566 | proper.ObjectData[0].SitName = new byte[0]; | ||
567 | proper.ObjectData[0].Name = new byte[0]; | ||
568 | proper.ObjectData[0].Description = new byte[0]; | ||
569 | proper.ObjectData[0].OwnerMask = primData.OwnerMask; | ||
570 | proper.ObjectData[0].NextOwnerMask = primData.NextOwnerMask; | ||
571 | proper.ObjectData[0].GroupMask = primData.GroupMask; | ||
572 | proper.ObjectData[0].EveryoneMask = primData.EveryoneMask; | ||
573 | proper.ObjectData[0].BaseMask = primData.BaseMask; | ||
574 | |||
575 | client.OutPacket(proper); | ||
576 | |||
577 | } | ||
578 | |||
579 | #endregion | ||
580 | |||
581 | } | ||
582 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs new file mode 100644 index 0000000..1d55c4d --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs | |||
@@ -0,0 +1,305 @@ | |||
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 System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using libsecondlife; | ||
32 | using libsecondlife.Packets; | ||
33 | using OpenSim.Physics.Manager; | ||
34 | using OpenSim.Framework.Interfaces; | ||
35 | using OpenSim.Framework.Types; | ||
36 | using OpenSim.Framework.Inventory; | ||
37 | using OpenSim.Framework.Utilities; | ||
38 | |||
39 | namespace OpenSim.Region.Environment.Scenes | ||
40 | { | ||
41 | public partial class Scene | ||
42 | { | ||
43 | /// <summary> | ||
44 | /// Modifies terrain using the specified information | ||
45 | /// </summary> | ||
46 | /// <param name="height">The height at which the user started modifying the terrain</param> | ||
47 | /// <param name="seconds">The number of seconds the modify button was pressed</param> | ||
48 | /// <param name="brushsize">The size of the brush used</param> | ||
49 | /// <param name="action">The action to be performed</param> | ||
50 | /// <param name="north">Distance from the north border where the cursor is located</param> | ||
51 | /// <param name="west">Distance from the west border where the cursor is located</param> | ||
52 | public void ModifyTerrain(float height, float seconds, byte brushsize, byte action, float north, float west) | ||
53 | { | ||
54 | // Shiny. | ||
55 | double size = (double)(1 << brushsize); | ||
56 | |||
57 | switch (action) | ||
58 | { | ||
59 | case 0: | ||
60 | // flatten terrain | ||
61 | Terrain.flatten(north, west, size, (double)seconds / 100.0); | ||
62 | RegenerateTerrain(true, (int)north, (int)west); | ||
63 | break; | ||
64 | case 1: | ||
65 | // raise terrain | ||
66 | Terrain.raise(north, west, size, (double)seconds / 100.0); | ||
67 | RegenerateTerrain(true, (int)north, (int)west); | ||
68 | break; | ||
69 | case 2: | ||
70 | //lower terrain | ||
71 | Terrain.lower(north, west, size, (double)seconds / 100.0); | ||
72 | RegenerateTerrain(true, (int)north, (int)west); | ||
73 | break; | ||
74 | case 3: | ||
75 | // smooth terrain | ||
76 | Terrain.smooth(north, west, size, (double)seconds / 100.0); | ||
77 | RegenerateTerrain(true, (int)north, (int)west); | ||
78 | break; | ||
79 | case 4: | ||
80 | // noise | ||
81 | Terrain.noise(north, west, size, (double)seconds / 100.0); | ||
82 | RegenerateTerrain(true, (int)north, (int)west); | ||
83 | break; | ||
84 | case 5: | ||
85 | // revert | ||
86 | Terrain.revert(north, west, size, (double)seconds / 100.0); | ||
87 | RegenerateTerrain(true, (int)north, (int)west); | ||
88 | break; | ||
89 | |||
90 | // CLIENT EXTENSIONS GO HERE | ||
91 | case 128: | ||
92 | // erode-thermal | ||
93 | break; | ||
94 | case 129: | ||
95 | // erode-aerobic | ||
96 | break; | ||
97 | case 130: | ||
98 | // erode-hydraulic | ||
99 | break; | ||
100 | } | ||
101 | return; | ||
102 | } | ||
103 | |||
104 | /// <summary> | ||
105 | /// | ||
106 | /// </summary> | ||
107 | /// <param name="message"></param> | ||
108 | /// <param name="type"></param> | ||
109 | /// <param name="fromPos"></param> | ||
110 | /// <param name="fromName"></param> | ||
111 | /// <param name="fromAgentID"></param> | ||
112 | public void SimChat(byte[] message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID) | ||
113 | { | ||
114 | Console.WriteLine("Chat message"); | ||
115 | ScenePresence avatar = null; | ||
116 | foreach (IClientAPI client in m_clientThreads.Values) | ||
117 | { | ||
118 | int dis = -1000; | ||
119 | if (this.Avatars.ContainsKey(client.AgentId)) | ||
120 | { | ||
121 | |||
122 | avatar = this.Avatars[client.AgentId]; | ||
123 | // int dis = Util.fast_distance2d((int)(client.ClientAvatar.Pos.X - simClient.ClientAvatar.Pos.X), (int)(client.ClientAvatar.Pos.Y - simClient.ClientAvatar.Pos.Y)); | ||
124 | dis= (int)avatar.Pos.GetDistanceTo(fromPos); | ||
125 | Console.WriteLine("found avatar at " +dis); | ||
126 | |||
127 | } | ||
128 | |||
129 | switch (type) | ||
130 | { | ||
131 | case 0: // Whisper | ||
132 | if ((dis < 10) && (dis > -10)) | ||
133 | { | ||
134 | //should change so the message is sent through the avatar rather than direct to the ClientView | ||
135 | client.SendChatMessage(message, type, fromPos, fromName, fromAgentID); | ||
136 | } | ||
137 | break; | ||
138 | case 1: // Say | ||
139 | if ((dis < 30) && (dis > -30)) | ||
140 | { | ||
141 | Console.WriteLine("sending chat"); | ||
142 | client.SendChatMessage(message, type, fromPos, fromName, fromAgentID); | ||
143 | } | ||
144 | break; | ||
145 | case 2: // Shout | ||
146 | if ((dis < 100) && (dis > -100)) | ||
147 | { | ||
148 | client.SendChatMessage(message, type, fromPos, fromName, fromAgentID); | ||
149 | } | ||
150 | break; | ||
151 | |||
152 | case 0xff: // Broadcast | ||
153 | client.SendChatMessage(message, type, fromPos, fromName, fromAgentID); | ||
154 | break; | ||
155 | } | ||
156 | |||
157 | } | ||
158 | } | ||
159 | |||
160 | /// <summary> | ||
161 | /// | ||
162 | /// </summary> | ||
163 | /// <param name="primAsset"></param> | ||
164 | /// <param name="pos"></param> | ||
165 | public void RezObject(AssetBase primAsset, LLVector3 pos) | ||
166 | { | ||
167 | |||
168 | } | ||
169 | |||
170 | /// <summary> | ||
171 | /// | ||
172 | /// </summary> | ||
173 | /// <param name="packet"></param> | ||
174 | /// <param name="simClient"></param> | ||
175 | public void DeRezObject(Packet packet, IClientAPI simClient) | ||
176 | { | ||
177 | |||
178 | } | ||
179 | |||
180 | /// <summary> | ||
181 | /// | ||
182 | /// </summary> | ||
183 | /// <param name="remoteClient"></param> | ||
184 | public void SendAvatarsToClient(IClientAPI remoteClient) | ||
185 | { | ||
186 | |||
187 | } | ||
188 | |||
189 | /// <summary> | ||
190 | /// | ||
191 | /// </summary> | ||
192 | /// <param name="parentPrim"></param> | ||
193 | /// <param name="childPrims"></param> | ||
194 | public void LinkObjects(uint parentPrim, List<uint> childPrims) | ||
195 | { | ||
196 | |||
197 | |||
198 | } | ||
199 | |||
200 | /// <summary> | ||
201 | /// | ||
202 | /// </summary> | ||
203 | /// <param name="primLocalID"></param> | ||
204 | /// <param name="shapeBlock"></param> | ||
205 | public void UpdatePrimShape(uint primLocalID, ObjectShapePacket.ObjectDataBlock shapeBlock) | ||
206 | { | ||
207 | |||
208 | } | ||
209 | |||
210 | /// <summary> | ||
211 | /// | ||
212 | /// </summary> | ||
213 | /// <param name="primLocalID"></param> | ||
214 | /// <param name="remoteClient"></param> | ||
215 | public void SelectPrim(uint primLocalID, IClientAPI remoteClient) | ||
216 | { | ||
217 | foreach (Entity ent in Entities.Values) | ||
218 | { | ||
219 | if (ent.LocalId == primLocalID) | ||
220 | { | ||
221 | ((OpenSim.Region.Environment.Scenes.Primitive)ent).GetProperites(remoteClient); | ||
222 | break; | ||
223 | } | ||
224 | } | ||
225 | } | ||
226 | |||
227 | public void MoveObject(LLUUID objectID, LLVector3 offset, LLVector3 pos, IClientAPI remoteClient) | ||
228 | { | ||
229 | if (this.Entities.ContainsKey(objectID)) | ||
230 | { | ||
231 | ((Primitive)this.Entities[objectID]).GrapMovement(offset, pos, remoteClient); | ||
232 | } | ||
233 | } | ||
234 | |||
235 | /// <summary> | ||
236 | /// | ||
237 | /// </summary> | ||
238 | /// <param name="localID"></param> | ||
239 | /// <param name="packet"></param> | ||
240 | /// <param name="remoteClient"></param> | ||
241 | public void UpdatePrimFlags(uint localID, Packet packet, IClientAPI remoteClient) | ||
242 | { | ||
243 | |||
244 | } | ||
245 | |||
246 | /// <summary> | ||
247 | /// | ||
248 | /// </summary> | ||
249 | /// <param name="localID"></param> | ||
250 | /// <param name="texture"></param> | ||
251 | /// <param name="remoteClient"></param> | ||
252 | public void UpdatePrimTexture(uint localID, byte[] texture, IClientAPI remoteClient) | ||
253 | { | ||
254 | |||
255 | } | ||
256 | |||
257 | /// <summary> | ||
258 | /// | ||
259 | /// </summary> | ||
260 | /// <param name="localID"></param> | ||
261 | /// <param name="pos"></param> | ||
262 | /// <param name="remoteClient"></param> | ||
263 | public void UpdatePrimPosition(uint localID, LLVector3 pos, IClientAPI remoteClient) | ||
264 | { | ||
265 | foreach (Entity ent in Entities.Values) | ||
266 | { | ||
267 | if (ent.LocalId == localID) | ||
268 | { | ||
269 | ((OpenSim.Region.Environment.Scenes.Primitive)ent).UpdatePosition(pos); | ||
270 | break; | ||
271 | } | ||
272 | } | ||
273 | } | ||
274 | |||
275 | /// <summary> | ||
276 | /// | ||
277 | /// </summary> | ||
278 | /// <param name="localID"></param> | ||
279 | /// <param name="rot"></param> | ||
280 | /// <param name="remoteClient"></param> | ||
281 | public void UpdatePrimRotation(uint localID, LLQuaternion rot, IClientAPI remoteClient) | ||
282 | { | ||
283 | |||
284 | } | ||
285 | |||
286 | /// <summary> | ||
287 | /// | ||
288 | /// </summary> | ||
289 | /// <param name="localID"></param> | ||
290 | /// <param name="scale"></param> | ||
291 | /// <param name="remoteClient"></param> | ||
292 | public void UpdatePrimScale(uint localID, LLVector3 scale, IClientAPI remoteClient) | ||
293 | { | ||
294 | } | ||
295 | |||
296 | /// <summary> | ||
297 | /// Sends prims to a client | ||
298 | /// </summary> | ||
299 | /// <param name="RemoteClient">Client to send to</param> | ||
300 | public void GetInitialPrims(IClientAPI RemoteClient) | ||
301 | { | ||
302 | |||
303 | } | ||
304 | } | ||
305 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/Scene.Scripting.cs b/OpenSim/Region/Environment/Scenes/Scene.Scripting.cs new file mode 100644 index 0000000..2249c3d --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/Scene.Scripting.cs | |||
@@ -0,0 +1,184 @@ | |||
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 System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using System.IO; | ||
32 | using System.Reflection; | ||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Framework.Interfaces; | ||
35 | using OpenSim.Framework.Types; | ||
36 | using libsecondlife; | ||
37 | |||
38 | namespace OpenSim.Region.Environment.Scenes | ||
39 | { | ||
40 | public partial class Scene | ||
41 | { | ||
42 | private Dictionary<string, IScriptEngine> scriptEngines = new Dictionary<string, IScriptEngine>(); | ||
43 | |||
44 | /// <summary> | ||
45 | /// | ||
46 | /// </summary> | ||
47 | private void LoadScriptEngines() | ||
48 | { | ||
49 | this.LoadScriptPlugins(); | ||
50 | } | ||
51 | |||
52 | /// <summary> | ||
53 | /// | ||
54 | /// </summary> | ||
55 | public void LoadScriptPlugins() | ||
56 | { | ||
57 | string path = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "ScriptEngines"); | ||
58 | string[] pluginFiles = Directory.GetFiles(path, "*.dll"); | ||
59 | |||
60 | |||
61 | for (int i = 0; i < pluginFiles.Length; i++) | ||
62 | { | ||
63 | this.AddPlugin(pluginFiles[i]); | ||
64 | } | ||
65 | } | ||
66 | |||
67 | /// <summary> | ||
68 | /// | ||
69 | /// </summary> | ||
70 | /// <param name="FileName"></param> | ||
71 | private void AddPlugin(string FileName) | ||
72 | { | ||
73 | Assembly pluginAssembly = Assembly.LoadFrom(FileName); | ||
74 | |||
75 | foreach (Type pluginType in pluginAssembly.GetTypes()) | ||
76 | { | ||
77 | if (pluginType.IsPublic) | ||
78 | { | ||
79 | if (!pluginType.IsAbstract) | ||
80 | { | ||
81 | Type typeInterface = pluginType.GetInterface("IScriptEngine", true); | ||
82 | |||
83 | if (typeInterface != null) | ||
84 | { | ||
85 | IScriptEngine plug = (IScriptEngine)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); | ||
86 | plug.Init(this); | ||
87 | this.scriptEngines.Add(plug.GetName(), plug); | ||
88 | |||
89 | } | ||
90 | |||
91 | typeInterface = null; | ||
92 | } | ||
93 | } | ||
94 | } | ||
95 | |||
96 | pluginAssembly = null; | ||
97 | } | ||
98 | |||
99 | /// <summary> | ||
100 | /// | ||
101 | /// </summary> | ||
102 | /// <param name="scriptType"></param> | ||
103 | /// <param name="scriptName"></param> | ||
104 | /// <param name="script"></param> | ||
105 | /// <param name="ent"></param> | ||
106 | public void LoadScript(string scriptType, string scriptName, string script, Entity ent) | ||
107 | { | ||
108 | if(this.scriptEngines.ContainsKey(scriptType)) | ||
109 | { | ||
110 | this.scriptEngines[scriptType].LoadScript(script, scriptName, ent.LocalId); | ||
111 | } | ||
112 | } | ||
113 | |||
114 | #region IScriptAPI Methods | ||
115 | |||
116 | /// <summary> | ||
117 | /// | ||
118 | /// </summary> | ||
119 | /// <param name="localID"></param> | ||
120 | /// <returns></returns> | ||
121 | public LLVector3 GetEntityPosition(uint localID) | ||
122 | { | ||
123 | LLVector3 res = new LLVector3(); | ||
124 | // Console.WriteLine("script- getting entity " + localID + " position"); | ||
125 | foreach (Entity entity in this.Entities.Values) | ||
126 | { | ||
127 | if (entity.LocalId == localID) | ||
128 | { | ||
129 | res.X = entity.Pos.X; | ||
130 | res.Y = entity.Pos.Y; | ||
131 | res.Z = entity.Pos.Z; | ||
132 | } | ||
133 | } | ||
134 | return res; | ||
135 | } | ||
136 | |||
137 | /// <summary> | ||
138 | /// | ||
139 | /// </summary> | ||
140 | /// <param name="localID"></param> | ||
141 | /// <param name="x"></param> | ||
142 | /// <param name="y"></param> | ||
143 | /// <param name="z"></param> | ||
144 | public void SetEntityPosition(uint localID, float x , float y, float z) | ||
145 | { | ||
146 | foreach (Entity entity in this.Entities.Values) | ||
147 | { | ||
148 | if (entity.LocalId == localID && entity is Primitive) | ||
149 | { | ||
150 | LLVector3 pos = entity.Pos; | ||
151 | pos.X = x; | ||
152 | pos.Y = y; | ||
153 | Primitive prim = entity as Primitive; | ||
154 | // Of course, we really should have asked the physEngine if this is possible, and if not, returned false. | ||
155 | //prim.UpdatePosition(pos); | ||
156 | // Console.WriteLine("script- setting entity " + localID + " positon"); | ||
157 | } | ||
158 | } | ||
159 | |||
160 | } | ||
161 | |||
162 | /// <summary> | ||
163 | /// | ||
164 | /// </summary> | ||
165 | /// <returns></returns> | ||
166 | public uint GetRandomAvatarID() | ||
167 | { | ||
168 | //Console.WriteLine("script- getting random avatar id"); | ||
169 | uint res = 0; | ||
170 | foreach (Entity entity in this.Entities.Values) | ||
171 | { | ||
172 | if (entity is ScenePresence) | ||
173 | { | ||
174 | res = entity.LocalId; | ||
175 | } | ||
176 | } | ||
177 | return res; | ||
178 | } | ||
179 | |||
180 | #endregion | ||
181 | |||
182 | |||
183 | } | ||
184 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs new file mode 100644 index 0000000..ff54efa --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/Scene.cs | |||
@@ -0,0 +1,795 @@ | |||
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 System.Timers; | ||
37 | using OpenSim.Physics.Manager; | ||
38 | using OpenSim.Framework.Interfaces; | ||
39 | using OpenSim.Framework.Types; | ||
40 | using OpenSim.Framework.Inventory; | ||
41 | using OpenSim.Framework; | ||
42 | using OpenSim.Region.Environment.Scripting; | ||
43 | using OpenSim.Region.Terrain; | ||
44 | using OpenSim.Framework.Communications; | ||
45 | using OpenSim.Region.Caches; | ||
46 | using OpenSim.Region.Environment; | ||
47 | using OpenSim.Framework.Servers; | ||
48 | |||
49 | namespace OpenSim.Region.Environment.Scenes | ||
50 | { | ||
51 | public delegate bool FilterAvatarList(ScenePresence avatar); | ||
52 | |||
53 | public partial class Scene : SceneBase, ILocalStorageReceiver, IScriptAPI | ||
54 | { | ||
55 | protected System.Timers.Timer m_heartbeatTimer = new System.Timers.Timer(); | ||
56 | protected Dictionary<libsecondlife.LLUUID, ScenePresence> Avatars; | ||
57 | protected Dictionary<libsecondlife.LLUUID, Primitive> Prims; | ||
58 | private PhysicsScene phyScene; | ||
59 | private float timeStep = 0.1f; | ||
60 | private Random Rand = new Random(); | ||
61 | private uint _primCount = 702000; | ||
62 | private int storageCount; | ||
63 | private Dictionary<LLUUID, ScriptHandler> m_scriptHandlers; | ||
64 | private Dictionary<string, ScriptFactory> m_scripts; | ||
65 | private Mutex updateLock; | ||
66 | |||
67 | protected AuthenticateSessionsBase authenticateHandler; | ||
68 | protected RegionCommsListener regionCommsHost; | ||
69 | protected CommunicationsManager commsManager; | ||
70 | |||
71 | protected Dictionary<LLUUID, Capabilities.Caps> capsHandlers = new Dictionary<LLUUID, Capabilities.Caps>(); | ||
72 | protected BaseHttpServer httpListener; | ||
73 | |||
74 | public ParcelManager parcelManager; | ||
75 | public EstateManager estateManager; | ||
76 | public EventManager eventManager; | ||
77 | |||
78 | #region Properties | ||
79 | /// <summary> | ||
80 | /// | ||
81 | /// </summary> | ||
82 | public PhysicsScene PhysScene | ||
83 | { | ||
84 | set | ||
85 | { | ||
86 | this.phyScene = value; | ||
87 | } | ||
88 | get | ||
89 | { | ||
90 | return (this.phyScene); | ||
91 | } | ||
92 | } | ||
93 | |||
94 | #endregion | ||
95 | |||
96 | #region Constructors | ||
97 | /// <summary> | ||
98 | /// Creates a new World class, and a region to go with it. | ||
99 | /// </summary> | ||
100 | /// <param name="clientThreads">Dictionary to contain client threads</param> | ||
101 | /// <param name="regionHandle">Region Handle for this region</param> | ||
102 | /// <param name="regionName">Region Name for this region</param> | ||
103 | public Scene(Dictionary<uint, IClientAPI> clientThreads, RegionInfo regInfo, AuthenticateSessionsBase authen, CommunicationsManager commsMan, AssetCache assetCach, BaseHttpServer httpServer) | ||
104 | { | ||
105 | try | ||
106 | { | ||
107 | updateLock = new Mutex(false); | ||
108 | this.authenticateHandler = authen; | ||
109 | this.commsManager = commsMan; | ||
110 | this.assetCache = assetCach; | ||
111 | m_clientThreads = clientThreads; | ||
112 | m_regInfo = regInfo; | ||
113 | m_regionHandle = m_regInfo.RegionHandle; | ||
114 | m_regionName = m_regInfo.RegionName; | ||
115 | this.m_datastore = m_regInfo.DataStore; | ||
116 | this.RegisterRegionWithComms(); | ||
117 | |||
118 | parcelManager = new ParcelManager(this, this.m_regInfo); | ||
119 | estateManager = new EstateManager(this, this.m_regInfo); | ||
120 | |||
121 | eventManager = new EventManager(); | ||
122 | |||
123 | m_scriptHandlers = new Dictionary<LLUUID, ScriptHandler>(); | ||
124 | m_scripts = new Dictionary<string, ScriptFactory>(); | ||
125 | |||
126 | OpenSim.Framework.Console.MainLog.Instance.Verbose( "World.cs - creating new entitities instance"); | ||
127 | Entities = new Dictionary<libsecondlife.LLUUID, Entity>(); | ||
128 | Avatars = new Dictionary<LLUUID, ScenePresence>(); | ||
129 | Prims = new Dictionary<LLUUID, Primitive>(); | ||
130 | |||
131 | OpenSim.Framework.Console.MainLog.Instance.Verbose( "World.cs - creating LandMap"); | ||
132 | Terrain = new TerrainEngine(); | ||
133 | |||
134 | ScenePresence.LoadAnims(); | ||
135 | this.httpListener = httpServer; | ||
136 | |||
137 | } | ||
138 | catch (Exception e) | ||
139 | { | ||
140 | OpenSim.Framework.Console.MainLog.Instance.Error( "World.cs: Constructor failed with exception " + e.ToString()); | ||
141 | } | ||
142 | } | ||
143 | #endregion | ||
144 | |||
145 | /// <summary> | ||
146 | /// | ||
147 | /// </summary> | ||
148 | public void StartTimer() | ||
149 | { | ||
150 | m_heartbeatTimer.Enabled = true; | ||
151 | m_heartbeatTimer.Interval = 100; | ||
152 | m_heartbeatTimer.Elapsed += new ElapsedEventHandler(this.Heartbeat); | ||
153 | } | ||
154 | |||
155 | |||
156 | #region Update Methods | ||
157 | |||
158 | |||
159 | /// <summary> | ||
160 | /// Performs per-frame updates regularly | ||
161 | /// </summary> | ||
162 | /// <param name="sender"></param> | ||
163 | /// <param name="e"></param> | ||
164 | void Heartbeat(object sender, System.EventArgs e) | ||
165 | { | ||
166 | this.Update(); | ||
167 | } | ||
168 | |||
169 | /// <summary> | ||
170 | /// Performs per-frame updates on the world, this should be the central world loop | ||
171 | /// </summary> | ||
172 | public override void Update() | ||
173 | { | ||
174 | updateLock.WaitOne(); | ||
175 | try | ||
176 | { | ||
177 | if (this.phyScene.IsThreaded) | ||
178 | { | ||
179 | this.phyScene.GetResults(); | ||
180 | |||
181 | } | ||
182 | |||
183 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | ||
184 | { | ||
185 | Entities[UUID].updateMovement(); | ||
186 | } | ||
187 | |||
188 | lock (this.m_syncRoot) | ||
189 | { | ||
190 | this.phyScene.Simulate(timeStep); | ||
191 | } | ||
192 | |||
193 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | ||
194 | { | ||
195 | Entities[UUID].update(); | ||
196 | } | ||
197 | |||
198 | // New | ||
199 | eventManager.TriggerOnFrame(); | ||
200 | |||
201 | // TODO: Obsolete - Phase out | ||
202 | foreach (ScriptHandler scriptHandler in m_scriptHandlers.Values) | ||
203 | { | ||
204 | scriptHandler.OnFrame(); | ||
205 | } | ||
206 | foreach (IScriptEngine scripteng in this.scriptEngines.Values) | ||
207 | { | ||
208 | scripteng.OnFrame(); | ||
209 | } | ||
210 | |||
211 | //backup world data | ||
212 | this.storageCount++; | ||
213 | if (storageCount > 1200) //set to how often you want to backup | ||
214 | { | ||
215 | this.Backup(); | ||
216 | storageCount = 0; | ||
217 | } | ||
218 | } | ||
219 | catch (Exception e) | ||
220 | { | ||
221 | OpenSim.Framework.Console.MainLog.Instance.Warn("World.cs: Update() - Failed with exception " + e.ToString()); | ||
222 | } | ||
223 | updateLock.ReleaseMutex(); | ||
224 | |||
225 | } | ||
226 | |||
227 | /// <summary> | ||
228 | /// | ||
229 | /// </summary> | ||
230 | /// <returns></returns> | ||
231 | public bool Backup() | ||
232 | { | ||
233 | /* | ||
234 | try | ||
235 | { | ||
236 | // Terrain backup routines | ||
237 | if (Terrain.tainted > 0) | ||
238 | { | ||
239 | Terrain.tainted = 0; | ||
240 | OpenSim.Framework.Console.MainLog.Instance.Verbose( "World.cs: Backup() - Terrain tainted, saving."); | ||
241 | localStorage.SaveMap(Terrain.getHeights1D()); | ||
242 | OpenSim.Framework.Console.MainLog.Instance.Verbose( "World.cs: Backup() - Terrain saved, informing Physics."); | ||
243 | lock (this.m_syncRoot) | ||
244 | { | ||
245 | phyScene.SetTerrain(Terrain.getHeights1D()); | ||
246 | } | ||
247 | } | ||
248 | |||
249 | // Primitive backup routines | ||
250 | OpenSim.Framework.Console.MainLog.Instance.Verbose( "World.cs: Backup() - Backing up Primitives"); | ||
251 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | ||
252 | { | ||
253 | Entities[UUID].BackUp(); | ||
254 | } | ||
255 | |||
256 | //Parcel backup routines | ||
257 | ParcelData[] parcels = new ParcelData[parcelManager.parcelList.Count]; | ||
258 | int i = 0; | ||
259 | foreach (OpenSim.Region.Environment.Parcel parcel in parcelManager.parcelList.Values) | ||
260 | { | ||
261 | parcels[i] = parcel.parcelData; | ||
262 | i++; | ||
263 | } | ||
264 | localStorage.SaveParcels(parcels); | ||
265 | |||
266 | // Backup successful | ||
267 | return true; | ||
268 | } | ||
269 | catch (Exception e) | ||
270 | { | ||
271 | // Backup failed | ||
272 | OpenSim.Framework.Console.MainLog.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH, "World.cs: Backup() - Backup Failed with exception " + e.ToString()); | ||
273 | return false; | ||
274 | } | ||
275 | */ | ||
276 | return true; | ||
277 | } | ||
278 | #endregion | ||
279 | |||
280 | #region Regenerate Terrain | ||
281 | |||
282 | /// <summary> | ||
283 | /// Rebuilds the terrain using a procedural algorithm | ||
284 | /// </summary> | ||
285 | public void RegenerateTerrain() | ||
286 | { | ||
287 | try | ||
288 | { | ||
289 | Terrain.hills(); | ||
290 | |||
291 | lock (this.m_syncRoot) | ||
292 | { | ||
293 | this.phyScene.SetTerrain(Terrain.getHeights1D()); | ||
294 | } | ||
295 | this.localStorage.SaveMap(this.Terrain.getHeights1D()); | ||
296 | |||
297 | foreach (IClientAPI client in m_clientThreads.Values) | ||
298 | { | ||
299 | this.SendLayerData(client); | ||
300 | } | ||
301 | |||
302 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | ||
303 | { | ||
304 | Entities[UUID].LandRenegerated(); | ||
305 | } | ||
306 | } | ||
307 | catch (Exception e) | ||
308 | { | ||
309 | OpenSim.Framework.Console.MainLog.Instance.Warn("World.cs: RegenerateTerrain() - Failed with exception " + e.ToString()); | ||
310 | } | ||
311 | } | ||
312 | |||
313 | /// <summary> | ||
314 | /// Rebuilds the terrain using a 2D float array | ||
315 | /// </summary> | ||
316 | /// <param name="newMap">256,256 float array containing heights</param> | ||
317 | public void RegenerateTerrain(float[,] newMap) | ||
318 | { | ||
319 | try | ||
320 | { | ||
321 | this.Terrain.setHeights2D(newMap); | ||
322 | lock (this.m_syncRoot) | ||
323 | { | ||
324 | this.phyScene.SetTerrain(this.Terrain.getHeights1D()); | ||
325 | } | ||
326 | this.localStorage.SaveMap(this.Terrain.getHeights1D()); | ||
327 | |||
328 | foreach (IClientAPI client in m_clientThreads.Values) | ||
329 | { | ||
330 | this.SendLayerData(client); | ||
331 | } | ||
332 | |||
333 | foreach (libsecondlife.LLUUID UUID in Entities.Keys) | ||
334 | { | ||
335 | Entities[UUID].LandRenegerated(); | ||
336 | } | ||
337 | } | ||
338 | catch (Exception e) | ||
339 | { | ||
340 | OpenSim.Framework.Console.MainLog.Instance.Warn("World.cs: RegenerateTerrain() - Failed with exception " + e.ToString()); | ||
341 | } | ||
342 | } | ||
343 | |||
344 | /// <summary> | ||
345 | /// Rebuilds the terrain assuming changes occured at a specified point[?] | ||
346 | /// </summary> | ||
347 | /// <param name="changes">???</param> | ||
348 | /// <param name="pointx">???</param> | ||
349 | /// <param name="pointy">???</param> | ||
350 | public void RegenerateTerrain(bool changes, int pointx, int pointy) | ||
351 | { | ||
352 | try | ||
353 | { | ||
354 | if (changes) | ||
355 | { | ||
356 | /* Dont save here, rely on tainting system instead */ | ||
357 | |||
358 | foreach (IClientAPI client in m_clientThreads.Values) | ||
359 | { | ||
360 | this.SendLayerData(pointx, pointy, client); | ||
361 | } | ||
362 | } | ||
363 | } | ||
364 | catch (Exception e) | ||
365 | { | ||
366 | OpenSim.Framework.Console.MainLog.Instance.Warn("World.cs: RegenerateTerrain() - Failed with exception " + e.ToString()); | ||
367 | } | ||
368 | } | ||
369 | |||
370 | #endregion | ||
371 | |||
372 | #region Load Terrain | ||
373 | /// <summary> | ||
374 | /// Loads the World heightmap | ||
375 | /// </summary> | ||
376 | /// | ||
377 | public override void LoadWorldMap() | ||
378 | { | ||
379 | try | ||
380 | { | ||
381 | float[] map = this.localStorage.LoadWorld(); | ||
382 | if (map == null) | ||
383 | { | ||
384 | if (string.IsNullOrEmpty(this.m_regInfo.estateSettings.terrainFile)) | ||
385 | { | ||
386 | Console.WriteLine("No default terrain, procedurally generating..."); | ||
387 | this.Terrain.hills(); | ||
388 | |||
389 | this.localStorage.SaveMap(this.Terrain.getHeights1D()); | ||
390 | } | ||
391 | else | ||
392 | { | ||
393 | try | ||
394 | { | ||
395 | this.Terrain.loadFromFileF32(this.m_regInfo.estateSettings.terrainFile); | ||
396 | this.Terrain *= this.m_regInfo.estateSettings.terrainMultiplier; | ||
397 | } | ||
398 | catch | ||
399 | { | ||
400 | Console.WriteLine("Unable to load default terrain, procedurally generating instead..."); | ||
401 | Terrain.hills(); | ||
402 | } | ||
403 | this.localStorage.SaveMap(this.Terrain.getHeights1D()); | ||
404 | } | ||
405 | } | ||
406 | else | ||
407 | { | ||
408 | this.Terrain.setHeights1D(map); | ||
409 | } | ||
410 | |||
411 | CreateTerrainTexture(); | ||
412 | |||
413 | } | ||
414 | catch (Exception e) | ||
415 | { | ||
416 | OpenSim.Framework.Console.MainLog.Instance.Warn("World.cs: LoadWorldMap() - Failed with exception " + e.ToString()); | ||
417 | } | ||
418 | } | ||
419 | |||
420 | /// <summary> | ||
421 | /// | ||
422 | /// </summary> | ||
423 | private void CreateTerrainTexture() | ||
424 | { | ||
425 | //create a texture asset of the terrain | ||
426 | byte[] data = this.Terrain.exportJpegImage("defaultstripe.png"); | ||
427 | this.m_regInfo.estateSettings.terrainImageID = LLUUID.Random(); | ||
428 | AssetBase asset = new AssetBase(); | ||
429 | asset.FullID = this.m_regInfo.estateSettings.terrainImageID; | ||
430 | asset.Data = data; | ||
431 | asset.Name = "terrainImage"; | ||
432 | asset.Type = 0; | ||
433 | this.assetCache.AddAsset(asset); | ||
434 | } | ||
435 | #endregion | ||
436 | |||
437 | #region Primitives Methods | ||
438 | |||
439 | |||
440 | /// <summary> | ||
441 | /// Loads the World's objects | ||
442 | /// </summary> | ||
443 | public void LoadPrimsFromStorage() | ||
444 | { | ||
445 | try | ||
446 | { | ||
447 | OpenSim.Framework.Console.MainLog.Instance.Verbose( "World.cs: LoadPrimsFromStorage() - Loading primitives"); | ||
448 | this.localStorage.LoadPrimitives(this); | ||
449 | } | ||
450 | catch (Exception e) | ||
451 | { | ||
452 | OpenSim.Framework.Console.MainLog.Instance.Warn("World.cs: LoadPrimsFromStorage() - Failed with exception " + e.ToString()); | ||
453 | } | ||
454 | } | ||
455 | |||
456 | /// <summary> | ||
457 | /// Loads a specific object from storage | ||
458 | /// </summary> | ||
459 | /// <param name="prim">The object to load</param> | ||
460 | public void PrimFromStorage(PrimData prim) | ||
461 | { | ||
462 | |||
463 | } | ||
464 | |||
465 | /// <summary> | ||
466 | /// | ||
467 | /// </summary> | ||
468 | /// <param name="addPacket"></param> | ||
469 | /// <param name="agentClient"></param> | ||
470 | public void AddNewPrim(Packet addPacket, IClientAPI agentClient) | ||
471 | { | ||
472 | AddNewPrim((ObjectAddPacket)addPacket, agentClient.AgentId); | ||
473 | } | ||
474 | |||
475 | /// <summary> | ||
476 | /// | ||
477 | /// </summary> | ||
478 | /// <param name="addPacket"></param> | ||
479 | /// <param name="ownerID"></param> | ||
480 | public void AddNewPrim(ObjectAddPacket addPacket, LLUUID ownerID) | ||
481 | { | ||
482 | try | ||
483 | { | ||
484 | Primitive prim = new Primitive(m_regionHandle, this, addPacket, ownerID, this._primCount); | ||
485 | |||
486 | this.Entities.Add(prim.uuid, prim); | ||
487 | this._primCount++; | ||
488 | |||
489 | // Trigger event for listeners | ||
490 | eventManager.TriggerOnNewPrimitive(prim); | ||
491 | } | ||
492 | catch (Exception e) | ||
493 | { | ||
494 | OpenSim.Framework.Console.MainLog.Instance.Warn("World.cs: AddNewPrim() - Failed with exception " + e.ToString()); | ||
495 | } | ||
496 | } | ||
497 | |||
498 | #endregion | ||
499 | |||
500 | #region Add/Remove Avatar Methods | ||
501 | |||
502 | /// <summary> | ||
503 | /// | ||
504 | /// </summary> | ||
505 | /// <param name="remoteClient"></param | ||
506 | /// <param name="agentID"></param> | ||
507 | /// <param name="child"></param> | ||
508 | public override void AddNewClient(IClientAPI remoteClient, LLUUID agentID, bool child) | ||
509 | { | ||
510 | remoteClient.OnRegionHandShakeReply += this.SendLayerData; | ||
511 | //remoteClient.OnRequestWearables += new GenericCall(this.GetInitialPrims); | ||
512 | remoteClient.OnChatFromViewer += this.SimChat; | ||
513 | remoteClient.OnRequestWearables += this.InformClientOfNeighbours; | ||
514 | remoteClient.OnAddPrim += this.AddNewPrim; | ||
515 | remoteClient.OnUpdatePrimPosition += this.UpdatePrimPosition; | ||
516 | remoteClient.OnRequestMapBlocks += this.RequestMapBlocks; | ||
517 | remoteClient.OnTeleportLocationRequest += this.RequestTeleportLocation; | ||
518 | //remoteClient.OnObjectSelect += this.SelectPrim; | ||
519 | remoteClient.OnGrapUpdate += this.MoveObject; | ||
520 | |||
521 | /* remoteClient.OnParcelPropertiesRequest += new ParcelPropertiesRequest(parcelManager.handleParcelPropertiesRequest); | ||
522 | remoteClient.OnParcelDivideRequest += new ParcelDivideRequest(parcelManager.handleParcelDivideRequest); | ||
523 | remoteClient.OnParcelJoinRequest += new ParcelJoinRequest(parcelManager.handleParcelJoinRequest); | ||
524 | remoteClient.OnParcelPropertiesUpdateRequest += new ParcelPropertiesUpdateRequest(parcelManager.handleParcelPropertiesUpdateRequest); | ||
525 | remoteClient.OnEstateOwnerMessage += new EstateOwnerMessageRequest(estateManager.handleEstateOwnerMessage); | ||
526 | */ | ||
527 | |||
528 | ScenePresence newAvatar = null; | ||
529 | try | ||
530 | { | ||
531 | |||
532 | OpenSim.Framework.Console.MainLog.Instance.Verbose( "World.cs:AddViewerAgent() - Creating new avatar for remote viewer agent"); | ||
533 | newAvatar = new ScenePresence(remoteClient, this, this.m_regInfo); | ||
534 | OpenSim.Framework.Console.MainLog.Instance.Verbose( "World.cs:AddViewerAgent() - Adding new avatar to world"); | ||
535 | OpenSim.Framework.Console.MainLog.Instance.Verbose( "World.cs:AddViewerAgent() - Starting RegionHandshake "); | ||
536 | |||
537 | //newAvatar.SendRegionHandshake(); | ||
538 | this.estateManager.sendRegionHandshake(remoteClient); | ||
539 | |||
540 | PhysicsVector pVec = new PhysicsVector(newAvatar.Pos.X, newAvatar.Pos.Y, newAvatar.Pos.Z); | ||
541 | lock (this.m_syncRoot) | ||
542 | { | ||
543 | newAvatar.PhysActor = this.phyScene.AddAvatar(pVec); | ||
544 | } | ||
545 | |||
546 | lock (Entities) | ||
547 | { | ||
548 | if (!Entities.ContainsKey(agentID)) | ||
549 | { | ||
550 | this.Entities.Add(agentID, newAvatar); | ||
551 | } | ||
552 | else | ||
553 | { | ||
554 | Entities[agentID] = newAvatar; | ||
555 | } | ||
556 | } | ||
557 | lock (Avatars) | ||
558 | { | ||
559 | if (Avatars.ContainsKey(agentID)) | ||
560 | { | ||
561 | Avatars[agentID] = newAvatar; | ||
562 | } | ||
563 | else | ||
564 | { | ||
565 | this.Avatars.Add(agentID, newAvatar); | ||
566 | } | ||
567 | } | ||
568 | } | ||
569 | catch (Exception e) | ||
570 | { | ||
571 | OpenSim.Framework.Console.MainLog.Instance.Warn("World.cs: AddViewerAgent() - Failed with exception " + e.ToString()); | ||
572 | } | ||
573 | return; | ||
574 | } | ||
575 | |||
576 | |||
577 | |||
578 | /// <summary> | ||
579 | /// | ||
580 | /// </summary> | ||
581 | /// <param name="agentID"></param> | ||
582 | public override void RemoveClient(LLUUID agentID) | ||
583 | { | ||
584 | eventManager.TriggerOnRemovePresence(agentID); | ||
585 | |||
586 | return; | ||
587 | } | ||
588 | #endregion | ||
589 | |||
590 | #region Request Avatars List Methods | ||
591 | //The idea is to have a group of method that return a list of avatars meeting some requirement | ||
592 | // ie it could be all Avatars within a certain range of the calling prim/avatar. | ||
593 | |||
594 | /// <summary> | ||
595 | /// Request a List of all Avatars in this World | ||
596 | /// </summary> | ||
597 | /// <returns></returns> | ||
598 | public List<ScenePresence> RequestAvatarList() | ||
599 | { | ||
600 | List<ScenePresence> result = new List<ScenePresence>(); | ||
601 | |||
602 | foreach (ScenePresence avatar in Avatars.Values) | ||
603 | { | ||
604 | result.Add(avatar); | ||
605 | } | ||
606 | |||
607 | return result; | ||
608 | } | ||
609 | |||
610 | /// <summary> | ||
611 | /// Request a filtered list of Avatars in this World | ||
612 | /// </summary> | ||
613 | /// <returns></returns> | ||
614 | public List<ScenePresence> RequestAvatarList(FilterAvatarList filter) | ||
615 | { | ||
616 | List<ScenePresence> result = new List<ScenePresence>(); | ||
617 | |||
618 | foreach (ScenePresence avatar in Avatars.Values) | ||
619 | { | ||
620 | if (filter(avatar)) | ||
621 | { | ||
622 | result.Add(avatar); | ||
623 | } | ||
624 | } | ||
625 | |||
626 | return result; | ||
627 | } | ||
628 | |||
629 | /// <summary> | ||
630 | /// Request a Avatar by UUID | ||
631 | /// </summary> | ||
632 | /// <param name="avatarID"></param> | ||
633 | /// <returns></returns> | ||
634 | public ScenePresence RequestAvatar(LLUUID avatarID) | ||
635 | { | ||
636 | if (this.Avatars.ContainsKey(avatarID)) | ||
637 | { | ||
638 | return Avatars[avatarID]; | ||
639 | } | ||
640 | return null; | ||
641 | } | ||
642 | #endregion | ||
643 | |||
644 | |||
645 | #region RegionCommsHost | ||
646 | |||
647 | /// <summary> | ||
648 | /// | ||
649 | /// </summary> | ||
650 | public void RegisterRegionWithComms() | ||
651 | { | ||
652 | GridInfo gridSettings = new GridInfo(); | ||
653 | this.regionCommsHost = this.commsManager.GridServer.RegisterRegion(this.m_regInfo,gridSettings); | ||
654 | if (this.regionCommsHost != null) | ||
655 | { | ||
656 | this.regionCommsHost.OnExpectUser += new ExpectUserDelegate(this.NewUserConnection); | ||
657 | this.regionCommsHost.OnAvatarCrossingIntoRegion += new AgentCrossing(this.AgentCrossing); | ||
658 | } | ||
659 | } | ||
660 | |||
661 | /// <summary> | ||
662 | /// | ||
663 | /// </summary> | ||
664 | /// <param name="regionHandle"></param> | ||
665 | /// <param name="agent"></param> | ||
666 | public void NewUserConnection(ulong regionHandle, AgentCircuitData agent) | ||
667 | { | ||
668 | // Console.WriteLine("World.cs - add new user connection"); | ||
669 | //should just check that its meant for this region | ||
670 | if (regionHandle == this.m_regInfo.RegionHandle) | ||
671 | { | ||
672 | if (agent.CapsPath != "") | ||
673 | { | ||
674 | //Console.WriteLine("new user, so creating caps handler for it"); | ||
675 | Capabilities.Caps cap = new Capabilities.Caps(this.assetCache, httpListener, this.m_regInfo.CommsIPListenAddr, 9000, agent.CapsPath, agent.AgentID); | ||
676 | cap.RegisterHandlers(); | ||
677 | this.capsHandlers.Add(agent.AgentID, cap); | ||
678 | } | ||
679 | this.authenticateHandler.AddNewCircuit(agent.circuitcode, agent); | ||
680 | } | ||
681 | } | ||
682 | |||
683 | public void AgentCrossing(ulong regionHandle, libsecondlife.LLUUID agentID, libsecondlife.LLVector3 position) | ||
684 | { | ||
685 | if (regionHandle == this.m_regInfo.RegionHandle) | ||
686 | { | ||
687 | if (this.Avatars.ContainsKey(agentID)) | ||
688 | { | ||
689 | this.Avatars[agentID].MakeAvatar(position); | ||
690 | } | ||
691 | } | ||
692 | } | ||
693 | |||
694 | /// <summary> | ||
695 | /// | ||
696 | /// </summary> | ||
697 | public void InformClientOfNeighbours(IClientAPI remoteClient) | ||
698 | { | ||
699 | // Console.WriteLine("informing client of neighbouring regions"); | ||
700 | List<RegionInfo> neighbours = this.commsManager.GridServer.RequestNeighbours(this.m_regInfo); | ||
701 | |||
702 | //Console.WriteLine("we have " + neighbours.Count + " neighbouring regions"); | ||
703 | if (neighbours != null) | ||
704 | { | ||
705 | for (int i = 0; i < neighbours.Count; i++) | ||
706 | { | ||
707 | // Console.WriteLine("sending neighbours data"); | ||
708 | AgentCircuitData agent = remoteClient.RequestClientInfo(); | ||
709 | agent.BaseFolder = LLUUID.Zero; | ||
710 | agent.InventoryFolder = LLUUID.Zero; | ||
711 | agent.startpos = new LLVector3(128, 128, 70); | ||
712 | agent.child = true; | ||
713 | this.commsManager.InterRegion.InformRegionOfChildAgent(neighbours[i].RegionHandle, agent); | ||
714 | remoteClient.InformClientOfNeighbour(neighbours[i].RegionHandle, System.Net.IPAddress.Parse(neighbours[i].CommsIPListenAddr), (ushort)neighbours[i].CommsIPListenPort); | ||
715 | //this.capsHandlers[remoteClient.AgentId].CreateEstablishAgentComms("", System.Net.IPAddress.Parse(neighbours[i].CommsIPListenAddr) + ":" + neighbours[i].CommsIPListenPort); | ||
716 | } | ||
717 | } | ||
718 | } | ||
719 | |||
720 | /// <summary> | ||
721 | /// | ||
722 | /// </summary> | ||
723 | /// <param name="regionHandle"></param> | ||
724 | /// <returns></returns> | ||
725 | public RegionInfo RequestNeighbouringRegionInfo(ulong regionHandle) | ||
726 | { | ||
727 | return this.commsManager.GridServer.RequestNeighbourInfo(regionHandle); | ||
728 | } | ||
729 | |||
730 | /// <summary> | ||
731 | /// | ||
732 | /// </summary> | ||
733 | /// <param name="minX"></param> | ||
734 | /// <param name="minY"></param> | ||
735 | /// <param name="maxX"></param> | ||
736 | /// <param name="maxY"></param> | ||
737 | public void RequestMapBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY) | ||
738 | { | ||
739 | List<MapBlockData> mapBlocks; | ||
740 | mapBlocks = this.commsManager.GridServer.RequestNeighbourMapBlocks(minX, minY, maxX, maxY); | ||
741 | remoteClient.SendMapBlock(mapBlocks); | ||
742 | } | ||
743 | |||
744 | /// <summary> | ||
745 | /// | ||
746 | /// </summary> | ||
747 | /// <param name="remoteClient"></param> | ||
748 | /// <param name="RegionHandle"></param> | ||
749 | /// <param name="position"></param> | ||
750 | /// <param name="lookAt"></param> | ||
751 | /// <param name="flags"></param> | ||
752 | public void RequestTeleportLocation(IClientAPI remoteClient, ulong regionHandle, LLVector3 position, LLVector3 lookAt, uint flags) | ||
753 | { | ||
754 | if (regionHandle == this.m_regionHandle) | ||
755 | { | ||
756 | if (this.Avatars.ContainsKey(remoteClient.AgentId)) | ||
757 | { | ||
758 | remoteClient.SendTeleportLocationStart(); | ||
759 | remoteClient.SendLocalTeleport(position, lookAt, flags); | ||
760 | this.Avatars[remoteClient.AgentId].Teleport(position); | ||
761 | } | ||
762 | } | ||
763 | else | ||
764 | { | ||
765 | RegionInfo reg = this.RequestNeighbouringRegionInfo(regionHandle); | ||
766 | if (reg != null) | ||
767 | { | ||
768 | remoteClient.SendTeleportLocationStart(); | ||
769 | AgentCircuitData agent = remoteClient.RequestClientInfo(); | ||
770 | agent.BaseFolder = LLUUID.Zero; | ||
771 | agent.InventoryFolder = LLUUID.Zero; | ||
772 | agent.startpos = new LLVector3(128, 128, 70); | ||
773 | agent.child = true; | ||
774 | this.commsManager.InterRegion.InformRegionOfChildAgent(regionHandle, agent); | ||
775 | this.commsManager.InterRegion.ExpectAvatarCrossing(regionHandle, remoteClient.AgentId, position); | ||
776 | remoteClient.SendRegionTeleport(regionHandle, 13, reg.CommsIPListenAddr, (ushort)reg.CommsIPListenPort, 4, (1 << 4)); | ||
777 | } | ||
778 | //remoteClient.SendTeleportCancel(); | ||
779 | } | ||
780 | } | ||
781 | |||
782 | /// <summary> | ||
783 | /// | ||
784 | /// </summary> | ||
785 | /// <param name="regionhandle"></param> | ||
786 | /// <param name="agentID"></param> | ||
787 | /// <param name="position"></param> | ||
788 | public bool InformNeighbourOfCrossing(ulong regionhandle, LLUUID agentID, LLVector3 position) | ||
789 | { | ||
790 | return this.commsManager.InterRegion.ExpectAvatarCrossing(regionhandle, agentID, position); | ||
791 | } | ||
792 | |||
793 | #endregion | ||
794 | } | ||
795 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/SceneBase.cs b/OpenSim/Region/Environment/Scenes/SceneBase.cs new file mode 100644 index 0000000..3d8f522 --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/SceneBase.cs | |||
@@ -0,0 +1,201 @@ | |||
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.Inventory; | ||
40 | using OpenSim.Region.Environment.Scripting; | ||
41 | using OpenSim.Region.Terrain; | ||
42 | using OpenSim.Region.Caches; | ||
43 | |||
44 | namespace OpenSim.Region.Environment.Scenes | ||
45 | { | ||
46 | public abstract class SceneBase : IWorld | ||
47 | { | ||
48 | public Dictionary<libsecondlife.LLUUID, Entity> Entities; | ||
49 | protected Dictionary<uint, IClientAPI> m_clientThreads; | ||
50 | protected ulong m_regionHandle; | ||
51 | protected string m_regionName; | ||
52 | protected RegionInfo m_regInfo; | ||
53 | |||
54 | public TerrainEngine Terrain; | ||
55 | |||
56 | public string m_datastore; | ||
57 | public ILocalStorage localStorage; | ||
58 | |||
59 | protected object m_syncRoot = new object(); | ||
60 | private uint m_nextLocalId = 8880000; | ||
61 | protected AssetCache assetCache; | ||
62 | |||
63 | #region Update Methods | ||
64 | /// <summary> | ||
65 | /// Normally called once every frame/tick to let the world preform anything required (like running the physics simulation) | ||
66 | /// </summary> | ||
67 | public abstract void Update(); | ||
68 | |||
69 | #endregion | ||
70 | |||
71 | #region Terrain Methods | ||
72 | |||
73 | /// <summary> | ||
74 | /// Loads the World heightmap | ||
75 | /// </summary> | ||
76 | public abstract void LoadWorldMap(); | ||
77 | |||
78 | /// <summary> | ||
79 | /// Loads a new storage subsystem from a named library | ||
80 | /// </summary> | ||
81 | /// <param name="dllName">Storage Library</param> | ||
82 | /// <returns>Successful or not</returns> | ||
83 | public bool LoadStorageDLL(string dllName) | ||
84 | { | ||
85 | try | ||
86 | { | ||
87 | Assembly pluginAssembly = Assembly.LoadFrom(dllName); | ||
88 | ILocalStorage store = null; | ||
89 | |||
90 | foreach (Type pluginType in pluginAssembly.GetTypes()) | ||
91 | { | ||
92 | if (pluginType.IsPublic) | ||
93 | { | ||
94 | if (!pluginType.IsAbstract) | ||
95 | { | ||
96 | Type typeInterface = pluginType.GetInterface("ILocalStorage", true); | ||
97 | |||
98 | if (typeInterface != null) | ||
99 | { | ||
100 | ILocalStorage plug = (ILocalStorage)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); | ||
101 | store = plug; | ||
102 | |||
103 | store.Initialise(this.m_datastore); | ||
104 | break; | ||
105 | } | ||
106 | |||
107 | typeInterface = null; | ||
108 | } | ||
109 | } | ||
110 | } | ||
111 | pluginAssembly = null; | ||
112 | this.localStorage = store; | ||
113 | return (store == null); | ||
114 | } | ||
115 | catch (Exception e) | ||
116 | { | ||
117 | OpenSim.Framework.Console.MainLog.Instance.Warn("World.cs: LoadStorageDLL() - Failed with exception " + e.ToString()); | ||
118 | return false; | ||
119 | } | ||
120 | } | ||
121 | |||
122 | |||
123 | /// <summary> | ||
124 | /// Send the region heightmap to the client | ||
125 | /// </summary> | ||
126 | /// <param name="RemoteClient">Client to send to</param> | ||
127 | public virtual void SendLayerData(IClientAPI RemoteClient) | ||
128 | { | ||
129 | RemoteClient.SendLayerData(Terrain.getHeights1D()); | ||
130 | } | ||
131 | |||
132 | /// <summary> | ||
133 | /// Sends a specified patch to a client | ||
134 | /// </summary> | ||
135 | /// <param name="px">Patch coordinate (x) 0..16</param> | ||
136 | /// <param name="py">Patch coordinate (y) 0..16</param> | ||
137 | /// <param name="RemoteClient">The client to send to</param> | ||
138 | public virtual void SendLayerData(int px, int py, IClientAPI RemoteClient) | ||
139 | { | ||
140 | RemoteClient.SendLayerData(px, py, Terrain.getHeights1D()); | ||
141 | } | ||
142 | |||
143 | #endregion | ||
144 | |||
145 | #region Add/Remove Agent/Avatar | ||
146 | /// <summary> | ||
147 | /// | ||
148 | /// </summary> | ||
149 | /// <param name="remoteClient"></param> | ||
150 | /// <param name="agentID"></param> | ||
151 | /// <param name="child"></param> | ||
152 | public abstract void AddNewClient(IClientAPI remoteClient, LLUUID agentID, bool child); | ||
153 | |||
154 | /// <summary> | ||
155 | /// | ||
156 | /// </summary> | ||
157 | /// <param name="agentID"></param> | ||
158 | public abstract void RemoveClient(LLUUID agentID); | ||
159 | |||
160 | #endregion | ||
161 | |||
162 | /// <summary> | ||
163 | /// | ||
164 | /// </summary> | ||
165 | /// <returns></returns> | ||
166 | public virtual RegionInfo RegionInfo | ||
167 | { | ||
168 | get { return this.m_regInfo; } | ||
169 | } | ||
170 | |||
171 | public object SyncRoot | ||
172 | { | ||
173 | get { return m_syncRoot; } | ||
174 | } | ||
175 | |||
176 | public uint NextLocalId | ||
177 | { | ||
178 | get { return m_nextLocalId++; } | ||
179 | } | ||
180 | |||
181 | #region Shutdown | ||
182 | /// <summary> | ||
183 | /// Tidy before shutdown | ||
184 | /// </summary> | ||
185 | public virtual void Close() | ||
186 | { | ||
187 | try | ||
188 | { | ||
189 | this.localStorage.ShutDown(); | ||
190 | } | ||
191 | catch (Exception e) | ||
192 | { | ||
193 | OpenSim.Framework.Console.MainLog.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH, "World.cs: Close() - Failed with exception " + e.ToString()); | ||
194 | } | ||
195 | } | ||
196 | |||
197 | #endregion | ||
198 | |||
199 | |||
200 | } | ||
201 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/SceneEvents.cs b/OpenSim/Region/Environment/Scenes/SceneEvents.cs new file mode 100644 index 0000000..fa1bacb --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/SceneEvents.cs | |||
@@ -0,0 +1,52 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.Region.Environment.Scenes | ||
6 | { | ||
7 | /// <summary> | ||
8 | /// A class for triggering remote scene events. | ||
9 | /// </summary> | ||
10 | public class EventManager | ||
11 | { | ||
12 | public delegate void OnFrameDelegate(); | ||
13 | public event OnFrameDelegate OnFrame; | ||
14 | |||
15 | public delegate void OnNewPresenceDelegate(ScenePresence presence); | ||
16 | public event OnNewPresenceDelegate OnNewPresence; | ||
17 | |||
18 | public delegate void OnNewPrimitiveDelegate(Primitive prim); | ||
19 | public event OnNewPrimitiveDelegate OnNewPrimitive; | ||
20 | |||
21 | public delegate void OnRemovePresenceDelegate(libsecondlife.LLUUID uuid); | ||
22 | public event OnRemovePresenceDelegate OnRemovePresence; | ||
23 | |||
24 | public void TriggerOnFrame() | ||
25 | { | ||
26 | if (OnFrame != null) | ||
27 | { | ||
28 | OnFrame(); | ||
29 | } | ||
30 | } | ||
31 | |||
32 | public void TriggerOnNewPrimitive(Primitive prim) | ||
33 | { | ||
34 | if (OnNewPrimitive != null) | ||
35 | OnNewPrimitive(prim); | ||
36 | } | ||
37 | |||
38 | public void TriggerOnNewPresence(ScenePresence presence) | ||
39 | { | ||
40 | if (OnNewPresence != null) | ||
41 | OnNewPresence(presence); | ||
42 | } | ||
43 | |||
44 | public void TriggerOnRemovePresence(libsecondlife.LLUUID uuid) | ||
45 | { | ||
46 | if (OnRemovePresence != null) | ||
47 | { | ||
48 | OnRemovePresence(uuid); | ||
49 | } | ||
50 | } | ||
51 | } | ||
52 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/SceneObject.cs b/OpenSim/Region/Environment/Scenes/SceneObject.cs new file mode 100644 index 0000000..88fb160 --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/SceneObject.cs | |||
@@ -0,0 +1,128 @@ | |||
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 System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using libsecondlife; | ||
32 | using libsecondlife.Packets; | ||
33 | using OpenSim.Framework.Interfaces; | ||
34 | using OpenSim.Physics.Manager; | ||
35 | using OpenSim.Framework.Types; | ||
36 | using OpenSim.Framework.Inventory; | ||
37 | |||
38 | namespace OpenSim.Region.Environment.Scenes | ||
39 | { | ||
40 | public class SceneObject : Entity | ||
41 | { | ||
42 | private LLUUID rootUUID; | ||
43 | //private Dictionary<LLUUID, Primitive> ChildPrimitives = new Dictionary<LLUUID, Primitive>(); | ||
44 | protected Primitive rootPrimitive; | ||
45 | private Scene m_world; | ||
46 | protected ulong regionHandle; | ||
47 | |||
48 | /// <summary> | ||
49 | /// | ||
50 | /// </summary> | ||
51 | public SceneObject() | ||
52 | { | ||
53 | |||
54 | } | ||
55 | |||
56 | /// <summary> | ||
57 | /// | ||
58 | /// </summary> | ||
59 | /// <param name="addPacket"></param> | ||
60 | /// <param name="agentID"></param> | ||
61 | /// <param name="localID"></param> | ||
62 | public void CreateFromPacket(ObjectAddPacket addPacket, LLUUID agentID, uint localID) | ||
63 | { | ||
64 | this.rootPrimitive = new Primitive( this.regionHandle, this.m_world, addPacket, agentID, localID); | ||
65 | } | ||
66 | |||
67 | /// <summary> | ||
68 | /// | ||
69 | /// </summary> | ||
70 | /// <param name="data"></param> | ||
71 | public void CreateFromBytes(byte[] data) | ||
72 | { | ||
73 | |||
74 | } | ||
75 | |||
76 | /// <summary> | ||
77 | /// | ||
78 | /// </summary> | ||
79 | public override void update() | ||
80 | { | ||
81 | |||
82 | } | ||
83 | |||
84 | /// <summary> | ||
85 | /// | ||
86 | /// </summary> | ||
87 | public override void BackUp() | ||
88 | { | ||
89 | |||
90 | } | ||
91 | |||
92 | /// <summary> | ||
93 | /// | ||
94 | /// </summary> | ||
95 | /// <param name="client"></param> | ||
96 | public void GetProperites(IClientAPI client) | ||
97 | { | ||
98 | //needs changing | ||
99 | ObjectPropertiesPacket proper = new ObjectPropertiesPacket(); | ||
100 | proper.ObjectData = new ObjectPropertiesPacket.ObjectDataBlock[1]; | ||
101 | proper.ObjectData[0] = new ObjectPropertiesPacket.ObjectDataBlock(); | ||
102 | proper.ObjectData[0].ItemID = LLUUID.Zero; | ||
103 | proper.ObjectData[0].CreationDate = (ulong)this.rootPrimitive.primData.CreationDate; | ||
104 | proper.ObjectData[0].CreatorID = this.rootPrimitive.primData.OwnerID; | ||
105 | proper.ObjectData[0].FolderID = LLUUID.Zero; | ||
106 | proper.ObjectData[0].FromTaskID = LLUUID.Zero; | ||
107 | proper.ObjectData[0].GroupID = LLUUID.Zero; | ||
108 | proper.ObjectData[0].InventorySerial = 0; | ||
109 | proper.ObjectData[0].LastOwnerID = LLUUID.Zero; | ||
110 | proper.ObjectData[0].ObjectID = this.uuid; | ||
111 | proper.ObjectData[0].OwnerID = this.rootPrimitive.primData.OwnerID; | ||
112 | proper.ObjectData[0].TouchName = new byte[0]; | ||
113 | proper.ObjectData[0].TextureID = new byte[0]; | ||
114 | proper.ObjectData[0].SitName = new byte[0]; | ||
115 | proper.ObjectData[0].Name = new byte[0]; | ||
116 | proper.ObjectData[0].Description = new byte[0]; | ||
117 | proper.ObjectData[0].OwnerMask = this.rootPrimitive.primData.OwnerMask; | ||
118 | proper.ObjectData[0].NextOwnerMask = this.rootPrimitive.primData.NextOwnerMask; | ||
119 | proper.ObjectData[0].GroupMask = this.rootPrimitive.primData.GroupMask; | ||
120 | proper.ObjectData[0].EveryoneMask = this.rootPrimitive.primData.EveryoneMask; | ||
121 | proper.ObjectData[0].BaseMask = this.rootPrimitive.primData.BaseMask; | ||
122 | |||
123 | client.OutPacket(proper); | ||
124 | |||
125 | } | ||
126 | |||
127 | } | ||
128 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.Animations.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.Animations.cs new file mode 100644 index 0000000..2caabc2 --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/ScenePresence.Animations.cs | |||
@@ -0,0 +1,76 @@ | |||
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 System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using libsecondlife; | ||
32 | using System.Xml; | ||
33 | |||
34 | namespace OpenSim.Region.Environment.Scenes | ||
35 | { | ||
36 | partial class ScenePresence | ||
37 | { | ||
38 | public class AvatarAnimations | ||
39 | { | ||
40 | |||
41 | public Dictionary<string, LLUUID> AnimsLLUUID = new Dictionary<string, LLUUID>(); | ||
42 | public Dictionary<LLUUID, string> AnimsNames = new Dictionary<LLUUID, string>(); | ||
43 | |||
44 | public AvatarAnimations() | ||
45 | { | ||
46 | } | ||
47 | |||
48 | public void LoadAnims() | ||
49 | { | ||
50 | //OpenSim.Framework.Console.MainLog.Instance.Verbose("Avatar.cs:LoadAnims() - Loading avatar animations"); | ||
51 | XmlTextReader reader = new XmlTextReader("data/avataranimations.xml"); | ||
52 | |||
53 | XmlDocument doc = new XmlDocument(); | ||
54 | doc.Load(reader); | ||
55 | foreach (XmlNode nod in doc.DocumentElement.ChildNodes) | ||
56 | { | ||
57 | |||
58 | if (nod.Attributes["name"] != null) | ||
59 | { | ||
60 | AnimsLLUUID.Add(nod.Attributes["name"].Value, nod.InnerText); | ||
61 | } | ||
62 | |||
63 | } | ||
64 | |||
65 | reader.Close(); | ||
66 | |||
67 | // OpenSim.Framework.Console.MainLog.Instance.Verbose("Loaded " + AnimsLLUUID.Count.ToString() + " animation(s)"); | ||
68 | |||
69 | foreach (KeyValuePair<string, LLUUID> kp in OpenSim.Region.Environment.Scenes.ScenePresence.Animations.AnimsLLUUID) | ||
70 | { | ||
71 | AnimsNames.Add(kp.Value, kp.Key); | ||
72 | } | ||
73 | } | ||
74 | } | ||
75 | } | ||
76 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.Body.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.Body.cs new file mode 100644 index 0000000..2c81d2a --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/ScenePresence.Body.cs | |||
@@ -0,0 +1,90 @@ | |||
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 System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using libsecondlife; | ||
32 | using libsecondlife.Packets; | ||
33 | using OpenSim.Physics.Manager; | ||
34 | using OpenSim.Framework.Interfaces; | ||
35 | using OpenSim.Framework.Types; | ||
36 | |||
37 | namespace OpenSim.Region.Environment.Scenes | ||
38 | { | ||
39 | partial class ScenePresence | ||
40 | { | ||
41 | public class Avatar : IScenePresenceBody | ||
42 | { | ||
43 | public Avatar() | ||
44 | { | ||
45 | |||
46 | } | ||
47 | |||
48 | public void processMovement(IClientAPI remoteClient, uint flags, LLQuaternion bodyRotation) | ||
49 | { | ||
50 | } | ||
51 | |||
52 | public void SetAppearance(byte[] texture, AgentSetAppearancePacket.VisualParamBlock[] visualParam) | ||
53 | { | ||
54 | } | ||
55 | |||
56 | public void SendOurAppearance(IClientAPI OurClient) | ||
57 | { | ||
58 | } | ||
59 | |||
60 | public void SendAppearanceToOtherAgent(ScenePresence avatarInfo) | ||
61 | { | ||
62 | } | ||
63 | } | ||
64 | |||
65 | public class ChildAgent : IScenePresenceBody //is a ghost | ||
66 | { | ||
67 | public ChildAgent() | ||
68 | { | ||
69 | |||
70 | } | ||
71 | |||
72 | public void processMovement(IClientAPI remoteClient, uint flags, LLQuaternion bodyRotation) | ||
73 | { | ||
74 | } | ||
75 | |||
76 | public void SetAppearance(byte[] texture, AgentSetAppearancePacket.VisualParamBlock[] visualParam) | ||
77 | { | ||
78 | } | ||
79 | |||
80 | public void SendOurAppearance(IClientAPI OurClient) | ||
81 | { | ||
82 | } | ||
83 | |||
84 | public void SendAppearanceToOtherAgent(ScenePresence avatarInfo) | ||
85 | { | ||
86 | } | ||
87 | } | ||
88 | } | ||
89 | |||
90 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.cs new file mode 100644 index 0000000..96e5c94 --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/ScenePresence.cs | |||
@@ -0,0 +1,525 @@ | |||
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 System.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Text; | ||
32 | using libsecondlife; | ||
33 | using libsecondlife.Packets; | ||
34 | using OpenSim.Physics.Manager; | ||
35 | using OpenSim.Framework.Inventory; | ||
36 | using OpenSim.Framework.Interfaces; | ||
37 | using OpenSim.Framework.Types; | ||
38 | using Axiom.MathLib; | ||
39 | |||
40 | namespace OpenSim.Region.Environment.Scenes | ||
41 | { | ||
42 | public partial class ScenePresence : Entity | ||
43 | { | ||
44 | public static bool PhysicsEngineFlying = false; | ||
45 | public static AvatarAnimations Animations; | ||
46 | public static byte[] DefaultTexture; | ||
47 | public string firstname; | ||
48 | public string lastname; | ||
49 | public IClientAPI ControllingClient; | ||
50 | public LLUUID current_anim; | ||
51 | public int anim_seq; | ||
52 | private bool updateflag = false; | ||
53 | private byte movementflag = 0; | ||
54 | private List<NewForce> forcesList = new List<NewForce>(); | ||
55 | private short _updateCount = 0; | ||
56 | private Axiom.MathLib.Quaternion bodyRot; | ||
57 | private LLObject.TextureEntry avatarAppearanceTexture = null; | ||
58 | private byte[] visualParams; | ||
59 | private AvatarWearable[] Wearables; | ||
60 | private LLVector3 positionLastFrame = new LLVector3(0, 0, 0); | ||
61 | private ulong m_regionHandle; | ||
62 | private bool childAgent = false; | ||
63 | private bool newForce = false; | ||
64 | private bool newAvatar = false; | ||
65 | private IScenePresenceBody m_body; | ||
66 | |||
67 | protected RegionInfo m_regionInfo; | ||
68 | |||
69 | #region Properties | ||
70 | /// <summary> | ||
71 | /// | ||
72 | /// </summary> | ||
73 | public PhysicsActor PhysActor | ||
74 | { | ||
75 | set | ||
76 | { | ||
77 | this._physActor = value; | ||
78 | } | ||
79 | get | ||
80 | { | ||
81 | return _physActor; | ||
82 | } | ||
83 | } | ||
84 | #endregion | ||
85 | |||
86 | #region Constructor(s) | ||
87 | /// <summary> | ||
88 | /// | ||
89 | /// </summary> | ||
90 | /// <param name="theClient"></param> | ||
91 | /// <param name="world"></param> | ||
92 | /// <param name="clientThreads"></param> | ||
93 | /// <param name="regionDat"></param> | ||
94 | public ScenePresence(IClientAPI theClient, Scene world, RegionInfo reginfo) | ||
95 | { | ||
96 | |||
97 | m_world = world; | ||
98 | this.uuid = theClient.AgentId; | ||
99 | |||
100 | m_regionInfo = reginfo; | ||
101 | m_regionHandle = reginfo.RegionHandle; | ||
102 | OpenSim.Framework.Console.MainLog.Instance.Verbose("Avatar.cs "); | ||
103 | ControllingClient = theClient; | ||
104 | this.firstname = ControllingClient.FirstName; | ||
105 | this.lastname = ControllingClient.LastName; | ||
106 | m_localId = m_world.NextLocalId; | ||
107 | Pos = ControllingClient.StartPos; | ||
108 | visualParams = new byte[218]; | ||
109 | for (int i = 0; i < 218; i++) | ||
110 | { | ||
111 | visualParams[i] = 100; | ||
112 | } | ||
113 | |||
114 | Wearables = AvatarWearable.DefaultWearables; | ||
115 | |||
116 | this.avatarAppearanceTexture = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005")); | ||
117 | |||
118 | //register for events | ||
119 | ControllingClient.OnRequestWearables += this.SendOurAppearance; | ||
120 | //ControllingClient.OnSetAppearance += new SetAppearance(this.SetAppearance); | ||
121 | ControllingClient.OnCompleteMovementToRegion += this.CompleteMovement; | ||
122 | ControllingClient.OnCompleteMovementToRegion += this.SendInitialData; | ||
123 | ControllingClient.OnAgentUpdate += this.HandleAgentUpdate; | ||
124 | // ControllingClient.OnStartAnim += new StartAnim(this.SendAnimPack); | ||
125 | // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange); | ||
126 | //ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement); | ||
127 | |||
128 | } | ||
129 | #endregion | ||
130 | |||
131 | #region Status Methods | ||
132 | /// <summary> | ||
133 | /// Not Used, most likely can be deleted | ||
134 | /// </summary> | ||
135 | /// <param name="status"></param> | ||
136 | public void ChildStatusChange(bool status) | ||
137 | { | ||
138 | this.childAgent = status; | ||
139 | |||
140 | if (this.childAgent == true) | ||
141 | { | ||
142 | this.Velocity = new LLVector3(0, 0, 0); | ||
143 | this.Pos = new LLVector3(128, 128, 70); | ||
144 | |||
145 | } | ||
146 | } | ||
147 | |||
148 | /// <summary> | ||
149 | /// | ||
150 | /// </summary> | ||
151 | /// <param name="pos"></param> | ||
152 | public void MakeAvatar(LLVector3 pos) | ||
153 | { | ||
154 | //this.childAvatar = false; | ||
155 | this.Pos = pos; | ||
156 | this.newAvatar = true; | ||
157 | this.childAgent = false; | ||
158 | } | ||
159 | |||
160 | protected void MakeChildAgent() | ||
161 | { | ||
162 | this.Velocity = new LLVector3(0, 0, 0); | ||
163 | this.Pos = new LLVector3(128, 128, 70); | ||
164 | this.childAgent = true; | ||
165 | } | ||
166 | |||
167 | /// <summary> | ||
168 | /// | ||
169 | /// </summary> | ||
170 | /// <param name="pos"></param> | ||
171 | public void Teleport(LLVector3 pos) | ||
172 | { | ||
173 | this.Pos = pos; | ||
174 | this.SendTerseUpdateToALLClients(); | ||
175 | } | ||
176 | |||
177 | /// <summary> | ||
178 | /// | ||
179 | /// </summary> | ||
180 | public void StopMovement() | ||
181 | { | ||
182 | |||
183 | } | ||
184 | #endregion | ||
185 | |||
186 | #region Event Handlers | ||
187 | /// <summary> | ||
188 | /// | ||
189 | /// </summary> | ||
190 | /// <param name="texture"></param> | ||
191 | /// <param name="visualParam"></param> | ||
192 | public void SetAppearance(byte[] texture, AgentSetAppearancePacket.VisualParamBlock[] visualParam) | ||
193 | { | ||
194 | |||
195 | } | ||
196 | |||
197 | /// <summary> | ||
198 | /// Complete Avatar's movement into the region | ||
199 | /// </summary> | ||
200 | public void CompleteMovement() | ||
201 | { | ||
202 | LLVector3 look = this.Velocity; | ||
203 | if ((look.X == 0) && (look.Y == 0) && (look.Z == 0)) | ||
204 | { | ||
205 | look = new LLVector3(0.99f, 0.042f, 0); | ||
206 | } | ||
207 | this.ControllingClient.MoveAgentIntoRegion(m_regionInfo, Pos, look); | ||
208 | if (this.childAgent) | ||
209 | { | ||
210 | this.childAgent = false; | ||
211 | } | ||
212 | } | ||
213 | |||
214 | /// <summary> | ||
215 | /// | ||
216 | /// </summary> | ||
217 | /// <param name="pack"></param> | ||
218 | public void HandleAgentUpdate(IClientAPI remoteClient, uint flags, LLQuaternion bodyRotation) | ||
219 | { | ||
220 | if ((flags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_AT_POS) != 0) | ||
221 | { | ||
222 | Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(bodyRotation.W, bodyRotation.X, bodyRotation.Y, bodyRotation.Z); | ||
223 | if (((movementflag & 1) == 0) || (q != this.bodyRot)) | ||
224 | { | ||
225 | Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(1, 0, 0); | ||
226 | this.AddNewMovement(v3, q); | ||
227 | movementflag = 1; | ||
228 | this.bodyRot = q; | ||
229 | } | ||
230 | } | ||
231 | else if ((flags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_AT_NEG) != 0) | ||
232 | { | ||
233 | Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(bodyRotation.W, bodyRotation.X, bodyRotation.Y, bodyRotation.Z); | ||
234 | if (((movementflag & 2) == 0) || (q != this.bodyRot)) | ||
235 | { | ||
236 | Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(-1, 0, 0); | ||
237 | this.AddNewMovement(v3, q); | ||
238 | movementflag = 2; | ||
239 | this.bodyRot = q; | ||
240 | } | ||
241 | } | ||
242 | else | ||
243 | { | ||
244 | if ((movementflag) != 0) | ||
245 | { | ||
246 | NewForce newVelocity = new NewForce(); | ||
247 | newVelocity.X = 0; | ||
248 | newVelocity.Y = 0; | ||
249 | newVelocity.Z = 0; | ||
250 | this.forcesList.Add(newVelocity); | ||
251 | movementflag = 0; | ||
252 | } | ||
253 | } | ||
254 | |||
255 | } | ||
256 | |||
257 | protected void AddNewMovement(Axiom.MathLib.Vector3 vec, Axiom.MathLib.Quaternion rotation) | ||
258 | { | ||
259 | NewForce newVelocity = new NewForce(); | ||
260 | Axiom.MathLib.Vector3 direc = rotation * vec; | ||
261 | direc.Normalize(); | ||
262 | |||
263 | direc = direc * ((0.03f) * 128f); | ||
264 | if (this._physActor.Flying) | ||
265 | direc *= 4; | ||
266 | |||
267 | newVelocity.X = direc.x; | ||
268 | newVelocity.Y = direc.y; | ||
269 | newVelocity.Z = direc.z; | ||
270 | this.forcesList.Add(newVelocity); | ||
271 | } | ||
272 | |||
273 | #endregion | ||
274 | |||
275 | #region Overridden Methods | ||
276 | /// <summary> | ||
277 | /// | ||
278 | /// </summary> | ||
279 | public override void LandRenegerated() | ||
280 | { | ||
281 | |||
282 | } | ||
283 | |||
284 | /// <summary> | ||
285 | /// | ||
286 | /// </summary> | ||
287 | public override void update() | ||
288 | { | ||
289 | if (this.childAgent == false) | ||
290 | { | ||
291 | if (this.newForce) | ||
292 | { | ||
293 | this.SendTerseUpdateToALLClients(); | ||
294 | _updateCount = 0; | ||
295 | } | ||
296 | else if (movementflag != 0) | ||
297 | { | ||
298 | _updateCount++; | ||
299 | if (_updateCount > 3) | ||
300 | { | ||
301 | this.SendTerseUpdateToALLClients(); | ||
302 | _updateCount = 0; | ||
303 | } | ||
304 | } | ||
305 | |||
306 | this.CheckForBorderCrossing(); | ||
307 | } | ||
308 | } | ||
309 | #endregion | ||
310 | |||
311 | #region Update Client(s) | ||
312 | /// <summary> | ||
313 | /// | ||
314 | /// </summary> | ||
315 | /// <param name="RemoteClient"></param> | ||
316 | public void SendTerseUpdateToClient(IClientAPI RemoteClient) | ||
317 | { | ||
318 | LLVector3 pos = this.Pos; | ||
319 | LLVector3 vel = this.Velocity; | ||
320 | RemoteClient.SendAvatarTerseUpdate(this.m_regionHandle, 64096, this.LocalId, new LLVector3(pos.X, pos.Y, pos.Z), new LLVector3(vel.X, vel.Y, vel.Z)); | ||
321 | } | ||
322 | |||
323 | /// <summary> | ||
324 | /// | ||
325 | /// </summary> | ||
326 | public void SendTerseUpdateToALLClients() | ||
327 | { | ||
328 | List<ScenePresence> avatars = this.m_world.RequestAvatarList(); | ||
329 | for (int i = 0; i < avatars.Count; i++) | ||
330 | { | ||
331 | this.SendTerseUpdateToClient(avatars[i].ControllingClient); | ||
332 | } | ||
333 | } | ||
334 | |||
335 | /// <summary> | ||
336 | /// | ||
337 | /// </summary> | ||
338 | /// <param name="remoteAvatar"></param> | ||
339 | public void SendFullUpdateToOtherClient(ScenePresence remoteAvatar) | ||
340 | { | ||
341 | remoteAvatar.ControllingClient.SendAvatarData(m_regionInfo.RegionHandle, this.firstname, this.lastname, this.uuid, this.LocalId, this.Pos, DefaultTexture); | ||
342 | } | ||
343 | |||
344 | /// <summary> | ||
345 | /// | ||
346 | /// </summary> | ||
347 | public void SendInitialData() | ||
348 | { | ||
349 | this.ControllingClient.SendAvatarData(m_regionInfo.RegionHandle, this.firstname, this.lastname, this.uuid, this.LocalId, this.Pos, DefaultTexture); | ||
350 | if (this.newAvatar) | ||
351 | { | ||
352 | this.m_world.InformClientOfNeighbours(this.ControllingClient); | ||
353 | this.newAvatar = false; | ||
354 | } | ||
355 | } | ||
356 | |||
357 | /// <summary> | ||
358 | /// | ||
359 | /// </summary> | ||
360 | /// <param name="OurClient"></param> | ||
361 | public void SendOurAppearance(IClientAPI OurClient) | ||
362 | { | ||
363 | this.ControllingClient.SendWearables(this.Wearables); | ||
364 | } | ||
365 | |||
366 | /// <summary> | ||
367 | /// | ||
368 | /// </summary> | ||
369 | /// <param name="avatarInfo"></param> | ||
370 | public void SendAppearanceToOtherAgent(ScenePresence avatarInfo) | ||
371 | { | ||
372 | |||
373 | } | ||
374 | |||
375 | /// <summary> | ||
376 | /// | ||
377 | /// </summary> | ||
378 | /// <param name="animID"></param> | ||
379 | /// <param name="seq"></param> | ||
380 | public void SendAnimPack(LLUUID animID, int seq) | ||
381 | { | ||
382 | |||
383 | |||
384 | } | ||
385 | |||
386 | /// <summary> | ||
387 | /// | ||
388 | /// </summary> | ||
389 | public void SendAnimPack() | ||
390 | { | ||
391 | |||
392 | } | ||
393 | #endregion | ||
394 | |||
395 | #region Border Crossing Methods | ||
396 | /// <summary> | ||
397 | /// | ||
398 | /// </summary> | ||
399 | protected void CheckForBorderCrossing() | ||
400 | { | ||
401 | LLVector3 pos2 = this.Pos; | ||
402 | LLVector3 vel = this.Velocity; | ||
403 | |||
404 | float timeStep = 0.2f; | ||
405 | pos2.X = pos2.X + (vel.X * timeStep); | ||
406 | pos2.Y = pos2.Y + (vel.Y * timeStep); | ||
407 | pos2.Z = pos2.Z + (vel.Z * timeStep); | ||
408 | |||
409 | if ((pos2.X < 0) || (pos2.X > 256)) | ||
410 | { | ||
411 | this.CrossToNewRegion(); | ||
412 | } | ||
413 | |||
414 | if ((pos2.Y < 0) || (pos2.Y > 256)) | ||
415 | { | ||
416 | this.CrossToNewRegion(); | ||
417 | } | ||
418 | } | ||
419 | |||
420 | /// <summary> | ||
421 | /// | ||
422 | /// </summary> | ||
423 | protected void CrossToNewRegion() | ||
424 | { | ||
425 | LLVector3 pos = this.Pos; | ||
426 | LLVector3 newpos = new LLVector3(pos.X, pos.Y, pos.Z); | ||
427 | uint neighbourx = this.m_regionInfo.RegionLocX; | ||
428 | uint neighboury = this.m_regionInfo.RegionLocY; | ||
429 | |||
430 | if (pos.X < 2) | ||
431 | { | ||
432 | neighbourx -= 1; | ||
433 | newpos.X = 254; | ||
434 | } | ||
435 | if (pos.X > 253) | ||
436 | { | ||
437 | neighbourx += 1; | ||
438 | newpos.X = 1; | ||
439 | } | ||
440 | if (pos.Y < 2) | ||
441 | { | ||
442 | neighboury -= 1; | ||
443 | newpos.Y = 254; | ||
444 | } | ||
445 | if (pos.Y > 253) | ||
446 | { | ||
447 | neighboury += 1; | ||
448 | newpos.Y = 1; | ||
449 | } | ||
450 | |||
451 | LLVector3 vel = this.velocity; | ||
452 | ulong neighbourHandle = Helpers.UIntsToLong((uint)(neighbourx * 256), (uint)(neighboury * 256)); | ||
453 | RegionInfo neighbourRegion = this.m_world.RequestNeighbouringRegionInfo(neighbourHandle); | ||
454 | if (neighbourRegion != null) | ||
455 | { | ||
456 | bool res = this.m_world.InformNeighbourOfCrossing(neighbourHandle, this.ControllingClient.AgentId, newpos); | ||
457 | if (res) | ||
458 | { | ||
459 | this.MakeChildAgent(); | ||
460 | this.ControllingClient.CrossRegion(neighbourHandle, newpos, vel, System.Net.IPAddress.Parse(neighbourRegion.CommsIPListenAddr), (ushort)neighbourRegion.CommsIPListenPort); | ||
461 | } | ||
462 | } | ||
463 | } | ||
464 | #endregion | ||
465 | |||
466 | /// <summary> | ||
467 | /// | ||
468 | /// </summary> | ||
469 | public static void LoadAnims() | ||
470 | { | ||
471 | |||
472 | } | ||
473 | |||
474 | /// <summary> | ||
475 | /// | ||
476 | /// </summary> | ||
477 | public override void updateMovement() | ||
478 | { | ||
479 | newForce = false; | ||
480 | lock (this.forcesList) | ||
481 | { | ||
482 | if (this.forcesList.Count > 0) | ||
483 | { | ||
484 | for (int i = 0; i < this.forcesList.Count; i++) | ||
485 | { | ||
486 | NewForce force = this.forcesList[i]; | ||
487 | |||
488 | this.updateflag = true; | ||
489 | this.Velocity = new LLVector3(force.X, force.Y, force.Z); | ||
490 | this.newForce = true; | ||
491 | } | ||
492 | for (int i = 0; i < this.forcesList.Count; i++) | ||
493 | { | ||
494 | this.forcesList.RemoveAt(0); | ||
495 | } | ||
496 | } | ||
497 | } | ||
498 | } | ||
499 | |||
500 | public static void LoadTextureFile(string name) | ||
501 | { | ||
502 | FileInfo fInfo = new FileInfo(name); | ||
503 | long numBytes = fInfo.Length; | ||
504 | FileStream fStream = new FileStream(name, FileMode.Open, FileAccess.Read); | ||
505 | BinaryReader br = new BinaryReader(fStream); | ||
506 | byte[] data1 = br.ReadBytes((int)numBytes); | ||
507 | br.Close(); | ||
508 | fStream.Close(); | ||
509 | DefaultTexture = data1; | ||
510 | } | ||
511 | |||
512 | public class NewForce | ||
513 | { | ||
514 | public float X; | ||
515 | public float Y; | ||
516 | public float Z; | ||
517 | |||
518 | public NewForce() | ||
519 | { | ||
520 | |||
521 | } | ||
522 | } | ||
523 | } | ||
524 | |||
525 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/scripting/IScriptContext.cs b/OpenSim/Region/Environment/Scenes/scripting/IScriptContext.cs new file mode 100644 index 0000000..eb8a117 --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/scripting/IScriptContext.cs | |||
@@ -0,0 +1,40 @@ | |||
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 System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using libsecondlife; | ||
32 | |||
33 | namespace OpenSim.Region.Environment.Scripting | ||
34 | { | ||
35 | public interface IScriptContext | ||
36 | { | ||
37 | IScriptEntity Entity { get; } | ||
38 | bool TryGetRandomAvatar(out IScriptReadonlyEntity avatar); | ||
39 | } | ||
40 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/scripting/IScriptEntity.cs b/OpenSim/Region/Environment/Scenes/scripting/IScriptEntity.cs new file mode 100644 index 0000000..e813626 --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/scripting/IScriptEntity.cs | |||
@@ -0,0 +1,46 @@ | |||
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 System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using libsecondlife; | ||
32 | |||
33 | namespace OpenSim.Region.Environment.Scripting | ||
34 | { | ||
35 | public interface IScriptReadonlyEntity | ||
36 | { | ||
37 | LLVector3 Pos { get; } | ||
38 | string Name { get; } | ||
39 | } | ||
40 | |||
41 | public interface IScriptEntity | ||
42 | { | ||
43 | LLVector3 Pos { get; set; } | ||
44 | string Name { get; } | ||
45 | } | ||
46 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/scripting/IScriptHandler.cs b/OpenSim/Region/Environment/Scenes/scripting/IScriptHandler.cs new file mode 100644 index 0000000..115b4f4 --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/scripting/IScriptHandler.cs | |||
@@ -0,0 +1,126 @@ | |||
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 System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using libsecondlife; | ||
32 | using OpenSim.Physics.Manager; | ||
33 | using OpenSim.Region.Environment; | ||
34 | using OpenSim.Region.Environment.Scenes; | ||
35 | using Avatar=OpenSim.Region.Environment.Scenes.ScenePresence; | ||
36 | using Primitive = OpenSim.Region.Environment.Scenes.Primitive; | ||
37 | |||
38 | namespace OpenSim.Region.Environment.Scripting | ||
39 | { | ||
40 | public delegate void ScriptEventHandler(IScriptContext context); | ||
41 | |||
42 | public class ScriptHandler : IScriptContext, IScriptEntity, IScriptReadonlyEntity | ||
43 | { | ||
44 | private Scene m_world; | ||
45 | private Script m_script; | ||
46 | private Entity m_entity; | ||
47 | |||
48 | public LLUUID ScriptId | ||
49 | { | ||
50 | get | ||
51 | { | ||
52 | return m_script.ScriptId; | ||
53 | } | ||
54 | } | ||
55 | |||
56 | public void OnFrame() | ||
57 | { | ||
58 | m_script.OnFrame(this); | ||
59 | } | ||
60 | |||
61 | public ScriptHandler(Script script, Entity entity, Scene world) | ||
62 | { | ||
63 | m_script = script; | ||
64 | m_entity = entity; | ||
65 | m_world = world; | ||
66 | } | ||
67 | |||
68 | #region IScriptContext Members | ||
69 | |||
70 | IScriptEntity IScriptContext.Entity | ||
71 | { | ||
72 | get | ||
73 | { | ||
74 | return this; | ||
75 | } | ||
76 | } | ||
77 | |||
78 | bool IScriptContext.TryGetRandomAvatar(out IScriptReadonlyEntity avatar) | ||
79 | { | ||
80 | foreach (Entity entity in m_world.Entities.Values ) | ||
81 | { | ||
82 | if( entity is Avatar ) | ||
83 | { | ||
84 | avatar = entity; | ||
85 | return true; | ||
86 | } | ||
87 | } | ||
88 | |||
89 | avatar = null; | ||
90 | return false; | ||
91 | } | ||
92 | |||
93 | #endregion | ||
94 | |||
95 | #region IScriptEntity and IScriptReadonlyEntity Members | ||
96 | |||
97 | public string Name | ||
98 | { | ||
99 | get | ||
100 | { | ||
101 | return m_entity.Name; | ||
102 | } | ||
103 | } | ||
104 | |||
105 | public LLVector3 Pos | ||
106 | { | ||
107 | get | ||
108 | { | ||
109 | return m_entity.Pos; | ||
110 | } | ||
111 | |||
112 | set | ||
113 | { | ||
114 | if (m_entity is Primitive) | ||
115 | { | ||
116 | Primitive prim = m_entity as Primitive; | ||
117 | // Of course, we really should have asked the physEngine if this is possible, and if not, returned false. | ||
118 | // prim.UpdatePosition( value ); | ||
119 | } | ||
120 | } | ||
121 | } | ||
122 | |||
123 | #endregion | ||
124 | } | ||
125 | |||
126 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Script.cs b/OpenSim/Region/Environment/Scenes/scripting/Script.cs new file mode 100644 index 0000000..5d398b0 --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/scripting/Script.cs | |||
@@ -0,0 +1,53 @@ | |||
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 System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using libsecondlife; | ||
32 | |||
33 | namespace OpenSim.Region.Environment.Scripting | ||
34 | { | ||
35 | public class Script | ||
36 | { | ||
37 | private LLUUID m_scriptId; | ||
38 | public virtual LLUUID ScriptId | ||
39 | { | ||
40 | get | ||
41 | { | ||
42 | return m_scriptId; | ||
43 | } | ||
44 | } | ||
45 | |||
46 | public Script( LLUUID scriptId ) | ||
47 | { | ||
48 | m_scriptId = scriptId; | ||
49 | } | ||
50 | |||
51 | public ScriptEventHandler OnFrame; | ||
52 | } | ||
53 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/scripting/ScriptFactory.cs b/OpenSim/Region/Environment/Scenes/scripting/ScriptFactory.cs new file mode 100644 index 0000000..0ce65ea --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/scripting/ScriptFactory.cs | |||
@@ -0,0 +1,35 @@ | |||
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 System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | |||
32 | namespace OpenSim.Region.Environment.Scripting | ||
33 | { | ||
34 | public delegate Script ScriptFactory(); | ||
35 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Scripts/FollowRandomAvatar.cs b/OpenSim/Region/Environment/Scenes/scripting/Scripts/FollowRandomAvatar.cs new file mode 100644 index 0000000..90c79e3 --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/scripting/Scripts/FollowRandomAvatar.cs | |||
@@ -0,0 +1,64 @@ | |||
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 System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using libsecondlife; | ||
32 | |||
33 | namespace OpenSim.Region.Environment.Scripting | ||
34 | { | ||
35 | public class FollowRandomAvatar : Script | ||
36 | { | ||
37 | public FollowRandomAvatar() | ||
38 | : base(LLUUID.Random()) | ||
39 | { | ||
40 | OnFrame += MyOnFrame; | ||
41 | } | ||
42 | |||
43 | private void MyOnFrame(IScriptContext context) | ||
44 | { | ||
45 | LLVector3 pos = context.Entity.Pos; | ||
46 | |||
47 | IScriptReadonlyEntity avatar; | ||
48 | |||
49 | if (context.TryGetRandomAvatar(out avatar)) | ||
50 | { | ||
51 | LLVector3 avatarPos = avatar.Pos; | ||
52 | |||
53 | float x = pos.X + ((float)avatarPos.X.CompareTo(pos.X)) / 2; | ||
54 | float y = pos.Y + ((float)avatarPos.Y.CompareTo(pos.Y)) / 2; | ||
55 | |||
56 | LLVector3 newPos = new LLVector3(x, y, pos.Z); | ||
57 | |||
58 | context.Entity.Pos = newPos; | ||
59 | } | ||
60 | } | ||
61 | } | ||
62 | |||
63 | |||
64 | } | ||