From a12ffa3730faf37f7f4feeba4d47e91bbf8c1791 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 27 Sep 2015 08:48:51 +1000 Subject: [PATCH] Fix custom key bindings not being loaded, sprites are now rotated diagonally. --- ClassicalSharp/ClassicalSharp.csproj | 2 +- ClassicalSharp/Game/Game.InputHandling.cs | 7 +-- ClassicalSharp/Game/Game.cs | 14 ++++-- ClassicalSharp/Map/ChunkMeshBuilder.cs | 5 +-- .../Map/ChunkMeshBuilderTex2Col4.cs | 43 ++++++++----------- ...apFcm3.Exporter.cs => MapFcm3.Importer.cs} | 0 ClassicalSharp/Utils/FastColour.cs | 2 + ClassicalSharp/Utils/Options.cs | 30 +++++++------ 8 files changed, 52 insertions(+), 51 deletions(-) rename ClassicalSharp/Map/{MapFcm3.Exporter.cs => MapFcm3.Importer.cs} (100%) diff --git a/ClassicalSharp/ClassicalSharp.csproj b/ClassicalSharp/ClassicalSharp.csproj index 769e56f56..9ebd24055 100644 --- a/ClassicalSharp/ClassicalSharp.csproj +++ b/ClassicalSharp/ClassicalSharp.csproj @@ -128,7 +128,7 @@ - + diff --git a/ClassicalSharp/Game/Game.InputHandling.cs b/ClassicalSharp/Game/Game.InputHandling.cs index 221c3e2d8..6b68d6997 100644 --- a/ClassicalSharp/Game/Game.InputHandling.cs +++ b/ClassicalSharp/Game/Game.InputHandling.cs @@ -192,7 +192,7 @@ namespace ClassicalSharp { !(Inventory.CanPlace[block] && Inventory.CanDelete[block]))); } - public KeyMap Keys = new KeyMap(); + public KeyMap Keys; } public enum KeyMapping { @@ -279,11 +279,6 @@ namespace ClassicalSharp { for( int i = 0; i < names.Length; i++ ) { Options.Set( "key-" + names[i], Keys[i].ToString() ); } - try { - Options.Save(); - } catch( IOException ) { - Utils.LogWarning( "Unable to sace options.txt" ); - } } } } \ No newline at end of file diff --git a/ClassicalSharp/Game/Game.cs b/ClassicalSharp/Game/Game.cs index 8e78a5d07..11a36fefd 100644 --- a/ClassicalSharp/Game/Game.cs +++ b/ClassicalSharp/Game/Game.cs @@ -49,7 +49,7 @@ namespace ClassicalSharp { internal string skinServer, chatInInputBuffer, defaultTexPack; internal int defaultIb; public bool CanUseThirdPersonCamera = true; - FpsScreen fpsScreen; + FpsScreen fpsScreen; public IPAddress IPAddress; public string Username; @@ -97,6 +97,7 @@ namespace ClassicalSharp { } catch( IOException ) { Utils.LogWarning( "Unable to load options.txt" ); } + Keys = new KeyMap(); ViewDistance = Options.GetInt( "viewdist", 16, 8192, 512 ); defaultIb = Graphics.MakeDefaultIb(); ModelCache = new ModelCache( this ); @@ -159,7 +160,6 @@ namespace ClassicalSharp { ViewDistance = distance; Utils.LogDebug( "setting view distance to: " + distance ); Options.Set( "viewdist", distance.ToString() ); - Options.Save(); Raise( ViewDistanceChanged ); UpdateProjection(); } @@ -206,7 +206,7 @@ namespace ClassicalSharp { MapRenderer.Render( e.Time ); if( SelectedPos.Valid ) Picking.Render( e.Time, SelectedPos ); - WeatherRenderer.Render( e.Time ); + WeatherRenderer.Render( e.Time ); SelectionManager.Render( e.Time ); bool left = IsMousePressed( MouseButton.Left ); bool right = IsMousePressed( MouseButton.Right ); @@ -351,6 +351,14 @@ namespace ClassicalSharp { Graphics.DeleteTexture( ref CloudsTextureId ); Graphics.DeleteTexture( ref RainTextureId ); Graphics.DeleteTexture( ref SnowTextureId ); + + if( Options.HasChanged ) { + try { + Options.Save(); + } catch( IOException ) { + Utils.LogWarning( "Unable to save options.txt" ); + } + } base.Dispose(); } } diff --git a/ClassicalSharp/Map/ChunkMeshBuilder.cs b/ClassicalSharp/Map/ChunkMeshBuilder.cs index 643af7b3d..281c8482a 100644 --- a/ClassicalSharp/Map/ChunkMeshBuilder.cs +++ b/ClassicalSharp/Map/ChunkMeshBuilder.cs @@ -172,9 +172,8 @@ namespace ClassicalSharp { countIndex += TileSide.Top; if( counts[countIndex] != 0 ) { X = x; Y = y; Z = z; - int count = StretchX( xx, countIndex, x, y, z, chunkIndex, tile, TileSide.Top ); - AddSpriteVertices( tile, count ); - counts[countIndex] = (byte)count; + AddSpriteVertices( tile, 1 ); + counts[countIndex] = 1; } } else { X = x; Y = y; Z = z; diff --git a/ClassicalSharp/Map/ChunkMeshBuilderTex2Col4.cs b/ClassicalSharp/Map/ChunkMeshBuilderTex2Col4.cs index 341d3a8b3..95b02abf1 100644 --- a/ClassicalSharp/Map/ChunkMeshBuilderTex2Col4.cs +++ b/ClassicalSharp/Map/ChunkMeshBuilderTex2Col4.cs @@ -45,7 +45,7 @@ namespace ClassicalSharp { if( vertices == null || vCount > vertices.Length ) { vertices = new VertexPos3fTex2fCol4b[vCount]; - } + } vIndex.left = spriteCount / 6 * 4; vIndex.right = vIndex.left + Count.left / 6 * 4; vIndex.front = vIndex.right + Count.right / 6 * 4; @@ -167,7 +167,7 @@ namespace ClassicalSharp { int texId = info.GetTextureLoc( tile, TileSide.Left ); int i; TextureRectangle rec = atlas.GetTexRec( texId, count, out i ); - FastColour col = emitsLight ? FastColour.White : + FastColour col = emitsLight ? FastColour.White : X > 0 ? ( Y > map.heightmap[( Z * width ) + (X - 1)] ? map.SunlightXSide : map.ShadowlightXSide ) : map.SunlightXSide; if( blockHeight != 1 ) { rec.V2 = rec.V1 + blockHeight * invVerElementSize; @@ -184,7 +184,7 @@ namespace ClassicalSharp { int texId = info.GetTextureLoc( tile, TileSide.Right ); int i; TextureRectangle rec = atlas.GetTexRec( texId, count, out i ); - FastColour col = emitsLight ? FastColour.White : + FastColour col = emitsLight ? FastColour.White : X < maxX ? ( Y > map.heightmap[( Z * width ) + (X + 1)] ? map.SunlightXSide : map.ShadowlightXSide ) : map.SunlightXSide; if( blockHeight != 1 ) { rec.V2 = rec.V1 + blockHeight * invVerElementSize; @@ -201,7 +201,7 @@ namespace ClassicalSharp { int texId = info.GetTextureLoc( tile, TileSide.Back ); int i; TextureRectangle rec = atlas.GetTexRec( texId, count, out i ); - FastColour col = emitsLight ? FastColour.White : + FastColour col = emitsLight ? FastColour.White : Z < maxZ ? ( Y > map.heightmap[( (Z + 1) * width ) + X] ? map.SunlightZSide : map.ShadowlightZSide ) : map.SunlightZSide; if( blockHeight != 1 ) { rec.V2 = rec.V1 + blockHeight * invVerElementSize; @@ -218,7 +218,7 @@ namespace ClassicalSharp { int texId = info.GetTextureLoc( tile, TileSide.Front ); int i; TextureRectangle rec = atlas.GetTexRec( texId, count, out i ); - FastColour col = emitsLight ? FastColour.White : + FastColour col = emitsLight ? FastColour.White : Z > 0 ? ( Y > map.heightmap[( (Z - 1) * width ) + X] ? map.SunlightZSide : map.ShadowlightZSide ) : map.SunlightZSide; if( blockHeight != 1 ) { rec.V2 = rec.V1 + blockHeight * invVerElementSize; @@ -235,7 +235,7 @@ namespace ClassicalSharp { int texId = info.GetTextureLoc( tile, TileSide.Bottom ); int i; TextureRectangle rec = atlas.GetTexRec( texId, count, out i ); - FastColour col = emitsLight ? FastColour.White : + FastColour col = emitsLight ? FastColour.White : Y > 0 ? ( (Y - 1) > map.heightmap[( Z * width ) + X] ? map.SunlightYBottom : map.ShadowlightYBottom ) : map.SunlightYBottom; DrawInfo part = isTranslucent ? drawInfoTranslucent[i] : drawInfoNormal[i]; @@ -249,7 +249,7 @@ namespace ClassicalSharp { int texId = info.GetTextureLoc( tile, TileSide.Top ); int i; TextureRectangle rec = atlas.GetTexRec( texId, count, out i ); - FastColour col = emitsLight ? FastColour.White : + FastColour col = emitsLight ? FastColour.White : Y < maxY ? ( Y > map.heightmap[( Z * width ) + X] ? map.Sunlight : map.Shadowlight ) : map.Sunlight; DrawInfo part = isTranslucent ? drawInfoTranslucent[i] : drawInfoNormal[i]; @@ -262,29 +262,22 @@ namespace ClassicalSharp { void DrawSprite( int count ) { int texId = info.GetTextureLoc( tile, TileSide.Right ); int i; - TextureRectangle rec = atlas.GetTexRec( texId, count, out i ); - FastColour col = Y < maxY ? ( emitsLight || Y > map.heightmap[( Z * width ) + X] ? map.Sunlight : map.Shadowlight ) + TextureRectangle rec = atlas.GetTexRec( texId, 1, out i ); + FastColour col = Y < maxY ? ( emitsLight || Y > map.heightmap[( Z * width ) + X] ? map.Sunlight : map.Shadowlight ) : map.Sunlight; DrawInfo part = drawInfoNormal[i]; - // Draw stretched Z axis - part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X, Y, Z + 0.5f, rec.U2, rec.V2, col ); - part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X, Y + blockHeight, Z + 0.5f, rec.U2, rec.V1, col ); - part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + count, Y + blockHeight, Z + 0.5f, rec.U1, rec.V1, col ); - part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + count, Y, Z + 0.5f, rec.U1, rec.V2, col ); + // Draw Z axis + part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 2.50f/16, Y, Z + 2.5f/16, rec.U2, rec.V2, col ); + part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 2.50f/16, Y + blockHeight, Z + 2.5f/16, rec.U2, rec.V1, col ); + part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 13.5f/16, Y + blockHeight, Z + 13.5f/16, rec.U1, rec.V1, col ); + part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 13.5f/16, Y, Z + 13.5f/16, rec.U1, rec.V2, col ); // Draw X axis - rec.U2 = 1; - int startX = X; - - for( int j = 0; j < count; j++ ) { - part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 0.5f, Y, Z, rec.U1, rec.V2, col ); - part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 0.5f, Y + blockHeight, Z, rec.U1, rec.V1, col ); - part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 0.5f, Y + blockHeight, Z + 1, rec.U2, rec.V1, col ); - part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 0.5f, Y, Z + 1, rec.U2, rec.V2, col ); - X++; - } - X = startX; + part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 2.50f/16, Y, Z + 13.5f/16, rec.U1, rec.V2, col ); + part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 2.50f/16, Y + blockHeight, Z + 13.5f/16, rec.U1, rec.V1, col ); + part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 13.5f/16, Y + blockHeight, Z + 2.5f/16, rec.U2, rec.V1, col ); + part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 13.5f/16, Y, Z + 2.5f/16, rec.U2, rec.V2, col ); } } } \ No newline at end of file diff --git a/ClassicalSharp/Map/MapFcm3.Exporter.cs b/ClassicalSharp/Map/MapFcm3.Importer.cs similarity index 100% rename from ClassicalSharp/Map/MapFcm3.Exporter.cs rename to ClassicalSharp/Map/MapFcm3.Importer.cs diff --git a/ClassicalSharp/Utils/FastColour.cs b/ClassicalSharp/Utils/FastColour.cs index 4319dfd0b..8580955b1 100644 --- a/ClassicalSharp/Utils/FastColour.cs +++ b/ClassicalSharp/Utils/FastColour.cs @@ -59,6 +59,8 @@ namespace ClassicalSharp { return result; } + + public Color ToColor() { return Color.FromArgb( A, R, G, B ); } diff --git a/ClassicalSharp/Utils/Options.cs b/ClassicalSharp/Utils/Options.cs index 3f20a6c25..12ea56d69 100644 --- a/ClassicalSharp/Utils/Options.cs +++ b/ClassicalSharp/Utils/Options.cs @@ -7,32 +7,36 @@ namespace ClassicalSharp { public static class Options { static Dictionary OptionsSet = new Dictionary(); + public static bool HasChanged; public static string Get( string key ) { string value; return OptionsSet.TryGetValue( key, out value ) ? value : null; } - public static bool TryGetInt( string key, out int valueInt ) { + public static int GetInt( string key, int min, int max, int defValue ) { string value; - valueInt = 0; - OptionsSet.TryGetValue( key, out value ); - - if( String.IsNullOrEmpty( value ) ) return false; - return Int32.TryParse( value, out valueInt ); + int valueInt = 0; + if( !OptionsSet.TryGetValue( key, out value ) || String.IsNullOrEmpty( value ) + || !Int32.TryParse( value, out valueInt ) ) + return defValue; + + Utils.Clamp( ref valueInt, min, max ); + return valueInt; } - public static int GetInt( string key, int min, int max, int defValue ) { - int valueInt = 0; - if( TryGetInt( key, out valueInt ) ) { - Utils.Clamp( ref valueInt, min, max ); - return valueInt; - } - return defValue; + public static bool GetBool( string key, bool defValue ) { + string value; + bool valueBool = false; + if( !OptionsSet.TryGetValue( key, out value ) || String.IsNullOrEmpty( value ) + || !Boolean.TryParse( value, out valueBool ) ) + return defValue; + return valueBool; } public static void Set( string key, string value ) { OptionsSet[key] = value; + HasChanged = true; } public const string OptionsFile = "options.txt";