mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 19:15:14 -04:00
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:
parent
88613a82ed
commit
bfe9e287c6
@ -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
|
||||
|
@ -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() {
|
||||
@ -44,5 +46,58 @@ namespace ClassicalSharp {
|
||||
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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -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 );
|
||||
|
@ -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;
|
||||
|
@ -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 );
|
||||
|
Loading…
x
Reference in New Issue
Block a user