Skip to content

Commit 356e08d

Browse files
committed
Fixed "not all control paths return a value" warnings
1 parent afddaa8 commit 356e08d

File tree

1 file changed

+54
-52
lines changed

1 file changed

+54
-52
lines changed

Source/Entities/DynamicSong.cpp

Lines changed: 54 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -128,77 +128,79 @@ SoundContainer& DynamicSongSection::SelectTransitionSoundContainer() {
128128
if (m_TransitionSoundContainers.empty()) {
129129
return SelectSoundContainer();
130130
}
131-
if (m_TransitionSoundContainers.size() == 1) {
132-
return m_TransitionSoundContainers[0];
133-
}
134131

135-
if (m_TransitionShuffleUnplayedIndices.empty()) {
136-
for (unsigned int i = 0; i < m_TransitionSoundContainers.size(); i++) {
137-
if (i != m_LastTransitionSoundContainerIndex) {
138-
m_TransitionShuffleUnplayedIndices.push_back(i);
139-
}
140-
}
141-
}
142-
143-
switch (m_SoundContainerSelectionCycleMode) {
144-
case RANDOMNOREPEAT: {
145-
std::vector<unsigned int> validIndices;
132+
// Shuffle between our options if we have multiple
133+
if (m_TransitionSoundContainers.size() > 1) {
134+
if (m_TransitionShuffleUnplayedIndices.empty()) {
146135
for (unsigned int i = 0; i < m_TransitionSoundContainers.size(); i++) {
147136
if (i != m_LastTransitionSoundContainerIndex) {
148-
validIndices.push_back(i);
137+
m_TransitionShuffleUnplayedIndices.push_back(i);
149138
}
150139
}
151-
152-
unsigned int randomIndex = validIndices[RandomNum(0, static_cast<int>(validIndices.size()) - 1)];
153-
m_LastTransitionSoundContainerIndex = randomIndex;
154-
return m_TransitionSoundContainers[randomIndex];
155-
}
156-
case SHUFFLE: {
157-
unsigned int randomSelection = RandomNum(0, static_cast<int>(m_TransitionShuffleUnplayedIndices.size() - 1));
158-
unsigned int selectedIndex = m_TransitionShuffleUnplayedIndices[randomSelection];
159-
m_TransitionShuffleUnplayedIndices.erase(m_TransitionShuffleUnplayedIndices.begin() + randomSelection);
160-
m_LastTransitionSoundContainerIndex = selectedIndex;
161-
return m_TransitionSoundContainers[selectedIndex];
162140
}
163-
}
164-
}
165-
166-
SoundContainer& DynamicSongSection::SelectSoundContainer() {
167-
RTEAssert(!m_SoundContainers.empty(), "Tried to get a SoundContainer from a DynamicSongSection with none to choose from!");
168141

169-
if (m_SoundContainers.size() == 1) {
170-
return m_SoundContainers[0];
171-
}
142+
switch (m_SoundContainerSelectionCycleMode) {
143+
case RANDOMNOREPEAT: {
144+
std::vector<unsigned int> validIndices;
145+
for (unsigned int i = 0; i < m_TransitionSoundContainers.size(); i++) {
146+
if (i != m_LastTransitionSoundContainerIndex) {
147+
validIndices.push_back(i);
148+
}
149+
}
172150

173-
if (m_ShuffleUnplayedIndices.empty()) {
174-
for (unsigned int i = 0; i < m_SoundContainers.size(); i++) {
175-
if (i != m_LastSoundContainerIndex) {
176-
m_ShuffleUnplayedIndices.push_back(i);
151+
unsigned int randomIndex = validIndices[RandomNum(0, static_cast<int>(validIndices.size()) - 1)];
152+
m_LastTransitionSoundContainerIndex = randomIndex;
153+
return m_TransitionSoundContainers[randomIndex];
154+
}
155+
case SHUFFLE: {
156+
unsigned int randomSelection = RandomNum(0, static_cast<int>(m_TransitionShuffleUnplayedIndices.size() - 1));
157+
unsigned int selectedIndex = m_TransitionShuffleUnplayedIndices[randomSelection];
158+
m_TransitionShuffleUnplayedIndices.erase(m_TransitionShuffleUnplayedIndices.begin() + randomSelection);
159+
m_LastTransitionSoundContainerIndex = selectedIndex;
160+
return m_TransitionSoundContainers[selectedIndex];
177161
}
178162
}
179163
}
180164

181-
switch (m_SoundContainerSelectionCycleMode) {
182-
case RANDOMNOREPEAT: {
183-
std::vector<unsigned int> validIndices;
165+
return m_TransitionSoundContainers[0];
166+
}
167+
168+
SoundContainer& DynamicSongSection::SelectSoundContainer() {
169+
// Shuffle between our options if we have multiple
170+
if (m_SoundContainers.size() != 1) {
171+
if (m_ShuffleUnplayedIndices.empty()) {
184172
for (unsigned int i = 0; i < m_SoundContainers.size(); i++) {
185173
if (i != m_LastSoundContainerIndex) {
186-
validIndices.push_back(i);
174+
m_ShuffleUnplayedIndices.push_back(i);
187175
}
188176
}
189-
190-
unsigned int randomIndex = validIndices[RandomNum(0, static_cast<int>(validIndices.size()) - 1)];
191-
m_LastSoundContainerIndex = randomIndex;
192-
return m_SoundContainers[randomIndex];
193177
}
194-
case SHUFFLE: {
195-
unsigned int randomSelection = RandomNum(0, static_cast<int>(m_ShuffleUnplayedIndices.size() - 1));
196-
unsigned int selectedIndex = m_ShuffleUnplayedIndices[randomSelection];
197-
m_ShuffleUnplayedIndices.erase(m_ShuffleUnplayedIndices.begin() + randomSelection);
198-
m_LastSoundContainerIndex = selectedIndex;
199-
return m_SoundContainers[selectedIndex];
178+
179+
switch (m_SoundContainerSelectionCycleMode) {
180+
case RANDOMNOREPEAT: {
181+
std::vector<unsigned int> validIndices;
182+
for (unsigned int i = 0; i < m_SoundContainers.size(); i++) {
183+
if (i != m_LastSoundContainerIndex) {
184+
validIndices.push_back(i);
185+
}
186+
}
187+
188+
unsigned int randomIndex = validIndices[RandomNum(0, static_cast<int>(validIndices.size()) - 1)];
189+
m_LastSoundContainerIndex = randomIndex;
190+
return m_SoundContainers[randomIndex];
191+
}
192+
case SHUFFLE: {
193+
unsigned int randomSelection = RandomNum(0, static_cast<int>(m_ShuffleUnplayedIndices.size() - 1));
194+
unsigned int selectedIndex = m_ShuffleUnplayedIndices[randomSelection];
195+
m_ShuffleUnplayedIndices.erase(m_ShuffleUnplayedIndices.begin() + randomSelection);
196+
m_LastSoundContainerIndex = selectedIndex;
197+
return m_SoundContainers[selectedIndex];
198+
}
200199
}
201200
}
201+
202+
RTEAssert(!m_SoundContainers.empty(), "Tried to get a SoundContainer from a DynamicSongSection with none to choose from!");
203+
return m_SoundContainers[0];
202204
}
203205

204206
DynamicSong::DynamicSong() {

0 commit comments

Comments
 (0)