なぜそんなに遅いのか分かりませんので、他の人が知りたいと思っていました。 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