8 ==============================================================================
12 This uses specialized forms of the maputils routines for optimized performance
14 ==============================================================================
17 fixed_t sightzstart; // eye z of looker
18 fixed_t topslope, bottomslope; // slopes to top and bottom of target
30 boolean PTR_SightTraverse (intercept_t *in)
38 // crosses a two sided line
42 if (openbottom >= opentop) // quick test for totally closed doors
45 if (li->frontsector->floorheight != li->backsector->floorheight)
47 slope = FixedDiv (openbottom - sightzstart , in->frac);
48 if (slope > bottomslope)
52 if (li->frontsector->ceilingheight != li->backsector->ceilingheight)
54 slope = FixedDiv (opentop - sightzstart , in->frac);
59 if (topslope <= bottomslope)
62 return true; // keep going
70 = P_SightBlockLinesIterator
75 boolean P_SightBlockLinesIterator (int x, int y )
83 offset = y*bmapwidth+x;
85 offset = *(blockmap+offset);
87 for ( list = blockmaplump+offset ; *list != -1 ; list++)
90 if (ld->validcount == validcount)
91 continue; // line has already been checked
92 ld->validcount = validcount;
94 s1 = P_PointOnDivlineSide (ld->v1->x, ld->v1->y, &trace);
95 s2 = P_PointOnDivlineSide (ld->v2->x, ld->v2->y, &trace);
97 continue; // line isn't crossed
98 P_MakeDivline (ld, &dl);
99 s1 = P_PointOnDivlineSide (trace.x, trace.y, &dl);
100 s2 = P_PointOnDivlineSide (trace.x+trace.dx, trace.y+trace.dy, &dl);
102 continue; // line isn't crossed
104 // try to early out the check
106 return false; // stop checking
108 // store the line for later intersection testing
109 intercept_p->d.line = ld;
114 return true; // everything was checked
120 = P_SightTraverseIntercepts
122 = Returns true if the traverser function returns true for all lines
126 boolean P_SightTraverseIntercepts ( void )
130 intercept_t *scan, *in;
133 count = intercept_p - intercepts;
135 // calculate intercept distance
137 for (scan = intercepts ; scan<intercept_p ; scan++)
139 P_MakeDivline (scan->d.line, &dl);
140 scan->frac = P_InterceptVector (&trace, &dl);
144 // go through in order
146 in = 0; // shut up compiler warning
151 for (scan = intercepts ; scan<intercept_p ; scan++)
152 if (scan->frac < dist)
158 if ( !PTR_SightTraverse (in) )
159 return false; // don't bother going farther
163 return true; // everything was traversed
171 = P_SightPathTraverse
173 = Traces a line from x1,y1 to x2,y2, calling the traverser function for each
174 = Returns true if the traverser function returns true for all lines
178 boolean P_SightPathTraverse (fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2)
180 fixed_t xt1,yt1,xt2,yt2;
183 fixed_t xintercept, yintercept;
184 int mapx, mapy, mapxstep, mapystep;
188 intercept_p = intercepts;
190 if ( ((x1-bmaporgx)&(MAPBLOCKSIZE-1)) == 0)
191 x1 += FRACUNIT; // don't side exactly on a line
192 if ( ((y1-bmaporgy)&(MAPBLOCKSIZE-1)) == 0)
193 y1 += FRACUNIT; // don't side exactly on a line
201 xt1 = x1>>MAPBLOCKSHIFT;
202 yt1 = y1>>MAPBLOCKSHIFT;
206 xt2 = x2>>MAPBLOCKSHIFT;
207 yt2 = y2>>MAPBLOCKSHIFT;
209 // points should never be out of bounds, but check once instead of
211 if (xt1<0 || yt1<0 || xt1>=bmapwidth || yt1>=bmapheight
212 || xt2<0 || yt2<0 || xt2>=bmapwidth || yt2>=bmapheight)
218 partial = FRACUNIT - ((x1>>MAPBTOFRAC)&(FRACUNIT-1));
219 ystep = FixedDiv (y2-y1,abs(x2-x1));
224 partial = (x1>>MAPBTOFRAC)&(FRACUNIT-1);
225 ystep = FixedDiv (y2-y1,abs(x2-x1));
231 ystep = 256*FRACUNIT;
233 yintercept = (y1>>MAPBTOFRAC) + FixedMul (partial, ystep);
239 partial = FRACUNIT - ((y1>>MAPBTOFRAC)&(FRACUNIT-1));
240 xstep = FixedDiv (x2-x1,abs(y2-y1));
245 partial = (y1>>MAPBTOFRAC)&(FRACUNIT-1);
246 xstep = FixedDiv (x2-x1,abs(y2-y1));
252 xstep = 256*FRACUNIT;
254 xintercept = (x1>>MAPBTOFRAC) + FixedMul (partial, xstep);
258 // step through map blocks
259 // Count is present to prevent a round off error from skipping the break
264 for (count = 0 ; count < 64 ; count++)
266 if (!P_SightBlockLinesIterator (mapx, mapy))
269 return false; // early out
272 if (mapx == xt2 && mapy == yt2)
275 if ( (yintercept >> FRACBITS) == mapy)
280 else if ( (xintercept >> FRACBITS) == mapx)
290 // couldn't early out, so go through the sorted list
294 return P_SightTraverseIntercepts ( );
300 =====================
304 = Returns true if a straight line between t1 and t2 is unobstructed
305 = look from eyes of t1 to any part of t2
307 =====================
310 boolean P_CheckSight (mobj_t *t1, mobj_t *t2)
313 int pnum, bytenum, bitnum;
316 // check for trivial rejection
318 s1 = (t1->subsector->sector - sectors);
319 s2 = (t2->subsector->sector - sectors);
320 pnum = s1*numsectors + s2;
322 bitnum = 1 << (pnum&7);
324 if (rejectmatrix[bytenum]&bitnum)
327 return false; // can't possibly be connected
333 sightzstart = t1->z + t1->height - (t1->height>>2);
334 topslope = (t2->z+t2->height) - sightzstart;
335 bottomslope = (t2->z) - sightzstart;
337 return P_SightPathTraverse ( t1->x, t1->y, t2->x, t2->y );