public void AddQuad(int x, int y, GroundMasks.UVData uvs)
            {
                int count = pos.Count;

                indices.Add(count);
                indices.Add(count + 1);
                indices.Add(count + 3);
                indices.Add(count);
                indices.Add(count + 3);
                indices.Add(count + 2);
                pos.Add(new Vector3((float)x + -0.5f, (float)y + -0.5f, 0f));
                pos.Add(new Vector3((float)x + 1f + -0.5f, (float)y + -0.5f, 0f));
                pos.Add(new Vector3((float)x + -0.5f, (float)y + 1f + -0.5f, 0f));
                pos.Add(new Vector3((float)x + 1f + -0.5f, (float)y + 1f + -0.5f, 0f));
                uv.Add(uvs.bl);
                uv.Add(uvs.br);
                uv.Add(uvs.tl);
                uv.Add(uvs.tr);
            }
 public void AddAlphaQuad(int x, int y, GroundMasks.UVData uvs)
 {
     alpha.AddQuad(x, y, uvs);
     tileCount++;
 }
        public void Rebuild(GroundMasks.BiomeMaskData[] biomeMasks, Dictionary <SimHashes, Materials> materials)
        {
            foreach (ElementChunk elementChunk3 in elementChunks)
            {
                elementChunk3.Clear();
            }
            Vector2I vector2I  = new Vector2I(chunkX * 16, chunkY * 16);
            Vector2I vector2I2 = new Vector2I(Math.Min(Grid.WidthInCells, (chunkX + 1) * 16), Math.Min(Grid.HeightInCells, (chunkY + 1) * 16));

            for (int i = vector2I.y; i < vector2I2.y; i++)
            {
                int num  = Math.Max(0, i - 1);
                int num2 = i;
                for (int j = vector2I.x; j < vector2I2.x; j++)
                {
                    int num3 = Math.Max(0, j - 1);
                    int num4 = j;
                    int num5 = num * Grid.WidthInCells + num3;
                    int num6 = num * Grid.WidthInCells + num4;
                    int num7 = num2 * Grid.WidthInCells + num3;
                    int num8 = num2 * Grid.WidthInCells + num4;
                    elements[0]       = Grid.Element[num5];
                    elements[1]       = Grid.Element[num6];
                    elements[2]       = Grid.Element[num7];
                    elements[3]       = Grid.Element[num8];
                    substances[0]     = ((!Grid.RenderedByWorld[num5] || !elements[0].IsSolid) ? (-1) : elements[0].substance.idx);
                    substances[1]     = ((!Grid.RenderedByWorld[num6] || !elements[1].IsSolid) ? (-1) : elements[1].substance.idx);
                    substances[2]     = ((!Grid.RenderedByWorld[num7] || !elements[2].IsSolid) ? (-1) : elements[2].substance.idx);
                    substances[3]     = ((!Grid.RenderedByWorld[num8] || !elements[3].IsSolid) ? (-1) : elements[3].substance.idx);
                    uniqueElements[0] = elements[0];
                    InsertSorted(elements[1], uniqueElements, 1);
                    InsertSorted(elements[2], uniqueElements, 2);
                    InsertSorted(elements[3], uniqueElements, 3);
                    int num9     = -1;
                    int cell     = i * Grid.WidthInCells + j;
                    int biomeIdx = GetBiomeIdx(cell);
                    GroundMasks.BiomeMaskData biomeMaskData = biomeMasks[biomeIdx];
                    for (int k = 0; k < uniqueElements.Length; k++)
                    {
                        Element element = uniqueElements[k];
                        if (element.IsSolid)
                        {
                            int idx = element.substance.idx;
                            if (idx != num9)
                            {
                                num9 = idx;
                                int num10 = (((substances[2] >= idx) ? 1 : 0) << 3) | (((substances[3] >= idx) ? 1 : 0) << 2) | (((substances[0] >= idx) ? 1 : 0) << 1) | (((substances[1] >= idx) ? 1 : 0) << 0);
                                if (num10 > 0)
                                {
                                    GroundMasks.UVData[] variationUVs = biomeMaskData.tiles[num10].variationUVs;
                                    float staticRandom              = GetStaticRandom(j, i);
                                    int   num11                     = Mathf.Min(variationUVs.Length - 1, (int)((float)variationUVs.Length * staticRandom));
                                    GroundMasks.UVData uvs          = variationUVs[num11 % variationUVs.Length];
                                    ElementChunk       elementChunk = GetElementChunk(element.id, materials);
                                    if (num10 == 15)
                                    {
                                        elementChunk.AddOpaqueQuad(j, i, uvs);
                                    }
                                    else
                                    {
                                        elementChunk.AddAlphaQuad(j, i, uvs);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            foreach (ElementChunk elementChunk4 in elementChunks)
            {
                elementChunk4.Build();
            }
            for (int num12 = elementChunks.Count - 1; num12 >= 0; num12--)
            {
                ElementChunk elementChunk2 = elementChunks[num12];
                if (elementChunk2.tileCount == 0)
                {
                    int index = elementChunks.Count - 1;
                    elementChunks[num12] = elementChunks[index];
                    elementChunks.RemoveAt(index);
                }
            }
        }
 public void AddOpaqueQuad(int x, int y, GroundMasks.UVData uvs)
 {
     opaque.AddQuad(x, y, uvs);
     tileCount++;
 }