From 688b23b85db663f6a1a9d4085049877f08f6b0c2 Mon Sep 17 00:00:00 2001 From: Misa Date: Mon, 19 Oct 2020 23:55:49 -0700 Subject: [PATCH] Standardize on using reference to tilesvec/spritesvec instead of pointer This cleans up the code readability a bit, as it's nicer to use reference syntax when indexing an array instead of that ugly pointer syntax. --- desktop_version/src/Graphics.cpp | 60 ++++++++++++-------------------- 1 file changed, 22 insertions(+), 38 deletions(-) diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index 2b7945d9..05e63b67 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -1600,25 +1600,9 @@ void Graphics::drawentities() bool custom_gray = false; #endif - std::vector *tilesvec; - if (map.custommode && !map.finalmode) - { - tilesvec = &entcolours; - } - else - { - tilesvec = &tiles; - } + std::vector& tilesvec = (map.custommode && !map.finalmode) ? entcolours : tiles; - std::vector *spritesvec; - if (flipmode) - { - spritesvec = &flipsprites; - } - else - { - spritesvec = &sprites; - } + std::vector& spritesvec = flipmode ? flipsprites : sprites; int yoff; if (map.towermode) @@ -1645,7 +1629,7 @@ void Graphics::drawentities() case 0: { // Sprites - if (!INBOUNDS_VEC(obj.entities[i].drawframe, (*spritesvec))) + if (!INBOUNDS_VEC(obj.entities[i].drawframe, spritesvec)) { continue; } @@ -1656,7 +1640,7 @@ void Graphics::drawentities() drawRect = sprites_rect; drawRect.x += tpoint.x; drawRect.y += tpoint.y; - BlitSurfaceColoured((*spritesvec)[obj.entities[i].drawframe], NULL, backBuffer, &drawRect, ct); + BlitSurfaceColoured(spritesvec[obj.entities[i].drawframe], NULL, backBuffer, &drawRect, ct); //screenwrapping! point wrappedPoint; @@ -1693,21 +1677,21 @@ void Graphics::drawentities() drawRect = sprites_rect; drawRect.x += wrappedPoint.x; drawRect.y += tpoint.y; - BlitSurfaceColoured((*spritesvec)[obj.entities[i].drawframe], NULL, backBuffer, &drawRect, ct); + BlitSurfaceColoured(spritesvec[obj.entities[i].drawframe], NULL, backBuffer, &drawRect, ct); } if (wrapY && map.warpy) { drawRect = sprites_rect; drawRect.x += tpoint.x; drawRect.y += wrappedPoint.y; - BlitSurfaceColoured((*spritesvec)[obj.entities[i].drawframe], NULL, backBuffer, &drawRect, ct); + BlitSurfaceColoured(spritesvec[obj.entities[i].drawframe], NULL, backBuffer, &drawRect, ct); } if (wrapX && wrapY && map.warpx && map.warpy) { drawRect = sprites_rect; drawRect.x += wrappedPoint.x; drawRect.y += wrappedPoint.y; - BlitSurfaceColoured((*spritesvec)[obj.entities[i].drawframe], NULL, backBuffer, &drawRect, ct); + BlitSurfaceColoured(spritesvec[obj.entities[i].drawframe], NULL, backBuffer, &drawRect, ct); } break; } @@ -1728,7 +1712,7 @@ void Graphics::drawentities() case 8: { // Special: Moving platform, 4 tiles or 8 tiles - if (!INBOUNDS_VEC(obj.entities[i].drawframe, (*tilesvec))) + if (!INBOUNDS_VEC(obj.entities[i].drawframe, tilesvec)) { continue; } @@ -1749,11 +1733,11 @@ void Graphics::drawentities() { colourTransform temp_ct; temp_ct.colour = 0xFFFFFFFF; - BlitSurfaceTinted((*tilesvec)[obj.entities[i].drawframe],NULL, backBuffer, &drawRect, temp_ct); + BlitSurfaceTinted(tilesvec[obj.entities[i].drawframe],NULL, backBuffer, &drawRect, temp_ct); } else { - BlitSurfaceStandard((*tilesvec)[obj.entities[i].drawframe],NULL, backBuffer, &drawRect); + BlitSurfaceStandard(tilesvec[obj.entities[i].drawframe],NULL, backBuffer, &drawRect); } } break; @@ -1795,7 +1779,7 @@ void Graphics::drawentities() // Note: This code is in the 4-tile code break; case 9: // Really Big Sprite! (2x2) - if (!INBOUNDS_VEC(obj.entities[i].drawframe, (*spritesvec))) + if (!INBOUNDS_VEC(obj.entities[i].drawframe, spritesvec)) { continue; } @@ -1807,7 +1791,7 @@ void Graphics::drawentities() drawRect = sprites_rect; drawRect.x += tpoint.x; drawRect.y += tpoint.y; - BlitSurfaceColoured((*spritesvec)[obj.entities[i].drawframe],NULL, backBuffer, &drawRect, ct); + BlitSurfaceColoured(spritesvec[obj.entities[i].drawframe],NULL, backBuffer, &drawRect, ct); tpoint.x = xp+32; tpoint.y = yp - yoff; @@ -1815,7 +1799,7 @@ void Graphics::drawentities() drawRect = sprites_rect; drawRect.x += tpoint.x; drawRect.y += tpoint.y; - BlitSurfaceColoured((*spritesvec)[obj.entities[i].drawframe+1],NULL, backBuffer, &drawRect, ct); + BlitSurfaceColoured(spritesvec[obj.entities[i].drawframe+1],NULL, backBuffer, &drawRect, ct); tpoint.x = xp; tpoint.y = yp+32 - yoff; @@ -1823,7 +1807,7 @@ void Graphics::drawentities() drawRect = sprites_rect; drawRect.x += tpoint.x; drawRect.y += tpoint.y; - BlitSurfaceColoured((*spritesvec)[obj.entities[i].drawframe+12],NULL, backBuffer, &drawRect, ct); + BlitSurfaceColoured(spritesvec[obj.entities[i].drawframe+12],NULL, backBuffer, &drawRect, ct); tpoint.x = xp+32; tpoint.y = yp+32 - yoff; @@ -1831,10 +1815,10 @@ void Graphics::drawentities() drawRect = sprites_rect; drawRect.x += tpoint.x; drawRect.y += tpoint.y; - BlitSurfaceColoured((*spritesvec)[obj.entities[i].drawframe + 13],NULL, backBuffer, &drawRect, ct); + BlitSurfaceColoured(spritesvec[obj.entities[i].drawframe + 13],NULL, backBuffer, &drawRect, ct); break; case 10: // 2x1 Sprite - if (!INBOUNDS_VEC(obj.entities[i].drawframe, (*spritesvec))) + if (!INBOUNDS_VEC(obj.entities[i].drawframe, spritesvec)) { continue; } @@ -1846,7 +1830,7 @@ void Graphics::drawentities() drawRect = sprites_rect; drawRect.x += tpoint.x; drawRect.y += tpoint.y; - BlitSurfaceColoured((*spritesvec)[obj.entities[i].drawframe],NULL, backBuffer, &drawRect, ct); + BlitSurfaceColoured(spritesvec[obj.entities[i].drawframe],NULL, backBuffer, &drawRect, ct); tpoint.x = xp+32; tpoint.y = yp - yoff; @@ -1854,14 +1838,14 @@ void Graphics::drawentities() drawRect = sprites_rect; drawRect.x += tpoint.x; drawRect.y += tpoint.y; - BlitSurfaceColoured((*spritesvec)[obj.entities[i].drawframe+1],NULL, backBuffer, &drawRect, ct); + BlitSurfaceColoured(spritesvec[obj.entities[i].drawframe+1],NULL, backBuffer, &drawRect, ct); break; case 11: //The fucking elephant setcolreal(obj.entities[i].realcol); drawimagecol(3, xp, yp - yoff); break; case 12: // Regular sprites that don't wrap - if (!INBOUNDS_VEC(obj.entities[i].drawframe, (*spritesvec))) + if (!INBOUNDS_VEC(obj.entities[i].drawframe, spritesvec)) { continue; } @@ -1872,7 +1856,7 @@ void Graphics::drawentities() drawRect = sprites_rect; drawRect.x += tpoint.x; drawRect.y += tpoint.y; - BlitSurfaceColoured((*spritesvec)[obj.entities[i].drawframe],NULL, backBuffer, &drawRect, ct); + BlitSurfaceColoured(spritesvec[obj.entities[i].drawframe],NULL, backBuffer, &drawRect, ct); //if we're outside the screen, we need to draw indicators @@ -1920,7 +1904,7 @@ void Graphics::drawentities() case 13: { //Special for epilogue: huge hero! - if (!INBOUNDS_VEC(obj.entities[i].drawframe, (*spritesvec))) + if (!INBOUNDS_VEC(obj.entities[i].drawframe, spritesvec)) { continue; } @@ -1928,7 +1912,7 @@ void Graphics::drawentities() tpoint.x = xp; tpoint.y = yp - yoff; setcolreal(obj.entities[i].realcol); SDL_Rect drawRect = {Sint16(obj.entities[i].xp ), Sint16(obj.entities[i].yp - yoff), Sint16(sprites_rect.x * 6), Sint16(sprites_rect.y * 6 ) }; - SDL_Surface* TempSurface = ScaleSurface( (*spritesvec)[obj.entities[i].drawframe], 6 * sprites_rect.w,6* sprites_rect.h ); + SDL_Surface* TempSurface = ScaleSurface( spritesvec[obj.entities[i].drawframe], 6 * sprites_rect.w,6* sprites_rect.h ); BlitSurfaceColoured(TempSurface, NULL , backBuffer, &drawRect, ct ); SDL_FreeSurface(TempSurface);