2016-03-26 13:51:42 +11:00
|
|
|
|
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
|
|
|
|
|
using System;
|
2015-05-09 18:37:20 +10:00
|
|
|
|
using System.Drawing;
|
2016-03-27 09:33:51 +11:00
|
|
|
|
using ClassicalSharp.Entities;
|
2015-10-08 19:39:27 +11:00
|
|
|
|
using ClassicalSharp.GraphicsAPI;
|
2016-09-26 18:33:05 +10:00
|
|
|
|
using ClassicalSharp.Gui.Widgets;
|
2016-07-14 11:29:54 +10:00
|
|
|
|
#if ANDROID
|
|
|
|
|
using Android.Graphics;
|
|
|
|
|
#endif
|
2014-12-17 14:47:17 +11:00
|
|
|
|
|
2016-09-26 18:33:05 +10:00
|
|
|
|
namespace ClassicalSharp.Gui.Screens {
|
2016-05-08 18:53:52 +10:00
|
|
|
|
public class FpsScreen : Screen, IGameComponent {
|
2014-12-17 14:47:17 +11:00
|
|
|
|
|
2015-10-28 07:20:15 +11:00
|
|
|
|
Font font, posFont;
|
2015-09-02 19:44:24 +10:00
|
|
|
|
StringBuffer text;
|
2015-10-08 19:39:27 +11:00
|
|
|
|
|
2016-11-27 14:47:09 +11:00
|
|
|
|
public FpsScreen(Game game) : base(game) {
|
|
|
|
|
text = new StringBuffer(128);
|
2014-12-17 14:47:17 +11:00
|
|
|
|
}
|
2015-10-28 07:20:15 +11:00
|
|
|
|
|
2016-11-27 14:47:09 +11:00
|
|
|
|
public void Init(Game game) { }
|
|
|
|
|
public void Ready(Game game) { Init(); }
|
|
|
|
|
public void Reset(Game game) { }
|
|
|
|
|
public void OnNewMap(Game game) { }
|
|
|
|
|
public void OnNewMapLoaded(Game game) { }
|
2016-05-08 18:53:52 +10:00
|
|
|
|
|
2016-04-18 21:44:10 +10:00
|
|
|
|
TextWidget fpsText, hackStates;
|
2016-10-18 18:09:36 +11:00
|
|
|
|
TextAtlas posAtlas;
|
2016-11-27 14:47:09 +11:00
|
|
|
|
public override void Render(double delta) {
|
|
|
|
|
UpdateFPS(delta);
|
|
|
|
|
if (game.HideGui || !game.ShowFPS) return;
|
2015-09-11 19:39:48 +10:00
|
|
|
|
|
2016-10-12 12:25:12 +11:00
|
|
|
|
gfx.Texturing = true;
|
2016-11-27 14:47:09 +11:00
|
|
|
|
fpsText.Render(delta);
|
|
|
|
|
if (!game.ClassicMode && game.Gui.activeScreen == null) {
|
|
|
|
|
UpdateHackState(false);
|
2015-10-11 20:22:20 +11:00
|
|
|
|
DrawPosition();
|
2016-11-27 14:47:09 +11:00
|
|
|
|
hackStates.Render(delta);
|
2015-10-11 20:22:20 +11:00
|
|
|
|
}
|
2016-10-12 12:25:12 +11:00
|
|
|
|
gfx.Texturing = false;
|
2014-12-17 14:47:17 +11:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-08 22:06:35 +10:00
|
|
|
|
double accumulator;
|
|
|
|
|
int frames, totalSeconds;
|
2016-02-05 18:51:06 +11:00
|
|
|
|
|
2016-11-27 14:47:09 +11:00
|
|
|
|
void UpdateFPS(double delta) {
|
2016-07-08 22:06:35 +10:00
|
|
|
|
frames++;
|
2014-12-17 14:47:17 +11:00
|
|
|
|
accumulator += delta;
|
2016-11-27 14:47:09 +11:00
|
|
|
|
if (accumulator < 1) return;
|
2016-04-18 21:44:10 +10:00
|
|
|
|
|
|
|
|
|
int index = 0;
|
|
|
|
|
totalSeconds++;
|
2016-07-08 22:06:35 +10:00
|
|
|
|
int fps = (int)(frames / accumulator);
|
|
|
|
|
|
|
|
|
|
text.Clear()
|
2016-11-27 14:47:09 +11:00
|
|
|
|
.AppendNum(ref index, fps).Append(ref index, " fps, ");
|
|
|
|
|
if (game.ClassicMode) {
|
|
|
|
|
text.AppendNum(ref index, game.ChunkUpdates).Append(ref index, " chunk updates");
|
2016-04-18 21:44:10 +10:00
|
|
|
|
} else {
|
2016-11-27 14:47:09 +11:00
|
|
|
|
text.AppendNum(ref index, game.ChunkUpdates).Append(ref index, " chunks/s, ")
|
|
|
|
|
.AppendNum(ref index, game.Vertices).Append(ref index, " vertices");
|
2014-12-17 14:47:17 +11:00
|
|
|
|
}
|
2016-04-18 21:44:10 +10:00
|
|
|
|
|
2016-09-11 13:02:35 +10:00
|
|
|
|
string textString = text.ToString();
|
2016-11-27 14:47:09 +11:00
|
|
|
|
fpsText.SetText(textString);
|
2016-04-18 21:44:10 +10:00
|
|
|
|
accumulator = 0;
|
2016-07-08 22:06:35 +10:00
|
|
|
|
frames = 0;
|
2016-04-18 21:44:10 +10:00
|
|
|
|
game.ChunkUpdates = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-27 14:47:09 +11:00
|
|
|
|
string Q(int value) { return value == 1 ? "" : "s"; }
|
2016-02-05 18:51:06 +11:00
|
|
|
|
|
2014-12-17 14:47:17 +11:00
|
|
|
|
public override void Init() {
|
2016-11-27 14:47:09 +11:00
|
|
|
|
font = new Font(game.FontName, 14);
|
|
|
|
|
posFont = new Font(game.FontName, 14, FontStyle.Italic);
|
2015-10-28 07:20:15 +11:00
|
|
|
|
game.Events.ChatFontChanged += ChatFontChanged;
|
|
|
|
|
|
2016-11-27 14:47:09 +11:00
|
|
|
|
fpsText = new TextWidget(game, font)
|
|
|
|
|
.SetLocation(Anchor.LeftOrTop, Anchor.LeftOrTop, 2, 2);
|
2016-04-18 21:44:10 +10:00
|
|
|
|
fpsText.ReducePadding = true;
|
|
|
|
|
fpsText.Init();
|
|
|
|
|
|
2016-09-11 13:02:35 +10:00
|
|
|
|
string msg = text.Length > 0 ? text.ToString() : "FPS: no data yet";
|
2016-11-27 14:47:09 +11:00
|
|
|
|
fpsText.SetText(msg);
|
|
|
|
|
posAtlas = new TextAtlas(game);
|
|
|
|
|
posAtlas.Pack("0123456789-, ()", posFont, "Feet pos: ");
|
2016-10-18 18:09:36 +11:00
|
|
|
|
posAtlas.tex.Y = (short)(fpsText.Height + 2);
|
2015-10-08 19:39:27 +11:00
|
|
|
|
|
2016-10-30 12:50:15 +11:00
|
|
|
|
int yOffset = fpsText.Height + posAtlas.tex.Height + 2;
|
2016-11-27 14:47:09 +11:00
|
|
|
|
hackStates = new TextWidget(game, posFont)
|
|
|
|
|
.SetLocation(Anchor.LeftOrTop, Anchor.LeftOrTop, 2, yOffset);
|
2016-04-18 21:44:10 +10:00
|
|
|
|
hackStates.ReducePadding = true;
|
|
|
|
|
hackStates.Init();
|
2016-11-27 14:47:09 +11:00
|
|
|
|
UpdateHackState(true);
|
2014-12-17 14:47:17 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Dispose() {
|
2015-05-09 18:37:20 +10:00
|
|
|
|
font.Dispose();
|
2015-10-08 19:39:27 +11:00
|
|
|
|
posFont.Dispose();
|
2016-04-18 21:44:10 +10:00
|
|
|
|
fpsText.Dispose();
|
2016-10-18 18:09:36 +11:00
|
|
|
|
|
|
|
|
|
posAtlas.Dispose();
|
2016-05-13 16:26:31 +10:00
|
|
|
|
hackStates.Dispose();
|
2015-10-28 07:20:15 +11:00
|
|
|
|
game.Events.ChatFontChanged -= ChatFontChanged;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-27 14:47:09 +11:00
|
|
|
|
void ChatFontChanged(object sender, EventArgs e) { Recreate(); }
|
2015-10-08 19:39:27 +11:00
|
|
|
|
|
2016-11-27 14:47:09 +11:00
|
|
|
|
public override void OnResize(int width, int height) { }
|
2015-10-09 16:47:39 +11:00
|
|
|
|
|
2015-10-08 19:39:27 +11:00
|
|
|
|
void DrawPosition() {
|
|
|
|
|
int index = 0;
|
2016-10-18 18:09:36 +11:00
|
|
|
|
Texture tex = posAtlas.tex;
|
|
|
|
|
tex.X1 = 2; tex.Width = (short)posAtlas.offset;
|
2016-11-27 14:47:09 +11:00
|
|
|
|
IGraphicsApi.Make2DQuad(ref tex, FastColour.WhitePacked,
|
|
|
|
|
game.ModelCache.vertices, ref index);
|
2015-10-08 19:39:27 +11:00
|
|
|
|
|
2016-11-27 14:47:09 +11:00
|
|
|
|
Vector3I pos = Vector3I.Floor(game.LocalPlayer.Position);
|
2016-10-18 18:09:36 +11:00
|
|
|
|
posAtlas.curX = posAtlas.offset + 2;
|
|
|
|
|
VertexP3fT2fC4b[] vertices = game.ModelCache.vertices;
|
|
|
|
|
|
2016-11-27 14:47:09 +11:00
|
|
|
|
posAtlas.Add(13, vertices, ref index);
|
|
|
|
|
posAtlas.AddInt(pos.X, vertices, ref index);
|
|
|
|
|
posAtlas.Add(11, vertices, ref index);
|
|
|
|
|
posAtlas.AddInt(pos.Y, vertices, ref index);
|
|
|
|
|
posAtlas.Add(11, vertices, ref index);
|
|
|
|
|
posAtlas.AddInt(pos.Z, vertices, ref index);
|
|
|
|
|
posAtlas.Add(14, vertices, ref index);
|
2015-10-08 19:39:27 +11:00
|
|
|
|
|
2016-11-27 14:47:09 +11:00
|
|
|
|
gfx.BindTexture(posAtlas.tex.ID);
|
|
|
|
|
gfx.UpdateDynamicIndexedVb(DrawMode.Triangles,
|
|
|
|
|
game.ModelCache.vb, game.ModelCache.vertices, index);
|
2015-10-08 19:39:27 +11:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-08 17:52:58 +11:00
|
|
|
|
bool speeding, halfSpeeding, noclip, fly;
|
2016-04-14 07:38:25 +10:00
|
|
|
|
int lastFov;
|
2016-11-27 14:47:09 +11:00
|
|
|
|
void UpdateHackState(bool force) {
|
2016-03-31 21:25:25 +11:00
|
|
|
|
HacksComponent hacks = game.LocalPlayer.Hacks;
|
2016-11-27 14:47:09 +11:00
|
|
|
|
if (force || hacks.Speeding != speeding || hacks.HalfSpeeding != halfSpeeding || hacks.Noclip != noclip ||
|
|
|
|
|
hacks.Flying != fly || game.Fov != lastFov) {
|
2016-03-31 21:25:25 +11:00
|
|
|
|
speeding = hacks.Speeding; halfSpeeding = hacks.HalfSpeeding; noclip = hacks.Noclip; fly = hacks.Flying;
|
2016-04-14 07:38:25 +10:00
|
|
|
|
lastFov = game.Fov;
|
2015-10-08 19:39:27 +11:00
|
|
|
|
int index = 0;
|
|
|
|
|
text.Clear();
|
|
|
|
|
|
2016-11-27 14:47:09 +11:00
|
|
|
|
if (game.Fov != game.DefaultFov) text.Append(ref index, "Zoom fov ")
|
|
|
|
|
.AppendNum(ref index, lastFov).Append(ref index, " ");
|
|
|
|
|
if (fly) text.Append(ref index, "Fly ON ");
|
2016-05-08 14:10:24 +10:00
|
|
|
|
|
2016-07-08 22:06:35 +10:00
|
|
|
|
bool speed = (speeding || halfSpeeding) &&
|
2016-05-17 07:45:52 +10:00
|
|
|
|
(hacks.CanSpeed || hacks.MaxSpeedMultiplier > 1);
|
2016-11-27 14:47:09 +11:00
|
|
|
|
if (speed) text.Append(ref index, "Speed ON ");
|
|
|
|
|
if (noclip) text.Append(ref index, "Noclip ON ");
|
|
|
|
|
hackStates.SetText(text.ToString());
|
2015-10-08 19:39:27 +11:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-12-17 14:47:17 +11:00
|
|
|
|
}
|
|
|
|
|
}
|