aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules
diff options
context:
space:
mode:
authorAdam Frisby2008-04-30 21:17:32 +0000
committerAdam Frisby2008-04-30 21:17:32 +0000
commit8b0c795a5ef21d030884e4f23aa527b737e49cdb (patch)
tree433ece0ecdc6292351a668927660d19761ab5b52 /OpenSim/Region/Environment/Modules
parent* Refactored Environment/Modules directory - modules now reside in their own ... (diff)
downloadopensim-SC-8b0c795a5ef21d030884e4f23aa527b737e49cdb.zip
opensim-SC-8b0c795a5ef21d030884e4f23aa527b737e49cdb.tar.gz
opensim-SC-8b0c795a5ef21d030884e4f23aa527b737e49cdb.tar.bz2
opensim-SC-8b0c795a5ef21d030884e4f23aa527b737e49cdb.tar.xz
* Previous commit managed to miss some files despite me hitting 'Select all'.
* Attached.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Environment/Modules/World/Sun/SunModule.cs195
-rw-r--r--OpenSim/Region/Environment/Modules/World/TreePopulator/TreePopulatorModule.cs248
2 files changed, 443 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/Sun/SunModule.cs b/OpenSim/Region/Environment/Modules/World/Sun/SunModule.cs
new file mode 100644
index 0000000..a465a60
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/World/Sun/SunModule.cs
@@ -0,0 +1,195 @@
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
28using System;
29using System.Collections.Generic;
30using libsecondlife;
31using Nini.Config;
32using OpenSim.Framework;
33using OpenSim.Region.Environment.Interfaces;
34using OpenSim.Region.Environment.Scenes;
35
36namespace 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}
diff --git a/OpenSim/Region/Environment/Modules/World/TreePopulator/TreePopulatorModule.cs b/OpenSim/Region/Environment/Modules/World/TreePopulator/TreePopulatorModule.cs
new file mode 100644
index 0000000..ce93060
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/World/TreePopulator/TreePopulatorModule.cs
@@ -0,0 +1,248 @@
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
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using System.Timers;
32using Axiom.Math;
33using libsecondlife;
34using log4net;
35using Nini.Config;
36using OpenSim.Framework;
37using OpenSim.Region.Environment.Interfaces;
38using OpenSim.Region.Environment.Scenes;
39
40namespace OpenSim.Region.Environment.Modules
41{
42 /// <summary>
43 /// Version 2.0 - Very hacky compared to the original. Will fix original and release as 0.3 later.
44 /// </summary>
45 public class TreePopulatorModule : IRegionModule
46 {
47 private Scene m_scene;
48 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49
50 private List<LLUUID> m_trees;
51
52 public double m_tree_density = 50.0; // Aim for this many per region
53 public double m_tree_updates = 1000.0; // MS between updates
54
55 public void Initialise(Scene scene, IConfigSource config)
56 {
57 try
58 {
59 m_tree_density = config.Configs["Trees"].GetDouble("tree_density", m_tree_density);
60 }
61 catch (Exception)
62 { }
63
64 m_trees = new List<LLUUID>();
65 m_scene = scene;
66
67 m_scene.EventManager.OnPluginConsole += new EventManager.OnPluginConsoleDelegate(EventManager_OnPluginConsole);
68
69 Timer CalculateTrees = new Timer(m_tree_updates);
70 CalculateTrees.Elapsed += new ElapsedEventHandler(CalculateTrees_Elapsed);
71 CalculateTrees.Start();
72 m_log.Debug("[TREES]: Initialised tree module");
73 }
74
75 void EventManager_OnPluginConsole(string[] args)
76 {
77 if (args[0] == "tree")
78 {
79 m_log.Debug("[TREES]: New tree planting");
80 CreateTree(new LLVector3(128.0f, 128.0f, 0.0f));
81 }
82 }
83
84 void growTrees()
85 {
86 foreach (LLUUID tree in m_trees)
87 {
88 if (m_scene.Entities.ContainsKey(tree))
89 {
90 SceneObjectPart s_tree = ((SceneObjectGroup)m_scene.Entities[tree]).RootPart;
91
92 // 100 seconds to grow 1m
93 s_tree.Scale += new LLVector3(0.1f, 0.1f, 0.1f);
94 s_tree.SendFullUpdateToAllClients();
95 //s_tree.ScheduleTerseUpdate();
96 }
97 else
98 {
99 m_trees.Remove(tree);
100 }
101 }
102 }
103
104 void seedTrees()
105 {
106 foreach (LLUUID tree in m_trees)
107 {
108 if (m_scene.Entities.ContainsKey(tree))
109 {
110 SceneObjectPart s_tree = ((SceneObjectGroup)m_scene.Entities[tree]).RootPart;
111
112 if (s_tree.Scale.X > 0.5)
113 {
114 if (Util.RandomClass.NextDouble() > 0.75)
115 {
116 SpawnChild(s_tree);
117 }
118 }
119
120 }
121 else
122 {
123 m_trees.Remove(tree);
124 }
125 }
126 }
127
128 void killTrees()
129 {
130 foreach (LLUUID tree in m_trees)
131 {
132 double killLikelyhood = 0.0;
133
134 if (m_scene.Entities.ContainsKey(tree))
135 {
136 SceneObjectPart selectedTree = ((SceneObjectGroup)m_scene.Entities[tree]).RootPart;
137 double selectedTreeScale = Math.Sqrt(Math.Pow(selectedTree.Scale.X, 2) +
138 Math.Pow(selectedTree.Scale.Y, 2) +
139 Math.Pow(selectedTree.Scale.Z, 2));
140
141 foreach (LLUUID picktree in m_trees)
142 {
143 if (picktree != tree)
144 {
145 SceneObjectPart pickedTree = ((SceneObjectGroup)m_scene.Entities[picktree]).RootPart;
146
147 double pickedTreeScale = Math.Sqrt(Math.Pow(pickedTree.Scale.X, 2) +
148 Math.Pow(pickedTree.Scale.Y, 2) +
149 Math.Pow(pickedTree.Scale.Z, 2));
150
151 double pickedTreeDistance = Math.Sqrt(Math.Pow(Math.Abs(pickedTree.AbsolutePosition.X - selectedTree.AbsolutePosition.X), 2) +
152 Math.Pow(Math.Abs(pickedTree.AbsolutePosition.Y - selectedTree.AbsolutePosition.Y), 2) +
153 Math.Pow(Math.Abs(pickedTree.AbsolutePosition.Z - selectedTree.AbsolutePosition.Z), 2));
154
155 killLikelyhood += (selectedTreeScale / (pickedTreeScale * pickedTreeDistance)) * 0.1;
156 }
157 }
158
159 if (Util.RandomClass.NextDouble() < killLikelyhood)
160 {
161 m_scene.RemoveEntity(selectedTree.ParentGroup);
162 m_trees.Remove(selectedTree.ParentGroup.UUID);
163
164 m_scene.ForEachClient(delegate(IClientAPI controller)
165 {
166 controller.SendKillObject(m_scene.RegionInfo.RegionHandle,
167 selectedTree.LocalId);
168 });
169
170 break;
171 }
172 else
173 {
174 selectedTree.SetText(killLikelyhood.ToString(), new Vector3(1.0f, 1.0f, 1.0f), 1.0);
175 }
176 }
177 else
178 {
179 m_trees.Remove(tree);
180 }
181 }
182 }
183
184 private void SpawnChild(SceneObjectPart s_tree)
185 {
186 LLVector3 position = new LLVector3();
187
188 position.X = s_tree.AbsolutePosition.X + (1 * (-1 * Util.RandomClass.Next(1)));
189 if (position.X > 255)
190 position.X = 255;
191 if (position.X < 0)
192 position.X = 0;
193 position.Y = s_tree.AbsolutePosition.Y + (1 * (-1 * Util.RandomClass.Next(1)));
194 if (position.Y > 255)
195 position.Y = 255;
196 if (position.Y < 0)
197 position.Y = 0;
198
199 double randX = ((Util.RandomClass.NextDouble() * 2.0) - 1.0) * (s_tree.Scale.X * 3);
200 double randY = ((Util.RandomClass.NextDouble() * 2.0) - 1.0) * (s_tree.Scale.X * 3);
201
202 position.X += (float)randX;
203 position.Y += (float)randY;
204
205 CreateTree(position);
206 }
207
208 private void CreateTree(LLVector3 position)
209 {
210 position.Z = (float)m_scene.Heightmap[(int)position.X, (int)position.Y];
211
212 SceneObjectGroup tree =
213 m_scene.AddTree(new LLVector3(0.1f, 0.1f, 0.1f),
214 LLQuaternion.Identity,
215 position,
216 Tree.Cypress1,
217 false);
218
219 m_trees.Add(tree.UUID);
220 tree.SendGroupFullUpdate();
221 }
222
223 void CalculateTrees_Elapsed(object sender, ElapsedEventArgs e)
224 {
225 growTrees();
226 seedTrees();
227 killTrees();
228 }
229
230 public void PostInitialise()
231 {
232 }
233
234 public void Close()
235 {
236 }
237
238 public string Name
239 {
240 get { return "TreePopulatorModule"; }
241 }
242
243 public bool IsSharedModule
244 {
245 get { return false; }
246 }
247 }
248}