Beispiel #1
0
 void drawStepper(DebugSystems systems)
 {
     EditorGUILayout.BeginVertical(GUI.skin.box);
     {
         EditorGUILayout.LabelField("Step Mode", EditorStyles.boldLabel);
         EditorGUILayout.BeginHorizontal();
         {
             var buttonStyle = new GUIStyle(GUI.skin.button);
             if (systems.paused)
             {
                 buttonStyle.normal = GUI.skin.button.active;
             }
             if (GUILayout.Button("▌▌", buttonStyle, GUILayout.Width(50)))
             {
                 systems.paused = !systems.paused;
             }
             if (GUILayout.Button("Step", GUILayout.Width(100)))
             {
                 systems.paused = true;
                 systems.Step();
                 addDuration((float)systems.totalDuration);
                 _systemsMonitor.Draw(_systemMonitorData.ToArray(), 80f);
             }
             GUILayout.FlexibleSpace();
         }
         EditorGUILayout.EndHorizontal();
     }
     EditorGUILayout.EndVertical();
 }
Beispiel #2
0
        void drawSystemsMonitor(DebugSystems systems)
        {
            if (_systemsMonitor == null)
            {
                _systemsMonitor    = new SystemsMonitor(SYSTEM_MONITOR_DATA_LENGTH);
                _systemMonitorData = new Queue <float>(new float[SYSTEM_MONITOR_DATA_LENGTH]);
                if (EditorApplication.update != Repaint)
                {
                    EditorApplication.update += Repaint;
                }
            }

            EditorGUILayout.BeginVertical(GUI.skin.box);
            {
                EditorGUILayout.LabelField("Execution duration", EditorStyles.boldLabel);
                EditorGUILayout.LabelField("Total", systems.totalDuration.ToString());
                EditorGUILayout.Space();

                if (!EditorApplication.isPaused && !systems.paused)
                {
                    addDuration((float)systems.totalDuration);
                }
                _systemsMonitor.Draw(_systemMonitorData.ToArray(), 80f);
            }
            EditorGUILayout.EndVertical();
        }
 void drawStepper(DebugSystems systems) {
     EditorGUILayout.BeginVertical(GUI.skin.box);
     {
         EditorGUILayout.LabelField("Step Mode", EditorStyles.boldLabel);
         EditorGUILayout.BeginHorizontal();
         {
             var buttonStyle = new GUIStyle(GUI.skin.button);
             if (systems.paused) {
                 buttonStyle.normal = GUI.skin.button.active;
             }
             if (GUILayout.Button("▌▌", buttonStyle, GUILayout.Width(50))) {
                 systems.paused = !systems.paused;
             }
             if (GUILayout.Button("Step", GUILayout.Width(100))) {
                 systems.paused = true;
                 systems.Step();
                 addDuration((float)systems.totalDuration);
                 _systemsMonitor.Draw(_systemMonitorData.ToArray(), 80f);
             }
             GUILayout.FlexibleSpace();
         }
         EditorGUILayout.EndHorizontal();
     }
     EditorGUILayout.EndVertical();
 }
Beispiel #4
0
        static bool shouldShowSystems(DebugSystems systems, SystemInterfaceFlags type)
        {
            if (!_hideEmptySystems)
            {
                return(true);
            }

            switch (type)
            {
            case SystemInterfaceFlags.IInitializeSystem:
                return(systems.totalInitializeSystemsCount > 0);

            case SystemInterfaceFlags.IExecuteSystem:
                return(systems.totalExecuteSystemsCount > 0);

            case SystemInterfaceFlags.ICleanupSystem:
                return(systems.totalCleanupSystemsCount > 0);

            case SystemInterfaceFlags.ITearDownSystem:
                return(systems.totalTearDownSystemsCount > 0);

            default:
                return(true);
            }
        }
 Systems createSubSystems() {
     var allSystems = createAllSystemCombinations();
     var subSystems = new DebugSystems("Sub Systems").Add(allSystems);
     
     return new DebugSystems("Systems with SubSystems")
         .Add(allSystems)
         .Add(allSystems)
         .Add(subSystems)
         .Add(subSystems);
 }
 static void drawSystemsOverview(DebugSystems systems) {
     EditorGUILayout.BeginVertical(GUI.skin.box);
     {
         EditorGUILayout.LabelField(systems.name, EditorStyles.boldLabel);
         EditorGUILayout.LabelField("Initialize Systems", systems.initializeSystemsCount.ToString());
         EditorGUILayout.LabelField("Execute Systems", systems.executeSystemsCount.ToString());
         EditorGUILayout.LabelField("Total Systems", systems.totalSystemsCount.ToString());
     }
     EditorGUILayout.EndVertical();
 }
    Systems createEmptySystems() {
        var systems1 = new DebugSystems("Empty 1");
        var systems2 = new DebugSystems("Empty 2");
        var systems3 = new DebugSystems("Empty 3");

        systems1.Add(systems2);
        systems2.Add(systems3);

        return new DebugSystems("Empty Systems")
            .Add(systems1);
    }
Beispiel #8
0
 static void drawSystemsOverview(DebugSystems systems)
 {
     EntitasEditorLayout.BeginVerticalBox();
     {
         EditorGUILayout.LabelField(systems.name, EditorStyles.boldLabel);
         EditorGUILayout.LabelField("Initialize Systems", systems.initializeSystemsCount.ToString());
         EditorGUILayout.LabelField("Execute Systems", systems.executeSystemsCount.ToString());
         EditorGUILayout.LabelField("Total Systems", systems.totalSystemsCount.ToString());
     }
     EntitasEditorLayout.EndVertical();
 }
    Systems createNestedSystems() {
        var systems1 = new DebugSystems("Nested 1");
        var systems2 = new DebugSystems("Nested 2");
        var systems3 = new DebugSystems("Nested 3");

        systems1.Add(systems2);
        systems2.Add(systems3);
        systems1.Add(createSomeSystems());

        return new DebugSystems("Nested Systems")
            .Add(systems1);
    }
        static bool showSystems(DebugSystems systems, bool initOnly)
        {
            if (!_hideEmptySystems) {
                return true;
            }

            if (initOnly) {
                return systems.totalInitializeSystemsCount > 0;
            }

            return systems.totalExecuteSystemsCount > 0;
        }
Beispiel #11
0
        void drawSystemsMonitor(DebugSystems systems)
        {
            if (_systemsMonitor == null)
            {
                _systemsMonitor    = new SystemsMonitor(SYSTEM_MONITOR_DATA_LENGTH);
                _systemMonitorData = new Queue <float>(new float[SYSTEM_MONITOR_DATA_LENGTH]);
            }

            _showSystemsMonitor = EntitasEditorLayout.DrawSectionHeaderToggle("Performance", _showSystemsMonitor);
            if (_showSystemsMonitor)
            {
                EntitasEditorLayout.BeginSectionContent();
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        EditorGUILayout.BeginVertical();
                        {
                            EditorGUILayout.LabelField("Execution duration", systems.executeDuration.ToString());
                            EditorGUILayout.LabelField("Cleanup duration", systems.cleanupDuration.ToString());
                        }
                        EditorGUILayout.EndVertical();

                        if (_stepButtonContent == null)
                        {
                            _stepButtonContent = EditorGUIUtility.IconContent("StepButton On");
                        }
                        if (_pauseButtonContent == null)
                        {
                            _pauseButtonContent = EditorGUIUtility.IconContent("PauseButton On");
                        }

                        systems.paused = GUILayout.Toggle(systems.paused, _pauseButtonContent, "CommandLeft");

                        if (GUILayout.Button(_stepButtonContent, "CommandRight"))
                        {
                            systems.paused = true;
                            systems.StepExecute();
                            systems.StepCleanup();
                            addDuration((float)systems.executeDuration + (float)systems.cleanupDuration);
                        }
                    }
                    EditorGUILayout.EndHorizontal();

                    if (!EditorApplication.isPaused && !systems.paused)
                    {
                        addDuration((float)systems.executeDuration + (float)systems.cleanupDuration);
                    }
                    _systemsMonitor.Draw(_systemMonitorData.ToArray(), 80f);
                }
                EntitasEditorLayout.EndSectionContent();
            }
        }
 static void drawSystemsOverview(DebugSystems systems)
 {
     EntitasEditorLayout.BeginVerticalBox();
     {
         EditorGUILayout.LabelField(systems.name, EditorStyles.boldLabel);
         EditorGUILayout.LabelField("Initialize Systems", systems.totalInitializeSystemsCount.ToString());
         EditorGUILayout.LabelField("Execute Systems", systems.totalExecuteSystemsCount.ToString());
         EditorGUILayout.LabelField("Cleanup Systems", systems.totalCleanupSystemsCount.ToString());
         EditorGUILayout.LabelField("TearDown Systems", systems.totalTearDownSystemsCount.ToString());
         EditorGUILayout.LabelField("Total Systems", systems.totalSystemsCount.ToString());
     }
     EntitasEditorLayout.EndVertical();
 }
Beispiel #13
0
        void drawSystemList(DebugSystems systems)
        {
            EntitasEditorLayout.BeginVerticalBox();
            {
                EntitasEditorLayout.BeginHorizontal();
                {
                    DebugSystems.avgResetInterval = (AvgResetInterval)EditorGUILayout.EnumPopup("Reset average duration Ø", DebugSystems.avgResetInterval);
                    if (GUILayout.Button("Reset Ø now", GUILayout.Width(88), GUILayout.Height(14)))
                    {
                        systems.ResetDurations();
                    }
                }
                EntitasEditorLayout.EndHorizontal();

                _threshold        = EditorGUILayout.Slider("Threshold Ø ms", _threshold, 0f, 33f);
                _sortSystemInfos  = EditorGUILayout.Toggle("Sort by execution duration", _sortSystemInfos);
                _hideEmptySystems = EditorGUILayout.Toggle("Hide empty systems", _hideEmptySystems);
                EditorGUILayout.Space();

                _systemNameSearchTerm = EditorGUILayout.TextField("Search", _systemNameSearchTerm);

                _showInitializeSystems = EditorGUILayout.Foldout(_showInitializeSystems, "Initialize Systems");
                if (_showInitializeSystems && shouldShowSystems(systems, true))
                {
                    EntitasEditorLayout.BeginVerticalBox();
                    {
                        var systemsDrawn = drawSystemInfos(systems, true, false);
                        if (systemsDrawn == 0)
                        {
                            EditorGUILayout.LabelField(string.Empty);
                        }
                    }
                    EntitasEditorLayout.EndVertical();
                }

                _showExecuteSystems = EditorGUILayout.Foldout(_showExecuteSystems, "Execute Systems");
                if (_showExecuteSystems && shouldShowSystems(systems, false))
                {
                    EntitasEditorLayout.BeginVerticalBox();
                    {
                        var systemsDrawn = drawSystemInfos(systems, false, false);
                        if (systemsDrawn == 0)
                        {
                            EditorGUILayout.LabelField(string.Empty);
                        }
                    }
                    EntitasEditorLayout.EndVertical();
                }
            }
            EntitasEditorLayout.EndVertical();
        }
Beispiel #14
0
        static bool shouldShowSystems(DebugSystems systems, bool initOnly)
        {
            if (!_hideEmptySystems)
            {
                return(true);
            }

            if (initOnly)
            {
                return(systems.totalInitializeSystemsCount > 0);
            }

            return(systems.totalExecuteSystemsCount > 0);
        }
Beispiel #15
0
        void drawSystemsMonitor(DebugSystems systems)
        {
            if (_systemsMonitor == null)
            {
                _systemsMonitor    = new SystemsMonitor(SYSTEM_MONITOR_DATA_LENGTH);
                _systemMonitorData = new Queue <float>(new float[SYSTEM_MONITOR_DATA_LENGTH]);
                if (EditorApplication.update != Repaint)
                {
                    EditorApplication.update += Repaint;
                }
            }

            EntitasEditorLayout.BeginVerticalBox();
            {
                EditorGUILayout.LabelField("Execution duration", EditorStyles.boldLabel);

                EntitasEditorLayout.BeginHorizontal();
                {
                    EditorGUILayout.LabelField("Total", systems.totalDuration.ToString());

                    var buttonStyle = new GUIStyle(GUI.skin.button);
                    if (systems.paused)
                    {
                        buttonStyle.normal = GUI.skin.button.active;
                    }
                    if (GUILayout.Button("▌▌", buttonStyle, GUILayout.Width(50)))
                    {
                        systems.paused = !systems.paused;
                    }
                    if (GUILayout.Button("Step", GUILayout.Width(50)))
                    {
                        systems.paused = true;
                        systems.Step();
                        addDuration((float)systems.totalDuration);
                        _systemsMonitor.Draw(_systemMonitorData.ToArray(), 80f);
                    }
                }
                EntitasEditorLayout.EndHorizontal();

                if (!EditorApplication.isPaused && !systems.paused)
                {
                    addDuration((float)systems.totalDuration);
                }
                _systemsMonitor.Draw(_systemMonitorData.ToArray(), 80f);
            }
            EntitasEditorLayout.EndVertical();
        }
Beispiel #16
0
 static void drawSystemsOverview(DebugSystems systems)
 {
     _showDetails = EntitasEditorLayout.DrawSectionHeaderToggle("Details", _showDetails);
     if (_showDetails)
     {
         EntitasEditorLayout.BeginSectionContent();
         {
             EditorGUILayout.LabelField(systems.name, EditorStyles.boldLabel);
             EditorGUILayout.LabelField("Initialize Systems", systems.totalInitializeSystemsCount.ToString());
             EditorGUILayout.LabelField("Execute Systems", systems.totalExecuteSystemsCount.ToString());
             EditorGUILayout.LabelField("Cleanup Systems", systems.totalCleanupSystemsCount.ToString());
             EditorGUILayout.LabelField("TearDown Systems", systems.totalTearDownSystemsCount.ToString());
             EditorGUILayout.LabelField("Total Systems", systems.totalSystemsCount.ToString());
         }
         EntitasEditorLayout.EndSectionContent();
     }
 }
        void drawSystemList(DebugSystems systems)
        {
            EditorGUILayout.BeginVertical(GUI.skin.box);
            {
                EditorGUILayout.BeginHorizontal();
                {
                    DebugSystems.avgResetInterval = (AvgResetInterval)EditorGUILayout.EnumPopup("Reset average duration Ø", DebugSystems.avgResetInterval);
                    if (GUILayout.Button("Reset Ø now", GUILayout.Width(88), GUILayout.Height(14)))
                    {
                        systems.ResetDurations();
                    }
                }
                EditorGUILayout.EndHorizontal();

                _threshold        = EditorGUILayout.Slider("Threshold Ø ms", _threshold, 0f, 33f);
                _sortSystemInfos  = EditorGUILayout.Toggle("Sort by execution duration", _sortSystemInfos);
                _hideEmptySystems = EditorGUILayout.Toggle("Hide empty systems", _hideEmptySystems);
                EditorGUILayout.Space();

                _showInitializeSystems = EditorGUILayout.Foldout(_showInitializeSystems, "Initialize Systems");
                if (_showInitializeSystems && showSystems(systems, true))
                {
                    EditorGUILayout.BeginVertical(GUI.skin.box);
                    {
                        drawSystemInfos(systems, true, false);
                    }
                    EditorGUILayout.EndVertical();
                }

                _showExecuteSystems = EditorGUILayout.Foldout(_showExecuteSystems, "Execute Systems");
                if (_showExecuteSystems && showSystems(systems, false))
                {
                    EditorGUILayout.BeginVertical(GUI.skin.box);
                    {
                        drawSystemInfos(systems, false, false);
                    }
                    EditorGUILayout.EndVertical();
                }
            }
            EditorGUILayout.EndVertical();
        }
        void drawSystemsMonitor(DebugSystems systems) {
            if (_systemsMonitor == null) {
                _systemsMonitor = new SystemsMonitor(SYSTEM_MONITOR_DATA_LENGTH);
                _systemMonitorData = new Queue<float>(new float[SYSTEM_MONITOR_DATA_LENGTH]);
                if (EditorApplication.update != Repaint) {
                    EditorApplication.update += Repaint;
                }
            }

            EditorGUILayout.BeginVertical(GUI.skin.box);
            {
                EditorGUILayout.LabelField("Execution duration", EditorStyles.boldLabel);
                EditorGUILayout.LabelField("Total", systems.totalDuration.ToString());
                EditorGUILayout.Space();

                if (!EditorApplication.isPaused && !systems.paused) {
                    addDuration((float)systems.totalDuration);
                }
                _systemsMonitor.Draw(_systemMonitorData.ToArray(), 80f);
            }
            EditorGUILayout.EndVertical();
        }
 public void Init(DebugSystems systems)
 {
     _systems = systems;
 }
        void drawSystemInfos(DebugSystems systems, bool initOnly, bool isChildSysem)
        {
            var systemInfos = initOnly ? systems.initializeSystemInfos : systems.executeSystemInfos;

            systemInfos = systemInfos
                          .Where(systemInfo => systemInfo.averageExecutionDuration >= _threshold)
                          .ToArray();

            if (_sortSystemInfos)
            {
                systemInfos = systemInfos
                              .OrderByDescending(systemInfo => systemInfo.averageExecutionDuration)
                              .ToArray();
            }

            foreach (var systemInfo in systemInfos)
            {
                var debugSystems = systemInfo.system as DebugSystems;
                if (debugSystems != null)
                {
                    if (!showSystems(debugSystems, initOnly))
                    {
                        continue;
                    }
                }

                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUI.BeginDisabledGroup(isChildSysem);
                    {
                        systemInfo.isActive = EditorGUILayout.Toggle(systemInfo.isActive, GUILayout.Width(20));
                    }
                    EditorGUI.EndDisabledGroup();
                    var reactiveSystem = systemInfo.system as ReactiveSystem;
                    if (reactiveSystem != null)
                    {
                        if (systemInfo.isActive)
                        {
                            reactiveSystem.Activate();
                        }
                        else
                        {
                            reactiveSystem.Deactivate();
                        }
                    }

                    var avg = string.Format("Ø {0:0.000}", systemInfo.averageExecutionDuration).PadRight(9);
                    var min = string.Format("min {0:0.000}", systemInfo.minExecutionDuration).PadRight(11);
                    var max = string.Format("max {0:0.000}", systemInfo.maxExecutionDuration);

                    EditorGUILayout.LabelField(systemInfo.systemName, avg + "\t" + min + "\t" + max, getSystemStyle(systemInfo));
                }
                EditorGUILayout.EndHorizontal();

                var debugSystem = systemInfo.system as DebugSystems;
                if (debugSystem != null)
                {
                    var indent = EditorGUI.indentLevel;
                    EditorGUI.indentLevel += 1;
                    drawSystemInfos(debugSystem, initOnly, true);
                    EditorGUI.indentLevel = indent;
                }
            }
        }
Beispiel #21
0
        int drawSystemInfos(DebugSystems systems, SystemInterfaceFlags type)
        {
            SystemInfo[] systemInfos = null;

            switch (type)
            {
            case SystemInterfaceFlags.IInitializeSystem:
                systemInfos = systems.initializeSystemInfos
                              .Where(systemInfo => systemInfo.initializationDuration >= _threshold)
                              .ToArray();
                break;

            case SystemInterfaceFlags.IExecuteSystem:
                systemInfos = systems.executeSystemInfos
                              .Where(systemInfo => systemInfo.averageExecutionDuration >= _threshold)
                              .ToArray();
                break;

            case SystemInterfaceFlags.ICleanupSystem:
                systemInfos = systems.cleanupSystemInfos
                              .Where(systemInfo => systemInfo.cleanupDuration >= _threshold)
                              .ToArray();
                break;

            case SystemInterfaceFlags.ITearDownSystem:
                systemInfos = systems.tearDownSystemInfos
                              .Where(systemInfo => systemInfo.teardownDuration >= _threshold)
                              .ToArray();
                break;
            }

            systemInfos = getSortedSystemInfos(systemInfos, _systemSortMethod);

            var systemsDrawn = 0;

            foreach (var systemInfo in systemInfos)
            {
                var debugSystems = systemInfo.system as DebugSystems;
                if (debugSystems != null)
                {
                    if (!shouldShowSystems(debugSystems, type))
                    {
                        continue;
                    }
                }

                if (EntitasEditorLayout.MatchesSearchString(systemInfo.systemName.ToLower(), _systemNameSearchString.ToLower()))
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        var indent = EditorGUI.indentLevel;
                        EditorGUI.indentLevel = 0;

                        var wasActive = systemInfo.isActive;
                        if (systemInfo.areAllParentsActive)
                        {
                            systemInfo.isActive = EditorGUILayout.Toggle(systemInfo.isActive, GUILayout.Width(20));
                        }
                        else
                        {
                            EditorGUI.BeginDisabledGroup(true);
                            {
                                EditorGUILayout.Toggle(false, GUILayout.Width(20));
                            }
                        }
                        EditorGUI.EndDisabledGroup();

                        EditorGUI.indentLevel = indent;

                        if (systemInfo.isActive != wasActive)
                        {
                            var reactiveSystem = systemInfo.system as IReactiveSystem;
                            if (reactiveSystem != null)
                            {
                                if (systemInfo.isActive)
                                {
                                    reactiveSystem.Activate();
                                }
                                else
                                {
                                    reactiveSystem.Deactivate();
                                }
                            }
                        }

                        switch (type)
                        {
                        case SystemInterfaceFlags.IInitializeSystem:
                            EditorGUILayout.LabelField(systemInfo.systemName, systemInfo.initializationDuration.ToString(), getSystemStyle(systemInfo));
                            break;

                        case SystemInterfaceFlags.IExecuteSystem:
                            var avgE = string.Format("Ø {0:00.000}", systemInfo.averageExecutionDuration).PadRight(12);
                            var minE = string.Format("▼ {0:00.000}", systemInfo.minExecutionDuration).PadRight(12);
                            var maxE = string.Format("▲ {0:00.000}", systemInfo.maxExecutionDuration);
                            EditorGUILayout.LabelField(systemInfo.systemName, avgE + minE + maxE, getSystemStyle(systemInfo));
                            break;

                        case SystemInterfaceFlags.ICleanupSystem:
                            var avgC = string.Format("Ø {0:00.000}", systemInfo.averageCleanupDuration).PadRight(12);
                            var minC = string.Format("▼ {0:00.000}", systemInfo.minCleanupDuration).PadRight(12);
                            var maxC = string.Format("▲ {0:00.000}", systemInfo.maxCleanupDuration);
                            EditorGUILayout.LabelField(systemInfo.systemName, avgC + minC + maxC, getSystemStyle(systemInfo));
                            break;

                        case SystemInterfaceFlags.ITearDownSystem:
                            EditorGUILayout.LabelField(systemInfo.systemName, systemInfo.teardownDuration.ToString(), getSystemStyle(systemInfo));
                            break;
                        }
                    }
                    EditorGUILayout.EndHorizontal();

                    systemsDrawn += 1;
                }

                var debugSystem = systemInfo.system as DebugSystems;
                if (debugSystem != null)
                {
                    var indent = EditorGUI.indentLevel;
                    EditorGUI.indentLevel += 1;
                    systemsDrawn          += drawSystemInfos(debugSystem, type);
                    EditorGUI.indentLevel  = indent;
                }
            }

            return(systemsDrawn);
        }
Beispiel #22
0
        void drawSystemList(DebugSystems systems)
        {
            _showSystemsList = EntitasEditorLayout.DrawSectionHeaderToggle("Systems", _showSystemsList);
            if (_showSystemsList)
            {
                EntitasEditorLayout.BeginSectionContent();
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        DebugSystems.avgResetInterval = (AvgResetInterval)EditorGUILayout.EnumPopup("Reset average duration Ø", DebugSystems.avgResetInterval);
                        if (GUILayout.Button("Reset Ø now", EditorStyles.miniButton, GUILayout.Width(88)))
                        {
                            systems.ResetDurations();
                        }
                    }
                    EditorGUILayout.EndHorizontal();

                    _threshold = EditorGUILayout.Slider("Threshold Ø ms", _threshold, 0f, 33f);

                    _hideEmptySystems = EditorGUILayout.Toggle("Hide empty systems", _hideEmptySystems);
                    EditorGUILayout.Space();

                    EditorGUILayout.BeginHorizontal();
                    {
                        _systemSortMethod       = (SortMethod)EditorGUILayout.EnumPopup(_systemSortMethod, EditorStyles.popup, GUILayout.Width(150));
                        _systemNameSearchString = EntitasEditorLayout.SearchTextField(_systemNameSearchString);
                    }
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.Space();

                    _showInitializeSystems = EntitasEditorLayout.DrawSectionHeaderToggle("Initialize Systems", _showInitializeSystems);
                    if (_showInitializeSystems && shouldShowSystems(systems, SystemInterfaceFlags.IInitializeSystem))
                    {
                        EntitasEditorLayout.BeginSectionContent();
                        {
                            var systemsDrawn = drawSystemInfos(systems, SystemInterfaceFlags.IInitializeSystem);
                            if (systemsDrawn == 0)
                            {
                                EditorGUILayout.LabelField(string.Empty);
                            }
                        }
                        EntitasEditorLayout.EndSectionContent();
                    }

                    _showExecuteSystems = EntitasEditorLayout.DrawSectionHeaderToggle("Execute Systems", _showExecuteSystems);
                    if (_showExecuteSystems && shouldShowSystems(systems, SystemInterfaceFlags.IExecuteSystem))
                    {
                        EntitasEditorLayout.BeginSectionContent();
                        {
                            var systemsDrawn = drawSystemInfos(systems, SystemInterfaceFlags.IExecuteSystem);
                            if (systemsDrawn == 0)
                            {
                                EditorGUILayout.LabelField(string.Empty);
                            }
                        }
                        EntitasEditorLayout.EndSectionContent();
                    }

                    _showCleanupSystems = EntitasEditorLayout.DrawSectionHeaderToggle("Cleanup Systems", _showCleanupSystems);
                    if (_showCleanupSystems && shouldShowSystems(systems, SystemInterfaceFlags.ICleanupSystem))
                    {
                        EntitasEditorLayout.BeginSectionContent();
                        {
                            var systemsDrawn = drawSystemInfos(systems, SystemInterfaceFlags.ICleanupSystem);
                            if (systemsDrawn == 0)
                            {
                                EditorGUILayout.LabelField(string.Empty);
                            }
                        }
                        EntitasEditorLayout.EndSectionContent();
                    }

                    _showTearDownSystems = EntitasEditorLayout.DrawSectionHeaderToggle("TearDown Systems", _showTearDownSystems);
                    if (_showTearDownSystems && shouldShowSystems(systems, SystemInterfaceFlags.ITearDownSystem))
                    {
                        EntitasEditorLayout.BeginSectionContent();
                        {
                            var systemsDrawn = drawSystemInfos(systems, SystemInterfaceFlags.ITearDownSystem);
                            if (systemsDrawn == 0)
                            {
                                EditorGUILayout.LabelField(string.Empty);
                            }
                        }
                        EntitasEditorLayout.EndSectionContent();
                    }
                }
                EntitasEditorLayout.EndSectionContent();
            }
        }
        int drawSystemInfos(DebugSystems systems, bool initOnly, bool isChildSysem)
        {
            var systemInfos = initOnly ? systems.initializeSystemInfos : systems.executeSystemInfos;
            systemInfos = systemInfos
                .Where(systemInfo => systemInfo.averageExecutionDuration >= _threshold)
                .ToArray();

            systemInfos = getSortedSystemInfos(systemInfos, _systemSortMethod);

            var systemsDrawn = 0;
            foreach (var systemInfo in systemInfos) {
                var debugSystems = systemInfo.system as DebugSystems;
                if (debugSystems != null) {
                    if (!shouldShowSystems(debugSystems, initOnly)) {
                        continue;
                    }
                }

                if (systemInfo.systemName.ToLower().Contains(_systemNameSearchTerm.ToLower())) {
                    EntitasEditorLayout.BeginHorizontal();
                    {
                        EditorGUI.BeginDisabledGroup(isChildSysem);
                        {
                            systemInfo.isActive = EditorGUILayout.Toggle(systemInfo.isActive, GUILayout.Width(20));
                        }
                        EditorGUI.EndDisabledGroup();
                        var reactiveSystem = systemInfo.system as ReactiveSystem;
                        if (reactiveSystem != null) {
                            if (systemInfo.isActive) {
                                reactiveSystem.Activate();
                            } else {
                                reactiveSystem.Deactivate();
                            }
                        }

                        var avg = string.Format("Ø {0:00.000}", systemInfo.averageExecutionDuration).PadRight(12);
                        var min = string.Format("▼ {0:00.000}", systemInfo.minExecutionDuration).PadRight(12);
                        var max = string.Format("▲ {0:00.000}", systemInfo.maxExecutionDuration);

                        EditorGUILayout.LabelField(systemInfo.systemName, avg + min + max, getSystemStyle(systemInfo));
                    }
                    EntitasEditorLayout.EndHorizontal();

                    systemsDrawn += 1;
                }

                var debugSystem = systemInfo.system as DebugSystems;
                if (debugSystem != null) {
                    var indent = EditorGUI.indentLevel;
                    EditorGUI.indentLevel += 1;
                    systemsDrawn += drawSystemInfos(debugSystem, initOnly, true);
                    EditorGUI.indentLevel = indent;
                }
            }

            return systemsDrawn;
        }
        void drawSystemList(DebugSystems systems)
        {
            EntitasEditorLayout.BeginVerticalBox();
            {
                EntitasEditorLayout.BeginHorizontal();
                {
                    DebugSystems.avgResetInterval = (AvgResetInterval)EditorGUILayout.EnumPopup("Reset average duration Ø", DebugSystems.avgResetInterval);
                    if (GUILayout.Button("Reset Ø now", GUILayout.Width(88), GUILayout.Height(14))) {
                        systems.ResetDurations();
                    }
                }
                EntitasEditorLayout.EndHorizontal();

                _threshold = EditorGUILayout.Slider("Threshold Ø ms", _threshold, 0f, 33f);
                _systemSortMethod = (SortMethod)EditorGUILayout.EnumPopup("Sort by ", _systemSortMethod);
                _hideEmptySystems = EditorGUILayout.Toggle("Hide empty systems", _hideEmptySystems);
                EditorGUILayout.Space();

                EntitasEditorLayout.BeginHorizontal();
                {
                    _systemNameSearchTerm = EditorGUILayout.TextField("Search", _systemNameSearchTerm);

                    const string clearButtonControlName = "Clear Button";
                    GUI.SetNextControlName(clearButtonControlName);
                    if (GUILayout.Button("x", GUILayout.Width(19), GUILayout.Height(14))) {
                        _systemNameSearchTerm = string.Empty;
                        GUI.FocusControl(clearButtonControlName);
                    }
                }
                EntitasEditorLayout.EndHorizontal();

                _showInitializeSystems = EditorGUILayout.Foldout(_showInitializeSystems, "Initialize Systems");
                if (_showInitializeSystems && shouldShowSystems(systems, true)) {
                    EntitasEditorLayout.BeginVerticalBox();
                    {
                        var systemsDrawn = drawSystemInfos(systems, true, false);
                        if (systemsDrawn == 0) {
                            EditorGUILayout.LabelField(string.Empty);
                        }
                    }
                    EntitasEditorLayout.EndVertical();
                }

                _showExecuteSystems = EditorGUILayout.Foldout(_showExecuteSystems, "Execute Systems");
                if (_showExecuteSystems && shouldShowSystems(systems, false)) {
                    EntitasEditorLayout.BeginVerticalBox();
                    {
                        var systemsDrawn = drawSystemInfos(systems, false, false);
                        if (systemsDrawn == 0) {
                            EditorGUILayout.LabelField(string.Empty);
                        }
                    }
                    EntitasEditorLayout.EndVertical();
                }
            }
            EntitasEditorLayout.EndVertical();
        }
Beispiel #25
0
        int drawSystemInfos(DebugSystems systems, bool initOnly, bool isChildSysem)
        {
            var systemInfos = initOnly ? systems.initializeSystemInfos : systems.executeSystemInfos;

            systemInfos = systemInfos
                          .Where(systemInfo => systemInfo.averageExecutionDuration >= _threshold)
                          .ToArray();

            systemInfos = getSortedSystemInfos(systemInfos, _systemSortMethod);

            var systemsDrawn = 0;

            foreach (var systemInfo in systemInfos)
            {
                var debugSystems = systemInfo.system as DebugSystems;
                if (debugSystems != null)
                {
                    if (!shouldShowSystems(debugSystems, initOnly))
                    {
                        continue;
                    }
                }

                if (systemInfo.systemName.ToLower().Contains(_systemNameSearchTerm.ToLower()))
                {
                    EntitasEditorLayout.BeginHorizontal();
                    {
                        EditorGUI.BeginDisabledGroup(isChildSysem);
                        {
                            systemInfo.isActive = EditorGUILayout.Toggle(systemInfo.isActive, GUILayout.Width(20));
                        }
                        EditorGUI.EndDisabledGroup();
                        var reactiveSystem = systemInfo.system as ReactiveSystem;
                        if (reactiveSystem != null)
                        {
                            if (systemInfo.isActive)
                            {
                                reactiveSystem.Activate();
                            }
                            else
                            {
                                reactiveSystem.Deactivate();
                            }
                        }

                        var avg = string.Format("Ø {0:00.000}", systemInfo.averageExecutionDuration).PadRight(12);
                        var min = string.Format("▼ {0:00.000}", systemInfo.minExecutionDuration).PadRight(12);
                        var max = string.Format("▲ {0:00.000}", systemInfo.maxExecutionDuration);

                        EditorGUILayout.LabelField(systemInfo.systemName, avg + min + max, getSystemStyle(systemInfo));
                    }
                    EntitasEditorLayout.EndHorizontal();

                    systemsDrawn += 1;
                }

                var debugSystem = systemInfo.system as DebugSystems;
                if (debugSystem != null)
                {
                    var indent = EditorGUI.indentLevel;
                    EditorGUI.indentLevel += 1;
                    systemsDrawn          += drawSystemInfos(debugSystem, initOnly, true);
                    EditorGUI.indentLevel  = indent;
                }
            }

            return(systemsDrawn);
        }
        void drawSystemsMonitor(DebugSystems systems)
        {
            if (_systemsMonitor == null) {
                _systemsMonitor = new SystemsMonitor(SYSTEM_MONITOR_DATA_LENGTH);
                _systemMonitorData = new Queue<float>(new float[SYSTEM_MONITOR_DATA_LENGTH]);
            }

            EntitasEditorLayout.BeginVerticalBox();
            {
                EditorGUILayout.LabelField("Execution duration", EditorStyles.boldLabel);

                EntitasEditorLayout.BeginHorizontal();
                {
                    EditorGUILayout.LabelField("Total", systems.totalDuration.ToString());

                    var buttonStyle = new GUIStyle(GUI.skin.button);
                    if (systems.paused) {
                        buttonStyle.normal = GUI.skin.button.active;
                    }
                    if (GUILayout.Button("▌▌", buttonStyle, GUILayout.Width(50))) {
                        systems.paused = !systems.paused;
                    }
                    if (GUILayout.Button("Step", GUILayout.Width(50))) {
                        systems.paused = true;
                        systems.Step();
                        addDuration((float)systems.totalDuration);
                        _systemsMonitor.Draw(_systemMonitorData.ToArray(), 80f);
                    }
                }
                EntitasEditorLayout.EndHorizontal();

                if (!EditorApplication.isPaused && !systems.paused) {
                    addDuration((float)systems.totalDuration);
                }
                _systemsMonitor.Draw(_systemMonitorData.ToArray(), 80f);
            }
            EntitasEditorLayout.EndVertical();
        }
        void drawSystemList(DebugSystems systems)
        {
            EntitasEditorLayout.BeginVerticalBox();
            {
                EntitasEditorLayout.BeginHorizontal();
                {
                    DebugSystems.avgResetInterval = (AvgResetInterval)EditorGUILayout.EnumPopup("Reset average duration Ø", DebugSystems.avgResetInterval);
                    if (GUILayout.Button("Reset Ø now", GUILayout.Width(88), GUILayout.Height(14)))
                    {
                        systems.ResetDurations();
                    }
                }
                EntitasEditorLayout.EndHorizontal();

                _threshold        = EditorGUILayout.Slider("Threshold Ø ms", _threshold, 0f, 33f);
                _systemSortMethod = (SortMethod)EditorGUILayout.EnumPopup("Sort by ", _systemSortMethod);
                _hideEmptySystems = EditorGUILayout.Toggle("Hide empty systems", _hideEmptySystems);
                EditorGUILayout.Space();

                EntitasEditorLayout.BeginHorizontal();
                {
                    _systemNameSearchTerm = EditorGUILayout.TextField("Search", _systemNameSearchTerm);

                    const string clearButtonControlName = "Clear Button";
                    GUI.SetNextControlName(clearButtonControlName);
                    if (GUILayout.Button("x", GUILayout.Width(19), GUILayout.Height(14)))
                    {
                        _systemNameSearchTerm = string.Empty;
                        GUI.FocusControl(clearButtonControlName);
                    }
                }
                EntitasEditorLayout.EndHorizontal();

                _showInitializeSystems = EntitasEditorLayout.Foldout(_showInitializeSystems, "Initialize Systems");
                if (_showInitializeSystems && shouldShowSystems(systems, SystemInterfaceFlags.IInitializeSystem))
                {
                    EntitasEditorLayout.BeginVerticalBox();
                    {
                        var systemsDrawn = drawSystemInfos(systems, SystemInterfaceFlags.IInitializeSystem, false);
                        if (systemsDrawn == 0)
                        {
                            EditorGUILayout.LabelField(string.Empty);
                        }
                    }
                    EntitasEditorLayout.EndVertical();
                }

                _showExecuteSystems = EntitasEditorLayout.Foldout(_showExecuteSystems, "Execute Systems");
                if (_showExecuteSystems && shouldShowSystems(systems, SystemInterfaceFlags.IExecuteSystem))
                {
                    EntitasEditorLayout.BeginVerticalBox();
                    {
                        var systemsDrawn = drawSystemInfos(systems, SystemInterfaceFlags.IExecuteSystem, false);
                        if (systemsDrawn == 0)
                        {
                            EditorGUILayout.LabelField(string.Empty);
                        }
                    }
                    EntitasEditorLayout.EndVertical();
                }

                _showCleanupSystems = EntitasEditorLayout.Foldout(_showCleanupSystems, "Cleanup Systems");
                if (_showCleanupSystems && shouldShowSystems(systems, SystemInterfaceFlags.ICleanupSystem))
                {
                    EntitasEditorLayout.BeginVerticalBox();
                    {
                        var systemsDrawn = drawSystemInfos(systems, SystemInterfaceFlags.ICleanupSystem, false);
                        if (systemsDrawn == 0)
                        {
                            EditorGUILayout.LabelField(string.Empty);
                        }
                    }
                    EntitasEditorLayout.EndVertical();
                }

                _showTearDownSystems = EntitasEditorLayout.Foldout(_showTearDownSystems, "TearDown Systems");
                if (_showTearDownSystems && shouldShowSystems(systems, SystemInterfaceFlags.ITearDownSystem))
                {
                    EntitasEditorLayout.BeginVerticalBox();
                    {
                        var systemsDrawn = drawSystemInfos(systems, SystemInterfaceFlags.ITearDownSystem, false);
                        if (systemsDrawn == 0)
                        {
                            EditorGUILayout.LabelField(string.Empty);
                        }
                    }
                    EntitasEditorLayout.EndVertical();
                }
            }
            EntitasEditorLayout.EndVertical();
        }
        void drawSystemInfos(DebugSystems systems, bool initOnly, bool isChildSysem)
        {
            var systemInfos = initOnly ? systems.initializeSystemInfos : systems.executeSystemInfos;
            systemInfos = systemInfos
                .Where(systemInfo => systemInfo.averageExecutionDuration >= _threshold)
                .ToArray();

            if (_sortSystemInfos) {
                systemInfos = systemInfos
                    .OrderByDescending(systemInfo => systemInfo.averageExecutionDuration)
                    .ToArray();
            }

            foreach (var systemInfo in systemInfos) {
                var debugSystems = systemInfo.system as DebugSystems;
                if (debugSystems != null) {
                    if (!showSystems(debugSystems, initOnly)) {
                        continue;
                    }
                }

                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUI.BeginDisabledGroup(isChildSysem);
                    {
                        systemInfo.isActive = EditorGUILayout.Toggle(systemInfo.isActive, GUILayout.Width(20));
                    }
                    EditorGUI.EndDisabledGroup();
                    var reactiveSystem = systemInfo.system as ReactiveSystem;
                    if (reactiveSystem != null) {
                        if (systemInfo.isActive) {
                            reactiveSystem.Activate();
                        } else {
                            reactiveSystem.Deactivate();
                        }
                    }

                    var avg = string.Format("Ø {0:0.000}", systemInfo.averageExecutionDuration).PadRight(9);
                    var min = string.Format("min {0:0.000}", systemInfo.minExecutionDuration).PadRight(11);
                    var max = string.Format("max {0:0.000}", systemInfo.maxExecutionDuration);

                    EditorGUILayout.LabelField(systemInfo.systemName, avg + "\t" + min + "\t" + max, getSystemStyle(systemInfo));
                }
                EditorGUILayout.EndHorizontal();

                var debugSystem = systemInfo.system as DebugSystems;
                if (debugSystem != null) {
                    var indent = EditorGUI.indentLevel;
                    EditorGUI.indentLevel += 1;
                    drawSystemInfos(debugSystem, initOnly, true);
                    EditorGUI.indentLevel = indent;
                }
            }
        }
        void drawSystemList(DebugSystems systems)
        {
            EditorGUILayout.BeginVertical(GUI.skin.box);
            {
                EditorGUILayout.BeginHorizontal();
                {
                    DebugSystems.avgResetInterval = (AvgResetInterval)EditorGUILayout.EnumPopup("Reset average duration Ø", DebugSystems.avgResetInterval);
                    if (GUILayout.Button("Reset Ø now", GUILayout.Width(88), GUILayout.Height(14))) {
                        systems.ResetDurations();
                    }
                }
                EditorGUILayout.EndHorizontal();

                _threshold = EditorGUILayout.Slider("Threshold Ø ms", _threshold, 0f, 33f);
                _sortSystemInfos = EditorGUILayout.Toggle("Sort by execution duration", _sortSystemInfos);
                _hideEmptySystems = EditorGUILayout.Toggle("Hide empty systems", _hideEmptySystems);
                EditorGUILayout.Space();

                _showInitializeSystems = EditorGUILayout.Foldout(_showInitializeSystems, "Initialize Systems");
                if (_showInitializeSystems && showSystems(systems, true)) {
                    EditorGUILayout.BeginVertical(GUI.skin.box);
                    {
                        drawSystemInfos(systems, true, false);
                    }
                    EditorGUILayout.EndVertical();
                }

                _showExecuteSystems = EditorGUILayout.Foldout(_showExecuteSystems, "Execute Systems");
                if (_showExecuteSystems && showSystems(systems, false)) {
                    EditorGUILayout.BeginVertical(GUI.skin.box);
                    {
                        drawSystemInfos(systems, false, false);
                    }
                    EditorGUILayout.EndVertical();
                }
            }
            EditorGUILayout.EndVertical();
        }
    void when_SystemInfo()
    {
        it["creates systemInfo for initialize system"] = () => {
            var system = new TestInitializeSystem();
            var info = new SystemInfo(system);

            info.system.should_be_same(system);
            info.systemName.should_be("TestInitialize");

            info.isInitializeSystems.should_be_true();
            info.isExecuteSystems.should_be_false();
            info.isReactiveSystems.should_be_false();

            info.accumulatedExecutionDuration.should_be(0);
            info.minExecutionDuration.should_be(0);
            info.maxExecutionDuration.should_be(0);
            info.averageExecutionDuration.should_be(0);

            info.isActive.should_be_true();
        };

        it["creates systemInfo for execute system"] = () => {
            var system = new TestExecuteSystem();
            var info = new SystemInfo(system);

            info.systemName.should_be("TestExecute");
            info.isInitializeSystems.should_be_false();
            info.isExecuteSystems.should_be_true();
            info.isReactiveSystems.should_be_false();
        };

        it["creates systemInfo for reactive system"] = () => {
            var system = new ReactiveSystem(new Pool(1), new TestReactiveSystem());
            var info = new SystemInfo(system);

            info.systemName.should_be("TestReactive");

            info.isInitializeSystems.should_be_false();
            info.isExecuteSystems.should_be_false();
            info.isReactiveSystems.should_be_true();
        };

        it["creates systemInfo for multi reactive system"] = () => {
            var system = new ReactiveSystem(new Pool(5), new TestMultiReactiveSystem());
            var info = new SystemInfo(system);

            info.systemName.should_be("TestMultiReactive");

            info.isInitializeSystems.should_be_false();
            info.isExecuteSystems.should_be_false();
            info.isReactiveSystems.should_be_true();
        };

        xit["uses name of DebugSystem"] = () => {
            const string systemName = "My System";
            var system = new DebugSystems(systemName);
            var info = new SystemInfo(system);
            info.systemName.should_be(systemName);
        };

        context["when created"] = () => {

            SystemInfo info = null;
            before = () => {
                info = new SystemInfo(new TestExecuteSystem());
            };

            it["adds execution duration"] = () => {
                info.AddExecutionDuration(42);

                info.accumulatedExecutionDuration.should_be(42);
                info.minExecutionDuration.should_be(42);
                info.maxExecutionDuration.should_be(42);
                info.averageExecutionDuration.should_be(42);
            };

            it["adds another execution duration"] = () => {
                info.AddExecutionDuration(20);
                info.AddExecutionDuration(10);

                info.accumulatedExecutionDuration.should_be(30);
                info.minExecutionDuration.should_be(10);
                info.maxExecutionDuration.should_be(20);
                info.averageExecutionDuration.should_be(15);
            };

            it["resets durations"] = () => {
                info.AddExecutionDuration(20);
                info.AddExecutionDuration(10);

                info.ResetDurations();

                info.accumulatedExecutionDuration.should_be(0);
                info.minExecutionDuration.should_be(10);
                info.maxExecutionDuration.should_be(20);
                info.averageExecutionDuration.should_be(0);
            };

            it["keeps min duration after reset"] = () => {
                info.AddExecutionDuration(20);
                info.AddExecutionDuration(10);

                info.ResetDurations();

                info.AddExecutionDuration(15);

                info.accumulatedExecutionDuration.should_be(15);
                info.minExecutionDuration.should_be(10);
                info.maxExecutionDuration.should_be(20);
                info.averageExecutionDuration.should_be(15);
            };
        };
    }
Beispiel #31
0
 public void Init(DebugSystems systems)
 {
     _systems = systems;
 }
        static bool shouldShowSystems(DebugSystems systems, SystemInterfaceFlags type)
        {
            if(!_hideEmptySystems) {
                return true;
            }

            switch(type) {
                case SystemInterfaceFlags.IInitializeSystem:
                    return systems.totalInitializeSystemsCount > 0;
                case SystemInterfaceFlags.IExecuteSystem:
                    return systems.totalExecuteSystemsCount > 0;
                case SystemInterfaceFlags.ICleanupSystem:
                    return systems.totalCleanupSystemsCount > 0;
                case SystemInterfaceFlags.ITearDownSystem:
                    return systems.totalTearDownSystemsCount > 0;
                default:
                    return true;
            }
        }