Ejemplo n.º 1
0
        public void CmdHandlerQueue()
        {
            if (m_ScriptEngine.Scene == null)
            {
                Interlocked.Exchange(ref CmdHandlerQueueIsRunning, 0);
                return;
            }
            Interlocked.Exchange(ref CmdHandlerQueueIsRunning, 1);
            IMonitorModule module    = m_ScriptEngine.Scene.RequestModuleInterface <IMonitorModule>();
            int            StartTime = Util.EnvironmentTickCount();

            if (!Started) //Break early
            {
                Interlocked.Exchange(ref CmdHandlerQueueIsRunning, 0);
                return;
            }

            if (m_ScriptEngine.ConsoleDisabled || m_ScriptEngine.Disabled || !m_ScriptEngine.Scene.ShouldRunHeartbeat)
            {
                Interlocked.Exchange(ref CmdHandlerQueueIsRunning, 0);
                return;
            }

            //Check timers, etc
            bool didAnything = false;

            try
            {
                didAnything = m_ScriptEngine.DoOneScriptPluginPass();
            }
            catch (Exception ex)
            {
                MainConsole.Instance.WarnFormat("[{0}]: Error in CmdHandlerPass, {1}", m_ScriptEngine.ScriptEngineName,
                                                ex);
            }

            if (module != null)
            {
                IScriptFrameTimeMonitor scriptMonitor = module.GetMonitor <IScriptFrameTimeMonitor>(m_ScriptEngine.Scene);
                if (scriptMonitor != null)
                {
                    scriptMonitor.AddTime(Util.EnvironmentTickCountSubtract(StartTime));
                }
            }

            if (didAnything) //If we did something, run us again soon
            {
                cmdThreadpool.QueueEvent(CmdHandlerQueue, 2);
            }
            else
            {
                Interlocked.Exchange(ref CmdHandlerQueueIsRunning, 0);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     This loop deals with starting and stoping scripts
        /// </summary>
        /// <returns></returns>
        public void ScriptChangeQueue()
        {
            if (m_ScriptEngine.Scene == null)
            {
                return;
            }

            IMonitorModule module    = m_ScriptEngine.Scene.RequestModuleInterface <IMonitorModule>();
            int            StartTime = Util.EnvironmentTickCount();

            if (!Started) //Break early
            {
                return;
            }

            if (m_ScriptEngine.ConsoleDisabled || m_ScriptEngine.Disabled || !m_ScriptEngine.Scene.ShouldRunHeartbeat)
            {
                return;
            }

            ScriptChangeIsRunning = true;

            object oitems;
            bool   broken = false;

            for (int i = 0; i < 5; i++)
            {
                if (LUQueue.GetNext(out oitems))
                {
                    StartScripts(oitems as LUStruct[]);
                }
                else
                {
                    //None left, stop looping
                    broken = true;
                    break;
                }
            }
            if (!broken)
            {
                scriptChangeThreadpool.QueueEvent(ScriptChangeQueue, 2); //Requeue us, still more to do
                return;
            }

            if (!FiredStartupEvent)
            {
                //If we are empty, we are all done with script startup and can tell the region that we are all done
                if (LUQueue.Count() == 0)
                {
                    FiredStartupEvent = true;
                    m_ScriptEngine.Scene.EventManager.TriggerEmptyScriptCompileQueue(m_ScriptEngine.ScriptFailCount,
                                                                                     m_ScriptEngine.ScriptErrorMessages);

                    m_ScriptEngine.Scene.EventManager.TriggerModuleFinishedStartup("ScriptEngine", new List <string>
                    {
                        m_ScriptEngine.ScriptFailCount.ToString(),
                        m_ScriptEngine.ScriptErrorMessages
                    });
                    //Tell that we are done
                }
            }
            ScriptChangeIsRunning = false;
            Thread.Sleep(20);

            if (module != null)
            {
                IScriptFrameTimeMonitor scriptMonitor = module.GetMonitor <IScriptFrameTimeMonitor>(m_ScriptEngine.Scene);
                if (scriptMonitor != null)
                {
                    scriptMonitor.AddTime(Util.EnvironmentTickCountSubtract(StartTime));
                }
            }
        }