diff options
author | Justin Clark-Casey (justincc) | 2013-01-10 00:32:22 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2013-01-10 00:32:22 +0000 |
commit | a0000a034f3d193662d56a1c8147771b0d994b23 (patch) | |
tree | 0ce737f2fa35002f43621a2107dfe90050ec3ab7 /OpenSim/Region/ScriptEngine | |
parent | minor: Remove unnecessary commented out code from last commit c28a2f05 and fi... (diff) | |
download | opensim-SC-a0000a034f3d193662d56a1c8147771b0d994b23.zip opensim-SC-a0000a034f3d193662d56a1c8147771b0d994b23.tar.gz opensim-SC-a0000a034f3d193662d56a1c8147771b0d994b23.tar.bz2 opensim-SC-a0000a034f3d193662d56a1c8147771b0d994b23.tar.xz |
Add "show sensors" command to show script sensor information for debug purposes.
Diffstat (limited to 'OpenSim/Region/ScriptEngine')
3 files changed, 153 insertions, 32 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs index 24cceea..37422d7 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs | |||
@@ -42,6 +42,41 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
42 | { | 42 | { |
43 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 43 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
44 | 44 | ||
45 | /// <summary> | ||
46 | /// Used by one-off and repeated sensors | ||
47 | /// </summary> | ||
48 | public class SensorInfo | ||
49 | { | ||
50 | public uint localID; | ||
51 | public UUID itemID; | ||
52 | public double interval; | ||
53 | public DateTime next; | ||
54 | |||
55 | public string name; | ||
56 | public UUID keyID; | ||
57 | public int type; | ||
58 | public double range; | ||
59 | public double arc; | ||
60 | public SceneObjectPart host; | ||
61 | |||
62 | public SensorInfo Clone() | ||
63 | { | ||
64 | SensorInfo s = new SensorInfo(); | ||
65 | s.localID = localID; | ||
66 | s.itemID = itemID; | ||
67 | s.interval = interval; | ||
68 | s.next = next; | ||
69 | s.name = name; | ||
70 | s.keyID = keyID; | ||
71 | s.type = type; | ||
72 | s.range = range; | ||
73 | s.arc = arc; | ||
74 | s.host = host; | ||
75 | |||
76 | return s; | ||
77 | } | ||
78 | } | ||
79 | |||
45 | public AsyncCommandManager m_CmdManager; | 80 | public AsyncCommandManager m_CmdManager; |
46 | 81 | ||
47 | /// <summary> | 82 | /// <summary> |
@@ -79,24 +114,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
79 | private int maximumToReturn = 16; | 114 | private int maximumToReturn = 16; |
80 | 115 | ||
81 | // | 116 | // |
82 | // SenseRepeater and Sensors | ||
83 | // | ||
84 | private class SenseRepeatClass | ||
85 | { | ||
86 | public uint localID; | ||
87 | public UUID itemID; | ||
88 | public double interval; | ||
89 | public DateTime next; | ||
90 | |||
91 | public string name; | ||
92 | public UUID keyID; | ||
93 | public int type; | ||
94 | public double range; | ||
95 | public double arc; | ||
96 | public SceneObjectPart host; | ||
97 | } | ||
98 | |||
99 | // | ||
100 | // Sensed entity | 117 | // Sensed entity |
101 | // | 118 | // |
102 | private class SensedEntity : IComparable | 119 | private class SensedEntity : IComparable |
@@ -128,7 +145,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
128 | /// | 145 | /// |
129 | /// Always lock SenseRepeatListLock when updating this list. | 146 | /// Always lock SenseRepeatListLock when updating this list. |
130 | /// </remarks> | 147 | /// </remarks> |
131 | private List<SenseRepeatClass> SenseRepeaters = new List<SenseRepeatClass>(); | 148 | private List<SensorInfo> SenseRepeaters = new List<SensorInfo>(); |
132 | private object SenseRepeatListLock = new object(); | 149 | private object SenseRepeatListLock = new object(); |
133 | 150 | ||
134 | public void SetSenseRepeatEvent(uint m_localID, UUID m_itemID, | 151 | public void SetSenseRepeatEvent(uint m_localID, UUID m_itemID, |
@@ -142,7 +159,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
142 | return; | 159 | return; |
143 | 160 | ||
144 | // Add to timer | 161 | // Add to timer |
145 | SenseRepeatClass ts = new SenseRepeatClass(); | 162 | SensorInfo ts = new SensorInfo(); |
146 | ts.localID = m_localID; | 163 | ts.localID = m_localID; |
147 | ts.itemID = m_itemID; | 164 | ts.itemID = m_itemID; |
148 | ts.interval = sec; | 165 | ts.interval = sec; |
@@ -161,11 +178,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
161 | AddSenseRepeater(ts); | 178 | AddSenseRepeater(ts); |
162 | } | 179 | } |
163 | 180 | ||
164 | private void AddSenseRepeater(SenseRepeatClass senseRepeater) | 181 | private void AddSenseRepeater(SensorInfo senseRepeater) |
165 | { | 182 | { |
166 | lock (SenseRepeatListLock) | 183 | lock (SenseRepeatListLock) |
167 | { | 184 | { |
168 | List<SenseRepeatClass> newSenseRepeaters = new List<SenseRepeatClass>(SenseRepeaters); | 185 | List<SensorInfo> newSenseRepeaters = new List<SensorInfo>(SenseRepeaters); |
169 | newSenseRepeaters.Add(senseRepeater); | 186 | newSenseRepeaters.Add(senseRepeater); |
170 | SenseRepeaters = newSenseRepeaters; | 187 | SenseRepeaters = newSenseRepeaters; |
171 | } | 188 | } |
@@ -176,8 +193,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
176 | // Remove from timer | 193 | // Remove from timer |
177 | lock (SenseRepeatListLock) | 194 | lock (SenseRepeatListLock) |
178 | { | 195 | { |
179 | List<SenseRepeatClass> newSenseRepeaters = new List<SenseRepeatClass>(); | 196 | List<SensorInfo> newSenseRepeaters = new List<SensorInfo>(); |
180 | foreach (SenseRepeatClass ts in SenseRepeaters) | 197 | foreach (SensorInfo ts in SenseRepeaters) |
181 | { | 198 | { |
182 | if (ts.localID != m_localID || ts.itemID != m_itemID) | 199 | if (ts.localID != m_localID || ts.itemID != m_itemID) |
183 | { | 200 | { |
@@ -192,7 +209,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
192 | public void CheckSenseRepeaterEvents() | 209 | public void CheckSenseRepeaterEvents() |
193 | { | 210 | { |
194 | // Go through all timers | 211 | // Go through all timers |
195 | foreach (SenseRepeatClass ts in SenseRepeaters) | 212 | foreach (SensorInfo ts in SenseRepeaters) |
196 | { | 213 | { |
197 | // Time has passed? | 214 | // Time has passed? |
198 | if (ts.next.ToUniversalTime() < DateTime.Now.ToUniversalTime()) | 215 | if (ts.next.ToUniversalTime() < DateTime.Now.ToUniversalTime()) |
@@ -209,7 +226,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
209 | double range, double arc, SceneObjectPart host) | 226 | double range, double arc, SceneObjectPart host) |
210 | { | 227 | { |
211 | // Add to timer | 228 | // Add to timer |
212 | SenseRepeatClass ts = new SenseRepeatClass(); | 229 | SensorInfo ts = new SensorInfo(); |
213 | ts.localID = m_localID; | 230 | ts.localID = m_localID; |
214 | ts.itemID = m_itemID; | 231 | ts.itemID = m_itemID; |
215 | ts.interval = 0; | 232 | ts.interval = 0; |
@@ -225,7 +242,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
225 | SensorSweep(ts); | 242 | SensorSweep(ts); |
226 | } | 243 | } |
227 | 244 | ||
228 | private void SensorSweep(SenseRepeatClass ts) | 245 | private void SensorSweep(SensorInfo ts) |
229 | { | 246 | { |
230 | if (ts.host == null) | 247 | if (ts.host == null) |
231 | { | 248 | { |
@@ -301,7 +318,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
301 | } | 318 | } |
302 | } | 319 | } |
303 | 320 | ||
304 | private List<SensedEntity> doObjectSensor(SenseRepeatClass ts) | 321 | private List<SensedEntity> doObjectSensor(SensorInfo ts) |
305 | { | 322 | { |
306 | List<EntityBase> Entities; | 323 | List<EntityBase> Entities; |
307 | List<SensedEntity> sensedEntities = new List<SensedEntity>(); | 324 | List<SensedEntity> sensedEntities = new List<SensedEntity>(); |
@@ -450,7 +467,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
450 | return sensedEntities; | 467 | return sensedEntities; |
451 | } | 468 | } |
452 | 469 | ||
453 | private List<SensedEntity> doAgentSensor(SenseRepeatClass ts) | 470 | private List<SensedEntity> doAgentSensor(SensorInfo ts) |
454 | { | 471 | { |
455 | List<SensedEntity> sensedEntities = new List<SensedEntity>(); | 472 | List<SensedEntity> sensedEntities = new List<SensedEntity>(); |
456 | 473 | ||
@@ -626,7 +643,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
626 | { | 643 | { |
627 | List<Object> data = new List<Object>(); | 644 | List<Object> data = new List<Object>(); |
628 | 645 | ||
629 | foreach (SenseRepeatClass ts in SenseRepeaters) | 646 | foreach (SensorInfo ts in SenseRepeaters) |
630 | { | 647 | { |
631 | if (ts.itemID == itemID) | 648 | if (ts.itemID == itemID) |
632 | { | 649 | { |
@@ -656,7 +673,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
656 | 673 | ||
657 | while (idx < data.Length) | 674 | while (idx < data.Length) |
658 | { | 675 | { |
659 | SenseRepeatClass ts = new SenseRepeatClass(); | 676 | SensorInfo ts = new SensorInfo(); |
660 | 677 | ||
661 | ts.localID = localID; | 678 | ts.localID = localID; |
662 | ts.itemID = itemID; | 679 | ts.itemID = itemID; |
@@ -677,5 +694,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
677 | idx += 6; | 694 | idx += 6; |
678 | } | 695 | } |
679 | } | 696 | } |
697 | |||
698 | public List<SensorInfo> GetSensorInfo() | ||
699 | { | ||
700 | List<SensorInfo> retList = new List<SensorInfo>(); | ||
701 | |||
702 | lock (SenseRepeatListLock) | ||
703 | { | ||
704 | foreach (SensorInfo si in SenseRepeaters) | ||
705 | retList.Add(si.Clone()); | ||
706 | } | ||
707 | |||
708 | return retList; | ||
709 | } | ||
680 | } | 710 | } |
681 | } | 711 | } \ No newline at end of file |
diff --git a/OpenSim/Region/ScriptEngine/XEngine/ScriptEngineConsoleCommands.cs b/OpenSim/Region/ScriptEngine/XEngine/ScriptEngineConsoleCommands.cs new file mode 100644 index 0000000..e47917d --- /dev/null +++ b/OpenSim/Region/ScriptEngine/XEngine/ScriptEngineConsoleCommands.cs | |||
@@ -0,0 +1,86 @@ | |||
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 OpenSimulator 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 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using OpenSim.Framework; | ||
31 | using OpenSim.Framework.Console; | ||
32 | using OpenSim.Region.ScriptEngine.Interfaces; | ||
33 | using OpenSim.Region.ScriptEngine.Shared.Api; | ||
34 | using OpenSim.Region.ScriptEngine.Shared.Api.Plugins; | ||
35 | |||
36 | namespace OpenSim.Region.ScriptEngine.XEngine | ||
37 | { | ||
38 | public class ScriptEngineConsoleCommands | ||
39 | { | ||
40 | IScriptEngine m_engine; | ||
41 | |||
42 | public ScriptEngineConsoleCommands(IScriptEngine engine) | ||
43 | { | ||
44 | m_engine = engine; | ||
45 | } | ||
46 | |||
47 | public void RegisterCommands() | ||
48 | { | ||
49 | MainConsole.Instance.Commands.AddCommand( | ||
50 | "Scripts", false, "show sensors", "show sensors", "Show script sensors information", | ||
51 | HandleShowSensors); | ||
52 | } | ||
53 | |||
54 | private void HandleShowSensors(string module, string[] cmdparams) | ||
55 | { | ||
56 | if (!(MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_engine.World)) | ||
57 | return; | ||
58 | |||
59 | SensorRepeat sr = AsyncCommandManager.GetSensorRepeatPlugin(m_engine); | ||
60 | |||
61 | if (sr == null) | ||
62 | { | ||
63 | MainConsole.Instance.Output("Sensor plugin not yet initialized"); | ||
64 | return; | ||
65 | } | ||
66 | |||
67 | List<SensorRepeat.SensorInfo> sensorInfo = sr.GetSensorInfo(); | ||
68 | |||
69 | ConsoleDisplayTable cdt = new ConsoleDisplayTable(); | ||
70 | cdt.AddColumn("Part name", 40); | ||
71 | cdt.AddColumn("Script item ID", 36); | ||
72 | cdt.AddColumn("Type", 4); | ||
73 | cdt.AddColumn("Interval", 8); | ||
74 | cdt.AddColumn("Range", 8); | ||
75 | cdt.AddColumn("Arc", 8); | ||
76 | |||
77 | foreach (SensorRepeat.SensorInfo s in sensorInfo) | ||
78 | { | ||
79 | cdt.AddRow(s.host.Name, s.itemID, s.type, s.interval, s.range, s.arc); | ||
80 | } | ||
81 | |||
82 | MainConsole.Instance.Output(cdt.ToString()); | ||
83 | MainConsole.Instance.OutputFormat("Total: {0}", sensorInfo.Count); | ||
84 | } | ||
85 | } | ||
86 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 4bbcb7c..8c3bb5b 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | |||
@@ -169,6 +169,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
169 | IWorkItemResult m_CurrentCompile = null; | 169 | IWorkItemResult m_CurrentCompile = null; |
170 | private Dictionary<UUID, int> m_CompileDict = new Dictionary<UUID, int>(); | 170 | private Dictionary<UUID, int> m_CompileDict = new Dictionary<UUID, int>(); |
171 | 171 | ||
172 | private ScriptEngineConsoleCommands m_consoleCommands; | ||
173 | |||
172 | public string ScriptEngineName | 174 | public string ScriptEngineName |
173 | { | 175 | { |
174 | get { return "XEngine"; } | 176 | get { return "XEngine"; } |
@@ -318,6 +320,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
318 | OnObjectRemoved += m_XmlRpcRouter.ObjectRemoved; | 320 | OnObjectRemoved += m_XmlRpcRouter.ObjectRemoved; |
319 | } | 321 | } |
320 | 322 | ||
323 | m_consoleCommands = new ScriptEngineConsoleCommands(this); | ||
324 | m_consoleCommands.RegisterCommands(); | ||
325 | |||
321 | MainConsole.Instance.Commands.AddCommand( | 326 | MainConsole.Instance.Commands.AddCommand( |
322 | "Scripts", false, "xengine status", "xengine status", "Show status information", | 327 | "Scripts", false, "xengine status", "xengine status", "Show status information", |
323 | "Show status information on the script engine.", | 328 | "Show status information on the script engine.", |