diff options
Diffstat (limited to 'OpenSim/Region/Environment/Modules/World')
-rw-r--r-- | OpenSim/Region/Environment/Modules/World/NPC/NPCAvatar.cs | 3 | ||||
-rw-r--r-- | OpenSim/Region/Environment/Modules/World/Wind/WindModule.cs | 257 |
2 files changed, 260 insertions, 0 deletions
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 | } | ||