Skip to content

Commit

Permalink
Implement option to correct automap aspect ratio (#1940)
Browse files Browse the repository at this point in the history
* Implement option to correct automap aspect ratio

* Fix gridlines when rotate mode is not on

* Fix center coordinate sliding around when rotate mode is not on

* Simplify arithmatic

* Rename "aspect ratio correction" -> "square aspect ratio"

* Merge AM_rotatePoint and AM_aspectCorrectPoint into AM_transformPoint

* Square aspect ratio of line characters

* Don't square automap when aspect ratio correction is off
  • Loading branch information
thearst3rd authored Oct 4, 2024
1 parent 9a43e54 commit 2ee9ead
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 46 deletions.
99 changes: 54 additions & 45 deletions src/am_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,12 @@ static void AM_drawFline_Vanilla(fline_t* fl, int color);
static void AM_drawFline_Smooth(fline_t* fl, int color);
void (*AM_drawFline)(fline_t*, int) = AM_drawFline_Vanilla;

// [crispy] automap rotate mode needs these early on
boolean automaprotate = false;
// [crispy/Woof!] automap rotate mode and square aspect ratio need these early on
static boolean automaprotate = false;
static boolean automapsquareaspect = false;
#define ADJUST_ASPECT_RATIO (correct_aspect_ratio && automapsquareaspect)
static void AM_rotate(int64_t *x, int64_t *y, angle_t a);
static void AM_rotatePoint(mpoint_t *pt);
static void AM_transformPoint(mpoint_t *pt);
static mpoint_t mapcenter;
static angle_t mapangle;

Expand Down Expand Up @@ -1511,19 +1513,19 @@ static void AM_drawGrid(int color)
// [crispy] moved here
ml.a.y = m_y;
ml.b.y = m_y+m_h;
if (automaprotate)
if (automaprotate || ADJUST_ASPECT_RATIO)
{
ml.a.y -= m_w / 2;
ml.b.y += m_w / 2;
AM_rotatePoint(&ml.a);
AM_rotatePoint(&ml.b);
}
AM_transformPoint(&ml.a);
AM_transformPoint(&ml.b);
AM_drawMline(&ml, color);
}

// Figure out start of horizontal gridlines
start = m_y;
if (automaprotate)
if (automaprotate || ADJUST_ASPECT_RATIO)
{
start -= m_w / 2;
}
Expand All @@ -1532,7 +1534,7 @@ static void AM_drawGrid(int color)
start += // (MAPBLOCKUNITS<<FRACBITS)
- ((start-(bmaporgy>>FRACTOMAPBITS))%gridsize);
end = m_y + m_h;
if (automaprotate)
if (automaprotate || ADJUST_ASPECT_RATIO)
{
end += m_w / 2;
}
Expand All @@ -1549,9 +1551,9 @@ static void AM_drawGrid(int color)
{
ml.a.x -= m_h / 2;
ml.b.x += m_h / 2;
AM_rotatePoint(&ml.a);
AM_rotatePoint(&ml.b);
}
AM_transformPoint(&ml.a);
AM_transformPoint(&ml.b);
AM_drawMline(&ml, color);
}
}
Expand Down Expand Up @@ -1644,11 +1646,8 @@ static void AM_drawWalls(void)
l.a.y = lines[i].v1->y >> FRACTOMAPBITS;
l.b.x = lines[i].v2->x >> FRACTOMAPBITS;
l.b.y = lines[i].v2->y >> FRACTOMAPBITS;
if (automaprotate)
{
AM_rotatePoint(&l.a);
AM_rotatePoint(&l.b);
}
AM_transformPoint(&l.a);
AM_transformPoint(&l.b);
// if line has been seen or IDDT has been used
if (ddt_cheating || (lines[i].flags & ML_MAPPED))
{
Expand Down Expand Up @@ -1877,26 +1876,36 @@ static void AM_rotate

// [crispy] rotate point around map center
// adapted from prboom-plus/src/am_map.c:898-920
static void AM_rotatePoint(mpoint_t *pt)
// [Woof!] Also, scale y coordinate of point for square aspect ratio
static void AM_transformPoint(mpoint_t *pt)
{
int64_t tmpx;
// [crispy] smooth automap rotation
angle_t smoothangle = followplayer ? ANG90 - viewangle : mapangle;
if (automaprotate)
{
int64_t tmpx;
// [crispy] smooth automap rotation
angle_t smoothangle = followplayer ? ANG90 - viewangle : mapangle;

pt->x -= mapcenter.x;
pt->y -= mapcenter.y;
pt->x -= mapcenter.x;
pt->y -= mapcenter.y;

smoothangle >>= ANGLETOFINESHIFT;
smoothangle >>= ANGLETOFINESHIFT;

tmpx = (int64_t)FixedMul(pt->x, finecosine[smoothangle])
- (int64_t)FixedMul(pt->y, finesine[smoothangle])
+ mapcenter.x;
tmpx = (int64_t)FixedMul(pt->x, finecosine[smoothangle])
- (int64_t)FixedMul(pt->y, finesine[smoothangle])
+ mapcenter.x;

pt->y = (int64_t)FixedMul(pt->x, finesine[smoothangle])
+ (int64_t)FixedMul(pt->y, finecosine[smoothangle])
+ mapcenter.y;
pt->y = (int64_t)FixedMul(pt->x, finesine[smoothangle])
+ (int64_t)FixedMul(pt->y, finecosine[smoothangle])
+ mapcenter.y;

pt->x = tmpx;
pt->x = tmpx;
}
if (ADJUST_ASPECT_RATIO)
{
int64_t diff = pt->y - mapcenter.y;
diff = 5 * diff / 6;
pt->y = mapcenter.y + diff;
}
}

//
Expand Down Expand Up @@ -1940,6 +1949,9 @@ static void AM_drawLineCharacter
if (angle)
AM_rotate(&l.a.x, &l.a.y, angle);

if (ADJUST_ASPECT_RATIO)
l.a.y = 5 * l.a.y / 6;

l.a.x += x;
l.a.y += y;

Expand All @@ -1955,6 +1967,9 @@ static void AM_drawLineCharacter
if (angle)
AM_rotate(&l.b.x, &l.b.y, angle);

if (ADJUST_ASPECT_RATIO)
l.b.y = 5 * l.b.y / 6;

l.b.x += x;
l.b.y += y;

Expand Down Expand Up @@ -1995,10 +2010,7 @@ static void AM_drawPlayers(void)
pt.x = plr->mo->x >> FRACTOMAPBITS;
pt.y = plr->mo->y >> FRACTOMAPBITS;
}
if (automaprotate)
{
AM_rotatePoint(&pt);
}
AM_transformPoint(&pt);

if (ddt_cheating)
AM_drawLineCharacter
Expand Down Expand Up @@ -2055,9 +2067,9 @@ static void AM_drawPlayers(void)
pt.y = p->mo->y >> FRACTOMAPBITS;
}

AM_transformPoint(&pt);
if (automaprotate)
{
AM_rotatePoint(&pt);
smoothangle = p->mo->angle;
}
else
Expand Down Expand Up @@ -2118,10 +2130,7 @@ static void AM_drawThings
pt.x = t->x >> FRACTOMAPBITS;
pt.y = t->y >> FRACTOMAPBITS;
}
if (automaprotate)
{
AM_rotatePoint(&pt);
}
AM_transformPoint(&pt);

//jff 1/5/98 case over doomednum of thing being drawn
if (mapcolor_rkey || mapcolor_ykey || mapcolor_bkey)
Expand Down Expand Up @@ -2225,10 +2234,7 @@ static void AM_drawMarks(void)
// [crispy] center marks around player
pt.x = markpoints[i].x;
pt.y = markpoints[i].y;
if (automaprotate)
{
AM_rotatePoint(&pt);
}
AM_transformPoint(&pt);
fx = CXMTOF(pt.x);
fy = CYMTOF(pt.y);

Expand Down Expand Up @@ -2294,13 +2300,13 @@ void AM_Drawer (void)
AM_changeWindowLoc();
}

// [crispy] required for AM_rotatePoint()
if (automaprotate)
// [crispy/Woof!] required for AM_transformPoint()
if (automaprotate || ADJUST_ASPECT_RATIO)
{
mapcenter.x = m_x + m_w / 2;
mapcenter.y = m_y + m_h / 2;
// [crispy] keep the map static if not following the player
if (followplayer)
if (automaprotate && followplayer)
{
mapangle = ANG90 - plr->mo->angle;
}
Expand Down Expand Up @@ -2421,6 +2427,9 @@ void AM_BindAutomapVariables(void)
AM_PRESET_VANILLA, AM_PRESET_ZDOOM, ss_auto, wad_no,
"Automap color preset (0 = Vanilla Doom; 1 = Crispy Doom; 2 = Boom; 3 = ZDoom)");

M_BindBool("automapsquareaspect", &automapsquareaspect, NULL, false, ss_auto, wad_no,
"Use square aspect ratio in automap");

#define BIND_CR(name, v, help) \
M_BindNum(#name, &name, NULL, (v), 0, 255, ss_none, wad_yes, help)

Expand Down
1 change: 0 additions & 1 deletion src/doomstat.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ typedef enum
} overlay_t;

extern overlay_t automapoverlay;
extern boolean automaprotate;

#define automap_on (automapactive && !automapoverlay)
#define automap_off (!automapactive || automapoverlay)
Expand Down
2 changes: 2 additions & 0 deletions src/mn_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -2061,6 +2061,8 @@ static setup_menu_t auto_settings1[] = {
{"Color Keyed Doors", S_CHOICE, H_X, M_SPC, {"map_keyed_door"},
.strings_id = str_automap_keyed_door},

{"Square Aspect Ratio", S_ONOFF, H_X, M_SPC, {"automapsquareaspect"}},

MI_RESET,

MI_END
Expand Down

0 comments on commit 2ee9ead

Please sign in to comment.