1 using Microsoft.Xna.Framework;
2 using Microsoft.Xna.Framework.Graphics;
3 using System.Collections.Generic;
17 private readonly
Graph[] graphs;
19 private readonly
float[] totalValue;
20 private readonly
float[] lastValue;
22 const float UpdateInterval = 0.1f;
27 graphs =
new Graph[3];
29 totalValue =
new float[3];
30 lastValue =
new float[3];
31 for (
int i = 0; i < 3; i++ )
33 graphs[i] =
new Graph();
39 float valueChange = value - lastValue[(int)statType];
40 totalValue[(int)statType] += valueChange;
41 lastValue[(int)statType] = value;
46 updateTimer -= deltaTime;
48 if (updateTimer > 0.0f)
return;
50 for (
int i = 0; i < 3; i++)
52 graphs[i].Update(totalValue[i] / UpdateInterval);
56 updateTimer = UpdateInterval;
59 public void Draw(SpriteBatch spriteBatch, Rectangle rect)
61 GUI.DrawRectangle(spriteBatch, rect, Color.Black * 0.4f,
true);
63 graphs[(int)
NetStatType.ReceivedBytes].Draw(spriteBatch, rect, color: Color.Cyan);
64 graphs[(int)
NetStatType.SentBytes].Draw(spriteBatch, rect,
null, color: GUIStyle.Orange);
65 if (graphs[(
int)
NetStatType.ResentMessages].Average() > 0)
67 graphs[(int)
NetStatType.ResentMessages].Draw(spriteBatch, rect, color: GUIStyle.Red);
68 GUIStyle.SmallFont.DrawString(spriteBatch,
"Peak resent: " + graphs[(
int)
NetStatType.ResentMessages].LargestValue() +
" messages/s",
69 new Vector2(rect.Right + 10, rect.Y + 50), GUIStyle.Red);
72 GUIStyle.SmallFont.DrawString(spriteBatch,
73 "Peak received: " + MathUtils.GetBytesReadable((
int)graphs[(
int)
NetStatType.ReceivedBytes].LargestValue()) +
"/s " +
74 "Avg received: " + MathUtils.GetBytesReadable((
int)graphs[(
int)
NetStatType.ReceivedBytes].Average()) +
"/s",
75 new Vector2(rect.Right + 10, rect.Y + 10), Color.Cyan);
77 GUIStyle.SmallFont.DrawString(spriteBatch,
"Peak sent: " + MathUtils.GetBytesReadable((
int)graphs[(
int)
NetStatType.SentBytes].LargestValue()) +
"/s " +
78 "Avg sent: " + MathUtils.GetBytesReadable((
int)graphs[(
int)
NetStatType.SentBytes].Average()) +
"/s",
79 new Vector2(rect.Right + 10, rect.Y + 30), GUIStyle.Orange);
void AddValue(NetStatType statType, float value)
void Update(float deltaTime)
void Draw(SpriteBatch spriteBatch, Rectangle rect)