diff options
Diffstat (limited to '')
5 files changed, 358 insertions, 1 deletions
diff --git a/OpenSim/Framework/IClientAPI.cs b/OpenSim/Framework/IClientAPI.cs index 1678185..244a2f3 100644 --- a/OpenSim/Framework/IClientAPI.cs +++ b/OpenSim/Framework/IClientAPI.cs | |||
@@ -558,6 +558,9 @@ namespace OpenSim.Framework | |||
558 | void SendLayerData(float[] map); | 558 | void SendLayerData(float[] map); |
559 | void SendLayerData(int px, int py, float[] map); | 559 | void SendLayerData(int px, int py, float[] map); |
560 | 560 | ||
561 | void SendWindData(float[] map); | ||
562 | void SendWindData(int px, int py, float[] map); | ||
563 | |||
561 | void MoveAgentIntoRegion(RegionInfo regInfo, Vector3 pos, Vector3 look); | 564 | void MoveAgentIntoRegion(RegionInfo regInfo, Vector3 pos, Vector3 look); |
562 | void InformClientOfNeighbour(ulong neighbourHandle, IPEndPoint neighbourExternalEndPoint); | 565 | void InformClientOfNeighbour(ulong neighbourHandle, IPEndPoint neighbourExternalEndPoint); |
563 | AgentCircuitData RequestClientInfo(); | 566 | AgentCircuitData RequestClientInfo(); |
diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index 983e1a9..3a90cff 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs | |||
@@ -1219,8 +1219,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1219 | 1219 | ||
1220 | LayerDataPacket layerpack = TerrainCompressor.CreateLandPacket(map, patches); | 1220 | LayerDataPacket layerpack = TerrainCompressor.CreateLandPacket(map, patches); |
1221 | layerpack.Header.Zerocoded = true; | 1221 | layerpack.Header.Zerocoded = true; |
1222 | 1222 | ||
1223 | OutPacket(layerpack, ThrottleOutPacketType.Land); | 1223 | OutPacket(layerpack, ThrottleOutPacketType.Land); |
1224 | |||
1224 | } | 1225 | } |
1225 | catch (Exception e) | 1226 | catch (Exception e) |
1226 | { | 1227 | { |
@@ -1229,6 +1230,96 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
1229 | } | 1230 | } |
1230 | 1231 | ||
1231 | /// <summary> | 1232 | /// <summary> |
1233 | /// Send the region heightmap to the client | ||
1234 | /// </summary> | ||
1235 | /// <param name="map">heightmap</param> | ||
1236 | public virtual void SendWindData(float[] map) | ||
1237 | { | ||
1238 | ThreadPool.QueueUserWorkItem(new WaitCallback(DoSendWindData), (object)map); | ||
1239 | } | ||
1240 | |||
1241 | /// <summary> | ||
1242 | /// Send terrain layer information to the client. | ||
1243 | /// </summary> | ||
1244 | /// <param name="o"></param> | ||
1245 | private void DoSendWindData(object o) | ||
1246 | { | ||
1247 | float[] map = (float[])o; | ||
1248 | |||
1249 | try | ||
1250 | { | ||
1251 | for (int y = 0; y < 16; y++) | ||
1252 | { | ||
1253 | // For some terrains, sending more than one terrain patch at once results in a libsecondlife exception | ||
1254 | // see http://opensimulator.org/mantis/view.php?id=1662 | ||
1255 | //for (int x = 0; x < 16; x += 4) | ||
1256 | //{ | ||
1257 | // SendLayerPacket(map, y, x); | ||
1258 | // Thread.Sleep(150); | ||
1259 | //} | ||
1260 | for (int x = 0; x < 16; x++) | ||
1261 | { | ||
1262 | SendWindData(x, y, map); | ||
1263 | Thread.Sleep(35); | ||
1264 | } | ||
1265 | } | ||
1266 | } | ||
1267 | catch (Exception e) | ||
1268 | { | ||
1269 | m_log.Warn("[CLIENT]: ClientView.API.cs: SendLayerData() - Failed with exception " + e.ToString()); | ||
1270 | } | ||
1271 | } | ||
1272 | |||
1273 | /// <summary> | ||
1274 | /// Sends a set of four patches (x, x+1, ..., x+3) to the client | ||
1275 | /// </summary> | ||
1276 | /// <param name="map">heightmap</param> | ||
1277 | /// <param name="px">X coordinate for patches 0..12</param> | ||
1278 | /// <param name="py">Y coordinate for patches 0..15</param> | ||
1279 | // private void SendLayerPacket(float[] map, int y, int x) | ||
1280 | // { | ||
1281 | // int[] patches = new int[4]; | ||
1282 | // patches[0] = x + 0 + y * 16; | ||
1283 | // patches[1] = x + 1 + y * 16; | ||
1284 | // patches[2] = x + 2 + y * 16; | ||
1285 | // patches[3] = x + 3 + y * 16; | ||
1286 | |||
1287 | // Packet layerpack = LLClientView.TerrainManager.CreateLandPacket(map, patches); | ||
1288 | // OutPacket(layerpack, ThrottleOutPacketType.Land); | ||
1289 | // } | ||
1290 | |||
1291 | /// <summary> | ||
1292 | /// Sends a specified patch to a client | ||
1293 | /// </summary> | ||
1294 | /// <param name="px">Patch coordinate (x) 0..15</param> | ||
1295 | /// <param name="py">Patch coordinate (y) 0..15</param> | ||
1296 | /// <param name="map">heightmap</param> | ||
1297 | public void SendWindData(int px, int py, float[] map) | ||
1298 | { | ||
1299 | try | ||
1300 | { | ||
1301 | int[] patches = new int[1]; | ||
1302 | int patchx, patchy; | ||
1303 | patchx = px; | ||
1304 | patchy = py; | ||
1305 | |||
1306 | patches[0] = patchx + 0 + patchy * 16; | ||
1307 | |||
1308 | LayerDataPacket layerpack = TerrainCompressor.CreateWindPacket(map, patches); | ||
1309 | layerpack.Header.Zerocoded = true; | ||
1310 | |||
1311 | OutPacket(layerpack, ThrottleOutPacketType.Wind); | ||
1312 | |||
1313 | } | ||
1314 | catch (Exception e) | ||
1315 | { | ||
1316 | m_log.Warn("[client]: ClientView.API.cs: SendLayerData() - Failed with exception " + e.ToString()); | ||
1317 | } | ||
1318 | } | ||
1319 | |||
1320 | |||
1321 | |||
1322 | /// <summary> | ||
1232 | /// Tell the client that the given neighbour region is ready to receive a child agent. | 1323 | /// Tell the client that the given neighbour region is ready to receive a child agent. |
1233 | /// </summary> | 1324 | /// </summary> |
1234 | /// <param name="neighbourHandle"></param> | 1325 | /// <param name="neighbourHandle"></param> |
diff --git a/OpenSim/Region/Environment/Modules/World/NPC/NPCAvatar.cs b/OpenSim/Region/Environment/Modules/World/NPC/NPCAvatar.cs index a1d72be..653932c 100644 --- a/OpenSim/Region/Environment/Modules/World/NPC/NPCAvatar.cs +++ b/OpenSim/Region/Environment/Modules/World/NPC/NPCAvatar.cs | |||
@@ -482,6 +482,9 @@ namespace OpenSim.Region.Environment.Modules.World.NPC | |||
482 | { | 482 | { |
483 | } | 483 | } |
484 | 484 | ||
485 | public virtual void SendWindData(float[] map) { } | ||
486 | public virtual void SendWindData(int px, int py, float[] map) { } | ||
487 | |||
485 | public virtual void MoveAgentIntoRegion(RegionInfo regInfo, Vector3 pos, Vector3 look) | 488 | public virtual void MoveAgentIntoRegion(RegionInfo regInfo, Vector3 pos, Vector3 look) |
486 | { | 489 | { |
487 | } | 490 | } |
diff --git a/OpenSim/Region/Environment/Modules/World/Wind/WindModule.cs b/OpenSim/Region/Environment/Modules/World/Wind/WindModule.cs new file mode 100644 index 0000000..190cc0b --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Wind/WindModule.cs | |||
@@ -0,0 +1,257 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.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 OpenMetaverse; | ||
31 | using Nini.Config; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Region.Environment.Interfaces; | ||
34 | using OpenSim.Region.Environment.Scenes; | ||
35 | |||
36 | namespace OpenSim.Region.Environment.Modules | ||
37 | { | ||
38 | public class WindModule : IRegionModule | ||
39 | { | ||
40 | |||
41 | private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||
42 | |||
43 | private int m_frame = 0; | ||
44 | private int m_frame_mod = 150; | ||
45 | private Random rndnums = new Random(System.Environment.TickCount); | ||
46 | private Scene m_scene = null; | ||
47 | private bool ready = false; | ||
48 | private float[] windarr = new float[256*256]; | ||
49 | |||
50 | private Dictionary<UUID, ulong> m_rootAgents = new Dictionary<UUID, ulong>(); | ||
51 | |||
52 | // Current time in elpased seconds since Jan 1st 1970 | ||
53 | |||
54 | |||
55 | public void Initialise(Scene scene, IConfigSource config) | ||
56 | { | ||
57 | |||
58 | m_log.Debug("[WIND] Initializing"); | ||
59 | |||
60 | m_scene = scene; | ||
61 | |||
62 | m_frame = 0; | ||
63 | |||
64 | |||
65 | |||
66 | // Align ticks with Second Life | ||
67 | |||
68 | |||
69 | |||
70 | // Just in case they don't have the stanzas | ||
71 | try | ||
72 | { | ||
73 | |||
74 | } | ||
75 | catch (Exception e) | ||
76 | { | ||
77 | m_log.Debug("[WIND] Configuration access failed, using defaults. Reason: " + e.Message); | ||
78 | |||
79 | } | ||
80 | |||
81 | |||
82 | scene.EventManager.OnFrame += WindUpdate; | ||
83 | |||
84 | scene.EventManager.OnMakeChildAgent += MakeChildAgent; | ||
85 | scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel; | ||
86 | scene.EventManager.OnClientClosed += ClientLoggedOut; | ||
87 | |||
88 | GenWindPos(); | ||
89 | |||
90 | ready = true; | ||
91 | |||
92 | |||
93 | |||
94 | } | ||
95 | |||
96 | public void PostInitialise() | ||
97 | { | ||
98 | } | ||
99 | |||
100 | public void Close() | ||
101 | { | ||
102 | ready = false; | ||
103 | // Remove our hooks | ||
104 | m_scene.EventManager.OnFrame -= WindUpdate; | ||
105 | // m_scene.EventManager.OnNewClient -= SunToClient; | ||
106 | m_scene.EventManager.OnMakeChildAgent -= MakeChildAgent; | ||
107 | m_scene.EventManager.OnAvatarEnteringNewParcel -= AvatarEnteringParcel; | ||
108 | m_scene.EventManager.OnClientClosed -= ClientLoggedOut; | ||
109 | } | ||
110 | |||
111 | public string Name | ||
112 | { | ||
113 | get { return "WindModule"; } | ||
114 | } | ||
115 | |||
116 | public bool IsSharedModule | ||
117 | { | ||
118 | get { return false; } | ||
119 | } | ||
120 | |||
121 | public void WindToClient(IClientAPI client) | ||
122 | { | ||
123 | |||
124 | if (ready) | ||
125 | { | ||
126 | //if (!sunFixed) | ||
127 | //GenWindPos(); // Generate shared values once | ||
128 | client.SendWindData(windarr); | ||
129 | m_log.Debug("[WIND] Initial update for new client"); | ||
130 | } | ||
131 | |||
132 | } | ||
133 | |||
134 | public void WindUpdate() | ||
135 | { | ||
136 | if (((m_frame++ % m_frame_mod) != 0) || !ready) | ||
137 | { | ||
138 | return; | ||
139 | } | ||
140 | //m_log.Debug("[WIND]:Regenerating..."); | ||
141 | GenWindPos(); // Generate shared values once | ||
142 | |||
143 | int spotxp = 0; | ||
144 | int spotyp = 0; | ||
145 | int spotxm = 0; | ||
146 | int spotym = 0; | ||
147 | List<ScenePresence> avatars = m_scene.GetAvatars(); | ||
148 | foreach (ScenePresence avatar in avatars) | ||
149 | { | ||
150 | if (!avatar.IsChildAgent) | ||
151 | { | ||
152 | spotxp = (int)avatar.CameraPosition.X + 3; | ||
153 | spotxm = (int)avatar.CameraPosition.X - 3; | ||
154 | spotyp = (int)avatar.CameraPosition.Y + 3; | ||
155 | spotym = (int)avatar.CameraPosition.Y - 3; | ||
156 | if (spotxm < 0) | ||
157 | spotxm = 0; | ||
158 | if (spotym < 0) | ||
159 | spotym = 0; | ||
160 | if (spotxp > 255) | ||
161 | spotxp = 255; | ||
162 | if (spotyp > 255) | ||
163 | spotyp = 255; | ||
164 | for (int x = spotxm; x<spotxp; x++) | ||
165 | { | ||
166 | for (int y = spotym; y<spotyp; y++) | ||
167 | { | ||
168 | avatar.ControllingClient.SendWindData( | ||
169 | x / Constants.TerrainPatchSize, | ||
170 | y / Constants.TerrainPatchSize, | ||
171 | windarr); | ||
172 | } | ||
173 | } | ||
174 | } | ||
175 | } | ||
176 | |||
177 | // set estate settings for region access to sun position | ||
178 | //m_scene.RegionInfo.RegionSettings.SunVector = Position; | ||
179 | //m_scene.RegionInfo.EstateSettings.sunHour = GetLindenEstateHourFromCurrentTime(); | ||
180 | } | ||
181 | public void ForceWindUpdateToAllClients() | ||
182 | { | ||
183 | GenWindPos(); // Generate shared values once | ||
184 | |||
185 | List<ScenePresence> avatars = m_scene.GetAvatars(); | ||
186 | foreach (ScenePresence avatar in avatars) | ||
187 | { | ||
188 | if (!avatar.IsChildAgent) | ||
189 | avatar.ControllingClient.SendWindData(windarr); | ||
190 | } | ||
191 | |||
192 | // set estate settings for region access to sun position | ||
193 | //m_scene.RegionInfo.RegionSettings.SunVector = Position; | ||
194 | //m_scene.RegionInfo.RegionSettings.SunPosition = GetLindenEstateHourFromCurrentTime(); | ||
195 | } | ||
196 | /// <summary> | ||
197 | /// Calculate the sun's orbital position and its velocity. | ||
198 | /// </summary> | ||
199 | |||
200 | private void GenWindPos() | ||
201 | { | ||
202 | windarr = new float[256*256]; | ||
203 | for (int x = 0; x < 256; x++) | ||
204 | { | ||
205 | for (int y = 0; y < 256; y++) | ||
206 | { | ||
207 | windarr[y*256 + x]= (float)(rndnums.NextDouble()* 2d - 1d); | ||
208 | } | ||
209 | } | ||
210 | |||
211 | // m_log.Debug("[SUN] Velocity("+Velocity.X+","+Velocity.Y+","+Velocity.Z+")"); | ||
212 | } | ||
213 | |||
214 | private void ClientLoggedOut(UUID AgentId) | ||
215 | { | ||
216 | lock (m_rootAgents) | ||
217 | { | ||
218 | if (m_rootAgents.ContainsKey(AgentId)) | ||
219 | { | ||
220 | m_rootAgents.Remove(AgentId); | ||
221 | m_log.Info("[WIND]: Removing " + AgentId + ". Agent logged out."); | ||
222 | } | ||
223 | } | ||
224 | } | ||
225 | |||
226 | private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, UUID regionID) | ||
227 | { | ||
228 | lock (m_rootAgents) | ||
229 | { | ||
230 | if (m_rootAgents.ContainsKey(avatar.UUID)) | ||
231 | { | ||
232 | m_rootAgents[avatar.UUID] = avatar.RegionHandle; | ||
233 | } | ||
234 | else | ||
235 | { | ||
236 | m_rootAgents.Add(avatar.UUID, avatar.RegionHandle); | ||
237 | WindToClient(avatar.ControllingClient); | ||
238 | } | ||
239 | } | ||
240 | //m_log.Info("[FRIEND]: " + avatar.Name + " status:" + (!avatar.IsChildAgent).ToString()); | ||
241 | } | ||
242 | |||
243 | private void MakeChildAgent(ScenePresence avatar) | ||
244 | { | ||
245 | lock (m_rootAgents) | ||
246 | { | ||
247 | if (m_rootAgents.ContainsKey(avatar.UUID)) | ||
248 | { | ||
249 | if (m_rootAgents[avatar.UUID] == avatar.RegionHandle) | ||
250 | { | ||
251 | m_rootAgents.Remove(avatar.UUID); | ||
252 | } | ||
253 | } | ||
254 | } | ||
255 | } | ||
256 | } | ||
257 | } | ||
diff --git a/OpenSim/Region/Examples/SimpleModule/MyNpcCharacter.cs b/OpenSim/Region/Examples/SimpleModule/MyNpcCharacter.cs index 623325e..279abdf 100644 --- a/OpenSim/Region/Examples/SimpleModule/MyNpcCharacter.cs +++ b/OpenSim/Region/Examples/SimpleModule/MyNpcCharacter.cs | |||
@@ -396,6 +396,9 @@ namespace OpenSim.Region.Examples.SimpleModule | |||
396 | { | 396 | { |
397 | } | 397 | } |
398 | 398 | ||
399 | public virtual void SendWindData(float[] map) { } | ||
400 | public virtual void SendWindData(int px, int py, float[] map) { } | ||
401 | |||
399 | public virtual void MoveAgentIntoRegion(RegionInfo regInfo, Vector3 pos, Vector3 look) | 402 | public virtual void MoveAgentIntoRegion(RegionInfo regInfo, Vector3 pos, Vector3 look) |
400 | { | 403 | { |
401 | } | 404 | } |