ゲームを開発していますが、問題が発生しています。基本的にアイデアは次のとおりです。
- プレイヤーはエリアで呪文を使用します。
- エンジンはエリア内のすべてのユニットを選択し、それぞれに効果を適用します。
問題は、ゲームが理論的に数千のユニットを所有し、ループを実行して、それぞれが指定された領域内にあるかどうかを確認するために多くの処理を消費することです。
このプロセスをインデックス化して高速化する方法はありますか?
ここに例があります(その理論的!!):
// Create the unit struct
typedef struct UNIT{
int ID;
int x;
int y;
}unit;
// Initialize the global unit struct
unit* allunits;
// Do some code, expand the array and add more units
void addUnits(){
...
}
// Search for the number of units that are inside a random region using for and the unit array
int unitsInRegion(x1, x2, y1, y2){
// Spend alot of processing because there is like 10.000 units and we need to look at each X and Y
}
この種のタスクを DirectX と組み合わせて、ビュー (カメラ) の視界内にないモデルをバッファーから除外してレンダリングするプロセスを合理化したいと考えています。
私の悪い英語でごめんなさい。