* 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.
0.6.0-stable
Teravus Ovares 2008-04-20 04:19:44 +00:00
parent 7d18a93c2e
commit 3358d70c5b
8 changed files with 358 additions and 4 deletions

View File

@ -51,6 +51,7 @@ namespace OpenSim.Region.Environment.Scenes
if (part != null) if (part != null)
{ {
part.StartScript(itemID); part.StartScript(itemID);
} }
else else
{ {
@ -119,6 +120,7 @@ namespace OpenSim.Region.Environment.Scenes
if (part != null) if (part != null)
{ {
part.StopScript(itemID); part.StopScript(itemID);
RemoveScriptEvents(itemID);
} }
else else
{ {

View File

@ -41,6 +41,40 @@ using OpenSim.Region.Physics.Manager;
namespace OpenSim.Region.Environment.Scenes namespace OpenSim.Region.Environment.Scenes
{ {
[Flags]
public enum scriptEvents : int
{
None = 0,
attach = 1,
collision = 15,
collision_end = 32,
collision_start = 64,
control = 128,
dataserver = 256,
email = 512,
http_response = 1024,
land_collision = 2048,
land_collision_end = 4096,
land_collision_start = 8192,
link_message = 16384,
listen = 32768,
money = 65536,
moving_end = 131072,
moving_start = 262144,
not_at_rot_target = 524288,
not_at_target = 1048576,
remote_data = 8388608,
run_time_permissions = 268435456,
state_entry = 1073741824,
state_exit = 2,
timer = 4,
touch = 8,
touch_end = 536870912,
touch_start = 2097152,
object_rez = 4194304
}
public delegate void PrimCountTaintedDelegate(); public delegate void PrimCountTaintedDelegate();
public partial class SceneObjectGroup : EntityBase public partial class SceneObjectGroup : EntityBase
@ -67,6 +101,9 @@ namespace OpenSim.Region.Environment.Scenes
private LLVector3 lastPhysGroupPos; private LLVector3 lastPhysGroupPos;
private LLQuaternion lastPhysGroupRot; private LLQuaternion lastPhysGroupRot;
private Dictionary<LLUUID, scriptEvents> m_scriptEvents = new Dictionary<LLUUID, scriptEvents>();
private scriptEvents m_aggregateScriptEvents = scriptEvents.None;
#region Properties #region Properties
/// <summary> /// <summary>
@ -2042,6 +2079,104 @@ namespace OpenSim.Region.Environment.Scenes
d.AddActiveScripts(count); d.AddActiveScripts(count);
} }
public void RemoveScriptEvents(LLUUID scriptid)
{
lock (m_scriptEvents)
{
if (m_scriptEvents.ContainsKey(scriptid))
{
scriptEvents oldparts = scriptEvents.None;
oldparts = (scriptEvents)m_scriptEvents[scriptid];
// remove values from aggregated script events
m_aggregateScriptEvents &= ~oldparts;
m_scriptEvents.Remove(scriptid);
}
}
aggregateScriptEvents();
}
public void SetScriptEvents(LLUUID scriptid, int events)
{
scriptEvents oldparts = scriptEvents.None;
lock (m_scriptEvents)
{
if (m_scriptEvents.ContainsKey(scriptid))
{
oldparts = (scriptEvents)m_scriptEvents[scriptid];
// remove values from aggregated script events
m_aggregateScriptEvents &= ~oldparts;
m_scriptEvents[scriptid] = (scriptEvents)events;
}
else
{
m_scriptEvents.Add(scriptid, (scriptEvents)events);
}
}
aggregateScriptEvents();
}
public void aggregateScriptEvents()
{
// Aggregate script events
lock (m_scriptEvents)
{
foreach (scriptEvents s in m_scriptEvents.Values)
{
m_aggregateScriptEvents |= s;
}
}
uint objectflagupdate = m_rootPart.ObjectFlags;
if (
((m_aggregateScriptEvents & scriptEvents.touch) != 0) ||
((m_aggregateScriptEvents & scriptEvents.touch_end) != 0) ||
((m_aggregateScriptEvents & scriptEvents.touch_start) != 0)
)
{
objectflagupdate |= (uint)LLObject.ObjectFlags.Touch;
}
else
{
objectflagupdate &= ~(uint)LLObject.ObjectFlags.Touch;
}
if ((m_aggregateScriptEvents & scriptEvents.money) != 0)
{
objectflagupdate |= (uint)LLObject.ObjectFlags.Money;
}
else
{
objectflagupdate &= ~(uint)LLObject.ObjectFlags.Money;
}
if (
((m_aggregateScriptEvents & scriptEvents.collision) != 0) ||
((m_aggregateScriptEvents & scriptEvents.collision_end) != 0) ||
((m_aggregateScriptEvents & scriptEvents.collision_start) != 0)
)
{
// subscribe to physics updates.
}
else
{
// unsubscribe to physics updates.
}
lock (m_parts)
{
foreach (SceneObjectPart part in m_parts.Values)
{
part.ObjectFlags = objectflagupdate;
}
}
ScheduleGroupForFullUpdate();
}
public override void SetText(string text, Vector3 color, double alpha) public override void SetText(string text, Vector3 color, double alpha)
{ {
Color = Color.FromArgb(0xff - (int) (alpha*0xff), Color = Color.FromArgb(0xff - (int) (alpha*0xff),

View File

@ -147,6 +147,7 @@ namespace OpenSim.Region.Environment.Scenes
if (10 == item.Type) if (10 == item.Type)
{ {
StopScript(item.ItemID); StopScript(item.ItemID);
m_parentGroup.RemoveScriptEvents(item.ItemID);
} }
} }
} }

View File

@ -83,6 +83,7 @@ namespace OpenSim.Region.Environment.Scenes
SCALE = 0x40 SCALE = 0x40
} }
[Serializable] [Serializable]
public partial class SceneObjectPart : IScriptHost, ISerializable public partial class SceneObjectPart : IScriptHost, ISerializable
{ {
@ -729,8 +730,7 @@ namespace OpenSim.Region.Environment.Scenes
m_folderID = LLUUID.Random(); m_folderID = LLUUID.Random();
Flags = 0; Flags = 0;
Flags |= LLObject.ObjectFlags.Touch | Flags |= LLObject.ObjectFlags.AllowInventoryDrop |
LLObject.ObjectFlags.AllowInventoryDrop |
LLObject.ObjectFlags.CreateSelected; LLObject.ObjectFlags.CreateSelected;
@ -774,7 +774,7 @@ namespace OpenSim.Region.Environment.Scenes
// Since we don't store script state, this is only a 'temporary' objectflag now // Since we don't store script state, this is only a 'temporary' objectflag now
// If the object is scripted, the script will get loaded and this will be set again // If the object is scripted, the script will get loaded and this will be set again
ObjectFlags &= ~(uint)LLObject.ObjectFlags.Scripted; ObjectFlags &= ~(uint)(LLObject.ObjectFlags.Scripted | LLObject.ObjectFlags.Touch);
TrimPermissions(); TrimPermissions();
// ApplyPhysics(); // ApplyPhysics();
@ -2312,6 +2312,14 @@ namespace OpenSim.Region.Environment.Scenes
SetText( text ); SetText( text );
} }
public void setScriptEvents(LLUUID scriptID, int events)
{
if (m_parentGroup != null)
{
m_parentGroup.SetScriptEvents(scriptID, events);
}
}
protected SceneObjectPart(SerializationInfo info, StreamingContext context) protected SceneObjectPart(SerializationInfo info, StreamingContext context)
{ {
//System.Console.WriteLine("SceneObjectPart Deserialize BGN"); //System.Console.WriteLine("SceneObjectPart Deserialize BGN");

View File

@ -1990,6 +1990,10 @@ namespace OpenSim.Region.ScriptEngine.Common
return m_LSL_Functions.osDrawImage(drawList, width, height, imageUrl); return m_LSL_Functions.osDrawImage(drawList, width, height, imageUrl);
} }
public void osSetStateEvents(int events)
{
m_LSL_Functions.osSetStateEvents(events);
}
// //

View File

@ -5597,6 +5597,11 @@ namespace OpenSim.Region.ScriptEngine.Common
return drawList; return drawList;
} }
public void osSetStateEvents(int events)
{
m_host.setScriptEvents(m_itemID,events);
}
private void NotImplemented(string command) private void NotImplemented(string command)
{ {
if (throwErrorOnNotImplemented) if (throwErrorOnNotImplemented)

View File

@ -669,5 +669,6 @@ namespace OpenSim.Region.ScriptEngine.Common
string osSetPenSize(string drawList, int penSize); string osSetPenSize(string drawList, int penSize);
string osSetPenColour(string drawList, string colour); string osSetPenColour(string drawList, string colour);
string osDrawImage(string drawList, int width, int height, string imageUrl); string osDrawImage(string drawList, int width, int height, string imageUrl);
void osSetStateEvents(int events);
} }
} }

View File

@ -32,6 +32,7 @@ using System;
namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
{ {
public class LSL2CSConverter public class LSL2CSConverter
{ {
@ -41,6 +42,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
//private Regex rnw = new Regex(@"[a-zA-Z0-9_\-]", RegexOptions.Compiled); //private Regex rnw = new Regex(@"[a-zA-Z0-9_\-]", RegexOptions.Compiled);
private Dictionary<string, string> dataTypes = new Dictionary<string, string>(); private Dictionary<string, string> dataTypes = new Dictionary<string, string>();
private Dictionary<string, string> quotes = new Dictionary<string, string>(); private Dictionary<string, string> quotes = new Dictionary<string, string>();
private Dictionary<string, scriptEvents> state_events = new Dictionary<string, scriptEvents>();
public LSL2CSConverter() public LSL2CSConverter()
{ {
@ -294,8 +296,63 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
} }
// Finds out which events are in the script and writes a method call with the events in each state_entry event
// Note the (?:)? block optional, and not returning a group. Less greedy then .*
string[] eventmatches = new string[0];
//Regex stateevents = new Regex(@"(public void )([^_]+)(_event_)([^\(]+)[\(\)]+\s+[^\{]\{");
eventmatches = Regex.Split(Script, @"public void\s([^_]+)_event_([^\(]+)\((?:[a-zA-Z0-9\s_,\.\-]+)?\)+\s+[^\{]\{", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase);
for (int pos = 0; pos<eventmatches.GetUpperBound(0);pos++)
{
pos++; // garbage
string statea = eventmatches[pos]; pos++;
string eventa = eventmatches[pos];
scriptEvents storedEventsForState = scriptEvents.None;
if (state_events.ContainsKey(statea))
{
storedEventsForState = state_events[statea];
state_events[statea] |= convertnametoFlag(eventa);
}
else
{
state_events.Add(statea, convertnametoFlag(eventa));
}
System.Console.WriteLine("State:" + statea + ", event: " + eventa);
}
System.Console.WriteLine("Matches:" + eventmatches.GetUpperBound(0));
// Add namespace, class name and inheritance // Add namespace, class name and inheritance
// Looking *ONLY* for state entry events
string scriptCopy = "";
//Only match State_Entry events now
// Note the whole regex is a group, then we have the state this entry belongs to.
eventmatches = Regex.Split(Script, @"(public void\s([^_]+)_event_state_entry[\(\)]+\s+[^\{]\{)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase);
int endloop = eventmatches.GetUpperBound(0);
for (int pos = 0; pos < endloop; pos++)
{
// Returns text before state entry match,
scriptCopy += eventmatches[pos]; pos++;
// Returns text of state entry match,
scriptCopy += eventmatches[pos]; pos++;
// Returns which state we're matching and writes a method call to the end of the above state_entry
scriptCopy += "\r\n\t\tosSetStateEvents((int)" + (int)state_events[eventmatches[pos]] + ");"; //pos++;
// adds the remainder of the script.
if ((pos + 1) == endloop)
{
pos++;
scriptCopy += eventmatches[pos++];
}
}
// save modified script.
Script = scriptCopy;
//System.Console.WriteLine(Script);
Return = String.Empty;// + Return = String.Empty;// +
//"using OpenSim.Region.ScriptEngine.Common; using System.Collections.Generic;"; //"using OpenSim.Region.ScriptEngine.Common; using System.Collections.Generic;";
@ -309,10 +366,151 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
Return += Script; Return += Script;
//Return += "} }\r\n"; //Return += "} }\r\n";
state_events.Clear();
quotes.Clear(); quotes.Clear();
return Return; return Return;
} }
public scriptEvents convertnametoFlag(string eventname)
{
switch (eventname)
{
case "attach":
return scriptEvents.attach;
//break;
// case "at_rot_target":
//return (long)scriptEvents.at_rot_target;
//break;
//case "at_target":
//return (long)scriptEvents.at_target;
//break;
//case "changed":
//return (long)scriptEvents.changed;
//break;
case "collision":
return scriptEvents.collision;
// break;
case "collision_end":
return scriptEvents.collision_end;
//break;
case "collision_start":
return scriptEvents.collision_start;
// break;
case "control":
return scriptEvents.control;
//break;
case "dataserver":
return scriptEvents.dataserver;
// break;
case "email":
return scriptEvents.email;
// break;
case "http_response":
return scriptEvents.http_response;
// break;
case "land_collision":
return scriptEvents.land_collision;
// break;
case "land_collision_end":
return scriptEvents.land_collision_end;
// break;
case "land_collision_start":
return scriptEvents.land_collision_start;
// break;
case "link_message":
return scriptEvents.link_message;
// break;
case "listen":
return scriptEvents.listen;
// break;
case "money":
return scriptEvents.money;
// break;
case "moving_end":
return scriptEvents.moving_end;
// break;
case "moving_start":
return scriptEvents.moving_start;
// break;
case "not_at_rot_target":
return scriptEvents.not_at_rot_target;
// break;
case "not_at_target":
return scriptEvents.not_at_target;
// break;
// case "no_sensor":
//return (long)scriptEvents.no_sensor;
//break;
//case "on_rez":
//return (long)scriptEvents.on_rez;
// break;
case "remote_data":
return scriptEvents.remote_data;
// break;
case "run_time_permissions":
return scriptEvents.run_time_permissions;
// break;
//case "sensor":
//return (long)scriptEvents.sensor;
// break;
case "state_entry":
return scriptEvents.state_entry;
// break;
case "state_exit":
return scriptEvents.state_exit;
// break;
case "timer":
return scriptEvents.timer;
// break;
case "touch":
return scriptEvents.touch;
// break;
case "touch_end":
return scriptEvents.touch_end;
// break;
case "touch_start":
return scriptEvents.touch_start;
// break;
case "object_rez":
return scriptEvents.object_rez;
default:
return 0;
//break;
}
//return 0;
}
}
[Flags]
public enum scriptEvents : int
{
None = 0,
attach = 1,
collision = 15,
collision_end = 32,
collision_start = 64,
control = 128,
dataserver = 256,
email = 512,
http_response = 1024,
land_collision = 2048,
land_collision_end = 4096,
land_collision_start = 8192,
link_message = 16384,
listen = 32768,
money = 65536,
moving_end = 131072,
moving_start = 262144,
not_at_rot_target = 524288,
not_at_target = 1048576,
remote_data = 8388608,
run_time_permissions = 268435456,
state_entry = 1073741824,
state_exit = 2,
timer = 4,
touch = 8,
touch_end = 536870912,
touch_start = 2097152,
object_rez = 4194304
} }
} }