1

我正在开发一款游戏,但我遇到了问题。基本上这个想法是:

  • 玩家在区域使用咒语。
  • 引擎选择该区域中的所有单位并对每个单位应用效果。

问题是游戏理论上拥有数千个单元,并且运行一个循环来检查每个单元是否在指定区域内会花费很多处理。

有没有办法索引和加速这个过程?

这是一个例子(它的理论!!):

// 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 混合,作为一种简化渲染过程的方法,排除不在缓冲区视线范围内的模型(相机)。

对不起,我的英语不好。

4

1 回答 1

2

有没有办法索引和加速这个过程?

正如评论中提到的,通常的做法是像QuadtreesOctreesBSP-Trees这样的树。

我想将这种任务与 DirectX 混合,作为一种简化渲染过程的方法,排除不在缓冲区视线范围内的模型(相机)。

我认为您正在寻找 View Frustum Culling(教程)。您可以将此方法与评论中提到的树之一混合使用,以有效地剔除场景中的所有对象。

于 2012-12-13T17:53:19.433 回答