Skip to content

Commit 9685cce

Browse files
committed
Split fetching of group data into multiple batches to avoid requesting a message that's way too large to process
1 parent 79dee43 commit 9685cce

4 files changed

Lines changed: 62 additions & 30 deletions

File tree

soh/soh/Enhancements/FileSelectEnhancements.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ std::array<std::string, LANGUAGE_MAX> ArchipelagoSettingsMenuText[ASM_MAX]{
109109
},
110110
// ASM_LOADING_DATA
111111
{
112-
"Loading Data...",
113-
"Loading Data...",
114-
"Loading Data...",
112+
"Loading Data: ",
113+
"Loading Data: ",
114+
"Loading Data: ",
115115
},
116116
// ASM_DATA_LOADED
117117
{

soh/soh/Network/Archipelago/Archipelago.cpp

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -423,29 +423,29 @@ bool ArchipelagoClient::StartClient() {
423423
UpdateHints(data.at(hint_key.str()));
424424
}
425425

426-
std::unordered_set<std::string> games;
427-
for (const APClient::NetworkPlayer& player : apClient->get_players()) {
428-
games.emplace(apClient->get_player_game(player.slot));
429-
}
430-
431-
// item & location groups
432-
bool groups_received = false;
433-
for (const std::string& game : games) {
434-
const std::string item_group_key = "_read_item_name_groups_" + game;
435-
if (data.contains(item_group_key)) {
436-
groups_received = true;
437-
UpdateItemGroup(game, data.at(item_group_key));
426+
bool all_groups_received = false;
427+
if (fetchingGroups.request_index != fetchingGroups.num_requests) {
428+
const std::string& game = fetchingGroups.hint_group_games[fetchingGroups.request_index];
429+
const std::string item_group = "_read_item_name_groups_" + game;
430+
const std::string location_group = "_read_location_name_groups_" + game;
431+
if (data.contains(item_group)) {
432+
UpdateItemGroup(game, data.at(item_group));
433+
}
434+
if (data.contains(location_group)) {
435+
UpdateLocationGroup(game, data.at(location_group));
438436
}
439-
const std::string location_group_key = "_read_location_name_groups_" + game;
440-
if (data.contains(location_group_key)) {
441-
groups_received = true;
442-
UpdateLocationGroup(game, data.at(location_group_key));
437+
fetchingGroups.request_index++;
438+
all_groups_received = fetchingGroups.request_index == fetchingGroups.num_requests;
439+
if (!all_groups_received) {
440+
const std::string& next_game = fetchingGroups.hint_group_games[fetchingGroups.request_index];
441+
apClient->Get({ "_read_item_name_groups_" + next_game, "_read_location_name_groups_" + next_game});
443442
}
444443
}
445444

446445
// after getting grouping data, fetch location scouts
447446
// Foreign hints should be loaded from the save file as well
448-
if (groups_received) {
447+
if (all_groups_received) {
448+
fetchingGroups.fetching = false;
449449
ArchipelagoClient::InitForeignHints();
450450
}
451451
});
@@ -462,26 +462,25 @@ void ArchipelagoClient::RequestInitData() {
462462
// To create a save file we'll need the following data:
463463
// Slot Data: received on connection, we already have this
464464
// Data package: received on connection, we already have this
465-
// Location Scouts, Asynch request done here
466465
// Location and Item groups, Asynch request done here
466+
// Location Scouts, Asynch request done after item groups have been loaded
467467

468468
CVarSetInteger(CVAR_REMOTE_ARCHIPELAGO("ConnectionStatus"), 4); // fetching foreign hint and scout data
469469

470-
// get location scouts
471-
StartLocationScouts();
472-
473470
// request the item and location groups
474471
std::unordered_set<std::string> games;
475472
for (const APClient::NetworkPlayer& player : apClient->get_players()) {
476473
games.emplace(apClient->get_player_game(player.slot));
477474
}
478475

479-
std::list<std::string> requests;
476+
fetchingGroups = ApHintFetchData();
480477
for (const std::string& game : games) {
481-
requests.emplace_back("_read_item_name_groups_" + game);
482-
requests.emplace_back("_read_location_name_groups_" + game);
478+
fetchingGroups.hint_group_games.emplace_back(game);
483479
}
484-
apClient->Get(requests);
480+
fetchingGroups.num_requests = fetchingGroups.hint_group_games.size();
481+
const std::string& firstGame = fetchingGroups.hint_group_games[0];
482+
fetchingGroups.fetching = true;
483+
apClient->Get({ "_read_item_name_groups_" + firstGame, "_read_location_name_groups_" + firstGame });
485484
}
486485

487486
// update the connection status if we have all data we need to initialize a save file
@@ -613,6 +612,9 @@ void ArchipelagoClient::InitForeignHints() {
613612

614613
hintsInitialized = true;
615614
newInitDataReceived();
615+
616+
// get location scouts
617+
StartLocationScouts();
616618
}
617619

618620
void ArchipelagoClient::QueueExternalCheck(const int64_t apLocation) {
@@ -1561,6 +1563,14 @@ extern "C" void Archipelago_RequestInitData() {
15611563
ArchipelagoClient::GetInstance().RequestInitData();
15621564
}
15631565

1566+
extern "C" size_t Archipelago_FetchHintMax() {
1567+
return ArchipelagoClient::GetInstance().GetFetchingGroupMax();
1568+
}
1569+
1570+
extern "C" size_t Archipelago_FetchHintCurrent() {
1571+
return ArchipelagoClient::GetInstance().GetFetchingGroupCurrent();
1572+
}
1573+
15641574
void SetArchipelagoParsing(uint8_t state) {
15651575
isArchipelagoParsing = state;
15661576
}

soh/soh/Network/Archipelago/Archipelago.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ class ArchipelagoClient {
4343
int64_t playerId;
4444
};
4545

46+
struct ApHintFetchData {
47+
bool fetching = false;
48+
std::vector<std::string> hint_group_games;
49+
size_t request_index;
50+
size_t num_requests;
51+
};
52+
4653
static ArchipelagoClient& GetInstance();
4754

4855
bool StartClient();
@@ -103,6 +110,8 @@ class ArchipelagoClient {
103110

104111
bool slotMatch(const std::string& slotName, const std::string& roomHash);
105112
void newInitDataReceived();
113+
size_t GetFetchingGroupMax() const { return fetchingGroups.fetching ? fetchingGroups.num_requests : 0; };
114+
size_t GetFetchingGroupCurrent() const { return fetchingGroups.fetching ? fetchingGroups.request_index : 0; };
106115

107116
static std::string SanitizeName(const std::string& name);
108117

@@ -140,6 +149,7 @@ class ArchipelagoClient {
140149
std::set<int64_t> locations;
141150
std::vector<ApItem> scoutedItems;
142151
std::queue<ApItem> receiveQueue;
152+
ApHintFetchData fetchingGroups;
143153

144154
bool locationsScouted;
145155
bool hintsInitialized;
@@ -155,6 +165,8 @@ void Archipelago_InitConnection();
155165
void Archipelago_RequestInitData();
156166
void SetArchipelagoParsing(uint8_t state);
157167
uint8_t IsArchipelagoParsing();
168+
size_t Archipelago_FetchHintMax();
169+
size_t Archipelago_FetchHintCurrent();
158170
#ifdef __cplusplus
159171
}
160172
#endif

soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,11 +2221,21 @@ void FileChoose_DrawWindowContents(GameState* thisx) {
22212221
SohFileSelect_GetArchipelagoSettingText(ASM_CONNECTED, language), statusPos, 175,
22222222
120, 255, 120, textAlpha, 0.8f, true);
22232223
break;
2224-
case 4: // Loading Data
2225-
Interface_DrawTextLine(this->state.gfxCtx,
2224+
case 4: // Loading Data
2225+
{
2226+
int offset = Interface_DrawTextLine(this->state.gfxCtx,
22262227
SohFileSelect_GetArchipelagoSettingText(ASM_LOADING_DATA, language), statusPos,
22272228
175, 185, 185, 185, textAlpha, 0.8f, true);
2229+
const size_t fetchIndex = Archipelago_FetchHintCurrent();
2230+
const size_t fetchMax = Archipelago_FetchHintMax();
2231+
char progress[12]; // enough room for "(xxxx/yyyy)"
2232+
snprintf(progress, 12, "(%i/%i)", fetchIndex, fetchMax);
2233+
Interface_DrawTextLine(this->state.gfxCtx,
2234+
progress, statusPos + offset,
2235+
175, 185, 185, 185, textAlpha, 0.8f, true);
2236+
22282237
break;
2238+
}
22292239
case 5: // Data Loaded
22302240
Interface_DrawTextLine(this->state.gfxCtx,
22312241
SohFileSelect_GetArchipelagoSettingText(ASM_DATA_LOADED, language), statusPos,

0 commit comments

Comments
 (0)