public void touch(ISceneChildEntity part, ISceneChildEntity child, Vector3 offsetPos,
                          IClientAPI remoteClient, SurfaceTouchEventArgs surfaceArgs)
        {
            Dictionary <UUID, DetectParams> det = new Dictionary <UUID, DetectParams>();

            if (!CoalescedTouchEvents.TryGetValue(part.LocalId, out det))
            {
                det = new Dictionary <UUID, DetectParams>();
            }

            // Add to queue for all scripts in ObjectID object
            DetectParams detparam = new DetectParams();

            detparam = new DetectParams
            {
                Key       = remoteClient.AgentId,
                OffsetPos = new LSL_Types.Vector3(offsetPos.X,
                                                  offsetPos.Y,
                                                  offsetPos.Z)
            };

            detparam.Populate(part.ParentEntity.Scene);
            detparam.LinkNum = child.LinkNum;

            if (surfaceArgs != null)
            {
                detparam.SurfaceTouchArgs = surfaceArgs;
            }

            det[remoteClient.AgentId]          = detparam;
            CoalescedTouchEvents[part.LocalId] = det;

            ScriptData[] datas = ScriptEngine.ScriptProtection.GetScripts(part.UUID);

            if (datas == null || datas.Length == 0)
            {
                return;
            }

            string functionName = "touch";

            object[] param = { new LSL_Types.LSLInteger(det.Count) };

            foreach (ScriptData ID in datas)
            {
                m_scriptEngine.AddToScriptQueue(ID, functionName, new List <DetectParams>(det.Values).ToArray(),
                                                EventPriority.FirstStart, param);
            }
        }
        public void touch_end(ISceneChildEntity part, ISceneChildEntity child, IClientAPI remoteClient,
                              SurfaceTouchEventArgs surfaceArgs)
        {
            Dictionary<UUID, DetectParams> det = new Dictionary<UUID, DetectParams>();
            if (!CoalescedTouchEvents.TryGetValue(part.LocalId, out det))
                det = new Dictionary<UUID, DetectParams>();

            // Add to queue for all scripts in ObjectID object
            DetectParams detparam = new DetectParams();
            detparam = new DetectParams {Key = remoteClient.AgentId};

            detparam.Populate(part.ParentEntity.Scene);
            detparam.LinkNum = child.LinkNum;

            if (surfaceArgs != null)
                detparam.SurfaceTouchArgs = surfaceArgs;

            det[remoteClient.AgentId] = detparam;
            CoalescedTouchEvents[part.LocalId] = det;

            ScriptData[] datas = ScriptEngine.ScriptProtection.GetScripts(part.UUID);

            if (datas == null || datas.Length == 0)
                return;

            string functionName = "touch_end";
            object[] param = {new LSL_Types.LSLInteger(det.Count)};

            foreach (ScriptData ID in datas)
            {
                m_scriptEngine.AddToScriptQueue(ID, functionName, new List<DetectParams>(det.Values).ToArray(),
                                                EventPriority.FirstStart, param);
            }
            //Remove us from the det param list
            det.Remove(remoteClient.AgentId);
            CoalescedTouchEvents[part.LocalId] = det;
        }
 public EventParams(string eventName, object[] eventParams, DetectParams[] detectParams)
 {
     EventName = eventName;
     Params = eventParams;
     DetectParams = detectParams;
 }
        public void AddEventSchQueue(ScriptData ID, string FunctionName, DetectParams[] qParams, EventPriority priority,
                                     params object[] param)
        {
            QueueItemStruct QIS = new QueueItemStruct
            {
                EventsProcData = new ScriptEventsProcData(),
                ID = ID,
                functionName = FunctionName,
                llDetectParams = qParams,
                param = param,
                VersionID = Interlocked.Read(ref ID.VersionID),
                State = ID.State,
                CurrentlyAt = null
            };

            if (ID.Script == null || ID.IgnoreNew)
                return;

            if (!ID.SetEventParams(QIS)) // check events delay rules
                return;

            ScriptEvents.Enqueue(QIS);

            long threadCount = Interlocked.Read(ref scriptThreadpool.nthreads);
            if (threadCount == 0 || threadCount < (ScriptEvents.Count + (SleepingScriptEventCount/2))*EventPerformance)
            {
                scriptThreadpool.QueueEvent(eventLoop, 2);
            }
        }