Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
NetDiagnosticsUI.cs
Go to the documentation of this file.
6using Terraria.ID;
7
8namespace Terraria.UI;
9
11{
12 private struct CounterForMessage
13 {
14 public int timesReceived;
15
16 public int timesSent;
17
18 public int bytesReceived;
19
20 public int bytesSent;
21
23
24 public void Reset()
25 {
26 timesReceived = 0;
27 timesSent = 0;
28 bytesReceived = 0;
29 bytesSent = 0;
30 }
31
32 public void CountReadMessage(int messageLength)
33 {
35 bytesReceived += messageLength;
36 }
37
38 public void CountSentMessage(int messageLength)
39 {
40 timesSent++;
41 bytesSent += messageLength;
42 }
43 }
44
45 private CounterForMessage[] _counterByMessageId = new CounterForMessage[MessageID.Count + 1];
46
48
49 private int _highestFoundReadBytes = 1;
50
51 private int _highestFoundReadCount = 1;
52
53 public void Reset()
54 {
55 for (int i = 0; i < _counterByMessageId.Length; i++)
56 {
58 }
62 }
63
64 public void CountReadMessage(int messageId, int messageLength)
65 {
67 }
68
69 public void CountSentMessage(int messageId, int messageLength)
70 {
72 }
73
74 public void CountReadModuleMessage(int moduleMessageId, int messageLength)
75 {
77 value.CountReadMessage(messageLength);
79 }
80
81 public void CountSentModuleMessage(int moduleMessageId, int messageLength)
82 {
84 value.CountSentMessage(messageLength);
86 }
87
88 public void Draw(SpriteBatch spriteBatch)
89 {
90 int num = _counterByMessageId.Length + _counterByModuleId.Count;
91 for (int i = 0; i <= num / 51; i++)
92 {
93 Utils.DrawInvBG(spriteBatch, 190 + 400 * i, 110, 390, 683);
94 }
95 Vector2 position = default(Vector2);
96 for (int j = 0; j < _counterByMessageId.Length; j++)
97 {
98 int num2 = j / 51;
99 int num3 = j - num2 * 51;
100 position.X = 200 + num2 * 400;
101 position.Y = 120 + num3 * 13;
102 DrawCounter(spriteBatch, ref _counterByMessageId[j], j.ToString(), position);
103 }
104 int num4 = _counterByMessageId.Length + 1;
106 {
107 int num5 = num4 / 51;
108 int num6 = num4 - num5 * 51;
109 position.X = 200 + num5 * 400;
110 position.Y = 120 + num6 * 13;
111 CounterForMessage counter = item.Value;
112 DrawCounter(spriteBatch, ref counter, ".." + item.Key, position);
113 num4++;
114 }
115 }
116
117 private void DrawCounter(SpriteBatch spriteBatch, ref CounterForMessage counter, string title, Vector2 position)
118 {
119 if (!counter.exemptFromBadScoreTest)
120 {
121 if (_highestFoundReadCount < counter.timesReceived)
122 {
123 _highestFoundReadCount = counter.timesReceived;
124 }
125 if (_highestFoundReadBytes < counter.bytesReceived)
126 {
127 _highestFoundReadBytes = counter.bytesReceived;
128 }
129 }
130 Vector2 pos = position;
131 string text = title + ": ";
132 float num = Utils.Remap(counter.bytesReceived, 0f, _highestFoundReadBytes, 0f, 1f);
133 Color color = Main.hslToRgb(0.3f * (1f - num), 1f, 0.5f);
134 if (counter.exemptFromBadScoreTest)
135 {
136 color = Color.White;
137 }
138 string text2 = "";
139 text2 = text;
140 DrawText(spriteBatch, text2, pos, color);
141 pos.X += 30f;
142 text2 = "rx:" + $"{counter.timesReceived}";
143 DrawText(spriteBatch, text2, pos, color);
144 pos.X += 70f;
145 text2 = $"{counter.bytesReceived}";
146 DrawText(spriteBatch, text2, pos, color);
147 pos.X += 70f;
148 text2 = text;
149 DrawText(spriteBatch, text2, pos, color);
150 pos.X += 30f;
151 text2 = "tx:" + $"{counter.timesSent}";
152 DrawText(spriteBatch, text2, pos, color);
153 pos.X += 70f;
154 text2 = $"{counter.bytesSent}";
155 DrawText(spriteBatch, text2, pos, color);
156 }
157
158 private void DrawText(SpriteBatch spriteBatch, string text, Vector2 pos, Color color)
159 {
160 DynamicSpriteFontExtensionMethods.DrawString(spriteBatch, FontAssets.MouseText.Value, text, pos, color, 0f, Vector2.Zero, 0.7f, SpriteEffects.None, 0f);
161 }
162}
static void DrawString(this SpriteBatch spriteBatch, DynamicSpriteFont spriteFont, string text, Vector2 position, Color color)
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
static Asset< DynamicSpriteFont > MouseText
Definition FontAssets.cs:10
static Microsoft.Xna.Framework.Color hslToRgb(Vector3 hslVector)
Definition Main.cs:44913
Dictionary< int, CounterForMessage > _counterByModuleId
void CountReadMessage(int messageId, int messageLength)
void DrawCounter(SpriteBatch spriteBatch, ref CounterForMessage counter, string title, Vector2 position)
void CountSentMessage(int messageId, int messageLength)
void CountSentModuleMessage(int moduleMessageId, int messageLength)
void Draw(SpriteBatch spriteBatch)
void CountReadModuleMessage(int moduleMessageId, int messageLength)
void DrawText(SpriteBatch spriteBatch, string text, Vector2 pos, Color color)
CounterForMessage[] _counterByMessageId
static float Remap(float fromValue, float fromMin, float fromMax, float toMin, float toMax, bool clamped=true)
Definition Utils.cs:233
static void DrawInvBG(SpriteBatch sb, Rectangle R, Color c=default(Color))
Definition Utils.cs:1921