Inline some string date format constants, only check whether a directory exists when opening a file.

This commit is contained in:
UnknownShadow200 2015-06-30 20:08:58 +10:00
parent 658f2518fe
commit d59aba361a
3 changed files with 65 additions and 9 deletions

View File

@ -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();
}
}
}

View File

@ -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 {

View File

@ -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;
}