Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intelmap fixes #3456

Merged
merged 2 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/sound/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ bool audio_PlayObjDynamicTrack(SIMPLE_OBJECT *psObj, int iTrack, AUDIO_CALLBACK
* \note You must _never_ manually free() the memory used by the returned
* pointer.
*/
AUDIO_STREAM *audio_PlayStream(const char *fileName, float volume, void (*onFinished)(const AUDIO_STREAM *, const void *), const void *user_data)
AUDIO_STREAM *audio_PlayStream(const char *fileName, float volume, const std::function<void (const AUDIO_STREAM *, const void *)>& onFinished, const void *user_data)
{
// If audio is not enabled return false to indicate that the given callback
// will not be invoked.
Expand Down
2 changes: 1 addition & 1 deletion lib/sound/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ bool audio_PlayObjDynamicTrack(SIMPLE_OBJECT *psObj, int iTrack, AUDIO_CALLBACK
void audio_StopObjTrack(SIMPLE_OBJECT *psObj, int iTrack);
void audio_PlayTrack(int iTrack);
void audio_PlayCallbackTrack(int iTrack, AUDIO_CALLBACK pUserCallback);
AUDIO_STREAM *audio_PlayStream(const char *fileName, float volume, void (*onFinished)(const AUDIO_STREAM *, const void *), const void *user_data);
AUDIO_STREAM *audio_PlayStream(const char *fileName, float volume, const std::function<void (const AUDIO_STREAM *, const void *)>& onFinished, const void *user_data);
void audio_QueueTrack(SDWORD iTrack);
void audio_QueueTrackMinDelay(SDWORD iTrack, UDWORD iMinDelay);
void audio_QueueTrackMinDelayPos(SDWORD iTrack, UDWORD iMinDelay, SDWORD iX, SDWORD iY, SDWORD iZ);
Expand Down
6 changes: 6 additions & 0 deletions src/hci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2479,6 +2479,12 @@ static bool intAddCommand()
//sets up the Intelligence Screen as far as the interface is concerned
void addIntelScreen()
{
if (intMode == INT_INTELMAP)
{
// screen is already up - do nothing
return;
}

intResetScreen(false);
intHideGroupSelectionMenu();

Expand Down
20 changes: 15 additions & 5 deletions src/intelmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,12 @@ class W_INTELLIGENCEOVERLAY_FORM : public W_FORM
protected:
W_INTELLIGENCEOVERLAY_FORM(W_FORMINIT const *init);
W_INTELLIGENCEOVERLAY_FORM();
~W_INTELLIGENCEOVERLAY_FORM() {
if (sound_isStreamPlaying(playing))
{
sound_StopStream(playing);
}
}
public:
static std::shared_ptr<W_INTELLIGENCEOVERLAY_FORM> make(bool _playCurrent, UDWORD formID = 0);
void clicked(W_CONTEXT *psContext, WIDGET_KEY key) override;
Expand All @@ -394,6 +400,7 @@ class W_INTELLIGENCEOVERLAY_FORM : public W_FORM
std::shared_ptr<WzMessageView> msgDetailsView;
bool isClosing = false;
bool delayedPlayCurrent = false;
AUDIO_STREAM *playing = nullptr;
};

constexpr int OVERLAY_MULTIMENU_FORM_Y = 50;
Expand Down Expand Up @@ -692,8 +699,6 @@ void W_INTELLIGENCEOVERLAY_FORM::intIntelButtonPressed(const std::shared_ptr<Int
psResearch = getResearchForMsg(psMessage->pViewData);
if (psResearch != nullptr)
{
static AUDIO_STREAM *playing = nullptr;

// only play the sample once, otherwise, they tend to overlap each other
if (sound_isStreamPlaying(playing))
{
Expand Down Expand Up @@ -727,10 +732,15 @@ void W_INTELLIGENCEOVERLAY_FORM::intIntelButtonPressed(const std::shared_ptr<Int

if (audio != nullptr)
{
playing = audio_PlayStream(audio, sound_GetUIVolume(), [](const AUDIO_STREAM *stream, const void *) {
if (stream == playing)
std::weak_ptr<W_INTELLIGENCEOVERLAY_FORM> weakSelf = std::dynamic_pointer_cast<W_INTELLIGENCEOVERLAY_FORM>(shared_from_this());
playing = audio_PlayStream(audio, sound_GetUIVolume(), [weakSelf](const AUDIO_STREAM *stream, const void *) {
auto strongSelf = weakSelf.lock();
if (strongSelf)
{
playing = nullptr;
if (stream == strongSelf->playing)
{
strongSelf->playing = nullptr;
}
}
}, nullptr);
}
Expand Down
Loading