Fix "no matching sound" error spam

Previously, the error message was only silenced for openclonk-server,
but appeared for openclonk if compiled without sounds.

Possible side effect: no local sounds will play if the global Sound.ocg
cannot be loaded. I don't think this is something we should support.
master
Lukas Werling 2019-02-19 17:26:48 +01:00
parent 319dc87eea
commit c9ee2c3eab
2 changed files with 4 additions and 3 deletions

View File

@ -50,11 +50,13 @@ bool C4SoundSystem::Init()
#if AUDIO_TK == AUDIO_TK_SDL_MIXER #if AUDIO_TK == AUDIO_TK_SDL_MIXER
Mix_AllocateChannels(C4MaxSoundInstances); Mix_AllocateChannels(C4MaxSoundInstances);
#endif #endif
initialized = true;
return true; return true;
} }
void C4SoundSystem::Clear() void C4SoundSystem::Clear()
{ {
initialized = false;
ClearEffects(); ClearEffects();
Modifiers.Clear(); Modifiers.Clear();
// Close sound file // Close sound file
@ -122,15 +124,13 @@ C4SoundEffect* C4SoundSystem::GetEffect(const char *szSndName)
C4SoundInstance *C4SoundSystem::NewEffect(const char *szSndName, bool fLoop, int32_t iVolume, C4Object *pObj, int32_t iCustomFalloffDistance, int32_t iPitch, C4SoundModifier *modifier) C4SoundInstance *C4SoundSystem::NewEffect(const char *szSndName, bool fLoop, int32_t iVolume, C4Object *pObj, int32_t iCustomFalloffDistance, int32_t iPitch, C4SoundModifier *modifier)
{ {
// Sound not active // Sound not active
if (!Config.Sound.RXSound) return nullptr; if (!initialized || !Config.Sound.RXSound) return nullptr;
// Get sound // Get sound
C4SoundEffect *csfx; C4SoundEffect *csfx;
if (!(csfx = GetEffect(szSndName))) if (!(csfx = GetEffect(szSndName)))
{ {
// Warn about missing or incorrectly spelled sound to allow finding mistakes earlier. // Warn about missing or incorrectly spelled sound to allow finding mistakes earlier.
#if !defined(USE_CONSOLE)
DebugLogF("Warning: could not find sound matching '%s'", szSndName); DebugLogF("Warning: could not find sound matching '%s'", szSndName);
#endif
return nullptr; return nullptr;
} }
// Play // Play

View File

@ -55,6 +55,7 @@ public:
protected: protected:
C4Group SoundFile; C4Group SoundFile;
C4SoundEffect *FirstSound{nullptr}; // TODO: Add a hash map for sound lookup. Also add a global list for all running sound instances. C4SoundEffect *FirstSound{nullptr}; // TODO: Add a hash map for sound lookup. Also add a global list for all running sound instances.
bool initialized{false};
void ClearEffects(); void ClearEffects();
C4SoundEffect* GetEffect(const char *szSound); C4SoundEffect* GetEffect(const char *szSound);
int32_t RemoveEffect(const char *szFilename); int32_t RemoveEffect(const char *szFilename);