diff options
Diffstat (limited to 'OpenSim/Region/Environment/Modules/SunModule.cs')
-rw-r--r-- | OpenSim/Region/Environment/Modules/SunModule.cs | 195 |
1 files changed, 0 insertions, 195 deletions
diff --git a/OpenSim/Region/Environment/Modules/SunModule.cs b/OpenSim/Region/Environment/Modules/SunModule.cs deleted file mode 100644 index e6801e8..0000000 --- a/OpenSim/Region/Environment/Modules/SunModule.cs +++ /dev/null | |||
@@ -1,195 +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 libsecondlife; | ||
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 SunModule : IRegionModule | ||
39 | { | ||
40 | //private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||
41 | |||
42 | private const double m_real_day = 24.0; | ||
43 | private const int m_default_frame = 100; | ||
44 | private int m_frame_mod; | ||
45 | private double m_day_length; | ||
46 | private int m_dilation; | ||
47 | private int m_frame; | ||
48 | private long m_start; | ||
49 | |||
50 | private Scene m_scene; | ||
51 | |||
52 | public void Initialise(Scene scene, IConfigSource config) | ||
53 | { | ||
54 | m_start = DateTime.Now.Ticks; | ||
55 | m_frame = 0; | ||
56 | |||
57 | // Just in case they don't have the stanzas | ||
58 | try | ||
59 | { | ||
60 | m_day_length = config.Configs["Sun"].GetDouble("day_length", m_real_day); | ||
61 | m_frame_mod = config.Configs["Sun"].GetInt("frame_rate", m_default_frame); | ||
62 | } | ||
63 | catch (Exception) | ||
64 | { | ||
65 | m_day_length = m_real_day; | ||
66 | m_frame_mod = m_default_frame; | ||
67 | } | ||
68 | |||
69 | m_dilation = (int) (m_real_day/m_day_length); | ||
70 | m_scene = scene; | ||
71 | scene.EventManager.OnFrame += SunUpdate; | ||
72 | scene.EventManager.OnNewClient += SunToClient; | ||
73 | } | ||
74 | |||
75 | public void PostInitialise() | ||
76 | { | ||
77 | } | ||
78 | |||
79 | public void Close() | ||
80 | { | ||
81 | } | ||
82 | |||
83 | public string Name | ||
84 | { | ||
85 | get { return "SunModule"; } | ||
86 | } | ||
87 | |||
88 | public bool IsSharedModule | ||
89 | { | ||
90 | get { return false; } | ||
91 | } | ||
92 | |||
93 | public void SunToClient(IClientAPI client) | ||
94 | { | ||
95 | client.SendSunPos(SunPos(HourOfTheDay()), new LLVector3(0, 0.0f, 10.0f)); | ||
96 | } | ||
97 | |||
98 | public void SunUpdate() | ||
99 | { | ||
100 | if (m_frame < m_frame_mod) | ||
101 | { | ||
102 | m_frame++; | ||
103 | return; | ||
104 | } | ||
105 | // m_log.InfoFormat("[SUN]: I've got an update {0} => {1}", m_scene.RegionsInfo.RegionName, HourOfTheDay()); | ||
106 | List<ScenePresence> avatars = m_scene.GetAvatars(); | ||
107 | foreach (ScenePresence avatar in avatars) | ||
108 | { | ||
109 | avatar.ControllingClient.SendSunPos(SunPos(HourOfTheDay()), new LLVector3(0, 0.0f, 10.0f)); | ||
110 | } | ||
111 | // set estate settings for region access to sun position | ||
112 | m_scene.RegionInfo.EstateSettings.sunPosition = SunPos(HourOfTheDay()); | ||
113 | |||
114 | m_frame = 0; | ||
115 | } | ||
116 | |||
117 | // Hour of the Day figures out the hour of the day as a float. | ||
118 | // The intent here is that we seed hour of the day with real | ||
119 | // time when the simulator starts, then run time forward | ||
120 | // faster based on time dilation factor. This means that | ||
121 | // ticks don't get out of hand | ||
122 | private double HourOfTheDay() | ||
123 | { | ||
124 | long m_addticks = (DateTime.Now.Ticks - m_start)*m_dilation; | ||
125 | DateTime dt = new DateTime(m_start + m_addticks); | ||
126 | return (double) dt.Hour + ((double) dt.Minute/60.0); | ||
127 | } | ||
128 | |||
129 | private LLVector3 SunPos(double hour) | ||
130 | { | ||
131 | // now we have our radian position | ||
132 | double rad = (hour/m_real_day)*2*Math.PI - (Math.PI/2.0); | ||
133 | double z = Math.Sin(rad); | ||
134 | double x = Math.Cos(rad); | ||
135 | return new LLVector3((float) x, 0f, (float) z); | ||
136 | } | ||
137 | |||
138 | // TODO: clear this out. This is here so that I remember to | ||
139 | // figure out if we need those other packet fields that I've | ||
140 | // left out so far | ||
141 | // | ||
142 | // public void SendViewerTime(int phase) | ||
143 | // { | ||
144 | // Console.WriteLine("SunPhase: {0}", phase); | ||
145 | // SimulatorViewerTimeMessagePacket viewertime = new SimulatorViewerTimeMessagePacket(); | ||
146 | // //viewertime.TimeInfo.SecPerDay = 86400; | ||
147 | // // viewertime.TimeInfo.SecPerYear = 31536000; | ||
148 | // viewertime.TimeInfo.SecPerDay = 1000; | ||
149 | // viewertime.TimeInfo.SecPerYear = 365000; | ||
150 | // viewertime.TimeInfo.SunPhase = 1; | ||
151 | // int sunPhase = (phase + 2)/2; | ||
152 | // if ((sunPhase < 6) || (sunPhase > 36)) | ||
153 | // { | ||
154 | // viewertime.TimeInfo.SunDirection = new LLVector3(0f, 0.8f, -0.8f); | ||
155 | // Console.WriteLine("sending night"); | ||
156 | // } | ||
157 | // else | ||
158 | // { | ||
159 | // if (sunPhase < 12) | ||
160 | // { | ||
161 | // sunPhase = 12; | ||
162 | // } | ||
163 | // sunPhase = sunPhase - 12; | ||
164 | // | ||
165 | // float yValue = 0.1f*(sunPhase); | ||
166 | // Console.WriteLine("Computed SunPhase: {0}, yValue: {1}", sunPhase, yValue); | ||
167 | // if (yValue > 1.2f) | ||
168 | // { | ||
169 | // yValue = yValue - 1.2f; | ||
170 | // } | ||
171 | // if (yValue > 1) | ||
172 | // { | ||
173 | // yValue = 1; | ||
174 | // } | ||
175 | // if (yValue < 0) | ||
176 | // { | ||
177 | // yValue = 0; | ||
178 | // } | ||
179 | // if (sunPhase < 14) | ||
180 | // { | ||
181 | // yValue = 1 - yValue; | ||
182 | // } | ||
183 | // if (sunPhase < 12) | ||
184 | // { | ||
185 | // yValue *= -1; | ||
186 | // } | ||
187 | // viewertime.TimeInfo.SunDirection = new LLVector3(0f, yValue, 0.3f); | ||
188 | // Console.WriteLine("sending sun update " + yValue); | ||
189 | // } | ||
190 | // viewertime.TimeInfo.SunAngVelocity = new LLVector3(0, 0.0f, 10.0f); | ||
191 | // viewertime.TimeInfo.UsecSinceStart = (ulong) Util.UnixTimeSinceEpoch(); | ||
192 | // // OutPacket(viewertime); | ||
193 | // } | ||
194 | } | ||
195 | } | ||