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 else /* avoid compiler warning */
779 if (outside == outcode1)
782 DOOUTCODE(outcode1, fl->a.x, fl->a.y);
785 DOOUTCODE(outcode2, fl->b.x, fl->b.y);
787 if (outcode1 & outcode2) return false; // trivially outside
794 // Classic Bresenham w/ whatever optimizations I need for speed
796 void AM_drawFline(fline_t *fl, int color)
798 register int x, y, dx, dy, sx, sy, ax, ay, d;
804 DrawWuLine(fl->a.x, fl->a.y, fl->b.x, fl->b.y,
805 &antialias[0][0], 8, 3);
808 DrawWuLine(fl->a.x, fl->a.y, fl->b.x, fl->b.y,
809 &antialias[1][0], 8, 3);
812 DrawWuLine(fl->a.x, fl->a.y, fl->b.x, fl->b.y,
813 &antialias[2][0], 8, 3);
817 // For debugging only
818 if ( fl->a.x < 0 || fl->a.x >= f_w
819 || fl->a.y < 0 || fl->a.y >= f_h
820 || fl->b.x < 0 || fl->b.x >= f_w
821 || fl->b.y < 0 || fl->b.y >= f_h)
823 //fprintf(stderr, "fuck %d \r", fuck++);
827 #define DOT(xx,yy,cc) fb[(yy)*f_w+(xx)]=(cc) //the MACRO!
829 dx = fl->b.x - fl->a.x;
830 ax = 2 * (dx<0 ? -dx : dx);
833 dy = fl->b.y - fl->a.y;
834 ay = 2 * (dy<0 ? -dy : dy);
846 if (x == fl->b.x) return;
860 if (y == fl->b.y) return;
874 /* Wu antialiased line drawer.
875 * (X0,Y0),(X1,Y1) = line to draw
876 * BaseColor = color # of first color in block used for antialiasing, the
877 * 100% intensity version of the drawing color
878 * NumLevels = size of color block, with BaseColor+NumLevels-1 being the
879 * 0% intensity version of the drawing color
880 * IntensityBits = log base 2 of NumLevels; the # of bits used to describe
881 * the intensity of the drawing color. 2**IntensityBits==NumLevels
883 void PUTDOT(short xx,short yy,byte *cc, byte *cm)
886 static int oldyyshifted;
891 else if(xx > (finit_width - 32))
892 cc += 7-((finit_width-xx) >> 2);
893 // if(cc==oldcc) //make sure that we don't double fade the corners.
897 else if(yy > (finit_height - 32))
898 cc += 7-((finit_height-yy) >> 2);
900 if(cc > cm && cm != NULL)
904 else if(cc > oldcc+6) // don't let the color escape from the fade table...
913 else if(yy == oldyy-1)
921 oldyyshifted = yy*320;
923 fb[oldyyshifted+xx] = *(cc);
924 // fb[(yy)*f_w+(xx)]=*(cc);
927 void DrawWuLine(int X0, int Y0, int X1, int Y1, byte *BaseColor,
928 int NumLevels, unsigned short IntensityBits)
930 unsigned short IntensityShift, ErrorAdj, ErrorAcc;
931 unsigned short ErrorAccTemp, Weighting, WeightingComplementMask;
932 short DeltaX, DeltaY, Temp, XDir;
934 /* Make sure the line runs top to bottom */
936 Temp = Y0; Y0 = Y1; Y1 = Temp;
937 Temp = X0; X0 = X1; X1 = Temp;
939 /* Draw the initial pixel, which is always exactly intersected by
940 the line and so needs no weighting */
941 PUTDOT(X0, Y0, &BaseColor[0], NULL);
943 if ((DeltaX = X1 - X0) >= 0) {
947 DeltaX = -DeltaX; /* make DeltaX positive */
949 /* Special-case horizontal, vertical, and diagonal lines, which
950 require no weighting because they go right through the center of
952 if ((DeltaY = Y1 - Y0) == 0) {
953 /* Horizontal line */
954 while (DeltaX-- != 0) {
956 PUTDOT(X0, Y0, &BaseColor[0], NULL);
964 PUTDOT(X0, Y0, &BaseColor[0], NULL);
965 } while (--DeltaY != 0);
969 if (DeltaX == DeltaY) {
973 PUTDOT(X0, Y0, &BaseColor[0], NULL);
974 } while (--DeltaY != 0);
977 /* Line is not horizontal, diagonal, or vertical */
978 ErrorAcc = 0; /* initialize the line error accumulator to 0 */
979 /* # of bits by which to shift ErrorAcc to get intensity level */
980 IntensityShift = 16 - IntensityBits;
981 /* Mask used to flip all bits in an intensity weighting, producing the
982 result (1 - intensity weighting) */
983 WeightingComplementMask = NumLevels - 1;
984 /* Is this an X-major or Y-major line? */
985 if (DeltaY > DeltaX) {
986 /* Y-major line; calculate 16-bit fixed-point fractional part of a
987 pixel that X advances each time Y advances 1 pixel, truncating the
988 result so that we won't overrun the endpoint along the X axis */
989 ErrorAdj = ((unsigned long) DeltaX << 16) / (unsigned long) DeltaY;
990 /* Draw all pixels other than the first and last */
992 ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */
993 ErrorAcc += ErrorAdj; /* calculate error for next pixel */
994 if (ErrorAcc <= ErrorAccTemp) {
995 /* The error accumulator turned over, so advance the X coord */
998 Y0++; /* Y-major, so always advance Y */
999 /* The IntensityBits most significant bits of ErrorAcc give us the
1000 intensity weighting for this pixel, and the complement of the
1001 weighting for the paired pixel */
1002 Weighting = ErrorAcc >> IntensityShift;
1003 PUTDOT(X0, Y0, &BaseColor[Weighting], &BaseColor[7]);
1004 PUTDOT(X0 + XDir, Y0,
1005 &BaseColor[(Weighting ^ WeightingComplementMask)], &BaseColor[7]);
1007 /* Draw the final pixel, which is always exactly intersected by the line
1008 and so needs no weighting */
1009 PUTDOT(X1, Y1, &BaseColor[0], NULL);
1012 /* It's an X-major line; calculate 16-bit fixed-point fractional part of a
1013 pixel that Y advances each time X advances 1 pixel, truncating the
1014 result to avoid overrunning the endpoint along the X axis */
1015 ErrorAdj = ((unsigned long) DeltaY << 16) / (unsigned long) DeltaX;
1016 /* Draw all pixels other than the first and last */
1018 ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */
1019 ErrorAcc += ErrorAdj; /* calculate error for next pixel */
1020 if (ErrorAcc <= ErrorAccTemp) {
1021 /* The error accumulator turned over, so advance the Y coord */
1024 X0 += XDir; /* X-major, so always advance X */
1025 /* The IntensityBits most significant bits of ErrorAcc give us the
1026 intensity weighting for this pixel, and the complement of the
1027 weighting for the paired pixel */
1028 Weighting = ErrorAcc >> IntensityShift;
1029 PUTDOT(X0, Y0, &BaseColor[Weighting], &BaseColor[7]);
1031 &BaseColor[(Weighting ^ WeightingComplementMask)], &BaseColor[7]);
1034 /* Draw the final pixel, which is always exactly intersected by the line
1035 and so needs no weighting */
1036 PUTDOT(X1, Y1, &BaseColor[0], NULL);
1039 void AM_drawMline(mline_t *ml, int color)
1042 byte *palette = W_CacheLumpName("playpal", PU_CACHE);
1043 byte r = palette[color*3], g = palette[color*3+1], b = palette[color*3+2];
1045 OGL_DrawLine( FIX2FLT(CXMTOFX(ml->a.x)), FIX2FLT(CYMTOFX(ml->a.y))/1.2,
1046 FIX2FLT(CXMTOFX(ml->b.x)), FIX2FLT(CYMTOFX(ml->b.y))/1.2,
1047 r/255.0, g/255.0, b/255.0, 1 );
1051 if (AM_clipMline(ml, &fl))
1052 AM_drawFline(&fl, color); // draws it on frame buffer using fb coords
1056 void AM_drawGrid(int color)
1062 // Figure out start of vertical gridlines
1064 if ((start-bmaporgx)%(MAPBLOCKUNITS<<FRACBITS))
1065 start += (MAPBLOCKUNITS<<FRACBITS)
1066 - ((start-bmaporgx)%(MAPBLOCKUNITS<<FRACBITS));
1069 // draw vertical gridlines
1072 for (x=start; x<end; x+=(MAPBLOCKUNITS<<FRACBITS))
1076 AM_drawMline(&ml, color);
1079 // Figure out start of horizontal gridlines
1081 if ((start-bmaporgy)%(MAPBLOCKUNITS<<FRACBITS))
1082 start += (MAPBLOCKUNITS<<FRACBITS)
1083 - ((start-bmaporgy)%(MAPBLOCKUNITS<<FRACBITS));
1086 // draw horizontal gridlines
1089 for (y=start; y<end; y+=(MAPBLOCKUNITS<<FRACBITS))
1093 AM_drawMline(&ml, color);
1097 void AM_drawWalls(void)
1102 //OGL_SetNoTexture();
1103 glDisable( GL_TEXTURE_2D );
1106 glBegin(GL_LINES); // We'll draw pretty much all of them.
1107 for(i=0;i<numlines;i++)
1109 if (cheating || (lines[i].flags & ML_MAPPED))
1111 if ((lines[i].flags & LINE_NEVERSEE) && !cheating)
1113 if (!lines[i].backsector)
1115 OGL_SetColor(WALLCOLORS);
1119 if (lines[i].flags & ML_SECRET) // secret door
1121 if (cheating) //AM_drawMline(&l, 0);
1124 OGL_SetColor(WALLCOLORS);
1126 else if(lines[i].special == 13 || lines[i].special == 83)
1127 { // Locked door line -- all locked doors are greed
1128 OGL_SetColor(GREENKEY);
1130 else if(lines[i].special == 70 || lines[i].special == 71)
1131 { // intra-level teleports are blue
1132 OGL_SetColor(BLUEKEY);
1134 else if(lines[i].special == 74 || lines[i].special == 75)
1135 { // inter-level teleport/game-winning exit -- both are red
1136 OGL_SetColor(BLOODRED);
1138 else if (lines[i].backsector->floorheight
1139 != lines[i].frontsector->floorheight)
1141 // floor level change
1142 OGL_SetColor(FDWALLCOLORS);
1144 else if (lines[i].backsector->ceilingheight
1145 != lines[i].frontsector->ceilingheight)
1147 // ceiling level change
1148 OGL_SetColor(CDWALLCOLORS);
1152 OGL_SetColor(TSWALLCOLORS);
1157 else if (plr->powers[pw_allmap])
1159 if (!(lines[i].flags & LINE_NEVERSEE))
1160 OGL_SetColor(GRAYS+3);
1166 // Draw the line. 1.2 is the to-square aspect corrector.
1167 glVertex2f( FIX2FLT(CXMTOFX(lines[i].v1->x)),
1168 FIX2FLT(CYMTOFX(lines[i].v1->y))/1.2);
1169 glVertex2f( FIX2FLT(CXMTOFX(lines[i].v2->x)),
1170 FIX2FLT(CYMTOFX(lines[i].v2->y))/1.2);
1174 glEnable( GL_TEXTURE_2D );
1178 for (i=0;i<numlines;i++)
1180 l.a.x = lines[i].v1->x;
1181 l.a.y = lines[i].v1->y;
1182 l.b.x = lines[i].v2->x;
1183 l.b.y = lines[i].v2->y;
1184 if (cheating || (lines[i].flags & ML_MAPPED))
1186 if ((lines[i].flags & LINE_NEVERSEE) && !cheating)
1188 if (!lines[i].backsector)
1190 AM_drawMline(&l, WALLCOLORS+lightlev);
1192 if (lines[i].flags & ML_SECRET) // secret door
1194 if (cheating) AM_drawMline(&l, 0);
1195 else AM_drawMline(&l, WALLCOLORS+lightlev);
1197 else if(lines[i].special == 13 || lines[i].special == 83)
1198 { // Locked door line -- all locked doors are greed
1199 AM_drawMline(&l, GREENKEY);
1201 else if(lines[i].special == 70 || lines[i].special == 71)
1202 { // intra-level teleports are blue
1203 AM_drawMline(&l, BLUEKEY);
1205 else if(lines[i].special == 74 || lines[i].special == 75)
1206 { // inter-level teleport/game-winning exit -- both are red
1207 AM_drawMline(&l, BLOODRED);
1209 else if (lines[i].backsector->floorheight
1210 != lines[i].frontsector->floorheight) {
1211 AM_drawMline(&l, FDWALLCOLORS + lightlev); // floor level change
1212 } else if (lines[i].backsector->ceilingheight
1213 != lines[i].frontsector->ceilingheight) {
1214 AM_drawMline(&l, CDWALLCOLORS+lightlev); // ceiling level change
1215 } else if (cheating) {
1216 AM_drawMline(&l, TSWALLCOLORS+lightlev);
1219 } else if (plr->powers[pw_allmap])
1221 if (!(lines[i].flags & LINE_NEVERSEE)) AM_drawMline(&l, GRAYS+3);
1227 void AM_rotate(fixed_t *x, fixed_t *y, angle_t a)
1231 tmpx = FixedMul(*x,finecosine[a>>ANGLETOFINESHIFT])
1232 - FixedMul(*y,finesine[a>>ANGLETOFINESHIFT]);
1233 *y = FixedMul(*x,finesine[a>>ANGLETOFINESHIFT])
1234 + FixedMul(*y,finecosine[a>>ANGLETOFINESHIFT]);
1238 void AM_drawLineCharacter(mline_t *lineguy, int lineguylines, fixed_t scale,
1239 angle_t angle, int color, fixed_t x, fixed_t y)
1244 for (i=0;i<lineguylines;i++)
1246 l.a.x = lineguy[i].a.x;
1247 l.a.y = lineguy[i].a.y;
1250 l.a.x = FixedMul(scale, l.a.x);
1251 l.a.y = FixedMul(scale, l.a.y);
1253 if (angle) AM_rotate(&l.a.x, &l.a.y, angle);
1257 l.b.x = lineguy[i].b.x;
1258 l.b.y = lineguy[i].b.y;
1261 l.b.x = FixedMul(scale, l.b.x);
1262 l.b.y = FixedMul(scale, l.b.y);
1264 if (angle) AM_rotate(&l.b.x, &l.b.y, angle);
1268 AM_drawMline(&l, color);
1272 void AM_drawPlayers(void)
1276 static int their_colors[] =
1287 int their_color = -1;
1292 AM_drawLineCharacter(player_arrow, NUMPLYRLINES, 0, plr->mo->angle,
1293 WHITE, plr->mo->x, plr->mo->y);
1297 for(i = 0; i < MAXPLAYERS; i++)
1301 if(deathmatch && !singledemo && p != plr)
1305 if (!playeringame[i]) continue;
1306 color = their_colors[their_color];
1307 AM_drawLineCharacter(player_arrow, NUMPLYRLINES, 0, p->mo->angle,
1308 color, p->mo->x, p->mo->y);
1312 void AM_drawThings(int colors, int colorrange)
1317 for (i=0;i<numsectors;i++)
1319 t = sectors[i].thinglist;
1322 AM_drawLineCharacter(thintriangle_guy, NUMTHINTRIANGLEGUYLINES,
1323 16<<FRACBITS, t->angle, colors+lightlev, t->x, t->y);
1330 void AM_drawMarks(void)
1332 int i, fx, fy, w, h;
1334 for (i=0;i<AM_NUMMARKPOINTS;i++)
1336 if (markpoints[i].x != -1)
1338 w = SHORT(marknums[i]->width);
1339 h = SHORT(marknums[i]->height);
1340 fx = CXMTOF(markpoints[i].x);
1341 fy = CYMTOF(markpoints[i].y);
1342 if (fx >= f_x && fx <= f_w - w && fy >= f_y && fy <= f_h - h)
1343 V_DrawPatch(fx, fy, marknums[i]);
1349 void AM_drawkeys(void)
1351 if(KeyPoints[0].x != 0 || KeyPoints[0].y != 0)
1353 AM_drawLineCharacter(keysquare, NUMKEYSQUARELINES, 0, 0, YELLOWKEY,
1354 KeyPoints[0].x, KeyPoints[0].y);
1356 if(KeyPoints[1].x != 0 || KeyPoints[1].y != 0)
1358 AM_drawLineCharacter(keysquare, NUMKEYSQUARELINES, 0, 0, GREENKEY,
1359 KeyPoints[1].x, KeyPoints[1].y);
1361 if(KeyPoints[2].x != 0 || KeyPoints[2].y != 0)
1363 AM_drawLineCharacter(keysquare, NUMKEYSQUARELINES, 0, 0, BLUEKEY,
1364 KeyPoints[2].x, KeyPoints[2].y);
1370 void AM_drawCrosshair(int color)
1372 fb[(f_w*(f_h+1))/2] = color; // single point for now
1378 void AM_OGL_SetupState()
1380 float ys = screenHeight/200.0;
1382 // Let's set up a scissor box to clip the map lines and stuff.
1383 glPushAttrib(GL_SCISSOR_BIT);
1384 glScissor(0, screenHeight-finit_height*ys, screenWidth, finit_height*ys);
1385 glEnable(GL_SCISSOR_TEST);
1388 void AM_OGL_RestoreState()
1395 void AM_Drawer (void)
1397 if (!automapactive) return;
1399 UpdateState |= I_FULLSCRN;
1402 // Update the height (in case sbarscale has been changed).
1403 finit_height = SCREENHEIGHT-SBARHEIGHT*sbarscale/20/*-3*/;
1406 AM_clearFB(BACKGROUND);
1409 AM_OGL_SetupState();
1412 if (grid) AM_drawGrid(GRIDCOLORS);
1417 if (cheating==2) AM_drawThings(THINGCOLORS, THINGRANGE);
1419 // AM_drawCrosshair(XHAIRCOLORS);
1421 // if(gameskill == sk_baby) AM_drawkeys();
1424 AM_OGL_RestoreState();
1427 MN_DrTextA(P_GetMapName(gamemap), 38, 144);
1428 if(ShowKills && netgame && deathmatch)
1430 AM_DrawDeathmatchStats();
1433 // V_MarkRect(f_x, f_y, f_w, f_h);
1437 //===========================================================================
1439 // AM_DrawDeathmatchStats
1441 //===========================================================================
1443 // 8-player note: Proper player color names here, too
1445 char *PlayerColorText[MAXPLAYERS] =
1457 void AM_DrawDeathmatchStats(void)
1460 int fragCount[MAXPLAYERS];
1461 int order[MAXPLAYERS];
1462 char textBuffer[80];
1465 for(i = 0; i < MAXPLAYERS; i++)
1470 for(i = 0; i < MAXPLAYERS; i++)
1472 if(!playeringame[i])
1478 for(j = 0; j < MAXPLAYERS; j++)
1482 fragCount[i] += players[i].frags[j];
1485 for(k = 0; k < MAXPLAYERS; k++)
1492 else if(fragCount[i] > fragCount[order[k]])
1494 for(m = MAXPLAYERS-1; m > k; m--)
1496 order[m] = order[m-1];
1505 for(i = 0; i < MAXPLAYERS; i++)
1507 if(!playeringame[order[i]])
1513 MN_DrTextA(PlayerColorText[order[i]], 8, yPosition);
1514 sprintf(textBuffer, "%d", fragCount[order[i]]);
1515 MN_DrTextA(textBuffer, 80, yPosition);
1521 //===========================================================================
1525 //===========================================================================
1527 static void DrawWorldTimer(void)
1534 char timeBuffer[15];
1537 worldTimer = players[consoleplayer].worldTimer;
1540 days = worldTimer/86400;
1541 worldTimer -= days*86400;
1542 hours = worldTimer/3600;
1543 worldTimer -= hours*3600;
1544 minutes = worldTimer/60;
1545 worldTimer -= minutes*60;
1546 seconds = worldTimer;
1548 sprintf(timeBuffer, "%.2d : %.2d : %.2d", hours, minutes,seconds);
1549 MN_DrTextA(timeBuffer, 240, 8);
1555 sprintf(dayBuffer, "%.2d DAY", days);
1559 sprintf(dayBuffer, "%.2d DAYS", days);
1561 MN_DrTextA(dayBuffer, 240, 20);
1564 MN_DrTextA("YOU FREAK!!!", 230, 35);