7 planefunction_t floorfunc, ceilingfunc;
21 visplane_t visplanes[MAXVISPLANES], *lastvisplane;
22 visplane_t *floorplane, *ceilingplane;
24 short openings[MAXOPENINGS], *lastopening;
27 // clip values are the solid pixel bounding the range
28 // floorclip starts out SCREENHEIGHT
29 // ceilingclip starts out -1
31 short floorclip[SCREENWIDTH];
32 short ceilingclip[SCREENWIDTH];
35 // spanstart holds the start of a plane span
36 // initialized to 0 at start
38 int spanstart[SCREENHEIGHT];
39 int spanstop[SCREENHEIGHT];
44 lighttable_t **planezlight;
47 fixed_t yslope[SCREENHEIGHT];
48 fixed_t distscale[SCREENWIDTH];
49 fixed_t basexscale, baseyscale;
51 fixed_t cachedheight[SCREENHEIGHT];
52 fixed_t cacheddistance[SCREENHEIGHT];
53 fixed_t cachedxstep[SCREENHEIGHT];
54 fixed_t cachedystep[SCREENHEIGHT];
62 = Called whenever the view size changes
67 void R_InitSkyMap (void)
69 skyflatnum = R_FlatNumForName ("F_SKY1");
70 skytexturemid = 200*FRACUNIT;
80 = Only at game startup
84 void R_InitPlanes (void)
107 void R_MapPlane (int y, int x1, int x2)
111 fixed_t distance, length;
115 if (x2 < x1 || x1<0 || x2>=viewwidth || (unsigned)y>viewheight)
116 I_Error ("R_MapPlane: %i, %i at %i",x1,x2,y);
119 if (planeheight != cachedheight[y])
121 cachedheight[y] = planeheight;
122 distance = cacheddistance[y] = FixedMul (planeheight, yslope[y]);
124 ds_xstep = cachedxstep[y] = FixedMul (distance,basexscale);
125 ds_ystep = cachedystep[y] = FixedMul (distance,baseyscale);
129 distance = cacheddistance[y];
130 ds_xstep = cachedxstep[y];
131 ds_ystep = cachedystep[y];
134 length = FixedMul (distance,distscale[x1]);
135 angle = (viewangle + xtoviewangle[x1])>>ANGLETOFINESHIFT;
136 ds_xfrac = viewx + FixedMul(finecosine[angle], length);
137 ds_yfrac = -viewy - FixedMul(finesine[angle], length);
140 ds_colormap = fixedcolormap;
143 index = distance >> LIGHTZSHIFT;
144 if (index >= MAXLIGHTZ )
146 ds_colormap = planezlight[index];
153 spanfunc (); // high or low detail
157 //=============================================================================
164 = At begining of frame
168 void R_ClearPlanes (void)
174 // opening / clipping determination
176 for (i=0 ; i<viewwidth ; i++)
178 floorclip[i] = viewheight;
182 lastvisplane = visplanes;
183 lastopening = openings;
186 // texture calculation
188 memset (cachedheight, 0, sizeof(cachedheight));
189 angle = (viewangle-ANG90)>>ANGLETOFINESHIFT; // left to right mapping
191 // scale will be unit scale at SCREENWIDTH/2 distance
192 basexscale = FixedDiv (finecosine[angle],centerxfrac);
193 baseyscale = -FixedDiv (finesine[angle],centerxfrac);
206 visplane_t *R_FindPlane(fixed_t height, int picnum,
207 int lightlevel, int special)
211 if(picnum == skyflatnum)
213 // all skies map together
218 for(check = visplanes; check < lastvisplane; check++)
220 if(height == check->height
221 && picnum == check->picnum
222 && lightlevel == check->lightlevel
223 && special == check->special)
227 if(check < lastvisplane)
232 if(lastvisplane-visplanes == MAXVISPLANES)
234 I_Error("R_FindPlane: no more visplanes");
238 check->height = height;
239 check->picnum = picnum;
240 check->lightlevel = lightlevel;
241 check->special = special;
242 check->minx = SCREENWIDTH;
244 memset(check->top,0xff,sizeof(check->top));
256 visplane_t *R_CheckPlane (visplane_t *pl, int start, int stop)
262 if (start < pl->minx)
284 for (x=intrl ; x<= intrh ; x++)
285 if (pl->top[x] != 0xff)
292 return pl; // use the same one
295 // make a new visplane
297 lastvisplane->height = pl->height;
298 lastvisplane->picnum = pl->picnum;
299 lastvisplane->lightlevel = pl->lightlevel;
300 lastvisplane->special = pl->special;
304 memset (pl->top,0xff,sizeof(pl->top));
311 //=============================================================================
321 void R_MakeSpans (int x, int t1, int b1, int t2, int b2)
323 while (t1 < t2 && t1<=b1)
325 R_MapPlane (t1,spanstart[t1],x-1);
328 while (b1 > b2 && b1>=t1)
330 R_MapPlane (b1,spanstart[b1],x-1);
334 while (t2 < t1 && t2<=b2)
339 while (b2 > b1 && b2>=t2)
353 = At the end of each frame
357 void R_DrawPlanes (void)
368 fixed_t frac, fracstep;
370 extern byte *ylookup[MAXHEIGHT];
371 extern int columnofs[MAXWIDTH];
374 if (ds_p - drawsegs > MAXDRAWSEGS)
375 I_Error ("R_DrawPlanes: drawsegs overflow (%i)", ds_p - drawsegs);
376 if (lastvisplane - visplanes > MAXVISPLANES)
377 I_Error ("R_DrawPlanes: visplane overflow (%i)", lastvisplane - visplanes);
378 if (lastopening - openings > MAXOPENINGS)
379 I_Error ("R_DrawPlanes: opening overflow (%i)", lastopening - openings);
382 for (pl = visplanes ; pl < lastvisplane ; pl++)
384 if (pl->minx > pl->maxx)
389 if (pl->picnum == skyflatnum)
391 dc_iscale = skyiscale;
392 dc_colormap = colormaps;// sky is allways drawn full bright
393 dc_texturemid = skytexturemid;
394 for (x=pl->minx ; x <= pl->maxx ; x++)
397 dc_yh = pl->bottom[x];
400 angle = (viewangle + xtoviewangle[x])>>ANGLETOSKYSHIFT;
402 dc_source = R_GetColumn(skytexture, angle);
404 count = dc_yh - dc_yl;
409 if ((unsigned)dc_x >= SCREENWIDTH || dc_yl < 0 || dc_yh >= SCREENHEIGHT)
410 I_Error ("R_DrawColumn: %i to %i at %i", dc_yl, dc_yh, dc_x);
413 dest = ylookup[dc_yl] + columnofs[dc_x];
416 frac = (dc_texturemid>>FRACBITS) + (dc_yl-centery);
419 *dest = dc_source[frac];
433 tempSource = W_CacheLumpNum(firstflat +
434 flattranslation[pl->picnum], PU_STATIC);
438 case 25: case 26: case 27: case 28: case 29: // Scroll_North
439 ds_source = tempSource;
441 case 20: case 21: case 22: case 23: case 24: // Scroll_East
442 ds_source = tempSource+((63-((leveltime>>1)&63))<<
443 (pl->special-20)&63);
444 //ds_source = tempSource+((leveltime>>1)&63);
446 case 30: case 31: case 32: case 33: case 34: // Scroll_South
447 ds_source = tempSource;
449 case 35: case 36: case 37: case 38: case 39: // Scroll_West
450 ds_source = tempSource;
452 case 4: // Scroll_EastLavaDamage
453 ds_source = tempSource+(((63-((leveltime>>1)&63))<<3)&63);
456 ds_source = tempSource;
458 planeheight = abs(pl->height-viewz);
459 light = (pl->lightlevel >> LIGHTSEGSHIFT)+extralight;
460 if (light >= LIGHTLEVELS)
461 light = LIGHTLEVELS-1;
464 planezlight = zlight[light];
466 pl->top[pl->maxx+1] = 0xff;
467 pl->top[pl->minx-1] = 0xff;
470 for (x=pl->minx ; x<= stop ; x++)
471 R_MakeSpans (x,pl->top[x-1],pl->bottom[x-1]
472 ,pl->top[x],pl->bottom[x]);
474 Z_ChangeTag (tempSource, PU_CACHE);