fix bugs, better crt, mouse cursor size in config

This commit is contained in:
Ondřej Novák 2025-03-23 13:52:09 +01:00
parent 15c88740bf
commit 3eb73c4ad1
7 changed files with 43 additions and 18 deletions

View file

@ -40,6 +40,7 @@ char game_display_init(const INI_CONFIG_SECTION *display_section, const char *ti
else if (istrcmp(filter,"rgbmatrix_3") == 0) cfg.crt_filter = SDLContext::CrtFilterType::rgb_matrix_3;
else cfg.crt_filter = SDLContext::CrtFilterType::autoselect;
cfg.cursor_size = ini_get_int(display_section, "cursor_size", 100)*0.01f;
screen_pitch = 640;
get_sdl_global_context().init_video(cfg, title);

View file

@ -74,13 +74,28 @@ void handle_sdl_error(const char *msg) {
void SDLContext::generateCRTTexture(SDL_Renderer* renderer, SDL_Texture** texture, int width, int height, CrtFilterType type) {
if (type == CrtFilterType::autoselect) {
if (height > 1680) type = CrtFilterType::rgb_matrix_3;
else if (height >= 1200) type = CrtFilterType::scanlines_2;
if (height >= 1200) type = CrtFilterType::scanlines_2;
else type = CrtFilterType::scanlines;
}
int interfer = 1;
switch (type) {
case CrtFilterType::scanlines: interfer = 2;break;
case CrtFilterType::scanlines_2: interfer = 3;break;
case CrtFilterType::rgb_matrix_2: interfer = 3;break;
case CrtFilterType::rgb_matrix_3: interfer = 4;break;
default: break;
}
if (type == CrtFilterType::scanlines || type == CrtFilterType::scanlines_2) {
width = 32;
} else {
unsigned int mult_of_base = std::max<unsigned int>((height+320)/640,interfer);
width = width * interfer / mult_of_base;
}
{
unsigned int mult_of_base = std::max<unsigned int>((height+240)/480,interfer);
height = height * interfer / mult_of_base;
}
// Vytvoř novou texturu ve správné velikosti
*texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING, width, height);
@ -169,9 +184,9 @@ static void crash_sdl_exception() {
try {
throw;
} catch (std::exception &e) {
display_error("Display server - unhandled exception: %s", e.what());
display_error("Display server - unhandled exception: %s", e.what());
} catch (...) {
display_error("Display server - unhandled unknown exception (probably crash)");
display_error("Display server - unhandled unknown exception (probably crash)");
}
abort();
}
@ -198,6 +213,7 @@ void SDLContext::init_video(const VideoConfig &config, const char *title) {
_fullscreen_mode = config.fullscreen;
_mouse_size = config.cursor_size;
std::atomic<bool> done = false;
std::exception_ptr e;
@ -251,13 +267,13 @@ void SDLContext::init_video(const VideoConfig &config, const char *title) {
}
done = true;
done.notify_all();
if (!err) {
try {
SDL_ShowCursor(SDL_DISABLE);
SDL_ShowCursor(SDL_DISABLE);
event_loop(stp);
} catch (...) {
SDL_ShowCursor(SDL_ENABLE);
SDL_ShowCursor(SDL_ENABLE);
crash_sdl_exception();
}
}
@ -641,9 +657,11 @@ void SDLContext::refresh_screen() {
}
if (_mouse) {
SDL_Rect recalc_rect = to_window_rect(winrc, _mouse_rect);
recalc_rect.w = static_cast<int>(recalc_rect.w * _mouse_size);
recalc_rect.h = static_cast<int>(recalc_rect.h * _mouse_size);
SDL_Point f= to_window_point({0,0,winrc.w, winrc.h}, _mouse_finger);
recalc_rect.x = _mouse_rect.x - f.x;
recalc_rect.y = _mouse_rect.y - f.y;
recalc_rect.x = _mouse_rect.x - static_cast<int>(f.x * _mouse_size);
recalc_rect.y = _mouse_rect.y - static_cast<int>(f.y * _mouse_size);
SDL_RenderCopy(_renderer.get(), _mouse.get(), NULL, &recalc_rect);
}
if (winrc.h >= 720 && _crt_filter != CrtFilterType::none && _enable_crt) {

View file

@ -36,6 +36,7 @@ public:
bool fullscreen;
int aspect_x;
int aspect_y;
float cursor_size;
};
struct AudioConfig {
@ -238,10 +239,9 @@ protected:
SDL_Texture *_visible_texture;
SDL_Texture *_hidden_texture;
std::jthread _render_thread;
bool _fullscreen_mode = false;
bool _present = false;
bool _present = false;
std::atomic<bool> _key_control = false;
std::atomic<bool> _key_shift = false;
std::atomic<bool> _key_capslock = false;
@ -254,6 +254,7 @@ protected:
std::queue<uint16_t> _keyboard_queue;
SDL_Rect _mouse_rect;
SDL_Point _mouse_finger;
float _mouse_size;
SpriteList _sprites;
@ -264,6 +265,8 @@ protected:
Uint32 _update_request_event;
Uint32 _refresh_request;
std::jthread _render_thread;
void event_loop(std::stop_token stp);
void update_screen(bool force_refresh = false);