Original Post
The code as it is works fine, but I would like to make it faster ... what can I do? I'm not afraid of ASM, but I can't really see what I could do that the compiler doesn't already do.
BTW, the sight_blocked call has been replaced with a (map[x,y].flags && OPAQUE) == false, but I wanted to leave the original intact ... just in case
#define SGN(a) ((a<0) ? -1 : 1)
BOOL los(coord mx, coord my)
{
int t, x, y, ax, ay, sx, sy, dx, dy;
dx = d.px - mx;
dy = d.py - my;
ax = abs(dx) << 1;
ay = abs(dy) << 1;
sx = SGN(dx);
sy = SGN(dy);
x = mx;
y = my;
if(ax > ay)
{
t = ay - (ax >> 1);
do
{
if(t >= 0)
{
y += sy;
t -= ax;
}
x += sx;
t += ay;
if x == d.px && y == d.py)
{
return TRUE;
}
while(sight_blocked(x,y) == FALSE);
return FALSE;
}
else
{
// Y dominant loop
t = ax - (ay >> 1);
do
{
if(t >= 0)
{
x += sx;
t -= ay;
}
y += sy;
t += ax;
if(x == d.px && y == d.py)
{
return TRUE;
}
}
while(sight_blocked(x,y) == FALSE);
return FALSE;
}
}
-------------------------------------------------
Mindphuq Software : "Who do you want to do today?"
Edited by - morfe on 9/8/00 12:52:54 PM