From 627e971e905b3f31cf5ce873f96f214be7a5cb9e Mon Sep 17 00:00:00 2001 From: Misa Date: Tue, 4 Aug 2020 00:55:18 -0700 Subject: [PATCH] Remove unnecessary intersectRect() function This function checked the intersection of rectangles, but it used floats for some reason when its only caller used ints. There's already an intersection function (UtilityClass::intersects()), so we should be using that one instead in order to minimize code duplication. Graphics::Hitest() is used for per-pixel collision detection, directly checking the pixels of both entities' sprites. I checked with one of my TASes and it still syncs, so I'm pretty sure this won't cause any issues. --- desktop_version/src/Graphics.cpp | 4 +++- desktop_version/src/GraphicsUtil.cpp | 5 ----- desktop_version/src/GraphicsUtil.h | 2 -- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index 6756e141..81b2dc0a 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -1396,7 +1396,9 @@ bool Graphics::Hitest(SDL_Surface* surface1, point p1, SDL_Surface* surface2, po int r2_bottom = p2.y; int r2_top = p2.y + surface2->h; - bool intersection = intersectRect(r1_left, r1_right, r1_bottom, r1_top, r2_left, r2_right, r2_bottom, r2_top); + SDL_Rect rect1 = {p1.x, p1.y, surface1->w, surface1->h}; + SDL_Rect rect2 = {p2.x, p2.y, surface2->w, surface2->h}; + bool intersection = help.intersects(rect1, rect2); if(intersection) { diff --git a/desktop_version/src/GraphicsUtil.cpp b/desktop_version/src/GraphicsUtil.cpp index 81ea4599..1dc67c8f 100644 --- a/desktop_version/src/GraphicsUtil.cpp +++ b/desktop_version/src/GraphicsUtil.cpp @@ -501,11 +501,6 @@ void FillRect( SDL_Surface* _surface, SDL_Rect rect, int rgba ) SDL_FillRect(_surface, &rect, rgba); } -bool intersectRect( float left1, float right1, float bottom1, float top1, float left2, float right2, float bottom2, float top2 ) -{ - return !( left2 > right1 || right2 < left1 || top2 < bottom1 || bottom2 > top1); -} - void OverlaySurfaceKeyed( SDL_Surface* _src, SDL_Surface* _dest, Uint32 _key ) { // const SDL_PixelFormat& fmt = *(_src->format); diff --git a/desktop_version/src/GraphicsUtil.h b/desktop_version/src/GraphicsUtil.h index 3d0e23a2..8492afbc 100644 --- a/desktop_version/src/GraphicsUtil.h +++ b/desktop_version/src/GraphicsUtil.h @@ -39,8 +39,6 @@ void FillRect( SDL_Surface* surface, SDL_Rect& rect, const int r, int g, int b ) void FillRect( SDL_Surface* surface, SDL_Rect rect, int rgba ); -bool intersectRect(float left1, float right1, float bottom1, float top1, float left2, float right2, float bottom2, float top2); - void OverlaySurfaceKeyed(SDL_Surface* _src, SDL_Surface* _dest, Uint32 _key); void ScrollSurface(SDL_Surface* _src, int pX, int py);