resolve the serious delay of play effect
This commit is contained in:
natural-law 2010-10-12 07:55:56 +00:00
parent 2a43160d39
commit 6c1d28acb4
7 changed files with 52 additions and 10 deletions

View File

@ -63,7 +63,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="WS2_32.Lib ..\..\PRJ_TG3\Common\SoftSupport\EosConfig.lib ..\..\PRJ_TG3\Common\SoftSupport\SoftSupport.lib ..\..\PRJ_TG3\Common\SoftSupport\TG3_DLL.lib"
AdditionalDependencies="WS2_32.Lib ..\..\PRJ_TG3\Common\SoftSupport\EosConfig.lib ..\..\PRJ_TG3\Common\SoftSupport\SoftSupport.lib ..\..\PRJ_TG3\Common\SoftSupport\TG3_DLL.lib libcocos2d.lib libCocosDenishion.lib"
OutputFile="$(OutDir)/Cocos2dSimpleGame.dll"
LinkIncremental="2"
AdditionalLibraryDirectories="../../PRJ_TG3/Common/ICU/lib;../../PRJ_TG3/Mtapi/Win32/lib;../../PRJ_TG3/LIB/Win32Lib;../../PRJ_TG3/Common/SoftSupport"

View File

@ -1 +1 @@
a80876d06382ec05f8d42ea3724d4273c31614bd
f35a3780499b097bc387ffcdb69162536c13decf

View File

@ -5,7 +5,7 @@
#include "Cocos2dSimpleGameAppDelegate.h"
#include "Framework\cocos2dsimplegame_res_c.h"
#include "cocos2dsimplegame_res_c.h"
const ResourceRegisterEntry ResRegList_Cocos2dSimpleGame[] =
{

View File

@ -42,7 +42,7 @@
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\PRJ_TG3\Include;..\..\PRJ_TG3\Include\MTAPI;..\..\PRJ_TG3\Include\TCOM;..\..\PRJ_TG3\Common\SoftSupport;..\..\PRJ_TG3\Common\ICU\Include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;COCOSDENSHION_EXPORTS;_TRANZDA_VM_;_EXPORT_DLL_"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;COCOSDENSHION_EXPORTS;_TRANZDA_VM_;_EXPORT_DLL_;_ENABLE_PROFILE_"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"

View File

@ -7,6 +7,7 @@ SoundPlayer::SoundPlayer()
, m_pMediaFile(NULL)
, m_bPaused(FALSE)
, m_MethodEmun(NULL)
, m_nCurrentSoundID(0)
{
// TCOM初始化使用TCOM组件前必须先初始化
TCoInitialize(NULL);
@ -197,3 +198,13 @@ Int32 SoundPlayer::DecodeFile(void* buffer, Int32 bufferLen, const char* pszFile
return nRet;
}
void SoundPlayer::SetCurrentSoundID(Int32 nSoundID)
{
m_nCurrentSoundID = nSoundID;
}
Int32 SoundPlayer::GetCurrentSoundID()
{
return m_nCurrentSoundID;
}

View File

@ -79,6 +79,18 @@ public:
*/
Int32 GetFileBufferSize(const char* pszFilePath);
/**
@brief ID
@param nSoundID ID
*/
void SetCurrentSoundID(Int32 nSoundID);
/**
@brief ID
@return ID
*/
Int32 GetCurrentSoundID();
private:
Boolean OpenAudioFile(const char* pszFilePath);
@ -91,6 +103,7 @@ private:
TCOM_MethodEmun m_MethodEmun; // 查找方法
TUChar m_fileName[MAX_PATH];
Int32 m_nCurrentSoundID;
};
#endif

View File

@ -23,7 +23,6 @@ SimpleAudioEngine::SimpleAudioEngine()
, m_bWillPlayBackgroundMusic(false)
, m_pEffects(NULL)
{
//m_pEffectPlayers->resize(0);
m_pEffectPlayers = new PlayerArray();
}
@ -219,7 +218,12 @@ void SimpleAudioEngine::playPreloadedEffect(int nSoundId)
BREAK_IF(!pElement);
SoundPlayer* pPlayer = pElement->pPlayer;
if (!pPlayer)
if (pPlayer && !pPlayer->IsPlaying())
{
// there has a player loaded the effect
pPlayer->Rewind();
}
else
{
// find the not playing player in m_pEffectPlayers
PlayerArrayIterator iter;
@ -228,6 +232,19 @@ void SimpleAudioEngine::playPreloadedEffect(int nSoundId)
if ((*iter) && !(*iter)->IsPlaying())
{
pPlayer = (*iter);
// Detach from the SoundID before
int nCurrentID = pPlayer->GetCurrentSoundID();
if (nCurrentID)
{
tHashElement* pTempElement = NULL;
HASH_FIND_INT(m_pEffects, &nCurrentID, pTempElement);
if (pTempElement)
{
pTempElement->pPlayer = NULL;
}
}
break;
}
}
@ -241,11 +258,12 @@ void SimpleAudioEngine::playPreloadedEffect(int nSoundId)
// set the player volume
pPlayer->SetVolumeValue(m_nEffectsVolume);
}
}
// play the sound and record the player
pPlayer->PlaySoundFromMem(pElement->pDataBuffer, pElement->nDataSize);
pElement->pPlayer = pPlayer;
// play the sound and record the player
pPlayer->PlaySoundFromMem(pElement->pDataBuffer, pElement->nDataSize);
pElement->pPlayer = pPlayer;
pPlayer->SetCurrentSoundID(nSoundId);
}
} while (0);
}