Exemplo n.º 1
0
        /// <summary>
        /// resumes suspended Co-routines
        /// </summary>
        /// <param name="includeFrameWaiters">should frame waiters be waken up? only use this immediately before a frame of emulation</param>
        public void ResumeScripts(bool includeFrameWaiters)
        {
            if (!LuaImp.ScriptList.Any())
            {
                return;
            }

            if (LuaImp.GuiLibrary.SurfaceIsNull)
            {
                LuaImp.GuiLibrary.DrawNew("emu");
            }

            foreach (var lf in LuaImp.ScriptList.Where(l => l.Enabled && l.Thread != null && !l.Paused))
            {
                try
                {
                    LuaSandbox.Sandbox(lf.Thread, () =>
                    {
                        var prohibit = lf.FrameWaiting && !includeFrameWaiters;
                        if (!prohibit)
                        {
                            var result = LuaImp.ResumeScriptFromThreadOf(lf);
                            if (result.Terminated)
                            {
                                LuaImp.CallExitEvent(lf);
                                lf.Stop();
                                UpdateDialog();
                            }

                            lf.FrameWaiting = result.WaitForFrame;
                        }
                    }, () =>
                    {
                        lf.Stop();
                    });
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }