📄 am_map.c
字号:
automapactive = true;
// DQ removed fb - wanted buffer to be a parameter, not global
// fb = RenderBuffer/*DQ screens[0]*/;
f_oldloc.x = MAXINT;
amclock = 0;
lightlev = 0;
m_paninc.x = m_paninc.y = 0;
ftom_zoommul = FRACUNIT;
mtof_zoommul = FRACUNIT;
m_w = FTOM(f_w);
m_h = FTOM(f_h);
// sprintf(MsgText, "f_w = %d, f_h = %d, m_w = %d, m_h = %d\n", f_w, f_h, m_w, m_h);
// WriteDebug(MsgText);
// find player to center on initially
if (!playeringame[pnum = consoleplayer])
for (pnum=0;pnum<MAXPLAYERS;pnum++)
if (playeringame[pnum])
break;
plr = &players[pnum];
m_x = plr->mo->x - m_w/2;
m_y = plr->mo->y - m_h/2;
AM_changeWindowLoc();
// for saving & restoring
old_m_x = m_x;
old_m_y = m_y;
old_m_w = m_w;
old_m_h = m_h;
// inform the status bar of the change
ST_Responder(&st_notify);
}
//
//
//
void AM_loadPics(void)
{
int i;
char namebuf[9];
for (i=0;i<10;i++)
{
sprintf(namebuf, "AMMNUM%d", i);
marknums[i] = W_CacheLumpName(namebuf, PU_STATIC);
}
}
void AM_unloadPics(void)
{
int i;
for (i=0;i<10;i++)
Z_ChangeTag(marknums[i], PU_CACHE);
}
void AM_clearMarks(void)
{
int i;
for (i=0;i<AM_NUMMARKPOINTS;i++)
markpoints[i].x = -1; // means empty
markpointnum = 0;
}
//
// should be called at the start of every level
// right now, i figure it out myself
//
void AM_LevelInit(void)
{
leveljuststarted = 0;
f_x = f_y = 0;
f_w = SCREENWIDTH;
f_h = (SCREENHEIGHT - 32);
// f_w = finit_width;
// f_h = finit_height;
AM_clearMarks();
AM_findMinMaxBoundaries();
scale_mtof = FixedDiv(min_scale_mtof, (int) (0.7*FRACUNIT));
if (scale_mtof > max_scale_mtof)
scale_mtof = min_scale_mtof;
scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
// sprintf(MsgText, "scale_mtof %d, scale_ftom %d\n", scale_mtof, scale_ftom);
// WriteDebug(MsgText);
}
//
//
//
void AM_Stop (void)
{
static event_t st_notify = { 0, ev_keyup, AM_MSGEXITED };
AM_unloadPics();
automapactive = false;
ST_Responder(&st_notify);
stopped = true;
}
//
//
//
void AM_Start (PBUFFER RenderBuffer) // DQ
//void AM_Start (void)
{
static int lastlevel = -1, lastepisode = -1;
if (!stopped) AM_Stop();
stopped = false;
if (lastlevel != gamemap || lastepisode != gameepisode)
{
AM_LevelInit();
lastlevel = gamemap;
lastepisode = gameepisode;
}
AM_initVariables();
AM_loadPics();
}
//
// set the window scale to the maximum size
//
void AM_minOutWindowScale(void)
{
scale_mtof = min_scale_mtof;
scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
AM_activateNewScale();
}
//
// set the window scale to the minimum size
//
void AM_maxOutWindowScale(void)
{
scale_mtof = max_scale_mtof;
scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
AM_activateNewScale();
}
//
// Handle events (user inputs) in automap mode
//
boolean
AM_Responder
( event_t* ev,
PBUFFER RenderBuffer) // DQ
//boolean
//AM_Responder
//( event_t* ev )
{
int rc;
static int cheatstate=0;
static int bigstate=0;
static char buffer[20];
rc = false;
if (!automapactive)
{
if (ev->type == ev_keydown && ev->data1 == AM_STARTKEY)
{
AM_Start (RenderBuffer/*DQ*/);
viewactive = false;
rc = true;
}
}
else if (ev->type == ev_keydown)
{
rc = true;
switch(ev->data1)
{
case AM_PANRIGHTKEY: // pan right
if (!followplayer) m_paninc.x = FTOM(F_PANINC);
else rc = false;
break;
case AM_PANLEFTKEY: // pan left
if (!followplayer) m_paninc.x = -FTOM(F_PANINC);
else rc = false;
break;
case AM_PANUPKEY: // pan up
if (!followplayer) m_paninc.y = FTOM(F_PANINC);
else rc = false;
break;
case AM_PANDOWNKEY: // pan down
if (!followplayer) m_paninc.y = -FTOM(F_PANINC);
else rc = false;
break;
case AM_ZOOMOUTKEY: // zoom out
mtof_zoommul = M_ZOOMOUT;
ftom_zoommul = M_ZOOMIN;
break;
case AM_ZOOMINKEY: // zoom in
mtof_zoommul = M_ZOOMIN;
ftom_zoommul = M_ZOOMOUT;
break;
case AM_ENDKEY:
bigstate = 0;
viewactive = true;
AM_Stop ();
break;
case AM_GOBIGKEY:
bigstate = !bigstate;
if (bigstate)
{
AM_saveScaleAndLoc();
AM_minOutWindowScale();
}
else AM_restoreScaleAndLoc();
break;
case AM_FOLLOWKEY:
followplayer = !followplayer;
f_oldloc.x = MAXINT;
plr->message = followplayer ? AMSTR_FOLLOWON : AMSTR_FOLLOWOFF;
break;
case AM_GRIDKEY:
grid = !grid;
plr->message = grid ? AMSTR_GRIDON : AMSTR_GRIDOFF;
break;
case AM_MARKKEY:
sprintf(buffer, "%s %d", AMSTR_MARKEDSPOT, markpointnum);
plr->message = buffer;
AM_addMark();
break;
case AM_CLEARMARKKEY:
AM_clearMarks();
plr->message = AMSTR_MARKSCLEARED;
break;
default:
cheatstate=0;
rc = false;
}
if (!deathmatch && cht_CheckCheat(&cheat_amap, ev->data1))
{
rc = false;
cheating = (cheating+1) % 3;
}
}
else if (ev->type == ev_keyup)
{
rc = false;
switch (ev->data1)
{
case AM_PANRIGHTKEY:
if (!followplayer) m_paninc.x = 0;
break;
case AM_PANLEFTKEY:
if (!followplayer) m_paninc.x = 0;
break;
case AM_PANUPKEY:
if (!followplayer) m_paninc.y = 0;
break;
case AM_PANDOWNKEY:
if (!followplayer) m_paninc.y = 0;
break;
case AM_ZOOMOUTKEY:
case AM_ZOOMINKEY:
mtof_zoommul = FRACUNIT;
ftom_zoommul = FRACUNIT;
break;
}
}
return rc;
}
//
// Zooming
//
void AM_changeWindowScale(void)
{
// Change the scaling multipliers
scale_mtof = FixedMul(scale_mtof, mtof_zoommul);
scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
if (scale_mtof < min_scale_mtof)
AM_minOutWindowScale();
else if (scale_mtof > max_scale_mtof)
AM_maxOutWindowScale();
else
AM_activateNewScale();
}
//
//
//
void AM_doFollowPlayer(void)
{
if (f_oldloc.x != plr->mo->x || f_oldloc.y != plr->mo->y)
{
m_x = FTOM(MTOF(plr->mo->x)) - m_w/2;
m_y = FTOM(MTOF(plr->mo->y)) - m_h/2;
m_x2 = m_x + m_w;
m_y2 = m_y + m_h;
f_oldloc.x = plr->mo->x;
f_oldloc.y = plr->mo->y;
// m_x = FTOM(MTOF(plr->mo->x - m_w/2));
// m_y = FTOM(MTOF(plr->mo->y - m_h/2));
// m_x = plr->mo->x - m_w/2;
// m_y = plr->mo->y - m_h/2;
}
}
//
//
//
void AM_updateLightLev(void)
{
static nexttic = 0;
//static int litelevels[] = { 0, 3, 5, 6, 6, 7, 7, 7 };
static int litelevels[] = { 0, 4, 7, 10, 12, 14, 15, 15 };
static int litelevelscnt = 0;
// Change light level
if (amclock>nexttic)
{
lightlev = litelevels[litelevelscnt++];
if (litelevelscnt == sizeof(litelevels)/sizeof(int)) litelevelscnt = 0;
nexttic = amclock + 6 - (amclock % 6);
}
}
//
// Updates on Game Tick
//
void AM_Ticker (void)
{
if (!automapactive)
return;
amclock++;
if (followplayer)
AM_doFollowPlayer();
// Change the zoom if necessary
if (ftom_zoommul != FRACUNIT)
AM_changeWindowScale();
// Change x,y location
if (m_paninc.x || m_paninc.y)
AM_changeWindowLoc();
// Update light level
// AM_updateLightLev();
}
//
// Clear automap frame buffer.
//
void AM_clearFB(int color, PBUFFER RenderBuffer)
//void AM_clearFB(int color)
{
int y;
for (y = 0; y < f_h; y++)
{
memset(RenderBuffer->Buffer + RenderBuffer->YLookup[y], color, f_w);
}
//memset(fb, color, f_w*f_h);
}
//
// Automap clipping of lines.
//
// Based on Cohen-Sutherland clipping algorithm but with a slightly
// faster reject and precalculated slopes. If the speed is needed,
// use a hash algorithm to handle the common cases.
//
boolean AM_clipMline( mline_t *ml, fline_t *fl )
{
enum
{
LEFT = 1,
RIGHT = 2,
BOTTOM = 4,
TOP = 8
};
register outcode1 = 0;
register outcode2 = 0;
register outside;
fpoint_t tmp;
int dx;
int dy;
// sprintf(MsgText, "Testing line : ml->a.x,ml->a.y %d,%d to ml->b.x,ml->b.y %d,%d\n", ml->a.x>>FRACBITS,ml->a.y>>FRACBITS,ml->b.x>>FRACBITS,ml->b.y>>FRACBITS);
// WriteDebug(MsgText);
#define DOOUTCODE(oc, mx, my) \
(oc) = 0; \
if ((my) < 0) (oc) |= TOP; \
else if ((my) >= f_h) (oc) |= BOTTOM; \
if ((mx) < 0) (oc) |= LEFT; \
else if ((mx) >= f_w) (oc) |= RIGHT;
// do trivial rejects and outcodes
if (ml->a.y > m_y2)
outcode1 = TOP;
else if (ml->a.y < m_y)
outcode1 = BOTTOM;
if (ml->b.y > m_y2)
outcode2 = TOP;
else if (ml->b.y < m_y)
outcode2 = BOTTOM;
if (outcode1 & outcode2)
return false; // trivially outside
if (ml->a.x < m_x)
outcode1 |= LEFT;
else if (ml->a.x > m_x2)
outcode1 |= RIGHT;
if (ml->b.x < m_x)
outcode2 |= LEFT;
else if (ml->b.x > m_x2)
outcode2 |= RIGHT;
if (outcode1 & outcode2)
return false; // trivially outside
// transform to frame-buffer coordinates.
fl->a.x = CXMTOF(ml->a.x);
fl->a.y = CYMTOF(ml->a.y);
fl->b.x = CXMTOF(ml->b.x);
fl->b.y = CYMTOF(ml->b.y);
DOOUTCODE(outcode1, fl->a.x, fl->a.y);
DOOUTCODE(outcode2, fl->b.x, fl->b.y);
if (outcode1 & outcode2)
return false;
while (outcode1 | outcode2)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -