Fix mistake with negative ping, rename FPSScreen to more accurate StatusScreen

This commit is contained in:
UnknownShadow200 2017-06-25 14:17:03 +10:00
parent 942ecfef6b
commit 757d18c4d8
4 changed files with 30 additions and 30 deletions

View File

@ -9,13 +9,13 @@ using Android.Graphics;
#endif #endif
namespace ClassicalSharp.Gui.Screens { namespace ClassicalSharp.Gui.Screens {
public class FpsScreen : Screen, IGameComponent { public class StatusScreen : Screen, IGameComponent {
Font font; Font font;
StringBuffer text; StringBuffer statusBuffer;
public FpsScreen(Game game) : base(game) { public StatusScreen(Game game) : base(game) {
text = new StringBuffer(128); statusBuffer = new StringBuffer(128);
} }
public void Init(Game game) { } public void Init(Game game) { }
@ -24,14 +24,14 @@ namespace ClassicalSharp.Gui.Screens {
public void OnNewMap(Game game) { } public void OnNewMap(Game game) { }
public void OnNewMapLoaded(Game game) { } public void OnNewMapLoaded(Game game) { }
TextWidget fpsText, hackStates; TextWidget status, hackStates;
TextAtlas posAtlas; TextAtlas posAtlas;
public override void Render(double delta) { public override void Render(double delta) {
UpdateFPS(delta); UpdateStatus(delta);
if (game.HideGui || !game.ShowFPS) return; if (game.HideGui || !game.ShowFPS) return;
gfx.Texturing = true; gfx.Texturing = true;
fpsText.Render(delta); status.Render(delta);
if (!game.ClassicMode && game.Gui.activeScreen == null) { if (!game.ClassicMode && game.Gui.activeScreen == null) {
UpdateHackState(false); UpdateHackState(false);
DrawPosition(); DrawPosition();
@ -43,7 +43,7 @@ namespace ClassicalSharp.Gui.Screens {
double accumulator; double accumulator;
int frames, totalSeconds; int frames, totalSeconds;
void UpdateFPS(double delta) { void UpdateStatus(double delta) {
frames++; frames++;
accumulator += delta; accumulator += delta;
if (accumulator < 1) return; if (accumulator < 1) return;
@ -52,17 +52,16 @@ namespace ClassicalSharp.Gui.Screens {
totalSeconds++; totalSeconds++;
int fps = (int)(frames / accumulator); int fps = (int)(frames / accumulator);
text.Clear() statusBuffer.Clear()
.AppendNum(ref index, fps).Append(ref index, " fps, "); .AppendNum(ref index, fps).Append(ref index, " fps, ");
if (game.ClassicMode) { if (game.ClassicMode) {
text.AppendNum(ref index, game.ChunkUpdates).Append(ref index, " chunk updates"); statusBuffer.AppendNum(ref index, game.ChunkUpdates).Append(ref index, " chunk updates");
} else { } else {
text.AppendNum(ref index, game.ChunkUpdates).Append(ref index, " chunks/s, ") statusBuffer.AppendNum(ref index, game.ChunkUpdates).Append(ref index, " chunks/s, ")
.AppendNum(ref index, game.Vertices).Append(ref index, " vertices"); .AppendNum(ref index, game.Vertices).Append(ref index, " vertices");
} }
string textString = text.ToString(); status.SetText(statusBuffer.ToString());
fpsText.SetText(textString);
accumulator = 0; accumulator = 0;
frames = 0; frames = 0;
game.ChunkUpdates = 0; game.ChunkUpdates = 0;
@ -80,24 +79,24 @@ namespace ClassicalSharp.Gui.Screens {
} }
protected override void ContextLost() { protected override void ContextLost() {
fpsText.Dispose(); status.Dispose();
posAtlas.Dispose(); posAtlas.Dispose();
hackStates.Dispose(); hackStates.Dispose();
} }
protected override void ContextRecreated() { protected override void ContextRecreated() {
fpsText = new TextWidget(game, font) status = new TextWidget(game, font)
.SetLocation(Anchor.LeftOrTop, Anchor.LeftOrTop, 2, 2); .SetLocation(Anchor.LeftOrTop, Anchor.LeftOrTop, 2, 2);
fpsText.ReducePadding = true; status.ReducePadding = true;
fpsText.Init(); status.Init();
string msg = text.Length > 0 ? text.ToString() : "FPS: no data yet"; string msg = statusBuffer.Length > 0 ? statusBuffer.ToString() : "FPS: no data yet";
fpsText.SetText(msg); status.SetText(msg);
posAtlas = new TextAtlas(game, 16); posAtlas = new TextAtlas(game, 16);
posAtlas.Pack("0123456789-, ()", font, "Position: "); posAtlas.Pack("0123456789-, ()", font, "Position: ");
posAtlas.tex.Y = (short)(fpsText.Height + 2); posAtlas.tex.Y = (short)(status.Height + 2);
int yOffset = fpsText.Height + posAtlas.tex.Height + 2; int yOffset = status.Height + posAtlas.tex.Height + 2;
hackStates = new TextWidget(game, font) hackStates = new TextWidget(game, font)
.SetLocation(Anchor.LeftOrTop, Anchor.LeftOrTop, 2, yOffset); .SetLocation(Anchor.LeftOrTop, Anchor.LeftOrTop, 2, yOffset);
hackStates.ReducePadding = true; hackStates.ReducePadding = true;
@ -151,17 +150,17 @@ namespace ClassicalSharp.Gui.Screens {
speeding = hacks.Speeding; halfSpeeding = hacks.HalfSpeeding; noclip = hacks.Noclip; fly = hacks.Flying; speeding = hacks.Speeding; halfSpeeding = hacks.HalfSpeeding; noclip = hacks.Noclip; fly = hacks.Flying;
lastFov = game.Fov; lastFov = game.Fov;
int index = 0; int index = 0;
text.Clear(); statusBuffer.Clear();
if (game.Fov != game.DefaultFov) text.Append(ref index, "Zoom fov ") if (game.Fov != game.DefaultFov) statusBuffer.Append(ref index, "Zoom fov ")
.AppendNum(ref index, lastFov).Append(ref index, " "); .AppendNum(ref index, lastFov).Append(ref index, " ");
if (fly) text.Append(ref index, "Fly ON "); if (fly) statusBuffer.Append(ref index, "Fly ON ");
bool speed = (speeding || halfSpeeding) && bool speed = (speeding || halfSpeeding) &&
(hacks.CanSpeed || hacks.MaxSpeedMultiplier > 1); (hacks.CanSpeed || hacks.MaxSpeedMultiplier > 1);
if (speed) text.Append(ref index, "Speed ON "); if (speed) statusBuffer.Append(ref index, "Speed ON ");
if (noclip) text.Append(ref index, "Noclip ON "); if (noclip) statusBuffer.Append(ref index, "Noclip ON ");
hackStates.SetText(text.ToString()); hackStates.SetText(statusBuffer.ToString());
} }
} }
} }

View File

@ -90,7 +90,7 @@
<Compile Include="2D\Screens\ClickableScreen.cs" /> <Compile Include="2D\Screens\ClickableScreen.cs" />
<Compile Include="2D\Screens\DeathScreen.cs" /> <Compile Include="2D\Screens\DeathScreen.cs" />
<Compile Include="2D\Screens\DisconnectScreen.cs" /> <Compile Include="2D\Screens\DisconnectScreen.cs" />
<Compile Include="2D\Screens\FpsScreen.cs" /> <Compile Include="2D\Screens\StatusScreen.cs" />
<Compile Include="2D\Screens\Inventory\InventoryScreen.cs" /> <Compile Include="2D\Screens\Inventory\InventoryScreen.cs" />
<Compile Include="2D\Screens\Inventory\InventoryScreen.Input.cs" /> <Compile Include="2D\Screens\Inventory\InventoryScreen.Input.cs" />
<Compile Include="2D\Screens\Inventory\InventoryScreen.Scrolling.cs" /> <Compile Include="2D\Screens\Inventory\InventoryScreen.Scrolling.cs" />

View File

@ -13,13 +13,13 @@ namespace ClassicalSharp {
public int GuiTex, GuiClassicTex, IconsTex; public int GuiTex, GuiClassicTex, IconsTex;
Game game; Game game;
IGraphicsApi gfx; IGraphicsApi gfx;
FpsScreen fpsScreen; StatusScreen fpsScreen;
internal HudScreen hudScreen; internal HudScreen hudScreen;
internal Screen activeScreen; internal Screen activeScreen;
internal List<WarningScreen> overlays = new List<WarningScreen>(); internal List<WarningScreen> overlays = new List<WarningScreen>();
public GuiInterface(Game game) { public GuiInterface(Game game) {
fpsScreen = game.AddComponent(new FpsScreen(game)); fpsScreen = game.AddComponent(new StatusScreen(game));
hudScreen = game.AddComponent(new HudScreen(game)); hudScreen = game.AddComponent(new HudScreen(game));
} }

View File

@ -36,6 +36,7 @@ namespace ClassicalSharp.Network {
static ushort SetTwoWayPing(int i, ushort prev) { static ushort SetTwoWayPing(int i, ushort prev) {
Entries[i].Data = (ushort)(prev + 1); Entries[i].Data = (ushort)(prev + 1);
Entries[i].TimeSent = DateTime.UtcNow; Entries[i].TimeSent = DateTime.UtcNow;
Entries[i].TimeReceived = default(DateTime);
return (ushort)(prev + 1); return (ushort)(prev + 1);
} }