Skip to content

Commit

Permalink
Use std::unique_ptr for SoundChannel::Unit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarod42 committed Oct 10, 2023
1 parent da18df1 commit 8ce272c
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/sound/sound_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ static bool External_Volume(int volume, int oldVolume) {

/// Channels for sound effects and unit speech
struct SoundChannel {
Origin *Unit = nullptr; /// pointer to unit, who plays the sound, if any
std::unique_ptr<Origin> Unit; /// pointer to unit, who plays the sound, if any
void (*FinishedCallback)(int channel) = nullptr; /// Callback for when a sample finishes playing
};

Expand Down Expand Up @@ -288,7 +288,6 @@ static void ChannelFinished(int channel)
event.user.data1 = (void*) Channels[channel].FinishedCallback;
SDL_PeepEvents(&event, 1, SDL_ADDEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT);
}
delete Channels[channel].Unit;
Channels[channel].Unit = nullptr;
}

Expand Down Expand Up @@ -483,7 +482,7 @@ static int PlaySample(Mix_Chunk *sample, Origin *origin, void (*callback)(int ch
DebugPrint("play sample %d\n", sample->volume);
#ifdef DYNAMIC_LOAD
if (sample->allocated == 0xcafebeef) {
char *name = (char*)(sample->abuf);
const char *name = (const char*)(sample->abuf);
Mix_Chunk *loadedSample = ForceLoadSample(name);
if (loadedSample) {
memcpy(sample, loadedSample, sizeof(Mix_Chunk));
Expand All @@ -498,10 +497,10 @@ static int PlaySample(Mix_Chunk *sample, Origin *origin, void (*callback)(int ch
if (channel >= 0 && channel < MaxChannels) {
Channels[channel].FinishedCallback = callback;
if (origin && origin->Base) {
Origin *source = new Origin;
auto source = std::make_unique<Origin>();
source->Base = origin->Base;
source->Id = origin->Id;
Channels[channel].Unit = source;
Channels[channel].Unit = std::move(source);
}
}
}
Expand Down Expand Up @@ -677,7 +676,7 @@ bool SoundEnabled()
**
** @return false if failure, true if everything ok.
*/
static int InitSdlSound()
static bool InitSdlSound()
{
fs::path timidityCfg(StratagusLibPath);
timidityCfg = timidityCfg / "timidity" / "timidity.cfg";
Expand Down

0 comments on commit 8ce272c

Please sign in to comment.