Пример #1
0
        private void DisplayScriptInfos()
        {
            UpdateScriptingModInfoData();

            PlayfieldData.Values.ForEach(PF => {
                var output        = new StringBuilder();
                var totalExecTime = new TimeSpan();
                Log($"ScriptInfos[{PF.PlayfieldName}]: RunCount:{PF.ScriptExecQueue.ScriptRunInfo.Count} ExecQueue:{PF.ScriptExecQueue.ExecQueue.Count} WaitForExec:{PF.ScriptExecQueue.WaitForExec.Count} BackgroundWorkerToDoCount:{PF.ScriptExecQueue.BackgroundWorkerToDo.Count} Sync:{PF.ScriptExecQueue.ScriptNeedsMainThread.Count(S => S.Value)} GameUpdateTimeLimitReached:{PF.ScriptExecQueue.GameUpdateScriptLoopTimeLimitReached} Total:{PF.ScriptExecQueue.ScriptNeedsMainThread.Count()}", LogLevel.Message);
                PF.ScriptExecQueue.ScriptRunInfo
                .OrderBy(I => I.Key)
                .ForEach(I =>
                {
                    var line       = $"Script: {I.Key,-50} {(PF.ScriptExecQueue.ScriptNeedsMainThread.TryGetValue(I.Key, out var sync) && sync ? ">SYNC<" : "")} #{I.Value.Count,5} LastStart:{I.Value.LastStart} ExecTime:{I.Value.ExecTime} TimeLimitReached:{I.Value._TimeLimitReached} {(I.Value._RunningInstances > 0 ? $" !!!running!!! {I.Value._RunningInstances} times" : "")}";
                    totalExecTime += I.Value.ExecTime;
                    if (Configuration.Current.DetailedScriptsInfoData)
                    {
                        output.AppendLine(line);
                    }
                    Log(line, I.Value._RunningInstances > 0 ? LogLevel.Error : LogLevel.Debug);
                });

                output.Insert(0, $"RunCount:{PF.ScriptExecQueue.ScriptRunInfo.Count} ExecQueue:{PF.ScriptExecQueue.ExecQueue.Count} WaitForExec:{PF.ScriptExecQueue.WaitForExec.Count} BackgroundWorkerToDoCount:{PF.ScriptExecQueue.BackgroundWorkerToDo.Count} Sync:{PF.ScriptExecQueue.ScriptNeedsMainThread.Count(S => S.Value)} GameUpdateTimeLimitReached:{PF.ScriptExecQueue.GameUpdateScriptLoopTimeLimitReached} Total:{PF.ScriptExecQueue.ScriptNeedsMainThread.Count()} TotalExecTime:{totalExecTime}\n");
                var result = output.ToString();
                ScriptingModScriptsInfoData.AddOrUpdate(PF.PlayfieldName, result, (k, o) => result);
            });
        }
Пример #2
0
        private void Application_OnPlayfieldUnloading(IPlayfield playfield)
        {
            ScriptingModScriptsInfoData.TryRemove(playfield.Name, out _);

            if (!PlayfieldData.TryRemove(playfield.Name, out var data))
            {
                return;
            }

            data.Playfield.OnEntityLoaded   -= data.Playfield_OnEntityLoaded;
            data.Playfield.OnEntityUnloaded -= data.Playfield_OnEntityUnloaded;

            ModApi.Log($"PauseScripts for {playfield.Name} {(data.PauseScripts ? "always stopped" : "scripts running")}");
            data.PauseScripts = true;

            DisplayScriptInfos();
            data.ScriptExecQueue?.Clear();
            data.LcdCompileCache?.Clear();
            data.PersistendData?.Clear();

            var stores = data.EventStore?.Values.ToArray();

            data.EventStore?.Clear();
            stores?.ForEach(S => ((EventStore)S).Dispose());
        }