From 4d4dca6de7310435968ef9e068d68ff87d1999bf Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 5 May 2015 18:58:09 +1000 Subject: [PATCH] More simplification of LocalPlayer. --- Entities/LocalPlayer.cs | 21 ++++++--------------- Entities/NetPlayer.cs | 9 +-------- Entities/Player.cs | 12 ++++++++++++ 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/Entities/LocalPlayer.cs b/Entities/LocalPlayer.cs index 4bc5853a6..e6b411aa7 100644 --- a/Entities/LocalPlayer.cs +++ b/Entities/LocalPlayer.cs @@ -72,25 +72,18 @@ namespace ClassicalSharp { if( Window.Map == null || Window.Map.IsNotLoaded ) return; map = Window.Map; - float xMoving, zMoving; + float xMoving = 0, zMoving = 0; lastPos = Position = nextPos; lastYaw = nextYaw; lastPitch = nextPitch; - HandleInput( out xMoving, out zMoving ); - UpdateState( xMoving, zMoving ); + HandleInput( ref xMoving, ref zMoving ); + UpdateVelocityYState(); PhysicsTick( xMoving, zMoving ); nextPos = Position; Position = lastPos; UpdateAnimState( lastPos, nextPos, delta ); if( renderer != null ) { - Bitmap bmp; - Window.AsyncDownloader.TryGetImage( "skin_" + SkinName, out bmp ); - if( bmp != null ) { - Window.Graphics.DeleteTexture( renderer.TextureId ); - renderer.TextureId = Window.Graphics.LoadTexture( bmp ); - SkinType = Utils.GetSkinType( bmp ); - bmp.Dispose(); - } + CheckSkin(); } } @@ -104,9 +97,7 @@ namespace ClassicalSharp { renderer.Render( deltaTime ); } - void HandleInput( out float xMoving, out float zMoving ) { - xMoving = 0; - zMoving = 0; + void HandleInput( ref float xMoving, ref float zMoving ) { if( Window.ScreenLockedInput ) { jumping = speeding = flyingUp = flyingDown = false; } else { @@ -122,7 +113,7 @@ namespace ClassicalSharp { } } - void UpdateState( float xMoving, float zMoving ) { + void UpdateVelocityYState() { if( flying || noClip ) { Velocity.Y = 0; // eliminate the effect of gravity float vel = noClip ? 0.24f : 0.06f; diff --git a/Entities/NetPlayer.cs b/Entities/NetPlayer.cs index a92cdf944..38f67afb1 100644 --- a/Entities/NetPlayer.cs +++ b/Entities/NetPlayer.cs @@ -64,14 +64,7 @@ namespace ClassicalSharp { List states = new List(); State newState, oldState; public override void Tick( double delta ) { - Bitmap bmp; - Window.AsyncDownloader.TryGetImage( "skin_" + SkinName, out bmp ); - if( bmp != null ) { - Window.Graphics.DeleteTexture( renderer.TextureId ); - renderer.TextureId = Window.Graphics.LoadTexture( bmp ); - SkinType = Utils.GetSkinType( bmp ); - bmp.Dispose(); - } + CheckSkin(); tickCount++; UpdateCurrentState(); UpdateAnimState( oldState.pos, newState.pos, delta ); diff --git a/Entities/Player.cs b/Entities/Player.cs index 837cca7ec..4320d6e29 100644 --- a/Entities/Player.cs +++ b/Entities/Player.cs @@ -1,4 +1,5 @@ using System; +using System.Drawing; using OpenTK; using ClassicalSharp.Model; using ClassicalSharp.Renderers; @@ -106,6 +107,17 @@ namespace ClassicalSharp { leftArmZRot = -idleZRot; } + protected void CheckSkin() { + Bitmap bmp; + Window.AsyncDownloader.TryGetImage( "skin_" + SkinName, out bmp ); + if( bmp != null ) { + Window.Graphics.DeleteTexture( renderer.TextureId ); + renderer.TextureId = Window.Graphics.LoadTexture( bmp ); + SkinType = Utils.GetSkinType( bmp ); + bmp.Dispose(); + } + } + public void SetModel( string modelName ) { ModelName = modelName; Model = Window.ModelCache.GetModel( ModelName );