From 7d85acac134c963c703a505222754296322ae743 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Tue, 20 Sep 2022 10:31:01 +1000 Subject: [PATCH] - Clean up remaining automap interfaces to finish the floatification. * Even though we pre-calculate the sine/cosine needed in `DrawOverheadMap()`, Duke and SW require the full angle for their more mature automaps. --- source/core/automap.cpp | 20 +++---- source/core/automap.h | 7 +-- source/core/gamestruct.h | 2 +- source/games/blood/src/blood.h | 2 +- source/games/blood/src/view.cpp | 16 +++--- source/games/duke/src/duke3d.h | 2 +- source/games/duke/src/game_misc.cpp | 88 ++++++++++------------------- source/games/exhumed/src/exhumed.h | 2 +- source/games/exhumed/src/map.cpp | 16 +++--- source/games/sw/src/draw.cpp | 79 ++++++++------------------ source/games/sw/src/game.h | 2 +- 11 files changed, 87 insertions(+), 149 deletions(-) diff --git a/source/core/automap.cpp b/source/core/automap.cpp index 4d760c5cf..2726db062 100644 --- a/source/core/automap.cpp +++ b/source/core/automap.cpp @@ -115,7 +115,6 @@ CCMD(togglerotate) Printf(PRINT_NOTIFY, "%s\n", msg); } - CCMD(am_zoom) { if (argv.argc() >= 2) @@ -182,7 +181,7 @@ static void CalcMapBounds() // //--------------------------------------------------------------------------- -void AutomapControl(const DAngle ang) +void AutomapControl() { static double nonsharedtimer; double ms = screen->FrameTime; @@ -225,7 +224,7 @@ void AutomapControl(const DAngle ang) if (min_bounds.X == INT_MAX) CalcMapBounds(); - follow = clamp(follow + DVector2(panvert, panhorz).Rotated(ang) * zoomspeed, min_bounds, max_bounds); + follow = clamp(follow + DVector2(panvert, panhorz).Rotated(follow_a) * zoomspeed, min_bounds, max_bounds); } } } @@ -309,7 +308,7 @@ void drawlinergb(const double x1, const double y1, const double x2, const double // //--------------------------------------------------------------------------- -PalEntry RedLineColor() +static inline PalEntry RedLineColor() { // todo: // Blood uses palette index 12 (99,99,99) @@ -318,7 +317,7 @@ PalEntry RedLineColor() return automapMode == am_overlay? *am_ovtwosidedcolor : *am_twosidedcolor; } -PalEntry WhiteLineColor() +static inline PalEntry WhiteLineColor() { // todo: @@ -328,7 +327,7 @@ PalEntry WhiteLineColor() return automapMode == am_overlay ? *am_ovonesidedcolor : *am_onesidedcolor; } -PalEntry PlayerLineColor() +static inline PalEntry PlayerLineColor() { return automapMode == am_overlay ? *am_ovplayercolor : *am_playercolor; } @@ -341,6 +340,7 @@ CCMD(printpalcol) int i = atoi(argv[1]); Printf("%d, %d, %d\n", GPalette.BaseColors[i].r, GPalette.BaseColors[i].g, GPalette.BaseColors[i].b); } + //--------------------------------------------------------------------------- // // @@ -589,11 +589,11 @@ static void renderDrawMapView(const DVector2& cpos, const double sine, const dou // //--------------------------------------------------------------------------- -void DrawOverheadMap(int pl_x, int pl_y, const DAngle pl_angle, double const smoothratio) +void DrawOverheadMap(const DVector2& plxy, const DAngle pl_angle, double const smoothratio) { if (am_followplayer || follow.X == INT_MAX) { - follow = DVector2(pl_x, pl_y) * inttoworld; + follow = plxy; } follow_a = -(am_rotate ? pl_angle : DAngle270); @@ -601,7 +601,7 @@ void DrawOverheadMap(int pl_x, int pl_y, const DAngle pl_angle, double const smo const double sine = follow_a.Sin(); const double cosine = follow_a.Cos(); - AutomapControl(-follow_a); + AutomapControl(); if (automapMode == am_full) { @@ -611,7 +611,7 @@ void DrawOverheadMap(int pl_x, int pl_y, const DAngle pl_angle, double const smo drawredlines(follow, sine, cosine, xydim); drawwhitelines(follow, sine, cosine, xydim); - if (!gi->DrawAutomapPlayer(pl_x, pl_y, follow.X * worldtoint, follow.Y * worldtoint, gZoom * 1024, -follow_a, smoothratio)) + if (!gi->DrawAutomapPlayer(plxy, follow, follow_a, xydim, gZoom, smoothratio)) DrawPlayerArrow(follow, follow_a, gZoom, pl_angle); } diff --git a/source/core/automap.h b/source/core/automap.h index 2835abe20..6b3fa2e20 100644 --- a/source/core/automap.h +++ b/source/core/automap.h @@ -16,15 +16,10 @@ extern BitArray show2dwall; void SerializeAutomap(FSerializer& arc); void ClearAutomap(); void MarkSectorSeen(sectortype* sect); -void DrawOverheadMap(int pl_x, int pl_y, const DAngle pl_angle, double const smoothratio); +void DrawOverheadMap(const DVector2& plxy, const DAngle pl_angle, double const smoothratio); bool AM_Responder(event_t* ev, bool last); void drawlinergb(const double x1, const double y1, const double x2, const double y2, PalEntry p); -inline void drawlinergb(int32_t x1, int32_t y1, int32_t x2, int32_t y2, PalEntry p) -{ - drawlinergb(x1 / 4096., y1 / 4096., x2 / 4096., y2 / 4096., p); -} - inline DVector2 OutAutomapVector(const DVector2& pos, const double sine, const double cosine, const double zoom = 1., const DVector2& xydim = { 0, 0 }) { return pos.Rotated(cosine, sine).Rotated90CW() * zoom + xydim; diff --git a/source/core/gamestruct.h b/source/core/gamestruct.h index b5049ddac..0a2e27f6e 100644 --- a/source/core/gamestruct.h +++ b/source/core/gamestruct.h @@ -107,7 +107,7 @@ struct GameInterface virtual void NextLevel(MapRecord* map, int skill) {} virtual void NewGame(MapRecord* map, int skill, bool special = false) {} virtual void LevelCompleted(MapRecord* map, int skill) {} - virtual bool DrawAutomapPlayer(int mx, int my, int x, int y, const double z, const DAngle a, double const smoothratio) { return false; } + virtual bool DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, const DAngle cang, const DVector2& xydim, const double czoom, double const smoothratio) { return false; } virtual void SetTileProps(int tile, int surf, int vox, int shade) {} virtual fixed_t playerHorizMin() { return IntToFixed(-200); } virtual fixed_t playerHorizMax() { return IntToFixed(200); } diff --git a/source/games/blood/src/blood.h b/source/games/blood/src/blood.h index 6e948b2b0..d58146f36 100644 --- a/source/games/blood/src/blood.h +++ b/source/games/blood/src/blood.h @@ -133,7 +133,7 @@ struct GameInterface : public ::GameInterface void NewGame(MapRecord* sng, int skill, bool) override; void NextLevel(MapRecord* map, int skill) override; void LevelCompleted(MapRecord* map, int skill) override; - bool DrawAutomapPlayer(int mx, int my, int x, int y, const double z, const DAngle a, double const smoothratio) override; + bool DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, const DAngle cang, const DVector2& xydim, const double czoom, double const smoothratio) override; void SetTileProps(int til, int surf, int vox, int shade) override; fixed_t playerHorizMin() override { return IntToFixed(-180); } fixed_t playerHorizMax() override { return IntToFixed(120); } diff --git a/source/games/blood/src/view.cpp b/source/games/blood/src/view.cpp index 0c7705eed..6c51a908d 100644 --- a/source/games/blood/src/view.cpp +++ b/source/games/blood/src/view.cpp @@ -472,10 +472,9 @@ static void DrawMap(DBloodActor* view) tm = 1; } VIEW* pView = &gPrevView[gViewIndex]; - int x = interpolatedvalue(pView->x, view->int_pos().X, gInterpolate); - int y = interpolatedvalue(pView->y, view->int_pos().Y, gInterpolate); + auto xy = DVector2(interpolatedvalue(pView->x, view->int_pos().X, gInterpolate), interpolatedvalue(pView->y, view->int_pos().Y, gInterpolate)) * inttoworld; auto ang = !SyncInput() ? gView->angle.sum() : gView->angle.interpolatedsum(gInterpolate); - DrawOverheadMap(x, y, ang, gInterpolate); + DrawOverheadMap(xy, ang, gInterpolate); if (tm) setViewport(hud_size); } @@ -860,18 +859,19 @@ std::pair GameInterface::GetCoordinates() // //--------------------------------------------------------------------------- -bool GameInterface::DrawAutomapPlayer(int mx, int my, int x, int y, const double z, const DAngle a, double const smoothratio) +bool GameInterface::DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, const DAngle cang, const DVector2& xydim, const double czoom, double const smoothratio) { + auto cangsin = cang.Sin(); + auto cangcos = cang.Cos(); + for (int i = connecthead; i >= 0; i = connectpoint2[i]) { if (i == gView->nPlayer || gGameOptions.nGameType == 1) { - auto an = -a; - auto xydim = DVector2(twod->GetWidth() * 0.5, twod->GetHeight() * 0.5); auto actor = gPlayer[i].actor; - auto vect = OutAutomapVector(DVector2(mx, my) - DVector2(x, y), a.Sin(), a.Cos(), z, xydim); + auto vect = OutAutomapVector(mxy - cpos, cangsin, cangcos, czoom, xydim); - DrawTexture(twod, tileGetTexture(actor->spr.picnum, true), vect.X, vect.Y, DTA_ClipLeft, viewport3d.Left(), DTA_ClipTop, viewport3d.Top(), DTA_ScaleX, z / 1536., DTA_ScaleY, z / 1536., DTA_CenterOffset, true, + DrawTexture(twod, tileGetTexture(actor->spr.picnum, true), vect.X, vect.Y, DTA_ClipLeft, viewport3d.Left(), DTA_ClipTop, viewport3d.Top(), DTA_ScaleX, czoom * (2. / 3.), DTA_ScaleY, czoom * (2. / 3.), DTA_CenterOffset, true, DTA_ClipRight, viewport3d.Right(), DTA_ClipBottom, viewport3d.Bottom(), DTA_Alpha, (actor->spr.cstat & CSTAT_SPRITE_TRANSLUCENT ? 0.5 : 1.), TAG_DONE); } } diff --git a/source/games/duke/src/duke3d.h b/source/games/duke/src/duke3d.h index 475e8d295..80a364033 100644 --- a/source/games/duke/src/duke3d.h +++ b/source/games/duke/src/duke3d.h @@ -50,7 +50,7 @@ struct GameInterface : public ::GameInterface void NextLevel(MapRecord* map, int skill) override; void NewGame(MapRecord* map, int skill, bool) override; void LevelCompleted(MapRecord* map, int skill) override; - bool DrawAutomapPlayer(int mx, int my, int x, int y, const double z, const DAngle a, double const smoothratio) override; + bool DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, const DAngle cang, const DVector2& xydim, const double czoom, double const smoothratio) override; int playerKeyMove() override { return 40; } void WarpToCoords(double x, double y, double z, DAngle ang, int horz) override; void ToggleThirdPerson() override; diff --git a/source/games/duke/src/game_misc.cpp b/source/games/duke/src/game_misc.cpp index 8605a78fc..b5d7668f8 100644 --- a/source/games/duke/src/game_misc.cpp +++ b/source/games/duke/src/game_misc.cpp @@ -229,7 +229,7 @@ void V_AddBlend (float r, float g, float b, float a, float v_blend[4]) void drawoverlays(double smoothratio) { player_struct* pp; - int cposx, cposy; + DVector2 cposxy; DAngle cang; pp = &ps[screenpeek]; @@ -266,24 +266,21 @@ void drawoverlays(double smoothratio) { if (screenpeek == myconnectindex && numplayers > 1) { - cposx = interpolatedvalue(omyx, myx, smoothratio); - cposy = interpolatedvalue(omyy, myy, smoothratio); + cposxy = DVector2(interpolatedvalue(omyx, myx, smoothratio), interpolatedvalue(omyy, myy, smoothratio)) * inttoworld; cang = !SyncInput() ? myang : interpolatedangle(omyang, myang, smoothratio); } else { - cposx = interpolatedvalue(pp->player_int_opos().X, pp->player_int_pos().X, smoothratio); - cposy = interpolatedvalue(pp->player_int_opos().Y, pp->player_int_pos().Y, smoothratio); + cposxy = interpolatedvec3(pp->opos, pp->pos, smoothratio / 65536.).XY(); cang = !SyncInput() ? pp->angle.ang : interpolatedangle(pp->angle.oang, pp->angle.ang, smoothratio); } } else { - cposx = pp->player_int_opos().X; - cposy = pp->player_int_opos().Y; + cposxy = pp->opos.XY(); cang = pp->angle.oang; } - DrawOverheadMap(cposx, cposy, cang, smoothratio); + DrawOverheadMap(cposxy, cang, smoothratio); RestoreInterpolations(); } } @@ -385,27 +382,15 @@ ReservedSpace GameInterface::GetReservedScreenSpace(int viewsize) // //--------------------------------------------------------------------------- -bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, const double czoom, const DAngle cang, double const smoothratio) +bool GameInterface::DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, const DAngle cang, const DVector2& xydim, const double czoom, double const smoothratio) { DVector2 b1, b2, b3, b4, v1, v2, v3, v4; - DAngle an; - int i, j, xoff, yoff; - int xspan, yspan, sprx, spry; - int tilenum; - int xvect, yvect; - int p; - PalEntry col; + int xoff, yoff, xspan, yspan, tilenum; - xvect = -cang.Sin() * 16384. * czoom; - yvect = -cang.Cos() * 16384. * czoom; + auto cangsin = cang.Sin(); + auto cangcos = cang.Cos(); - int xdim = twod->GetWidth() << 11; - int ydim = twod->GetHeight() << 11; - - auto xydim = DVector2(twod->GetWidth() * 0.5, twod->GetHeight() * 0.5); - auto cp = DVector2(cposx, cposy) * inttoworld; - - //Draw sprites + // Draw sprites auto pactor = ps[screenpeek].GetActor(); for (unsigned ii = 0; ii < sector.Size(); ii++) { @@ -415,20 +400,13 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, cons { if (act == pactor || (act->spr.cstat & CSTAT_SPRITE_INVISIBLE) || act->spr.cstat == CSTAT_SPRITE_BLOCK_ALL || act->spr.xrepeat == 0) continue; - col = PalEntry(0, 170, 170); - if (act->spr.cstat & CSTAT_SPRITE_BLOCK) col = PalEntry(170, 0, 170); - - sprx = act->int_pos().X; - spry = act->int_pos().Y; - - auto sp = DVector2(sprx, spry) * inttoworld; + PalEntry col = act->spr.cstat & CSTAT_SPRITE_BLOCK ? PalEntry(170, 0, 170) : PalEntry(0, 170, 170); if ((act->spr.cstat & CSTAT_SPRITE_BLOCK_ALL) != 0) switch (act->spr.cstat & CSTAT_SPRITE_ALIGNMENT_MASK) { case CSTAT_SPRITE_ALIGNMENT_FACING: - an = -cang; - v1 = OutAutomapVector(DVector2(sprx - cposx, spry - cposy) * inttoworld, an.Sin(), an.Cos(), czoom / 1024.); - v2 = OutAutomapVector(act->spr.angle.ToVector() * 8., an.Sin(), an.Cos(), czoom / 1024.); + v1 = OutAutomapVector(act->spr.pos.XY() - cpos, cangsin, cangcos, czoom); + v2 = OutAutomapVector(act->spr.angle.ToVector() * 8., cangsin, cangcos, czoom); drawlinergb(v1.X - v2.X + xydim.X, v1.Y - v2.Y + xydim.Y, v1.X + v2.X + xydim.X, v1.Y + v2.Y + xydim.Y, col); drawlinergb(v1.X - v2.Y + xydim.X, v1.Y + v2.X + xydim.Y, v1.X + v2.X + xydim.X, v1.Y + v2.Y + xydim.Y, col); @@ -444,13 +422,12 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, cons xspan = tileWidth(tilenum); - an = -cang; b1 = act->spr.angle.ToVector().Rotated90CW() * act->spr.xrepeat * (1. / 64.); - b2 = sp * inttoworld - b1 * ((xspan * 0.5) + xoff); + b2 = act->spr.pos.XY() - b1 * ((xspan * 0.5) + xoff); b3 = b2 + b1 * xspan; - v1 = OutAutomapVector(b2 - cp, an.Sin(), an.Cos(), czoom / 1024., xydim); - v2 = OutAutomapVector(b3 - cp, an.Sin(), an.Cos(), czoom / 1024., xydim); + v1 = OutAutomapVector(b2 - cpos, cangsin, cangcos, czoom, xydim); + v2 = OutAutomapVector(b3 - cpos, cangsin, cangcos, czoom, xydim); drawlinergb(v1.X, v1.Y, v2.X, v2.Y, col); } @@ -470,29 +447,27 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, cons if ((act->spr.cstat & CSTAT_SPRITE_XFLIP) > 0) xoff = -xoff; if ((act->spr.cstat & CSTAT_SPRITE_YFLIP) > 0) yoff = -yoff; - an = -cang; - - auto acos = act->spr.angle.Cos(); - auto asin = act->spr.angle.Sin(); + auto sprcos = act->spr.angle.Cos(); + auto sprsin = act->spr.angle.Sin(); xspan = tileWidth(tilenum); auto xrep = act->spr.xrepeat * (1. / 64.); yspan = tileHeight(tilenum); auto yrep = act->spr.yrepeat * (1. / 64.); - auto xscale = DVector2(-asin * xspan * xrep, +acos * xspan * xrep); - auto yscale = DVector2(-acos * yspan * yrep, -asin * yspan * yrep); + auto xscale = DVector2(-sprsin * xspan * xrep, +sprcos * xspan * xrep); + auto yscale = DVector2(-sprcos * yspan * yrep, -sprsin * yspan * yrep); auto b0 = DVector2(((xspan * 0.5) + xoff) * xrep, ((yspan * 0.5) + yoff) * yrep); - b1 = sp + (b0 * asin) + (b0.Rotated90CW() * acos); + b1 = act->spr.pos.XY() + (b0 * sprsin) + (b0.Rotated90CW() * sprcos); b2 = b1 + xscale; b3 = b2 + yscale; b4 = b1 + yscale; - v1 = OutAutomapVector(-(b1 - cp), -an.Sin(), -an.Cos(), czoom / 1024., xydim); - v2 = OutAutomapVector(-(b2 - cp), -an.Sin(), -an.Cos(), czoom / 1024., xydim); - v3 = OutAutomapVector(-(b3 - cp), -an.Sin(), -an.Cos(), czoom / 1024., xydim); - v4 = OutAutomapVector(-(b4 - cp), -an.Sin(), -an.Cos(), czoom / 1024., xydim); + v1 = OutAutomapVector(b1 - cpos, cangsin, cangcos, czoom, xydim); + v2 = OutAutomapVector(b2 - cpos, cangsin, cangcos, czoom, xydim); + v3 = OutAutomapVector(b3 - cpos, cangsin, cangcos, czoom, xydim); + v4 = OutAutomapVector(b4 - cpos, cangsin, cangcos, czoom, xydim); drawlinergb(v1.X, v1.Y, v2.X, v2.Y, col); drawlinergb(v2.X, v2.Y, v3.X, v3.Y, col); @@ -503,21 +478,20 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, cons } } - for (p = connecthead; p >= 0; p = connectpoint2[p]) + for (int p = connecthead; p >= 0; p = connectpoint2[p]) { if (p == screenpeek || ud.coop == 1) { auto& pp = ps[p]; auto act = pp.GetActor(); - i = TILE_APLAYERTOP + (act->spr.xvel > 16 && pp.on_ground ? (PlayClock >> 4) & 3 : 0); - j = clamp(czoom * (act->spr.yrepeat + abs(pp.truefz - pp.pos.Z)), 22000., 131072.); + int i = TILE_APLAYERTOP + (act->spr.xvel > 16 && pp.on_ground ? (PlayClock >> 4) & 3 : 0); + double j = clamp(czoom * act->spr.yrepeat + abs(pp.truefz - pp.pos.Z), 21.5, 128.) * REPEAT_SCALE; - an = -cang; - auto const vec = OutAutomapVector(DVector2(mx, my) * inttoworld - cp, an.Sin(), an.Cos(), czoom / 1024., xydim); - auto const daang = -((!SyncInput() ? act->spr.angle : act->interpolatedangle(smoothratio / 65536.)) - cang).Normalized360().Degrees(); + auto const vec = OutAutomapVector(mxy - cpos, cangsin, cangcos, czoom, xydim); + auto const daang = -((!SyncInput() ? act->spr.angle : act->interpolatedangle(smoothratio / 65536.)) + cang).Normalized360().Degrees(); DrawTexture(twod, tileGetTexture(i), vec.X, vec.Y, DTA_TranslationIndex, TRANSLATION(Translation_Remap + setpal(&pp), act->spr.pal), DTA_CenterOffset, true, - DTA_Rotate, daang, DTA_Color, shadeToLight(act->spr.shade), DTA_ScaleX, j / 65536., DTA_ScaleY, j / 65536., TAG_DONE); + DTA_Rotate, daang, DTA_Color, shadeToLight(act->spr.shade), DTA_ScaleX, j, DTA_ScaleY, j, TAG_DONE); } } return true; diff --git a/source/games/exhumed/src/exhumed.h b/source/games/exhumed/src/exhumed.h index f49e1d805..1ecdffd3d 100644 --- a/source/games/exhumed/src/exhumed.h +++ b/source/games/exhumed/src/exhumed.h @@ -230,7 +230,7 @@ struct GameInterface : public ::GameInterface void NewGame(MapRecord *map, int skill, bool) override; void LevelCompleted(MapRecord *map, int skill) override; void NextLevel(MapRecord *map, int skill) override; - bool DrawAutomapPlayer(int mx, int my, int x, int y, const double z, const DAngle a, double const smoothratio) override; + bool DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, const DAngle cang, const DVector2& xydim, const double czoom, double const smoothratio) override; fixed_t playerHorizMin() override { return IntToFixed(-150); } fixed_t playerHorizMax() override { return IntToFixed(150); } int playerKeyMove() override { return 6; } diff --git a/source/games/exhumed/src/map.cpp b/source/games/exhumed/src/map.cpp index d117e4f57..9698f9b70 100644 --- a/source/games/exhumed/src/map.cpp +++ b/source/games/exhumed/src/map.cpp @@ -49,11 +49,8 @@ void DrawMap(double const smoothratio) if (!nFreeze && automapMode != am_off) { auto pPlayerActor = PlayerList[nLocalPlayer].pActor; - - int x = pPlayerActor->__interpolatedx(smoothratio); - int y = pPlayerActor->__interpolatedy(smoothratio); auto ang = !SyncInput() ? PlayerList[nLocalPlayer].angle.sum() : PlayerList[nLocalPlayer].angle.interpolatedsum(smoothratio); - DrawOverheadMap(x, y, ang, smoothratio); + DrawOverheadMap(pPlayerActor->interpolatedvec3(smoothratio / 65536.).XY(), ang, smoothratio); } } @@ -69,18 +66,19 @@ void GetActorExtents(DExhumedActor* actor, int* top, int* bottom) } } -bool GameInterface::DrawAutomapPlayer(int mx, int my, int x, int y, const double z, const DAngle a, double const smoothratio) +bool GameInterface::DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, const DAngle cang, const DVector2& xydim, const double czoom, double const smoothratio) { + auto cangsin = cang.Sin(); + auto cangcos = cang.Cos(); + for (int i = connecthead; i >= 0; i = connectpoint2[i]) { if (i == nLocalPlayer)// || gGameOptions.nGameType == 1) { auto pPlayerActor = PlayerList[i].pActor; - auto an = -a; - auto xydim = DVector2(twod->GetWidth() * 0.5, twod->GetHeight() * 0.5); - auto vect = OutAutomapVector(DVector2(mx, my) - DVector2(x, y), a.Sin(), a.Cos(), z, xydim); + auto vect = OutAutomapVector(mxy - cpos, cangsin, cangcos, czoom, xydim); - DrawTexture(twod, tileGetTexture(pPlayerActor->spr.picnum /*+ ((PlayClock >> 4) & 3)*/, true), vect.X, vect.Y, DTA_ClipLeft, viewport3d.Left(), DTA_ClipTop, viewport3d.Top(), DTA_ScaleX, z / 1536., DTA_ScaleY, z / 1536., DTA_CenterOffset, true, + DrawTexture(twod, tileGetTexture(pPlayerActor->spr.picnum /*+ ((PlayClock >> 4) & 3)*/, true), vect.X, vect.Y, DTA_ClipLeft, viewport3d.Left(), DTA_ClipTop, viewport3d.Top(), DTA_ScaleX, czoom * (2. / 3.), DTA_ScaleY, czoom * (2. / 3.), DTA_CenterOffset, true, DTA_ClipRight, viewport3d.Right(), DTA_ClipBottom, viewport3d.Bottom(), DTA_Alpha, (pPlayerActor->spr.cstat & CSTAT_SPRITE_TRANSLUCENT ? 0.5 : 1.), TAG_DONE); break; } diff --git a/source/games/sw/src/draw.cpp b/source/games/sw/src/draw.cpp index 3817890a5..93e7f46ac 100644 --- a/source/games/sw/src/draw.cpp +++ b/source/games/sw/src/draw.cpp @@ -1508,7 +1508,7 @@ void drawscreen(PLAYER* pp, double smoothratio, bool sceneonly) } } } - DrawOverheadMap(tx, ty, tang, smoothratio); + DrawOverheadMap(DVector2(tx, ty) * inttoworld, tang, smoothratio); } SWSpriteIterator it; @@ -1570,28 +1570,15 @@ bool GameInterface::GenerateSavePic() -bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, const double czoom, const DAngle cang, double const smoothratio) +bool GameInterface::DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, const DAngle cang, const DVector2& xydim, const double czoom, double const smoothratio) { DVector2 b1, b2, b3, b4, v1, v2, v3, v4; - DAngle an; - int k, l, x1, y1, x2, y2, x3, y3, x4, y4, ox, oy, xoff, yoff; - int dax, day, cosang, sinang, xspan, yspan, sprx, spry; - int xrepeat, yrepeat, z1, z2, startwall, endwall, tilenum; - int xvect, yvect; - walltype* wal, * wal2; - short p; + int xoff, yoff, xspan, yspan, tilenum, p; static int pspr_ndx[8] = { 0,0,0,0,0,0,0,0 }; bool sprisplayer = false; - short txt_x, txt_y; - xvect = -cang.Sin() * 16384. * czoom; - yvect = -cang.Cos() * 16384. * czoom; - - int xdim = twod->GetWidth() << 11; - int ydim = twod->GetHeight() << 11; - - auto xydim = DVector2(twod->GetWidth() * 0.5, twod->GetHeight() * 0.5); - auto cp = DVector2(cposx, cposy) * inttoworld; + auto cangsin = cang.Sin(); + auto cangcos = cang.Cos(); // Draw sprites auto peekActor = Player[screenpeek].actor; @@ -1615,34 +1602,21 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, cons { SHOWSPRITE: - PalEntry col = GPalette.BaseColors[56]; // 1=white / 31=black / 44=green / 56=pink / 128=yellow / 210=blue / 248=orange / 255=purple - if ((actor->spr.cstat & CSTAT_SPRITE_BLOCK) > 0) - col = GPalette.BaseColors[248]; - if (actor == peekActor) - col = GPalette.BaseColors[31]; + // 1=white / 31=black / 44=green / 56=pink / 128=yellow / 210=blue / 248=orange / 255=purple + PalEntry col = (actor->spr.cstat & CSTAT_SPRITE_BLOCK) > 0 ? GPalette.BaseColors[248] : actor == peekActor ? GPalette.BaseColors[31] : GPalette.BaseColors[56]; - sprx = actor->int_pos().X; - spry = actor->int_pos().Y; - - k = actor->spr.statnum; - if ((k >= 1) && (k <= 8) && (k != 2)) // Interpolate moving - { - sprx = actor->__interpolatedx(smoothratio); - spry = actor->__interpolatedy(smoothratio); - } - - auto sp = DVector2(sprx, spry) * inttoworld; + auto statnum = actor->spr.statnum; + auto sprxy = ((statnum >= 1) && (statnum <= 8) && (statnum != 2) ? actor->interpolatedvec3(smoothratio / 65536.) : actor->spr.pos).XY(); switch (actor->spr.cstat & CSTAT_SPRITE_ALIGNMENT_MASK) { case CSTAT_SPRITE_ALIGNMENT_FACING: // Regular sprite if (Player[p].actor == actor) { - if (czoom > 192) + if (czoom > 0.1875) { - an = -cang; - const auto daang = -((!SyncInput() ? actor->spr.angle : actor->interpolatedangle(smoothratio / 65536.)) - cang).Normalized360().Degrees(); - auto vect = OutAutomapVector(DVector2(mx, my) * inttoworld - cp, an.Sin(), an.Cos(), czoom / 1024., xydim); + const auto daang = -((!SyncInput() ? actor->spr.angle : actor->interpolatedangle(smoothratio / 65536.)) + cang).Normalized360().Degrees(); + auto vect = OutAutomapVector(mxy - cpos, cangsin, cangcos, czoom, xydim); // Special case tiles if (actor->spr.picnum == 3123) break; @@ -1655,7 +1629,7 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, cons } else spnum = actor->spr.picnum; - double sc = czoom * (actor->spr.yrepeat) / 32768.; + double sc = czoom * actor->spr.yrepeat * (1. / 32.); if (spnum >= 0) { DrawTexture(twod, tileGetTexture(1196 + pspr_ndx[myconnectindex], true), vect.X, vect.Y, DTA_ScaleX, sc, DTA_ScaleY, sc, DTA_Rotate, daang, @@ -1673,13 +1647,12 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, cons xspan = tileWidth(tilenum); - an = -cang; b1 = actor->spr.angle.ToVector().Rotated90CW() * actor->spr.xrepeat * (1. / 64.); - b2 = sp - b1 * ((xspan * 0.5) + xoff); + b2 = sprxy - b1 * ((xspan * 0.5) + xoff); b3 = b2 + b1 * xspan; - v1 = OutAutomapVector(b2 - cp, an.Sin(), an.Cos(), czoom / 1024., xydim); - v2 = OutAutomapVector(b3 - cp, an.Sin(), an.Cos(), czoom / 1024., xydim); + v1 = OutAutomapVector(b2 - cpos, cangsin, cangcos, czoom, xydim); + v2 = OutAutomapVector(b3 - cpos, cangsin, cangcos, czoom, xydim); drawlinergb(v1.X, v1.Y, v2.X, v2.Y, col); break; @@ -1694,29 +1667,27 @@ bool GameInterface::DrawAutomapPlayer(int mx, int my, int cposx, int cposy, cons if ((actor->spr.cstat & CSTAT_SPRITE_YFLIP) > 0) yoff = -yoff; - an = -cang; - - auto acos = actor->spr.angle.Cos(); - auto asin = actor->spr.angle.Sin(); + auto sprcos = actor->spr.angle.Cos(); + auto sprsin = actor->spr.angle.Sin(); xspan = tileWidth(tilenum); auto xrep = actor->spr.xrepeat * (1. / 64.); yspan = tileHeight(tilenum); auto yrep = actor->spr.yrepeat * (1. / 64.); - auto xscale = DVector2(-asin * xspan * xrep, +acos * xspan * xrep); - auto yscale = DVector2(-acos * yspan * yrep, -asin * yspan * yrep); + auto xscale = DVector2(-sprsin * xspan * xrep, +sprcos * xspan * xrep); + auto yscale = DVector2(-sprcos * yspan * yrep, -sprsin * yspan * yrep); auto b0 = DVector2(((xspan * 0.5) + xoff) * xrep, ((yspan * 0.5) + yoff) * yrep); - b1 = sp + (b0 * asin) + (b0.Rotated90CW() * acos); + b1 = sprxy + (b0 * sprsin) + (b0.Rotated90CW() * sprcos); b2 = b1 + xscale; b3 = b2 + yscale; b4 = b1 + yscale; - v1 = OutAutomapVector(-(b1 - cp), -an.Sin(), -an.Cos(), czoom / 1024., xydim); - v2 = OutAutomapVector(-(b2 - cp), -an.Sin(), -an.Cos(), czoom / 1024., xydim); - v3 = OutAutomapVector(-(b3 - cp), -an.Sin(), -an.Cos(), czoom / 1024., xydim); - v4 = OutAutomapVector(-(b4 - cp), -an.Sin(), -an.Cos(), czoom / 1024., xydim); + v1 = OutAutomapVector(b1 - cpos, cangsin, cangcos, czoom, xydim); + v2 = OutAutomapVector(b2 - cpos, cangsin, cangcos, czoom, xydim); + v3 = OutAutomapVector(b3 - cpos, cangsin, cangcos, czoom, xydim); + v4 = OutAutomapVector(b4 - cpos, cangsin, cangcos, czoom, xydim); drawlinergb(v1.X, v1.Y, v2.X, v2.Y, col); drawlinergb(v2.X, v2.Y, v3.X, v3.Y, col); diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 44c8562b1..d90adfb66 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -2044,7 +2044,7 @@ struct GameInterface : public ::GameInterface void LevelCompleted(MapRecord *map, int skill) override; void NextLevel(MapRecord *map, int skill) override; void NewGame(MapRecord *map, int skill, bool) override; - bool DrawAutomapPlayer(int mx, int my, int x, int y, const double z, const DAngle a, double const smoothratio) override; + bool DrawAutomapPlayer(const DVector2& mxy, const DVector2& cpos, const DAngle cang, const DVector2& xydim, const double czoom, double const smoothratio) override; int playerKeyMove() override { return 35; } void WarpToCoords(double x, double y, double z, DAngle ang, int horz) override; void ToggleThirdPerson() override;