make dolphin random cycle through all stages (#31)

Co-authored-by: Jas Laferriere <Fizzi36@gmail.com>
This commit is contained in:
Edgar Handal 2020-07-16 16:36:59 -05:00 committed by R2DLiu
commit fc7b9e4e8f
2 changed files with 11 additions and 23 deletions

View file

@ -1868,31 +1868,16 @@ u16 CEXISlippi::getRandomStage()
0x20, // Final Destination
};
std::vector<u16> stagesToConsider;
// stagesToConsider = stages;
// Add all stages to consider to the vector
for (auto it = stages.begin(); it != stages.end(); ++it)
{
auto stageId = *it;
if (lastSelectedStage != nullptr && stageId == *lastSelectedStage)
continue;
stagesToConsider.push_back(stageId);
}
// Shuffle the stages to consider. This isn't really necessary considering we
// use a random number to select an index but idk the generator was giving a lot
// of the same stage (same index) many times in a row or so it seemed to I figured
// this can't hurt
std::shuffle(stagesToConsider.begin(), stagesToConsider.end(), generator);
// Reset stage pool if it's empty
if (stagePool.empty())
stagePool.insert(stagePool.end(), stages.begin(), stages.end());
// Get random stage
int randIndex = generator() % stagesToConsider.size();
selectedStage = stagesToConsider[randIndex];
int randIndex = generator() % stagePool.size();
selectedStage = stagePool[randIndex];
// Set last selected stage
lastSelectedStage = &selectedStage;
// Remove last selection from stage pool
stagePool.erase(stagePool.begin() + randIndex);
return selectedStage;
}
@ -2074,6 +2059,9 @@ void CEXISlippi::handleConnectionCleanup()
// Clear character selections
localSelections.Reset();
// Reset random stage pool
stagePool.clear();
ERROR_LOG(SLIPPI_ONLINE, "Connection cleanup completed...");
}

View file

@ -197,7 +197,7 @@ namespace ExpansionInterface
std::unique_ptr<Slippi::SlippiGame> m_current_game = nullptr;
SlippiMatchmaking::MatchSearchSettings lastSearch;
u16* lastSelectedStage = nullptr;
std::vector<u16> stagePool;
u32 frameSeqIdx = 0;