0
我似乎无法弄清楚为什么它如此之慢,所以我希望别人可能知道:/。 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);
}
}
定义“慢”。比较慢什么? – 2012-03-03 19:21:58
定义“这么慢”。 – millimoose 2012-03-03 19:22:18
OP是如何定义缓慢的?只需查看代码并尝试查找可能的优化。 – Marlon 2012-03-03 19:23:27