Less popping in of chunks on fog border (Thanks MrGoober), also can press F8 to show a shadow above the block you are standing on. (Thanks MrGoober)

This commit is contained in:
UnknownShadow200 2016-02-05 00:10:01 +11:00
parent 88613a82ed
commit bfe9e287c6
7 changed files with 71 additions and 8 deletions

View File

@ -10,7 +10,7 @@ namespace ClassicalSharp {
/// <summary> Position the player's position is set to when the 'respawn' key binding is pressed. </summary>
public Vector3 SpawnPoint;
public float SpawnYaw, SpawnPitch;
/// <summary> The distance (in blocks) that players are allowed to
@ -21,6 +21,8 @@ namespace ClassicalSharp {
/// when the 'speeding' key binding is held down. </summary>
public float SpeedMultiplier = 10;
public bool ShowShadow = false;
public byte UserType;
/// <summary> Whether blocks that the player places that intersect themselves

View File

@ -13,6 +13,8 @@ namespace ClassicalSharp {
public override void Despawn() {
game.Graphics.DeleteTexture( ref PlayerTextureId );
game.Graphics.DeleteTexture( ref nameTex.ID );
if( shadowTex != -1 )
game.Graphics.DeleteTexture( ref shadowTex );
}
protected void InitRenderingData() {
@ -38,11 +40,64 @@ namespace ClassicalSharp {
Utils.CalcBillboardPoints( size, pos, ref game.View, out p111, out p121, out p212, out p222 );
api.texVerts[0] = new VertexPos3fTex2fCol4b( p111, nameTex.U1, nameTex.V2, col );
api.texVerts[1] = new VertexPos3fTex2fCol4b( p121, nameTex.U1, nameTex.V1, col );
api.texVerts[2] = new VertexPos3fTex2fCol4b( p222, nameTex.U2, nameTex.V1, col );
api.texVerts[2] = new VertexPos3fTex2fCol4b( p222, nameTex.U2, nameTex.V1, col );
api.texVerts[3] = new VertexPos3fTex2fCol4b( p212, nameTex.U2, nameTex.V2, col );
api.SetBatchFormat( VertexFormat.Pos3fTex2fCol4b );
api.UpdateDynamicIndexedVb( DrawMode.Triangles, api.texVb, api.texVerts, 4, 6 );
}
internal void DrawShadow( bool show ) {
int x = Utils.Floor( Position.X ), z = Utils.Floor( Position.Z );
if( !show || !game.Map.IsValidPos( x, 0, z ) || Position.Y < 0 ) return;
CheckShadowTexture();
BlockInfo info = game.BlockInfo;
game.Graphics.BindTexture( shadowTex );
int y = Math.Min( (int)Position.Y, game.Map.Height - 1 );
float shadowY = 0;
while( y >= 0 ) {
byte block = game.Map.GetBlock( x, y, z );
if( !(info.IsAir[block] || info.IsSprite[block]) ) {
shadowY = y + info.MaxBB[block].Y; break;
}
y--;
}
if( (Position.Y - y) <= 16 ) shadowY += 1/32f;
else if( (Position.Y - y) <= 32 ) shadowY += 1/16f;
else if( (Position.Y - y) <= 96 ) shadowY += 1/8f;
else shadowY += 1/4f;
VertexPos3fTex2fCol4b[] verts = game.Graphics.texVerts;
int vb = game.Graphics.texVb;
FastColour col = FastColour.White;
verts[0] = new VertexPos3fTex2fCol4b( x, shadowY, z, 0, 0, col );
verts[1] = new VertexPos3fTex2fCol4b( x + 1, shadowY, z, 1, 0, col );
verts[2] = new VertexPos3fTex2fCol4b( x + 1, shadowY, z + 1, 1, 1, col );
verts[3] = new VertexPos3fTex2fCol4b( x, shadowY, z + 1, 0, 1, col );
game.Graphics.UpdateDynamicIndexedVb( DrawMode.Triangles, vb, verts, 4, 6 );
}
int shadowTex = -1;
unsafe void CheckShadowTexture() {
if( shadowTex != -1 ) return;
const int size = 128, half = size / 2;
using( Bitmap bmp = new Bitmap( size, size ) )
using( FastBitmap fastBmp = new FastBitmap( bmp, true, false ) )
{
int inPix = new FastColour( 0, 0, 0, 200 ).ToArgb();
int outPix = inPix & 0xFFFFFF;
for( int y = 0; y < fastBmp.Height; y++ ) {
int* row = fastBmp.GetRowPtr( y );
for( int x = 0; x < fastBmp.Width; x++ ) {
double dist = (half - (x + 0.5)) * (half - (x + 0.5)) +
(half - (y + 0.5)) * (half - (y + 0.5));
row[x] = dist < half * half ? inPix : outPix;
}
}
shadowTex = game.Graphics.CreateTexture( fastBmp );
}
}
}
}

View File

@ -347,6 +347,8 @@ namespace ClassicalSharp {
game.SetNewScreen( new PauseScreen( game ) );
} else if( key == Keys[KeyBinding.OpenInventory] ) {
game.SetNewScreen( new BlockSelectScreen( game ) );
} else if( key == Key.F8 ) {
game.LocalPlayer.ShowShadow = !game.LocalPlayer.ShowShadow;
} else {
return false;
}

View File

@ -248,8 +248,8 @@ namespace ClassicalSharp.GraphicsAPI {
DeleteDynamicVb( texVb );
}
VertexPos3fCol4b[] quadVerts = new VertexPos3fCol4b[4];
int quadVb;
internal VertexPos3fCol4b[] quadVerts = new VertexPos3fCol4b[4];
internal int quadVb;
public virtual void Draw2DQuad( float x, float y, float width, float height, FastColour col ) {
quadVerts[0] = new VertexPos3fCol4b( x, y, 0, col );
quadVerts[1] = new VertexPos3fCol4b( x + width, y, 0, col );

View File

@ -54,8 +54,10 @@ namespace ClassicalSharp {
Vector3 camPos = game.CurrentCameraPos;
bool underWater = camPos.Y < game.Map.EdgeHeight;
graphics.AlphaBlending = true;
if( underWater )
if( underWater ) {
game.LocalPlayer.DrawShadow( game.LocalPlayer.ShowShadow );
game.WeatherRenderer.Render( deltaTime );
}
graphics.BindTexture( edgeTexId );
graphics.BindVb( edgesVb );
@ -65,8 +67,10 @@ namespace ClassicalSharp {
if( game.Map.EdgeBlock != Block.Air && camPos.Y >= yVisible )
graphics.DrawIndexedVb_TrisT2fC4b( edgesVertices * 6 / 4, 0 );
if( !underWater )
if( !underWater ) {
game.LocalPlayer.DrawShadow( game.LocalPlayer.ShowShadow );
game.WeatherRenderer.Render( deltaTime );
}
graphics.AlphaBlending = false;
graphics.Texturing = false;
graphics.AlphaTest = false;

View File

@ -256,7 +256,7 @@ namespace ClassicalSharp {
const double targetTime = (1.0 / 30) + 0.01;
void UpdateChunks( double deltaTime ) {
int chunkUpdates = 0;
int viewDist = game.ViewDistance < 16 ? 16 : game.ViewDistance;
int viewDist = Utils.AdjViewDist( game.ViewDistance < 16 ? 16 : game.ViewDistance );
int adjViewDistSqr = (viewDist + 24) * (viewDist + 24);
chunksTarget += deltaTime < targetTime ? 1 : -1; // build more chunks if 30 FPS or over, otherwise slowdown.
Utils.Clamp( ref chunksTarget, 4, 12 );

View File

@ -29,7 +29,7 @@ namespace ClassicalSharp {
public void Render( double deltaTime ) {
Weather weather = map.Weather;
if( weather == Weather.Sunny ) return;
if( heightmap == null ) InitHeightmap();
if( heightmap == null ) InitHeightmap();
graphics.BindTexture( weather == Weather.Rainy ? game.RainTexId : game.SnowTexId );
Vector3 camPos = game.CurrentCameraPos;