diff --git a/ClassicalSharp/Map/ChunkMeshBuilder.cs b/ClassicalSharp/Map/ChunkMeshBuilder.cs index 2cefe4fb5..20c964a54 100644 --- a/ClassicalSharp/Map/ChunkMeshBuilder.cs +++ b/ClassicalSharp/Map/ChunkMeshBuilder.cs @@ -190,7 +190,7 @@ namespace ClassicalSharp { countIndex += TileSide.Top; if( counts[countIndex] != 0 ) { X = x; Y = y; Z = z; - AddSpriteVertices( tile, 1 ); + AddSpriteVertices( tile ); counts[countIndex] = 1; } } else { diff --git a/ClassicalSharp/Map/ChunkMeshBuilderTex2Col4.cs b/ClassicalSharp/Map/ChunkMeshBuilderTex2Col4.cs index 9a52cb12a..9006f86ec 100644 --- a/ClassicalSharp/Map/ChunkMeshBuilderTex2Col4.cs +++ b/ClassicalSharp/Map/ChunkMeshBuilderTex2Col4.cs @@ -45,8 +45,9 @@ namespace ClassicalSharp { public void ExpandToCapacity() { vCount = iCount / 6 * 4; - if( vertices == null || (vCount + 1) > vertices.Length ) { - vertices = new VertexPos3fTex2fCol4b[vCount + 1]; + if( vertices == null || (vCount + 2) > vertices.Length ) { + vertices = new VertexPos3fTex2fCol4b[vCount + 2]; + // ensure buffer is up to 64 bits aligned for last element } vIndex.left = spriteCount / 6 * 4; vIndex.right = vIndex.left + Count.left / 6 * 4; @@ -94,7 +95,7 @@ namespace ClassicalSharp { if( part.iCount == 0 ) return; ChunkPartInfo info; - info.VbId = graphics.CreateVb( part.vertices, VertexFormat.Pos3fTex2fCol4b, part.vCount + 1 ); + info.VbId = graphics.CreateVb( part.vertices, VertexFormat.Pos3fTex2fCol4b, part.vCount + 2 ); info.IndicesCount = part.iCount; info.leftCount = (ushort)part.Count.left; info.rightCount = (ushort)part.Count.right; info.frontCount = (ushort)part.Count.front; info.backCount = (ushort)part.Count.back; @@ -146,11 +147,11 @@ namespace ClassicalSharp { } } - void AddSpriteVertices( byte tile, int count ) { + void AddSpriteVertices( byte tile ) { int i = atlas.Get1DIndex( info.GetTextureLoc( tile, TileSide.Left ) ); DrawInfo part = drawInfoNormal[i]; - part.spriteCount += 6 + 6 * count; - part.iCount += 6 + 6 * count; + part.spriteCount += 6 * 4; + part.iCount += 6 * 4; } unsafe void AddVertices( byte tile, int count, int face ) { @@ -287,16 +288,28 @@ namespace ClassicalSharp { FastColour col = fullBright ? FastColour.White : (Y > map.heightmap[(Z * width) + X] ? map.Sunlight : map.Shadowlight); // Draw Z axis - part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 2.50f/16, Y, Z + 2.5f/16, u2, v2, col ); - part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 2.50f/16, Y + blockHeight, Z + 2.5f/16, u2, v1, col ); - part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 13.5f/16, Y + blockHeight, Z + 13.5f/16, u1, v1, col ); - part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 13.5f/16, Y, Z + 13.5f/16, u1, v2, col ); + part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 2.50f/16, Y, Z + 2.5f/16, u1, v2, col ); + part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 2.50f/16, Y + blockHeight, Z + 2.5f/16, u1, v1, col ); + part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 13.5f/16, Y + blockHeight, Z + 13.5f/16, u2, v1, col ); + part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 13.5f/16, Y, Z + 13.5f/16, u2, v2, col ); + // Draw Z axis mirrored + part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 13.5f/16, Y, Z + 13.5f/16, u1, v2, col ); + part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 13.5f/16, Y + blockHeight, Z + 13.5f/16, u1, v1, col ); + part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 2.50f/16, Y + blockHeight, Z + 2.5f/16, u2, v1, col ); + part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 2.50f/16, Y, Z + 2.5f/16, u2, v2, col ); + // Draw X axis - part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 2.50f/16, Y, Z + 13.5f/16, u1, v2, col ); - part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 2.50f/16, Y + blockHeight, Z + 13.5f/16, u1, v1, col ); - part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 13.5f/16, Y + blockHeight, Z + 2.5f/16, u2, v1, col ); + part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 2.50f/16, Y, Z + 13.5f/16, u2, v2, col ); + part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 2.50f/16, Y + blockHeight, Z + 13.5f/16, u2, v1, col ); + part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 13.5f/16, Y + blockHeight, Z + 2.5f/16, u1, v1, col ); + part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 13.5f/16, Y, Z + 2.5f/16, u1, v2, col ); + + // Draw X axis mirrored part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 13.5f/16, Y, Z + 2.5f/16, u2, v2, col ); + part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 13.5f/16, Y + blockHeight, Z + 2.5f/16, u2, v1, col ); + part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 2.50f/16, Y + blockHeight, Z + 13.5f/16, u1, v1, col ); + part.vertices[part.spriteIndex++] = new VertexPos3fTex2fCol4b( X + 2.50f/16, Y, Z + 13.5f/16, u1, v2, col ); } } } \ No newline at end of file diff --git a/ClassicalSharp/Rendering/MapRenderer.Rendering.cs b/ClassicalSharp/Rendering/MapRenderer.Rendering.cs index b4dc04a20..453c9b0a1 100644 --- a/ClassicalSharp/Rendering/MapRenderer.Rendering.cs +++ b/ClassicalSharp/Rendering/MapRenderer.Rendering.cs @@ -71,14 +71,16 @@ namespace ClassicalSharp { ChunkPartInfo part = info.NormalParts[batch]; if( part.IndicesCount == 0 ) continue; usedNormal[batch] = true; - if( part.IndicesCount > maxIndices ) { + if( part.IndicesCount > maxIndices ) DrawBigPart( info, ref part ); - } else { - DrawPart( info, ref part ); - } + else + DrawPart( info, ref part ); - if( part.spriteCount > 0 ) + if( part.spriteCount > 0 ) { + api.FaceCulling = true; api.DrawIndexedVb_TrisT2fC4b( part.spriteCount, 0 ); + api.FaceCulling = false; + } game.Vertices += part.IndicesCount; } } diff --git a/ClassicalSharp/Rendering/MapRenderer.cs b/ClassicalSharp/Rendering/MapRenderer.cs index 24d9b1ef4..1873ffb54 100644 --- a/ClassicalSharp/Rendering/MapRenderer.cs +++ b/ClassicalSharp/Rendering/MapRenderer.cs @@ -176,14 +176,13 @@ namespace ClassicalSharp { void CreateChunkCache() { int index = 0; - for( int z = 0; z < length; z += 16 ) { - for( int y = 0; y < height; y += 16 ) { - for( int x = 0; x < width; x += 16 ) { - chunks[index] = new ChunkInfo( x, y, z ); - unsortedChunks[index] = chunks[index]; - index++; - } - } + for( int z = 0; z < length; z += 16 ) + for( int y = 0; y < height; y += 16 ) + for( int x = 0; x < width; x += 16 ) + { + chunks[index] = new ChunkInfo( x, y, z ); + unsortedChunks[index] = chunks[index]; + index++; } } @@ -307,7 +306,7 @@ namespace ClassicalSharp { info.Visible = inRange && game.Culling.SphereInFrustum( info.CentreX, info.CentreY, info.CentreZ, 14 ); // 14 ~ sqrt(3 * 8^2) } - } + } } }