
It looks pretty nifty, but it's damn slow. Can anybody see how to speed up the code below? I think the easiest way is to lower the scan resolution, but I don't know how to do it ...
Code: Select all
for(int y=starty;y<endy;++y){
for(int x=0;x<gs->hmapx;++x){
int a=y*(gs->pwr2mapx>>1)+x;
bool inCircle=false;
// convert square (x,y) to a float3 position
float xpos = (float) x * SQUARE_SIZE * 2;
float zpos = (float) y * SQUARE_SIZE * 2;
// determine whether we're in the bounding box
if (xpos > drawAttackRangeUnit->pos[0] - drawAttackRangeUnit->maxRange &&
xpos < drawAttackRangeUnit->pos[0] + drawAttackRangeUnit->maxRange &&
zpos > drawAttackRangeUnit->pos[2] - drawAttackRangeUnit->maxRange &&
zpos < drawAttackRangeUnit->pos[2] + drawAttackRangeUnit->maxRange)
{
float ypos = readmap->centerheightmap[y*gs->mapx+x];
float3 currentPos = float3(xpos,ypos,zpos);
// check whether we're in the circle
if (drawAttackRangeUnit->pos.distance2D(currentPos) < drawAttackRangeUnit->maxRange)
{
inCircle = true;
bool canAttackHere = false;
for(std::vector<CWeapon*>::iterator wi=drawAttackRangeUnit->weapons.begin();wi!=drawAttackRangeUnit->weapons.end();++wi)
{
if ((*wi)->TryTarget(currentPos,true,0))
{
canAttackHere = true;
break;
}
}
if (canAttackHere)
{
// good area, draw it green
infoTexMem[a*4+0]=0;
infoTexMem[a*4+1]=255;
infoTexMem[a*4+2]=0;
}
else
{
// bad area, draw it red
infoTexMem[a*4+0]=255;
infoTexMem[a*4+1]=0;
infoTexMem[a*4+2]=0;
}
} // circle
} // bounding box
if (!inCircle) // draw areas outside the circle normally
{
infoTexMem[a*4+0]=128;
infoTexMem[a*4+1]=128;
infoTexMem[a*4+2]=128;
}
}
}