Skip to content

Add sound throttling from ID 0008814 #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7282,17 +7282,17 @@ CClientEffect* CStaticFunctionDefinitions::CreateEffect(CResource& Resource, con
}


CClientSound* CStaticFunctionDefinitions::PlaySound ( CResource* pResource, const SString& strSound, bool bIsURL, bool bLoop )
CClientSound* CStaticFunctionDefinitions::PlaySound ( CResource* pResource, const SString& strSound, bool bIsURL, bool bLoop, bool bThrottle )
{
CClientSound* pSound = m_pSoundManager->PlaySound2D ( strSound, bIsURL, bLoop );
CClientSound* pSound = m_pSoundManager->PlaySound2D ( strSound, bIsURL, bLoop, bThrottle );
if ( pSound ) pSound->SetParent ( pResource->GetResourceDynamicEntity() );
return pSound;
}


CClientSound* CStaticFunctionDefinitions::PlaySound3D ( CResource* pResource, const SString& strSound, bool bIsURL, const CVector& vecPosition, bool bLoop )
CClientSound* CStaticFunctionDefinitions::PlaySound3D ( CResource* pResource, const SString& strSound, bool bIsURL, const CVector& vecPosition, bool bLoop, bool bThrottle )
{
CClientSound* pSound = m_pSoundManager->PlaySound3D ( strSound, bIsURL, vecPosition, bLoop );
CClientSound* pSound = m_pSoundManager->PlaySound3D ( strSound, bIsURL, vecPosition, bLoop, bThrottle );
if ( pSound ) pSound->SetParent ( pResource->GetResourceDynamicEntity() );
return pSound;
}
Expand Down
4 changes: 2 additions & 2 deletions MTA10/mods/deathmatch/logic/CStaticFunctionDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,8 @@ class CStaticFunctionDefinitions
static CClientEffect* CreateEffect ( CResource& Resource, const SString& strFxName, const CVector& vecPosition );

// Sound funcs
static CClientSound* PlaySound ( CResource* pResource, const SString& strSound, bool bIsURL, bool bLoop );
static CClientSound* PlaySound3D ( CResource* pResource, const SString& strSound, bool bIsURL, const CVector& vecPosition, bool bLoop );
static CClientSound* PlaySound ( CResource* pResource, const SString& strSound, bool bIsURL, bool bLoop, bool bThrottle );
static CClientSound* PlaySound3D ( CResource* pResource, const SString& strSound, bool bIsURL, const CVector& vecPosition, bool bLoop, bool bThrottle );
static bool StopSound ( CClientSound& Sound );
static bool SetSoundPosition ( CClientSound& Sound, double dPosition );
static bool GetSoundPosition ( CClientSound& Sound, double& dPosition );
Expand Down
8 changes: 6 additions & 2 deletions MTA10/mods/shared_logic/CBassAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ namespace
}


CBassAudio::CBassAudio ( bool bStream, const SString& strPath, bool bLoop, bool b3D )
CBassAudio::CBassAudio ( bool bStream, const SString& strPath, bool bLoop, bool bThrottle, bool b3D )
: m_bStream ( bStream )
, m_strPath ( strPath )
, m_bLoop ( bLoop )
, m_bThrottle ( bThrottle )
, m_b3D ( b3D )
{
m_fVolume = 1.0f;
Expand All @@ -85,7 +86,7 @@ CBassAudio::CBassAudio ( bool bStream, const SString& strPath, bool bLoop, bool
}


CBassAudio::CBassAudio ( void* pBuffer, unsigned int uiBufferLength, bool bLoop, bool b3D ) : m_bStream ( false ), m_pBuffer ( pBuffer ), m_uiBufferLength ( uiBufferLength ), m_bLoop ( bLoop ), m_b3D ( b3D )
CBassAudio::CBassAudio ( void* pBuffer, unsigned int uiBufferLength, bool bLoop, bool b3D ) : m_bStream ( false ), m_pBuffer ( pBuffer ), m_uiBufferLength ( uiBufferLength ), m_bLoop ( bLoop ), m_bThrottle( false), m_b3D ( b3D )
{
m_fVolume = 1.0f;
m_fDefaultFrequency = 44100.0f;
Expand Down Expand Up @@ -150,6 +151,9 @@ bool CBassAudio::BeginLoadingMedia ( void )
if ( m_bLoop )
lFlags |= BASS_SAMPLE_LOOP;

if ( m_bThrottle )
lFlags |= BASS_STREAM_RESTRATE;

if ( m_bStream )
{
//
Expand Down
3 changes: 2 additions & 1 deletion MTA10/mods/shared_logic/CBassAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class CBassAudio
{
public:
ZERO_ON_NEW
CBassAudio ( bool bStream, const SString& strPath, bool bLoop, bool b3D );
CBassAudio ( bool bStream, const SString& strPath, bool bLoop, bool bThrottle, bool b3D );
CBassAudio ( void* pBuffer, unsigned int uiBufferLength, bool bLoop, bool b3D );
~CBassAudio ( void );
void Destroy ( void );
Expand Down Expand Up @@ -107,6 +107,7 @@ class CBassAudio
const SString m_strPath;
const bool m_b3D;
const bool m_bLoop;
const bool m_bThrottle;
void* m_pBuffer;
unsigned int m_uiBufferLength;

Expand Down
5 changes: 3 additions & 2 deletions MTA10/mods/shared_logic/CClientSound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ bool CClientSound::Create ( void )

// Initial state
if ( !m_pBuffer )
m_pAudio = new CBassAudio ( m_bStream, m_strPath, m_bLoop, m_b3D );
m_pAudio = new CBassAudio ( m_bStream, m_strPath, m_bLoop, m_bThrottle, m_b3D );
else
m_pAudio = new CBassAudio ( m_pBuffer, m_uiBufferLength, m_bLoop, m_b3D );

Expand Down Expand Up @@ -286,14 +286,15 @@ bool CClientSound::Play3D ( void* pMemory, unsigned int uiLength, bool bLoop )
}


void CClientSound::PlayStream ( const SString& strURL, bool bLoop, bool b3D )
void CClientSound::PlayStream ( const SString& strURL, bool bLoop, bool bThrottle, bool b3D )
{
assert ( m_strPath.empty () );

m_bStream = true;
m_b3D = b3D;
m_strPath = strURL;
m_bLoop = bLoop;
m_bThrottle = bThrottle;

// Instant distance-stream in if not 3D
if ( !m_b3D )
Expand Down
3 changes: 2 additions & 1 deletion MTA10/mods/shared_logic/CClientSound.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CClientSound : public CClientEntity
bool Play ( void* pMemory, unsigned int uiLength, bool bLoop );
bool Play3D ( const SString& strPath, bool bLoop );
bool Play3D ( void* pMemory, unsigned int uiLength, bool bLoop );
void PlayStream ( const SString& strURL, bool bLoop, bool b3D = false );
void PlayStream ( const SString& strURL, bool bLoop, bool bThrottle, bool b3D = false );

void SetPaused ( bool bPaused );
bool IsPaused ( void );
Expand Down Expand Up @@ -111,6 +111,7 @@ class CClientSound : public CClientEntity
bool m_b3D;
SString m_strPath;
bool m_bLoop;
bool m_bThrottle;
void* m_pBuffer;
unsigned int m_uiBufferLength;

Expand Down
8 changes: 4 additions & 4 deletions MTA10/mods/shared_logic/CClientSoundManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ void CClientSoundManager::SetDimension ( unsigned short usDimension )
m_usDimension = usDimension;
}

CClientSound* CClientSoundManager::PlaySound2D ( const SString& strSound, bool bIsURL, bool bLoop )
CClientSound* CClientSoundManager::PlaySound2D ( const SString& strSound, bool bIsURL, bool bLoop, bool bThrottle )
{
CClientSound* pSound = new CClientSound ( m_pClientManager, INVALID_ELEMENT_ID );
if ( bIsURL )
{
pSound->PlayStream ( strSound, bLoop );
pSound->PlayStream ( strSound, bLoop, bThrottle );
return pSound;
}
else
Expand All @@ -154,13 +154,13 @@ CClientSound* CClientSoundManager::PlaySound2D ( void* pMemory, unsigned int uiL
return NULL;
}

CClientSound* CClientSoundManager::PlaySound3D ( const SString& strSound, bool bIsURL, const CVector& vecPosition, bool bLoop )
CClientSound* CClientSoundManager::PlaySound3D ( const SString& strSound, bool bIsURL, const CVector& vecPosition, bool bLoop, bool bThrottle )
{
CClientSound* pSound = new CClientSound ( m_pClientManager, INVALID_ELEMENT_ID );

if ( bIsURL )
{
pSound->PlayStream ( strSound, bLoop, true );
pSound->PlayStream ( strSound, bLoop, bThrottle, true );
pSound->SetPosition ( vecPosition );
return pSound;
}
Expand Down
4 changes: 2 additions & 2 deletions MTA10/mods/shared_logic/CClientSoundManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class CClientSoundManager

void SetDimension ( unsigned short usDimension );

CClientSound* PlaySound2D ( const SString& strSound, bool bIsURL, bool bLoop );
CClientSound* PlaySound2D ( const SString& strSound, bool bIsURL, bool bLoop, bool bThrottle );
CClientSound* PlaySound2D ( void* pMemory, unsigned int uiLength, bool bLoop );
CClientSound* PlaySound3D ( const SString& strSound, bool bIsURL, const CVector& vecPosition, bool bLoop );
CClientSound* PlaySound3D ( const SString& strSound, bool bIsURL, const CVector& vecPosition, bool bLoop, bool bThrottle );
CClientSound* PlaySound3D ( void* pMemory, unsigned int uiLength, const CVector& vecPosition, bool bLoop );

CClientSound* PlayGTASFX ( eAudioLookupIndex containerIndex, int iBankIndex, int iAudioIndex, bool bLoop = false );
Expand Down
8 changes: 6 additions & 2 deletions MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ int CLuaFunctionDefs::PlaySound ( lua_State* luaVM )
{
SString strSound = "";
bool bLoop = false;
bool bThrottle = true;
CScriptArgReader argStream ( luaVM );
argStream.ReadString ( strSound );
argStream.ReadBool ( bLoop, false );
argStream.ReadBool ( bThrottle, true );

if ( !argStream.HasErrors() )
{
Expand All @@ -46,7 +48,7 @@ int CLuaFunctionDefs::PlaySound ( lua_State* luaVM )
// Fixes #6507 - Caz
if ( pResource )
{
CClientSound* pSound = CStaticFunctionDefinitions::PlaySound ( pResource, strSound, bIsURL, bLoop );
CClientSound* pSound = CStaticFunctionDefinitions::PlaySound ( pResource, strSound, bIsURL, bLoop, bThrottle );
if ( pSound )
{
// call onClientSoundStarted
Expand Down Expand Up @@ -74,10 +76,12 @@ int CLuaFunctionDefs::PlaySound3D ( lua_State* luaVM )
SString strSound = "";
CVector vecPosition;
bool bLoop = false;
bool bThrottle = false;
CScriptArgReader argStream ( luaVM );
argStream.ReadString ( strSound );
argStream.ReadVector3D ( vecPosition );
argStream.ReadBool ( bLoop, false );
argStream.ReadBool ( bThrottle, true );

if ( !argStream.HasErrors() )
{
Expand All @@ -98,7 +102,7 @@ int CLuaFunctionDefs::PlaySound3D ( lua_State* luaVM )
// Fixes #6507 - Caz
if ( pResource )
{
CClientSound* pSound = CStaticFunctionDefinitions::PlaySound3D ( pResource, strSound, bIsURL, vecPosition, bLoop );
CClientSound* pSound = CStaticFunctionDefinitions::PlaySound3D ( pResource, strSound, bIsURL, vecPosition, bLoop, bThrottle );
if ( pSound )
{
// call onClientSoundStarted
Expand Down