From da612de1f4f5bf3e0c9696e613b8eef9205da2ba Mon Sep 17 00:00:00 2001 From: Misa Date: Sat, 25 Apr 2020 14:49:05 -0700 Subject: [PATCH] De-duplicate size-type 2/8 drawing by putting them together They're literally the exact same thing, except one is 4 and the other has an 8. No need to have all that copy-pasted code. Actually, the only other difference was that size-type 8 set the drawRect to sprites_rect instead of tiles_rect for some reason? Even though it doesn't matter, anyway, because SDL_BlitSurface() only cares about the X and Y you pass it, not the width and height, which is the only difference between tiles_rect and sprites_rect. To make sure that people wouldn't wonder where size-type 8 went if they saw a blank space between size-type 7 and size-type 9, I kept the size-type 8 conditional, but inside it is just a comment telling you to go to size-type 2. --- desktop_version/src/Graphics.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index 9ba7966d..696063f7 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -1527,15 +1527,20 @@ void Graphics::drawentities() drawRect.y += tpoint.y; BlitSurfaceStandard(tiles[obj.entities[i].drawframe],NULL, backBuffer, &drawRect); } - else if (obj.entities[i].size == 2) + else if (obj.entities[i].size == 2 || obj.entities[i].size == 8) { - // Special: Moving platform, 4 tiles + // Special: Moving platform, 4 tiles or 8 tiles tpoint.x = obj.entities[i].xp; tpoint.y = obj.entities[i].yp; drawRect = tiles_rect; drawRect.x += tpoint.x; drawRect.y += tpoint.y; - for (int ii = 0; ii < 4; ii++) + int thiswidth = 4; + if (obj.entities[i].size == 8) + { + thiswidth = 8; + } + for (int ii = 0; ii < thiswidth; ii++) { BlitSurfaceStandard((*tilesvec)[obj.entities[i].drawframe],NULL, backBuffer, &drawRect); drawRect.x += 8; @@ -1581,17 +1586,7 @@ void Graphics::drawentities() } else if (obj.entities[i].size == 8) // Special: Moving platform, 8 tiles { - tpoint.x = obj.entities[i].xp; - tpoint.y = obj.entities[i].yp; - drawRect = sprites_rect; - drawRect.x += tpoint.x; - drawRect.y += tpoint.y; - - for (int ii = 0; ii < 8; ii++) - { - BlitSurfaceStandard((*tilesvec)[obj.entities[i].drawframe],NULL, backBuffer, &drawRect); - drawRect.x += 8; - } + // Note: This code is in the 4-tile code } else if (obj.entities[i].size == 9) // Really Big Sprite! (2x2) {