aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorTeravus Ovares2008-04-20 04:19:44 +0000
committerTeravus Ovares2008-04-20 04:19:44 +0000
commit3358d70c5b174b2b9ac1216e9e43497279982805 (patch)
tree3b6684a1d58912962eeda8a6b5fd1fc69ae2d00d /OpenSim/Region
parent* Added experimental "svn load <revision>" command to allow you to load a reg... (diff)
downloadopensim-SC-3358d70c5b174b2b9ac1216e9e43497279982805.zip
opensim-SC-3358d70c5b174b2b9ac1216e9e43497279982805.tar.gz
opensim-SC-3358d70c5b174b2b9ac1216e9e43497279982805.tar.bz2
opensim-SC-3358d70c5b174b2b9ac1216e9e43497279982805.tar.xz
* Updates LSL2CS converter
* All objects are not touchable by default now * When a script listens for one of the touch events in the state, an object becomes touchable. * All LSL scripts report which events they consume now ** This uses semi-complicated Regex to discover the events, stick them in a dictionary, and then write a method call into each script state's state_entry() event. ** Tedd may figure out a better way to do this in the future. For now, this works for LSL.
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/Environment/Scenes/SceneObjectGroup.Inventory.cs2
-rw-r--r--OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs135
-rw-r--r--OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs1
-rw-r--r--OpenSim/Region/Environment/Scenes/SceneObjectPart.cs14
-rw-r--r--OpenSim/Region/ScriptEngine/Common/BuiltIn_Commands_BaseClass.cs4
-rw-r--r--OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs5
-rw-r--r--OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands_Interface.cs1
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs200
8 files changed, 358 insertions, 4 deletions
diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.Inventory.cs b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.Inventory.cs
index 3f14fff..495b604 100644
--- a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.Inventory.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.Inventory.cs
@@ -51,6 +51,7 @@ namespace OpenSim.Region.Environment.Scenes
51 if (part != null) 51 if (part != null)
52 { 52 {
53 part.StartScript(itemID); 53 part.StartScript(itemID);
54
54 } 55 }
55 else 56 else
56 { 57 {
@@ -119,6 +120,7 @@ namespace OpenSim.Region.Environment.Scenes
119 if (part != null) 120 if (part != null)
120 { 121 {
121 part.StopScript(itemID); 122 part.StopScript(itemID);
123 RemoveScriptEvents(itemID);
122 } 124 }
123 else 125 else
124 { 126 {
diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs
index 1f38e4f..7abaaee 100644
--- a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs
@@ -41,6 +41,40 @@ using OpenSim.Region.Physics.Manager;
41 41
42namespace OpenSim.Region.Environment.Scenes 42namespace OpenSim.Region.Environment.Scenes
43{ 43{
44
45 [Flags]
46 public enum scriptEvents : int
47 {
48 None = 0,
49 attach = 1,
50 collision = 15,
51 collision_end = 32,
52 collision_start = 64,
53 control = 128,
54 dataserver = 256,
55 email = 512,
56 http_response = 1024,
57 land_collision = 2048,
58 land_collision_end = 4096,
59 land_collision_start = 8192,
60 link_message = 16384,
61 listen = 32768,
62 money = 65536,
63 moving_end = 131072,
64 moving_start = 262144,
65 not_at_rot_target = 524288,
66 not_at_target = 1048576,
67 remote_data = 8388608,
68 run_time_permissions = 268435456,
69 state_entry = 1073741824,
70 state_exit = 2,
71 timer = 4,
72 touch = 8,
73 touch_end = 536870912,
74 touch_start = 2097152,
75 object_rez = 4194304
76 }
77
44 public delegate void PrimCountTaintedDelegate(); 78 public delegate void PrimCountTaintedDelegate();
45 79
46 public partial class SceneObjectGroup : EntityBase 80 public partial class SceneObjectGroup : EntityBase
@@ -67,6 +101,9 @@ namespace OpenSim.Region.Environment.Scenes
67 private LLVector3 lastPhysGroupPos; 101 private LLVector3 lastPhysGroupPos;
68 private LLQuaternion lastPhysGroupRot; 102 private LLQuaternion lastPhysGroupRot;
69 103
104 private Dictionary<LLUUID, scriptEvents> m_scriptEvents = new Dictionary<LLUUID, scriptEvents>();
105 private scriptEvents m_aggregateScriptEvents = scriptEvents.None;
106
70 #region Properties 107 #region Properties
71 108
72 /// <summary> 109 /// <summary>
@@ -2042,6 +2079,104 @@ namespace OpenSim.Region.Environment.Scenes
2042 d.AddActiveScripts(count); 2079 d.AddActiveScripts(count);
2043 } 2080 }
2044 2081
2082 public void RemoveScriptEvents(LLUUID scriptid)
2083 {
2084 lock (m_scriptEvents)
2085 {
2086 if (m_scriptEvents.ContainsKey(scriptid))
2087 {
2088 scriptEvents oldparts = scriptEvents.None;
2089 oldparts = (scriptEvents)m_scriptEvents[scriptid];
2090
2091 // remove values from aggregated script events
2092 m_aggregateScriptEvents &= ~oldparts;
2093 m_scriptEvents.Remove(scriptid);
2094 }
2095
2096 }
2097 aggregateScriptEvents();
2098 }
2099
2100 public void SetScriptEvents(LLUUID scriptid, int events)
2101 {
2102
2103 scriptEvents oldparts = scriptEvents.None;
2104 lock (m_scriptEvents)
2105 {
2106 if (m_scriptEvents.ContainsKey(scriptid))
2107 {
2108 oldparts = (scriptEvents)m_scriptEvents[scriptid];
2109
2110 // remove values from aggregated script events
2111 m_aggregateScriptEvents &= ~oldparts;
2112 m_scriptEvents[scriptid] = (scriptEvents)events;
2113 }
2114 else
2115 {
2116 m_scriptEvents.Add(scriptid, (scriptEvents)events);
2117 }
2118
2119 }
2120
2121 aggregateScriptEvents();
2122 }
2123 public void aggregateScriptEvents()
2124 {
2125 // Aggregate script events
2126 lock (m_scriptEvents)
2127 {
2128 foreach (scriptEvents s in m_scriptEvents.Values)
2129 {
2130 m_aggregateScriptEvents |= s;
2131 }
2132 }
2133 uint objectflagupdate = m_rootPart.ObjectFlags;
2134
2135 if (
2136 ((m_aggregateScriptEvents & scriptEvents.touch) != 0) ||
2137 ((m_aggregateScriptEvents & scriptEvents.touch_end) != 0) ||
2138 ((m_aggregateScriptEvents & scriptEvents.touch_start) != 0)
2139 )
2140 {
2141 objectflagupdate |= (uint)LLObject.ObjectFlags.Touch;
2142 }
2143 else
2144 {
2145 objectflagupdate &= ~(uint)LLObject.ObjectFlags.Touch;
2146 }
2147
2148 if ((m_aggregateScriptEvents & scriptEvents.money) != 0)
2149 {
2150 objectflagupdate |= (uint)LLObject.ObjectFlags.Money;
2151 }
2152 else
2153 {
2154 objectflagupdate &= ~(uint)LLObject.ObjectFlags.Money;
2155 }
2156
2157 if (
2158 ((m_aggregateScriptEvents & scriptEvents.collision) != 0) ||
2159 ((m_aggregateScriptEvents & scriptEvents.collision_end) != 0) ||
2160 ((m_aggregateScriptEvents & scriptEvents.collision_start) != 0)
2161 )
2162 {
2163 // subscribe to physics updates.
2164 }
2165 else
2166 {
2167 // unsubscribe to physics updates.
2168 }
2169 lock (m_parts)
2170 {
2171 foreach (SceneObjectPart part in m_parts.Values)
2172 {
2173 part.ObjectFlags = objectflagupdate;
2174 }
2175 }
2176 ScheduleGroupForFullUpdate();
2177
2178 }
2179
2045 public override void SetText(string text, Vector3 color, double alpha) 2180 public override void SetText(string text, Vector3 color, double alpha)
2046 { 2181 {
2047 Color = Color.FromArgb(0xff - (int) (alpha*0xff), 2182 Color = Color.FromArgb(0xff - (int) (alpha*0xff),
diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs
index 16da516..8ce71c4 100644
--- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs
@@ -147,6 +147,7 @@ namespace OpenSim.Region.Environment.Scenes
147 if (10 == item.Type) 147 if (10 == item.Type)
148 { 148 {
149 StopScript(item.ItemID); 149 StopScript(item.ItemID);
150 m_parentGroup.RemoveScriptEvents(item.ItemID);
150 } 151 }
151 } 152 }
152 } 153 }
diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs
index b42375f..61d10c9 100644
--- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs
@@ -83,6 +83,7 @@ namespace OpenSim.Region.Environment.Scenes
83 SCALE = 0x40 83 SCALE = 0x40
84 } 84 }
85 85
86
86 [Serializable] 87 [Serializable]
87 public partial class SceneObjectPart : IScriptHost, ISerializable 88 public partial class SceneObjectPart : IScriptHost, ISerializable
88 { 89 {
@@ -729,8 +730,7 @@ namespace OpenSim.Region.Environment.Scenes
729 m_folderID = LLUUID.Random(); 730 m_folderID = LLUUID.Random();
730 731
731 Flags = 0; 732 Flags = 0;
732 Flags |= LLObject.ObjectFlags.Touch | 733 Flags |= LLObject.ObjectFlags.AllowInventoryDrop |
733 LLObject.ObjectFlags.AllowInventoryDrop |
734 LLObject.ObjectFlags.CreateSelected; 734 LLObject.ObjectFlags.CreateSelected;
735 735
736 736
@@ -774,7 +774,7 @@ namespace OpenSim.Region.Environment.Scenes
774 774
775 // Since we don't store script state, this is only a 'temporary' objectflag now 775 // Since we don't store script state, this is only a 'temporary' objectflag now
776 // If the object is scripted, the script will get loaded and this will be set again 776 // If the object is scripted, the script will get loaded and this will be set again
777 ObjectFlags &= ~(uint)LLObject.ObjectFlags.Scripted; 777 ObjectFlags &= ~(uint)(LLObject.ObjectFlags.Scripted | LLObject.ObjectFlags.Touch);
778 778
779 TrimPermissions(); 779 TrimPermissions();
780 // ApplyPhysics(); 780 // ApplyPhysics();
@@ -2312,6 +2312,14 @@ namespace OpenSim.Region.Environment.Scenes
2312 SetText( text ); 2312 SetText( text );
2313 } 2313 }
2314 2314
2315 public void setScriptEvents(LLUUID scriptID, int events)
2316 {
2317 if (m_parentGroup != null)
2318 {
2319 m_parentGroup.SetScriptEvents(scriptID, events);
2320 }
2321 }
2322
2315 protected SceneObjectPart(SerializationInfo info, StreamingContext context) 2323 protected SceneObjectPart(SerializationInfo info, StreamingContext context)
2316 { 2324 {
2317 //System.Console.WriteLine("SceneObjectPart Deserialize BGN"); 2325 //System.Console.WriteLine("SceneObjectPart Deserialize BGN");
diff --git a/OpenSim/Region/ScriptEngine/Common/BuiltIn_Commands_BaseClass.cs b/OpenSim/Region/ScriptEngine/Common/BuiltIn_Commands_BaseClass.cs
index cb4ca39..b6468c2 100644
--- a/OpenSim/Region/ScriptEngine/Common/BuiltIn_Commands_BaseClass.cs
+++ b/OpenSim/Region/ScriptEngine/Common/BuiltIn_Commands_BaseClass.cs
@@ -1990,6 +1990,10 @@ namespace OpenSim.Region.ScriptEngine.Common
1990 return m_LSL_Functions.osDrawImage(drawList, width, height, imageUrl); 1990 return m_LSL_Functions.osDrawImage(drawList, width, height, imageUrl);
1991 } 1991 }
1992 1992
1993 public void osSetStateEvents(int events)
1994 {
1995 m_LSL_Functions.osSetStateEvents(events);
1996 }
1993 1997
1994 // 1998 //
1995 1999
diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs
index 26e56c7..4192d40 100644
--- a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs
+++ b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs
@@ -5597,6 +5597,11 @@ namespace OpenSim.Region.ScriptEngine.Common
5597 return drawList; 5597 return drawList;
5598 } 5598 }
5599 5599
5600 public void osSetStateEvents(int events)
5601 {
5602 m_host.setScriptEvents(m_itemID,events);
5603 }
5604
5600 private void NotImplemented(string command) 5605 private void NotImplemented(string command)
5601 { 5606 {
5602 if (throwErrorOnNotImplemented) 5607 if (throwErrorOnNotImplemented)
diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands_Interface.cs b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands_Interface.cs
index 4e632ef..205e908 100644
--- a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands_Interface.cs
+++ b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands_Interface.cs
@@ -669,5 +669,6 @@ namespace OpenSim.Region.ScriptEngine.Common
669 string osSetPenSize(string drawList, int penSize); 669 string osSetPenSize(string drawList, int penSize);
670 string osSetPenColour(string drawList, string colour); 670 string osSetPenColour(string drawList, string colour);
671 string osDrawImage(string drawList, int width, int height, string imageUrl); 671 string osDrawImage(string drawList, int width, int height, string imageUrl);
672 void osSetStateEvents(int events);
672 } 673 }
673} 674}
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs
index 9f753df..8d85b69 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs
@@ -32,6 +32,7 @@ using System;
32 32
33namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL 33namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
34{ 34{
35
35 public class LSL2CSConverter 36 public class LSL2CSConverter
36 { 37 {
37 38
@@ -41,6 +42,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
41 //private Regex rnw = new Regex(@"[a-zA-Z0-9_\-]", RegexOptions.Compiled); 42 //private Regex rnw = new Regex(@"[a-zA-Z0-9_\-]", RegexOptions.Compiled);
42 private Dictionary<string, string> dataTypes = new Dictionary<string, string>(); 43 private Dictionary<string, string> dataTypes = new Dictionary<string, string>();
43 private Dictionary<string, string> quotes = new Dictionary<string, string>(); 44 private Dictionary<string, string> quotes = new Dictionary<string, string>();
45 private Dictionary<string, scriptEvents> state_events = new Dictionary<string, scriptEvents>();
44 46
45 public LSL2CSConverter() 47 public LSL2CSConverter()
46 { 48 {
@@ -294,8 +296,63 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
294 } 296 }
295 297
296 298
299 // Finds out which events are in the script and writes a method call with the events in each state_entry event
300
301 // Note the (?:)? block optional, and not returning a group. Less greedy then .*
302
303 string[] eventmatches = new string[0];
304 //Regex stateevents = new Regex(@"(public void )([^_]+)(_event_)([^\(]+)[\(\)]+\s+[^\{]\{");
305 eventmatches = Regex.Split(Script, @"public void\s([^_]+)_event_([^\(]+)\((?:[a-zA-Z0-9\s_,\.\-]+)?\)+\s+[^\{]\{", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase);
306 for (int pos = 0; pos<eventmatches.GetUpperBound(0);pos++)
307 {
308 pos++; // garbage
309
310 string statea = eventmatches[pos]; pos++;
311 string eventa = eventmatches[pos];
312 scriptEvents storedEventsForState = scriptEvents.None;
313 if (state_events.ContainsKey(statea))
314 {
315 storedEventsForState = state_events[statea];
316 state_events[statea] |= convertnametoFlag(eventa);
317 }
318 else
319 {
320 state_events.Add(statea, convertnametoFlag(eventa));
321 }
322 System.Console.WriteLine("State:" + statea + ", event: " + eventa);
323 }
324 System.Console.WriteLine("Matches:" + eventmatches.GetUpperBound(0));
297 // Add namespace, class name and inheritance 325 // Add namespace, class name and inheritance
298 326
327 // Looking *ONLY* for state entry events
328 string scriptCopy = "";
329
330 //Only match State_Entry events now
331 // Note the whole regex is a group, then we have the state this entry belongs to.
332 eventmatches = Regex.Split(Script, @"(public void\s([^_]+)_event_state_entry[\(\)]+\s+[^\{]\{)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase);
333 int endloop = eventmatches.GetUpperBound(0);
334 for (int pos = 0; pos < endloop; pos++)
335 {
336 // Returns text before state entry match,
337 scriptCopy += eventmatches[pos]; pos++;
338
339 // Returns text of state entry match,
340 scriptCopy += eventmatches[pos]; pos++;
341
342 // Returns which state we're matching and writes a method call to the end of the above state_entry
343 scriptCopy += "\r\n\t\tosSetStateEvents((int)" + (int)state_events[eventmatches[pos]] + ");"; //pos++;
344
345 // adds the remainder of the script.
346 if ((pos + 1) == endloop)
347 {
348 pos++;
349 scriptCopy += eventmatches[pos++];
350 }
351
352 }
353 // save modified script.
354 Script = scriptCopy;
355 //System.Console.WriteLine(Script);
299 Return = String.Empty;// + 356 Return = String.Empty;// +
300 //"using OpenSim.Region.ScriptEngine.Common; using System.Collections.Generic;"; 357 //"using OpenSim.Region.ScriptEngine.Common; using System.Collections.Generic;";
301 358
@@ -309,10 +366,151 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
309 Return += Script; 366 Return += Script;
310 //Return += "} }\r\n"; 367 //Return += "} }\r\n";
311 368
312 369 state_events.Clear();
313 quotes.Clear(); 370 quotes.Clear();
314 371
315 return Return; 372 return Return;
316 } 373 }
374 public scriptEvents convertnametoFlag(string eventname)
375 {
376 switch (eventname)
377 {
378 case "attach":
379 return scriptEvents.attach;
380 //break;
381 // case "at_rot_target":
382 //return (long)scriptEvents.at_rot_target;
383 //break;
384 //case "at_target":
385 //return (long)scriptEvents.at_target;
386 //break;
387 //case "changed":
388 //return (long)scriptEvents.changed;
389 //break;
390 case "collision":
391 return scriptEvents.collision;
392 // break;
393 case "collision_end":
394 return scriptEvents.collision_end;
395 //break;
396 case "collision_start":
397 return scriptEvents.collision_start;
398 // break;
399 case "control":
400 return scriptEvents.control;
401 //break;
402 case "dataserver":
403 return scriptEvents.dataserver;
404 // break;
405 case "email":
406 return scriptEvents.email;
407 // break;
408 case "http_response":
409 return scriptEvents.http_response;
410 // break;
411 case "land_collision":
412 return scriptEvents.land_collision;
413 // break;
414 case "land_collision_end":
415 return scriptEvents.land_collision_end;
416 // break;
417 case "land_collision_start":
418 return scriptEvents.land_collision_start;
419 // break;
420 case "link_message":
421 return scriptEvents.link_message;
422 // break;
423 case "listen":
424 return scriptEvents.listen;
425 // break;
426 case "money":
427 return scriptEvents.money;
428 // break;
429 case "moving_end":
430 return scriptEvents.moving_end;
431 // break;
432 case "moving_start":
433 return scriptEvents.moving_start;
434 // break;
435 case "not_at_rot_target":
436 return scriptEvents.not_at_rot_target;
437 // break;
438 case "not_at_target":
439 return scriptEvents.not_at_target;
440 // break;
441 // case "no_sensor":
442 //return (long)scriptEvents.no_sensor;
443 //break;
444 //case "on_rez":
445 //return (long)scriptEvents.on_rez;
446 // break;
447 case "remote_data":
448 return scriptEvents.remote_data;
449 // break;
450 case "run_time_permissions":
451 return scriptEvents.run_time_permissions;
452 // break;
453 //case "sensor":
454 //return (long)scriptEvents.sensor;
455 // break;
456 case "state_entry":
457 return scriptEvents.state_entry;
458 // break;
459 case "state_exit":
460 return scriptEvents.state_exit;
461 // break;
462 case "timer":
463 return scriptEvents.timer;
464 // break;
465 case "touch":
466 return scriptEvents.touch;
467 // break;
468 case "touch_end":
469 return scriptEvents.touch_end;
470 // break;
471 case "touch_start":
472 return scriptEvents.touch_start;
473 // break;
474 case "object_rez":
475 return scriptEvents.object_rez;
476 default:
477 return 0;
478 //break;
479 }
480 //return 0;
481 }
482 }
483
484 [Flags]
485 public enum scriptEvents : int
486 {
487 None = 0,
488 attach = 1,
489 collision = 15,
490 collision_end = 32,
491 collision_start = 64,
492 control = 128,
493 dataserver = 256,
494 email = 512,
495 http_response = 1024,
496 land_collision = 2048,
497 land_collision_end = 4096,
498 land_collision_start = 8192,
499 link_message = 16384,
500 listen = 32768,
501 money = 65536,
502 moving_end = 131072,
503 moving_start = 262144,
504 not_at_rot_target = 524288,
505 not_at_target = 1048576,
506 remote_data = 8388608,
507 run_time_permissions = 268435456,
508 state_entry = 1073741824,
509 state_exit = 2,
510 timer = 4,
511 touch = 8,
512 touch_end = 536870912,
513 touch_start = 2097152,
514 object_rez = 4194304
317 } 515 }
318} \ No newline at end of file 516} \ No newline at end of file