internal static void ValidateCurrentGraph(bool force = false)
        {
            var shouldRun = k_Cooldown.Update(DateTime.Now);

            if (!force && !shouldRun)
            {
                return;
            }

            foreach (var recorder in Current.RecordersBySystem.Values)
            {
                recorder.Update();
            }

            var graph = new PlayerLoopSystemGraph();

            ParsePlayerLoopSystem(PlayerLoop.GetCurrentPlayerLoop(), graph);
            if (!DidChange(Current, graph))
            {
                graph.Reset();
                return;
            }

            Current.Reset();
            Current = graph;
            OnGraphChanged?.Invoke();
        }
        static void Parse(PlayerLoopSystem playerLoopSystem, PlayerLoopSystemGraph graph, IPlayerLoopNode parent = null)
        {
            // The integration of `ComponentSystemBase` into the player loop is done through a wrapper type.
            // If the target of the player loop system is the wrapper type, we will parse this as a `ComponentSystemBase`.
            if (null != playerLoopSystem.updateDelegate && playerLoopSystem.updateDelegate.Target is SystemWrapper wrapper)
            {
                Parse(wrapper.System, graph, parent);
                return;
            }

            // Add the player loop system to the graph if it is not the root one.
            if (null != playerLoopSystem.type)
            {
                var playerLoopSystemNode = Pool <PlayerLoopSystemNode> .GetPooled();

                playerLoopSystemNode.Value = playerLoopSystem;
                var node = playerLoopSystemNode;
                AddToGraph(graph, node, parent);
                parent = node;
            }

            if (null == playerLoopSystem.subSystemList)
            {
                return;
            }

            foreach (var subSystem in playerLoopSystem.subSystemList)
            {
                Parse(subSystem, graph, parent);
            }
        }
        static void Parse(SystemHandle systemHandle, PlayerLoopSystemGraph graph, IPlayerLoopNode parent = null)
        {
            IPlayerLoopNode node;

            graph.AllSystems.Add(systemHandle);

            if (systemHandle.Managed != null && systemHandle.Managed is ComponentSystemGroup group)
            {
                var groupNode = Pool <ComponentGroupNode> .GetPooled();

                groupNode.Value = group;
                node            = groupNode;

                ref var updateSystemList = ref group.m_MasterUpdateList;
                for (int i = 0, count = updateSystemList.length; i < count; ++i)
                {
                    var updateIndex = updateSystemList[i];
                    if (updateIndex.IsManaged)
                    {
                        var child = group.Systems[updateIndex.Index];
                        Parse(child, graph, node);
                    }
                    else
                    {
                        var child = group.UnmanagedSystems[updateIndex.Index];
                        Parse(new SystemHandle(child, group.World), graph, node);
                    }
                }
            }
Пример #4
0
        IEnumerable <Type> GetSystemTypesFromNamesInSearchFilter(PlayerLoopSystemGraph graph)
        {
            if (string.IsNullOrEmpty(SearchFilter))
            {
                yield break;
            }

            var systemNameList = SearchUtility.GetStringFollowedByGivenToken(SearchFilter, Constants.SystemSchedule.k_SystemDependencyToken).ToList();

            if (!systemNameList.Any())
            {
                yield break;
            }

            using (var pooled = PooledHashSet <Type> .Make())
            {
                foreach (var system in graph.AllSystems)
                {
                    foreach (var singleSystemName in systemNameList)
                    {
                        if (string.Compare(system.GetType().Name, singleSystemName, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            var type = system.GetType();
                            if (pooled.Set.Add(type))
                            {
                                yield return(type);
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Build the GUI for the system window.
        /// </summary>
        void OnEnable()
        {
            titleContent = EditorGUIUtility.TrTextContent(k_WindowName, EditorIcons.System);
            minSize      = k_MinWindowSize;

            m_Root = new VisualElement {
                style = { flexGrow = 1 }
            };
            rootVisualElement.Add(m_Root);

            m_NoWorld = new CenteredMessageElement()
            {
                Message = NoWorldMessageContent
            };
            rootVisualElement.Add(m_NoWorld);
            m_NoWorld.Hide();

            m_State = SessionState <State> .GetOrCreate($"{typeof(SystemScheduleWindow).FullName}+{nameof(State)}+{EditorWindowInstanceKey}");

            Resources.Templates.SystemSchedule.AddStyles(m_Root);
            Resources.Templates.DotsEditorCommon.AddStyles(m_Root);

            CreateToolBar(m_Root);
            CreateTreeViewHeader(m_Root);
            CreateTreeView(m_Root);

            PlayerLoopSystemGraph.Register();

            m_SearchElement.Search(SearchFilter);

            PlayerLoopSystemGraph.OnGraphChanged      += RebuildTreeView;
            SystemDetailsVisualElement.OnAddFilter    += OnAddFilter;
            SystemDetailsVisualElement.OnRemoveFilter += OnRemoveFilter;
        }
        void OnDisable()
        {
            PlayerLoopSystemGraph.OnGraphChanged      -= RebuildTreeView;
            SystemDetailsVisualElement.OnAddFilter    -= OnAddFilter;
            SystemDetailsVisualElement.OnRemoveFilter -= OnRemoveFilter;

            PlayerLoopSystemGraph.Unregister();
            m_SystemTreeView.Dispose();
        }
Пример #7
0
        public static SystemTreeViewItem GetSystemTreeViewItem(PlayerLoopSystemGraph graph, IPlayerLoopNode node, SystemTreeViewItem parent, World world)
        {
            var item = Pool <SystemTreeViewItem> .GetPooled(LifetimePolicy.Permanent);

            item.World  = world;
            item.Graph  = graph;
            item.Node   = node;
            item.parent = parent;
            return(item);
        }
        public static SystemTreeViewItem Acquire(PlayerLoopSystemGraph graph, IPlayerLoopNode node, SystemTreeViewItem parent, World world)
        {
            var item = Pool.Acquire();

            item.World  = world;
            item.Graph  = graph;
            item.Node   = node;
            item.parent = parent;

            return(item);
        }
 static void AddToGraph(PlayerLoopSystemGraph graph, IPlayerLoopNode node, IPlayerLoopNode parent = null)
 {
     if (null == parent)
     {
         graph.Roots.Add(node);
     }
     else
     {
         node.Parent = parent;
         parent.Children.Add(node);
     }
 }
Пример #10
0
        static void Parse(ComponentSystemBase system, PlayerLoopSystemGraph graph, IPlayerLoopNode parent = null)
        {
            IPlayerLoopNode node;

            graph.AllSystems.Add(system);

            switch (system)
            {
            case ComponentSystemGroup group:
                var groupNode = Pool <ComponentGroupNode> .GetPooled();

                groupNode.Value = group;
                node            = groupNode;
                foreach (var s in group.Systems)
                {
                    Parse(s, graph, node);
                }
                break;

            default:
                var systemNode = Pool <ComponentSystemBaseNode> .GetPooled();

                systemNode.Value = system;
                node             = systemNode;

                var recorder    = Recorder.Get($"{system.World?.Name ?? "none"} {system.GetType().FullName}");
                var recorderKey = new RecorderKey
                {
                    World  = system.World,
                    Group  = (ComponentSystemGroup)((ComponentGroupNode)parent).System,
                    System = system
                };

                if (!graph.RecordersBySystem.ContainsKey(recorderKey))
                {
                    graph.RecordersBySystem.Add(recorderKey, new AverageRecorder(recorder));
                }
                else
                {
                    UnityEngine.Debug.LogError("System added twice: " + system);
                }

                recorder.enabled = true;
                break;
            }

            AddToGraph(graph, node, parent);
        }
        static bool DidChange(PlayerLoopSystemGraph lhs, PlayerLoopSystemGraph rhs)
        {
            if (lhs.Roots.Count != rhs.Roots.Count)
            {
                return(true);
            }

            for (var i = 0; i < lhs.Roots.Count; ++i)
            {
                if (DidChange(lhs.Roots[i], rhs.Roots[i]))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #12
0
        static void ValidateCurrentGraph()
        {
            var now = DateTime.Now;

            if (now - s_LastValidate < s_OneSecond)
            {
                return;
            }

            s_LastValidate = now;

            var graph = new PlayerLoopSystemGraph();

            ParsePlayerLoopSystem(PlayerLoop.GetCurrentPlayerLoop(), graph);
            if (!DidChange(Current, graph))
            {
                graph.Reset();
                return;
            }

            Current.Reset();
            Current = graph;
            OnGraphChanged?.Invoke();
        }
 // Parse through the player loop system to get all system list and their parent-children relationship,
 // which will be used to build the treeview.
 public static void ParsePlayerLoopSystem(PlayerLoopSystem rootPlayerLoopSystem, PlayerLoopSystemGraph graph)
 {
     graph.Reset();
     Parse(rootPlayerLoopSystem, graph);
 }