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 RebuildSides(int y, int axisSize) { BlockID block = game.World.Env.SidesBlock; sidesVertices = 0; if (BlockInfo.Draw[block] == DrawType.Gas) { return; } for (int i = 0; i < rects.Length; i++) { Rectangle r = rects[i]; sidesVertices += Utils.CountVertices(r.Width, r.Height, axisSize); // YQuads outside } sidesVertices += Utils.CountVertices(map.Width, map.Length, axisSize); // YQuads beneath map sidesVertices += 2 * Utils.CountVertices(map.Width, Math.Abs(y), axisSize); // ZQuads sidesVertices += 2 * Utils.CountVertices(map.Length, Math.Abs(y), axisSize); // XQuads VertexP3fT2fC4b[] v = new VertexP3fT2fC4b[sidesVertices]; int index = 0; fullBrightSides = BlockInfo.FullBright[block]; int col = fullBrightSides ? FastColour.WhitePacked : map.Env.Shadow; if (BlockInfo.Tinted[block]) { col = Utils.Tint(col, BlockInfo.FogColour[block]); } for (int i = 0; i < rects.Length; i++) { Rectangle r = rects[i]; DrawY(r.X, r.Y, r.X + r.Width, r.Y + r.Height, y, axisSize, col, 0, YOffset(block), v, ref index); } // Work properly for when ground level is below 0 int y1 = 0, y2 = y; if (y < 0) { y1 = y; y2 = 0; } DrawY(0, 0, map.Width, map.Length, 0, axisSize, col, 0, 0, v, ref index); DrawZ(0, 0, map.Width, y1, y2, axisSize, col, v, ref index); DrawZ(map.Length, 0, map.Width, y1, y2, axisSize, col, v, ref index); DrawX(0, 0, map.Length, y1, y2, axisSize, col, v, ref index); DrawX(map.Width, 0, map.Length, y1, y2, axisSize, col, v, ref index); fixed(VertexP3fT2fC4b *ptr = v) { sidesVb = gfx.CreateVb((IntPtr)ptr, VertexFormat.P3fT2fC4b, sidesVertices); } }
void SetPartInfo(DrawInfo part, int i, ref ChunkPartInfo[] parts) { if (part.iCount == 0) { return; } ChunkPartInfo info; int vertCount = (part.iCount / 6 * 4) + 2; info.VbId = gfx.CreateVb(part.vertices, VertexFormat.P3fT2fC4b, vertCount); info.IndicesCount = part.iCount; info.LeftCount = (ushort)part.vCount[Side.Left]; info.RightCount = (ushort)part.vCount[Side.Right]; info.FrontCount = (ushort)part.vCount[Side.Front]; info.BackCount = (ushort)part.vCount[Side.Back]; info.BottomCount = (ushort)part.vCount[Side.Bottom]; info.TopCount = (ushort)part.vCount[Side.Top]; info.SpriteCount = part.spriteCount; info.LeftIndex = info.SpriteCount; info.RightIndex = info.LeftIndex + info.LeftCount; info.FrontIndex = info.RightIndex + info.RightCount; info.BackIndex = info.FrontIndex + info.FrontCount; info.BottomIndex = info.BackIndex + info.BackCount; info.TopIndex = info.BottomIndex + info.BottomCount; // Lazy initalize part arrays so we can save time in MapRenderer for chunks that only contain 1 or 2 part types. if (parts == null) { parts = new ChunkPartInfo[arraysCount]; } parts[i] = info; }
public SelectionBox( Vector3I start, Vector3I end, FastColour col, IGraphicsApi graphics ) { Graphics = graphics; Min = Vector3I.Min( start, end ); Max = Vector3I.Max( start, end ); int index = 0; Vector3 p1 = (Vector3)Min + new Vector3( 1/16f, 1/16f, 1/16f ); Vector3 p2 = (Vector3)Max - new Vector3( 1/16f, 1/16f, 1/16f ); YQuad( ref index, p1.X, p1.Z, p2.X, p2.Z, p1.Y, col ); // bottom YQuad( ref index, p1.X, p1.Z, p2.X, p2.Z, p2.Y, col ); // top XQuad( ref index, p1.X, p2.X, p1.Y, p2.Y, p1.Z, col ); // sides XQuad( ref index, p1.X, p2.X, p1.Y, p2.Y, p2.Z, col ); ZQuad( ref index, p1.Z, p2.Z, p1.Y, p2.Y, p1.X, col ); ZQuad( ref index, p1.Z, p2.Z, p1.Y, p2.Y, p2.X, col ); col = new FastColour( (byte)~col.R, (byte)~col.G, (byte)~col.B ); // bottom face Line( ref index, p1.X, p1.Y, p1.Z, p2.X, p1.Y, p1.Z, col ); Line( ref index, p2.X, p1.Y, p1.Z, p2.X, p1.Y, p2.Z, col ); Line( ref index, p2.X, p1.Y, p2.Z, p1.X, p1.Y, p2.Z, col ); Line( ref index, p1.X, p1.Y, p2.Z, p1.X, p1.Y, p1.Z, col ); // top face Line( ref index, p1.X, p2.Y, p1.Z, p2.X, p2.Y, p1.Z, col ); Line( ref index, p2.X, p2.Y, p1.Z, p2.X, p2.Y, p2.Z, col ); Line( ref index, p2.X, p2.Y, p2.Z, p1.X, p2.Y, p2.Z, col ); Line( ref index, p1.X, p2.Y, p2.Z, p1.X, p2.Y, p1.Z, col ); // side faces Line( ref index, p1.X, p1.Y, p1.Z, p1.X, p2.Y, p1.Z, col ); Line( ref index, p2.X, p1.Y, p1.Z, p2.X, p2.Y, p1.Z, col ); Line( ref index, p2.X, p1.Y, p2.Z, p2.X, p2.Y, p2.Z, col ); Line( ref index, p1.X, p1.Y, p2.Z, p1.X, p2.Y, p2.Z, col ); Vb = Graphics.CreateVb( vertices, VertexFormat.Pos3fCol4b, VerticesCount + LineVerticesCount ); }
void SetPartInfo(DrawInfo part, int i, ref ChunkPartInfo[] parts) { int vertCount = part.VerticesCount(); if (vertCount == 0) { return; } ChunkPartInfo info; fixed(VertexP3fT2fC4b *ptr = part.vertices) { // add an extra element to fix crashing on some GPUs info.VbId = gfx.CreateVb((IntPtr)ptr, VertexFormat.P3fT2fC4b, vertCount + 1); } info.VerticesCount = vertCount; info.LeftCount = (ushort)part.vCount[Side.Left]; info.RightCount = (ushort)part.vCount[Side.Right]; info.FrontCount = (ushort)part.vCount[Side.Front]; info.BackCount = (ushort)part.vCount[Side.Back]; info.BottomCount = (ushort)part.vCount[Side.Bottom]; info.TopCount = (ushort)part.vCount[Side.Top]; info.SpriteCount = part.spriteCount; // Lazy initalize part arrays so we can save time in MapRenderer for chunks that only contain 1 or 2 part types. if (parts == null) { parts = new ChunkPartInfo[arraysCount]; } parts[i] = info; }
void RebuildSides(int y, int axisSize) { float yOffset = 0; byte block = game.World.Env.EdgeBlock; if (game.BlockInfo.IsLiquid[block]) { yOffset = -1.5f / 16; } sidesVertices = 0; foreach (Rectangle r in rects) { sidesVertices += Utils.CountVertices(r.Width, r.Height, axisSize); // YQuads outside } sidesVertices += Utils.CountVertices(map.Width, map.Length, axisSize); // YQuads beneath map sidesVertices += 2 * Utils.CountVertices(map.Width, Math.Abs(y), axisSize); // ZQuads sidesVertices += 2 * Utils.CountVertices(map.Length, Math.Abs(y), axisSize); // XQuads VertexP3fT2fC4b *v = stackalloc VertexP3fT2fC4b[sidesVertices]; IntPtr ptr = (IntPtr)v; fullColSides = game.BlockInfo.FullBright[block]; FastColour col = fullColSides ? FastColour.White : map.Env.Shadowlight; foreach (Rectangle r in rects) { DrawY(r.X, r.Y, r.X + r.Width, r.Y + r.Height, y, axisSize, col, 0, yOffset, ref v); } // Work properly for when ground level is below 0 int y1 = 0, y2 = y; if (y < 0) { y1 = y; y2 = 0; } DrawY(0, 0, map.Width, map.Length, 0, axisSize, col, 0, 0, ref v); DrawZ(0, 0, map.Width, y1, y2, axisSize, col, ref v); DrawZ(map.Length, 0, map.Width, y1, y2, axisSize, col, ref v); DrawX(0, 0, map.Length, y1, y2, axisSize, col, ref v); DrawX(map.Width, 0, map.Length, y1, y2, axisSize, col, ref v); sidesVb = graphics.CreateVb(ptr, VertexFormat.P3fT2fC4b, sidesVertices); }
void RebuildSides(int y, int axisSize) { byte block = game.World.Env.SidesBlock; sidesVertices = 0; for (int i = 0; i < rects.Length; i++) { Rectangle r = rects[i]; sidesVertices += Utils.CountVertices(r.Width, r.Height, axisSize); // YQuads outside } sidesVertices += Utils.CountVertices(map.Width, map.Length, axisSize); // YQuads beneath map sidesVertices += 2 * Utils.CountVertices(map.Width, Math.Abs(y), axisSize); // ZQuads sidesVertices += 2 * Utils.CountVertices(map.Length, Math.Abs(y), axisSize); // XQuads VertexP3fT2fC4b *v = stackalloc VertexP3fT2fC4b[sidesVertices]; IntPtr ptr = (IntPtr)v; fullColSides = game.BlockInfo.FullBright[block]; int col = fullColSides ? FastColour.WhitePacked : map.Env.Shadow; for (int i = 0; i < rects.Length; i++) { Rectangle r = rects[i]; DrawY(r.X, r.Y, r.X + r.Width, r.Y + r.Height, y, axisSize, col, 0, YOffset(block), ref v); } // Work properly for when ground level is below 0 int y1 = 0, y2 = y; if (y < 0) { y1 = y; y2 = 0; } DrawY(0, 0, map.Width, map.Length, 0, axisSize, col, 0, 0, ref v); DrawZ(0, 0, map.Width, y1, y2, axisSize, col, ref v); DrawZ(map.Length, 0, map.Width, y1, y2, axisSize, col, ref v); DrawX(0, 0, map.Length, y1, y2, axisSize, col, ref v); DrawX(map.Width, 0, map.Length, y1, y2, axisSize, col, ref v); sidesVb = graphics.CreateVb(ptr, VertexFormat.P3fT2fC4b, sidesVertices); }