blob: 7d2f4f8ed6f9b52b25efc011a5ed8c8296fc402d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
|
/* ---------------------------------------
* Author: Martin Pane (martintayx@gmail.com) (@tayx94)
* Collaborators: Lars Aalbertsen (@Rockylars)
* Project: Graphy - Ultimate Stats Monitor
* Date: 15-Dec-17
* Studio: Tayx
*
* This project is released under the MIT license.
* Attribution is not required, but it is always welcomed!
* -------------------------------------*/
using Tayx.Graphy.Graph;
using UnityEngine;
using UnityEngine.UI;
#if UNITY_5_5_OR_NEWER
using UnityEngine.Profiling;
#endif
namespace Tayx.Graphy.Ram
{
public class G_RamGraph : G_Graph
{
/* ----- TODO: ----------------------------
* Add summaries to the variables.
* Add summaries to the functions.
* Check if we should add a "RequireComponent" for "RamMonitor".
* --------------------------------------*/
#region Variables -> Serialized Private
[SerializeField] private Image m_imageAllocated = null;
[SerializeField] private Image m_imageReserved = null;
[SerializeField] private Image m_imageMono = null;
[SerializeField] private Shader ShaderFull = null;
[SerializeField] private Shader ShaderLight = null;
#endregion
#region Variables -> Private
private GraphyManager m_graphyManager = null;
private G_RamMonitor m_ramMonitor = null;
private int m_resolution = 150;
private G_GraphShader m_shaderGraphAllocated = null;
private G_GraphShader m_shaderGraphReserved = null;
private G_GraphShader m_shaderGraphMono = null;
private float[] m_allocatedArray;
private float[] m_reservedArray;
private float[] m_monoArray;
private float m_highestMemory = 0;
#endregion
#region Methods -> Unity Callbacks
private void OnEnable()
{
Init();
}
private void Update()
{
UpdateGraph();
}
#endregion
#region Methods -> Public
public void UpdateParameters()
{
if ( m_shaderGraphAllocated == null
|| m_shaderGraphReserved == null
|| m_shaderGraphMono == null)
{
Init();
}
switch (m_graphyManager.GraphyMode)
{
case GraphyManager.Mode.FULL:
m_shaderGraphAllocated .ArrayMaxSize = G_GraphShader.ArrayMaxSizeFull;
m_shaderGraphReserved .ArrayMaxSize = G_GraphShader.ArrayMaxSizeFull;
m_shaderGraphMono .ArrayMaxSize = G_GraphShader.ArrayMaxSizeFull;
m_shaderGraphAllocated .Image.material = new Material(ShaderFull);
m_shaderGraphReserved .Image.material = new Material(ShaderFull);
m_shaderGraphMono .Image.material = new Material(ShaderFull);
break;
case GraphyManager.Mode.LIGHT:
m_shaderGraphAllocated .ArrayMaxSize = G_GraphShader.ArrayMaxSizeLight;
m_shaderGraphReserved .ArrayMaxSize = G_GraphShader.ArrayMaxSizeLight;
m_shaderGraphMono .ArrayMaxSize = G_GraphShader.ArrayMaxSizeLight;
m_shaderGraphAllocated .Image.material = new Material(ShaderLight);
m_shaderGraphReserved .Image.material = new Material(ShaderLight);
m_shaderGraphMono .Image.material = new Material(ShaderLight);
break;
}
m_shaderGraphAllocated.InitializeShader();
m_shaderGraphReserved.InitializeShader();
m_shaderGraphMono.InitializeShader();
m_resolution = m_graphyManager.RamGraphResolution;
CreatePoints();
}
#endregion
#region Methods -> Protected Override
protected override void UpdateGraph()
{
float allocatedMemory = m_ramMonitor.AllocatedRam;
float reservedMemory = m_ramMonitor.ReservedRam;
float monoMemory = m_ramMonitor.MonoRam;
m_highestMemory = 0;
for (int i = 0; i <= m_resolution - 1; i++)
{
if (i >= m_resolution - 1)
{
m_allocatedArray[i] = allocatedMemory;
m_reservedArray[i] = reservedMemory;
m_monoArray[i] = monoMemory;
}
else
{
m_allocatedArray[i] = m_allocatedArray[i + 1];
m_reservedArray[i] = m_reservedArray[i + 1];
m_monoArray[i] = m_monoArray[i + 1];
}
if (m_highestMemory < m_reservedArray[i])
{
m_highestMemory = m_reservedArray[i];
}
}
for (int i = 0; i <= m_resolution - 1; i++)
{
m_shaderGraphAllocated.Array[i] = m_allocatedArray[i] / m_highestMemory;
m_shaderGraphReserved.Array[i] = m_reservedArray[i] / m_highestMemory;
m_shaderGraphMono.Array[i] = m_monoArray[i] / m_highestMemory;
}
m_shaderGraphAllocated.UpdatePoints();
m_shaderGraphReserved.UpdatePoints();
m_shaderGraphMono.UpdatePoints();
}
protected override void CreatePoints()
{
m_shaderGraphAllocated.Array = new float[m_resolution];
m_shaderGraphReserved.Array = new float[m_resolution];
m_shaderGraphMono.Array = new float[m_resolution];
m_allocatedArray = new float[m_resolution];
m_reservedArray = new float[m_resolution];
m_monoArray = new float[m_resolution];
for (int i = 0; i < m_resolution; i++)
{
m_shaderGraphAllocated.Array[i] = 0;
m_shaderGraphReserved.Array[i] = 0;
m_shaderGraphMono.Array[i] = 0;
}
// Initialize the material values
// Colors
m_shaderGraphAllocated.GoodColor = m_graphyManager.AllocatedRamColor;
m_shaderGraphAllocated.CautionColor = m_graphyManager.AllocatedRamColor;
m_shaderGraphAllocated.CriticalColor = m_graphyManager.AllocatedRamColor;
m_shaderGraphAllocated.UpdateColors();
m_shaderGraphReserved.GoodColor = m_graphyManager.ReservedRamColor;
m_shaderGraphReserved.CautionColor = m_graphyManager.ReservedRamColor;
m_shaderGraphReserved.CriticalColor = m_graphyManager.ReservedRamColor;
m_shaderGraphReserved.UpdateColors();
m_shaderGraphMono.GoodColor = m_graphyManager.MonoRamColor;
m_shaderGraphMono.CautionColor = m_graphyManager.MonoRamColor;
m_shaderGraphMono.CriticalColor = m_graphyManager.MonoRamColor;
m_shaderGraphMono.UpdateColors();
// Thresholds
m_shaderGraphAllocated.GoodThreshold = 0;
m_shaderGraphAllocated.CautionThreshold = 0;
m_shaderGraphAllocated.UpdateThresholds();
m_shaderGraphReserved.GoodThreshold = 0;
m_shaderGraphReserved.CautionThreshold = 0;
m_shaderGraphReserved.UpdateThresholds();
m_shaderGraphMono.GoodThreshold = 0;
m_shaderGraphMono.CautionThreshold = 0;
m_shaderGraphMono.UpdateThresholds();
m_shaderGraphAllocated.UpdateArray();
m_shaderGraphReserved.UpdateArray();
m_shaderGraphMono.UpdateArray();
// Average
m_shaderGraphAllocated.Average = 0;
m_shaderGraphReserved.Average = 0;
m_shaderGraphMono.Average = 0;
m_shaderGraphAllocated.UpdateAverage();
m_shaderGraphReserved.UpdateAverage();
m_shaderGraphMono.UpdateAverage();
}
#endregion
#region Methods -> Private
private void Init()
{
m_graphyManager = transform.root.GetComponentInChildren<GraphyManager>();
m_ramMonitor = GetComponent<G_RamMonitor>();
m_shaderGraphAllocated = new G_GraphShader();
m_shaderGraphReserved = new G_GraphShader();
m_shaderGraphMono = new G_GraphShader();
m_shaderGraphAllocated .Image = m_imageAllocated;
m_shaderGraphReserved .Image = m_imageReserved;
m_shaderGraphMono .Image = m_imageMono;
UpdateParameters();
}
#endregion
}
}
|