diff options
author | Dr Scofield | 2009-02-10 13:10:57 +0000 |
---|---|---|
committer | Dr Scofield | 2009-02-10 13:10:57 +0000 |
commit | 180be7de07014aa33bc6066f12a0819b731c1c9d (patch) | |
tree | 3aa13af3cda4b808fa9453655875327699b61311 /OpenSim/Region/CoreModules/World/Wind | |
parent | Stopgap measure: To use gridlaunch, or GUI, start opensim with (diff) | |
download | opensim-SC_OLD-180be7de07014aa33bc6066f12a0819b731c1c9d.zip opensim-SC_OLD-180be7de07014aa33bc6066f12a0819b731c1c9d.tar.gz opensim-SC_OLD-180be7de07014aa33bc6066f12a0819b731c1c9d.tar.bz2 opensim-SC_OLD-180be7de07014aa33bc6066f12a0819b731c1c9d.tar.xz |
this is step 2 of 2 of the OpenSim.Region.Environment refactor.
NOTHING has been deleted or moved off to forge at this point. what
has happened is that OpenSim.Region.Environment.Modules has been split
in two:
- OpenSim.Region.CoreModules: all those modules that are either
directly or indirectly referenced from other OpenSim packages, or
that provide functionality that the OpenSim developer community
considers core functionality:
CoreModules/Agent/AssetTransaction
CoreModules/Agent/Capabilities
CoreModules/Agent/TextureDownload
CoreModules/Agent/TextureSender
CoreModules/Agent/TextureSender/Tests
CoreModules/Agent/Xfer
CoreModules/Avatar/AvatarFactory
CoreModules/Avatar/Chat/ChatModule
CoreModules/Avatar/Combat
CoreModules/Avatar/Currency/SampleMoney
CoreModules/Avatar/Dialog
CoreModules/Avatar/Friends
CoreModules/Avatar/Gestures
CoreModules/Avatar/Groups
CoreModules/Avatar/InstantMessage
CoreModules/Avatar/Inventory
CoreModules/Avatar/Inventory/Archiver
CoreModules/Avatar/Inventory/Transfer
CoreModules/Avatar/Lure
CoreModules/Avatar/ObjectCaps
CoreModules/Avatar/Profiles
CoreModules/Communications/Local
CoreModules/Communications/REST
CoreModules/Framework/EventQueue
CoreModules/Framework/InterfaceCommander
CoreModules/Hypergrid
CoreModules/InterGrid
CoreModules/Scripting/DynamicTexture
CoreModules/Scripting/EMailModules
CoreModules/Scripting/HttpRequest
CoreModules/Scripting/LoadImageURL
CoreModules/Scripting/VectorRender
CoreModules/Scripting/WorldComm
CoreModules/Scripting/XMLRPC
CoreModules/World/Archiver
CoreModules/World/Archiver/Tests
CoreModules/World/Estate
CoreModules/World/Land
CoreModules/World/Permissions
CoreModules/World/Serialiser
CoreModules/World/Sound
CoreModules/World/Sun
CoreModules/World/Terrain
CoreModules/World/Terrain/DefaultEffects
CoreModules/World/Terrain/DefaultEffects/bin
CoreModules/World/Terrain/DefaultEffects/bin/Debug
CoreModules/World/Terrain/Effects
CoreModules/World/Terrain/FileLoaders
CoreModules/World/Terrain/FloodBrushes
CoreModules/World/Terrain/PaintBrushes
CoreModules/World/Terrain/Tests
CoreModules/World/Vegetation
CoreModules/World/Wind
CoreModules/World/WorldMap
- OpenSim.Region.OptionalModules: all those modules that are not core
modules:
OptionalModules/Avatar/Chat/IRC-stuff
OptionalModules/Avatar/Concierge
OptionalModules/Avatar/Voice/AsterixVoice
OptionalModules/Avatar/Voice/SIPVoice
OptionalModules/ContentManagementSystem
OptionalModules/Grid/Interregion
OptionalModules/Python
OptionalModules/SvnSerialiser
OptionalModules/World/NPC
OptionalModules/World/TreePopulator
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Wind')
-rw-r--r-- | OpenSim/Region/CoreModules/World/Wind/WindModule.cs | 207 |
1 files changed, 207 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/World/Wind/WindModule.cs b/OpenSim/Region/CoreModules/World/Wind/WindModule.cs new file mode 100644 index 0000000..b8bd605 --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Wind/WindModule.cs | |||
@@ -0,0 +1,207 @@ | |||
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.CoreModules | ||
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 | } | ||