mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-08-28 12:17:04 -05:00
Fix getCurrentScene() returning garbage if scene group has type random (#125)
This commit is contained in:
@@ -37,7 +37,7 @@ struct SceneGroup {
|
||||
|
||||
int currentCount = -1;
|
||||
std::chrono::high_resolution_clock::time_point lastAdvTime;
|
||||
OBSWeakSource lastRandomScene = nullptr;
|
||||
int lastRandomScene = -1;
|
||||
|
||||
inline SceneGroup(){};
|
||||
inline SceneGroup(std::string name_) : name(name_){};
|
||||
|
||||
@@ -51,27 +51,26 @@ OBSWeakSource SceneGroup::getNextSceneTime()
|
||||
OBSWeakSource SceneGroup::getNextSceneRandom()
|
||||
{
|
||||
if (scenes.size() == 1) {
|
||||
return *scenes.begin();
|
||||
currentIdx = 0;
|
||||
return scenes[currentIdx];
|
||||
}
|
||||
|
||||
std::vector<OBSWeakSource> rs(scenes);
|
||||
std::random_device rng;
|
||||
std::mt19937 urng(rng());
|
||||
std::shuffle(rs.begin(), rs.end(), urng);
|
||||
for (OBSWeakSource &s : rs) {
|
||||
if (s == lastRandomScene) {
|
||||
continue;
|
||||
}
|
||||
int rIdx = lastRandomScene;
|
||||
do {
|
||||
rIdx = rand() % scenes.size();
|
||||
} while (rIdx == lastRandomScene);
|
||||
|
||||
lastRandomScene = s;
|
||||
lastRandomScene = rIdx;
|
||||
currentIdx = rIdx;
|
||||
|
||||
return s;
|
||||
}
|
||||
return nullptr;
|
||||
return scenes[currentIdx];
|
||||
}
|
||||
|
||||
OBSWeakSource SceneGroup::getCurrentScene()
|
||||
{
|
||||
if (scenes.size() < currentIdx + 1) {
|
||||
return nullptr;
|
||||
}
|
||||
return scenes[currentIdx];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user