Exemple #1
0
void CALLBACK DownloadSync ( HSYNC handle, DWORD channel, DWORD data, void* user )
{
    CClientSound* pClientSound = static_cast <CClientSound*> ( user );

    // Call onClientSoundFinishedDownload LUA event
    CLuaArguments Arguments;
    Arguments.PushNumber ( pClientSound->GetLength () );
    pClientSound->CallEvent ( "onClientSoundFinishedDownload", Arguments, true );
}
int CLuaFunctionDefs::PlaySound3D ( lua_State* luaVM )
{
    SString strSound = "";
    CVector vecPosition;
    CScriptArgReader argStream ( luaVM );
    argStream.ReadString ( strSound );
    argStream.ReadNumber ( vecPosition.fX );
    argStream.ReadNumber ( vecPosition.fY );
    argStream.ReadNumber ( vecPosition.fZ );

    if ( !argStream.HasErrors() )
    {
        CLuaMain * luaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( luaMain )
        {
            CResource* pResource = luaMain->GetResource();
            if ( pResource )
            {
                SString strFilename;
                bool bIsURL = false;
                if ( CResourceManager::ParseResourcePathInput( strSound, pResource, strFilename ) )
                    strSound = strFilename;
                else
                    bIsURL = true;

                // ParseResourcePathInput changes pResource in some cases e.g. an invalid resource URL - crun playSound( ":myNotRunningResource/music/track.mp3" )
                // Fixes #6507 - Caz
                if ( pResource )
                {
                    bool bLoop = false;
                    if ( argStream.NextIsBool ( ) )
                    {
                        argStream.ReadBool ( bLoop );
                    }

                    CClientSound* pSound = CStaticFunctionDefinitions::PlaySound3D ( pResource, strSound, bIsURL, vecPosition, bLoop );
                    if ( pSound )
                    {
                        // call onClientSoundStarted
                        CLuaArguments Arguments;
                        Arguments.PushString ( "play" );     // Reason
                        pSound->CallEvent ( "onClientSoundStarted", Arguments, false );

                        lua_pushelement ( luaVM, pSound );
                        return 1;
                    }
                }
            }
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    lua_pushboolean ( luaVM, false );
    return 1;
}
void CClientSoundManager::DoPulse ( void )
{
    UpdateVolume ();

    CClientCamera* pCamera = m_pClientManager->GetCamera();

    CVector vecCameraPosition, vecPosition, vecLookAt, vecFront, vecVelocity;
    pCamera->GetPosition ( vecCameraPosition );
    pCamera->GetFixedTarget ( vecLookAt );
    vecFront = vecLookAt - vecCameraPosition;

    CClientPlayer* p_LocalPlayer = m_pClientManager->GetPlayerManager()->GetLocalPlayer();
    if ( p_LocalPlayer )
    {
        p_LocalPlayer->GetMoveSpeed( vecVelocity );

        if ( pCamera->IsInFixedMode() )
            vecPosition = vecCameraPosition;
        else
            p_LocalPlayer->GetPosition( vecPosition );

    }
    else
    {
        // Make sure the players position at least has something (I'd be surprised if we get here though)
        vecPosition = vecCameraPosition;
    }

    // Update volume position and velocity from all sounds
    list < CClientSound* > ::iterator iter = m_Sounds.begin ();
    for ( ; iter != m_Sounds.end () ; ++iter )
    {
        CClientSound* pSound = *iter;
        pSound->Process3D ( vecPosition, vecCameraPosition, vecLookAt );

        // Delete sound if finished
        if ( pSound->IsFinished () )
        {
            // call onClientSoundStopped
            CLuaArguments Arguments;
            Arguments.PushString ( "finished" );     // Reason
            pSound->CallEvent ( "onClientSoundStopped", Arguments, false );
            g_pClientGame->GetElementDeleter()->Delete ( pSound );
        }
    }
    UpdateDistanceStreaming ( vecPosition );
}