GRIM: Fix Memset on Structures GCC Warnings

This now uses a clear() method in the Track structure.
This commit is contained in:
D G Turner 2021-03-19 08:52:11 +00:00
parent b41a90a1d5
commit 7763ce5802
4 changed files with 45 additions and 12 deletions

View File

@ -58,7 +58,7 @@ Imuse::Imuse(int fps, bool demo) {
for (int l = 0; l < MAX_IMUSE_TRACKS + MAX_IMUSE_FADETRACKS; l++) {
_track[l] = new Track;
assert(_track[l]);
memset(_track[l], 0, sizeof(Track));
_track[l]->clear();
_track[l]->trackId = l;
}
vimaInit(imuseDestTable);
@ -99,7 +99,7 @@ void Imuse::restoreState(SaveGame *savedState) {
for (int l = 0; l < MAX_IMUSE_TRACKS + MAX_IMUSE_FADETRACKS; l++) {
Track *track = _track[l];
memset(track, 0, sizeof(Track));
track->clear();
track->trackId = l;
track->pan = savedState->readLESint32();
track->panFadeDest = savedState->readLESint32();
@ -210,7 +210,7 @@ void Imuse::callback() {
// mark it as unused.
if (!track->stream) {
if (!track->soundDesc || !g_system->getMixer()->isSoundHandleActive(track->handle))
memset(track, 0, sizeof(Track));
track->clear();
continue;
}

View File

@ -45,7 +45,7 @@ void Imuse::flushTrack(Track *track) {
}
if (!g_system->getMixer()->isSoundHandleActive(track->handle)) {
memset(track, 0, sizeof(Track));
track->clear();
}
}
@ -54,7 +54,7 @@ void Imuse::flushTracks() {
for (int l = 0; l < MAX_IMUSE_TRACKS + MAX_IMUSE_FADETRACKS; l++) {
Track *track = _track[l];
if (track->used && track->toBeRemoved && !g_system->getMixer()->isSoundHandleActive(track->handle)) {
memset(track, 0, sizeof(Track));
track->clear();
}
}
}
@ -167,7 +167,7 @@ void Imuse::stopAllSounds() {
if (track->soundDesc) {
_sound->closeSound(track->soundDesc);
}
memset(track, 0, sizeof(Track));
track->clear();
}
}
}

View File

@ -61,7 +61,7 @@ int Imuse::allocSlot(int priority) {
}
// Mark it as unused
memset(track, 0, sizeof(Track));
track->clear();
} else {
return -1;
}
@ -91,7 +91,7 @@ bool Imuse::startSound(const char *soundName, int volGroupId, int hookId, int vo
memcpy(track, fadeTrack, sizeof(Track));
track->trackId = i - MAX_IMUSE_TRACKS;
// Reset the track
memset(fadeTrack, 0, sizeof(Track));
fadeTrack->clear();
// Mark as used for now so the track won't be reused again this frame
track->used = true;
@ -124,7 +124,7 @@ bool Imuse::startSound(const char *soundName, int volGroupId, int hookId, int vo
track = _track[l];
// Reset the track
memset(track, 0, sizeof(Track));
track->clear();
track->pan = pan * 1000;
track->vol = volume * 1000;
@ -443,7 +443,7 @@ Track *Imuse::moveToFadeOutTrack(Track *track, int fadeDelay) {
fadeTrack->trackId = track->trackId + MAX_IMUSE_TRACKS;
// Reset the track
memset(track, 0, sizeof(Track));
track->clear();
// Mark as used for now so the track won't be reused again this frame
track->used = true;

View File

@ -65,8 +65,41 @@ struct Track {
Audio::SoundHandle handle;
Audio::QueuingAudioStream *stream;
Track() : used(false), stream(NULL) {
soundName[0] = 0;
Track() {
clear();
}
void clear() {
trackId = 0;
pan = 0;
panFadeDest = 0;
panFadeStep = 0;
panFadeDelay = 0;
panFadeUsed = 0;
vol = 0;
volFadeDest = 0;
volFadeStep = 0;
volFadeDelay = 0;
volFadeUsed = 0;
for (uint i = 0; i < ARRAYSIZE(soundName); i++) {
soundName[i] = 0;
}
used = false;
toBeRemoved = false;
priority = 0;
regionOffset = 0;
dataOffset = 0;
curRegion = 0;
curHookId = 0;
volGroupId = 0;
feedSize = 0;
mixerFlags = 0;
soundDesc = nullptr;
// handle not cleared. FIXME: Clear by resetting _val to default (0xFFFFFFFF not 0)?
stream = nullptr;
}
/* getPan() returns -127 ... 127 */