2 //**************************************************************************
4 //** am_map.c : Heretic 2 : Raven Software, Corp.
11 //**************************************************************************
22 #define MTOFX(x) FixedMul((x),scale_mtof)
24 #define CXMTOFX(x) ((f_x<<16) + MTOFX((x)-m_x))
25 #define CYMTOFX(y) ((f_y<<16) + ((f_h<<16) - MTOFX((y)-m_y)))
27 static int maplumpnum;
31 #define NUMALIAS 3 // Number of antialiased lines.
36 static int leveljuststarted = 1; // kluge until AM_LevelInit() is called
38 boolean automapactive = false;
39 static int finit_width = SCREENWIDTH;
40 static int finit_height = SCREENHEIGHT-SBARHEIGHT-3;
41 static int f_x, f_y; // location of window on screen
42 static int f_w, f_h; // size of window on screen
43 static int lightlev; // used for funky strobing effect
44 static byte *fb; // pseudo-frame buffer
47 static mpoint_t m_paninc; // how far the window pans each tic (map coords)
48 static fixed_t mtof_zoommul; // how far the window zooms in each tic (map coords)
49 static fixed_t ftom_zoommul; // how far the window zooms in each tic (fb coords)
51 static fixed_t m_x, m_y; // LL x,y where the window is on the map (map coords)
52 static fixed_t m_x2, m_y2; // UR x,y where the window is on the map (map coords)
54 // width/height of window on map (map coords)
55 static fixed_t m_w, m_h;
56 static fixed_t min_x, min_y; // based on level size
57 static fixed_t max_x, max_y; // based on level size
58 static fixed_t max_w, max_h; // max_x-min_x, max_y-min_y
59 static fixed_t min_w, min_h; // based on player size
60 static fixed_t min_scale_mtof; // used to tell when to stop zooming out
61 static fixed_t max_scale_mtof; // used to tell when to stop zooming in
63 // old stuff for recovery later
64 static fixed_t old_m_w, old_m_h;
65 static fixed_t old_m_x, old_m_y;
67 // old location used by the Follower routine
68 static mpoint_t f_oldloc;
70 // used by MTOF to scale from map-to-frame-buffer coords
71 static fixed_t scale_mtof = INITSCALEMTOF;
72 // used by FTOM to scale from frame-buffer-to-map coords (=1/scale_mtof)
73 static fixed_t scale_ftom;
75 static player_t *plr; // the player represented by an arrow
76 static vertex_t oldplr;
78 //static patch_t *marknums[10]; // numbers used for marking by the automap
79 //static mpoint_t markpoints[AM_NUMMARKPOINTS]; // where the points are
80 //static int markpointnum = 0; // next point to be assigned
82 static int followplayer = 1; // specifies whether to follow the player around
84 static char cheat_kills[] = { 'k', 'i', 'l', 'l', 's' };
85 static boolean ShowKills = 0;
86 static unsigned ShowKillsCount = 0;
88 extern boolean viewactive;
90 static byte antialias[NUMALIAS][8]=
92 { 83, 84, 85, 86, 87, 88, 89, 90 },
93 { 96, 96, 95, 94, 93, 92, 91, 90 },
94 { 107, 108, 109, 110, 111, 112, 89, 90 }
98 static byte *aliasmax[NUMALIAS] = {
99 &antialias[0][7], &antialias[1][7], &antialias[2][7]
103 static byte *maplump; // pointer to the raw data for the automap background.
106 static short mapystart=0; // y-value for the start of the map bitmap...used in
107 //the parallax stuff.
108 static short mapxstart=0; //x-value for the bitmap.
110 //byte screens[][SCREENWIDTH*SCREENHEIGHT];
111 //void V_MarkRect (int x, int y, int width, int height);
115 void DrawWuLine(int X0, int Y0, int X1, int Y1, byte *BaseColor,
116 int NumLevels, unsigned short IntensityBits);
118 void AM_DrawDeathmatchStats(void);
119 static void DrawWorldTimer(void);
121 // Calculates the slope and slope according to the x-axis of a line
122 // segment in map coordinates (with the upright y-axis n' all) so
123 // that it can be used with the brain-dead drawing stuff.
125 // Ripped out for Heretic
127 void AM_getIslope(mline_t *ml, islope_t *is)
131 dy = ml->a.y - ml->b.y;
132 dx = ml->b.x - ml->a.x;
133 if (!dy) is->islp = (dx<0?-MAXINT:MAXINT);
134 else is->islp = FixedDiv(dx, dy);
135 if (!dx) is->slp = (dy<0?-MAXINT:MAXINT);
136 else is->slp = FixedDiv(dy, dx);
140 void AM_activateNewScale(void)
152 void AM_saveScaleAndLoc(void)
160 void AM_restoreScaleAndLoc(void)
170 m_x = plr->mo->x - m_w/2;
171 m_y = plr->mo->y - m_h/2;
176 // Change the scaling multipliers
177 scale_mtof = FixedDiv(f_w<<FRACBITS, m_w);
178 scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
181 // adds a marker at the current location
184 void AM_addMark(void)
186 markpoints[markpointnum].x = m_x + m_w/2;
187 markpoints[markpointnum].y = m_y + m_h/2;
188 markpointnum = (markpointnum + 1) % AM_NUMMARKPOINTS;
192 void AM_findMinMaxBoundaries(void)
197 min_x = min_y = MAXINT;
198 max_x = max_y = -MAXINT;
199 for (i=0;i<numvertexes;i++)
201 if (vertexes[i].x < min_x) min_x = vertexes[i].x;
202 else if (vertexes[i].x > max_x) max_x = vertexes[i].x;
203 if (vertexes[i].y < min_y) min_y = vertexes[i].y;
204 else if (vertexes[i].y > max_y) max_y = vertexes[i].y;
206 max_w = max_x - min_x;
207 max_h = max_y - min_y;
208 min_w = 2*PLAYERRADIUS;
209 min_h = 2*PLAYERRADIUS;
211 a = FixedDiv(f_w<<FRACBITS, max_w);
212 b = FixedDiv(f_h<<FRACBITS, max_h);
213 min_scale_mtof = a < b ? a : b;
215 max_scale_mtof = FixedDiv(f_h<<FRACBITS, 2*PLAYERRADIUS);
219 void AM_changeWindowLoc(void)
221 if (m_paninc.x || m_paninc.y)
230 if (m_x + m_w/2 > max_x)
235 else if (m_x + m_w/2 < min_x)
240 if (m_y + m_h/2 > max_y)
245 else if (m_y + m_h/2 < min_y)
251 mapxstart += MTOF(m_paninc.x+FRACUNIT/2);
252 mapystart -= MTOF(m_paninc.y+FRACUNIT/2);
253 if(mapxstart >= finit_width)
254 mapxstart -= finit_width;
256 mapxstart += finit_width;
257 if(mapystart >= finit_height)
258 mapystart -= finit_height;
260 mapystart += finit_height;
266 void AM_initVariables(void)
272 //static event_t st_notify = { ev_keyup, AM_MSGENTERED };
274 automapactive = true;
281 m_paninc.x = m_paninc.y = 0;
282 ftom_zoommul = FRACUNIT;
283 mtof_zoommul = FRACUNIT;
288 // find player to center on initially
289 if (!playeringame[pnum = consoleplayer])
290 for (pnum=0;pnum<MAXPLAYERS;pnum++) if (playeringame[pnum]) break;
291 plr = &players[pnum];
292 oldplr.x = plr->mo->x;
293 oldplr.y = plr->mo->y;
294 m_x = plr->mo->x - m_w/2;
295 m_y = plr->mo->y - m_h/2;
296 AM_changeWindowLoc();
298 // for saving & restoring
304 // load in the location of keys, if in baby mode
306 // memset(KeyPoints, 0, sizeof(vertex_t)*3);
307 if(gameskill == sk_baby)
309 for(think = thinkercap.next; think != &thinkercap; think = think->next)
311 if(think->function != P_MobjThinker)
315 mo = (mobj_t *)think;
319 // inform the status bar of the change
320 //c ST_Responder(&st_notify);
323 void AM_loadPics(void)
326 maplumpnum = W_GetNumForName("AUTOPAGE");
328 maplump = W_CacheLumpName("AUTOPAGE", PU_STATIC);
334 void AM_clearMarks(void)
337 for (i=0;i<AM_NUMMARKPOINTS;i++) markpoints[i].x = -1; // means empty
342 // should be called at the start of every level
343 // right now, i figure it out myself
345 void AM_LevelInit(void)
347 leveljuststarted = 0;
352 mapxstart = mapystart = 0;
357 AM_findMinMaxBoundaries();
358 scale_mtof = FixedDiv(min_scale_mtof, (int) (0.7*FRACUNIT));
359 if (scale_mtof > max_scale_mtof) scale_mtof = min_scale_mtof;
360 scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
363 static boolean stopped = true;
367 //static event_t st_notify = { 0, ev_keyup, AM_MSGEXITED };
370 automapactive = false;
371 // ST_Responder(&st_notify);
373 BorderNeedRefresh = true;
378 static int lastlevel = -1, lastepisode = -1;
380 if (!stopped) AM_Stop();
382 if(gamestate != GS_LEVEL)
384 return; // don't show automap if we aren't in a game!
386 if (lastlevel != gamemap || lastepisode != gameepisode)
390 lastepisode = gameepisode;
396 // set the window scale to the maximum size
398 void AM_minOutWindowScale(void)
400 scale_mtof = min_scale_mtof;
401 scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
402 AM_activateNewScale();
405 // set the window scale to the minimum size
407 void AM_maxOutWindowScale(void)
409 scale_mtof = max_scale_mtof;
410 scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
411 AM_activateNewScale();
414 boolean AM_Responder (event_t *ev)
417 static int cheatstate=0;
418 static int bigstate=0;
423 if (ev->type == ev_keydown && ev->data1 == AM_STARTKEY
424 && gamestate == GS_LEVEL)
432 else if (ev->type == ev_keydown)
437 case AM_PANRIGHTKEY: // pan right
438 if (!followplayer) m_paninc.x = FTOM(F_PANINC);
441 case AM_PANLEFTKEY: // pan left
442 if (!followplayer) m_paninc.x = -FTOM(F_PANINC);
445 case AM_PANUPKEY: // pan up
446 if (!followplayer) m_paninc.y = FTOM(F_PANINC);
449 case AM_PANDOWNKEY: // pan down
450 if (!followplayer) m_paninc.y = -FTOM(F_PANINC);
453 case AM_ZOOMOUTKEY: // zoom out
454 mtof_zoommul = M_ZOOMOUT;
455 ftom_zoommul = M_ZOOMIN;
457 case AM_ZOOMINKEY: // zoom in
458 mtof_zoommul = M_ZOOMIN;
459 ftom_zoommul = M_ZOOMOUT;
468 bigstate = !bigstate;
471 AM_saveScaleAndLoc();
472 AM_minOutWindowScale();
474 else AM_restoreScaleAndLoc();
477 followplayer = !followplayer;
480 followplayer ? AMSTR_FOLLOWON : AMSTR_FOLLOWOFF, true);
487 if(cheat_kills[ShowKillsCount] == ev->data1 && netgame && deathmatch)
490 if(ShowKillsCount == 5)
502 else if (ev->type == ev_keyup)
508 if (!followplayer) m_paninc.x = 0;
511 if (!followplayer) m_paninc.x = 0;
514 if (!followplayer) m_paninc.y = 0;
517 if (!followplayer) m_paninc.y = 0;
521 mtof_zoommul = FRACUNIT;
522 ftom_zoommul = FRACUNIT;
529 void AM_changeWindowScale(void)
532 // Change the scaling multipliers
533 scale_mtof = FixedMul(scale_mtof, mtof_zoommul);
534 scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
536 if (scale_mtof < min_scale_mtof) AM_minOutWindowScale();
537 else if (scale_mtof > max_scale_mtof) AM_maxOutWindowScale();
538 else AM_activateNewScale();
541 void AM_doFollowPlayer(void)
543 if (f_oldloc.x != plr->mo->x || f_oldloc.y != plr->mo->y)
545 // m_x = FTOM(MTOF(plr->mo->x - m_w/2));
546 // m_y = FTOM(MTOF(plr->mo->y - m_h/2));
547 // m_x = plr->mo->x - m_w/2;
548 // m_y = plr->mo->y - m_h/2;
549 m_x = FTOM(MTOF(plr->mo->x)) - m_w/2;
550 m_y = FTOM(MTOF(plr->mo->y)) - m_h/2;
554 // do the parallax parchment scrolling.
556 dmapx = (MTOF(plr->mo->x)-MTOF(f_oldloc.x)); //fixed point
557 dmapy = (MTOF(f_oldloc.y)-MTOF(plr->mo->y));
559 if(f_oldloc.x == MAXINT) //to eliminate an error when the user first
560 dmapx=0; //goes into the automap.
564 while(mapxstart >= finit_width)
565 mapxstart -= finit_width;
567 mapxstart += finit_width;
568 while(mapystart >= finit_height)
569 mapystart -= finit_height;
571 mapystart += finit_height;
573 f_oldloc.x = plr->mo->x;
574 f_oldloc.y = plr->mo->y;
578 // Ripped out for Heretic
580 void AM_updateLightLev(void)
583 //static int litelevels[] = { 0, 3, 5, 6, 6, 7, 7, 7 };
584 static int litelevels[] = { 0, 4, 7, 10, 12, 14, 15, 15 };
585 static int litelevelscnt = 0;
587 // Change light level
590 lightlev = litelevels[litelevelscnt++];
591 if (litelevelscnt == sizeof(litelevels)/sizeof(int)) litelevelscnt = 0;
592 nexttic = amclock + 6 - (amclock % 6);
597 void AM_Ticker (void)
600 if (!automapactive) return;
604 if (followplayer) AM_doFollowPlayer();
606 // Change the zoom if necessary
607 if (ftom_zoommul != FRACUNIT) AM_changeWindowScale();
609 // Change x,y location
610 if (m_paninc.x || m_paninc.y) AM_changeWindowLoc();
611 // Update light level
612 // AM_updateLightLev();
616 void AM_clearFB(int color)
630 dmapx = (MTOF(plr->mo->x)-MTOF(oldplr.x)); //fixed point
631 dmapy = (MTOF(oldplr.y)-MTOF(plr->mo->y));
633 oldplr.x = plr->mo->x;
634 oldplr.y = plr->mo->y;
635 // if(f_oldloc.x == MAXINT) //to eliminate an error when the user first
636 // dmapx=0; //goes into the automap.
637 mapxstart += dmapx>>1;
638 mapystart += dmapy>>1;
640 while(mapxstart >= finit_width)
641 mapxstart -= finit_width;
643 mapxstart += finit_width;
644 while(mapystart >= finit_height)
645 mapystart -= finit_height;
647 mapystart += finit_height;
651 mapxstart += (MTOF(m_paninc.x)>>1);
652 mapystart -= (MTOF(m_paninc.y)>>1);
653 if(mapxstart >= finit_width)
654 mapxstart -= finit_width;
656 mapxstart += finit_width;
657 if(mapystart >= finit_height)
658 mapystart -= finit_height;
660 mapystart += finit_height;
664 OGL_SetColorAndAlpha(1, 1, 1, 1);
666 OGL_SetFlat(W_GetNumForName("F_022")-firstflat);
667 scaler = sbarscale/20.0;
668 OGL_DrawCutRectTiled(0, finit_height+4, 320, 200-finit_height-4, 64, 64,
669 160-160*scaler+1, finit_height, 320*scaler-2, 200-finit_height);
671 OGL_SetPatch(lump=W_GetNumForName("bordb"));
672 OGL_DrawCutRectTiled(0, finit_height, 320, 4,
673 lumptexsizes[lump].w, lumptexsizes[lump].h,
674 160-160*scaler+1, finit_height, 320*scaler-2, 4);
676 OGL_SetRawImage(maplumpnum, 0); // We only want the left portion.
677 OGL_DrawRectTiled( 0, 0, finit_width,
678 /*(sbarscale<20)?200:*/ finit_height,
681 //blit the automap background to the screen.
682 j=mapystart*finit_width;
683 for(i = 0; i < SCREENHEIGHT-SBARHEIGHT; i++)
685 memcpy(screen+i*finit_width, maplump+j+mapxstart,
686 finit_width-mapxstart);
687 memcpy(screen+i*finit_width+finit_width-mapxstart, maplump+j,
690 if(j >= finit_height*finit_width)
694 // memcpy(screen, maplump, finit_width*finit_height);
695 // memset(fb, color, f_w*f_h);
699 // Based on Cohen-Sutherland clipping algorithm but with a slightly
700 // faster reject and precalculated slopes. If I need the speed, will
701 // hash algorithm to the common cases.
703 boolean AM_clipMline(mline_t *ml, fline_t *fl)
705 enum { LEFT=1, RIGHT=2, BOTTOM=4, TOP=8 };
706 register int outcode1 = 0, outcode2 = 0, outside; /* jim - added int */
710 #define DOOUTCODE(oc, mx, my) \
712 if ((my) < 0) (oc) |= TOP; \
713 else if ((my) >= f_h) (oc) |= BOTTOM; \
714 if ((mx) < 0) (oc) |= LEFT; \
715 else if ((mx) >= f_w) (oc) |= RIGHT
717 // do trivial rejects and outcodes
718 if (ml->a.y > m_y2) outcode1 = TOP;
719 else if (ml->a.y < m_y) outcode1 = BOTTOM;
720 if (ml->b.y > m_y2) outcode2 = TOP;
721 else if (ml->b.y < m_y) outcode2 = BOTTOM;
722 if (outcode1 & outcode2) return false; // trivially outside
724 if (ml->a.x < m_x) outcode1 |= LEFT;
725 else if (ml->a.x > m_x2) outcode1 |= RIGHT;
726 if (ml->b.x < m_x) outcode2 |= LEFT;
727 else if (ml->b.x > m_x2) outcode2 |= RIGHT;
728 if (outcode1 & outcode2) return false; // trivially outside
730 // transform to frame-buffer coordinates.
731 fl->a.x = CXMTOF(ml->a.x);
732 fl->a.y = CYMTOF(ml->a.y);
733 fl->b.x = CXMTOF(ml->b.x);
734 fl->b.y = CYMTOF(ml->b.y);
735 DOOUTCODE(outcode1, fl->a.x, fl->a.y);
736 DOOUTCODE(outcode2, fl->b.x, fl->b.y);
737 if (outcode1 & outcode2) return false;
739 while (outcode1 | outcode2)
741 // may be partially inside box
742 // find an outside point
743 if (outcode1) outside = outcode1;
744 else outside = outcode2;
748 dy = fl->a.y - fl->b.y;
749 dx = fl->b.x - fl->a.x;
750 tmp.x = fl->a.x + (dx*(fl->a.y))/dy;
753 else if (outside & BOTTOM)
755 dy = fl->a.y - fl->b.y;
756 dx = fl->b.x - fl->a.x;
757 tmp.x = fl->a.x + (dx*(fl->a.y-f_h))/dy;
760 else if (outside & RIGHT)
762 dy = fl->b.y - fl->a.y;
763 dx = fl->b.x - fl->a.x;
764 tmp.y = fl->a.y + (dy*(f_w-1 - fl->a.x))/dx;
767 else if (outside & LEFT)
769 dy = fl->b.y - fl->a.y;
770 dx = fl->b.x - fl->a.x;
771 tmp.y = fl->a.y + (dy*(-fl->a.x))/dx;
774 if (outside == outcode1)
777 DOOUTCODE(outcode1, fl->a.x, fl->a.y);
780 DOOUTCODE(outcode2, fl->b.x, fl->b.y);
782 if (outcode1 & outcode2) return false; // trivially outside
789 // Classic Bresenham w/ whatever optimizations I need for speed
791 void AM_drawFline(fline_t *fl, int color)
793 register int x, y, dx, dy, sx, sy, ax, ay, d;
799 DrawWuLine(fl->a.x, fl->a.y, fl->b.x, fl->b.y,
800 &antialias[0][0], 8, 3);
803 DrawWuLine(fl->a.x, fl->a.y, fl->b.x, fl->b.y,
804 &antialias[1][0], 8, 3);
807 DrawWuLine(fl->a.x, fl->a.y, fl->b.x, fl->b.y,
808 &antialias[2][0], 8, 3);
812 // For debugging only
813 if ( fl->a.x < 0 || fl->a.x >= f_w
814 || fl->a.y < 0 || fl->a.y >= f_h
815 || fl->b.x < 0 || fl->b.x >= f_w
816 || fl->b.y < 0 || fl->b.y >= f_h)
818 //fprintf(stderr, "fuck %d \r", fuck++);
822 #define DOT(xx,yy,cc) fb[(yy)*f_w+(xx)]=(cc) //the MACRO!
824 dx = fl->b.x - fl->a.x;
825 ax = 2 * (dx<0 ? -dx : dx);
828 dy = fl->b.y - fl->a.y;
829 ay = 2 * (dy<0 ? -dy : dy);
841 if (x == fl->b.x) return;
855 if (y == fl->b.y) return;
869 /* Wu antialiased line drawer.
870 * (X0,Y0),(X1,Y1) = line to draw
871 * BaseColor = color # of first color in block used for antialiasing, the
872 * 100% intensity version of the drawing color
873 * NumLevels = size of color block, with BaseColor+NumLevels-1 being the
874 * 0% intensity version of the drawing color
875 * IntensityBits = log base 2 of NumLevels; the # of bits used to describe
876 * the intensity of the drawing color. 2**IntensityBits==NumLevels
878 void PUTDOT(short xx,short yy,byte *cc, byte *cm)
881 static int oldyyshifted;
886 else if(xx > (finit_width - 32))
887 cc += 7-((finit_width-xx) >> 2);
888 // if(cc==oldcc) //make sure that we don't double fade the corners.
892 else if(yy > (finit_height - 32))
893 cc += 7-((finit_height-yy) >> 2);
895 if(cc > cm && cm != NULL)
899 else if(cc > oldcc+6) // don't let the color escape from the fade table...
908 else if(yy == oldyy-1)
916 oldyyshifted = yy*320;
918 fb[oldyyshifted+xx] = *(cc);
919 // fb[(yy)*f_w+(xx)]=*(cc);
922 void DrawWuLine(int X0, int Y0, int X1, int Y1, byte *BaseColor,
923 int NumLevels, unsigned short IntensityBits)
925 unsigned short IntensityShift, ErrorAdj, ErrorAcc;
926 unsigned short ErrorAccTemp, Weighting, WeightingComplementMask;
927 short DeltaX, DeltaY, Temp, XDir;
929 /* Make sure the line runs top to bottom */
931 Temp = Y0; Y0 = Y1; Y1 = Temp;
932 Temp = X0; X0 = X1; X1 = Temp;
934 /* Draw the initial pixel, which is always exactly intersected by
935 the line and so needs no weighting */
936 PUTDOT(X0, Y0, &BaseColor[0], NULL);
938 if ((DeltaX = X1 - X0) >= 0) {
942 DeltaX = -DeltaX; /* make DeltaX positive */
944 /* Special-case horizontal, vertical, and diagonal lines, which
945 require no weighting because they go right through the center of
947 if ((DeltaY = Y1 - Y0) == 0) {
948 /* Horizontal line */
949 while (DeltaX-- != 0) {
951 PUTDOT(X0, Y0, &BaseColor[0], NULL);
959 PUTDOT(X0, Y0, &BaseColor[0], NULL);
960 } while (--DeltaY != 0);
964 if (DeltaX == DeltaY) {
968 PUTDOT(X0, Y0, &BaseColor[0], NULL);
969 } while (--DeltaY != 0);
972 /* Line is not horizontal, diagonal, or vertical */
973 ErrorAcc = 0; /* initialize the line error accumulator to 0 */
974 /* # of bits by which to shift ErrorAcc to get intensity level */
975 IntensityShift = 16 - IntensityBits;
976 /* Mask used to flip all bits in an intensity weighting, producing the
977 result (1 - intensity weighting) */
978 WeightingComplementMask = NumLevels - 1;
979 /* Is this an X-major or Y-major line? */
980 if (DeltaY > DeltaX) {
981 /* Y-major line; calculate 16-bit fixed-point fractional part of a
982 pixel that X advances each time Y advances 1 pixel, truncating the
983 result so that we won't overrun the endpoint along the X axis */
984 ErrorAdj = ((unsigned long) DeltaX << 16) / (unsigned long) DeltaY;
985 /* Draw all pixels other than the first and last */
987 ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */
988 ErrorAcc += ErrorAdj; /* calculate error for next pixel */
989 if (ErrorAcc <= ErrorAccTemp) {
990 /* The error accumulator turned over, so advance the X coord */
993 Y0++; /* Y-major, so always advance Y */
994 /* The IntensityBits most significant bits of ErrorAcc give us the
995 intensity weighting for this pixel, and the complement of the
996 weighting for the paired pixel */
997 Weighting = ErrorAcc >> IntensityShift;
998 PUTDOT(X0, Y0, &BaseColor[Weighting], &BaseColor[7]);
999 PUTDOT(X0 + XDir, Y0,
1000 &BaseColor[(Weighting ^ WeightingComplementMask)], &BaseColor[7]);
1002 /* Draw the final pixel, which is always exactly intersected by the line
1003 and so needs no weighting */
1004 PUTDOT(X1, Y1, &BaseColor[0], NULL);
1007 /* It's an X-major line; calculate 16-bit fixed-point fractional part of a
1008 pixel that Y advances each time X advances 1 pixel, truncating the
1009 result to avoid overrunning the endpoint along the X axis */
1010 ErrorAdj = ((unsigned long) DeltaY << 16) / (unsigned long) DeltaX;
1011 /* Draw all pixels other than the first and last */
1013 ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */
1014 ErrorAcc += ErrorAdj; /* calculate error for next pixel */
1015 if (ErrorAcc <= ErrorAccTemp) {
1016 /* The error accumulator turned over, so advance the Y coord */
1019 X0 += XDir; /* X-major, so always advance X */
1020 /* The IntensityBits most significant bits of ErrorAcc give us the
1021 intensity weighting for this pixel, and the complement of the
1022 weighting for the paired pixel */
1023 Weighting = ErrorAcc >> IntensityShift;
1024 PUTDOT(X0, Y0, &BaseColor[Weighting], &BaseColor[7]);
1026 &BaseColor[(Weighting ^ WeightingComplementMask)], &BaseColor[7]);
1029 /* Draw the final pixel, which is always exactly intersected by the line
1030 and so needs no weighting */
1031 PUTDOT(X1, Y1, &BaseColor[0], NULL);
1034 void AM_drawMline(mline_t *ml, int color)
1037 byte *palette = W_CacheLumpName("playpal", PU_CACHE);
1038 byte r = palette[color*3], g = palette[color*3+1], b = palette[color*3+2];
1040 OGL_DrawLine( FIX2FLT(CXMTOFX(ml->a.x)), FIX2FLT(CYMTOFX(ml->a.y))/1.2,
1041 FIX2FLT(CXMTOFX(ml->b.x)), FIX2FLT(CYMTOFX(ml->b.y))/1.2,
1042 r/255.0, g/255.0, b/255.0, 1 );
1046 if (AM_clipMline(ml, &fl))
1047 AM_drawFline(&fl, color); // draws it on frame buffer using fb coords
1051 void AM_drawGrid(int color)
1057 // Figure out start of vertical gridlines
1059 if ((start-bmaporgx)%(MAPBLOCKUNITS<<FRACBITS))
1060 start += (MAPBLOCKUNITS<<FRACBITS)
1061 - ((start-bmaporgx)%(MAPBLOCKUNITS<<FRACBITS));
1064 // draw vertical gridlines
1067 for (x=start; x<end; x+=(MAPBLOCKUNITS<<FRACBITS))
1071 AM_drawMline(&ml, color);
1074 // Figure out start of horizontal gridlines
1076 if ((start-bmaporgy)%(MAPBLOCKUNITS<<FRACBITS))
1077 start += (MAPBLOCKUNITS<<FRACBITS)
1078 - ((start-bmaporgy)%(MAPBLOCKUNITS<<FRACBITS));
1081 // draw horizontal gridlines
1084 for (y=start; y<end; y+=(MAPBLOCKUNITS<<FRACBITS))
1088 AM_drawMline(&ml, color);
1092 void AM_drawWalls(void)
1097 //OGL_SetNoTexture();
1098 glDisable( GL_TEXTURE_2D );
1101 glBegin(GL_LINES); // We'll draw pretty much all of them.
1102 for(i=0;i<numlines;i++)
1104 if (cheating || (lines[i].flags & ML_MAPPED))
1106 if ((lines[i].flags & LINE_NEVERSEE) && !cheating)
1108 if (!lines[i].backsector)
1110 OGL_SetColor(WALLCOLORS);
1114 if (lines[i].flags & ML_SECRET) // secret door
1116 if (cheating) //AM_drawMline(&l, 0);
1119 OGL_SetColor(WALLCOLORS);
1121 else if(lines[i].special == 13 || lines[i].special == 83)
1122 { // Locked door line -- all locked doors are greed
1123 OGL_SetColor(GREENKEY);
1125 else if(lines[i].special == 70 || lines[i].special == 71)
1126 { // intra-level teleports are blue
1127 OGL_SetColor(BLUEKEY);
1129 else if(lines[i].special == 74 || lines[i].special == 75)
1130 { // inter-level teleport/game-winning exit -- both are red
1131 OGL_SetColor(BLOODRED);
1133 else if (lines[i].backsector->floorheight
1134 != lines[i].frontsector->floorheight)
1136 // floor level change
1137 OGL_SetColor(FDWALLCOLORS);
1139 else if (lines[i].backsector->ceilingheight
1140 != lines[i].frontsector->ceilingheight)
1142 // ceiling level change
1143 OGL_SetColor(CDWALLCOLORS);
1147 OGL_SetColor(TSWALLCOLORS);
1152 else if (plr->powers[pw_allmap])
1154 if (!(lines[i].flags & LINE_NEVERSEE))
1155 OGL_SetColor(GRAYS+3);
1161 // Draw the line. 1.2 is the to-square aspect corrector.
1162 glVertex2f( FIX2FLT(CXMTOFX(lines[i].v1->x)),
1163 FIX2FLT(CYMTOFX(lines[i].v1->y))/1.2);
1164 glVertex2f( FIX2FLT(CXMTOFX(lines[i].v2->x)),
1165 FIX2FLT(CYMTOFX(lines[i].v2->y))/1.2);
1169 glEnable( GL_TEXTURE_2D );
1173 for (i=0;i<numlines;i++)
1175 l.a.x = lines[i].v1->x;
1176 l.a.y = lines[i].v1->y;
1177 l.b.x = lines[i].v2->x;
1178 l.b.y = lines[i].v2->y;
1179 if (cheating || (lines[i].flags & ML_MAPPED))
1181 if ((lines[i].flags & LINE_NEVERSEE) && !cheating)
1183 if (!lines[i].backsector)
1185 AM_drawMline(&l, WALLCOLORS+lightlev);
1187 if (lines[i].flags & ML_SECRET) // secret door
1189 if (cheating) AM_drawMline(&l, 0);
1190 else AM_drawMline(&l, WALLCOLORS+lightlev);
1192 else if(lines[i].special == 13 || lines[i].special == 83)
1193 { // Locked door line -- all locked doors are greed
1194 AM_drawMline(&l, GREENKEY);
1196 else if(lines[i].special == 70 || lines[i].special == 71)
1197 { // intra-level teleports are blue
1198 AM_drawMline(&l, BLUEKEY);
1200 else if(lines[i].special == 74 || lines[i].special == 75)
1201 { // inter-level teleport/game-winning exit -- both are red
1202 AM_drawMline(&l, BLOODRED);
1204 else if (lines[i].backsector->floorheight
1205 != lines[i].frontsector->floorheight) {
1206 AM_drawMline(&l, FDWALLCOLORS + lightlev); // floor level change
1207 } else if (lines[i].backsector->ceilingheight
1208 != lines[i].frontsector->ceilingheight) {
1209 AM_drawMline(&l, CDWALLCOLORS+lightlev); // ceiling level change
1210 } else if (cheating) {
1211 AM_drawMline(&l, TSWALLCOLORS+lightlev);
1214 } else if (plr->powers[pw_allmap])
1216 if (!(lines[i].flags & LINE_NEVERSEE)) AM_drawMline(&l, GRAYS+3);
1222 void AM_rotate(fixed_t *x, fixed_t *y, angle_t a)
1226 tmpx = FixedMul(*x,finecosine[a>>ANGLETOFINESHIFT])
1227 - FixedMul(*y,finesine[a>>ANGLETOFINESHIFT]);
1228 *y = FixedMul(*x,finesine[a>>ANGLETOFINESHIFT])
1229 + FixedMul(*y,finecosine[a>>ANGLETOFINESHIFT]);
1233 void AM_drawLineCharacter(mline_t *lineguy, int lineguylines, fixed_t scale,
1234 angle_t angle, int color, fixed_t x, fixed_t y)
1239 for (i=0;i<lineguylines;i++)
1241 l.a.x = lineguy[i].a.x;
1242 l.a.y = lineguy[i].a.y;
1245 l.a.x = FixedMul(scale, l.a.x);
1246 l.a.y = FixedMul(scale, l.a.y);
1248 if (angle) AM_rotate(&l.a.x, &l.a.y, angle);
1252 l.b.x = lineguy[i].b.x;
1253 l.b.y = lineguy[i].b.y;
1256 l.b.x = FixedMul(scale, l.b.x);
1257 l.b.y = FixedMul(scale, l.b.y);
1259 if (angle) AM_rotate(&l.b.x, &l.b.y, angle);
1263 AM_drawMline(&l, color);
1267 void AM_drawPlayers(void)
1271 static int their_colors[] =
1282 int their_color = -1;
1287 AM_drawLineCharacter(player_arrow, NUMPLYRLINES, 0, plr->mo->angle,
1288 WHITE, plr->mo->x, plr->mo->y);
1292 for(i = 0; i < MAXPLAYERS; i++)
1296 if(deathmatch && !singledemo && p != plr)
1300 if (!playeringame[i]) continue;
1301 color = their_colors[their_color];
1302 AM_drawLineCharacter(player_arrow, NUMPLYRLINES, 0, p->mo->angle,
1303 color, p->mo->x, p->mo->y);
1307 void AM_drawThings(int colors, int colorrange)
1312 for (i=0;i<numsectors;i++)
1314 t = sectors[i].thinglist;
1317 AM_drawLineCharacter(thintriangle_guy, NUMTHINTRIANGLEGUYLINES,
1318 16<<FRACBITS, t->angle, colors+lightlev, t->x, t->y);
1325 void AM_drawMarks(void)
1327 int i, fx, fy, w, h;
1329 for (i=0;i<AM_NUMMARKPOINTS;i++)
1331 if (markpoints[i].x != -1)
1333 w = SHORT(marknums[i]->width);
1334 h = SHORT(marknums[i]->height);
1335 fx = CXMTOF(markpoints[i].x);
1336 fy = CYMTOF(markpoints[i].y);
1337 if (fx >= f_x && fx <= f_w - w && fy >= f_y && fy <= f_h - h)
1338 V_DrawPatch(fx, fy, marknums[i]);
1344 void AM_drawkeys(void)
1346 if(KeyPoints[0].x != 0 || KeyPoints[0].y != 0)
1348 AM_drawLineCharacter(keysquare, NUMKEYSQUARELINES, 0, 0, YELLOWKEY,
1349 KeyPoints[0].x, KeyPoints[0].y);
1351 if(KeyPoints[1].x != 0 || KeyPoints[1].y != 0)
1353 AM_drawLineCharacter(keysquare, NUMKEYSQUARELINES, 0, 0, GREENKEY,
1354 KeyPoints[1].x, KeyPoints[1].y);
1356 if(KeyPoints[2].x != 0 || KeyPoints[2].y != 0)
1358 AM_drawLineCharacter(keysquare, NUMKEYSQUARELINES, 0, 0, BLUEKEY,
1359 KeyPoints[2].x, KeyPoints[2].y);
1365 void AM_drawCrosshair(int color)
1367 fb[(f_w*(f_h+1))/2] = color; // single point for now
1373 void AM_OGL_SetupState()
1375 float ys = screenHeight/200.0;
1377 // Let's set up a scissor box to clip the map lines and stuff.
1378 glPushAttrib(GL_SCISSOR_BIT);
1379 glScissor(0, screenHeight-finit_height*ys, screenWidth, finit_height*ys);
1380 glEnable(GL_SCISSOR_TEST);
1383 void AM_OGL_RestoreState()
1390 void AM_Drawer (void)
1392 if (!automapactive) return;
1394 UpdateState |= I_FULLSCRN;
1397 // Update the height (in case sbarscale has been changed).
1398 finit_height = SCREENHEIGHT-SBARHEIGHT*sbarscale/20/*-3*/;
1401 AM_clearFB(BACKGROUND);
1404 AM_OGL_SetupState();
1407 if (grid) AM_drawGrid(GRIDCOLORS);
1412 if (cheating==2) AM_drawThings(THINGCOLORS, THINGRANGE);
1414 // AM_drawCrosshair(XHAIRCOLORS);
1416 // if(gameskill == sk_baby) AM_drawkeys();
1419 AM_OGL_RestoreState();
1422 MN_DrTextA(P_GetMapName(gamemap), 38, 144);
1423 if(ShowKills && netgame && deathmatch)
1425 AM_DrawDeathmatchStats();
1428 // V_MarkRect(f_x, f_y, f_w, f_h);
1432 //===========================================================================
1434 // AM_DrawDeathmatchStats
1436 //===========================================================================
1438 // 8-player note: Proper player color names here, too
1440 char *PlayerColorText[MAXPLAYERS] =
1452 void AM_DrawDeathmatchStats(void)
1455 int fragCount[MAXPLAYERS];
1456 int order[MAXPLAYERS];
1457 char textBuffer[80];
1460 for(i = 0; i < MAXPLAYERS; i++)
1465 for(i = 0; i < MAXPLAYERS; i++)
1467 if(!playeringame[i])
1473 for(j = 0; j < MAXPLAYERS; j++)
1477 fragCount[i] += players[i].frags[j];
1480 for(k = 0; k < MAXPLAYERS; k++)
1487 else if(fragCount[i] > fragCount[order[k]])
1489 for(m = MAXPLAYERS-1; m > k; m--)
1491 order[m] = order[m-1];
1500 for(i = 0; i < MAXPLAYERS; i++)
1502 if(!playeringame[order[i]])
1508 MN_DrTextA(PlayerColorText[order[i]], 8, yPosition);
1509 sprintf(textBuffer, "%d", fragCount[order[i]]);
1510 MN_DrTextA(textBuffer, 80, yPosition);
1516 //===========================================================================
1520 //===========================================================================
1522 static void DrawWorldTimer(void)
1529 char timeBuffer[15];
1532 worldTimer = players[consoleplayer].worldTimer;
1535 days = worldTimer/86400;
1536 worldTimer -= days*86400;
1537 hours = worldTimer/3600;
1538 worldTimer -= hours*3600;
1539 minutes = worldTimer/60;
1540 worldTimer -= minutes*60;
1541 seconds = worldTimer;
1543 sprintf(timeBuffer, "%.2d : %.2d : %.2d", hours, minutes,seconds);
1544 MN_DrTextA(timeBuffer, 240, 8);
1550 sprintf(dayBuffer, "%.2d DAY", days);
1554 sprintf(dayBuffer, "%.2d DAYS", days);
1556 MN_DrTextA(dayBuffer, 240, 20);
1559 MN_DrTextA("YOU FREAK!!!", 230, 35);