From 3eb73c4ad167f391e9765a81a9f59002cc40c8d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Nov=C3=A1k?= Date: Sun, 23 Mar 2025 13:52:09 +0100 Subject: [PATCH] fix bugs, better crt, mouse cursor size in config --- CMakeLists.txt | 1 + game/gamesave.c | 4 ++-- game/skeldal.c | 6 +++--- platform/sdl/BGraph2.cpp | 1 + platform/sdl/sdl_context.cpp | 36 +++++++++++++++++++++++++++--------- platform/sdl/sdl_context.h | 7 +++++-- skeldal.ini | 6 ++++-- 7 files changed, 43 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f8dc14..76a71ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,4 +23,5 @@ enable_testing() add_subdirectory(libs) add_subdirectory(platform) add_subdirectory(game) +add_subdirectory(tools) diff --git a/game/gamesave.c b/game/gamesave.c index ef0edfa..1999a12 100644 --- a/game/gamesave.c +++ b/game/gamesave.c @@ -219,7 +219,8 @@ void restore_items(TMPFILE_RD *f) temp_storage_read(new_item_map[i],2*j,f); short *v = new_item_map[i]; while (*v) { //sanitize map items - if (*v < 1 || *v >= item_count) { + int vv = abs(*v); + if (vv > item_count) { free(new_item_map[i]); new_item_map[i] = map_items[i]; map_items[i] = NULL; @@ -230,7 +231,6 @@ void restore_items(TMPFILE_RD *f) } for(i=0;i720p)"); - str_replace(&texty,0,"Byl nalezen p\xA9ipojen\x98 ovlada\x87\nPro aktivaci ovlada\x87""e stiskn\x88te kt\x82rekoliv tla\x87\xA1tko na ovlada\x87i"); + str_replace(&texty,0,"Byl nalezen p\xA9ipojen\x98 ovlada\x87\nPro aktivaci ovlada\x87""e stiskn\x88te kter\x82koliv tla\x87\xA1tko na ovlada\x87i"); lang_patch_stringtable(&texty, "ui.csv", ""); } @@ -968,7 +968,7 @@ void show_joystick_info(void) { break; } } - + } void show_loading_picture(char *filename) @@ -996,7 +996,7 @@ void init_skeldal(const INI_CONFIG *cfg) char verr = game_display_init(ini_section_open(cfg, "video"), "Skeldal"); if (!verr) { - display_error("Error game_display_init %d", verr); + display_error("Error game_display_init %d", verr); exit(1); } showview = game_display_update_rect; diff --git a/platform/sdl/BGraph2.cpp b/platform/sdl/BGraph2.cpp index 4941d2e..28509ac 100644 --- a/platform/sdl/BGraph2.cpp +++ b/platform/sdl/BGraph2.cpp @@ -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); diff --git a/platform/sdl/sdl_context.cpp b/platform/sdl/sdl_context.cpp index 185cdae..355509a 100644 --- a/platform/sdl/sdl_context.cpp +++ b/platform/sdl/sdl_context.cpp @@ -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((height+320)/640,interfer); + width = width * interfer / mult_of_base; + } + { + unsigned int mult_of_base = std::max((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 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(recalc_rect.w * _mouse_size); + recalc_rect.h = static_cast(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(f.x * _mouse_size); + recalc_rect.y = _mouse_rect.y - static_cast(f.y * _mouse_size); SDL_RenderCopy(_renderer.get(), _mouse.get(), NULL, &recalc_rect); } if (winrc.h >= 720 && _crt_filter != CrtFilterType::none && _enable_crt) { diff --git a/platform/sdl/sdl_context.h b/platform/sdl/sdl_context.h index dfc3ad7..09db4dc 100644 --- a/platform/sdl/sdl_context.h +++ b/platform/sdl/sdl_context.h @@ -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 _key_control = false; std::atomic _key_shift = false; std::atomic _key_capslock = false; @@ -254,6 +254,7 @@ protected: std::queue _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); diff --git a/skeldal.ini b/skeldal.ini index a067477..5e7be5f 100644 --- a/skeldal.ini +++ b/skeldal.ini @@ -24,8 +24,8 @@ # crt_filter = enable filter simmulates lowres CRT monitor for higher resolution (>720p) # none = disabled # auto = auto select depend on resolution (default) -# scanline = 1 pixel wide scanline (best for HD resolution, 960p-1080p) -# scanline_2 = 2 pixels wide scanline (best for QHD resolution, 1440p) +# scanlines = 1 pixel wide scanlines (best for HD resolution, 960p-1080p) +# scanlines_2 = 2 pixels wide scanlines (best for QHD resolution, 1440p) # rgbmatrix_2 = emulates CRT shadow mask (best for QHD resolution, 1440p) # rgbmatrix_3 = emulates CRT shadow mask (best for 4K resolution, 1920p+) # (hardware composer and linear filtering is recommended) @@ -38,6 +38,7 @@ # linear - use linear filtering (Direct3D and OpenGL) # nearest - use nearest filtering # aspect_ratio = x:y, none = don't keep fixed ratio' +# cursor_size = mouse cursor size in percent # [video] #fullscreen=on @@ -47,6 +48,7 @@ #scale_quality=auto #composer=auto #aspect_ratio=4:3 +#cursor_size=100 ### audio settings