Implement sprite mirroring, closes #56.

This commit is contained in:
UnknownShadow200 2016-02-29 18:11:37 +11:00
parent 672ebf696d
commit ddc38805b0
4 changed files with 42 additions and 28 deletions

View File

@ -190,7 +190,7 @@ namespace ClassicalSharp {
countIndex += TileSide.Top; countIndex += TileSide.Top;
if( counts[countIndex] != 0 ) { if( counts[countIndex] != 0 ) {
X = x; Y = y; Z = z; X = x; Y = y; Z = z;
AddSpriteVertices( tile, 1 ); AddSpriteVertices( tile );
counts[countIndex] = 1; counts[countIndex] = 1;
} }
} else { } else {

View File

@ -45,8 +45,9 @@ namespace ClassicalSharp {
public void ExpandToCapacity() { public void ExpandToCapacity() {
vCount = iCount / 6 * 4; vCount = iCount / 6 * 4;
if( vertices == null || (vCount + 1) > vertices.Length ) { if( vertices == null || (vCount + 2) > vertices.Length ) {
vertices = new VertexPos3fTex2fCol4b[vCount + 1]; vertices = new VertexPos3fTex2fCol4b[vCount + 2];
// ensure buffer is up to 64 bits aligned for last element
} }
vIndex.left = spriteCount / 6 * 4; vIndex.left = spriteCount / 6 * 4;
vIndex.right = vIndex.left + Count.left / 6 * 4; vIndex.right = vIndex.left + Count.left / 6 * 4;
@ -94,7 +95,7 @@ namespace ClassicalSharp {
if( part.iCount == 0 ) return; if( part.iCount == 0 ) return;
ChunkPartInfo info; 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.IndicesCount = part.iCount;
info.leftCount = (ushort)part.Count.left; info.rightCount = (ushort)part.Count.right; info.leftCount = (ushort)part.Count.left; info.rightCount = (ushort)part.Count.right;
info.frontCount = (ushort)part.Count.front; info.backCount = (ushort)part.Count.back; 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 ) ); int i = atlas.Get1DIndex( info.GetTextureLoc( tile, TileSide.Left ) );
DrawInfo part = drawInfoNormal[i]; DrawInfo part = drawInfoNormal[i];
part.spriteCount += 6 + 6 * count; part.spriteCount += 6 * 4;
part.iCount += 6 + 6 * count; part.iCount += 6 * 4;
} }
unsafe void AddVertices( byte tile, int count, int face ) { 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); FastColour col = fullBright ? FastColour.White : (Y > map.heightmap[(Z * width) + X] ? map.Sunlight : map.Shadowlight);
// Draw Z axis // 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, Z + 2.5f/16, u1, 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 + 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, 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, 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 // 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, Z + 13.5f/16, u2, 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 + 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, 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, 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 );
} }
} }
} }

View File

@ -71,14 +71,16 @@ namespace ClassicalSharp {
ChunkPartInfo part = info.NormalParts[batch]; ChunkPartInfo part = info.NormalParts[batch];
if( part.IndicesCount == 0 ) continue; if( part.IndicesCount == 0 ) continue;
usedNormal[batch] = true; usedNormal[batch] = true;
if( part.IndicesCount > maxIndices ) { if( part.IndicesCount > maxIndices )
DrawBigPart( info, ref part ); DrawBigPart( info, ref part );
} else { else
DrawPart( info, ref part ); DrawPart( info, ref part );
}
if( part.spriteCount > 0 ) if( part.spriteCount > 0 ) {
api.FaceCulling = true;
api.DrawIndexedVb_TrisT2fC4b( part.spriteCount, 0 ); api.DrawIndexedVb_TrisT2fC4b( part.spriteCount, 0 );
api.FaceCulling = false;
}
game.Vertices += part.IndicesCount; game.Vertices += part.IndicesCount;
} }
} }

View File

@ -176,14 +176,13 @@ namespace ClassicalSharp {
void CreateChunkCache() { void CreateChunkCache() {
int index = 0; int index = 0;
for( int z = 0; z < length; z += 16 ) { for( int z = 0; z < length; z += 16 )
for( int y = 0; y < height; y += 16 ) { for( int y = 0; y < height; y += 16 )
for( int x = 0; x < width; x += 16 ) { for( int x = 0; x < width; x += 16 )
chunks[index] = new ChunkInfo( x, y, z ); {
unsortedChunks[index] = chunks[index]; chunks[index] = new ChunkInfo( x, y, z );
index++; unsortedChunks[index] = chunks[index];
} index++;
}
} }
} }