More simplification of LocalPlayer.

This commit is contained in:
UnknownShadow200 2015-05-05 18:58:09 +10:00
parent 8376a3b881
commit 4d4dca6de7
3 changed files with 19 additions and 23 deletions

View File

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

View File

@ -64,14 +64,7 @@ namespace ClassicalSharp {
List<State> states = new List<State>();
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 );

View File

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