From 73b4fbe861b4da7d4957539c8791c1fe8ddec442 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 14 Apr 2020 00:25:08 +0200 Subject: [PATCH] - FGameTexture conversion in am_map.cpp --- src/am_map.cpp | 26 +++++++++++++------------- src/common/2d/v_draw.h | 6 ++++++ src/common/textures/texturemanager.h | 7 ++++++- src/common/textures/textures.h | 14 ++++++++++++++ 4 files changed, 39 insertions(+), 14 deletions(-) diff --git a/src/am_map.cpp b/src/am_map.cpp index 3648381fd..fd195ea70 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -988,7 +988,7 @@ class DAutomap :public DAutomapBase void calcMinMaxMtoF(); - void DrawMarker(FTexture *tex, double x, double y, int yadjust, + void DrawMarker(FGameTexture *tex, double x, double y, int yadjust, INTBOOL flip, double xscale, double yscale, int translation, double alpha, uint32_t fillcolor, FRenderStyle renderstyle); void rotatePoint(double *x, double *y); @@ -1235,7 +1235,7 @@ void DAutomap::ScrollParchment (double dmapx, double dmapy) if (mapback.isValid()) { - FTexture *backtex = TexMan.GetTexture(mapback); + auto backtex = TexMan.GetGameTexture(mapback); if (backtex != nullptr) { @@ -1588,7 +1588,7 @@ void DAutomap::clearFB (const AMColor &color) } else { - FTexture *backtex = TexMan.GetTexture(mapback); + auto backtex = TexMan.GetGameTexture(mapback); if (backtex != nullptr) { int pwidth = backtex->GetDisplayWidth(); @@ -2908,7 +2908,7 @@ void DAutomap::drawThings () if (am_showthingsprites > 0 && t->sprite > 0) { - FTexture *texture = nullptr; + FGameTexture *texture = nullptr; spriteframe_t *frame; int rotation = 0; @@ -2928,7 +2928,7 @@ void DAutomap::drawThings () rotation = int((angle.Normalized360() * (16. / 360.)).Degrees); const FTextureID textureID = frame->Texture[show > 2 ? rotation : 0]; - texture = TexMan.GetTexture(textureID, true); + texture = TexMan.GetGameTexture(textureID, true); } if (texture == nullptr) goto drawTriangle; // fall back to standard display if no sprite can be found. @@ -3023,7 +3023,7 @@ void DAutomap::drawThings () // //============================================================================= -void DAutomap::DrawMarker (FTexture *tex, double x, double y, int yadjust, +void DAutomap::DrawMarker (FGameTexture *tex, double x, double y, int yadjust, INTBOOL flip, double xscale, double yscale, int translation, double alpha, uint32_t fillcolor, FRenderStyle renderstyle) { if (tex == nullptr || !tex->isValid()) @@ -3035,8 +3035,8 @@ void DAutomap::DrawMarker (FTexture *tex, double x, double y, int yadjust, rotatePoint (&x, &y); } DrawTexture(twod, tex, CXMTOF(x) + f_x, CYMTOF(y) + yadjust + f_y, - DTA_DestWidthF, tex->GetDisplayWidthDouble() * CleanXfac * xscale, - DTA_DestHeightF, tex->GetDisplayHeightDouble() * CleanYfac * yscale, + DTA_DestWidth, tex->GetDisplayWidth() * CleanXfac * xscale, + DTA_DestHeight, tex->GetDisplayHeight() * CleanYfac * yscale, DTA_ClipTop, f_y, DTA_ClipBottom, f_y + f_h, DTA_ClipLeft, f_x, @@ -3072,7 +3072,7 @@ void DAutomap::drawMarks () if (font == nullptr) { - DrawMarker(TexMan.GetTexture(marknums[i], true), markpoints[i].x, markpoints[i].y, -3, 0, + DrawMarker(TexMan.GetGameTexture(marknums[i], true), markpoints[i].x, markpoints[i].y, -3, 0, 1, 1, 0, 1, 0, LegacyRenderStyles[STYLE_Normal]); } else @@ -3114,18 +3114,18 @@ void DAutomap::drawAuthorMarkers () } FTextureID picnum; - FTexture *tex; + FGameTexture *tex; uint16_t flip = 0; if (mark->picnum.isValid()) { - tex = TexMan.GetTexture(mark->picnum, true); + tex = TexMan.GetGameTexture(mark->picnum, true); if (tex->GetRotations() != 0xFFFF) { spriteframe_t *sprframe = &SpriteFrames[tex->GetRotations()]; picnum = sprframe->Texture[0]; flip = sprframe->Flip & 1; - tex = TexMan.GetTexture(picnum); + tex = TexMan.GetGameTexture(picnum); } } else @@ -3140,7 +3140,7 @@ void DAutomap::drawAuthorMarkers () spriteframe_t *sprframe = &SpriteFrames[sprdef->spriteframes + mark->frame]; picnum = sprframe->Texture[0]; flip = sprframe->Flip & 1; - tex = TexMan.GetTexture(picnum); + tex = TexMan.GetGameTexture(picnum); } } auto it = Level->GetActorIterator(mark->args[0]); diff --git a/src/common/2d/v_draw.h b/src/common/2d/v_draw.h index a3e6b747c..5aebfd833 100644 --- a/src/common/2d/v_draw.h +++ b/src/common/2d/v_draw.h @@ -214,6 +214,12 @@ void DrawText(F2DDrawer* drawer, FFont* font, int normalcolor, double x, double void DrawChar(F2DDrawer* drawer, FFont* font, int normalcolor, double x, double y, int character, int tag_first, ...); void DrawTexture(F2DDrawer* drawer, FTexture* img, double x, double y, int tags_first, ...); +template +void DrawTexture(F2DDrawer* drawer, FGameTexture* img, double x, double y, int tags_first, Params&&... params) +{ + DrawTexture(drawer, img->GetTexture(), x, y, tags_first, std::forward(params)...); +} + void DoDim(F2DDrawer* drawer, PalEntry color, float amount, int x1, int y1, int w, int h, FRenderStyle* style = nullptr); void Dim(F2DDrawer* drawer, PalEntry color, float damount, int x1, int y1, int w, int h, FRenderStyle* style = nullptr); void FillBorder(F2DDrawer *drawer, FTexture* img); // Fills the border around a 4:3 part of the screen on non-4:3 displays diff --git a/src/common/textures/texturemanager.h b/src/common/textures/texturemanager.h index ac47b170b..ed239c8ba 100644 --- a/src/common/textures/texturemanager.h +++ b/src/common/textures/texturemanager.h @@ -44,7 +44,12 @@ public: { return InternalGetTexture(texnum.GetIndex(), animate, true, false); } - + + FGameTexture* GetGameTexture(FTextureID texnum, bool animate = false) + { + return reinterpret_cast(GetTexture(texnum, animate)); + } + // This is the only access function that should be used inside the software renderer. FTexture *GetPalettedTexture(FTextureID texnum, bool animate) { diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 35487c772..74d3bed19 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -559,6 +559,20 @@ struct FTexCoordInfo void GetFromTexture(FTexture *tex, float x, float y, bool forceworldpanning); }; +// Refactoring helper to allow piece by piece adjustment of the API +class FGameTexture +{ + FTexture wrapped; +public: + FTexture* GetTexture() { return &wrapped; } + + int GetDisplayWidth() /*const*/ { return wrapped.GetDisplayWidth(); } + int GetDisplayHeight() /*const*/ { return wrapped.GetDisplayHeight(); } + + bool isValid() { return wrapped.isValid(); } + uint16_t GetRotations() { return wrapped.GetRotations(); } +}; + #endif