aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorAdam Frisby2008-04-22 07:53:32 +0000
committerAdam Frisby2008-04-22 07:53:32 +0000
commitc8eb8d66fdedebbbb82348a9a60cd47fb0955305 (patch)
tree24572c1d599a1b9e249b190070e1cebbcbc29583 /OpenSim
parent* Added missing reference to OpenSim.Framework.Communications to RemoteAdminP... (diff)
downloadopensim-SC_OLD-c8eb8d66fdedebbbb82348a9a60cd47fb0955305.zip
opensim-SC_OLD-c8eb8d66fdedebbbb82348a9a60cd47fb0955305.tar.gz
opensim-SC_OLD-c8eb8d66fdedebbbb82348a9a60cd47fb0955305.tar.bz2
opensim-SC_OLD-c8eb8d66fdedebbbb82348a9a60cd47fb0955305.tar.xz
* Committing new terrain plugin effects system. Loads DLLs in /bin/Terrain/ as terrain module extensions. Committing sample plugin library.
* prebuild.xml changes.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs83
-rw-r--r--OpenSim/Region/Modules/Terrain/Extensions/DefaultEffects/Effects/ChannelDigger.cs80
2 files changed, 153 insertions, 10 deletions
diff --git a/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs b/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs
index f758c91..40d4771 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs
@@ -35,7 +35,6 @@ using Nini.Config;
35using OpenSim.Framework; 35using OpenSim.Framework;
36using OpenSim.Region.Environment.Interfaces; 36using OpenSim.Region.Environment.Interfaces;
37using OpenSim.Region.Environment.Modules.ModuleFramework; 37using OpenSim.Region.Environment.Modules.ModuleFramework;
38using OpenSim.Region.Environment.Modules.Terrain.Effects;
39using OpenSim.Region.Environment.Modules.Terrain.FileLoaders; 38using OpenSim.Region.Environment.Modules.Terrain.FileLoaders;
40using OpenSim.Region.Environment.Modules.Terrain.FloodBrushes; 39using OpenSim.Region.Environment.Modules.Terrain.FloodBrushes;
41using OpenSim.Region.Environment.Modules.Terrain.PaintBrushes; 40using OpenSim.Region.Environment.Modules.Terrain.PaintBrushes;
@@ -80,6 +79,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain
80 new Dictionary<StandardTerrainEffects, ITerrainPaintableEffect>(); 79 new Dictionary<StandardTerrainEffects, ITerrainPaintableEffect>();
81 80
82 private ITerrainChannel m_channel; 81 private ITerrainChannel m_channel;
82 private Dictionary<string, ITerrainEffect> m_plugineffects;
83 private ITerrainChannel m_revert; 83 private ITerrainChannel m_revert;
84 private Scene m_scene; 84 private Scene m_scene;
85 private bool m_tainted = false; 85 private bool m_tainted = false;
@@ -135,6 +135,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain
135 { 135 {
136 InstallDefaultEffects(); 136 InstallDefaultEffects();
137 InstallInterfaces(); 137 InstallInterfaces();
138 LoadPlugins();
138 } 139 }
139 140
140 public void Close() 141 public void Close()
@@ -184,7 +185,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain
184 { 185 {
185 m_log.Error( 186 m_log.Error(
186 "[TERRAIN]: Unable to load heightmap, file not found. (A directory permissions error may also cause this)"); 187 "[TERRAIN]: Unable to load heightmap, file not found. (A directory permissions error may also cause this)");
187 throw new Exception(String.Format("unable to load heightmap: file {0} not found (or permissions do not allow access", 188 throw new Exception(String.Format("unable to load heightmap: file {0} not found (or permissions do not allow access",
188 filename)); 189 filename));
189 } 190 }
190 } 191 }
@@ -194,7 +195,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain
194 } 195 }
195 } 196 }
196 m_log.Error("[TERRAIN]: Unable to load heightmap, no file loader availible for that format."); 197 m_log.Error("[TERRAIN]: Unable to load heightmap, no file loader availible for that format.");
197 throw new Exception(String.Format("unable to load heightmap from file {0}: no loader available for that format", 198 throw new Exception(String.Format("unable to load heightmap from file {0}: no loader available for that format",
198 filename)); 199 filename));
199 } 200 }
200 201
@@ -222,6 +223,46 @@ namespace OpenSim.Region.Environment.Modules.Terrain
222 } 223 }
223 } 224 }
224 225
226 #region Plugin Loading Methods
227
228 private void LoadPlugins()
229 {
230 m_plugineffects = new Dictionary<string, ITerrainEffect>();
231 // Load the files in the Terrain/ dir
232 string[] files = Directory.GetFiles("Terrain");
233 foreach (string file in files)
234 {
235 m_log.Info("Loading effects in " + file);
236 try
237 {
238 Assembly library = Assembly.LoadFrom(file);
239 foreach (Type pluginType in library.GetTypes())
240 {
241 try
242 {
243 if (pluginType.IsAbstract || pluginType.IsNotPublic)
244 continue;
245
246 if (pluginType.GetInterface("ITerrainEffect", false) != null)
247 {
248 ITerrainEffect terEffect = (ITerrainEffect) Activator.CreateInstance(library.GetType(pluginType.ToString()));
249 m_plugineffects.Add(pluginType.Name, terEffect);
250 m_log.Info("... " + pluginType.Name);
251 }
252 }
253 catch (AmbiguousMatchException)
254 {
255 }
256 }
257 }
258 catch (BadImageFormatException)
259 {
260 }
261 }
262 }
263
264 #endregion
265
225 #endregion 266 #endregion
226 267
227 /// <summary> 268 /// <summary>
@@ -564,10 +605,31 @@ namespace OpenSim.Region.Environment.Modules.Terrain
564 } 605 }
565 } 606 }
566 607
567 private void InterfacePerformEffectTest(Object[] args) 608 private void InterfaceRunPluginEffect(Object[] args)
568 { 609 {
569 CookieCutter cookie = new CookieCutter(); 610 if ((string) args[0] == "list")
570 cookie.RunEffect(m_channel); 611 {
612 m_log.Info("List of loaded plugins");
613 foreach (KeyValuePair<string, ITerrainEffect> kvp in m_plugineffects)
614 {
615 m_log.Info(kvp.Key);
616 }
617 return;
618 }
619 if ((string) args[0] == "reload")
620 {
621 LoadPlugins();
622 return;
623 }
624 if (m_plugineffects.ContainsKey((string) args[0]))
625 {
626 m_plugineffects[(string) args[0]].RunEffect(m_channel);
627 CheckForTerrainUpdates();
628 }
629 else
630 {
631 m_log.Warn("No such plugin effect loaded.");
632 }
571 } 633 }
572 634
573 private void InstallInterfaces() 635 private void InstallInterfaces()
@@ -634,9 +696,10 @@ namespace OpenSim.Region.Environment.Modules.Terrain
634 "Enables experimental brushes which replace the standard terrain brushes. WARNING: This is a debug setting and may be removed at any time."); 696 "Enables experimental brushes which replace the standard terrain brushes. WARNING: This is a debug setting and may be removed at any time.");
635 experimentalBrushesCommand.AddArgument("Enabled?", "true / false - Enable new brushes", "Boolean"); 697 experimentalBrushesCommand.AddArgument("Enabled?", "true / false - Enable new brushes", "Boolean");
636 698
637 // Effects 699 //Plugins
638 Command effectsTestCommand = 700 Command pluginRunCommand =
639 new Command("test", InterfacePerformEffectTest, "Performs an effects module test"); 701 new Command("effect", InterfaceRunPluginEffect, "Runs a specified plugin effect");
702 pluginRunCommand.AddArgument("name", "The plugin effect you wish to run, or 'list' to see all plugins", "String");
640 703
641 m_commander.RegisterCommand("load", loadFromFileCommand); 704 m_commander.RegisterCommand("load", loadFromFileCommand);
642 m_commander.RegisterCommand("load-tile", loadFromTileCommand); 705 m_commander.RegisterCommand("load-tile", loadFromTileCommand);
@@ -648,8 +711,8 @@ namespace OpenSim.Region.Environment.Modules.Terrain
648 m_commander.RegisterCommand("bake", bakeRegionCommand); 711 m_commander.RegisterCommand("bake", bakeRegionCommand);
649 m_commander.RegisterCommand("revert", revertRegionCommand); 712 m_commander.RegisterCommand("revert", revertRegionCommand);
650 m_commander.RegisterCommand("newbrushes", experimentalBrushesCommand); 713 m_commander.RegisterCommand("newbrushes", experimentalBrushesCommand);
651 m_commander.RegisterCommand("test", effectsTestCommand);
652 m_commander.RegisterCommand("stats", showDebugStatsCommand); 714 m_commander.RegisterCommand("stats", showDebugStatsCommand);
715 m_commander.RegisterCommand("effect", pluginRunCommand);
653 716
654 // Add this to our scene so scripts can call these functions 717 // Add this to our scene so scripts can call these functions
655 m_scene.RegisterModuleCommander("Terrain", m_commander); 718 m_scene.RegisterModuleCommander("Terrain", m_commander);
diff --git a/OpenSim/Region/Modules/Terrain/Extensions/DefaultEffects/Effects/ChannelDigger.cs b/OpenSim/Region/Modules/Terrain/Extensions/DefaultEffects/Effects/ChannelDigger.cs
new file mode 100644
index 0000000..2f2c04e
--- /dev/null
+++ b/OpenSim/Region/Modules/Terrain/Extensions/DefaultEffects/Effects/ChannelDigger.cs
@@ -0,0 +1,80 @@
1using System;
2using OpenSim.Region.Environment.Interfaces;
3using OpenSim.Region.Environment.Modules.Terrain;
4using OpenSim.Region.Environment.Modules.Terrain.FloodBrushes;
5
6namespace OpenSim.Region.Modules.Terrain.Extensions.DefaultEffects.Effects
7{
8 public class ChannelDigger : ITerrainEffect
9 {
10 private readonly int num_h = 4;
11 private readonly int num_w = 4;
12
13 private readonly ITerrainFloodEffect raiseFunction = new RaiseArea();
14 private readonly ITerrainFloodEffect smoothFunction = new SmoothArea();
15
16 #region ITerrainEffect Members
17
18 public void RunEffect(ITerrainChannel map)
19 {
20 FillMap(map, 15);
21 BuildTiles(map, 7);
22 SmoothMap(map, 3);
23 }
24
25 #endregion
26
27 private void SmoothMap(ITerrainChannel map, int rounds)
28 {
29 Boolean[,] bitmap = new bool[map.Width,map.Height];
30 for (int x = 0; x < map.Width; x++)
31 {
32 for (int y = 0; y < map.Height; y++)
33 {
34 bitmap[x, y] = true;
35 }
36 }
37
38 for (int i = 0; i < rounds; i++)
39 {
40 smoothFunction.FloodEffect(map, bitmap, 1.0);
41 }
42 }
43
44 private void FillMap(ITerrainChannel map, double val)
45 {
46 for (int x = 0; x < map.Width; x++)
47 for (int y = 0; y < map.Height; y++)
48 map[x, y] = val;
49 }
50
51 private void BuildTiles(ITerrainChannel map, double height)
52 {
53 int channelWidth = (int) Math.Floor((map.Width / num_w) * 0.8);
54 int channelHeight = (int) Math.Floor((map.Height / num_h) * 0.8);
55 int channelXOffset = (map.Width / num_w) - channelWidth;
56 int channelYOffset = (map.Height / num_h) - channelHeight;
57
58 for (int x = 0; x < num_w; x++)
59 {
60 for (int y = 0; y < num_h; y++)
61 {
62 int xoff = ((channelXOffset + channelWidth) * x) + (channelXOffset / 2);
63 int yoff = ((channelYOffset + channelHeight) * y) + (channelYOffset / 2);
64
65 Boolean[,] bitmap = new bool[map.Width,map.Height];
66
67 for (int dx = 0; dx < channelWidth; dx++)
68 {
69 for (int dy = 0; dy < channelHeight; dy++)
70 {
71 bitmap[dx + xoff, dy + yoff] = true;
72 }
73 }
74
75 raiseFunction.FloodEffect(map, bitmap, height);
76 }
77 }
78 }
79 }
80} \ No newline at end of file