13 #define MTOFX(x) FixedMul((x),scale_mtof)
15 #define CXMTOFX(x) ((f_x<<16) + MTOFX((x)-m_x))
16 #define CYMTOFX(y) ((f_y<<16) + ((f_h<<16) - MTOFX((y)-m_y)))
18 static int maplumpnum;
21 vertex_t KeyPoints[NUMKEYS];
23 #define NUMALIAS 3 // Number of antialiased lines.
27 // EPISODE 1 - THE CITY OF THE DAMNED
30 "E1M3: THE GATEHOUSE",
31 "E1M4: THE GUARD TOWER",
33 "E1M6: THE CATHEDRAL",
36 "E1M9: THE GRAVEYARD",
37 // EPISODE 2 - HELL'S MAW
39 "E2M2: THE LAVA PITS",
40 "E2M3: THE RIVER OF FIRE",
41 "E2M4: THE ICE GROTTO",
42 "E2M5: THE CATACOMBS",
43 "E2M6: THE LABYRINTH",
44 "E2M7: THE GREAT HALL",
45 "E2M8: THE PORTALS OF CHAOS",
47 // EPISODE 3 - THE DOME OF D'SPARIL
48 "E3M1: THE STOREHOUSE",
50 "E3M3: THE CONFLUENCE",
51 "E3M4: THE AZURE FORTRESS",
52 "E3M5: THE OPHIDIAN LAIR",
53 "E3M6: THE HALLS OF FEAR",
55 "E3M8: D'SPARIL'S KEEP",
57 // EPISODE 4: THE OSSUARY
63 "E4M6: HALLS OF THE APOSTATE",
64 "E4M7: RAMPARTS OF PERDITION",
65 "E4M8: SHATTERED BRIDGE",
67 // EPISODE 5: THE STAGNANT DEMESNE
75 "E5M8: FIELD OF JUDGEMENT",
76 "E5M9: SKEIN OF D'SPARIL"
79 static int cheating = 0;
82 static int leveljuststarted = 1; // kluge until AM_LevelInit() is called
84 boolean automapactive = false;
85 static int finit_width = SCREENWIDTH;
86 static int finit_height = SCREENHEIGHT-42;
87 static int f_x, f_y; // location of window on screen
88 static int f_w, f_h; // size of window on screen
89 static int lightlev; // used for funky strobing effect
90 static byte *fb; // pseudo-frame buffer
93 static mpoint_t m_paninc; // how far the window pans each tic (map coords)
94 static fixed_t mtof_zoommul; // how far the window zooms in each tic (map coords)
95 static fixed_t ftom_zoommul; // how far the window zooms in each tic (fb coords)
97 static fixed_t m_x, m_y; // LL x,y where the window is on the map (map coords)
98 static fixed_t m_x2, m_y2; // UR x,y where the window is on the map (map coords)
100 // width/height of window on map (map coords)
101 static fixed_t m_w, m_h;
102 static fixed_t min_x, min_y; // based on level size
103 static fixed_t max_x, max_y; // based on level size
104 static fixed_t max_w, max_h; // max_x-min_x, max_y-min_y
105 static fixed_t min_w, min_h; // based on player size
106 static fixed_t min_scale_mtof; // used to tell when to stop zooming out
107 static fixed_t max_scale_mtof; // used to tell when to stop zooming in
109 // old stuff for recovery later
110 static fixed_t old_m_w, old_m_h;
111 static fixed_t old_m_x, old_m_y;
113 // old location used by the Follower routine
114 static mpoint_t f_oldloc;
116 // used by MTOF to scale from map-to-frame-buffer coords
117 static fixed_t scale_mtof = INITSCALEMTOF;
118 // used by FTOM to scale from frame-buffer-to-map coords (=1/scale_mtof)
119 static fixed_t scale_ftom;
121 static player_t *plr; // the player represented by an arrow
122 static vertex_t oldplr;
124 //static patch_t *marknums[10]; // numbers used for marking by the automap
125 //static mpoint_t markpoints[AM_NUMMARKPOINTS]; // where the points are
126 //static int markpointnum = 0; // next point to be assigned
128 static int followplayer = 1; // specifies whether to follow the player around
130 static char cheat_amap[] = { 'r','a','v','m','a','p' };
132 static byte cheatcount=0;
134 extern boolean viewactive;
136 static byte antialias[NUMALIAS][8]=
138 {96, 97, 98, 99, 100, 101, 102, 103},
139 {110, 109, 108, 107, 106, 105, 104, 103},
140 {75, 76, 77, 78, 79, 80, 81, 103}
143 static byte *aliasmax[NUMALIAS] = {
144 &antialias[0][7], &antialias[1][7], &antialias[2][7]
148 static byte *maplump; // pointer to the raw data for the automap background.
151 static short mapystart=0; // y-value for the start of the map bitmap...used in the paralax stuff.
152 static short mapxstart=0; //x-value for the bitmap.
154 //byte screens[][SCREENWIDTH*SCREENHEIGHT];
155 //void V_MarkRect (int x, int y, int width, int height);
159 void DrawWuLine(int X0, int Y0, int X1, int Y1, byte *BaseColor,
160 int NumLevels, unsigned short IntensityBits);
162 // Calculates the slope and slope according to the x-axis of a line
163 // segment in map coordinates (with the upright y-axis n' all) so
164 // that it can be used with the brain-dead drawing stuff.
166 // Ripped out for Heretic
168 void AM_getIslope(mline_t *ml, islope_t *is)
172 dy = ml->a.y - ml->b.y;
173 dx = ml->b.x - ml->a.x;
174 if (!dy) is->islp = (dx<0?-MAXINT:MAXINT);
175 else is->islp = FixedDiv(dx, dy);
176 if (!dx) is->slp = (dy<0?-MAXINT:MAXINT);
177 else is->slp = FixedDiv(dy, dx);
181 void AM_activateNewScale(void)
193 void AM_saveScaleAndLoc(void)
201 void AM_restoreScaleAndLoc(void)
211 m_x = plr->mo->x - m_w/2;
212 m_y = plr->mo->y - m_h/2;
217 // Change the scaling multipliers
218 scale_mtof = FixedDiv(f_w<<FRACBITS, m_w);
219 scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
222 // adds a marker at the current location
225 void AM_addMark(void)
227 markpoints[markpointnum].x = m_x + m_w/2;
228 markpoints[markpointnum].y = m_y + m_h/2;
229 markpointnum = (markpointnum + 1) % AM_NUMMARKPOINTS;
233 void AM_findMinMaxBoundaries(void)
238 min_x = min_y = MAXINT;
239 max_x = max_y = -MAXINT;
240 for (i=0;i<numvertexes;i++)
242 if (vertexes[i].x < min_x) min_x = vertexes[i].x;
243 else if (vertexes[i].x > max_x) max_x = vertexes[i].x;
244 if (vertexes[i].y < min_y) min_y = vertexes[i].y;
245 else if (vertexes[i].y > max_y) max_y = vertexes[i].y;
247 max_w = max_x - min_x;
248 max_h = max_y - min_y;
249 min_w = 2*PLAYERRADIUS;
250 min_h = 2*PLAYERRADIUS;
252 a = FixedDiv(f_w<<FRACBITS, max_w);
253 b = FixedDiv(f_h<<FRACBITS, max_h);
254 min_scale_mtof = a < b ? a : b;
256 max_scale_mtof = FixedDiv(f_h<<FRACBITS, 2*PLAYERRADIUS);
260 void AM_changeWindowLoc(void)
262 if (m_paninc.x || m_paninc.y)
271 if (m_x + m_w/2 > max_x)
276 else if (m_x + m_w/2 < min_x)
281 if (m_y + m_h/2 > max_y)
286 else if (m_y + m_h/2 < min_y)
292 mapxstart += MTOF(m_paninc.x+FRACUNIT/2);
293 mapystart -= MTOF(m_paninc.y+FRACUNIT/2);
294 if(mapxstart >= finit_width)
295 mapxstart -= finit_width;
297 mapxstart += finit_width;
298 if(mapystart >= finit_height)
299 mapystart -= finit_height;
301 mapystart += finit_height;
307 void AM_initVariables(void)
313 //static event_t st_notify = { ev_keyup, AM_MSGENTERED };
315 automapactive = true;
322 m_paninc.x = m_paninc.y = 0;
323 ftom_zoommul = FRACUNIT;
324 mtof_zoommul = FRACUNIT;
329 // find player to center on initially
330 if (!playeringame[pnum = consoleplayer])
331 for (pnum=0;pnum<MAXPLAYERS;pnum++) if (playeringame[pnum]) break;
332 plr = &players[pnum];
333 oldplr.x = plr->mo->x;
334 oldplr.y = plr->mo->y;
335 m_x = plr->mo->x - m_w/2;
336 m_y = plr->mo->y - m_h/2;
337 AM_changeWindowLoc();
339 // for saving & restoring
345 // load in the location of keys, if in baby mode
347 memset(KeyPoints, 0, sizeof(vertex_t)*3);
348 if(gameskill == sk_baby)
350 for(think = thinkercap.next; think != &thinkercap; think = think->next)
352 if(think->function != P_MobjThinker)
356 mo = (mobj_t *)think;
357 if(mo->type == MT_CKEY)
359 KeyPoints[0].x = mo->x;
360 KeyPoints[0].y = mo->y;
362 else if(mo->type == MT_AKYY)
364 KeyPoints[1].x = mo->x;
365 KeyPoints[1].y = mo->y;
367 else if(mo->type == MT_BKYY)
369 KeyPoints[2].x = mo->x;
370 KeyPoints[2].y = mo->y;
375 // inform the status bar of the change
376 //c ST_Responder(&st_notify);
379 void AM_loadPics(void)
383 /* for (i=0;i<10;i++)
385 sprintf(namebuf, "AMMNUM%d", i);
386 marknums[i] = W_CacheLumpName(namebuf, PU_STATIC);
389 maplumpnum = W_GetNumForName("AUTOPAGE");
391 maplump = W_CacheLumpName("AUTOPAGE", PU_STATIC);
395 /*void AM_unloadPics(void)
398 for (i=0;i<10;i++) Z_ChangeTag(marknums[i], PU_CACHE);
403 void AM_clearMarks(void)
406 for (i=0;i<AM_NUMMARKPOINTS;i++) markpoints[i].x = -1; // means empty
411 // should be called at the start of every level
412 // right now, i figure it out myself
414 void AM_LevelInit(void)
416 leveljuststarted = 0;
421 mapxstart = mapystart = 0;
426 AM_findMinMaxBoundaries();
427 scale_mtof = FixedDiv(min_scale_mtof, (int) (0.7*FRACUNIT));
428 if (scale_mtof > max_scale_mtof) scale_mtof = min_scale_mtof;
429 scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
432 static boolean stopped = true;
436 //static event_t st_notify = { 0, ev_keyup, AM_MSGEXITED };
439 automapactive = false;
440 // ST_Responder(&st_notify);
442 BorderNeedRefresh = true;
447 static int lastlevel = -1, lastepisode = -1;
449 if (!stopped) AM_Stop();
451 if(gamestate != GS_LEVEL)
453 return; // don't show automap if we aren't in a game!
455 if (lastlevel != gamemap || lastepisode != gameepisode)
459 lastepisode = gameepisode;
465 // set the window scale to the maximum size
467 void AM_minOutWindowScale(void)
469 scale_mtof = min_scale_mtof;
470 scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
471 AM_activateNewScale();
474 // set the window scale to the minimum size
476 void AM_maxOutWindowScale(void)
478 scale_mtof = max_scale_mtof;
479 scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
480 AM_activateNewScale();
483 boolean AM_Responder (event_t *ev)
486 static int cheatstate=0;
487 static int bigstate=0;
492 if (ev->type == ev_keydown && ev->data1 == AM_STARTKEY
493 && gamestate == GS_LEVEL)
497 // viewactive = true;
501 else if (ev->type == ev_keydown)
507 case AM_PANRIGHTKEY: // pan right
508 if (!followplayer) m_paninc.x = FTOM(F_PANINC);
511 case AM_PANLEFTKEY: // pan left
512 if (!followplayer) m_paninc.x = -FTOM(F_PANINC);
515 case AM_PANUPKEY: // pan up
516 if (!followplayer) m_paninc.y = FTOM(F_PANINC);
519 case AM_PANDOWNKEY: // pan down
520 if (!followplayer) m_paninc.y = -FTOM(F_PANINC);
523 case AM_ZOOMOUTKEY: // zoom out
524 mtof_zoommul = M_ZOOMOUT;
525 ftom_zoommul = M_ZOOMIN;
527 case AM_ZOOMINKEY: // zoom in
528 mtof_zoommul = M_ZOOMIN;
529 ftom_zoommul = M_ZOOMOUT;
537 bigstate = !bigstate;
540 AM_saveScaleAndLoc();
541 AM_minOutWindowScale();
543 else AM_restoreScaleAndLoc();
546 followplayer = !followplayer;
548 P_SetMessage(plr, followplayer ? AMSTR_FOLLOWON : AMSTR_FOLLOWOFF, true);
553 plr->message = grid ? AMSTR_GRIDON : AMSTR_GRIDOFF;
556 sprintf(buffer, "%s %d", AMSTR_MARKEDSPOT, markpointnum);
557 plr->message = buffer;
560 case AM_CLEARMARKKEY:
562 plr->message = AMSTR_MARKSCLEARED;
569 if(cheat_amap[cheatcount]==ev->data1 && !netgame)
577 cheating = (cheating+1) % 3;
581 else if (ev->type == ev_keyup)
587 if (!followplayer) m_paninc.x = 0;
590 if (!followplayer) m_paninc.x = 0;
593 if (!followplayer) m_paninc.y = 0;
596 if (!followplayer) m_paninc.y = 0;
600 mtof_zoommul = FRACUNIT;
601 ftom_zoommul = FRACUNIT;
610 void AM_changeWindowScale(void)
613 // Change the scaling multipliers
614 scale_mtof = FixedMul(scale_mtof, mtof_zoommul);
615 scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
617 if (scale_mtof < min_scale_mtof) AM_minOutWindowScale();
618 else if (scale_mtof > max_scale_mtof) AM_maxOutWindowScale();
619 else AM_activateNewScale();
622 void AM_doFollowPlayer(void)
624 if (f_oldloc.x != plr->mo->x || f_oldloc.y != plr->mo->y)
626 // m_x = FTOM(MTOF(plr->mo->x - m_w/2));
627 // m_y = FTOM(MTOF(plr->mo->y - m_h/2));
628 // m_x = plr->mo->x - m_w/2;
629 // m_y = plr->mo->y - m_h/2;
630 m_x = FTOM(MTOF(plr->mo->x)) - m_w/2;
631 m_y = FTOM(MTOF(plr->mo->y)) - m_h/2;
635 // do the parallax parchment scrolling.
637 dmapx = (MTOF(plr->mo->x)-MTOF(f_oldloc.x)); //fixed point
638 dmapy = (MTOF(f_oldloc.y)-MTOF(plr->mo->y));
640 if(f_oldloc.x == MAXINT) //to eliminate an error when the user first
641 dmapx=0; //goes into the automap.
645 while(mapxstart >= finit_width)
646 mapxstart -= finit_width;
648 mapxstart += finit_width;
649 while(mapystart >= finit_height)
650 mapystart -= finit_height;
652 mapystart += finit_height;
654 f_oldloc.x = plr->mo->x;
655 f_oldloc.y = plr->mo->y;
659 // Ripped out for Heretic
661 void AM_updateLightLev(void)
664 //static int litelevels[] = { 0, 3, 5, 6, 6, 7, 7, 7 };
665 static int litelevels[] = { 0, 4, 7, 10, 12, 14, 15, 15 };
666 static int litelevelscnt = 0;
668 // Change light level
671 lightlev = litelevels[litelevelscnt++];
672 if (litelevelscnt == sizeof(litelevels)/sizeof(int)) litelevelscnt = 0;
673 nexttic = amclock + 6 - (amclock % 6);
678 void AM_Ticker (void)
681 if (!automapactive) return;
685 if (followplayer) AM_doFollowPlayer();
687 // Change the zoom if necessary
688 if (ftom_zoommul != FRACUNIT) AM_changeWindowScale();
690 // Change x,y location
691 if (m_paninc.x || m_paninc.y) AM_changeWindowLoc();
692 // Update light level
693 // AM_updateLightLev();
697 void AM_clearFB(int color)
711 dmapx = (MTOF(plr->mo->x)-MTOF(oldplr.x)); //fixed point
712 dmapy = (MTOF(oldplr.y)-MTOF(plr->mo->y));
714 oldplr.x = plr->mo->x;
715 oldplr.y = plr->mo->y;
716 // if(f_oldloc.x == MAXINT) //to eliminate an error when the user first
717 // dmapx=0; //goes into the automap.
718 mapxstart += dmapx>>1;
719 mapystart += dmapy>>1;
721 while(mapxstart >= finit_width)
722 mapxstart -= finit_width;
724 mapxstart += finit_width;
725 while(mapystart >= finit_height)
726 mapystart -= finit_height;
728 mapystart += finit_height;
732 mapxstart += (MTOF(m_paninc.x)>>1);
733 mapystart -= (MTOF(m_paninc.y)>>1);
734 if(mapxstart >= finit_width)
735 mapxstart -= finit_width;
737 mapxstart += finit_width;
738 if(mapystart >= finit_height)
739 mapystart -= finit_height;
741 mapystart += finit_height;
745 OGL_SetColorAndAlpha(1, 1, 1, 1);
748 OGL_SetFlat(W_GetNumForName ("FLOOR04")-firstflat);
752 OGL_SetFlat(W_GetNumForName("FLAT513")-firstflat);
754 scalar = sbarscale/20.0;
755 OGL_DrawCutRectTiled(0, finit_height+4, 320, 200-finit_height-4, 64, 64,
756 160-160*scalar+1, finit_height, 320*scalar-2, 200-finit_height);
758 OGL_SetPatch(lump=W_GetNumForName("bordb"));
759 OGL_DrawCutRectTiled(0, finit_height, 320, 4,
760 lumptexsizes[lump].w, lumptexsizes[lump].h,
761 160-160*scalar+1, finit_height, 320*scalar-2, 4);
763 OGL_SetRawImage(maplumpnum, 0); // We only want the left portion.
764 OGL_DrawRectTiled( 0, 0, finit_width,
765 /*(sbarscale<20)?200:*/ finit_height,
768 //blit the automap background to the screen.
769 j=mapystart*finit_width;
770 for(i=0;i<finit_height;i++)
772 memcpy(screen+i*finit_width, maplump+j+mapxstart, finit_width-mapxstart);
773 memcpy(screen+i*finit_width+finit_width-mapxstart, maplump+j, mapxstart);
775 if(j >= finit_height*finit_width)
779 // memcpy(screen, maplump, finit_width*finit_height);
780 // memset(fb, color, f_w*f_h);
784 // Based on Cohen-Sutherland clipping algorithm but with a slightly
785 // faster reject and precalculated slopes. If I need the speed, will
786 // hash algorithm to the common cases.
788 boolean AM_clipMline(mline_t *ml, fline_t *fl)
790 enum { LEFT=1, RIGHT=2, BOTTOM=4, TOP=8 };
791 int outcode1 = 0, outcode2 = 0, outside;
795 #define DOOUTCODE(oc, mx, my) \
797 if ((my) < 0) (oc) |= TOP; \
798 else if ((my) >= f_h) (oc) |= BOTTOM; \
799 if ((mx) < 0) (oc) |= LEFT; \
800 else if ((mx) >= f_w) (oc) |= RIGHT
802 // do trivial rejects and outcodes
803 if (ml->a.y > m_y2) outcode1 = TOP;
804 else if (ml->a.y < m_y) outcode1 = BOTTOM;
805 if (ml->b.y > m_y2) outcode2 = TOP;
806 else if (ml->b.y < m_y) outcode2 = BOTTOM;
807 if (outcode1 & outcode2) return false; // trivially outside
809 if (ml->a.x < m_x) outcode1 |= LEFT;
810 else if (ml->a.x > m_x2) outcode1 |= RIGHT;
811 if (ml->b.x < m_x) outcode2 |= LEFT;
812 else if (ml->b.x > m_x2) outcode2 |= RIGHT;
813 if (outcode1 & outcode2) return false; // trivially outside
815 // transform to frame-buffer coordinates.
816 fl->a.x = CXMTOF(ml->a.x);
817 fl->a.y = CYMTOF(ml->a.y);
818 fl->b.x = CXMTOF(ml->b.x);
819 fl->b.y = CYMTOF(ml->b.y);
820 DOOUTCODE(outcode1, fl->a.x, fl->a.y);
821 DOOUTCODE(outcode2, fl->b.x, fl->b.y);
822 if (outcode1 & outcode2) return false;
824 while (outcode1 | outcode2)
826 // may be partially inside box
827 // find an outside point
828 if (outcode1) outside = outcode1;
829 else outside = outcode2;
833 dy = fl->a.y - fl->b.y;
834 dx = fl->b.x - fl->a.x;
835 tmp.x = fl->a.x + (dx*(fl->a.y))/dy;
838 else if (outside & BOTTOM)
840 dy = fl->a.y - fl->b.y;
841 dx = fl->b.x - fl->a.x;
842 tmp.x = fl->a.x + (dx*(fl->a.y-f_h))/dy;
845 else if (outside & RIGHT)
847 dy = fl->b.y - fl->a.y;
848 dx = fl->b.x - fl->a.x;
849 tmp.y = fl->a.y + (dy*(f_w-1 - fl->a.x))/dx;
852 else if (outside & LEFT)
854 dy = fl->b.y - fl->a.y;
855 dx = fl->b.x - fl->a.x;
856 tmp.y = fl->a.y + (dy*(-fl->a.x))/dx;
859 if (outside == outcode1)
862 DOOUTCODE(outcode1, fl->a.x, fl->a.y);
865 DOOUTCODE(outcode2, fl->b.x, fl->b.y);
867 if (outcode1 & outcode2) return false; // trivially outside
874 // Classic Bresenham w/ whatever optimizations I need for speed
876 void AM_drawFline(fline_t *fl, int color)
879 register int x, y, dx, dy, sx, sy, ax, ay, d;
885 DrawWuLine(fl->a.x, fl->a.y, fl->b.x, fl->b.y, &antialias[0][0], 8, 3);
888 DrawWuLine(fl->a.x, fl->a.y, fl->b.x, fl->b.y, &antialias[1][0], 8, 3);
891 DrawWuLine(fl->a.x, fl->a.y, fl->b.x, fl->b.y, &antialias[2][0], 8, 3);
895 // For debugging only
896 if ( fl->a.x < 0 || fl->a.x >= f_w
897 || fl->a.y < 0 || fl->a.y >= f_h
898 || fl->b.x < 0 || fl->b.x >= f_w
899 || fl->b.y < 0 || fl->b.y >= f_h)
901 fprintf(stderr, "fuck %d \r", fuck++);
905 #define DOT(xx,yy,cc) fb[(yy)*f_w+(xx)]=(cc) //the MACRO!
907 dx = fl->b.x - fl->a.x;
908 ax = 2 * (dx<0 ? -dx : dx);
911 dy = fl->b.y - fl->a.y;
912 ay = 2 * (dy<0 ? -dy : dy);
924 if (x == fl->b.x) return;
938 if (y == fl->b.y) return;
952 /* Wu antialiased line drawer.
953 * (X0,Y0),(X1,Y1) = line to draw
954 * BaseColor = color # of first color in block used for antialiasing, the
955 * 100% intensity version of the drawing color
956 * NumLevels = size of color block, with BaseColor+NumLevels-1 being the
957 * 0% intensity version of the drawing color
958 * IntensityBits = log base 2 of NumLevels; the # of bits used to describe
959 * the intensity of the drawing color. 2**IntensityBits==NumLevels
961 void PUTDOT(short xx,short yy,byte *cc, byte *cm)
964 static int oldyyshifted;
969 else if(xx > (finit_width - 32))
970 cc += 7-((finit_width-xx) >> 2);
971 // if(cc==oldcc) //make sure that we don't double fade the corners.
975 else if(yy > (finit_height - 32))
976 cc += 7-((finit_height-yy) >> 2);
978 if(cc > cm && cm != NULL)
982 else if(cc > oldcc+6) // don't let the color escape from the fade table...
991 else if(yy == oldyy-1)
999 oldyyshifted = yy*320;
1001 fb[oldyyshifted+xx] = *(cc);
1002 // fb[(yy)*f_w+(xx)]=*(cc);
1005 void DrawWuLine(int X0, int Y0, int X1, int Y1, byte *BaseColor,
1006 int NumLevels, unsigned short IntensityBits)
1008 unsigned short IntensityShift, ErrorAdj, ErrorAcc;
1009 unsigned short ErrorAccTemp, Weighting, WeightingComplementMask;
1010 short DeltaX, DeltaY, Temp, XDir;
1012 /* Make sure the line runs top to bottom */
1014 Temp = Y0; Y0 = Y1; Y1 = Temp;
1015 Temp = X0; X0 = X1; X1 = Temp;
1017 /* Draw the initial pixel, which is always exactly intersected by
1018 the line and so needs no weighting */
1019 PUTDOT(X0, Y0, &BaseColor[0], NULL);
1021 if ((DeltaX = X1 - X0) >= 0) {
1025 DeltaX = -DeltaX; /* make DeltaX positive */
1027 /* Special-case horizontal, vertical, and diagonal lines, which
1028 require no weighting because they go right through the center of
1030 if ((DeltaY = Y1 - Y0) == 0) {
1031 /* Horizontal line */
1032 while (DeltaX-- != 0) {
1034 PUTDOT(X0, Y0, &BaseColor[0], NULL);
1042 PUTDOT(X0, Y0, &BaseColor[0], NULL);
1043 } while (--DeltaY != 0);
1047 if (DeltaX == DeltaY) {
1051 PUTDOT(X0, Y0, &BaseColor[0], NULL);
1052 } while (--DeltaY != 0);
1055 /* Line is not horizontal, diagonal, or vertical */
1056 ErrorAcc = 0; /* initialize the line error accumulator to 0 */
1057 /* # of bits by which to shift ErrorAcc to get intensity level */
1058 IntensityShift = 16 - IntensityBits;
1059 /* Mask used to flip all bits in an intensity weighting, producing the
1060 result (1 - intensity weighting) */
1061 WeightingComplementMask = NumLevels - 1;
1062 /* Is this an X-major or Y-major line? */
1063 if (DeltaY > DeltaX) {
1064 /* Y-major line; calculate 16-bit fixed-point fractional part of a
1065 pixel that X advances each time Y advances 1 pixel, truncating the
1066 result so that we won't overrun the endpoint along the X axis */
1067 ErrorAdj = ((unsigned long) DeltaX << 16) / (unsigned long) DeltaY;
1068 /* Draw all pixels other than the first and last */
1070 ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */
1071 ErrorAcc += ErrorAdj; /* calculate error for next pixel */
1072 if (ErrorAcc <= ErrorAccTemp) {
1073 /* The error accumulator turned over, so advance the X coord */
1076 Y0++; /* Y-major, so always advance Y */
1077 /* The IntensityBits most significant bits of ErrorAcc give us the
1078 intensity weighting for this pixel, and the complement of the
1079 weighting for the paired pixel */
1080 Weighting = ErrorAcc >> IntensityShift;
1081 PUTDOT(X0, Y0, &BaseColor[Weighting], &BaseColor[7]);
1082 PUTDOT(X0 + XDir, Y0,
1083 &BaseColor[(Weighting ^ WeightingComplementMask)], &BaseColor[7]);
1085 /* Draw the final pixel, which is always exactly intersected by the line
1086 and so needs no weighting */
1087 PUTDOT(X1, Y1, &BaseColor[0], NULL);
1090 /* It's an X-major line; calculate 16-bit fixed-point fractional part of a
1091 pixel that Y advances each time X advances 1 pixel, truncating the
1092 result to avoid overrunning the endpoint along the X axis */
1093 ErrorAdj = ((unsigned long) DeltaY << 16) / (unsigned long) DeltaX;
1094 /* Draw all pixels other than the first and last */
1096 ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */
1097 ErrorAcc += ErrorAdj; /* calculate error for next pixel */
1098 if (ErrorAcc <= ErrorAccTemp) {
1099 /* The error accumulator turned over, so advance the Y coord */
1102 X0 += XDir; /* X-major, so always advance X */
1103 /* The IntensityBits most significant bits of ErrorAcc give us the
1104 intensity weighting for this pixel, and the complement of the
1105 weighting for the paired pixel */
1106 Weighting = ErrorAcc >> IntensityShift;
1107 PUTDOT(X0, Y0, &BaseColor[Weighting], &BaseColor[7]);
1109 &BaseColor[(Weighting ^ WeightingComplementMask)], &BaseColor[7]);
1112 /* Draw the final pixel, which is always exactly intersected by the line
1113 and so needs no weighting */
1114 PUTDOT(X1, Y1, &BaseColor[0], NULL);
1117 void AM_drawMline(mline_t *ml, int color)
1120 byte *palette = W_CacheLumpName("playpal", PU_CACHE);
1121 byte r = palette[color*3], g = palette[color*3+1], b = palette[color*3+2];
1123 OGL_DrawLine( FIX2FLT(CXMTOFX(ml->a.x)), FIX2FLT(CYMTOFX(ml->a.y))/1.2,
1124 FIX2FLT(CXMTOFX(ml->b.x)), FIX2FLT(CYMTOFX(ml->b.y))/1.2,
1125 r/255.0, g/255.0, b/255.0, 1 );
1129 if (AM_clipMline(ml, &fl))
1130 AM_drawFline(&fl, color); // draws it on frame buffer using fb coords
1134 void AM_drawGrid(int color)
1140 // Figure out start of vertical gridlines
1142 if ((start-bmaporgx)%(MAPBLOCKUNITS<<FRACBITS))
1143 start += (MAPBLOCKUNITS<<FRACBITS)
1144 - ((start-bmaporgx)%(MAPBLOCKUNITS<<FRACBITS));
1147 // draw vertical gridlines
1150 for (x=start; x<end; x+=(MAPBLOCKUNITS<<FRACBITS))
1154 AM_drawMline(&ml, color);
1157 // Figure out start of horizontal gridlines
1159 if ((start-bmaporgy)%(MAPBLOCKUNITS<<FRACBITS))
1160 start += (MAPBLOCKUNITS<<FRACBITS)
1161 - ((start-bmaporgy)%(MAPBLOCKUNITS<<FRACBITS));
1164 // draw horizontal gridlines
1167 for (y=start; y<end; y+=(MAPBLOCKUNITS<<FRACBITS))
1171 AM_drawMline(&ml, color);
1175 void AM_drawWalls(void)
1180 //OGL_SetNoTexture();
1181 glDisable( GL_TEXTURE_2D );
1184 glBegin(GL_LINES); // We'll draw pretty much all of them.
1185 for(i=0;i<numlines;i++)
1187 if (cheating || (lines[i].flags & ML_MAPPED))
1189 if ((lines[i].flags & LINE_NEVERSEE) && !cheating)
1191 if (!lines[i].backsector)
1193 OGL_SetColor(WALLCOLORS);
1197 if (lines[i].flags & ML_SECRET) // secret door
1199 if (cheating) //AM_drawMline(&l, 0);
1202 OGL_SetColor(WALLCOLORS);
1204 else if(lines[i].special == 13 || lines[i].special == 83)
1205 { // Locked door line -- all locked doors are greed
1206 OGL_SetColor(GREENKEY);
1208 else if(lines[i].special == 70 || lines[i].special == 71)
1209 { // intra-level teleports are blue
1210 OGL_SetColor(BLUEKEY);
1212 else if(lines[i].special == 74 || lines[i].special == 75)
1213 { // inter-level teleport/game-winning exit -- both are red
1214 OGL_SetColor(BLOODRED);
1216 else if (lines[i].backsector->floorheight
1217 != lines[i].frontsector->floorheight)
1219 // floor level change
1220 OGL_SetColor(FDWALLCOLORS);
1222 else if (lines[i].backsector->ceilingheight
1223 != lines[i].frontsector->ceilingheight)
1225 // ceiling level change
1226 OGL_SetColor(CDWALLCOLORS);
1230 OGL_SetColor(TSWALLCOLORS);
1235 else if (plr->powers[pw_allmap])
1237 if (!(lines[i].flags & LINE_NEVERSEE))
1238 OGL_SetColor(GRAYS+3);
1244 // Draw the line. 1.2 is the to-square aspect corrector.
1245 glVertex2f( FIX2FLT(CXMTOFX(lines[i].v1->x)),
1246 FIX2FLT(CYMTOFX(lines[i].v1->y))/1.2);
1247 glVertex2f( FIX2FLT(CXMTOFX(lines[i].v2->x)),
1248 FIX2FLT(CYMTOFX(lines[i].v2->y))/1.2);
1252 glEnable( GL_TEXTURE_2D );
1256 for (i=0;i<numlines;i++)
1258 l.a.x = lines[i].v1->x;
1259 l.a.y = lines[i].v1->y;
1260 l.b.x = lines[i].v2->x;
1261 l.b.y = lines[i].v2->y;
1262 if (cheating || (lines[i].flags & ML_MAPPED))
1264 if ((lines[i].flags & LINE_NEVERSEE) && !cheating)
1266 if (!lines[i].backsector)
1268 AM_drawMline(&l, WALLCOLORS+lightlev);
1270 if (lines[i].special == 39)
1272 AM_drawMline(&l, WALLCOLORS+WALLRANGE/2);
1273 } else if (lines[i].flags & ML_SECRET) // secret door
1275 if (cheating) AM_drawMline(&l, 0);
1276 else AM_drawMline(&l, WALLCOLORS+lightlev);
1278 else if(lines[i].special > 25 && lines[i].special < 35)
1280 switch(lines[i].special)
1284 AM_drawMline(&l, BLUEKEY);
1288 AM_drawMline(&l, YELLOWKEY);
1292 AM_drawMline(&l, GREENKEY);
1298 else if (lines[i].backsector->floorheight
1299 != lines[i].frontsector->floorheight) {
1300 AM_drawMline(&l, FDWALLCOLORS + lightlev); // floor level change
1301 } else if (lines[i].backsector->ceilingheight
1302 != lines[i].frontsector->ceilingheight) {
1303 AM_drawMline(&l, CDWALLCOLORS+lightlev); // ceiling level change
1304 } else if (cheating) {
1305 AM_drawMline(&l, TSWALLCOLORS+lightlev);
1308 } else if (plr->powers[pw_allmap])
1310 if (!(lines[i].flags & LINE_NEVERSEE)) AM_drawMline(&l, GRAYS+3);
1316 void AM_rotate(fixed_t *x, fixed_t *y, angle_t a)
1320 tmpx = FixedMul(*x,finecosine[a>>ANGLETOFINESHIFT])
1321 - FixedMul(*y,finesine[a>>ANGLETOFINESHIFT]);
1322 *y = FixedMul(*x,finesine[a>>ANGLETOFINESHIFT])
1323 + FixedMul(*y,finecosine[a>>ANGLETOFINESHIFT]);
1327 void AM_drawLineCharacter(mline_t *lineguy, int lineguylines, fixed_t scale,
1328 angle_t angle, int color, fixed_t x, fixed_t y)
1333 for (i=0;i<lineguylines;i++)
1335 l.a.x = lineguy[i].a.x;
1336 l.a.y = lineguy[i].a.y;
1339 l.a.x = FixedMul(scale, l.a.x);
1340 l.a.y = FixedMul(scale, l.a.y);
1342 if (angle) AM_rotate(&l.a.x, &l.a.y, angle);
1346 l.b.x = lineguy[i].b.x;
1347 l.b.y = lineguy[i].b.y;
1350 l.b.x = FixedMul(scale, l.b.x);
1351 l.b.y = FixedMul(scale, l.b.y);
1353 if (angle) AM_rotate(&l.b.x, &l.b.y, angle);
1357 AM_drawMline(&l, color);
1362 void AM_drawPlayers(void)
1367 static int their_colors[] = { GREENKEY, YELLOWKEY, BLOODRED, BLUEKEY };
1368 int their_color = -1;
1374 if (cheating) AM_drawLineCharacter(cheat_player_arrow, NUMCHEATPLYRLINES, 0,
1375 plr->mo->angle, WHITE, plr->mo->x, plr->mo->y);
1376 */ //cheat key player pointer is the same as non-cheat pointer..
1378 AM_drawLineCharacter(player_arrow, NUMPLYRLINES, 0, plr->mo->angle,
1379 WHITE, plr->mo->x, plr->mo->y);
1383 for (i=0;i<MAXPLAYERS;i++)
1387 if(deathmatch && !singledemo && p != plr)
1391 if (!playeringame[i]) continue;
1392 if (p->powers[pw_invisibility]) color = 102; // *close* to the automap color
1393 else color = their_colors[their_color];
1394 AM_drawLineCharacter(player_arrow, NUMPLYRLINES, 0, p->mo->angle,
1395 color, p->mo->x, p->mo->y);
1399 void AM_drawThings(int colors, int colorrange)
1404 for (i=0;i<numsectors;i++)
1406 t = sectors[i].thinglist;
1409 AM_drawLineCharacter(thintriangle_guy, NUMTHINTRIANGLEGUYLINES,
1410 16<<FRACBITS, t->angle, colors+lightlev, t->x, t->y);
1417 void AM_drawMarks(void)
1419 int i, fx, fy, w, h;
1421 for (i=0;i<AM_NUMMARKPOINTS;i++)
1423 if (markpoints[i].x != -1)
1425 w = SHORT(marknums[i]->width);
1426 h = SHORT(marknums[i]->height);
1427 fx = CXMTOF(markpoints[i].x);
1428 fy = CYMTOF(markpoints[i].y);
1429 if (fx >= f_x && fx <= f_w - w && fy >= f_y && fy <= f_h - h)
1430 V_DrawPatch(fx, fy, marknums[i]);
1436 void AM_drawkeys(void)
1438 if(KeyPoints[0].x != 0 || KeyPoints[0].y != 0)
1440 AM_drawLineCharacter(keysquare, NUMKEYSQUARELINES, 0, 0, YELLOWKEY,
1441 KeyPoints[0].x, KeyPoints[0].y);
1443 if(KeyPoints[1].x != 0 || KeyPoints[1].y != 0)
1445 AM_drawLineCharacter(keysquare, NUMKEYSQUARELINES, 0, 0, GREENKEY,
1446 KeyPoints[1].x, KeyPoints[1].y);
1448 if(KeyPoints[2].x != 0 || KeyPoints[2].y != 0)
1450 AM_drawLineCharacter(keysquare, NUMKEYSQUARELINES, 0, 0, BLUEKEY,
1451 KeyPoints[2].x, KeyPoints[2].y);
1455 void AM_drawCrosshair(int color)
1457 fb[(f_w*(f_h+1))/2] = color; // single point for now
1461 void AM_OGL_SetupState()
1463 float ys = screenHeight/200.0;
1465 // Let's set up a scissor box to clip the map lines and stuff.
1466 glPushAttrib(GL_SCISSOR_BIT);
1467 glScissor(0, screenHeight-finit_height*ys, screenWidth, finit_height*ys);
1468 glEnable(GL_SCISSOR_TEST);
1471 void AM_OGL_RestoreState()
1477 void AM_Drawer(void)
1479 //int highestEpisode; // unused variable - DDOI
1481 if (!automapactive) return;
1483 // Update the height (in case sbarscale has been changed).
1484 finit_height = SCREENHEIGHT-SBARHEIGHT*sbarscale/20/*-3*/;
1487 UpdateState |= I_FULLSCRN;
1490 AM_OGL_SetupState();
1493 AM_clearFB(BACKGROUND);
1494 if (grid) AM_drawGrid(GRIDCOLORS);
1497 if (cheating==2) AM_drawThings(THINGCOLORS, THINGRANGE);
1498 // AM_drawCrosshair(XHAIRCOLORS);
1501 if(gameskill == sk_baby)
1507 AM_OGL_RestoreState();
1510 if((gameepisode < (ExtendedWAD ? 6 : 4)) && gamemap < 10)
1512 MN_DrTextA(LevelNames[(gameepisode-1)*9+gamemap-1], 20, 145);
1515 // V_MarkRect(f_x, f_y, f_w, f_h);