< Summary

Class:SceneDebugMetricModule
Assembly:FPSDisplay
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/Debugging/FPSDisplay/MetricsModules/SceneDebugMetricModule.cs
Covered lines:0
Uncovered lines:45
Coverable lines:45
Total lines:110
Line coverage:0% (0 of 45)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetUpModule(...)0%2100%
UpdateModule()0%12300%
EnableModule()0%2100%
DisableModule()0%2100%
SetSceneData()0%6200%
GetSceneMetric(...)0%2100%
OnMessageWillDequeue(...)0%2100%
OnMessageWillQueue(...)0%2100%
GetActiveScene()0%12300%
GetSceneID()0%2100%
Dispose()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/Debugging/FPSDisplay/MetricsModules/SceneDebugMetricModule.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using DCL;
 4using DCL.Controllers;
 5using DCL.FPSDisplay;
 6
 7public class SceneDebugMetricModule : IDebugMetricModule
 8{
 9
 10    private const string TWO_DECIMALS = "##.00";
 11
 12    private string sceneID;
 13    private string sceneComponents;
 14    private SceneMetricsModel metrics;
 15    private SceneMetricsModel limits;
 16    private IParcelScene activeScene;
 17    private int totalMessagesCurrent;
 18    private int totalMessagesGlobal;
 19
 20
 21    public void SetUpModule(Dictionary<DebugValueEnum, Func<string>> updateValueDictionary)
 22    {
 023        updateValueDictionary.Add(DebugValueEnum.Scene_Name, () => sceneID);
 024        updateValueDictionary.Add(DebugValueEnum.Scene_ProcessedMessages, () =>  $"{((float)totalMessagesCurrent / total
 025        updateValueDictionary.Add(DebugValueEnum.Scene_PendingOnQueue, () =>  $"{totalMessagesGlobal - totalMessagesCurr
 026        updateValueDictionary.Add(DebugValueEnum.Scene_Poly, () => GetSceneMetric(metrics.triangles, limits.triangles));
 027        updateValueDictionary.Add(DebugValueEnum.Scene_Textures, () => GetSceneMetric(metrics.textures,limits.textures))
 028        updateValueDictionary.Add(DebugValueEnum.Scene_Materials, () => GetSceneMetric(metrics.materials,limits.material
 029        updateValueDictionary.Add(DebugValueEnum.Scene_Entities, () =>GetSceneMetric(metrics.entities,limits.entities));
 030        updateValueDictionary.Add(DebugValueEnum.Scene_Meshes, () => GetSceneMetric(metrics.meshes, limits.meshes));
 031        updateValueDictionary.Add(DebugValueEnum.Scene_Bodies, () => GetSceneMetric(metrics.bodies,limits.bodies));
 032        updateValueDictionary.Add(DebugValueEnum.Scene_Components, () => sceneComponents);
 033    }
 34
 35
 36    public void UpdateModule()
 37    {
 038        activeScene = GetActiveScene();
 039        if (activeScene != null && activeScene.metricsCounter != null)
 40        {
 041            metrics = activeScene.metricsCounter.currentCount;
 042            limits = activeScene.metricsCounter.maxCount;
 043            SetSceneData();
 44        }
 045    }
 46    public void EnableModule()
 47    {
 048        ProfilingEvents.OnMessageWillQueue += OnMessageWillQueue;
 049        ProfilingEvents.OnMessageWillDequeue += OnMessageWillDequeue;
 050    }
 51    public void DisableModule()
 52    {
 053        ProfilingEvents.OnMessageWillQueue -= OnMessageWillQueue;
 054        ProfilingEvents.OnMessageWillDequeue -= OnMessageWillDequeue;
 055    }
 56
 57    private void SetSceneData()
 58    {
 059        sceneID = activeScene.sceneData.id;
 060        if (sceneID.Length >= 11)
 61        {
 062            sceneID = $"{sceneID.Substring(0, 5)}...{sceneID.Substring(sceneID.Length - 5, 5)}";
 63        }
 064        sceneComponents = (activeScene.componentsManagerLegacy.GetSceneSharedComponentsDictionary().Count + activeScene.
 065    }
 66
 67    private string GetSceneMetric(int value, int limit)
 68    {
 069        return $"{FPSColoring.GetPercentageColoringString(value, limit)}current: {value} max: {limit}</color>";
 70    }
 71
 72    private void OnMessageWillDequeue(string obj)
 73    {
 074        totalMessagesCurrent = Math.Min(totalMessagesCurrent + 1, totalMessagesGlobal);
 075    }
 76
 77    private void OnMessageWillQueue(string obj)
 78    {
 079        totalMessagesGlobal++;
 080    }
 81
 82    private IParcelScene GetActiveScene()
 83    {
 084        IWorldState worldState = DCL.Environment.i.world.state;
 085        int debugSceneNumber = KernelConfig.i.Get().debugConfig.sceneDebugPanelTargetSceneNumber;
 86
 087        if (debugSceneNumber > 0)
 88        {
 089            if (worldState.TryGetScene(debugSceneNumber, out IParcelScene scene))
 090                return scene;
 91        }
 92
 093        var currentPos = DataStore.i.player.playerGridPosition.Get();
 094        worldState.TryGetScene(worldState.GetSceneNumberByCoords(currentPos), out IParcelScene resultScene);
 95
 096        return resultScene;
 97    }
 98
 99    public string GetSceneID()
 100    {
 0101        return activeScene.sceneData.id;
 102    }
 103
 104    public void Dispose()
 105    {
 0106        ProfilingEvents.OnMessageWillQueue -= OnMessageWillQueue;
 0107        ProfilingEvents.OnMessageWillDequeue -= OnMessageWillDequeue;
 0108    }
 109
 110}