diff --git a/TrueCraft.Client/Modules/ChunkModule.cs b/TrueCraft.Client/Modules/ChunkModule.cs index bee6752..a1a188a 100644 --- a/TrueCraft.Client/Modules/ChunkModule.cs +++ b/TrueCraft.Client/Modules/ChunkModule.cs @@ -13,6 +13,7 @@ namespace TrueCraft.Client.Modules { public TrueCraftGame Game { get; set; } public ChunkRenderer ChunkRenderer { get; set; } + public int ChunksRendered { get; set; } private List ChunkMeshes { get; set; } private ConcurrentBag IncomingChunks { get; set; } @@ -79,7 +80,7 @@ namespace TrueCraft.Client.Modules } } - private static readonly BlendState ColorWriteDisable = new BlendState() + private static readonly BlendState ColorWriteDisable = new BlendState { ColorWriteChannels = ColorWriteChannels.None }; @@ -89,13 +90,12 @@ namespace TrueCraft.Client.Modules Game.Camera.ApplyTo(OpaqueEffect); Game.Camera.ApplyTo(TransparentEffect); - int verticies = 0, chunks = 0; + int chunks = 0; Game.GraphicsDevice.DepthStencilState = DepthStencilState.Default; for (int i = 0; i < ChunkMeshes.Count; i++) { if (Game.Camera.Frustum.Intersects(ChunkMeshes[i].BoundingBox)) { - verticies += ChunkMeshes[i].GetTotalVertices(); chunks++; ChunkMeshes[i].Draw(OpaqueEffect, 0); } @@ -105,23 +105,17 @@ namespace TrueCraft.Client.Modules for (int i = 0; i < ChunkMeshes.Count; i++) { if (Game.Camera.Frustum.Intersects(ChunkMeshes[i].BoundingBox)) - { - if (!ChunkMeshes[i].IsDisposed) - verticies += ChunkMeshes[i].GetTotalVertices(); ChunkMeshes[i].Draw(TransparentEffect, 1); - } } Game.GraphicsDevice.BlendState = BlendState.NonPremultiplied; for (int i = 0; i < ChunkMeshes.Count; i++) { if (Game.Camera.Frustum.Intersects(ChunkMeshes[i].BoundingBox)) - { - if (!ChunkMeshes[i].IsDisposed) - verticies += ChunkMeshes[i].GetTotalVertices(); ChunkMeshes[i].Draw(TransparentEffect, 1); - } } + + ChunksRendered = chunks; } } -} \ No newline at end of file +} diff --git a/TrueCraft.Client/Modules/DebugInfoModule.cs b/TrueCraft.Client/Modules/DebugInfoModule.cs new file mode 100644 index 0000000..0d8948a --- /dev/null +++ b/TrueCraft.Client/Modules/DebugInfoModule.cs @@ -0,0 +1,87 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; +using TrueCraft.Client.Input; +using TrueCraft.Client.Rendering; + +namespace TrueCraft.Client.Modules +{ + public class DebugInfoModule : IGraphicalModule, IInputModule + { + public bool Chunks { get; set; } + + private TrueCraftGame Game { get; set; } + private FontRenderer Font { get; set; } + private SpriteBatch SpriteBatch { get; set; } + private bool Enabled { get; set; } + + public DebugInfoModule(TrueCraftGame game, FontRenderer font) + { + Game = game; + Font = font; + SpriteBatch = new SpriteBatch(Game.GraphicsDevice); + } + + public bool KeyDown(GameTime gameTime, KeyboardKeyEventArgs e) + { + switch (e.Key) + { + case Keys.F2: + return true; + } + return false; + } + + public bool KeyUp(GameTime gameTime, KeyboardKeyEventArgs e) + { + switch (e.Key) + { + case Keys.F2: + Enabled = !Enabled; + return true; + } + return false; + } + + public void MouseMove(GameTime gameTime, MouseMoveEventArgs e) + { + } + + public void Update(GameTime gameTime) + { + } + + public void Draw(GameTime gameTime) + { + if (!Enabled) + return; + + var fps = (int)(1 / gameTime.ElapsedGameTime.TotalSeconds) + 1; + + const int xOrigin = 10; + const int yOrigin = 5; + const int yOffset = 25; + + SpriteBatch.Begin(); + Font.DrawText(SpriteBatch, xOrigin, yOrigin, string.Format("§lRunning at {0}{1} FPS", + GetFPSColor(fps), fps), 1); + Font.DrawText(SpriteBatch, xOrigin, yOrigin + (yOffset * 1), string.Format("§o{0} vertices, {1} indicies", + Mesh.VerticiesRendered, Mesh.IndiciesRendered), 1); + Font.DrawText(SpriteBatch, xOrigin, yOrigin + (yOffset * 2), + string.Format("§o{0} chunks", Game.ChunkModule.ChunksRendered), 1); + Font.DrawText(SpriteBatch, xOrigin, yOrigin + (yOffset * 3), + string.Format("§o<{0:N2}, {1:N2}, {2:N2}>", + Game.Client.Position.X, Game.Client.Position.Y, Game.Client.Position.Z), 1); + SpriteBatch.End(); + } + + private string GetFPSColor(int fps) + { + if (fps <= 16) + return "§c"; + if (fps <= 32) + return "§e"; + return "§a"; + } + } +} diff --git a/TrueCraft.Client/Rendering/BlockRenderer.cs b/TrueCraft.Client/Rendering/BlockRenderer.cs index fb8a388..8a27cda 100644 --- a/TrueCraft.Client/Rendering/BlockRenderer.cs +++ b/TrueCraft.Client/Rendering/BlockRenderer.cs @@ -192,12 +192,6 @@ namespace TrueCraft.Client.Rendering new Vector3(-0.5f, -0.5f, 0.5f), new Vector3(0.5f, -0.5f, 0.5f) }; - - // TEMP - return; - for (int i = 0; i < CubeMesh.Length; i++) - for (int j = 0; j < CubeMesh[0].Length; j++) - CubeMesh[i][j] *= new Vector3(0.5f); } } -} \ No newline at end of file +} diff --git a/TrueCraft.Client/Rendering/Mesh.cs b/TrueCraft.Client/Rendering/Mesh.cs index c4695df..3b76369 100644 --- a/TrueCraft.Client/Rendering/Mesh.cs +++ b/TrueCraft.Client/Rendering/Mesh.cs @@ -10,6 +10,15 @@ namespace TrueCraft.Client.Rendering /// public class Mesh : IDisposable { + public static int VerticiesRendered { get; set; } + public static int IndiciesRendered { get; set; } + + public static void ResetStats() + { + VerticiesRendered = 0; + IndiciesRendered = 0; + } + /// /// The maximum number of submeshes stored in a single mesh. /// @@ -61,9 +70,6 @@ namespace TrueCraft.Client.Rendering /// /// Creates a new mesh. /// - /// The graphics device to store the mesh on. - /// The number of submeshes in the mesh. - /// Whether the mesh should recalculate its bounding box when changed. public Mesh(TrueCraftGame game, int submeshes = 1, bool recalculateBounds = true) { if ((submeshes < 0) || (submeshes >= Mesh.SubmeshLimit)) @@ -78,12 +84,8 @@ namespace TrueCraft.Client.Rendering /// /// Creates a new mesh. /// - /// The graphics device to store the mesh on. - /// The vertices in the mesh. - /// The number of submeshes in the mesh. - /// Whether the mesh should recalculate its bounding box when changed. - public Mesh(TrueCraftGame game, VertexPositionNormalColorTexture[] vertices, int submeshes = 1, bool recalculateBounds = true) - : this(game, submeshes, recalculateBounds) + public Mesh(TrueCraftGame game, VertexPositionNormalColorTexture[] vertices, + int submeshes = 1, bool recalculateBounds = true) : this(game, submeshes, recalculateBounds) { Vertices = vertices; } @@ -91,12 +93,8 @@ namespace TrueCraft.Client.Rendering /// /// Creates a new mesh. /// - /// The graphics device to store the mesh on. - /// The vertices in the mesh. - /// The first (and only) submesh in the mesh. - /// Whether the mesh should recalculate its bounding box when changed. - public Mesh(TrueCraftGame game, VertexPositionNormalColorTexture[] vertices, int[] indices, bool recalculateBounds = true) - : this(game, 1, recalculateBounds) + public Mesh(TrueCraftGame game, VertexPositionNormalColorTexture[] vertices, + int[] indices, bool recalculateBounds = true) : this(game, 1, recalculateBounds) { Vertices = vertices; SetSubmesh(0, indices); @@ -105,8 +103,6 @@ namespace TrueCraft.Client.Rendering /// /// Sets a submesh in this mesh. /// - /// The submesh index. - /// The indices for the submesh. public void SetSubmesh(int index, int[] indices) { if ((index < 0) || (index > _indices.Length)) @@ -163,12 +159,13 @@ namespace TrueCraft.Client.Rendering effect.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, _indices[index].IndexCount, 0, _indices[index].IndexCount / 3); } + VerticiesRendered += _vertices.VertexCount; + IndiciesRendered += _indices[index].IndexCount; } /// /// Returns the total vertices in this mesh. /// - /// public int GetTotalVertices() { if (_vertices == null) @@ -181,7 +178,6 @@ namespace TrueCraft.Client.Rendering /// /// Returns the total indices for all the submeshes in this mesh. /// - /// public int GetTotalIndices() { lock (_syncLock) @@ -245,4 +241,4 @@ namespace TrueCraft.Client.Rendering Dispose(false); } } -} \ No newline at end of file +} diff --git a/TrueCraft.Client/TrueCraft.Client.csproj b/TrueCraft.Client/TrueCraft.Client.csproj index d89d102..05af9ad 100644 --- a/TrueCraft.Client/TrueCraft.Client.csproj +++ b/TrueCraft.Client/TrueCraft.Client.csproj @@ -135,6 +135,7 @@ + diff --git a/TrueCraft.Client/TrueCraftGame.cs b/TrueCraft.Client/TrueCraftGame.cs index d5d2d31..2e0adbe 100644 --- a/TrueCraft.Client/TrueCraftGame.cs +++ b/TrueCraft.Client/TrueCraftGame.cs @@ -14,7 +14,6 @@ using TrueCraft.API.World; using TrueCraft.Core; using TrueCraft.Core.Networking.Packets; using TrueCraft.Client.Input; -using TrueCraft.Client.Interface; using TrueCraft.Client.Modules; using TrueCraft.Client.Rendering; @@ -28,6 +27,7 @@ namespace TrueCraft.Client public Camera Camera { get; private set; } public ConcurrentBag PendingMainThreadActions { get; set; } public double Bobbing { get; set; } + public ChunkModule ChunkModule { get; set; } private List Modules { get; set; } private SpriteBatch SpriteBatch { get; set; } @@ -41,7 +41,7 @@ namespace TrueCraft.Client private DateTime NextPhysicsUpdate { get; set; } private bool MouseCaptured { get; set; } private GameTime GameTime { get; set; } - private Microsoft.Xna.Framework.Vector3 Delta { get; set; } + private DebugInfoModule DebugInfoModule { get; set; } public static readonly int Reach = 5; @@ -62,6 +62,7 @@ namespace TrueCraft.Client Graphics.IsFullScreen = UserSettings.Local.IsFullscreen; Graphics.PreferredBackBufferWidth = UserSettings.Local.WindowResolution.Width; Graphics.PreferredBackBufferHeight = UserSettings.Local.WindowResolution.Height; + Graphics.ApplyChanges(); Client = client; EndPoint = endPoint; LastPhysicsUpdate = DateTime.MinValue; @@ -85,9 +86,13 @@ namespace TrueCraft.Client base.Initialize(); // (calls LoadContent) - Modules.Add(new ChunkModule(this)); + ChunkModule = new ChunkModule(this); + DebugInfoModule = new DebugInfoModule(this, Pixel); + + Modules.Add(ChunkModule); Modules.Add(new HighlightModule(this)); Modules.Add(new PlayerControlModule(this)); + Modules.Add(DebugInfoModule); Client.PropertyChanged += HandleClientPropertyChanged; Client.Connect(EndPoint); @@ -136,9 +141,7 @@ namespace TrueCraft.Client Pixel = new FontRenderer( new Font(Content, "Fonts/Pixel"), - new Font(Content, "Fonts/Pixel", FontStyle.Bold), - null, // No support for underlined or strikethrough yet. The FontRenderer will revert to using the regular font style. - null, // (I don't think BMFont has those options?) + new Font(Content, "Fonts/Pixel", FontStyle.Bold), null, null, new Font(Content, "Fonts/Pixel", FontStyle.Italic)); base.LoadContent(); @@ -250,6 +253,7 @@ namespace TrueCraft.Client GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp; GraphicsDevice.SamplerStates[1] = SamplerState.PointClamp; + Mesh.ResetStats(); foreach (var module in Modules) { var drawable = module as IGraphicalModule;