diff --git a/ClassicalSharp/2D/Screens/ChatScreen.cs b/ClassicalSharp/2D/Screens/ChatScreen.cs index 281dffaea..99d67eee7 100644 --- a/ClassicalSharp/2D/Screens/ChatScreen.cs +++ b/ClassicalSharp/2D/Screens/ChatScreen.cs @@ -151,6 +151,7 @@ namespace ClassicalSharp { game.CursorVisible = true; suppressNextPress = true; HandlesAllInput = true; + game.Keyboard.KeyRepeat = true; textInput.chatInputText.Clear(); textInput.chatInputText.Append( 0, initialText ); textInput.Init(); @@ -165,6 +166,7 @@ namespace ClassicalSharp { if( game.CursorVisible ) game.CursorVisible = false; game.Camera.RegrabMouse(); + game.Keyboard.KeyRepeat = false; if( key == game.Keys[KeyMapping.PauseOrExit] ) textInput.chatInputText.Clear(); diff --git a/ClassicalSharp/2D/Screens/Menu/EnvSettingsScreen.cs b/ClassicalSharp/2D/Screens/Menu/EnvSettingsScreen.cs index 12ad9d2e0..3caad2b43 100644 --- a/ClassicalSharp/2D/Screens/Menu/EnvSettingsScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/EnvSettingsScreen.cs @@ -10,9 +10,7 @@ namespace ClassicalSharp { } public override void Init() { - titleFont = new Font( "Arial", 16, FontStyle.Bold ); - regularFont = new Font( "Arial", 16, FontStyle.Regular ); - hintFont = new Font( "Arial", 14, FontStyle.Italic ); + base.Init(); buttons = new ButtonWidget[] { Make( -140, -150, "Clouds colour", Docking.Centre, OnWidgetClick, diff --git a/ClassicalSharp/2D/Screens/Menu/MenuInputScreen.cs b/ClassicalSharp/2D/Screens/Menu/MenuInputScreen.cs index 62ed1a9a0..54074602f 100644 --- a/ClassicalSharp/2D/Screens/Menu/MenuInputScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/MenuInputScreen.cs @@ -26,6 +26,13 @@ namespace ClassicalSharp { graphicsApi.Texturing = false; } + public override void Init() { + titleFont = new Font( "Arial", 16, FontStyle.Bold ); + regularFont = new Font( "Arial", 16, FontStyle.Regular ); + hintFont = new Font( "Arial", 14, FontStyle.Italic ); + game.Keyboard.KeyRepeat = true; + } + public override bool HandlesKeyPress( char key ) { if( inputWidget == null ) return true; return inputWidget.HandlesKeyPress( key ); @@ -59,6 +66,7 @@ namespace ClassicalSharp { if( inputWidget != null ) inputWidget.Dispose(); hintFont.Dispose(); + game.Keyboard.KeyRepeat = false; base.Dispose(); } diff --git a/ClassicalSharp/2D/Screens/Menu/OptionsScreen.cs b/ClassicalSharp/2D/Screens/Menu/OptionsScreen.cs index ed47c21de..6e02d009a 100644 --- a/ClassicalSharp/2D/Screens/Menu/OptionsScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/OptionsScreen.cs @@ -10,9 +10,7 @@ namespace ClassicalSharp { } public override void Init() { - titleFont = new Font( "Arial", 16, FontStyle.Bold ); - regularFont = new Font( "Arial", 16, FontStyle.Regular ); - hintFont = new Font( "Arial", 14, FontStyle.Italic ); + base.Init(); INetworkProcessor network = game.Network; buttons = new ButtonWidget[] { diff --git a/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs b/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs index 1e852a2c5..78ecc653b 100644 --- a/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/PauseScreen.cs @@ -22,7 +22,7 @@ namespace ClassicalSharp { Make( 0, -100, "Options", Docking.Centre, (g, w) => g.SetNewScreen( new OptionsScreen( g ) ) ), Make( 0, -50, "Environment settings", Docking.Centre, (g, w) => g.SetNewScreen( new EnvSettingsScreen( g ) ) ), Make( 0, 0, "Key mappings", Docking.Centre, (g, w) => g.SetNewScreen( new KeyMappingsScreen( g ) ) ), - //Make( 0, 50, "Load/Save/Gen level", Docking.Centre, (g, w) => { } ), + Make( 0, 50, "Load/Save/Gen level", Docking.Centre, (g, w) => g.SetNewScreen( new SaveLevelScreen( g ) ) ), Make( 0, 55, "Back to game", Docking.BottomOrRight, (g, w) => g.SetNewScreen( new NormalScreen( g ) ) ), Make( 0, 5, "Quit game", Docking.BottomOrRight, (g, w) => g.Exit() ), }; diff --git a/ClassicalSharp/2D/Screens/Menu/SaveLevelScreen.cs b/ClassicalSharp/2D/Screens/Menu/SaveLevelScreen.cs new file mode 100644 index 000000000..35802a1c3 --- /dev/null +++ b/ClassicalSharp/2D/Screens/Menu/SaveLevelScreen.cs @@ -0,0 +1,77 @@ +using System; +using System.Drawing; +using OpenTK.Input; + +namespace ClassicalSharp { + + public sealed class SaveLevelScreen : MenuScreen { + + public SaveLevelScreen( Game game ) : base( game ) { + } + + MenuInputWidget inputWidget; + Font hintFont; + + public override void Render( double delta ) { + RenderMenuBounds(); + graphicsApi.Texturing = true; + RenderMenuButtons( delta ); + inputWidget.Render( delta ); + graphicsApi.Texturing = false; + } + + public override bool HandlesKeyPress( char key ) { + return inputWidget.HandlesKeyPress( key ); + } + + public override bool HandlesKeyDown( Key key ) { + if( key == Key.Escape ) { + game.SetNewScreen( new NormalScreen( game ) ); + return true; + } + return inputWidget.HandlesKeyDown( key ); + } + + public override bool HandlesKeyUp( Key key ) { + return inputWidget.HandlesKeyUp( key ); + } + + public override void Init() { + game.Keyboard.KeyRepeat = true; + titleFont = new Font( "Arial", 16, FontStyle.Bold ); + regularFont = new Font( "Arial", 16, FontStyle.Regular ); + hintFont = new Font( "Arial", 14, FontStyle.Italic ); + + inputWidget = MenuInputWidget.Create( + game, 0, 50, 400, 25, "", Docking.Centre, Docking.Centre, + regularFont, titleFont, hintFont, new PathValidator() ); + buttons = new [] { + ButtonWidget.Create( game, 240, 50, 30, 30, "OK", Docking.Centre, + Docking.Centre, titleFont, OkButtonClick ), + ButtonWidget.Create( game, 0, 5, 240, 35, "Back to menu", Docking.Centre, Docking.BottomOrRight, + titleFont, (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ), + }; + } + + + public override void OnResize( int oldWidth, int oldHeight, int width, int height ) { + inputWidget.OnResize( oldWidth, oldHeight, width, height ); + base.OnResize( oldWidth, oldHeight, width, height ); + } + + public override void Dispose() { + game.Keyboard.KeyRepeat = false; + inputWidget.Dispose(); + hintFont.Dispose(); + base.Dispose(); + } + + void OkButtonClick( Game game, ButtonWidget widget ) { + string text = inputWidget.GetText(); + + if( inputWidget.Validator.IsValidValue( text ) ) + game.AddChat( "okay path" ); + game.SetNewScreen( new PauseScreen( game ) ); + } + } +} \ No newline at end of file diff --git a/ClassicalSharp/2D/Widgets/Menu/MenuInputValidator.cs b/ClassicalSharp/2D/Widgets/Menu/MenuInputValidator.cs index 4d96be9c9..eb53fbd06 100644 --- a/ClassicalSharp/2D/Widgets/Menu/MenuInputValidator.cs +++ b/ClassicalSharp/2D/Widgets/Menu/MenuInputValidator.cs @@ -92,6 +92,25 @@ namespace ClassicalSharp { } } + public sealed class PathValidator : MenuInputValidator { + + public PathValidator() { + Range = "&7(Enter filename)"; + } + + public override bool IsValidChar( char c ) { + return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == ' '; + } + + public override bool IsValidString( string s ) { + return true; + } + + public override bool IsValidValue( string s ) { + return s.Length > 0; + } + } + public sealed class BooleanValidator : MenuInputValidator { public BooleanValidator() { diff --git a/ClassicalSharp/2D/Widgets/TextInputWidget.cs b/ClassicalSharp/2D/Widgets/TextInputWidget.cs index 77cfade81..63078aaf0 100644 --- a/ClassicalSharp/2D/Widgets/TextInputWidget.cs +++ b/ClassicalSharp/2D/Widgets/TextInputWidget.cs @@ -10,12 +10,6 @@ namespace ClassicalSharp { public TextInputWidget( Game game, Font font, Font boldFont ) : base( game ) { HorizontalDocking = Docking.LeftOrTop; VerticalDocking = Docking.BottomOrRight; - handlers[0] = new InputHandler( BackspaceKey, Key.BackSpace, 10 ); - handlers[1] = new InputHandler( DeleteKey, Key.Delete, 10 ); - handlers[2] = new InputHandler( LeftKey, Key.Left, 10 ); - handlers[3] = new InputHandler( RightKey, Key.Right, 10 ); - handlers[4] = new InputHandler( UpKey, Key.Up, 5 ); - handlers[5] = new InputHandler( DownKey, Key.Down, 5 ); typingLogPos = game.ChatInputLog.Count; // Index of newest entry + 1. this.font = font; this.boldFont = boldFont; @@ -33,7 +27,6 @@ namespace ClassicalSharp { public override void Render( double delta ) { chatInputTexture.Render( graphicsApi ); chatCaretTexture.Render( graphicsApi ); - TickInput( delta ); } public override void Init() { @@ -109,53 +102,6 @@ namespace ClassicalSharp { } #region Input handling - InputHandler[] handlers = new InputHandler[6]; - - class InputHandler { - public Action KeyFunction; - public DateTime LastDown; - public Key AssociatedKey; - public double accumulator, period; - - public InputHandler( Action func, Key key, int frequency ) { - KeyFunction = func; - AssociatedKey = key; - LastDown = DateTime.MinValue; - period = 1.0 / frequency; - } - - public bool HandlesKeyDown( Key key ) { - if( key != AssociatedKey ) return false; - LastDown = DateTime.UtcNow; - KeyFunction(); - return true; - } - - public void KeyTick( Game game ) { - if( LastDown == DateTime.MinValue ) return; - if( game.IsKeyDown( AssociatedKey ) && - (DateTime.UtcNow - LastDown).TotalSeconds >= period ) { - KeyFunction(); - } - } - - public bool HandlesKeyUp( Key key ) { - if( key != AssociatedKey ) return false; - LastDown = DateTime.MinValue; - return true; - } - } - - void TickInput( double delta ) { - for( int i = 0; i < handlers.Length; i++ ) { - InputHandler handler = handlers[i]; - handler.accumulator += delta; - while( handler.accumulator > handler.period ) { - handler.KeyTick( game ); - handler.accumulator -= handler.period; - } - } - } public override bool HandlesKeyPress( char key ) { if( chatInputText.Length < 64 && !IsInvalidChar( key ) ) { @@ -172,6 +118,18 @@ namespace ClassicalSharp { return false; } + public override bool HandlesKeyDown( Key key ) { + if( key == Key.Down ) DownKey(); + else if( key == Key.Up ) UpKey(); + else if( key == Key.Left ) LeftKey(); + else if( key == Key.Right ) RightKey(); + else if( key == Key.BackSpace ) BackspaceKey(); + else if( key == Key.Delete ) DeleteKey(); + else if( !OtherKey( key ) ) return false; + + return true; + } + void BackspaceKey() { if( !chatInputText.Empty && caretPos != 0 ) { if( caretPos == -1 ) { @@ -240,10 +198,7 @@ namespace ClassicalSharp { } } - public override bool HandlesKeyDown( Key key ) { - for( int i = 0; i < handlers.Length; i++ ) { - if( handlers[i].HandlesKeyDown( key ) ) return true; - } + bool OtherKey( Key key ) { bool controlDown = game.IsKeyDown( Key.ControlLeft ) || game.IsKeyDown( Key.ControlRight ); if( key == Key.V && controlDown && chatInputText.Length < 64 ) { string text = Clipboard.GetText(); @@ -277,14 +232,6 @@ namespace ClassicalSharp { } return false; } - - public override bool HandlesKeyUp( Key key ) { - for( int i = 0; i < handlers.Length; i++ ) { - if( handlers[i].HandlesKeyUp( key ) ) return true; - } - return false; - } - #endregion } } \ No newline at end of file diff --git a/ClassicalSharp/ClassicalSharp.csproj b/ClassicalSharp/ClassicalSharp.csproj index 9ebd24055..9c6551ed6 100644 --- a/ClassicalSharp/ClassicalSharp.csproj +++ b/ClassicalSharp/ClassicalSharp.csproj @@ -77,6 +77,7 @@ + diff --git a/ClassicalSharp/Model/ChickenModel.cs b/ClassicalSharp/Model/ChickenModel.cs index bc8b77e1f..c661da25f 100644 --- a/ClassicalSharp/Model/ChickenModel.cs +++ b/ClassicalSharp/Model/ChickenModel.cs @@ -7,7 +7,7 @@ namespace ClassicalSharp.Model { public class ChickenModel : IModel { public ChickenModel( Game window ) : base( window ) { - vertices = new VertexPos3fTex2fCol4b[partVertices * 6 + planeVertices * 2 * 2]; + vertices = new ModelVertex[partVertices * 6 + planeVertices * 2 * 2]; Head = MakeHead(); Head2 = MakeHead2(); // TODO: Find a more appropriate name. Head3 = MakeHead3(); diff --git a/ClassicalSharp/Model/CreeperModel.cs b/ClassicalSharp/Model/CreeperModel.cs index b027f8d2d..18a667cc0 100644 --- a/ClassicalSharp/Model/CreeperModel.cs +++ b/ClassicalSharp/Model/CreeperModel.cs @@ -7,7 +7,7 @@ namespace ClassicalSharp.Model { public class CreeperModel : IModel { public CreeperModel( Game window ) : base( window ) { - vertices = new VertexPos3fTex2fCol4b[partVertices * 6]; + vertices = new ModelVertex[partVertices * 6]; Head = MakeHead(); Torso = MakeTorso(); LeftLegFront = MakeLeg( -4/16f, 0, -6/16f, -2/16f ); diff --git a/ClassicalSharp/Model/IModel.cs b/ClassicalSharp/Model/IModel.cs index 1543cd84b..a1a582a68 100644 --- a/ClassicalSharp/Model/IModel.cs +++ b/ClassicalSharp/Model/IModel.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.InteropServices; using ClassicalSharp.GraphicsAPI; using ClassicalSharp.Renderers; using OpenTK; @@ -48,7 +49,7 @@ namespace ClassicalSharp.Model { } protected FastColour col; - protected VertexPos3fTex2fCol4b[] vertices; + protected ModelVertex[] vertices; protected int index; protected ModelPart MakePart( int x, int y, int sidesW, int sidesH, int endsW, int endsH, int bodyW, int bodyH, @@ -59,7 +60,7 @@ namespace ClassicalSharp.Model { ZPlane( x + sidesW + bodyW + sidesW, y + endsH, bodyW, bodyH, x1, x2, y1, y2, z2, _64x64 ); // back XPlane( x, y + endsH, sidesW, sidesH, z2, z1, y1, y2, x2, _64x64 ); // left XPlane( x + sidesW + bodyW, y + endsH, sidesW, sidesH, z1, z2, y1, y2, x1, _64x64 ); // right - return new ModelPart( index - 6 * 4, 6 * 4 ); + return new ModelPart( index - 6 * 4, 6 * 4 ); } protected ModelPart MakeRotatedPart( int x, int y, int sidesW, int sidesH, int endsW, int endsH, int bodyW, int bodyH, @@ -72,52 +73,50 @@ namespace ClassicalSharp.Model { XPlane( x + sidesW + bodyW, y + endsH, sidesW, sidesH, y1, y2, z2, z1, x1, _64x64 ); // right // rotate left and right 90 degrees for( int i = index - 8; i < index; i++ ) { - VertexPos3fTex2fCol4b vertex = vertices[i]; + ModelVertex vertex = vertices[i]; float z = vertex.Z; vertex.Z = vertex.Y; vertex.Y = z; vertices[i] = vertex; } - return new ModelPart( index - 6 * 4, 6 * 4 ); - } - - protected static TextureRectangle SkinTexCoords( int x, int y, int width, int height, float skinWidth, float skinHeight ) { - return new TextureRectangle( x / skinWidth, y / skinHeight, width / skinWidth, height / skinHeight ); + return new ModelPart( index - 6 * 4, 6 * 4 ); } protected void XPlane( int texX, int texY, int texWidth, int texHeight, float z1, float z2, float y1, float y2, float x, bool _64x64 ) { - TextureRectangle rec = SkinTexCoords( texX, texY, texWidth, texHeight, 64, _64x64 ? 64 : 32 ); - vertices[index++] = new VertexPos3fTex2fCol4b( x, y1, z1, rec.U1, rec.V2, FastColour.White ); - vertices[index++] = new VertexPos3fTex2fCol4b( x, y2, z1, rec.U1, rec.V1, FastColour.White ); - vertices[index++] = new VertexPos3fTex2fCol4b( x, y2, z2, rec.U2, rec.V1, FastColour.White ); - vertices[index++] = new VertexPos3fTex2fCol4b( x, y1, z2, rec.U2, rec.V2, FastColour.White ); + vertices[index++] = new ModelVertex( x, y1, z1, texX, texY + texHeight ); + vertices[index++] = new ModelVertex( x, y2, z1, texX, texY ); + vertices[index++] = new ModelVertex( x, y2, z2, texX + texWidth, texY ); + vertices[index++] = new ModelVertex( x, y1, z2, texX + texWidth, texY + texHeight ); } protected void YPlane( int texX, int texY, int texWidth, int texHeight, float x1, float x2, float z1, float z2, float y, bool _64x64 ) { - TextureRectangle rec = SkinTexCoords( texX, texY, texWidth, texHeight, 64, _64x64 ? 64 : 32 ); - vertices[index++] = new VertexPos3fTex2fCol4b( x1, y, z1, rec.U1, rec.V1, FastColour.White ); - vertices[index++] = new VertexPos3fTex2fCol4b( x2, y, z1, rec.U2, rec.V1, FastColour.White ); - vertices[index++] = new VertexPos3fTex2fCol4b( x2, y, z2, rec.U2, rec.V2, FastColour.White ); - vertices[index++] = new VertexPos3fTex2fCol4b( x1, y, z2, rec.U1, rec.V2, FastColour.White ); + vertices[index++] = new ModelVertex( x1, y, z1, texX, texY ); + vertices[index++] = new ModelVertex( x2, y, z1, texX + texWidth, texY ); + vertices[index++] = new ModelVertex( x2, y, z2, texX + texWidth, texY + texHeight ); + vertices[index++] = new ModelVertex( x1, y, z2, texX, texY + texHeight ); } protected void ZPlane( int texX, int texY, int texWidth, int texHeight, float x1, float x2, float y1, float y2, float z, bool _64x64 ) { - TextureRectangle rec = SkinTexCoords( texX, texY, texWidth, texHeight, 64, _64x64 ? 64 : 32 ); - vertices[index++] = new VertexPos3fTex2fCol4b( x1, y1, z, rec.U1, rec.V2, FastColour.White ); - vertices[index++] = new VertexPos3fTex2fCol4b( x2, y1, z, rec.U2, rec.V2, FastColour.White ); - vertices[index++] = new VertexPos3fTex2fCol4b( x2, y2, z, rec.U2, rec.V1, FastColour.White ); - vertices[index++] = new VertexPos3fTex2fCol4b( x1, y2, z, rec.U1, rec.V1, FastColour.White ); + vertices[index++] = new ModelVertex( x1, y1, z, texX, texY + texHeight ); + vertices[index++] = new ModelVertex( x2, y1, z, texX + texWidth, texY + texHeight ); + vertices[index++] = new ModelVertex( x2, y2, z, texX + texWidth, texY ); + vertices[index++] = new ModelVertex( x1, y2, z, texX, texY ); } + protected bool _64x64 = false; protected void DrawPart( ModelPart part ) { + float vScale = _64x64 ? 64f : 32f; for( int i = 0; i < part.Count; i++ ) { - VertexPos3fTex2fCol4b vertex = vertices[part.Offset + i]; - Vector3 newPos = Utils.RotateY( vertex.X, vertex.Y, vertex.Z, cosA, sinA ) + pos; + ModelVertex model = vertices[part.Offset + i]; + Vector3 newPos = Utils.RotateY( model.X, model.Y, model.Z, cosA, sinA ) + pos; + + VertexPos3fTex2fCol4b vertex = default( VertexPos3fTex2fCol4b ); vertex.X = newPos.X; vertex.Y = newPos.Y; vertex.Z = newPos.Z; - vertex.R = col.R; vertex.G = col.G; vertex.B = col.B; + vertex.R = col.R; vertex.G = col.G; vertex.B = col.B; vertex.A = 255; + vertex.U = model.U / 64f; vertex.V = model.V / vScale; cache.vertices[index++] = vertex; } } @@ -126,19 +125,33 @@ namespace ClassicalSharp.Model { float cosX = (float)Math.Cos( -angleX ), sinX = (float)Math.Sin( -angleX ); float cosY = (float)Math.Cos( -angleY ), sinY = (float)Math.Sin( -angleY ); float cosZ = (float)Math.Cos( -angleZ ), sinZ = (float)Math.Sin( -angleZ ); + float vScale = _64x64 ? 64f : 32f; for( int i = 0; i < part.Count; i++ ) { - VertexPos3fTex2fCol4b vertex = vertices[part.Offset + i]; - Vector3 loc = new Vector3( vertex.X - x, vertex.Y - y, vertex.Z - z ); + ModelVertex model = vertices[part.Offset + i]; + Vector3 loc = new Vector3( model.X - x, model.Y - y, model.Z - z ); loc = Utils.RotateZ( loc.X, loc.Y, loc.Z, cosZ, sinZ ); loc = Utils.RotateY( loc.X, loc.Y, loc.Z, cosY, sinY ); - loc = Utils.RotateX( loc.X, loc.Y, loc.Z, cosX, sinX ); + loc = Utils.RotateX( loc.X, loc.Y, loc.Z, cosX, sinX ); + VertexPos3fTex2fCol4b vertex = default( VertexPos3fTex2fCol4b ); Vector3 newPos = Utils.RotateY( loc.X + x, loc.Y + y, loc.Z + z, cosA, sinA ) + pos; vertex.X = newPos.X; vertex.Y = newPos.Y; vertex.Z = newPos.Z; - vertex.R = col.R; vertex.G = col.G; vertex.B = col.B; + vertex.R = col.R; vertex.G = col.G; vertex.B = col.B; vertex.A = 255; + vertex.U = model.U / 64f; vertex.V = model.V / vScale; cache.vertices[index++] = vertex; } } + + [StructLayout( LayoutKind.Sequential, Pack = 1 )] + protected struct ModelVertex { + public float X, Y, Z; + public ushort U, V; + + public ModelVertex( float x, float y, float z, int u, int v ) { + X = x; Y = y; Z = z; + U = (ushort)u; V = (ushort)v; + } + } } } \ No newline at end of file diff --git a/ClassicalSharp/Model/PigModel.cs b/ClassicalSharp/Model/PigModel.cs index 6919ee53a..dfa7525a1 100644 --- a/ClassicalSharp/Model/PigModel.cs +++ b/ClassicalSharp/Model/PigModel.cs @@ -7,7 +7,7 @@ namespace ClassicalSharp.Model { public class PigModel : IModel { public PigModel( Game window ) : base( window ) { - vertices = new VertexPos3fTex2fCol4b[partVertices * 6]; + vertices = new ModelVertex[partVertices * 6]; Head = MakeHead(); Torso = MakeTorso(); LeftLegFront = MakeLeg( -5/16f, -1/16f, -7/16f, -3/16f ); diff --git a/ClassicalSharp/Model/PlayerModel.cs b/ClassicalSharp/Model/PlayerModel.cs index 9bc1c3d7d..0c8b0f60b 100644 --- a/ClassicalSharp/Model/PlayerModel.cs +++ b/ClassicalSharp/Model/PlayerModel.cs @@ -7,35 +7,26 @@ namespace ClassicalSharp.Model { public class PlayerModel : IModel { - ModelSet Set64x32, Set64x64, Set64x64Slim; + ModelSet Set, SetSlim; public PlayerModel( Game window ) : base( window ) { - vertices = new VertexPos3fTex2fCol4b[partVertices * ( 7 * 2 + 2 )]; - Set64x32 = new ModelSet(); - Set64x32.Head = MakeHead( false ); - Set64x32.Torso = MakeTorso( false ); - Set64x32.LeftLeg = MakeLeftLeg( 0, 16, 4/16f, 0f, false ); - Set64x32.RightLeg = MakeRightLeg( 0, 16, 0, 4/16f, false ); - Set64x32.LeftArm = MakeLeftArm( 40, 16, 8/16f, 4/16f, 4, false ); - Set64x32.RightArm = MakeRightArm( 40, 16, 4/16f, 8/16f, 4, false ); - Set64x32.Hat = MakeHat( false ); + vertices = new ModelVertex[partVertices * ( 7 + 2 )]; + Set = new ModelSet(); + Set.Head = MakeHead( false ); + Set.Torso = MakeTorso( false ); + Set.LeftLeg = MakeLeftLeg( 0, 16, 4/16f, 0f, false ); + Set.RightLeg = MakeRightLeg( 0, 16, 0, 4/16f, false ); + Set.LeftArm = MakeLeftArm( 40, 16, 8/16f, 4/16f, 4, false ); + Set.RightArm = MakeRightArm( 40, 16, 4/16f, 8/16f, 4, false ); + Set.Hat = MakeHat( false ); - Set64x64 = new ModelSet(); - Set64x64.Head = MakeHead( true ); - Set64x64.Torso = MakeTorso( true ); - Set64x64.LeftLeg = MakeLeftLeg( 16, 48, 0, 4/16f, true ); - Set64x64.RightLeg = MakeRightLeg( 0, 16, 0, 4/16f, true ); - Set64x64.LeftArm = MakeLeftArm( 32, 48, 4/16f, 8/16f, 4, true ); - Set64x64.RightArm = MakeRightArm( 40, 16, 4/16f, 8/16f, 4, true ); - Set64x64.Hat = MakeHat( true ); - - Set64x64Slim = new ModelSet(); - Set64x64Slim.Head = Set64x64.Head; - Set64x64Slim.Torso = Set64x64.Torso; - Set64x64Slim.LeftLeg = Set64x64.LeftLeg; - Set64x64Slim.RightLeg = Set64x64.RightLeg; - Set64x64Slim.LeftArm = MakeLeftArm( 32, 48, 4/16f, 7/16f, 3, true ); - Set64x64Slim.RightArm = MakeRightArm( 40, 16, 4/16f, 7/16f, 3, true ); - Set64x64Slim.Hat = Set64x64.Hat; + SetSlim = new ModelSet(); + SetSlim.Head = Set.Head; + SetSlim.Torso = Set.Torso; + SetSlim.LeftLeg = Set.LeftLeg; + SetSlim.RightLeg = Set.RightLeg; + SetSlim.LeftArm = MakeLeftArm( 32, 48, 4/16f, 7/16f, 3, true ); + SetSlim.RightArm = MakeRightArm( 40, 16, 4/16f, 7/16f, 3, true ); + SetSlim.Hat = Set.Hat; } ModelPart MakeLeftArm( int x, int y, float x1, float x2, int width, bool _64x64 ) { @@ -89,9 +80,8 @@ namespace ClassicalSharp.Model { graphics.BindTexture( texId ); SkinType skinType = p.SkinType; - model = Set64x32; - if( skinType == SkinType.Type64x64 ) model = Set64x64; - else if( skinType == SkinType.Type64x64Slim ) model = Set64x64Slim; + _64x64 = skinType != SkinType.Type64x32; + model = skinType == SkinType.Type64x64Slim ? SetSlim : Set; DrawRotate( 0, 24/16f, 0, -p.PitchRadians, 0, 0, model.Head ); DrawPart( model.Torso ); diff --git a/ClassicalSharp/Model/SheepModel.cs b/ClassicalSharp/Model/SheepModel.cs index 33afa5051..02d2626e5 100644 --- a/ClassicalSharp/Model/SheepModel.cs +++ b/ClassicalSharp/Model/SheepModel.cs @@ -10,7 +10,7 @@ namespace ClassicalSharp.Model { public bool Fur = true; public SheepModel( Game window ) : base( window ) { - vertices = new VertexPos3fTex2fCol4b[partVertices * 6 * ( Fur ? 2 : 1 )]; + vertices = new ModelVertex[partVertices * 6 * ( Fur ? 2 : 1 )]; Head = MakeHead(); Torso = MakeTorso(); LeftLegFront = MakeLeg( -5/16f, -1/16f, -7/16f, -3/16f ); diff --git a/ClassicalSharp/Model/SkeletonModel.cs b/ClassicalSharp/Model/SkeletonModel.cs index 0a9e7045e..5314c82e7 100644 --- a/ClassicalSharp/Model/SkeletonModel.cs +++ b/ClassicalSharp/Model/SkeletonModel.cs @@ -6,7 +6,7 @@ namespace ClassicalSharp.Model { public class SkeletonModel : IModel { public SkeletonModel( Game window ) : base( window ) { - vertices = new VertexPos3fTex2fCol4b[partVertices * 6]; + vertices = new ModelVertex[partVertices * 6]; Head = MakeHead(); Torso = MakeTorso(); LeftLeg = MakeLeftLeg( 3/16f, 1/16f ); diff --git a/ClassicalSharp/Model/SpiderModel.cs b/ClassicalSharp/Model/SpiderModel.cs index 8e8ae1375..f308011d9 100644 --- a/ClassicalSharp/Model/SpiderModel.cs +++ b/ClassicalSharp/Model/SpiderModel.cs @@ -6,7 +6,7 @@ namespace ClassicalSharp.Model { public class SpiderModel : IModel { public SpiderModel( Game window ) : base( window ) { - vertices = new VertexPos3fTex2fCol4b[partVertices * 5]; + vertices = new ModelVertex[partVertices * 5]; Head = MakeHead(); Link = MakeLink(); End = MakeEnd(); diff --git a/ClassicalSharp/Model/ZombieModel.cs b/ClassicalSharp/Model/ZombieModel.cs index 7c77d907a..b5bb9b461 100644 --- a/ClassicalSharp/Model/ZombieModel.cs +++ b/ClassicalSharp/Model/ZombieModel.cs @@ -7,7 +7,7 @@ namespace ClassicalSharp.Model { public class ZombieModel : IModel { public ZombieModel( Game window ) : base( window ) { - vertices = new VertexPos3fTex2fCol4b[partVertices * 6]; + vertices = new ModelVertex[partVertices * 6]; Head = MakeHead(); Torso = MakeTorso(); LeftLeg = MakeLeftLeg( 4/16f, 0f );