diff options
Diffstat (limited to 'OpenSim/Region/Environment/Modules/World/Sun/SunModule.cs')
-rw-r--r-- | OpenSim/Region/Environment/Modules/World/Sun/SunModule.cs | 396 |
1 files changed, 198 insertions, 198 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/Sun/SunModule.cs b/OpenSim/Region/Environment/Modules/World/Sun/SunModule.cs index a12118e..85c4cdd 100644 --- a/OpenSim/Region/Environment/Modules/World/Sun/SunModule.cs +++ b/OpenSim/Region/Environment/Modules/World/Sun/SunModule.cs | |||
@@ -1,199 +1,199 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using libsecondlife; | 30 | using libsecondlife; |
31 | using Nini.Config; | 31 | using Nini.Config; |
32 | using OpenSim.Framework; | 32 | using OpenSim.Framework; |
33 | using OpenSim.Region.Environment.Interfaces; | 33 | using OpenSim.Region.Environment.Interfaces; |
34 | using OpenSim.Region.Environment.Scenes; | 34 | using OpenSim.Region.Environment.Scenes; |
35 | 35 | ||
36 | namespace OpenSim.Region.Environment.Modules | 36 | namespace OpenSim.Region.Environment.Modules |
37 | { | 37 | { |
38 | public class SunModule : IRegionModule | 38 | public class SunModule : IRegionModule |
39 | { | 39 | { |
40 | //private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | 40 | //private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); |
41 | 41 | ||
42 | private const int m_default_frame = 100; | 42 | private const int m_default_frame = 100; |
43 | private const double m_real_day = 24.0; | 43 | private const double m_real_day = 24.0; |
44 | private double m_day_length; | 44 | private double m_day_length; |
45 | private int m_dilation; | 45 | private int m_dilation; |
46 | private int m_frame; | 46 | private int m_frame; |
47 | private int m_frame_mod; | 47 | private int m_frame_mod; |
48 | 48 | ||
49 | private Scene m_scene; | 49 | private Scene m_scene; |
50 | private long m_start; | 50 | private long m_start; |
51 | 51 | ||
52 | #region IRegionModule Members | 52 | #region IRegionModule Members |
53 | 53 | ||
54 | public void Initialise(Scene scene, IConfigSource config) | 54 | public void Initialise(Scene scene, IConfigSource config) |
55 | { | 55 | { |
56 | m_start = DateTime.Now.Ticks; | 56 | m_start = DateTime.Now.Ticks; |
57 | m_frame = 0; | 57 | m_frame = 0; |
58 | 58 | ||
59 | // Just in case they don't have the stanzas | 59 | // Just in case they don't have the stanzas |
60 | try | 60 | try |
61 | { | 61 | { |
62 | m_day_length = config.Configs["Sun"].GetDouble("day_length", m_real_day); | 62 | m_day_length = config.Configs["Sun"].GetDouble("day_length", m_real_day); |
63 | m_frame_mod = config.Configs["Sun"].GetInt("frame_rate", m_default_frame); | 63 | m_frame_mod = config.Configs["Sun"].GetInt("frame_rate", m_default_frame); |
64 | } | 64 | } |
65 | catch (Exception) | 65 | catch (Exception) |
66 | { | 66 | { |
67 | m_day_length = m_real_day; | 67 | m_day_length = m_real_day; |
68 | m_frame_mod = m_default_frame; | 68 | m_frame_mod = m_default_frame; |
69 | } | 69 | } |
70 | 70 | ||
71 | m_dilation = (int) (m_real_day / m_day_length); | 71 | m_dilation = (int) (m_real_day / m_day_length); |
72 | m_scene = scene; | 72 | m_scene = scene; |
73 | scene.EventManager.OnFrame += SunUpdate; | 73 | scene.EventManager.OnFrame += SunUpdate; |
74 | scene.EventManager.OnNewClient += SunToClient; | 74 | scene.EventManager.OnNewClient += SunToClient; |
75 | } | 75 | } |
76 | 76 | ||
77 | public void PostInitialise() | 77 | public void PostInitialise() |
78 | { | 78 | { |
79 | } | 79 | } |
80 | 80 | ||
81 | public void Close() | 81 | public void Close() |
82 | { | 82 | { |
83 | } | 83 | } |
84 | 84 | ||
85 | public string Name | 85 | public string Name |
86 | { | 86 | { |
87 | get { return "SunModule"; } | 87 | get { return "SunModule"; } |
88 | } | 88 | } |
89 | 89 | ||
90 | public bool IsSharedModule | 90 | public bool IsSharedModule |
91 | { | 91 | { |
92 | get { return false; } | 92 | get { return false; } |
93 | } | 93 | } |
94 | 94 | ||
95 | #endregion | 95 | #endregion |
96 | 96 | ||
97 | public void SunToClient(IClientAPI client) | 97 | public void SunToClient(IClientAPI client) |
98 | { | 98 | { |
99 | client.SendSunPos(SunPos(HourOfTheDay()), new LLVector3(0, 0.0f, 10.0f)); | 99 | client.SendSunPos(SunPos(HourOfTheDay()), new LLVector3(0, 0.0f, 10.0f)); |
100 | } | 100 | } |
101 | 101 | ||
102 | public void SunUpdate() | 102 | public void SunUpdate() |
103 | { | 103 | { |
104 | if (m_frame < m_frame_mod) | 104 | if (m_frame < m_frame_mod) |
105 | { | 105 | { |
106 | m_frame++; | 106 | m_frame++; |
107 | return; | 107 | return; |
108 | } | 108 | } |
109 | // m_log.InfoFormat("[SUN]: I've got an update {0} => {1}", m_scene.RegionsInfo.RegionName, HourOfTheDay()); | 109 | // m_log.InfoFormat("[SUN]: I've got an update {0} => {1}", m_scene.RegionsInfo.RegionName, HourOfTheDay()); |
110 | List<ScenePresence> avatars = m_scene.GetAvatars(); | 110 | List<ScenePresence> avatars = m_scene.GetAvatars(); |
111 | foreach (ScenePresence avatar in avatars) | 111 | foreach (ScenePresence avatar in avatars) |
112 | { | 112 | { |
113 | avatar.ControllingClient.SendSunPos(SunPos(HourOfTheDay()), new LLVector3(0, 0.0f, 10.0f)); | 113 | avatar.ControllingClient.SendSunPos(SunPos(HourOfTheDay()), new LLVector3(0, 0.0f, 10.0f)); |
114 | } | 114 | } |
115 | // set estate settings for region access to sun position | 115 | // set estate settings for region access to sun position |
116 | m_scene.RegionInfo.EstateSettings.sunPosition = SunPos(HourOfTheDay()); | 116 | m_scene.RegionInfo.EstateSettings.sunPosition = SunPos(HourOfTheDay()); |
117 | 117 | ||
118 | m_frame = 0; | 118 | m_frame = 0; |
119 | } | 119 | } |
120 | 120 | ||
121 | // Hour of the Day figures out the hour of the day as a float. | 121 | // Hour of the Day figures out the hour of the day as a float. |
122 | // The intent here is that we seed hour of the day with real | 122 | // The intent here is that we seed hour of the day with real |
123 | // time when the simulator starts, then run time forward | 123 | // time when the simulator starts, then run time forward |
124 | // faster based on time dilation factor. This means that | 124 | // faster based on time dilation factor. This means that |
125 | // ticks don't get out of hand | 125 | // ticks don't get out of hand |
126 | private double HourOfTheDay() | 126 | private double HourOfTheDay() |
127 | { | 127 | { |
128 | long m_addticks = (DateTime.Now.Ticks - m_start) * m_dilation; | 128 | long m_addticks = (DateTime.Now.Ticks - m_start) * m_dilation; |
129 | DateTime dt = new DateTime(m_start + m_addticks); | 129 | DateTime dt = new DateTime(m_start + m_addticks); |
130 | return (double) dt.Hour + ((double) dt.Minute / 60.0); | 130 | return (double) dt.Hour + ((double) dt.Minute / 60.0); |
131 | } | 131 | } |
132 | 132 | ||
133 | private LLVector3 SunPos(double hour) | 133 | private LLVector3 SunPos(double hour) |
134 | { | 134 | { |
135 | // now we have our radian position | 135 | // now we have our radian position |
136 | double rad = (hour / m_real_day) * 2 * Math.PI - (Math.PI / 2.0); | 136 | double rad = (hour / m_real_day) * 2 * Math.PI - (Math.PI / 2.0); |
137 | double z = Math.Sin(rad); | 137 | double z = Math.Sin(rad); |
138 | double x = Math.Cos(rad); | 138 | double x = Math.Cos(rad); |
139 | return new LLVector3((float) x, 0f, (float) z); | 139 | return new LLVector3((float) x, 0f, (float) z); |
140 | } | 140 | } |
141 | 141 | ||
142 | // TODO: clear this out. This is here so that I remember to | 142 | // TODO: clear this out. This is here so that I remember to |
143 | // figure out if we need those other packet fields that I've | 143 | // figure out if we need those other packet fields that I've |
144 | // left out so far | 144 | // left out so far |
145 | // | 145 | // |
146 | // public void SendViewerTime(int phase) | 146 | // public void SendViewerTime(int phase) |
147 | // { | 147 | // { |
148 | // Console.WriteLine("SunPhase: {0}", phase); | 148 | // Console.WriteLine("SunPhase: {0}", phase); |
149 | // SimulatorViewerTimeMessagePacket viewertime = new SimulatorViewerTimeMessagePacket(); | 149 | // SimulatorViewerTimeMessagePacket viewertime = new SimulatorViewerTimeMessagePacket(); |
150 | // //viewertime.TimeInfo.SecPerDay = 86400; | 150 | // //viewertime.TimeInfo.SecPerDay = 86400; |
151 | // // viewertime.TimeInfo.SecPerYear = 31536000; | 151 | // // viewertime.TimeInfo.SecPerYear = 31536000; |
152 | // viewertime.TimeInfo.SecPerDay = 1000; | 152 | // viewertime.TimeInfo.SecPerDay = 1000; |
153 | // viewertime.TimeInfo.SecPerYear = 365000; | 153 | // viewertime.TimeInfo.SecPerYear = 365000; |
154 | // viewertime.TimeInfo.SunPhase = 1; | 154 | // viewertime.TimeInfo.SunPhase = 1; |
155 | // int sunPhase = (phase + 2)/2; | 155 | // int sunPhase = (phase + 2)/2; |
156 | // if ((sunPhase < 6) || (sunPhase > 36)) | 156 | // if ((sunPhase < 6) || (sunPhase > 36)) |
157 | // { | 157 | // { |
158 | // viewertime.TimeInfo.SunDirection = new LLVector3(0f, 0.8f, -0.8f); | 158 | // viewertime.TimeInfo.SunDirection = new LLVector3(0f, 0.8f, -0.8f); |
159 | // Console.WriteLine("sending night"); | 159 | // Console.WriteLine("sending night"); |
160 | // } | 160 | // } |
161 | // else | 161 | // else |
162 | // { | 162 | // { |
163 | // if (sunPhase < 12) | 163 | // if (sunPhase < 12) |
164 | // { | 164 | // { |
165 | // sunPhase = 12; | 165 | // sunPhase = 12; |
166 | // } | 166 | // } |
167 | // sunPhase = sunPhase - 12; | 167 | // sunPhase = sunPhase - 12; |
168 | // | 168 | // |
169 | // float yValue = 0.1f*(sunPhase); | 169 | // float yValue = 0.1f*(sunPhase); |
170 | // Console.WriteLine("Computed SunPhase: {0}, yValue: {1}", sunPhase, yValue); | 170 | // Console.WriteLine("Computed SunPhase: {0}, yValue: {1}", sunPhase, yValue); |
171 | // if (yValue > 1.2f) | 171 | // if (yValue > 1.2f) |
172 | // { | 172 | // { |
173 | // yValue = yValue - 1.2f; | 173 | // yValue = yValue - 1.2f; |
174 | // } | 174 | // } |
175 | // if (yValue > 1) | 175 | // if (yValue > 1) |
176 | // { | 176 | // { |
177 | // yValue = 1; | 177 | // yValue = 1; |
178 | // } | 178 | // } |
179 | // if (yValue < 0) | 179 | // if (yValue < 0) |
180 | // { | 180 | // { |
181 | // yValue = 0; | 181 | // yValue = 0; |
182 | // } | 182 | // } |
183 | // if (sunPhase < 14) | 183 | // if (sunPhase < 14) |
184 | // { | 184 | // { |
185 | // yValue = 1 - yValue; | 185 | // yValue = 1 - yValue; |
186 | // } | 186 | // } |
187 | // if (sunPhase < 12) | 187 | // if (sunPhase < 12) |
188 | // { | 188 | // { |
189 | // yValue *= -1; | 189 | // yValue *= -1; |
190 | // } | 190 | // } |
191 | // viewertime.TimeInfo.SunDirection = new LLVector3(0f, yValue, 0.3f); | 191 | // viewertime.TimeInfo.SunDirection = new LLVector3(0f, yValue, 0.3f); |
192 | // Console.WriteLine("sending sun update " + yValue); | 192 | // Console.WriteLine("sending sun update " + yValue); |
193 | // } | 193 | // } |
194 | // viewertime.TimeInfo.SunAngVelocity = new LLVector3(0, 0.0f, 10.0f); | 194 | // viewertime.TimeInfo.SunAngVelocity = new LLVector3(0, 0.0f, 10.0f); |
195 | // viewertime.TimeInfo.UsecSinceStart = (ulong) Util.UnixTimeSinceEpoch(); | 195 | // viewertime.TimeInfo.UsecSinceStart = (ulong) Util.UnixTimeSinceEpoch(); |
196 | // // OutPacket(viewertime); | 196 | // // OutPacket(viewertime); |
197 | // } | 197 | // } |
198 | } | 198 | } |
199 | } \ No newline at end of file | 199 | } \ No newline at end of file |