7 ==============================================================================
11 This uses specialized forms of the maputils routines for optimized performance
13 ==============================================================================
16 fixed_t sightzstart; // eye z of looker
17 fixed_t topslope, bottomslope; // slopes to top and bottom of target
29 boolean PTR_SightTraverse (intercept_t *in)
37 // crosses a two sided line
41 if (openbottom >= opentop) // quick test for totally closed doors
44 if (li->frontsector->floorheight != li->backsector->floorheight)
46 slope = FixedDiv (openbottom - sightzstart , in->frac);
47 if (slope > bottomslope)
51 if (li->frontsector->ceilingheight != li->backsector->ceilingheight)
53 slope = FixedDiv (opentop - sightzstart , in->frac);
58 if (topslope <= bottomslope)
61 return true; // keep going
69 = P_SightBlockLinesIterator
74 boolean P_SightBlockLinesIterator (int x, int y )
82 offset = y*bmapwidth+x;
84 offset = *(blockmap+offset);
86 for ( list = blockmaplump+offset ; *list != -1 ; list++)
89 if (ld->validcount == validcount)
90 continue; // line has already been checked
91 ld->validcount = validcount;
93 s1 = P_PointOnDivlineSide (ld->v1->x, ld->v1->y, &trace);
94 s2 = P_PointOnDivlineSide (ld->v2->x, ld->v2->y, &trace);
96 continue; // line isn't crossed
97 P_MakeDivline (ld, &dl);
98 s1 = P_PointOnDivlineSide (trace.x, trace.y, &dl);
99 s2 = P_PointOnDivlineSide (trace.x+trace.dx, trace.y+trace.dy, &dl);
101 continue; // line isn't crossed
103 // try to early out the check
105 return false; // stop checking
107 // store the line for later intersection testing
108 intercept_p->d.line = ld;
113 return true; // everything was checked
119 = P_SightTraverseIntercepts
121 = Returns true if the traverser function returns true for all lines
125 boolean P_SightTraverseIntercepts ( void )
129 intercept_t *scan, *in;
132 count = intercept_p - intercepts;
134 // calculate intercept distance
136 for (scan = intercepts ; scan<intercept_p ; scan++)
138 P_MakeDivline (scan->d.line, &dl);
139 scan->frac = P_InterceptVector (&trace, &dl);
143 // go through in order
145 in = 0; // shut up compiler warning
150 for (scan = intercepts ; scan<intercept_p ; scan++)
151 if (scan->frac < dist)
157 if ( !PTR_SightTraverse (in) )
158 return false; // don't bother going farther
162 return true; // everything was traversed
170 = P_SightPathTraverse
172 = Traces a line from x1,y1 to x2,y2, calling the traverser function for each
173 = Returns true if the traverser function returns true for all lines
177 boolean P_SightPathTraverse (fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2)
179 fixed_t xt1,yt1,xt2,yt2;
182 fixed_t xintercept, yintercept;
183 int mapx, mapy, mapxstep, mapystep;
187 intercept_p = intercepts;
189 if ( ((x1-bmaporgx)&(MAPBLOCKSIZE-1)) == 0)
190 x1 += FRACUNIT; // don't side exactly on a line
191 if ( ((y1-bmaporgy)&(MAPBLOCKSIZE-1)) == 0)
192 y1 += FRACUNIT; // don't side exactly on a line
200 xt1 = x1>>MAPBLOCKSHIFT;
201 yt1 = y1>>MAPBLOCKSHIFT;
205 xt2 = x2>>MAPBLOCKSHIFT;
206 yt2 = y2>>MAPBLOCKSHIFT;
208 // points should never be out of bounds, but check once instead of
210 if (xt1<0 || yt1<0 || xt1>=bmapwidth || yt1>=bmapheight
211 || xt2<0 || yt2<0 || xt2>=bmapwidth || yt2>=bmapheight)
217 partial = FRACUNIT - ((x1>>MAPBTOFRAC)&(FRACUNIT-1));
218 ystep = FixedDiv (y2-y1,abs(x2-x1));
223 partial = (x1>>MAPBTOFRAC)&(FRACUNIT-1);
224 ystep = FixedDiv (y2-y1,abs(x2-x1));
230 ystep = 256*FRACUNIT;
232 yintercept = (y1>>MAPBTOFRAC) + FixedMul (partial, ystep);
238 partial = FRACUNIT - ((y1>>MAPBTOFRAC)&(FRACUNIT-1));
239 xstep = FixedDiv (x2-x1,abs(y2-y1));
244 partial = (y1>>MAPBTOFRAC)&(FRACUNIT-1);
245 xstep = FixedDiv (x2-x1,abs(y2-y1));
251 xstep = 256*FRACUNIT;
253 xintercept = (x1>>MAPBTOFRAC) + FixedMul (partial, xstep);
257 // step through map blocks
258 // Count is present to prevent a round off error from skipping the break
263 for (count = 0 ; count < 64 ; count++)
265 if (!P_SightBlockLinesIterator (mapx, mapy))
268 return false; // early out
271 if (mapx == xt2 && mapy == yt2)
274 if ( (yintercept >> FRACBITS) == mapy)
279 else if ( (xintercept >> FRACBITS) == mapx)
289 // couldn't early out, so go through the sorted list
293 return P_SightTraverseIntercepts ( );
299 =====================
303 = Returns true if a straight line between t1 and t2 is unobstructed
304 = look from eyes of t1 to any part of t2
306 =====================
309 boolean P_CheckSight (mobj_t *t1, mobj_t *t2)
312 int pnum, bytenum, bitnum;
315 // check for trivial rejection
317 s1 = (t1->subsector->sector - sectors);
318 s2 = (t2->subsector->sector - sectors);
319 pnum = s1*numsectors + s2;
321 bitnum = 1 << (pnum&7);
323 if (rejectmatrix[bytenum]&bitnum)
326 return false; // can't possibly be connected
332 sightzstart = t1->z + t1->height - (t1->height>>2);
333 topslope = (t2->z+t2->height) - sightzstart;
334 bottomslope = (t2->z) - sightzstart;
336 return P_SightPathTraverse ( t1->x, t1->y, t2->x, t2->y );