Client Development Dynamic music mute when client out of scope /inactive

Mothanna

Very Active Pirate
Veteran
Developer
Server Owner
Registered
LV
4
 
Joined
Dec 29, 2025
Messages
93
Reaction score
65
Points
33
Website
satisfy.live
Dynamic music mute when client out of scope /inactive
this old code i had for optimize music conflict with multi client's run ,
//open :
#src\UISystemForm.cpp
//search for void CSystemMgr::FrameMove(const DWORD dwTime) {

//inside it add:
C++:
    //mute music value when client inactive/out of scope ,
        if (static CTimeWork time(1000); time.IsTimeOut(dwTime)) {
            // change music size depends if client active or not
            static bool reactivateit = false;
            if (CGameApp::CIsGameWindowActive()) {
                if (g_stUISystem.m_sysProp.m_audioProp.nMusicEffect > 0 || g_stUISystem.m_sysProp.m_audioProp.nMusicSound > 0) {
                    if (!reactivateit) {
                        reactivateit = true;
                        [[maybe_unused]] const auto ignore = g_stUISystem.m_sysProp.ApplyAudio();
                    }
                    //g_pGameApp->mSoundManager->SetMasterVolume(1);   
                }
            } else {
                //g_pGameApp->mSoundManager->SetMasterVolume(0);   
                reactivateit = false;
                if (g_stUISystem.m_sysProp.m_audioProp.nMusicEffect >= 0 || g_stUISystem.m_sysProp.m_audioProp.nMusicSound > 0) {
                    CGameApp::GetCurScene()->SetSoundSize(0.0f);
                    CGameApp::SetMusicSize(0.0f);
                    g_pGameApp->mSoundManager->SetVolume(0);
                }
            }
            // music controller end           
        }
//open:
#\src\GameApp.h
//in public add:

C++:
//to check if game in focus or in background to use later for optimize
    static bool CIsGameWindowActive();

//open
#\src\GameAppInit.cpp

C++:
//anywhere in file add:
bool CGameApp::CIsGameWindowActive() {
    //if result is true then its on focus , but if its false means its out of focus
    const HWND hForegroundWnd = GetForegroundWindow(); // get the handle of the window currently in focus
    return (g_pGameApp->GetHWND() == hForegroundWnd);  // compare the two handles
}
 
  • Like
Reactions: Panda and ximboliex