From 5f776faba783bc1b5616ca764f827fe49915bd55 Mon Sep 17 00:00:00 2001 From: Misa Date: Tue, 4 Aug 2020 13:09:13 -0700 Subject: [PATCH] Ax ScaleSurfaceSlow() in favor of ScaleSurface() ScaleSurfaceSlow() uses DrawPixel() instead of SDL_FillRect() to scale a given surface, which is slow and inefficient, and makes it less likely that the game could be moved to SDL_Render. Unfortunately, it has this weird -1,-1 offset, but that will be fixed in the next commit. --- desktop_version/src/Graphics.cpp | 4 ++-- desktop_version/src/GraphicsUtil.cpp | 32 ---------------------------- desktop_version/src/GraphicsUtil.h | 1 - 3 files changed, 2 insertions(+), 35 deletions(-) diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index c2cfc831..1c520f54 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -424,7 +424,7 @@ void Graphics::bigprint( int _x, int _y, std::string _s, int r, int g, int b, b idx = font_idx(curr); if (INBOUNDS(idx, font)) { - SDL_Surface* tempPrint = ScaleSurfaceSlow(font[idx], font[idx]->w *sc,font[idx]->h *sc); + SDL_Surface* tempPrint = ScaleSurface(font[idx], font[idx]->w *sc,font[idx]->h *sc); SDL_Rect printrect = { static_cast((_x) + bfontpos), static_cast(_y) , static_cast((bfont_rect.w*sc)+1), static_cast((bfont_rect.h * sc)+1)}; BlitSurfaceColoured(tempPrint, NULL, backBuffer, &printrect, ct); SDL_FreeSurface(tempPrint); @@ -3023,7 +3023,7 @@ void Graphics::bigrprint(int x, int y, std::string& t, int r, int g, int b, bool idx = font_idx(cur); if (INBOUNDS(idx, font)) { - SDL_Surface* tempPrint = ScaleSurfaceSlow(font[idx], font[idx]->w *sc,font[idx]->h *sc); + SDL_Surface* tempPrint = ScaleSurface(font[idx], font[idx]->w *sc,font[idx]->h *sc); SDL_Rect printrect = { Sint16((x) + bfontpos), Sint16(y) , Sint16(bfont_rect.w*sc), Sint16(bfont_rect.h * sc)}; BlitSurfaceColoured(tempPrint, NULL, backBuffer, &printrect, ct); SDL_FreeSurface(tempPrint); diff --git a/desktop_version/src/GraphicsUtil.cpp b/desktop_version/src/GraphicsUtil.cpp index fae16b1e..37fdd286 100644 --- a/desktop_version/src/GraphicsUtil.cpp +++ b/desktop_version/src/GraphicsUtil.cpp @@ -171,38 +171,6 @@ SDL_Surface * ScaleSurface( SDL_Surface *_surface, int Width, int Height, SDL_Su return _ret; } -SDL_Surface * ScaleSurfaceSlow( SDL_Surface *_surface, int Width, int Height) -{ - if(!_surface || !Width || !Height) - return 0; - - SDL_Surface *_ret; - - _ret = SDL_CreateRGBSurface(_surface->flags, Width, Height, _surface->format->BitsPerPixel, - _surface->format->Rmask, _surface->format->Gmask, _surface->format->Bmask, _surface->format->Amask); - if(_ret == NULL) - { - return NULL; - } - - - - float _stretch_factor_x = (static_cast(Width) / static_cast(_surface->w)), _stretch_factor_y = (static_cast(Height) / static_cast(_surface->h)); - - - for(Sint32 y = 0; y < _surface->h; y++) - for(Sint32 x = 0; x < _surface->w; x++) - for(Sint32 o_y = 0; o_y < _stretch_factor_y; ++o_y) - for(Sint32 o_x = 0; o_x < _stretch_factor_x; ++o_x) - DrawPixel(_ret, static_cast(_stretch_factor_x * x) + o_x, - static_cast(_stretch_factor_y * y) + o_y, ReadPixel(_surface, x, y)); - - // DrawPixel(_ret, static_cast(_stretch_factor_x * x) + o_x, - //static_cast(_stretch_factor_y * y) + o_y, ReadPixel(_surface, x, y)); - - return _ret; -} - SDL_Surface * FlipSurfaceHorizontal(SDL_Surface* _src) { SDL_Surface * ret = SDL_CreateRGBSurface(_src->flags, _src->w, _src->h, _src->format->BitsPerPixel, diff --git a/desktop_version/src/GraphicsUtil.h b/desktop_version/src/GraphicsUtil.h index e7d45603..9424115d 100644 --- a/desktop_version/src/GraphicsUtil.h +++ b/desktop_version/src/GraphicsUtil.h @@ -43,7 +43,6 @@ void ScrollSurface(SDL_Surface* _src, int pX, int py); SDL_Surface * FlipSurfaceHorizontal(SDL_Surface* _src); SDL_Surface * FlipSurfaceVerticle(SDL_Surface* _src); -SDL_Surface * ScaleSurfaceSlow( SDL_Surface *_surface, int Width, int Height ); void UpdateFilter(); SDL_Surface* ApplyFilter( SDL_Surface* _src );