mirror of
https://github.com/k4zmu2a/SpaceCadetPinball.git
synced 2024-11-22 08:50:18 +01:00
Compare commits
2 commits
5789492021
...
3ec96b84ad
Author | SHA1 | Date | |
---|---|---|---|
|
3ec96b84ad | ||
|
34cb964ea5 |
4 changed files with 65 additions and 23 deletions
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "fullscrn.h"
|
#include "fullscrn.h"
|
||||||
#include "midi.h"
|
#include "midi.h"
|
||||||
|
#include "render.h"
|
||||||
#include "Sound.h"
|
#include "Sound.h"
|
||||||
#include "winmain.h"
|
#include "winmain.h"
|
||||||
|
|
||||||
|
@ -246,7 +247,7 @@ void options::toggle(Menu1 uIDCheckItem)
|
||||||
break;
|
break;
|
||||||
case Menu1::WindowLinearFilter:
|
case Menu1::WindowLinearFilter:
|
||||||
Options.LinearFiltering ^= true;
|
Options.LinearFiltering ^= true;
|
||||||
winmain::Restart();
|
render::recreate_screen_texture();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -77,4 +77,10 @@ inline float RandFloat()
|
||||||
return static_cast<float>(std::rand() / static_cast<double>(RAND_MAX));
|
return static_cast<float>(std::rand() / static_cast<double>(RAND_MAX));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T> constexpr
|
||||||
|
int Sign(T val)
|
||||||
|
{
|
||||||
|
return (T(0) < val) - (val < T(0));
|
||||||
|
}
|
||||||
|
|
||||||
#endif //PCH_H
|
#endif //PCH_H
|
||||||
|
|
|
@ -42,17 +42,7 @@ void render::init(gdrv_bitmap8* bmp, float zMin, float zScaler, int width, int h
|
||||||
else
|
else
|
||||||
gdrv::fill_bitmap(vscreen, vscreen->Width, vscreen->Height, 0, 0, 0);
|
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()
|
void render::uninit()
|
||||||
|
@ -69,6 +59,25 @@ void render::uninit()
|
||||||
dirty_list.clear();
|
dirty_list.clear();
|
||||||
sprite_list.clear();
|
sprite_list.clear();
|
||||||
SDL_DestroyTexture(vScreenTex);
|
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()
|
void render::update()
|
||||||
|
@ -554,29 +563,53 @@ void render::PresentVScreen()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int32_t srcSeparationX = static_cast<int32_t>(vscreen->Width * 0.625f);
|
auto tableWidthCoef = static_cast<float>(pb::MainTable->Width) / vscreen->Width;
|
||||||
|
auto srcSeparationX = static_cast<int>(round(vscreen->Width * tableWidthCoef));
|
||||||
SDL_Rect srcBoardRect = SDL_Rect
|
auto srcBoardRect = SDL_Rect
|
||||||
{
|
{
|
||||||
0, 0,
|
0, 0,
|
||||||
srcSeparationX, vscreen->Height
|
srcSeparationX, vscreen->Height
|
||||||
};
|
};
|
||||||
|
auto srcSidebarRect = SDL_Rect
|
||||||
SDL_Rect srcSidebarRect = SDL_Rect
|
|
||||||
{
|
{
|
||||||
srcSeparationX, 0,
|
srcSeparationX, 0,
|
||||||
vscreen->Width - srcSeparationX, vscreen->Height
|
vscreen->Width - srcSeparationX, vscreen->Height
|
||||||
};
|
};
|
||||||
|
|
||||||
int32_t dstSeparationX = static_cast<int32_t>(DestinationRect.w * 0.625f);
|
#if SDL_VERSION_ATLEAST(2, 0, 10)
|
||||||
|
// SDL_RenderCopyF was added in 2.0.10
|
||||||
SDL_Rect dstBoardRect = SDL_Rect
|
auto dstSeparationX = DestinationRect.w * tableWidthCoef;
|
||||||
|
auto dstBoardRect = SDL_FRect
|
||||||
{
|
{
|
||||||
DestinationRect.x + static_cast<int32_t>(offset_x * fullscrn::ScaleX), DestinationRect.y + static_cast<int32_t>(offset_y * fullscrn::ScaleY),
|
DestinationRect.x + offset_x * fullscrn::ScaleX,
|
||||||
dstSeparationX, DestinationRect.h
|
DestinationRect.y + offset_y * fullscrn::ScaleY,
|
||||||
|
dstSeparationX, static_cast<float>(DestinationRect.h)
|
||||||
|
};
|
||||||
|
auto dstSidebarRect = SDL_FRect
|
||||||
|
{
|
||||||
|
DestinationRect.x + dstSeparationX, static_cast<float>(DestinationRect.y),
|
||||||
|
DestinationRect.w - dstSeparationX, static_cast<float>(DestinationRect.h)
|
||||||
};
|
};
|
||||||
|
|
||||||
SDL_Rect dstSidebarRect = SDL_Rect
|
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<int>(DestinationRect.w * tableWidthCoef);
|
||||||
|
auto scaledOffX = static_cast<int>(round(offset_x * fullscrn::ScaleX));
|
||||||
|
if (offset_x != 0 && scaledOffX == 0)
|
||||||
|
scaledOffX = Sign(offset_x);
|
||||||
|
auto scaledOffY = static_cast<int>(round(offset_y * fullscrn::ScaleY));
|
||||||
|
if (offset_y != 0 && scaledOffX == 0)
|
||||||
|
scaledOffY = Sign(offset_y);
|
||||||
|
|
||||||
|
auto dstBoardRect = SDL_Rect
|
||||||
|
{
|
||||||
|
DestinationRect.x + scaledOffX, DestinationRect.y + scaledOffY,
|
||||||
|
dstSeparationX, DestinationRect.h
|
||||||
|
};
|
||||||
|
auto dstSidebarRect = SDL_Rect
|
||||||
{
|
{
|
||||||
DestinationRect.x + dstSeparationX, DestinationRect.y,
|
DestinationRect.x + dstSeparationX, DestinationRect.y,
|
||||||
DestinationRect.w - dstSeparationX, DestinationRect.h
|
DestinationRect.w - dstSeparationX, DestinationRect.h
|
||||||
|
@ -584,5 +617,6 @@ void render::PresentVScreen()
|
||||||
|
|
||||||
SDL_RenderCopy(winmain::Renderer, vScreenTex, &srcBoardRect, &dstBoardRect);
|
SDL_RenderCopy(winmain::Renderer, vScreenTex, &srcBoardRect, &dstBoardRect);
|
||||||
SDL_RenderCopy(winmain::Renderer, vScreenTex, &srcSidebarRect, &dstSidebarRect);
|
SDL_RenderCopy(winmain::Renderer, vScreenTex, &srcSidebarRect, &dstSidebarRect);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ public:
|
||||||
|
|
||||||
static void init(gdrv_bitmap8* bmp, float zMin, float zScaler, int width, int height);
|
static void init(gdrv_bitmap8* bmp, float zMin, float zScaler, int width, int height);
|
||||||
static void uninit();
|
static void uninit();
|
||||||
|
static void recreate_screen_texture();
|
||||||
static void update();
|
static void update();
|
||||||
static void sprite_modified(render_sprite_type_struct* sprite);
|
static void sprite_modified(render_sprite_type_struct* sprite);
|
||||||
static render_sprite_type_struct* create_sprite(VisualTypes visualType, gdrv_bitmap8* bmp,
|
static render_sprite_type_struct* create_sprite(VisualTypes visualType, gdrv_bitmap8* bmp,
|
||||||
|
|
Loading…
Reference in a new issue