| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using DCL; |
| | 4 | | using DCL.Controllers; |
| | 5 | | using DCL.FPSDisplay; |
| | 6 | |
|
| | 7 | | public 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 | | { |
| 0 | 23 | | updateValueDictionary.Add(DebugValueEnum.Scene_Name, () => sceneID); |
| 0 | 24 | | updateValueDictionary.Add(DebugValueEnum.Scene_ProcessedMessages, () => $"{((float)totalMessagesCurrent / total |
| 0 | 25 | | updateValueDictionary.Add(DebugValueEnum.Scene_PendingOnQueue, () => $"{totalMessagesGlobal - totalMessagesCurr |
| 0 | 26 | | updateValueDictionary.Add(DebugValueEnum.Scene_Poly, () => GetSceneMetric(metrics.triangles, limits.triangles)); |
| 0 | 27 | | updateValueDictionary.Add(DebugValueEnum.Scene_Textures, () => GetSceneMetric(metrics.textures,limits.textures)) |
| 0 | 28 | | updateValueDictionary.Add(DebugValueEnum.Scene_Materials, () => GetSceneMetric(metrics.materials,limits.material |
| 0 | 29 | | updateValueDictionary.Add(DebugValueEnum.Scene_Entities, () =>GetSceneMetric(metrics.entities,limits.entities)); |
| 0 | 30 | | updateValueDictionary.Add(DebugValueEnum.Scene_Meshes, () => GetSceneMetric(metrics.meshes, limits.meshes)); |
| 0 | 31 | | updateValueDictionary.Add(DebugValueEnum.Scene_Bodies, () => GetSceneMetric(metrics.bodies,limits.bodies)); |
| 0 | 32 | | updateValueDictionary.Add(DebugValueEnum.Scene_Components, () => sceneComponents); |
| 0 | 33 | | } |
| | 34 | |
|
| | 35 | |
|
| | 36 | | public void UpdateModule() |
| | 37 | | { |
| 0 | 38 | | activeScene = GetActiveScene(); |
| 0 | 39 | | if (activeScene != null && activeScene.metricsCounter != null) |
| | 40 | | { |
| 0 | 41 | | metrics = activeScene.metricsCounter.currentCount; |
| 0 | 42 | | limits = activeScene.metricsCounter.maxCount; |
| 0 | 43 | | SetSceneData(); |
| | 44 | | } |
| 0 | 45 | | } |
| | 46 | | public void EnableModule() |
| | 47 | | { |
| 0 | 48 | | ProfilingEvents.OnMessageWillQueue += OnMessageWillQueue; |
| 0 | 49 | | ProfilingEvents.OnMessageWillDequeue += OnMessageWillDequeue; |
| 0 | 50 | | } |
| | 51 | | public void DisableModule() |
| | 52 | | { |
| 0 | 53 | | ProfilingEvents.OnMessageWillQueue -= OnMessageWillQueue; |
| 0 | 54 | | ProfilingEvents.OnMessageWillDequeue -= OnMessageWillDequeue; |
| 0 | 55 | | } |
| | 56 | |
|
| | 57 | | private void SetSceneData() |
| | 58 | | { |
| 0 | 59 | | sceneID = activeScene.sceneData.id; |
| 0 | 60 | | if (sceneID.Length >= 11) |
| | 61 | | { |
| 0 | 62 | | sceneID = $"{sceneID.Substring(0, 5)}...{sceneID.Substring(sceneID.Length - 5, 5)}"; |
| | 63 | | } |
| 0 | 64 | | sceneComponents = (activeScene.componentsManagerLegacy.GetSceneSharedComponentsDictionary().Count + activeScene. |
| 0 | 65 | | } |
| | 66 | |
|
| | 67 | | private string GetSceneMetric(int value, int limit) |
| | 68 | | { |
| 0 | 69 | | return $"{FPSColoring.GetPercentageColoringString(value, limit)}current: {value} max: {limit}</color>"; |
| | 70 | | } |
| | 71 | |
|
| | 72 | | private void OnMessageWillDequeue(string obj) |
| | 73 | | { |
| 0 | 74 | | totalMessagesCurrent = Math.Min(totalMessagesCurrent + 1, totalMessagesGlobal); |
| 0 | 75 | | } |
| | 76 | |
|
| | 77 | | private void OnMessageWillQueue(string obj) |
| | 78 | | { |
| 0 | 79 | | totalMessagesGlobal++; |
| 0 | 80 | | } |
| | 81 | |
|
| | 82 | | private IParcelScene GetActiveScene() |
| | 83 | | { |
| 0 | 84 | | IWorldState worldState = DCL.Environment.i.world.state; |
| 0 | 85 | | string debugSceneId = KernelConfig.i.Get().debugConfig.sceneDebugPanelTargetSceneId; |
| | 86 | |
|
| 0 | 87 | | if (!string.IsNullOrEmpty(debugSceneId)) |
| | 88 | | { |
| 0 | 89 | | if (worldState.TryGetScene(debugSceneId, out IParcelScene scene)) |
| 0 | 90 | | return scene; |
| | 91 | | } |
| | 92 | |
|
| 0 | 93 | | var currentPos = DataStore.i.player.playerGridPosition.Get(); |
| 0 | 94 | | worldState.TryGetScene(worldState.GetSceneIdByCoords(currentPos), out IParcelScene resultScene); |
| | 95 | |
|
| 0 | 96 | | return resultScene; |
| | 97 | | } |
| | 98 | |
|
| | 99 | | public string GetSceneID() |
| | 100 | | { |
| 0 | 101 | | return activeScene.sceneData.id; |
| | 102 | | } |
| | 103 | |
|
| | 104 | | public void Dispose() |
| | 105 | | { |
| 0 | 106 | | ProfilingEvents.OnMessageWillQueue -= OnMessageWillQueue; |
| 0 | 107 | | ProfilingEvents.OnMessageWillDequeue -= OnMessageWillDequeue; |
| 0 | 108 | | } |
| | 109 | |
|
| | 110 | | } |