6 planefunction_t floorfunc, ceilingfunc;
20 visplane_t visplanes[MAXVISPLANES], *lastvisplane;
21 visplane_t *floorplane, *ceilingplane;
23 short openings[MAXOPENINGS], *lastopening;
26 // clip values are the solid pixel bounding the range
27 // floorclip starts out SCREENHEIGHT
28 // ceilingclip starts out -1
30 short floorclip[SCREENWIDTH];
31 short ceilingclip[SCREENWIDTH];
34 // spanstart holds the start of a plane span
35 // initialized to 0 at start
37 int spanstart[SCREENHEIGHT];
38 int spanstop[SCREENHEIGHT];
43 lighttable_t **planezlight;
46 fixed_t yslope[SCREENHEIGHT];
47 fixed_t distscale[SCREENWIDTH];
48 fixed_t basexscale, baseyscale;
50 fixed_t cachedheight[SCREENHEIGHT];
51 fixed_t cacheddistance[SCREENHEIGHT];
52 fixed_t cachedxstep[SCREENHEIGHT];
53 fixed_t cachedystep[SCREENHEIGHT];
61 = Called whenever the view size changes
66 void R_InitSkyMap (void)
68 skyflatnum = R_FlatNumForName ("F_SKY1");
69 skytexturemid = 200*FRACUNIT;
79 = Only at game startup
83 void R_InitPlanes (void)
106 void R_MapPlane (int y, int x1, int x2)
110 fixed_t distance, length;
114 if (x2 < x1 || x1<0 || x2>=viewwidth || (unsigned)y>viewheight)
115 I_Error ("R_MapPlane: %i, %i at %i",x1,x2,y);
118 if (planeheight != cachedheight[y])
120 cachedheight[y] = planeheight;
121 distance = cacheddistance[y] = FixedMul (planeheight, yslope[y]);
123 ds_xstep = cachedxstep[y] = FixedMul (distance,basexscale);
124 ds_ystep = cachedystep[y] = FixedMul (distance,baseyscale);
128 distance = cacheddistance[y];
129 ds_xstep = cachedxstep[y];
130 ds_ystep = cachedystep[y];
133 length = FixedMul (distance,distscale[x1]);
134 angle = (viewangle + xtoviewangle[x1])>>ANGLETOFINESHIFT;
135 ds_xfrac = viewx + FixedMul(finecosine[angle], length);
136 ds_yfrac = -viewy - FixedMul(finesine[angle], length);
139 ds_colormap = fixedcolormap;
142 index = distance >> LIGHTZSHIFT;
143 if (index >= MAXLIGHTZ )
145 ds_colormap = planezlight[index];
152 spanfunc (); // high or low detail
156 //=============================================================================
163 = At begining of frame
167 void R_ClearPlanes (void)
173 // opening / clipping determination
175 for (i=0 ; i<viewwidth ; i++)
177 floorclip[i] = viewheight;
181 lastvisplane = visplanes;
182 lastopening = openings;
185 // texture calculation
187 memset (cachedheight, 0, sizeof(cachedheight));
188 angle = (viewangle-ANG90)>>ANGLETOFINESHIFT; // left to right mapping
190 // scale will be unit scale at SCREENWIDTH/2 distance
191 basexscale = FixedDiv (finecosine[angle],centerxfrac);
192 baseyscale = -FixedDiv (finesine[angle],centerxfrac);
205 visplane_t *R_FindPlane(fixed_t height, int picnum,
206 int lightlevel, int special)
210 if(picnum == skyflatnum)
212 // all skies map together
217 for(check = visplanes; check < lastvisplane; check++)
219 if(height == check->height
220 && picnum == check->picnum
221 && lightlevel == check->lightlevel
222 && special == check->special)
226 if(check < lastvisplane)
231 if(lastvisplane-visplanes == MAXVISPLANES)
233 I_Error("R_FindPlane: no more visplanes");
237 check->height = height;
238 check->picnum = picnum;
239 check->lightlevel = lightlevel;
240 check->special = special;
241 check->minx = SCREENWIDTH;
243 memset(check->top,0xff,sizeof(check->top));
255 visplane_t *R_CheckPlane (visplane_t *pl, int start, int stop)
261 if (start < pl->minx)
283 for (x=intrl ; x<= intrh ; x++)
284 if (pl->top[x] != 0xff)
291 return pl; // use the same one
294 // make a new visplane
296 lastvisplane->height = pl->height;
297 lastvisplane->picnum = pl->picnum;
298 lastvisplane->lightlevel = pl->lightlevel;
299 lastvisplane->special = pl->special;
303 memset (pl->top,0xff,sizeof(pl->top));
310 //=============================================================================
320 void R_MakeSpans (int x, int t1, int b1, int t2, int b2)
322 while (t1 < t2 && t1<=b1)
324 R_MapPlane (t1,spanstart[t1],x-1);
327 while (b1 > b2 && b1>=t1)
329 R_MapPlane (b1,spanstart[b1],x-1);
333 while (t2 < t1 && t2<=b2)
338 while (b2 > b1 && b2>=t2)
352 = At the end of each frame
356 void R_DrawPlanes (void)
367 fixed_t frac, fracstep;
369 extern byte *ylookup[MAXHEIGHT];
370 extern int columnofs[MAXWIDTH];
373 if (ds_p - drawsegs > MAXDRAWSEGS)
374 I_Error ("R_DrawPlanes: drawsegs overflow (%i)", ds_p - drawsegs);
375 if (lastvisplane - visplanes > MAXVISPLANES)
376 I_Error ("R_DrawPlanes: visplane overflow (%i)", lastvisplane - visplanes);
377 if (lastopening - openings > MAXOPENINGS)
378 I_Error ("R_DrawPlanes: opening overflow (%i)", lastopening - openings);
381 for (pl = visplanes ; pl < lastvisplane ; pl++)
383 if (pl->minx > pl->maxx)
388 if (pl->picnum == skyflatnum)
390 dc_iscale = skyiscale;
391 dc_colormap = colormaps;// sky is allways drawn full bright
392 dc_texturemid = skytexturemid;
393 for (x=pl->minx ; x <= pl->maxx ; x++)
396 dc_yh = pl->bottom[x];
399 angle = (viewangle + xtoviewangle[x])>>ANGLETOSKYSHIFT;
401 dc_source = R_GetColumn(skytexture, angle);
403 count = dc_yh - dc_yl;
408 if ((unsigned)dc_x >= SCREENWIDTH || dc_yl < 0 || dc_yh >= SCREENHEIGHT)
409 I_Error ("R_DrawColumn: %i to %i at %i", dc_yl, dc_yh, dc_x);
412 dest = ylookup[dc_yl] + columnofs[dc_x];
415 frac = (dc_texturemid>>FRACBITS) + (dc_yl-centery);
418 *dest = dc_source[frac];
432 tempSource = W_CacheLumpNum(firstflat +
433 flattranslation[pl->picnum], PU_STATIC);
437 case 25: case 26: case 27: case 28: case 29: // Scroll_North
438 ds_source = tempSource;
440 case 20: case 21: case 22: case 23: case 24: // Scroll_East
441 ds_source = tempSource+((63-((leveltime>>1)&63))<<
442 (pl->special-20)&63);
443 //ds_source = tempSource+((leveltime>>1)&63);
445 case 30: case 31: case 32: case 33: case 34: // Scroll_South
446 ds_source = tempSource;
448 case 35: case 36: case 37: case 38: case 39: // Scroll_West
449 ds_source = tempSource;
451 case 4: // Scroll_EastLavaDamage
452 ds_source = tempSource+(((63-((leveltime>>1)&63))<<3)&63);
455 ds_source = tempSource;
457 planeheight = abs(pl->height-viewz);
458 light = (pl->lightlevel >> LIGHTSEGSHIFT)+extralight;
459 if (light >= LIGHTLEVELS)
460 light = LIGHTLEVELS-1;
463 planezlight = zlight[light];
465 pl->top[pl->maxx+1] = 0xff;
466 pl->top[pl->minx-1] = 0xff;
469 for (x=pl->minx ; x<= stop ; x++)
470 R_MakeSpans (x,pl->top[x-1],pl->bottom[x-1]
471 ,pl->top[x],pl->bottom[x]);
473 Z_ChangeTag (tempSource, PU_CACHE);