From d59aba361ab0b706d0a46284865c6f1c9bcb22d3 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 30 Jun 2015 20:08:58 +1000 Subject: [PATCH] Inline some string date format constants, only check whether a directory exists when opening a file. --- .../Renderers/MapRenderer.ShadowMap.cs | 57 +++++++++++++++++++ Game/Game.Chat.cs | 14 ++--- Game/Game.cs | 3 +- 3 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 DefaultPlugin/Renderers/MapRenderer.ShadowMap.cs diff --git a/DefaultPlugin/Renderers/MapRenderer.ShadowMap.cs b/DefaultPlugin/Renderers/MapRenderer.ShadowMap.cs new file mode 100644 index 000000000..c072eddeb --- /dev/null +++ b/DefaultPlugin/Renderers/MapRenderer.ShadowMap.cs @@ -0,0 +1,57 @@ +using System; +using ClassicalSharp; +using ClassicalSharp.GraphicsAPI; +using OpenTK; + +namespace DefaultPlugin { + + public sealed partial class StandardMapRenderer : MapRenderer { + + MapShadowPassShader shadowShader; + Framebuffer shadowMap; + + void InitShadowMap() { + shadowShader = new MapShadowPassShader(); + shadowShader.Init( api ); + shadowMap = new Framebuffer( 1920, 1080 ); + shadowMap.Initalise( false, true, true ); + } + + Matrix4 mvp; + Matrix4 biasedMvp; + static Matrix4 bias = new Matrix4( + 0.5f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.5f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.5f, 0.0f, + 0.5f, 0.5f, 0.5f, 1.0f + ); + + void RenderShadowMap() { + shadowShader.Bind(); + Matrix4 proj = Matrix4.CreatePerspectiveFieldOfView( + (float)Math.PI / 2 - 0.01f, 1920f / 1080f, 0.1f, 800f ); + Matrix4 view = Matrix4.LookAt( new Vector3( 32, 32, 32 ), Vector3.Zero, Vector3.UnitY ); + mvp = view * proj; + biasedMvp = mvp * bias; + shadowShader.SetUniform( shadowShader.mvpLoc, ref mvp ); + + shadowMap.BindForWriting( Window ); + api.FaceCulling = true; + RenderSolidBatch(); + api.FaceCulling = false; + RenderSpriteBatch(); + shadowMap.UnbindFromWriting( Window ); + } + + void BindForReadingShadowMap() { + shader.SetUniform( shader.lightMVPLoc, ref biasedMvp ); + shader.SetUniform( shader.shadowImageLoc, 1 ); + shadowMap.BindForDepthReading( 1 ); + } + + void DisposeShadowMap() { + shadowShader.Dispose(); + shadowMap.Dispose(); + } + } +} \ No newline at end of file diff --git a/Game/Game.Chat.cs b/Game/Game.Chat.cs index 035c20c58..77c094809 100644 --- a/Game/Game.Chat.cs +++ b/Game/Game.Chat.cs @@ -65,16 +65,10 @@ namespace ClassicalSharp { RaiseEvent( ChatReceived, chatArgs ); } - const string fileNameFormat = "yyyy-MM-dd"; - const string chatEntryFormat = "[yyyy-MM-dd HH:mm:ss]"; - const string dateFormat = "dd-MM-yyyy-HH-mm-ss"; DateTime last = new DateTime( 1, 1, 1 ); StreamWriter writer = null; void LogChatToFile( string text ) { DateTime now = DateTime.Now; - if( !Directory.Exists( "logs" ) ) { - Directory.CreateDirectory( "logs" ); - } if( now.Day != last.Day || now.Month != last.Month || now.Year != last.Year ) { if( writer != null ) { @@ -87,16 +81,20 @@ namespace ClassicalSharp { if( writer != null ) { string data = Utils.StripColours( text ); - string entry = now.ToString( chatEntryFormat ) + " " + data; + string entry = now.ToString( "[yyyy-MM-dd HH:mm:ss] " ) + data; writer.WriteLine( entry ); } } void OpenChatFile( DateTime now ) { + if( !Directory.Exists( "logs" ) ) { + Directory.CreateDirectory( "logs" ); + } + string date = now.ToString( "yyyy-MM-dd" ); // Cheap way of ensuring multiple instances do not end up overwriting each other's log entries. for( int i = 0; i < 20; i++ ) { string id = i == 0 ? "" : " _" + i; - string fileName = "chat-" + now.ToString( fileNameFormat ) + id + ".log"; + string fileName = "chat-" + date + id + ".log"; string path = Path.Combine( "logs", fileName ); FileStream stream = null; try { diff --git a/Game/Game.cs b/Game/Game.cs index 44931b14b..1fa8faeb6 100644 --- a/Game/Game.cs +++ b/Game/Game.cs @@ -255,7 +255,8 @@ namespace ClassicalSharp { if( !Directory.Exists( "screenshots" ) ) { Directory.CreateDirectory( "screenshots" ); } - string path = Path.Combine( "screenshots", "screenshot_" + DateTime.Now.ToString( dateFormat ) + ".png" ); + string timestamp = DateTime.Now.ToString( "dd-MM-yyyy-HH-mm-ss" ); + string path = Path.Combine( "screenshots", "screenshot_" + timestamp + ".png" ); Graphics.TakeScreenshot( path, ClientSize ); screenshotRequested = false; }