diff options
Diffstat (limited to 'OpenSim/Region/Environment/Modules/World/Wind/WindModule.cs')
-rw-r--r-- | OpenSim/Region/Environment/Modules/World/Wind/WindModule.cs | 207 |
1 files changed, 0 insertions, 207 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/Wind/WindModule.cs b/OpenSim/Region/Environment/Modules/World/Wind/WindModule.cs deleted file mode 100644 index 8e54fd9..0000000 --- a/OpenSim/Region/Environment/Modules/World/Wind/WindModule.cs +++ /dev/null | |||
@@ -1,207 +0,0 @@ | |||
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.Framework.Interfaces; | ||
34 | using OpenSim.Region.Framework.Scenes; | ||
35 | |||
36 | namespace OpenSim.Region.Environment.Modules | ||
37 | { | ||
38 | public class WindModule : IWindModule | ||
39 | { | ||
40 | // private static readonly log4net.ILog m_log | ||
41 | // = 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 Vector2[] windSpeeds = new Vector2[16 * 16]; | ||
49 | private Dictionary<UUID, ulong> m_rootAgents = new Dictionary<UUID, ulong>(); | ||
50 | |||
51 | public void Initialise(Scene scene, IConfigSource config) | ||
52 | { | ||
53 | m_scene = scene; | ||
54 | m_frame = 0; | ||
55 | |||
56 | scene.EventManager.OnFrame += WindUpdate; | ||
57 | scene.EventManager.OnMakeChildAgent += MakeChildAgent; | ||
58 | scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel; | ||
59 | scene.EventManager.OnClientClosed += ClientLoggedOut; | ||
60 | scene.RegisterModuleInterface<IWindModule>(this); | ||
61 | |||
62 | GenWindPos(); | ||
63 | |||
64 | ready = true; | ||
65 | } | ||
66 | |||
67 | public void PostInitialise() | ||
68 | { | ||
69 | } | ||
70 | |||
71 | public void Close() | ||
72 | { | ||
73 | ready = false; | ||
74 | // Remove our hooks | ||
75 | m_scene.EventManager.OnFrame -= WindUpdate; | ||
76 | // m_scene.EventManager.OnNewClient -= SunToClient; | ||
77 | m_scene.EventManager.OnMakeChildAgent -= MakeChildAgent; | ||
78 | m_scene.EventManager.OnAvatarEnteringNewParcel -= AvatarEnteringParcel; | ||
79 | m_scene.EventManager.OnClientClosed -= ClientLoggedOut; | ||
80 | } | ||
81 | |||
82 | public string Name | ||
83 | { | ||
84 | get { return "WindModule"; } | ||
85 | } | ||
86 | |||
87 | public bool IsSharedModule | ||
88 | { | ||
89 | get { return false; } | ||
90 | } | ||
91 | |||
92 | public Vector2[] WindSpeeds | ||
93 | { | ||
94 | get { return windSpeeds; } | ||
95 | } | ||
96 | |||
97 | public void WindToClient(IClientAPI client) | ||
98 | { | ||
99 | if (ready) | ||
100 | { | ||
101 | //if (!sunFixed) | ||
102 | //GenWindPos(); // Generate shared values once | ||
103 | client.SendWindData(windSpeeds); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | public void WindUpdate() | ||
108 | { | ||
109 | if (((m_frame++ % m_frame_mod) != 0) || !ready) | ||
110 | { | ||
111 | return; | ||
112 | } | ||
113 | //m_log.Debug("[WIND]:Regenerating..."); | ||
114 | GenWindPos(); // Generate shared values once | ||
115 | |||
116 | //int spotxp = 0; | ||
117 | //int spotyp = 0; | ||
118 | //int spotxm = 0; | ||
119 | //int spotym = 0; | ||
120 | List<ScenePresence> avatars = m_scene.GetAvatars(); | ||
121 | foreach (ScenePresence avatar in avatars) | ||
122 | { | ||
123 | if (!avatar.IsChildAgent) | ||
124 | { | ||
125 | avatar.ControllingClient.SendWindData(windSpeeds); | ||
126 | } | ||
127 | } | ||
128 | |||
129 | // set estate settings for region access to sun position | ||
130 | //m_scene.RegionInfo.RegionSettings.SunVector = Position; | ||
131 | //m_scene.RegionInfo.EstateSettings.sunHour = GetLindenEstateHourFromCurrentTime(); | ||
132 | } | ||
133 | |||
134 | public void ForceWindUpdateToAllClients() | ||
135 | { | ||
136 | GenWindPos(); // Generate shared values once | ||
137 | |||
138 | List<ScenePresence> avatars = m_scene.GetAvatars(); | ||
139 | foreach (ScenePresence avatar in avatars) | ||
140 | { | ||
141 | if (!avatar.IsChildAgent) | ||
142 | avatar.ControllingClient.SendWindData(windSpeeds); | ||
143 | } | ||
144 | |||
145 | // set estate settings for region access to sun position | ||
146 | //m_scene.RegionInfo.RegionSettings.SunVector = Position; | ||
147 | //m_scene.RegionInfo.RegionSettings.SunPosition = GetLindenEstateHourFromCurrentTime(); | ||
148 | } | ||
149 | /// <summary> | ||
150 | /// Calculate the sun's orbital position and its velocity. | ||
151 | /// </summary> | ||
152 | |||
153 | private void GenWindPos() | ||
154 | { | ||
155 | for (int y = 0; y < 16; y++) | ||
156 | { | ||
157 | for (int x = 0; x < 16; x++) | ||
158 | { | ||
159 | windSpeeds[y * 16 + x].X = (float)(rndnums.NextDouble() * 2d - 1d); | ||
160 | windSpeeds[y * 16 + x].Y = (float)(rndnums.NextDouble() * 2d - 1d); | ||
161 | } | ||
162 | } | ||
163 | } | ||
164 | |||
165 | private void ClientLoggedOut(UUID AgentId) | ||
166 | { | ||
167 | lock (m_rootAgents) | ||
168 | { | ||
169 | if (m_rootAgents.ContainsKey(AgentId)) | ||
170 | { | ||
171 | m_rootAgents.Remove(AgentId); | ||
172 | } | ||
173 | } | ||
174 | } | ||
175 | |||
176 | private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, UUID regionID) | ||
177 | { | ||
178 | lock (m_rootAgents) | ||
179 | { | ||
180 | if (m_rootAgents.ContainsKey(avatar.UUID)) | ||
181 | { | ||
182 | m_rootAgents[avatar.UUID] = avatar.RegionHandle; | ||
183 | } | ||
184 | else | ||
185 | { | ||
186 | m_rootAgents.Add(avatar.UUID, avatar.RegionHandle); | ||
187 | WindToClient(avatar.ControllingClient); | ||
188 | } | ||
189 | } | ||
190 | //m_log.Info("[FRIEND]: " + avatar.Name + " status:" + (!avatar.IsChildAgent).ToString()); | ||
191 | } | ||
192 | |||
193 | private void MakeChildAgent(ScenePresence avatar) | ||
194 | { | ||
195 | lock (m_rootAgents) | ||
196 | { | ||
197 | if (m_rootAgents.ContainsKey(avatar.UUID)) | ||
198 | { | ||
199 | if (m_rootAgents[avatar.UUID] == avatar.RegionHandle) | ||
200 | { | ||
201 | m_rootAgents.Remove(avatar.UUID); | ||
202 | } | ||
203 | } | ||
204 | } | ||
205 | } | ||
206 | } | ||
207 | } | ||