diff --git a/SpaceCadetPinball/options.cpp b/SpaceCadetPinball/options.cpp index d78850a..5dd9d5d 100644 --- a/SpaceCadetPinball/options.cpp +++ b/SpaceCadetPinball/options.cpp @@ -3,7 +3,6 @@ #include "fullscrn.h" #include "midi.h" -#include "render.h" #include "Sound.h" #include "winmain.h" @@ -247,7 +246,7 @@ void options::toggle(Menu1 uIDCheckItem) break; case Menu1::WindowLinearFilter: Options.LinearFiltering ^= true; - render::recreate_screen_texture(); + winmain::Restart(); break; default: break; diff --git a/SpaceCadetPinball/pch.h b/SpaceCadetPinball/pch.h index 40e2849..9a49af3 100644 --- a/SpaceCadetPinball/pch.h +++ b/SpaceCadetPinball/pch.h @@ -77,10 +77,4 @@ inline float RandFloat() return static_cast(std::rand() / static_cast(RAND_MAX)); } -template constexpr -int Sign(T val) -{ - return (T(0) < val) - (val < T(0)); -} - #endif //PCH_H diff --git a/SpaceCadetPinball/render.cpp b/SpaceCadetPinball/render.cpp index cd9bae6..ed4d05a 100644 --- a/SpaceCadetPinball/render.cpp +++ b/SpaceCadetPinball/render.cpp @@ -42,7 +42,17 @@ void render::init(gdrv_bitmap8* bmp, float zMin, float zScaler, int width, int h else gdrv::fill_bitmap(vscreen, vscreen->Width, vscreen->Height, 0, 0, 0); - recreate_screen_texture(); + { + UsingSdlHint hint{SDL_HINT_RENDER_SCALE_QUALITY, options::Options.LinearFiltering ? "linear" : "nearest"}; + vScreenTex = SDL_CreateTexture + ( + winmain::Renderer, + SDL_PIXELFORMAT_ARGB8888, + SDL_TEXTUREACCESS_STREAMING, + width, height + ); + SDL_SetTextureBlendMode(vScreenTex, SDL_BLENDMODE_NONE); + } } void render::uninit() @@ -59,25 +69,6 @@ void render::uninit() dirty_list.clear(); sprite_list.clear(); SDL_DestroyTexture(vScreenTex); - vScreenTex = nullptr; -} - -void render::recreate_screen_texture() -{ - if (vScreenTex != nullptr) - { - SDL_DestroyTexture(vScreenTex); - } - - UsingSdlHint hint{ SDL_HINT_RENDER_SCALE_QUALITY, options::Options.LinearFiltering ? "linear" : "nearest" }; - vScreenTex = SDL_CreateTexture - ( - winmain::Renderer, - SDL_PIXELFORMAT_ARGB8888, - SDL_TEXTUREACCESS_STREAMING, - vscreen_rect.Width, vscreen_rect.Height - ); - SDL_SetTextureBlendMode(vScreenTex, SDL_BLENDMODE_NONE); } void render::update() @@ -563,53 +554,29 @@ void render::PresentVScreen() } else { - auto tableWidthCoef = static_cast(pb::MainTable->Width) / vscreen->Width; - auto srcSeparationX = static_cast(round(vscreen->Width * tableWidthCoef)); - auto srcBoardRect = SDL_Rect + int32_t srcSeparationX = static_cast(vscreen->Width * 0.625f); + + SDL_Rect srcBoardRect = SDL_Rect { 0, 0, srcSeparationX, vscreen->Height }; - auto srcSidebarRect = SDL_Rect + + SDL_Rect srcSidebarRect = SDL_Rect { srcSeparationX, 0, vscreen->Width - srcSeparationX, vscreen->Height }; -#if SDL_VERSION_ATLEAST(2, 0, 10) - // SDL_RenderCopyF was added in 2.0.10 - auto dstSeparationX = DestinationRect.w * tableWidthCoef; - auto dstBoardRect = SDL_FRect - { - DestinationRect.x + offset_x * fullscrn::ScaleX, - DestinationRect.y + offset_y * fullscrn::ScaleY, - dstSeparationX, static_cast(DestinationRect.h) - }; - auto dstSidebarRect = SDL_FRect - { - DestinationRect.x + dstSeparationX, static_cast(DestinationRect.y), - DestinationRect.w - dstSeparationX, static_cast(DestinationRect.h) - }; + int32_t dstSeparationX = static_cast(DestinationRect.w * 0.625f); - SDL_RenderCopyF(winmain::Renderer, vScreenTex, &srcBoardRect, &dstBoardRect); - SDL_RenderCopyF(winmain::Renderer, vScreenTex, &srcSidebarRect, &dstSidebarRect); -#else - // SDL_RenderCopy cannot express sub pixel offset. - // Vscreen shift is required for that. - auto dstSeparationX = static_cast(DestinationRect.w * tableWidthCoef); - auto scaledOffX = static_cast(round(offset_x * fullscrn::ScaleX)); - if (offset_x != 0 && scaledOffX == 0) - scaledOffX = Sign(offset_x); - auto scaledOffY = static_cast(round(offset_y * fullscrn::ScaleY)); - if (offset_y != 0 && scaledOffX == 0) - scaledOffY = Sign(offset_y); - - auto dstBoardRect = SDL_Rect + SDL_Rect dstBoardRect = SDL_Rect { - DestinationRect.x + scaledOffX, DestinationRect.y + scaledOffY, + DestinationRect.x + static_cast(offset_x * fullscrn::ScaleX), DestinationRect.y + static_cast(offset_y * fullscrn::ScaleY), dstSeparationX, DestinationRect.h }; - auto dstSidebarRect = SDL_Rect + + SDL_Rect dstSidebarRect = SDL_Rect { DestinationRect.x + dstSeparationX, DestinationRect.y, DestinationRect.w - dstSeparationX, DestinationRect.h @@ -617,6 +584,5 @@ void render::PresentVScreen() SDL_RenderCopy(winmain::Renderer, vScreenTex, &srcBoardRect, &dstBoardRect); SDL_RenderCopy(winmain::Renderer, vScreenTex, &srcSidebarRect, &dstSidebarRect); -#endif } } diff --git a/SpaceCadetPinball/render.h b/SpaceCadetPinball/render.h index 5e66ade..ba794f4 100644 --- a/SpaceCadetPinball/render.h +++ b/SpaceCadetPinball/render.h @@ -35,7 +35,6 @@ public: static void init(gdrv_bitmap8* bmp, float zMin, float zScaler, int width, int height); static void uninit(); - static void recreate_screen_texture(); static void update(); static void sprite_modified(render_sprite_type_struct* sprite); static render_sprite_type_struct* create_sprite(VisualTypes visualType, gdrv_bitmap8* bmp,