Skip to content

Commit

Permalink
PKG: optimize libretro-scummvm & libretro-scummvm-legacy and ligh…
Browse files Browse the repository at this point in the history
…ten (#150)

* PKG: optimize `lr-scummvm-legacy`
- reduce number of linked engines (only LITE+ & no WIP)
- cap framerate & increase audio_buffer (lr-option)

* PKG: optimize `lr-scummvm`
- disable Tooltip
- reduce engines count (inline with standalone)
- cap framerate->15Hz & samplerate-> 44100Hz (increase cursor speed)
  • Loading branch information
Apaczer authored Feb 10, 2025
1 parent 0bbd0bb commit e1c3756
Show file tree
Hide file tree
Showing 6 changed files with 459 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
From 2a25e6b5e20fd9638d6da37fef29165eb63a6db0 Mon Sep 17 00:00:00 2001
From: Apaczer <[email protected]>
Date: Thu, 30 Jan 2025 21:12:31 +0100
Subject: [PATCH 1/3] LIBRETRO-Makefile: optimize by reducing engines count

also -fno-PIC
---
backends/platform/libretro/build/Makefile | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/backends/platform/libretro/build/Makefile b/backends/platform/libretro/build/Makefile
index 25d141eb551..066f6472422 100644
--- a/backends/platform/libretro/build/Makefile
+++ b/backends/platform/libretro/build/Makefile
@@ -283,15 +283,17 @@ else ifeq ($(platform), miyoo)
LD = /opt/miyoo/usr/bin/arm-linux-g++
AR = /opt/miyoo/usr/bin/arm-linux-ar cru
RANLIB = /opt/miyoo/usr/bin/arm-linux-ranlib
- DEFINES += -DDINGUX -fomit-frame-pointer -ffast-math -march=armv5te -mtune=arm926ej-s -fPIC
+ DEFINES += -DDINGUX -fomit-frame-pointer -ffast-math -march=armv5te -mtune=arm926ej-s -fno-PIC
DEFINES += -ffunction-sections -fdata-sections
- LDFLAGS += -shared -Wl,--gc-sections -Wl,--version-script=../link.T -fPIC
+ LDFLAGS += -shared -Wl,--gc-sections -Wl,--version-script=../link.T -fno-PIC
USE_VORBIS = 0
USE_THEORADEC = 0
USE_TREMOR = 1
USE_LIBCO = 0
HAVE_MT32EMU = 0
NO_HIGH_DEF := 1
+ LITE := 1
+ NO_WIP := 1

else ifeq ($(platform), android-armv7)
TARGET := $(TARGET_NAME)_libretro_android.so
--
2.45.2.windows.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
From 9af918e6c23832bfe6545f3d5db8fcc6d8130948 Mon Sep 17 00:00:00 2001
From: Apaczer <[email protected]>
Date: Sun, 9 Feb 2025 15:09:54 +0100
Subject: [PATCH 2/3] LR-Makefile.common: mv useful engines to LITE type

---
backends/platform/libretro/build/Makefile.common | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/backends/platform/libretro/build/Makefile.common b/backends/platform/libretro/build/Makefile.common
index c683e2c7e59..dabbe1c38d0 100644
--- a/backends/platform/libretro/build/Makefile.common
+++ b/backends/platform/libretro/build/Makefile.common
@@ -9,6 +9,7 @@ LIBRETRO_COMM_DIR = $(LIBRETRO_DIR)/libretro-common
ENABLED=STATIC_PLUGIN

ifeq ($(NO_HIGH_DEF), 1)
+ENABLE_ACCESS = $(ENABLED)
ENABLE_AGI = $(ENABLED)
ENABLE_AGOS = $(ENABLED)
ENABLE_CINE = $(ENABLED)
@@ -20,10 +21,12 @@ ENABLE_GOB = $(ENABLED)
ENABLE_HE = $(ENABLED)
ENABLE_IHNM = $(ENABLED)
ENABLE_KYRA = $(ENABLED)
+ENABLE_LAB = $(ENABLED)
ENABLE_LOL = $(ENABLED)
ENABLE_LURE = $(ENABLED)
ENABLE_MADE = $(ENABLED)
ENABLE_PARALLACTION = $(ENABLED)
+ENABLE_PLUMBERS = $(ENABLED)
ENABLE_QUEEN = $(ENABLED)
ENABLE_SAGA = $(ENABLED)
ENABLE_SCI = $(ENABLED)
@@ -46,6 +49,7 @@ ENABLE_TSAGE = $(ENABLED)
ENABLE_VOYEUR = $(ENABLED)
ENABLE_XEEN = $(ENABLED)
else
+ENABLE_ACCESS = $(ENABLED)
ENABLE_AGI = $(ENABLED)
ENABLE_AGOS = $(ENABLED)
ENABLE_AGOS2 = $(ENABLED)
@@ -59,11 +63,13 @@ ENABLE_GROOVIE = $(ENABLED)
ENABLE_HE = $(ENABLED)
ENABLE_IHNM = $(ENABLED)
ENABLE_KYRA = $(ENABLED)
+ENABLE_LAB = $(ENABLED)
ENABLE_LOL = $(ENABLED)
ENABLE_LURE = $(ENABLED)
ENABLE_MADE = $(ENABLED)
ENABLE_MORTEVIELLE = $(ENABLED)
ENABLE_PARALLACTION = $(ENABLED)
+ENABLE_PLUMBERS = $(ENABLED)
ENABLE_QUEEN = $(ENABLED)
ENABLE_SAGA = $(ENABLED)
ENABLE_SCI = $(ENABLED)
@@ -80,7 +86,6 @@ ENABLE_TOUCHE = $(ENABLED)
ENABLE_TUCKER = $(ENABLED)

ifneq ($(LITE), 1)
-ENABLE_ACCESS = $(ENABLED)
ENABLE_ADL = $(ENABLED)
ENABLE_BBVS = $(ENABLED)
ENABLE_BLADERUNNER = $(ENABLED)
@@ -95,13 +100,11 @@ ENABLE_HDB = $(ENABLED)
ENABLE_HUGO = $(ENABLED)
ENABLE_HOPKINS = $(ENABLED)
ENABLE_ILLUSIONS = $(ENABLED)
-ENABLE_LAB = $(ENABLED)
ENABLE_MADS = $(ENABLED)
ENABLE_MOHAWK = $(ENABLED)
ENABLE_MYST = $(ENABLED)
ENABLE_NEVERHOOD = $(ENABLED)
ENABLE_PEGASUS = $(ENABLED)
-ENABLE_PLUMBERS = $(ENABLED)
ENABLE_PRINCE = $(ENABLED)
ENABLE_RIVEN = $(ENABLED)
ENABLE_SUPERNOVA = $(ENABLED)
--
2.45.2.windows.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
From 3eb8564fd92ae2939275a40ea67c3475dadd431b Mon Sep 17 00:00:00 2001
From: Apaczer <[email protected]>
Date: Mon, 10 Feb 2025 21:28:33 +0100
Subject: [PATCH 3/3] LIBRETRO: add "Framerate cap" option to reduce audio
stutter

via MM+ and: https://github.com/StupidHoroscope/libretro-scummvm-miyoo-backend/commit/6c3954f916bf430e7756afd8ca74618d48b56744
---
backends/platform/libretro/libretro.cpp | 32 +++++++++++++++++--
.../platform/libretro/libretro_core_options.h | 19 +++++++++++
2 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/backends/platform/libretro/libretro.cpp b/backends/platform/libretro/libretro.cpp
index 3a5bf84b4bc..1668182774b 100644
--- a/backends/platform/libretro/libretro.cpp
+++ b/backends/platform/libretro/libretro.cpp
@@ -55,6 +55,10 @@ static bool analog_response_is_quadratic = false;
static float mouse_speed = 1.0f;

static bool speed_hack_is_enabled = false;
+static int cap_fps=50u;
+
+static size_t audio_buffer_length = 0;
+static uint32* audio_buffer = NULL;

char cmd_params[20][200];
char cmd_params_num;
@@ -144,6 +148,11 @@ void retro_init (void)

void retro_deinit(void)
{
+ if (audio_buffer != NULL)
+ {
+ delete [] audio_buffer;
+ audio_buffer = NULL;
+ }
}

void parse_command_params(char* cmdline)
@@ -258,6 +267,13 @@ static void update_variables(void)
if (strcmp(var.value, "enabled") == 0)
speed_hack_is_enabled = true;
}
+ var.key = "scummvm_audio_cap_fps";
+ var.value = NULL;
+ cap_fps = 50u;
+ if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
+ {
+ cap_fps = (int)atof(var.value);
+ }
}

static int retro_device = RETRO_DEVICE_JOYPAD;
@@ -463,8 +479,18 @@ void retro_run (void)
video_cb(screen.pixels, screen.w, screen.h, screen.pitch);

/* Upload audio */
- static uint32 buf[735];
- int count = ((Audio::MixerImpl*)g_system->getMixer())->mixCallback((byte*)buf, 735*4);
+ // HACK: Reduce audio buffer under-run by capping framerate to lower value.
+ int samples_per_frame = 44100u / (cap_fps);
+ if (audio_buffer == NULL || samples_per_frame != audio_buffer_length)
+ {
+ if (audio_buffer != NULL)
+ {
+ delete [] audio_buffer;
+ }
+ audio_buffer_length = samples_per_frame;
+ audio_buffer = new uint32[audio_buffer_length];
+ }
+ int count = ((Audio::MixerImpl*)g_system->getMixer())->mixCallback((byte*)audio_buffer, audio_buffer_length*4);
#if defined(_3DS)
/* Hack: 3DS will produce static noise
* unless we manually send a zeroed
@@ -478,7 +504,7 @@ void retro_run (void)
}
else
#endif
- audio_batch_cb((int16_t*)buf, count);
+ audio_batch_cb((int16_t*)audio_buffer, count);
}

#if defined(USE_LIBCO)
diff --git a/backends/platform/libretro/libretro_core_options.h b/backends/platform/libretro/libretro_core_options.h
index 0fbd01e86d8..a32c0e37529 100644
--- a/backends/platform/libretro/libretro_core_options.h
+++ b/backends/platform/libretro/libretro_core_options.h
@@ -138,6 +138,25 @@ struct retro_core_option_definition option_defs_us[] = {
"disabled"
#endif
},
+ {
+ "scummvm_audio_cap_fps",
+ "Framerate cap",
+ "Lock max framerate on resource-intensive games, to reduce audio crackling",
+ {
+ { "15", NULL },
+ { "20", NULL },
+ { "25", NULL },
+ { "30", NULL },
+ { "35", NULL },
+ { "40", NULL },
+ { "45", NULL },
+ { "50", NULL },
+ { "55", NULL },
+ { "60", NULL },
+ { NULL, NULL },
+ },
+ "50"
+ },
{ NULL, NULL, NULL, {{0}}, NULL },
};

--
2.45.2.windows.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
From a6eecfa329b7fa39707a208e7071cb7b37ccb53f Mon Sep 17 00:00:00 2001
From: Apaczer <[email protected]>
Date: Fri, 31 Jan 2025 21:09:07 +0100
Subject: [PATCH 2/4] gui/Tooltip: disable tooltip entirely

it is unreliable & slow
---
gui/Tooltip.cpp | 55 -------------------------------------------------
1 file changed, 55 deletions(-)

diff --git a/gui/Tooltip.cpp b/gui/Tooltip.cpp
index 23e5b5f7437..ef12c467dff 100644
--- a/gui/Tooltip.cpp
+++ b/gui/Tooltip.cpp
@@ -37,64 +37,9 @@ Tooltip::Tooltip() :
}

void Tooltip::setup(Dialog *parent, Widget *widget, int x, int y) {
- assert(widget->hasTooltip());
-
- _parent = parent;
-
- setMouseUpdatedOnFocus(false);
-
- _maxWidth = g_gui.xmlEval()->getVar("Globals.Tooltip.MaxWidth", 100);
- _xdelta = g_gui.xmlEval()->getVar("Globals.Tooltip.XDelta", 0);
- _ydelta = g_gui.xmlEval()->getVar("Globals.Tooltip.YDelta", 0);
- _xpadding = g_gui.xmlEval()->getVar("Globals.Tooltip.XPadding", 2);
- _ypadding = g_gui.xmlEval()->getVar("Globals.Tooltip.YPadding", 2);
-
- const Graphics::Font *tooltipFont = g_gui.theme()->getFont(ThemeEngine::kFontStyleTooltip);
-
- _wrappedLines.clear();
- _w = tooltipFont->wordWrapText(widget->getTooltip(), _maxWidth - _xpadding * 2, _wrappedLines) + _xpadding * 2;
- _h = (tooltipFont->getFontHeight() + 2) * _wrappedLines.size() + _ypadding * 2;
-
- _x = MIN<int16>(parent->_x + x + _xdelta + _xpadding, g_system->getOverlayWidth() - _w - _xpadding * 2);
- _y = MIN<int16>(parent->_y + y + _ydelta + _ypadding, g_system->getOverlayHeight() - _h - _ypadding * 2);
-
- if (g_gui.useRTL())
- _x = g_system->getOverlayWidth() - _w - _x + g_gui.getOverlayOffset();
-
- if (ConfMan.hasKey("tts_enabled", "scummvm") &&
- ConfMan.getBool("tts_enabled", "scummvm")) {
- Common::TextToSpeechManager *ttsMan = g_system->getTextToSpeechManager();
- if (ttsMan == nullptr)
- return;
- ttsMan->say(widget->getTooltip(), Common::TextToSpeechManager::QUEUE_NO_REPEAT);
- }
}

void Tooltip::drawDialog(DrawLayer layerToDraw) {
- int num = 0;
- int h = g_gui.theme()->getFontHeight(ThemeEngine::kFontStyleTooltip) + 2;
-
- Dialog::drawDialog(layerToDraw);
-
- int16 textX = g_gui.useRTL() ? _x - 1 - _xpadding : _x + 1 + _xpadding;
- int16 textY = _y + 1 + _ypadding;
-
- Graphics::TextAlign textAlignment = g_gui.useRTL() ? Graphics::kTextAlignRight : Graphics::kTextAlignLeft;
-
- for (Common::U32StringArray::const_iterator i = _wrappedLines.begin(); i != _wrappedLines.end(); ++i, ++num) {
- g_gui.theme()->drawText(
- Common::Rect(textX, textY + num * h, textX + _w, textY + (num + 1) * h),
- *i,
- ThemeEngine::kStateEnabled,
- textAlignment,
- ThemeEngine::kTextInversionNone,
- 0,
- false,
- ThemeEngine::kFontStyleTooltip,
- ThemeEngine::kFontColorNormal,
- false
- );
- }
}

}
--
2.45.2.windows.1

Loading

0 comments on commit e1c3756

Please sign in to comment.