私のコードのこの部分は、Tile
オブジェクトの不規則な形の輪郭を取り、リングを作成し、リング内のタイルの高さ値を減らしながらリングを展開して、直前のタイルリング(それは理にかなっていますか?)しかし、私が見つけたのは、大規模なパフォーマンスの低下が起こっていることです。各ループは以前よりも馬鹿げて遅くなっています。なぜこれができますか?巨大なパフォーマンスの低下 - 問題のベクトルですか?
私はそれがnoobish oldEdge = theEdge;
とそれに類する行(両方ともベクトルであり、私はもう一方を割り当てている)のためかもしれないと思っていました。しかし、それでも、私は巨大なパフォーマンス低下を理解していません。たぶん私は明らかに愚かな何かをしている。誰かが私をまっすぐにすることができます
なお、oldEdge
,theEdge
およびnewEdge
はすべてvector<Tile*>
である。
int decrease = 1;
while(decrease < 10)
{
cout << "Trying to smooth!\n";
//First, modify the new edge.
int newHeight = 70 - decrease;
cout << "Height at: " << newHeight << endl;
for(int i = 0; i < newEdge.size(); ++i)
{
newEdge[i]->SetHeight(newHeight);
}
//Increment decrease.
decrease += 1;
//Set the oldEdge and theEdge variables.
oldEdge = theEdge;
theEdge = newEdge;
newEdge.clear();
//Finally, find the new edge.
cout << "Finding new edge!\n";
for(int i = 0; i < theEdge.size(); ++i)
{
//cout << "Checking a tile's neighbors!\n";
for(int j = 0; j < theEdge[i]->m_AdjacentTiles.size(); ++j)
{
bool valid = true;
//Is this neighbor in theEdge?
//cout << "Is this neighbor in theEdge?\n";
for(int k = 0; k < theEdge.size(); ++k)
{
if(theEdge[i]->m_AdjacentTiles[j] == theEdge[k])
{
valid = false;
break;
}
}
//If not, is it in oldEdge?
if(valid)
{
//cout << "Is this neighbor in oldEdge?\n";
for(int k = 0; k < oldEdge.size(); ++k)
{
if(theEdge[i]->m_AdjacentTiles[j] == oldEdge[k])
{
valid = false;
break;
}
}
}
//If neither, it must be valid for continued expansion.
if(valid)
{
newEdge.push_back(theEdge[i]->m_AdjacentTiles[j]);
}
}
}
}
なぜ「タイル」ではなく「タイル*」ですか?とにかく 'newEdge'を破棄したので、' swap'の代入を変更しようとしましたか? –
あなたは3つのネストされたループを持っています。最も内側のループを最初に調べます。例: 'theEdge [i] - > m_AdjacentTiles [j]'はループから移動できます。 (それを行うためにコンパイラを数えないでください)また、 'for(int k = theEdge.size(); valid && --k> = 0;)のように、私はカウントダウンします。 –
扱っている 'size()'の種類の大まかなアイデアはありますか?それは必ずしもロジックに影響するわけではありませんが、最適化する場所を指示するのに役立ちます。 – dolphy