Make selected block lines smaller (Thanks Coliop).

This commit is contained in:
UnknownShadow200 2016-06-08 13:54:46 +10:00
parent 041bbc5f5d
commit d06110f571
4 changed files with 58 additions and 18 deletions

View File

@ -42,7 +42,7 @@
<DebugType>None</DebugType>
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE;</DefineConstants>
<DefineConstants>TRACE;__MonoCS__</DefineConstants>
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath>
<StartAction>Project</StartAction>
</PropertyGroup>

View File

@ -326,10 +326,13 @@ namespace ClassicalSharp {
ParticleManager.Render( delta, t );
Camera.GetPickedBlock( SelectedPos ); // TODO: only pick when necessary
EnvRenderer.Render( delta );
EnvRenderer.Render( delta );
MapRenderer.Render( delta );
if( SelectedPos.Valid && !HideGui )
Picking.Render( delta, SelectedPos );
MapRenderer.Render( delta );
MapRenderer.RenderTranslucent( delta );
Entities.DrawShadows();
SelectionManager.Render( delta );
Entities.RenderHoveredNames( Graphics, delta, t );

View File

@ -68,18 +68,20 @@ namespace ClassicalSharp.Renderers {
public void Render( double deltaTime ) {
if( chunks == null ) return;
ChunkSorter.UpdateSortOrder( game, updater );
updater.UpdateChunks( deltaTime );
RenderNormal( deltaTime );
updater.UpdateChunks( deltaTime );
RenderNormalChunks( deltaTime );
}
public void RenderTranslucent( double deltaTime ) {
if( chunks == null ) return;
game.MapBordersRenderer.Render( deltaTime );
RenderTranslucent( deltaTime );
game.Entities.DrawShadows();
RenderTranslucentChunks( deltaTime );
}
// Render solid and fully transparent to fill depth buffer.
// These blocks are treated as having an alpha value of either none or full.
void RenderNormal( double deltaTime ) {
void RenderNormalChunks( double deltaTime ) {
int[] texIds = game.TerrainAtlas1D.TexIds;
api.SetBatchFormat( VertexFormat.P3fT2fC4b );
api.Texturing = true;
@ -120,7 +122,7 @@ namespace ClassicalSharp.Renderers {
}
// Render translucent(liquid) blocks. These 'blend' into other blocks.
void RenderTranslucent( double deltaTime ) {
void RenderTranslucentChunks( double deltaTime ) {
// First fill depth buffer
int[] texIds = game.TerrainAtlas1D.TexIds;

View File

@ -17,27 +17,36 @@ namespace ClassicalSharp.Renderers {
this.game = game;
}
public void Ready( Game game ) { }
public void Ready( Game game ) { }
public void Reset( Game game ) { }
public void OnNewMap( Game game ) { }
public void OnNewMapLoaded( Game game ) { }
FastColour col = FastColour.Black;
FastColour col = new FastColour( 0, 0, 0, 150 );
int index;
const int verticesCount = 16 * 6;
VertexP3fC4b[] vertices = new VertexP3fC4b[verticesCount];
const float offset = 0.01f;
public void Render( double delta, PickedPos pickedPos ) {
index = 0;
Vector3 camPos = game.CurrentCameraPos;
float dist = (camPos - pickedPos.Min).LengthSquared;
float size = dist < 12 * 12 ? 1/64f : 1/32f;
if( dist > 32 * 32 ) size = 1/16f;
float offset = dist < 12 * 12 ? 0.001f : 0.01f;
Vector3 p1 = pickedPos.Min - new Vector3( offset, offset, offset );
Vector3 p2 = pickedPos.Max + new Vector3( offset, offset, offset );
graphics.AlphaBlending = true;
if( dist < 12 * 12 ) {
DrawSimpleLines( p1, p2 );
} else {
float size = dist > 32 * 32 ? 1/16f : 1/32f;
DrawThickLines( p1, p2, size );
}
graphics.AlphaBlending = false;
}
void DrawThickLines( Vector3 p1, Vector3 p2, float size ) {
// bottom face
YQuad( p1.Y, p1.X, p1.Z, p1.X + size, p2.Z );
YQuad( p1.Y, p2.X, p1.Z, p2.X - size, p2.Z );
@ -70,7 +79,28 @@ namespace ClassicalSharp.Renderers {
ZQuad( p2.Z, p1.X, p2.Y, p2.X, p2.Y - size );
graphics.SetBatchFormat( VertexFormat.P3fC4b );
graphics.UpdateDynamicIndexedVb( DrawMode.Triangles, vb, vertices, verticesCount, verticesCount * 6 / 4 );
graphics.UpdateDynamicIndexedVb( DrawMode.Triangles, vb, vertices, index, index * 6 / 4 );
}
void DrawSimpleLines( Vector3 p1, Vector3 p2 ) {
// bottom face
Line( p1.X, p1.Y, p1.Z, p2.X, p1.Y, p1.Z );
Line( p1.X, p1.Y, p2.Z, p2.X, p1.Y, p2.Z );
Line( p1.X, p1.Y, p1.Z, p1.X, p1.Y, p2.Z );
Line( p2.X, p1.Y, p1.Z, p2.X, p1.Y, p2.Z );
// top face
Line( p1.X, p2.Y, p1.Z, p2.X, p2.Y, p1.Z );
Line( p1.X, p2.Y, p2.Z, p2.X, p2.Y, p2.Z );
Line( p1.X, p2.Y, p1.Z, p1.X, p2.Y, p2.Z );
Line( p2.X, p2.Y, p1.Z, p2.X, p2.Y, p2.Z );
// side faces
Line( p1.X, p1.Y, p1.Z, p1.X, p2.Y, p1.Z );
Line( p1.X, p1.Y, p2.Z, p1.X, p2.Y, p2.Z );
Line( p2.X, p1.Y, p1.Z, p2.X, p2.Y, p1.Z );
Line( p2.X, p1.Y, p2.Z, p2.X, p2.Y, p2.Z );
graphics.SetBatchFormat( VertexFormat.P3fC4b );
graphics.UpdateDynamicVb( DrawMode.Lines, vb, vertices, index );
}
public void Dispose() {
@ -79,14 +109,14 @@ namespace ClassicalSharp.Renderers {
void XQuad( float x, float z1, float y1, float z2, float y2 ) {
vertices[index++] = new VertexP3fC4b( x, y1, z1, col );
vertices[index++] = new VertexP3fC4b( x, y2, z1, col );
vertices[index++] = new VertexP3fC4b( x, y2, z1, col );
vertices[index++] = new VertexP3fC4b( x, y2, z2, col );
vertices[index++] = new VertexP3fC4b( x, y1, z2, col );
}
void ZQuad( float z, float x1, float y1, float x2, float y2 ) {
vertices[index++] = new VertexP3fC4b( x1, y1, z, col );
vertices[index++] = new VertexP3fC4b( x1, y2, z, col );
vertices[index++] = new VertexP3fC4b( x1, y2, z, col );
vertices[index++] = new VertexP3fC4b( x2, y2, z, col );
vertices[index++] = new VertexP3fC4b( x2, y1, z, col );
}
@ -97,5 +127,10 @@ namespace ClassicalSharp.Renderers {
vertices[index++] = new VertexP3fC4b( x2, y, z2, col );
vertices[index++] = new VertexP3fC4b( x2, y, z1, col );
}
void Line( float x1, float y1, float z1, float x2, float y2, float z2 ) {
vertices[index++] = new VertexP3fC4b( x1, y1, z1, col );
vertices[index++] = new VertexP3fC4b( x2, y2, z2, col );
}
}
}