diff --git a/ClassicalSharp/2D/IsometricBlockDrawer.cs b/ClassicalSharp/2D/IsometricBlockDrawer.cs index ba3e17133..28a7bf1f7 100644 --- a/ClassicalSharp/2D/IsometricBlockDrawer.cs +++ b/ClassicalSharp/2D/IsometricBlockDrawer.cs @@ -27,11 +27,10 @@ namespace ClassicalSharp { blockHeight = info.Height[block]; index = 0; scale = size; - - // screen to isometric coords - pos.X = x; pos.Y = -y; pos.Z = 0; - pos = Utils.RotateX( pos, (float)Utils.DegreesToRadians( -35.264f ) ); - pos = Utils.RotateY( pos, (float)Utils.DegreesToRadians( 45f ) ); + + // screen to isometric coords + pos.X = x; pos.Y = y; pos.Z = 0; + pos = Utils.RotateY( Utils.RotateX( pos, -angleX ), -angleY ); if( info.IsSprite[block] ) { DrawXFace( block, 0f, TileSide.Right ); @@ -41,40 +40,48 @@ namespace ClassicalSharp { DrawZFace( block, -scale, TileSide.Back ); DrawYFace( block, scale * blockHeight, TileSide.Top ); } - game.Graphics.DrawDynamicIndexedVb( DrawMode.Triangles, cache.vb, + + for( int i = 0; i < index; i++ ) + TransformVertex( ref cache.vertices[i] ); + game.Graphics.DrawDynamicIndexedVb( DrawMode.Triangles, cache.vb, cache.vertices, index, index * 6 / 4 ); } + static float angleY = (float)Utils.DegreesToRadians( -45f ); + static float angleX = (float)Utils.DegreesToRadians( 26.565f ); + static void TransformVertex( ref VertexPos3fTex2fCol4b vertex ) { + Vector3 pos = new Vector3( vertex.X, vertex.Y, vertex.Z ); + #if USE_DX + // See comment in IGraphicsApi.Draw2DTexture() + pos.X -= 0.5f; + pos.Y -= 0.5f; + #endif + pos = Utils.RotateX( Utils.RotateY( pos, angleY ), angleX ); + vertex.X = pos.X; vertex.Y = pos.Y; vertex.Z = pos.Z; + } public static void SetupState( IGraphicsApi graphics, bool setFog ) { - graphics.PushMatrix(); - Matrix4 m = Matrix4.RotateY( (float)Utils.DegreesToRadians( 45f ) ) * - Matrix4.RotateX( (float)Utils.RadiansToDegrees( -35.264f ) ); - graphics.LoadMatrix( ref m ); - if( setFog ) - graphics.Fog = false; + if( setFog ) graphics.Fog = false; graphics.BeginVbBatch( VertexFormat.Pos3fTex2fCol4b ); } public static void RestoreState( IGraphicsApi graphics, bool setFog ) { - graphics.PopMatrix(); - if( setFog ) - graphics.Fog = true; + if( setFog ) graphics.Fog = true; } - static Vector3 pos = Vector3.Zero; + static Vector3 pos = Vector3.Zero; static void DrawYFace( byte block, float y, int side ) { int texId = info.GetTextureLoc( block, side ); TextureRectangle rec = atlas.GetTexRec( texId ); FastColour col = colNormal; - cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X - scale, pos.Y + y, + cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X - scale, pos.Y - y, pos.Z - scale, rec.U2, rec.V2, col ); - cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X - scale, pos.Y + y, + cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X - scale, pos.Y - y, pos.Z + scale, rec.U1, rec.V2, col ); - cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + scale, pos.Y + y, + cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + scale, pos.Y - y, pos.Z + scale, rec.U1, rec.V1, col ); - cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + scale, pos.Y + y, + cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + scale, pos.Y - y, pos.Z - scale, rec.U2, rec.V1, col ); } @@ -85,14 +92,14 @@ namespace ClassicalSharp { rec.V2 = rec.V1 + blockHeight * TerrainAtlas2D.invElementSize; FastColour col = colZSide; - cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X - scale, pos.Y - scale * blockHeight, - pos.Z + z, rec.U1, rec.V2, col ); - cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X - scale, pos.Y + scale * blockHeight, - pos.Z + z, rec.U1, rec.V1, col ); - cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + scale, pos.Y + scale * blockHeight, - pos.Z + z, rec.U2, rec.V1, col ); - cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + scale, pos.Y - scale * blockHeight, - pos.Z + z, rec.U2, rec.V2, col ); + cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X - scale, pos.Y + scale * blockHeight, + pos.Z - z, rec.U1, rec.V2, col ); + cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X - scale, pos.Y - scale * blockHeight, + pos.Z - z, rec.U1, rec.V1, col ); + cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + scale, pos.Y - scale * blockHeight, + pos.Z - z, rec.U2, rec.V1, col ); + cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + scale, pos.Y + scale * blockHeight, + pos.Z - z, rec.U2, rec.V2, col ); } static void DrawXFace( byte block, float x, int side ) { @@ -102,13 +109,13 @@ namespace ClassicalSharp { rec.V2 = rec.V1 + blockHeight * TerrainAtlas2D.invElementSize; FastColour col = colXSide; - cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + x, pos.Y - scale * blockHeight, + cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X - x, pos.Y + scale * blockHeight, pos.Z - scale, rec.U1, rec.V2, colNormal ); - cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + x, pos.Y + scale * blockHeight, + cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X - x, pos.Y - scale * blockHeight, pos.Z - scale, rec.U1, rec.V1, colNormal ); - cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + x, pos.Y + scale * blockHeight, + cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X - x, pos.Y - scale * blockHeight, pos.Z + scale, rec.U2, rec.V1, colNormal ); - cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + x, pos.Y - scale * blockHeight, + cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X - x, pos.Y + scale * blockHeight, pos.Z + scale, rec.U2, rec.V2, colNormal ); } } diff --git a/ClassicalSharp/2D/Screens/Menu/MenuInputScreen.cs b/ClassicalSharp/2D/Screens/Menu/MenuInputScreen.cs index 54074602f..55d464681 100644 --- a/ClassicalSharp/2D/Screens/Menu/MenuInputScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/MenuInputScreen.cs @@ -42,6 +42,10 @@ namespace ClassicalSharp { if( key == Key.Escape ) { game.SetNewScreen( new NormalScreen( game ) ); return true; + } else if( (key == Key.Enter || key == Key.KeypadEnter) + && inputWidget != null ) { + ChangeSetting(); + return true; } if( inputWidget == null ) return true; return inputWidget.HandlesKeyDown( key ); @@ -87,20 +91,12 @@ namespace ClassicalSharp { string text = widget.Text + ": " + widget.GetValue( game ); descWidget = TextWidget.Create( game, 0, 100, text, Docking.Centre, Docking.Centre, regularFont ); } - + protected void OnWidgetClick( Game game, ButtonWidget widget ) { if( widget == buttons[okayIndex] ) { - string text = inputWidget.GetText(); - if( inputWidget.Validator.IsValidValue( text ) ) - targetWidget.SetValue( game, text ); - inputWidget.Dispose(); - inputWidget = null; - UpdateDescription( targetWidget ); - targetWidget = null; - buttons[okayIndex].Dispose(); - buttons[okayIndex] = null; + ChangeSetting(); return; - } + } int index = Array.IndexOf( buttons, widget ); MenuInputValidator validator = validators[index]; @@ -122,5 +118,17 @@ namespace ClassicalSharp { Docking.Centre, Docking.Centre, titleFont, OnWidgetClick ); UpdateDescription( targetWidget ); } + + void ChangeSetting() { + string text = inputWidget.GetText(); + if( inputWidget.Validator.IsValidValue( text ) ) + targetWidget.SetValue( game, text ); + inputWidget.Dispose(); + inputWidget = null; + UpdateDescription( targetWidget ); + targetWidget = null; + buttons[okayIndex].Dispose(); + buttons[okayIndex] = null; + } } } \ No newline at end of file diff --git a/ClassicalSharp/2D/Screens/Menu/OptionsScreen.cs b/ClassicalSharp/2D/Screens/Menu/OptionsScreen.cs index 6526ef21e..47e6dccaa 100644 --- a/ClassicalSharp/2D/Screens/Menu/OptionsScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/OptionsScreen.cs @@ -28,11 +28,13 @@ namespace ClassicalSharp { Make( 140, -50, "Mouse sensitivity", Docking.Centre, OnWidgetClick, g => g.MouseSensitivity.ToString(), - (g, v) => g.MouseSensitivity = Int32.Parse( v ) ), + (g, v) => { g.MouseSensitivity = Int32.Parse( v ); + Options.Set( OptionsKey.Sensitivity, v ); } ), Make( 140, 0, "Chat font size", Docking.Centre, OnWidgetClick, g => g.Chat.FontSize.ToString(), - (g, v) => g.Chat.FontSize = Int32.Parse( v ) ), + (g, v) => { g.Chat.FontSize = Int32.Parse( v ); + Options.Set( OptionsKey.FontSize, v ); } ), !network.IsSinglePlayer ? null : Make( 140, 50, "Singleplayer physics", Docking.Centre, OnWidgetClick, diff --git a/ClassicalSharp/2D/Widgets/BlockHotbarWidget.cs b/ClassicalSharp/2D/Widgets/BlockHotbarWidget.cs index e1c793f8d..b95b629a0 100644 --- a/ClassicalSharp/2D/Widgets/BlockHotbarWidget.cs +++ b/ClassicalSharp/2D/Widgets/BlockHotbarWidget.cs @@ -49,7 +49,7 @@ namespace ClassicalSharp { for( int i = 0; i < hotbarCount; i++ ) { int x = X + i * blockSize; IsometricBlockDrawer.Draw( game, (byte)game.Inventory.Hotbar[i], 10, - x + blockSize / 2, game.Height - 12 ); + x + blockSize / 2, game.Height - 18 ); if( i == game.Inventory.HeldBlockIndex ) selectedBlock.X1 = x; } diff --git a/ClassicalSharp/Game/Game.cs b/ClassicalSharp/Game/Game.cs index 1309d4192..93aa972ea 100644 --- a/ClassicalSharp/Game/Game.cs +++ b/ClassicalSharp/Game/Game.cs @@ -102,12 +102,14 @@ namespace ClassicalSharp { } catch( IOException ) { Utils.LogWarning( "Unable to load options.txt" ); } - ViewDistance = Options.GetInt( "viewdist", 16, 8192, 512 ); + ViewDistance = Options.GetInt( OptionsKey.ViewDist, 16, 8192, 512 ); Keys = new KeyMap(); InputHandler = new InputHandler( this ); Chat = new ChatLog( this ); + Chat.FontSize = Options.GetInt( OptionsKey.FontSize, 6, 30, 12 ); Drawer2D = new GdiPlusDrawer2D( Graphics ); defaultIb = Graphics.MakeDefaultIb(); + MouseSensitivity = Options.GetInt( OptionsKey.Sensitivity, 1, 100, 30 ); ModelCache = new ModelCache( this ); ModelCache.InitCache(); @@ -170,7 +172,7 @@ namespace ClassicalSharp { public void SetViewDistance( int distance ) { ViewDistance = distance; Utils.LogDebug( "setting view distance to: " + distance ); - Options.Set( "viewdist", distance.ToString() ); + Options.Set( OptionsKey.ViewDist, distance ); Events.RaiseViewDistanceChanged(); UpdateProjection(); } diff --git a/ClassicalSharp/Game/KeyMap.cs b/ClassicalSharp/Game/KeyMap.cs index 9cf3c4e07..cf785e0c2 100644 --- a/ClassicalSharp/Game/KeyMap.cs +++ b/ClassicalSharp/Game/KeyMap.cs @@ -66,7 +66,7 @@ namespace ClassicalSharp { string key = "key-" + names[i]; string value = Options.Get( key ); if( value == null ) { - Options.Set( key, Keys[i].ToString() ); + Options.Set( key, Keys[i] ); continue; } @@ -74,7 +74,7 @@ namespace ClassicalSharp { try { mapping = (Key)Enum.Parse( typeof( Key ), value, true ); } catch( ArgumentException ) { - Options.Set( key, Keys[i].ToString() ); + Options.Set( key, Keys[i] ); continue; } if( !IsReservedKey( mapping ) ) @@ -85,7 +85,7 @@ namespace ClassicalSharp { void SaveKeyBindings() { string[] names = KeyMapping.GetNames( typeof( KeyMapping ) ); for( int i = 0; i < names.Length; i++ ) { - Options.Set( "key-" + names[i], Keys[i].ToString() ); + Options.Set( "key-" + names[i], Keys[i] ); } } } diff --git a/ClassicalSharp/Utils/Options.cs b/ClassicalSharp/Utils/Options.cs index ea396a732..d7ee3faa2 100644 --- a/ClassicalSharp/Utils/Options.cs +++ b/ClassicalSharp/Utils/Options.cs @@ -4,6 +4,12 @@ using System.IO; namespace ClassicalSharp { + public static class OptionsKey { + public const string ViewDist = "viewdist"; + public const string FontSize = "chatfontsize"; + public const string Sensitivity = "mousesensitivity"; + } + public static class Options { static Dictionary OptionsSet = new Dictionary(); @@ -39,6 +45,11 @@ namespace ClassicalSharp { HasChanged = true; } + public static void Set( string key, T value ) { + OptionsSet[key] = value.ToString(); + HasChanged = true; + } + public const string OptionsFile = "options.txt"; public static void Load() { diff --git a/Launcher/MainForm.cs b/Launcher/MainForm.cs index 87b7dd680..22484f4ff 100644 --- a/Launcher/MainForm.cs +++ b/Launcher/MainForm.cs @@ -235,7 +235,7 @@ namespace Launcher { Options.Set( "launcher-ip", data.Ip ); Options.Set( "launcher-port", data.Port ); Options.Set( "launcher-mppass", EncodeMppass( data.Mppass, data.Username ) ); - Options.Set( "launcher-ccskins", classiCubeSkins.ToString() ); + Options.Set( "launcher-ccskins", classiCubeSkins ); try { Options.Save(); diff --git a/OpenTK/Math/Vector4.cs b/OpenTK/Math/Vector4.cs index ef0292753..852ceeb38 100644 --- a/OpenTK/Math/Vector4.cs +++ b/OpenTK/Math/Vector4.cs @@ -119,6 +119,20 @@ namespace OpenTK { public static void Divide(ref Vector4 vector, ref Vector4 scale, out Vector4 result) { result = new Vector4(vector.X / scale.X, vector.Y / scale.Y, vector.Z / scale.Z, vector.W / scale.W); } + + public static Vector4 Transform(Vector4 vec, Matrix4 mat) { + Vector4 result; + Transform(ref vec, ref mat, out result); + return result; + } + + public static void Transform(ref Vector4 vec, ref Matrix4 mat, out Vector4 result) { + result = new Vector4( + vec.X * mat.Row0.X + vec.Y * mat.Row1.X + vec.Z * mat.Row2.X + vec.W * mat.Row3.X, + vec.X * mat.Row0.Y + vec.Y * mat.Row1.Y + vec.Z * mat.Row2.Y + vec.W * mat.Row3.Y, + vec.X * mat.Row0.Z + vec.Y * mat.Row1.Z + vec.Z * mat.Row2.Z + vec.W * mat.Row3.Z, + vec.X * mat.Row0.W + vec.Y * mat.Row1.W + vec.Z * mat.Row2.W + vec.W * mat.Row3.W); + } public static Vector4 operator + (Vector4 left, Vector4 right) { left.X += right.X;