From c9ee2c3eaba27a0b9f7ee115a3f6174e5aff4aab Mon Sep 17 00:00:00 2001 From: Lukas Werling Date: Tue, 19 Feb 2019 17:26:48 +0100 Subject: [PATCH] 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. --- src/platform/C4SoundSystem.cpp | 6 +++--- src/platform/C4SoundSystem.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/platform/C4SoundSystem.cpp b/src/platform/C4SoundSystem.cpp index 6c64d270c..b3d4d8010 100644 --- a/src/platform/C4SoundSystem.cpp +++ b/src/platform/C4SoundSystem.cpp @@ -50,11 +50,13 @@ bool C4SoundSystem::Init() #if AUDIO_TK == AUDIO_TK_SDL_MIXER Mix_AllocateChannels(C4MaxSoundInstances); #endif + initialized = true; return true; } void C4SoundSystem::Clear() { + initialized = false; ClearEffects(); Modifiers.Clear(); // 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) { // Sound not active - if (!Config.Sound.RXSound) return nullptr; + if (!initialized || !Config.Sound.RXSound) return nullptr; // Get sound C4SoundEffect *csfx; if (!(csfx = GetEffect(szSndName))) { // 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); -#endif return nullptr; } // Play diff --git a/src/platform/C4SoundSystem.h b/src/platform/C4SoundSystem.h index e6b445486..24cc7ba98 100644 --- a/src/platform/C4SoundSystem.h +++ b/src/platform/C4SoundSystem.h @@ -55,6 +55,7 @@ public: protected: C4Group SoundFile; 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(); C4SoundEffect* GetEffect(const char *szSound); int32_t RemoveEffect(const char *szFilename);