OK, Iāve been working a little more on doing this ārightā, following some extremely generous help from @NoSloppy (thanks again for that Brian
). But Iām sharing this question here as it might help others as well as myself.
Iāve ignored the reset thing, as we agreed that locking the system while that ran was actually beneficial. So Iām working now on two things - playing a bladeidX.wav when using on-demand bladeid scanning, and playing an arrayX.wav when using manual array switching - both of which I want to be followed by playing the font ident (subject to a define).
Iāll focus just on array switching as, for the benefits of this, they both work the same.
So Iāve re-arranged things so that this is now in my loop section:
// For enabling sequential sounds effects and processes on array handling.
#ifdef SABERSENSE_ARRAY_SELECTOR
if (donewfont_after_sound_has_played_ && !IsArraySoundPlaying()) {
SaberBase::DoNewFont();
}
#endif
This is the main code:
#ifdef SABERSENSE_ARRAY_SELECTOR
bool IsArraySoundPlaying() {
return !!GetWavPlayerPlaying(&SFX_array);
}
#ifdef SABERSENSE_ENABLE_ARRAY_FONT_IDENT // Plays 'array' sound AND 'font' sound.
void NextBladeArray() {
FakeFindBladeAgain();
SFX_array.Select(current_config - blades);
hybrid_font.PlayCommon(&SFX_array);
donewfont_after_sound_has_played_ = true;
return false;
// if (!IsArraySoundPlaying()); // Wait for 'array' sound file to finish...
// SaberBase::DoNewFont(); // ...then play font ident.
}
#else
// Plays 'array' sound only, or 'font' sound if no 'array' sound available.
void NextBladeArray() {
FakeFindBladeAgain();
if (SFX_array) {
SFX_array.Select(current_config - blades);
hybrid_font.PlayCommon(&SFX_array); // Play 'array' sound file if available.
} else {
SaberBase::DoNewFont(); // Play font ident if 'array' sound file missing.
}
}
#endif
#endif
And this line has been added to my private bool section at the bottom of the prop:
bool donewfont_after_sound_has_played_ = false;
So if Iāve understood it right, what should happen is this:
Loop keeps on asking has the array wav finished and is it still playing. If it gets a false to either of those - which it does to at least one of them by default because of the bottom bool line, it returns false and moves on. But once both of those returns true, it knows it has to run SaberBase::DoNewFont();
once the previous effect has finished.
This, I think, follows the advice given above, except for the fact that in my version,
if (!IsBladeidSoundPlaying());
and
SaberBase::DoNewFont();
are shown twice - once in the loop and once in the main code. Iām pretty sure this is wrong, but I canāt quite figure out what it should be instead.
What seems to be happening is that when
donewfont_after_sound_has_played_ = true;
which is in the main code calls
if (donewfont_after_sound_has_played_ && !IsArraySoundPlaying()) {
from loop,
SaberBase::DoNewFont();
gets stuck in a loop playing the first few milliseconds of the font ident over and over again until I hit the kill switch. But if I leave out the
donewfont_after_sound_has_played_ = true;
,
weāre back to arrayX.wav and font ident playing at the same time.
Conversely, if I leave out the two lines from the main code
if (!IsBladeidSoundPlaying());
and
SaberBase::DoNewFont();
,
I again get the weird looping effect.
Iāve tried leaving out
SaberBase::DoNewFont();
from both the main code and the loop, plus as many other combinations as I can think of, but thereās clearly some little detail wrong. It almost feels like I need a return false;
somewhere, but when I try that, it wonāt compile.
What have I missed?