Я не могу понять, почему это так медленно, поэтому я надеялся, что кто-то еще может знать: /. chunk_vertices и chunk_indices - это списки.Почему эта функция работает так медленно?
public void get_cube_at_position(int x, int y, int z,Color colour)
{
int length;
if (y > y_size - 2)
{
chunk_vertices.Add(new VertexPositionColor(new Vector3(x, y + 1, z), colour));
chunk_vertices.Add(new VertexPositionColor(new Vector3(1 + x, y + 1, z), colour));
chunk_vertices.Add(new VertexPositionColor(new Vector3(x, y + 1, 1 + z), colour));
chunk_vertices.Add(new VertexPositionColor(new Vector3(1 + x, y + 1, 1 + z), colour));
length = chunk_vertices.Count - 4;
chunk_indices.Add(0 + length);
chunk_indices.Add(1 + length);
chunk_indices.Add(2 + length);
chunk_indices.Add(3 + length);
chunk_indices.Add(2 + length);
chunk_indices.Add(1 + length);
}
else if (blocks[x, y + 1, z] == 0)
{
chunk_vertices.Add(new VertexPositionColor(new Vector3(x, y + 1, z), colour));
chunk_vertices.Add(new VertexPositionColor(new Vector3(1 + x, y + 1, z), colour));
chunk_vertices.Add(new VertexPositionColor(new Vector3(x, y + 1, 1 + z), colour));
chunk_vertices.Add(new VertexPositionColor(new Vector3(1 + x, y + 1, 1 + z), colour));
length = chunk_vertices.Count - 4;
chunk_indices.Add(0 + length);
chunk_indices.Add(1 + length);
chunk_indices.Add(2 + length);
chunk_indices.Add(3 + length);
chunk_indices.Add(2 + length);
chunk_indices.Add(1 + length);
}
if (y != 0 && blocks[x, y - 1, z] == 0)
{
chunk_vertices.Add(new VertexPositionColor(new Vector3(x, y, z), colour));
chunk_vertices.Add(new VertexPositionColor(new Vector3(x, y, 1 + z), colour));
chunk_vertices.Add(new VertexPositionColor(new Vector3(1 + x, y, z), colour));
chunk_vertices.Add(new VertexPositionColor(new Vector3(1 + x, y, 1 + z), colour));
length = chunk_vertices.Count - 4;
chunk_indices.Add(0 + length);
chunk_indices.Add(1 + length);
chunk_indices.Add(2 + length);
chunk_indices.Add(3 + length);
chunk_indices.Add(2 + length);
chunk_indices.Add(1 + length);
}
if (x > x_size - 2)
{
}
else if (blocks[x + 1, y, z] == 0)
{
chunk_vertices.Add(new VertexPositionColor(new Vector3(1 + x, y, z), colour));
chunk_vertices.Add(new VertexPositionColor(new Vector3(1 + x, y, 1 + z), colour));
chunk_vertices.Add(new VertexPositionColor(new Vector3(1 + x, 1 + y, z), colour));
chunk_vertices.Add(new VertexPositionColor(new Vector3(1 + x, 1 + y, 1 + z), colour));
length = chunk_vertices.Count - 4;
chunk_indices.Add(0 + length);
chunk_indices.Add(1 + length);
chunk_indices.Add(2 + length);
chunk_indices.Add(3 + length);
chunk_indices.Add(2 + length);
chunk_indices.Add(1 + length);
}
if (x != 0 && blocks[x - 1, y, z] == 0)
{
chunk_vertices.Add(new VertexPositionColor(new Vector3(x, y, z), colour));
chunk_vertices.Add(new VertexPositionColor(new Vector3(x, y + 1, z), colour));
chunk_vertices.Add(new VertexPositionColor(new Vector3(x, y, 1 + z), colour));
chunk_vertices.Add(new VertexPositionColor(new Vector3(x, y + 1, 1 + z), colour));
length = chunk_vertices.Count - 4;
chunk_indices.Add(0 + length);
chunk_indices.Add(1 + length);
chunk_indices.Add(2 + length);
chunk_indices.Add(3 + length);
chunk_indices.Add(2 + length);
chunk_indices.Add(1 + length);
}
if (z > z_size - 2)
{
}
else if (blocks[x, y, z + 1] == 0)
{
chunk_vertices.Add(new VertexPositionColor(new Vector3(x, y, 1 + z), colour));
chunk_vertices.Add(new VertexPositionColor(new Vector3(x, y + 1, 1 + z), colour));
chunk_vertices.Add(new VertexPositionColor(new Vector3(1 + x, y, 1 + z), colour));
chunk_vertices.Add(new VertexPositionColor(new Vector3(1 + x, y + 1, 1 + z), colour));
length = chunk_vertices.Count - 4;
chunk_indices.Add(0 + length);
chunk_indices.Add(1 + length);
chunk_indices.Add(2 + length);
chunk_indices.Add(3 + length);
chunk_indices.Add(2 + length);
chunk_indices.Add(1 + length);
}
if (z != 0 && blocks[x, y, z - 1] == 0)
{
chunk_vertices.Add(new VertexPositionColor(new Vector3(x, y, z), colour));
chunk_vertices.Add(new VertexPositionColor(new Vector3(1 + x, y, z), colour));
chunk_vertices.Add(new VertexPositionColor(new Vector3(x, y + 1, z), colour));
chunk_vertices.Add(new VertexPositionColor(new Vector3(1 + x, y + 1, z), colour));
length = chunk_vertices.Count - 4;
chunk_indices.Add(0 + length);
chunk_indices.Add(1 + length);
chunk_indices.Add(2 + length);
chunk_indices.Add(3 + length);
chunk_indices.Add(2 + length);
chunk_indices.Add(1 + length);
}
}
Определить «медленный». Медленно по сравнению с чем? –
Определите «так медленно». – millimoose
Имеет ли значение, как OP хочет определить медленное? Просто просмотрите код и попытайтесь найти возможные оптимизации. – Marlon