aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorSean Dague2007-11-07 22:22:32 +0000
committerSean Dague2007-11-07 22:22:32 +0000
commit288411222755afaeb7e7a9a56c106f60edfa2506 (patch)
tree4093a323a70eb85c5472090676a21b0a7ebd12bc /OpenSim/Region
parentUpdate of libraries MonoXnaCompactMaths and Modified BulletX cause an update ... (diff)
downloadopensim-SC-288411222755afaeb7e7a9a56c106f60edfa2506.zip
opensim-SC-288411222755afaeb7e7a9a56c106f60edfa2506.tar.gz
opensim-SC-288411222755afaeb7e7a9a56c106f60edfa2506.tar.bz2
opensim-SC-288411222755afaeb7e7a9a56c106f60edfa2506.tar.xz
move Sun into a Region Module, pass 1. Currently this works fine with
a fixed 30 minute day and the sun going East -> West again. It gets rid of super noon as well. It's a bit debug heavy right now, which I'll clean up tomorrow. I also plan to make time progression configurable in OpenSim.ini, but that will be tomorrow.
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/Environment/Modules/SunModule.cs178
-rw-r--r--OpenSim/Region/Environment/Scenes/Scene.cs4
-rw-r--r--OpenSim/Region/Environment/Scenes/ScenePresence.cs3
3 files changed, 182 insertions, 3 deletions
diff --git a/OpenSim/Region/Environment/Modules/SunModule.cs b/OpenSim/Region/Environment/Modules/SunModule.cs
new file mode 100644
index 0000000..2e266c2
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/SunModule.cs
@@ -0,0 +1,178 @@
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
29using System;
30using System.Collections.Generic;
31using Nini.Config;
32using OpenSim.Region.Environment.Interfaces;
33using OpenSim.Region.Environment.Scenes;
34using OpenSim.Framework;
35using OpenSim.Framework.Console;
36using libsecondlife;
37
38
39namespace OpenSim.Region.Environment.Modules
40{
41 public class SunModule : IRegionModule
42 {
43 private static double m_real_day = 24.0;
44 private static int m_frame_mod = 100;
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 private LogBase m_log;
52
53 public void Initialise(Scene scene, IConfigSource config)
54 {
55 m_start = DateTime.Now.Ticks;
56 m_frame = 0;
57 m_day_length = 0.5;
58 m_dilation = (int)(m_real_day / m_day_length);
59 m_scene = scene;
60 m_log = MainLog.Instance;
61 scene.EventManager.OnFrame += SunUpdate;
62 scene.EventManager.OnNewClient += SunToClient;
63 }
64
65 public void PostInitialise()
66 {
67 }
68
69 public void Close()
70 {
71 }
72
73 public string Name
74 {
75 get { return "SunModule"; }
76 }
77
78 public bool IsSharedModule
79 {
80 get { return false; }
81 }
82
83 public void SunToClient(IClientAPI client)
84 {
85 client.SendSunPos(SunPos(HourOfTheDay()), new LLVector3(0, 0.0f, 10.0f));
86 }
87
88 public void SunUpdate()
89 {
90 if (m_frame < m_frame_mod) {
91 m_frame++;
92 return;
93 }
94 m_log.Verbose("SUN","I've got an update {0} => {1}", m_scene.RegionsInfo.RegionName, HourOfTheDay());
95 List<ScenePresence> avatars = m_scene.GetAvatars();
96 foreach (ScenePresence avatar in avatars)
97 {
98 avatar.ControllingClient.SendSunPos(SunPos(HourOfTheDay()), new LLVector3(0, 0.0f, 10.0f));
99 }
100 m_frame = 0;
101 }
102
103 // Hour of the Day figures out the hour of the day as a float. The intent here is that we seed hour of the day with real time when the simulator starts, then run time forward faster based on time dilation factor. This means that ticks don't get out of hand
104 private double HourOfTheDay()
105 {
106 long m_addticks = (DateTime.Now.Ticks - m_start) * m_dilation;
107 DateTime dt = new DateTime(m_start + m_addticks);
108 return (double)dt.Hour + ((double)dt.Minute / 60.0);
109 }
110
111 private LLVector3 SunPos(double hour)
112 {
113 // now we have our radian position
114 double rad = (hour / m_real_day) * 2 * Math.PI - (Math.PI / 2.0);
115 double z = Math.Sin(rad);
116 double x = Math.Cos(rad);
117 return new LLVector3((float)x, 0f, (float)z);
118 }
119
120 // TODO: clear this out. This is here so that I remember to
121 // figure out if we need those other packet fields that I've
122 // left out so far
123 //
124 // public void SendViewerTime(int phase)
125 // {
126 // Console.WriteLine("SunPhase: {0}", phase);
127 // SimulatorViewerTimeMessagePacket viewertime = new SimulatorViewerTimeMessagePacket();
128 // //viewertime.TimeInfo.SecPerDay = 86400;
129 // // viewertime.TimeInfo.SecPerYear = 31536000;
130 // viewertime.TimeInfo.SecPerDay = 1000;
131 // viewertime.TimeInfo.SecPerYear = 365000;
132 // viewertime.TimeInfo.SunPhase = 1;
133 // int sunPhase = (phase + 2)/2;
134 // if ((sunPhase < 6) || (sunPhase > 36))
135 // {
136 // viewertime.TimeInfo.SunDirection = new LLVector3(0f, 0.8f, -0.8f);
137 // Console.WriteLine("sending night");
138 // }
139 // else
140 // {
141 // if (sunPhase < 12)
142 // {
143 // sunPhase = 12;
144 // }
145 // sunPhase = sunPhase - 12;
146
147 // float yValue = 0.1f*(sunPhase);
148 // Console.WriteLine("Computed SunPhase: {0}, yValue: {1}", sunPhase, yValue);
149 // if (yValue > 1.2f)
150 // {
151 // yValue = yValue - 1.2f;
152 // }
153 // if (yValue > 1)
154 // {
155 // yValue = 1;
156 // }
157 // if (yValue < 0)
158 // {
159 // yValue = 0;
160 // }
161 // if (sunPhase < 14)
162 // {
163 // yValue = 1 - yValue;
164 // }
165 // if (sunPhase < 12)
166 // {
167 // yValue *= -1;
168 // }
169 // viewertime.TimeInfo.SunDirection = new LLVector3(0f, yValue, 0.3f);
170 // Console.WriteLine("sending sun update " + yValue);
171 // }
172 // viewertime.TimeInfo.SunAngVelocity = new LLVector3(0, 0.0f, 10.0f);
173 // viewertime.TimeInfo.UsecSinceStart = (ulong) Util.UnixTimeSinceEpoch();
174 // // OutPacket(viewertime);
175 // }
176
177 }
178} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs
index d436bb3..7e1bbfa 100644
--- a/OpenSim/Region/Environment/Scenes/Scene.cs
+++ b/OpenSim/Region/Environment/Scenes/Scene.cs
@@ -324,8 +324,8 @@ namespace OpenSim.Region.Environment.Scenes
324 if (m_frame%m_update_land == 0) 324 if (m_frame%m_update_land == 0)
325 UpdateLand(); 325 UpdateLand();
326 326
327 if (m_frame%m_update_avatars == 0) 327 // if (m_frame%m_update_avatars == 0)
328 UpdateInWorldTime(); 328 // UpdateInWorldTime();
329 } 329 }
330 catch (NotImplementedException) 330 catch (NotImplementedException)
331 { 331 {
diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.cs
index b08f39f..789bd68 100644
--- a/OpenSim/Region/Environment/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Environment/Scenes/ScenePresence.cs
@@ -855,7 +855,8 @@ namespace OpenSim.Region.Environment.Scenes
855 { 855 {
856 SendOwnWearables( ); 856 SendOwnWearables( );
857 m_scene.SendAllSceneObjectsToClient(this); 857 m_scene.SendAllSceneObjectsToClient(this);
858 m_controllingClient.SendViewerTime(m_scene.TimePhase); 858 // TODO: remove this once the SunModule is slightly more tested
859 // m_controllingClient.SendViewerTime(m_scene.TimePhase);
859 } 860 }
860 861
861 /// <summary> 862 /// <summary>