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

View File

@ -90,7 +90,7 @@
<Compile Include="2D\Screens\ClickableScreen.cs" />
<Compile Include="2D\Screens\DeathScreen.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.Input.cs" />
<Compile Include="2D\Screens\Inventory\InventoryScreen.Scrolling.cs" />

View File

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

View File

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