diff options
Diffstat (limited to 'OpenSim/Region/Environment/Modules')
-rw-r--r-- | OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs | 92 |
1 files changed, 87 insertions, 5 deletions
diff --git a/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs b/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs index 4f8b377..24b3f50 100644 --- a/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs +++ b/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs | |||
@@ -49,6 +49,11 @@ namespace OpenSim.Region.Environment.Modules.Terrain | |||
49 | void FloodEffect(ITerrainChannel map, Boolean[,] fillArea, double strength); | 49 | void FloodEffect(ITerrainChannel map, Boolean[,] fillArea, double strength); |
50 | } | 50 | } |
51 | 51 | ||
52 | public interface ITerrainEffect | ||
53 | { | ||
54 | void RunEffect(ITerrainChannel map, double strength); | ||
55 | } | ||
56 | |||
52 | /// <summary> | 57 | /// <summary> |
53 | /// A new version of the old Channel class, simplified | 58 | /// A new version of the old Channel class, simplified |
54 | /// </summary> | 59 | /// </summary> |
@@ -103,16 +108,97 @@ namespace OpenSim.Region.Environment.Modules.Terrain | |||
103 | } | 108 | } |
104 | } | 109 | } |
105 | 110 | ||
111 | public enum StandardTerrainEffects : byte | ||
112 | { | ||
113 | Flatten = 0, | ||
114 | Raise = 1, | ||
115 | Lower = 2, | ||
116 | Smooth = 3, | ||
117 | Noise = 4, | ||
118 | Revert = 5 | ||
119 | } | ||
120 | |||
106 | public class TerrainModule : IRegionModule | 121 | public class TerrainModule : IRegionModule |
107 | { | 122 | { |
108 | Scene m_scene; | 123 | private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); |
109 | 124 | ||
125 | private Dictionary<StandardTerrainEffects, ITerrainPaintableEffect> m_painteffects = | ||
126 | new Dictionary<StandardTerrainEffects, ITerrainPaintableEffect>(); | ||
127 | private Dictionary<StandardTerrainEffects, ITerrainFloodEffect> m_floodeffects = | ||
128 | new Dictionary<StandardTerrainEffects, ITerrainFloodEffect>(); | ||
129 | Scene m_scene; | ||
130 | ITerrainChannel m_channel; | ||
110 | private IConfigSource m_gConfig; | 131 | private IConfigSource m_gConfig; |
111 | 132 | ||
133 | private void InstallDefaultEffects() | ||
134 | { | ||
135 | m_painteffects[StandardTerrainEffects.Raise] = new PaintBrushes.RaiseSphere(); | ||
136 | m_floodeffects[StandardTerrainEffects.Raise] = new FloodBrushes.RaiseArea(); | ||
137 | } | ||
138 | |||
112 | public void Initialise(Scene scene, IConfigSource config) | 139 | public void Initialise(Scene scene, IConfigSource config) |
113 | { | 140 | { |
114 | m_scene = scene; | 141 | m_scene = scene; |
115 | m_gConfig = config; | 142 | m_gConfig = config; |
143 | |||
144 | m_channel = new TerrainChannel(); | ||
145 | m_scene.EventManager.OnNewClient += EventManager_OnNewClient; | ||
146 | } | ||
147 | |||
148 | void EventManager_OnNewClient(IClientAPI client) | ||
149 | { | ||
150 | client.OnModifyTerrain += client_OnModifyTerrain; | ||
151 | } | ||
152 | |||
153 | void client_OnModifyTerrain(float height, float seconds, byte size, byte action, float north, float west, float south, float east, IClientAPI remoteClient) | ||
154 | { | ||
155 | // Not a good permissions check, if in area mode, need to check the entire area. | ||
156 | if (m_scene.PermissionsMngr.CanTerraform(remoteClient.AgentId, new LLVector3(north, west, 0))) | ||
157 | { | ||
158 | |||
159 | if (north == south && east == west) | ||
160 | { | ||
161 | if (m_painteffects.ContainsKey((StandardTerrainEffects)action)) | ||
162 | { | ||
163 | m_painteffects[(StandardTerrainEffects)action].PaintEffect( | ||
164 | m_channel, west, south, Math.Pow(size, 2.0)); | ||
165 | } | ||
166 | else | ||
167 | { | ||
168 | m_log.Debug("Unknown terrain brush type " + action.ToString()); | ||
169 | } | ||
170 | } | ||
171 | else | ||
172 | { | ||
173 | if (m_floodeffects.ContainsKey((StandardTerrainEffects)action)) | ||
174 | { | ||
175 | bool[,] fillArea = new bool[m_channel.Width, m_channel.Height]; | ||
176 | |||
177 | fillArea.Initialize(); | ||
178 | |||
179 | int x, y; | ||
180 | for (x = 0; x < m_channel.Width; x++) | ||
181 | { | ||
182 | for (y = 0; y < m_channel.Height; y++) | ||
183 | { | ||
184 | fillArea[x, y] = true; | ||
185 | } | ||
186 | } | ||
187 | |||
188 | m_floodeffects[(StandardTerrainEffects)action].FloodEffect( | ||
189 | m_channel, fillArea, Math.Pow(size, 2.0)); | ||
190 | } | ||
191 | else | ||
192 | { | ||
193 | m_log.Debug("Unknown terrain flood type " + action.ToString()); | ||
194 | } | ||
195 | } | ||
196 | } | ||
197 | } | ||
198 | |||
199 | public void PostInitialise() | ||
200 | { | ||
201 | InstallDefaultEffects(); | ||
116 | } | 202 | } |
117 | 203 | ||
118 | public void Close() | 204 | public void Close() |
@@ -128,9 +214,5 @@ namespace OpenSim.Region.Environment.Modules.Terrain | |||
128 | { | 214 | { |
129 | get { return false; } | 215 | get { return false; } |
130 | } | 216 | } |
131 | |||
132 | public void PostInitialise() | ||
133 | { | ||
134 | } | ||
135 | } | 217 | } |
136 | } | 218 | } |