Skip to content

Commit af95503

Browse files
committed
Reduce Dreamcast load-time stalls in menu transitions.
Limit save-slot probing on hero selection, skip unnecessary hero-item reads for list rendering, and throttle repeated progress-event error logs that slow loading. Signed-off-by: Panagiotis Georgiadis <pgeorgia@redhat.com>
1 parent 80a4915 commit af95503

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

Source/interfac.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,15 @@ void IncProgress(uint32_t steps)
620620
SDL_Event event;
621621
CustomEventToSdlEvent(event, WM_PROGRESS);
622622
if (!SDLC_PushEvent(&event)) {
623+
#ifdef __DREAMCAST__
624+
static bool loggedDreamcastProgressPushFailure = false;
625+
if (!loggedDreamcastProgressPushFailure) {
626+
LogError("Failed to send WM_PROGRESS {}", SDL_GetError());
627+
loggedDreamcastProgressPushFailure = true;
628+
}
629+
#else
623630
LogError("Failed to send WM_PROGRESS {}", SDL_GetError());
631+
#endif
624632
SDL_ClearError();
625633
}
626634
#ifdef LOAD_ON_MAIN_THREAD

Source/pfile.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
#include "pfile.h"
77

8+
#include <algorithm>
89
#include <cstdint>
910
#include <string>
1011
#include <string_view>
@@ -65,6 +66,19 @@ namespace {
6566
/** List of character names for the character selection screen. */
6667
char hero_names[MAX_CHARACTERS][PlayerNameLength];
6768

69+
#ifdef __DREAMCAST__
70+
constexpr uint32_t DreamcastMaxSaveSlots = 8;
71+
#endif
72+
73+
uint32_t GetPlatformSaveSlotCount()
74+
{
75+
#ifdef __DREAMCAST__
76+
return std::min<uint32_t>(MAX_CHARACTERS, DreamcastMaxSaveSlots);
77+
#else
78+
return MAX_CHARACTERS;
79+
#endif
80+
}
81+
6882
#ifdef __DREAMCAST__
6983
bool IsRamSavePath(std::string_view path)
7084
{
@@ -890,7 +904,7 @@ bool pfile_ui_set_hero_infos(bool (*uiAddHeroInfo)(_uiheroinfo *))
890904
{
891905
memset(hero_names, 0, sizeof(hero_names));
892906

893-
for (uint32_t i = 0; i < MAX_CHARACTERS; i++) {
907+
for (uint32_t i = 0; i < GetPlatformSaveSlotCount(); i++) {
894908
std::optional<SaveReader> archive = OpenSaveArchive(i);
895909
if (archive) {
896910
PlayerPack pkplr;
@@ -905,9 +919,11 @@ bool pfile_ui_set_hero_infos(bool (*uiAddHeroInfo)(_uiheroinfo *))
905919
Player &player = Players[0];
906920

907921
UnPackPlayer(pkplr, player);
922+
#ifndef __DREAMCAST__
908923
LoadHeroItems(player);
909924
RemoveAllInvalidItems(player);
910925
CalcPlrInv(player, false);
926+
#endif
911927

912928
Game2UiPlayer(player, &uihero, hasSaveGame);
913929
uiAddHeroInfo(&uihero);
@@ -930,7 +946,8 @@ void pfile_ui_set_class_stats(HeroClass playerClass, _uidefaultstats *classStats
930946
uint32_t pfile_ui_get_first_unused_save_num()
931947
{
932948
uint32_t saveNum;
933-
for (saveNum = 0; saveNum < MAX_CHARACTERS; saveNum++) {
949+
const uint32_t saveSlotCount = GetPlatformSaveSlotCount();
950+
for (saveNum = 0; saveNum < saveSlotCount; saveNum++) {
934951
if (hero_names[saveNum][0] == '\0')
935952
break;
936953
}
@@ -942,7 +959,7 @@ bool pfile_ui_save_create(_uiheroinfo *heroinfo)
942959
PlayerPack pkplr;
943960

944961
const uint32_t saveNum = heroinfo->saveNumber;
945-
if (saveNum >= MAX_CHARACTERS)
962+
if (saveNum >= GetPlatformSaveSlotCount())
946963
return false;
947964
heroinfo->saveNumber = saveNum;
948965

0 commit comments

Comments
 (0)