| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using System.Linq; |
| | 5 | | using DCL.Configuration; |
| | 6 | | using DCL.Controllers; |
| | 7 | | using DCL.Helpers; |
| | 8 | | using UnityEngine; |
| | 9 | |
|
| | 10 | | namespace DCL |
| | 11 | | { |
| | 12 | | [RequireComponent(typeof(StatsPanel))] |
| | 13 | | public class UserBenchmarkController : MonoBehaviour, IBenchmarkController |
| | 14 | | { |
| | 15 | | public enum Columns |
| | 16 | | { |
| | 17 | | LABEL, |
| | 18 | | VALUE, |
| | 19 | | } |
| | 20 | |
|
| | 21 | | public enum Rows |
| | 22 | | { |
| | 23 | | NONE, |
| | 24 | | PROCESSED_MESSAGES, |
| | 25 | | PENDING_MESSAGES, |
| | 26 | | BREAK_0, |
| | 27 | | CURRENT_SCENE, |
| | 28 | | POLYGONS_VS_LIMIT, |
| | 29 | | TEXTURES_VS_LIMIT, |
| | 30 | | MATERIALS_VS_LIMIT, |
| | 31 | | ENTITIES_VS_LIMIT, |
| | 32 | | MESHES_VS_LIMIT, |
| | 33 | | BODIES_VS_LIMIT, |
| | 34 | | COMPONENT_OBJECTS_COUNT |
| | 35 | | } |
| | 36 | |
|
| | 37 | | const string BREAK_0_TEXT = ""; |
| | 38 | |
|
| | 39 | | const string PROCESSED_MESSAGES_TEXT = "Processed Messages"; |
| | 40 | | const string PENDING_MESSAGES_TEXT = "Pending on Queue"; |
| | 41 | |
|
| | 42 | | const string CURRENT_SCENE_TEST = "Scene Location:"; |
| | 43 | | const string POLYGON_VS_LIMIT_TEXT = "Poly Count"; |
| | 44 | | const string TEXTURES_VS_LIMIT_TEXT = "Textures Count"; |
| | 45 | | const string MATERIALS_VS_LIMIT_TEXT = "Materials Count"; |
| | 46 | | const string ENTITIES_VS_LIMIT_TEXT = "Entities Count"; |
| | 47 | | const string MESHES_VS_LIMIT_TEXT = "Meshes Count"; |
| | 48 | | const string BODIES_VS_LIMIT_TEXT = "Bodies Count"; |
| | 49 | | const string COMPONENT_OBJECTS_COUNT_TEXT = "Components Count"; |
| | 50 | |
|
| | 51 | | int totalMessagesCurrent; |
| | 52 | | int totalMessagesGlobal; |
| | 53 | |
|
| | 54 | | StatsPanel statsPanel; |
| | 55 | | List<Columns> columnsList; |
| | 56 | | List<Rows> rowsList; |
| | 57 | |
|
| 0 | 58 | | private void Awake() { StartProfiling(); } |
| | 59 | |
|
| 0 | 60 | | private void OnDestroy() { StopProfiling(); } |
| | 61 | |
|
| | 62 | | public void Init() |
| | 63 | | { |
| 0 | 64 | | this.statsPanel = GetComponent<StatsPanel>(); |
| | 65 | |
|
| 0 | 66 | | columnsList = Enum.GetValues(typeof(Columns)).Cast<Columns>().ToList(); |
| 0 | 67 | | rowsList = Enum.GetValues(typeof(Rows)).Cast<Rows>().ToList(); |
| | 68 | |
|
| 0 | 69 | | statsPanel.PopulateTable(columnsList.Count, rowsList.Count, 240, 240); |
| | 70 | |
|
| 0 | 71 | | statsPanel.SetCellText((int) Columns.LABEL, (int) Columns.LABEL, ""); |
| | 72 | |
|
| | 73 | | //Init Labels |
| 0 | 74 | | statsPanel.SetCellText((int) Columns.LABEL, (int) Rows.PROCESSED_MESSAGES, PROCESSED_MESSAGES_TEXT); |
| 0 | 75 | | statsPanel.SetCellText((int) Columns.LABEL, (int) Rows.PENDING_MESSAGES, PENDING_MESSAGES_TEXT); |
| | 76 | |
|
| 0 | 77 | | statsPanel.SetCellText((int) Columns.LABEL, (int) Rows.BREAK_0, BREAK_0_TEXT); |
| | 78 | |
|
| 0 | 79 | | statsPanel.SetCellText((int) Columns.LABEL, (int) Rows.CURRENT_SCENE, CURRENT_SCENE_TEST); |
| 0 | 80 | | statsPanel.SetCellText((int) Columns.LABEL, (int) Rows.POLYGONS_VS_LIMIT, POLYGON_VS_LIMIT_TEXT); |
| 0 | 81 | | statsPanel.SetCellText((int) Columns.LABEL, (int) Rows.TEXTURES_VS_LIMIT, TEXTURES_VS_LIMIT_TEXT); |
| 0 | 82 | | statsPanel.SetCellText((int) Columns.LABEL, (int) Rows.MATERIALS_VS_LIMIT, MATERIALS_VS_LIMIT_TEXT); |
| 0 | 83 | | statsPanel.SetCellText((int) Columns.LABEL, (int) Rows.ENTITIES_VS_LIMIT, ENTITIES_VS_LIMIT_TEXT); |
| 0 | 84 | | statsPanel.SetCellText((int) Columns.LABEL, (int) Rows.MESHES_VS_LIMIT, MESHES_VS_LIMIT_TEXT); |
| 0 | 85 | | statsPanel.SetCellText((int) Columns.LABEL, (int) Rows.BODIES_VS_LIMIT, BODIES_VS_LIMIT_TEXT); |
| 0 | 86 | | statsPanel.SetCellText((int) Columns.LABEL, (int) Rows.COMPONENT_OBJECTS_COUNT, COMPONENT_OBJECTS_COUNT_TEXT |
| | 87 | |
|
| | 88 | | //Init Values |
| | 89 | |
|
| 0 | 90 | | statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.PROCESSED_MESSAGES, "=/="); |
| 0 | 91 | | statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.PENDING_MESSAGES, "=/="); |
| | 92 | |
|
| 0 | 93 | | statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.CURRENT_SCENE, "=/="); |
| 0 | 94 | | statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.POLYGONS_VS_LIMIT, "=/="); |
| 0 | 95 | | statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.TEXTURES_VS_LIMIT, "=/="); |
| 0 | 96 | | statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.MATERIALS_VS_LIMIT, "=/="); |
| 0 | 97 | | statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.ENTITIES_VS_LIMIT, "=/="); |
| 0 | 98 | | statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.MESHES_VS_LIMIT, "=/="); |
| 0 | 99 | | statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.BODIES_VS_LIMIT, "=/="); |
| 0 | 100 | | statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.COMPONENT_OBJECTS_COUNT, "=/="); |
| | 101 | |
|
| 0 | 102 | | Canvas.ForceUpdateCanvases(); |
| 0 | 103 | | } |
| | 104 | |
|
| | 105 | | public void StartProfiling() |
| | 106 | | { |
| 0 | 107 | | if (statsPanel == null) |
| | 108 | | { |
| 0 | 109 | | Init(); |
| | 110 | | } |
| | 111 | |
|
| 0 | 112 | | profilingCoroutine = CoroutineStarter.Start(RefreshProfilingData()); |
| 0 | 113 | | ProfilingEvents.OnMessageWillQueue += OnMessageWillQueue; |
| 0 | 114 | | ProfilingEvents.OnMessageWillDequeue += OnMessageWillDequeue; |
| 0 | 115 | | } |
| | 116 | |
|
| | 117 | | private void OnMessageWillDequeue(string obj) |
| | 118 | | { |
| 0 | 119 | | totalMessagesCurrent = Math.Min(totalMessagesCurrent + 1, totalMessagesGlobal); |
| 0 | 120 | | statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.PROCESSED_MESSAGES, $"{totalMessagesCurrent} of {tota |
| 0 | 121 | | statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.PENDING_MESSAGES, $"{totalMessagesGlobal - totalMessa |
| 0 | 122 | | } |
| | 123 | |
|
| | 124 | | private void OnMessageWillQueue(string obj) |
| | 125 | | { |
| 0 | 126 | | totalMessagesGlobal++; |
| 0 | 127 | | statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.PROCESSED_MESSAGES, $"{totalMessagesCurrent}:{totalMe |
| 0 | 128 | | statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.PENDING_MESSAGES, $"{totalMessagesGlobal - totalMessa |
| 0 | 129 | | } |
| | 130 | |
|
| | 131 | | private Coroutine profilingCoroutine; |
| | 132 | |
|
| | 133 | | public void StopProfiling() |
| | 134 | | { |
| 0 | 135 | | if (profilingCoroutine != null) |
| 0 | 136 | | CoroutineStarter.Stop(profilingCoroutine); |
| | 137 | |
|
| 0 | 138 | | ProfilingEvents.OnMessageWillQueue -= OnMessageWillQueue; |
| 0 | 139 | | ProfilingEvents.OnMessageWillDequeue -= OnMessageWillDequeue; |
| 0 | 140 | | } |
| | 141 | |
|
| | 142 | | private IEnumerator RefreshProfilingData() |
| | 143 | | { |
| 0 | 144 | | while (true) |
| | 145 | | { |
| 0 | 146 | | var currentPos = Utils.WorldToGridPosition(DCLCharacterController.i.characterPosition.worldPosition); |
| | 147 | |
|
| 0 | 148 | | IWorldState worldState = Environment.i.world.state; |
| | 149 | |
|
| 0 | 150 | | ParcelScene activeScene = worldState.loadedScenes.Values.FirstOrDefault( |
| 0 | 151 | | x => x.sceneData.parcels != null |
| 0 | 152 | | && x.sceneData.parcels.Any(y => y == currentPos)) as ParcelScene; |
| | 153 | |
|
| 0 | 154 | | if (activeScene != null && activeScene.metricsController != null) |
| | 155 | | { |
| 0 | 156 | | var metrics = activeScene.metricsController.GetModel(); |
| 0 | 157 | | var limits = activeScene.metricsController.GetLimits(); |
| 0 | 158 | | statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.CURRENT_SCENE, $"{activeScene.sceneData.id}") |
| 0 | 159 | | statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.POLYGONS_VS_LIMIT, $"{metrics.triangles} of { |
| 0 | 160 | | statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.TEXTURES_VS_LIMIT, $"{metrics.textures} of {l |
| 0 | 161 | | statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.MATERIALS_VS_LIMIT, $"{metrics.materials} of |
| 0 | 162 | | statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.ENTITIES_VS_LIMIT, $"{metrics.entities} of {l |
| 0 | 163 | | statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.MESHES_VS_LIMIT, $"{metrics.meshes} of {limit |
| 0 | 164 | | statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.BODIES_VS_LIMIT, $"{metrics.bodies} of {limit |
| 0 | 165 | | statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.COMPONENT_OBJECTS_COUNT, activeScene.disposab |
| | 166 | | } |
| | 167 | |
|
| 0 | 168 | | yield return WaitForSecondsCache.Get(0.2f); |
| | 169 | | } |
| | 170 | | } |
| | 171 | | } |
| | 172 | | } |