void RebuildSides(int groundLevel, int axisSize) { sidesVertices = 0; foreach (Rectangle rec in rects) { sidesVertices += Utils.CountVertices(rec.Width, rec.Height, axisSize); // YQuads outside } sidesVertices += Utils.CountVertices(map.Width, map.Length, axisSize); // YQuads beneath map sidesVertices += 2 * Utils.CountVertices(map.Width, Math.Abs(groundLevel), axisSize); // ZQuads sidesVertices += 2 * Utils.CountVertices(map.Length, Math.Abs(groundLevel), axisSize); // XQuads VertexPos3fTex2fCol4b *vertices = stackalloc VertexPos3fTex2fCol4b[sidesVertices]; IntPtr ptr = (IntPtr)vertices; fullColSides = game.BlockInfo.FullBright[(byte)game.Map.SidesBlock]; FastColour col = fullColSides ? FastColour.White : map.Shadowlight; foreach (Rectangle rec in rects) { DrawY(rec.X, rec.Y, rec.X + rec.Width, rec.Y + rec.Height, groundLevel, axisSize, col, ref vertices); } // Work properly for when ground level is below 0 int y1 = 0, y2 = groundLevel; if (groundLevel < 0) { y1 = groundLevel; y2 = 0; } DrawY(0, 0, map.Width, map.Length, 0, axisSize, col, ref vertices); DrawZ(0, 0, map.Width, y1, y2, axisSize, col, ref vertices); DrawZ(map.Length, 0, map.Width, y1, y2, axisSize, col, ref vertices); DrawX(0, 0, map.Length, y1, y2, axisSize, col, ref vertices); DrawX(map.Width, 0, map.Length, y1, y2, axisSize, col, ref vertices); sidesVb = graphics.CreateVb(ptr, VertexFormat.Pos3fTex2fCol4b, sidesVertices); }
void RebuildEdges(int waterLevel, int axisSize) { edgesVertices = 0; foreach (Rectangle rec in rects) { edgesVertices += Utils.CountVertices(rec.Width, rec.Height, axisSize); // YPlanes outside } VertexPos3fTex2fCol4b *vertices = stackalloc VertexPos3fTex2fCol4b[edgesVertices]; IntPtr ptr = (IntPtr)vertices; fullColEdge = game.BlockInfo.FullBright[(byte)game.Map.EdgeBlock]; FastColour col = fullColEdge ? FastColour.White : map.Sunlight; foreach (Rectangle rec in rects) { DrawY(rec.X, rec.Y, rec.X + rec.Width, rec.Y + rec.Height, waterLevel, axisSize, col, ref vertices); } edgesVb = graphics.CreateVb(ptr, VertexFormat.Pos3fTex2fCol4b, edgesVertices); }
void DrawY(int x1, int z1, int x2, int z2, int y, int axisSize, FastColour col, ref VertexPos3fTex2fCol4b *vertices) { int endX = x2, endZ = z2, startZ = z1; for ( ; x1 < endX; x1 += axisSize) { x2 = x1 + axisSize; if (x2 > endX) { x2 = endX; } z1 = startZ; for ( ; z1 < endZ; z1 += axisSize) { z2 = z1 + axisSize; if (z2 > endZ) { z2 = endZ; } TextureRec rec = new TextureRec(0, 0, x2 - x1, z2 - z1); * vertices++ = new VertexPos3fTex2fCol4b(x1, y, z1, rec.U1, rec.V1, col); * vertices++ = new VertexPos3fTex2fCol4b(x1, y, z2, rec.U1, rec.V2, col); * vertices++ = new VertexPos3fTex2fCol4b(x2, y, z2, rec.U2, rec.V2, col); * vertices++ = new VertexPos3fTex2fCol4b(x2, y, z1, rec.U2, rec.V1, col); } } }
void DrawZ(int z, int x1, int x2, int y1, int y2, int axisSize, FastColour col, ref VertexPos3fTex2fCol4b *vertices) { int endX = x2, endY = y2, startY = y1; for ( ; x1 < endX; x1 += axisSize) { x2 = x1 + axisSize; if (x2 > endX) { x2 = endX; } y1 = startY; for ( ; y1 < endY; y1 += axisSize) { y2 = y1 + axisSize; if (y2 > endY) { y2 = endY; } TextureRec rec = new TextureRec(0, 0, x2 - x1, y2 - y1); * vertices++ = new VertexPos3fTex2fCol4b(x1, y1, z, rec.U1, rec.V2, col); * vertices++ = new VertexPos3fTex2fCol4b(x1, y2, z, rec.U1, rec.V1, col); * vertices++ = new VertexPos3fTex2fCol4b(x2, y2, z, rec.U2, rec.V1, col); * vertices++ = new VertexPos3fTex2fCol4b(x2, y1, z, rec.U2, rec.V2, col); } } }
void DrawX(int x, int z1, int z2, int y1, int y2, int axisSize, FastColour col, ref VertexPos3fTex2fCol4b *vertices) { int endZ = z2, endY = y2, startY = y1; for ( ; z1 < endZ; z1 += axisSize) { z2 = z1 + axisSize; if (z2 > endZ) { z2 = endZ; } y1 = startY; for ( ; y1 < endY; y1 += axisSize) { y2 = y1 + axisSize; if (y2 > endY) { y2 = endY; } TextureRec rec = new TextureRec(0, 0, z2 - z1, y2 - y1); * vertices++ = new VertexPos3fTex2fCol4b(x, y1, z1, rec.U1, rec.V2, col); * vertices++ = new VertexPos3fTex2fCol4b(x, y2, z1, rec.U1, rec.V1, col); * vertices++ = new VertexPos3fTex2fCol4b(x, y2, z2, rec.U2, rec.V1, col); * vertices++ = new VertexPos3fTex2fCol4b(x, y1, z2, rec.U2, rec.V2, col); } } }