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