From 37915cfed6e5fa2a0b3ce44a3d4cc69b172b9a13 Mon Sep 17 00:00:00 2001 From: minggo Date: Wed, 28 Dec 2011 14:46:49 +0800 Subject: [PATCH 01/12] remove unneeded function, and make protocol an abstract class --- cocos2dx/include/CCAtlasNode.h | 2 -- cocos2dx/include/CCLabelBMFont.h | 3 +-- cocos2dx/include/CCLayer.h | 3 ++- cocos2dx/include/CCMenu.h | 3 ++- cocos2dx/include/CCMenuItem.h | 9 ++++++--- cocos2dx/include/CCObject.h | 4 ++-- cocos2dx/include/CCProtocols.h | 6 +++--- cocos2dx/include/CCSprite.h | 2 -- cocos2dx/platform/CCPlatformMacros.h | 8 ++++---- 9 files changed, 20 insertions(+), 20 deletions(-) diff --git a/cocos2dx/include/CCAtlasNode.h b/cocos2dx/include/CCAtlasNode.h index 3f6982d637..aca04144cf 100755 --- a/cocos2dx/include/CCAtlasNode.h +++ b/cocos2dx/include/CCAtlasNode.h @@ -88,8 +88,6 @@ public: virtual void draw(); - virtual CCRGBAProtocol* convertToRGBAProtocol() { return (CCRGBAProtocol*)this; } - // CC Texture protocol /** returns the used texture*/ diff --git a/cocos2dx/include/CCLabelBMFont.h b/cocos2dx/include/CCLabelBMFont.h index 847a825324..9e730de79a 100755 --- a/cocos2dx/include/CCLabelBMFont.h +++ b/cocos2dx/include/CCLabelBMFont.h @@ -180,8 +180,7 @@ namespace cocos2d{ virtual const char* getString(void); virtual void setCString(const char *label); virtual void setAnchorPoint(const CCPoint& var); - virtual CCRGBAProtocol* convertToRGBAProtocol() { return (CCRGBAProtocol*)this; } - virtual CCLabelProtocol* convertToLabelProtocol() { return (CCLabelProtocol*)this; } + #if CC_LABELBMFONT_DEBUG_DRAW virtual void draw(); #endif // CC_LABELBMFONT_DEBUG_DRAW diff --git a/cocos2dx/include/CCLayer.h b/cocos2dx/include/CCLayer.h index 5adcaf0028..7b01f2d77b 100755 --- a/cocos2dx/include/CCLayer.h +++ b/cocos2dx/include/CCLayer.h @@ -182,7 +182,8 @@ public: /** BlendFunction. Conforms to CCBlendProtocol protocol */ CC_PROPERTY(ccBlendFunc, m_tBlendFunc, BlendFunc) - virtual CCRGBAProtocol* convertToRGBAProtocol() { return (CCRGBAProtocol*)this; } + virtual void setIsOpacityModifyRGB(bool bValue) {CC_UNUSED_PARAM(bValue);} + virtual bool getIsOpacityModifyRGB(void) { return false;} LAYER_NODE_FUNC(CCLayerColor); protected: diff --git a/cocos2dx/include/CCMenu.h b/cocos2dx/include/CCMenu.h index ddb0104301..c1b2ba6bea 100755 --- a/cocos2dx/include/CCMenu.h +++ b/cocos2dx/include/CCMenu.h @@ -118,7 +118,8 @@ namespace cocos2d{ */ virtual void onExit(); - virtual CCRGBAProtocol* convertToRGBAProtocol() { return (CCRGBAProtocol*)this; } + virtual void setIsOpacityModifyRGB(bool bValue) {CC_UNUSED_PARAM(bValue);} + virtual bool getIsOpacityModifyRGB(void) { return false;} protected: CCMenuItem* itemForTouch(CCTouch * touch); diff --git a/cocos2dx/include/CCMenuItem.h b/cocos2dx/include/CCMenuItem.h index 5842afabd5..20d558ce35 100755 --- a/cocos2dx/include/CCMenuItem.h +++ b/cocos2dx/include/CCMenuItem.h @@ -124,7 +124,8 @@ namespace cocos2d{ virtual void setColor(const ccColor3B& color); virtual const ccColor3B& getColor(); - virtual CCRGBAProtocol* convertToRGBAProtocol() { return (CCRGBAProtocol*)this; } + virtual void setIsOpacityModifyRGB(bool bValue) {CC_UNUSED_PARAM(bValue);} + virtual bool getIsOpacityModifyRGB(void) { return false;} protected: ccColor3B m_tColorBackup; float m_fOriginalScale; @@ -236,7 +237,8 @@ namespace cocos2d{ virtual void unselected(); virtual void setIsEnabled(bool bEnabled); - virtual CCRGBAProtocol* convertToRGBAProtocol() { return (CCRGBAProtocol*)this; } + virtual void setIsOpacityModifyRGB(bool bValue) {CC_UNUSED_PARAM(bValue);} + virtual bool getIsOpacityModifyRGB(void) { return false;} }; /** @brief CCMenuItemImage accepts images as items. @@ -308,7 +310,8 @@ namespace cocos2d{ virtual void unselected(); virtual void setIsEnabled(bool var); - virtual CCRGBAProtocol* convertToRGBAProtocol() { return (CCRGBAProtocol*)this; } + virtual void setIsOpacityModifyRGB(bool bValue) {CC_UNUSED_PARAM(bValue);} + virtual bool getIsOpacityModifyRGB(void) { return false;} }; } diff --git a/cocos2dx/include/CCObject.h b/cocos2dx/include/CCObject.h index 9029c57992..15d7fc3b35 100755 --- a/cocos2dx/include/CCObject.h +++ b/cocos2dx/include/CCObject.h @@ -52,8 +52,8 @@ public: CCObject(void); virtual ~CCObject(void); - virtual void release(void); - virtual void retain(void); + void release(void); + void retain(void); CCObject* autorelease(void); CCObject* copy(void); bool isSingleRefrence(void); diff --git a/cocos2dx/include/CCProtocols.h b/cocos2dx/include/CCProtocols.h index 4a8aa0d4db..742b7efaf1 100755 --- a/cocos2dx/include/CCProtocols.h +++ b/cocos2dx/include/CCProtocols.h @@ -63,12 +63,12 @@ public: Textures with premultiplied alpha will have this property by default on YES. Otherwise the default value is NO @since v0.8 */ - virtual void setIsOpacityModifyRGB(bool bValue) {CC_UNUSED_PARAM(bValue);} + virtual void setIsOpacityModifyRGB(bool bValue) = 0; /** returns whether or not the opacity will be applied using glColor(R,G,B,opacity) or glColor(opacity, opacity, opacity, opacity); @since v0.8 */ - virtual bool getIsOpacityModifyRGB(void) { return false;} + virtual bool getIsOpacityModifyRGB(void) = 0; }; /** @@ -101,7 +101,7 @@ public: virtual CCTexture2D* getTexture(void) = 0; // sets a new texture. it will be retained - virtual void setTexture(CCTexture2D *texture) {CC_UNUSED_PARAM(texture);} + virtual void setTexture(CCTexture2D *texture) = 0; }; //! @brief Common interface for Labels diff --git a/cocos2dx/include/CCSprite.h b/cocos2dx/include/CCSprite.h index 33cb714c85..249084d040 100755 --- a/cocos2dx/include/CCSprite.h +++ b/cocos2dx/include/CCSprite.h @@ -246,8 +246,6 @@ public: virtual void setIsOpacityModifyRGB(bool bValue); virtual bool getIsOpacityModifyRGB(void); - virtual CCRGBAProtocol* convertToRGBAProtocol() { return (CCRGBAProtocol *)this; } - // CCTextureProtocol virtual void setTexture(CCTexture2D *texture); virtual CCTexture2D* getTexture(void); diff --git a/cocos2dx/platform/CCPlatformMacros.h b/cocos2dx/platform/CCPlatformMacros.h index 580caf51d8..81c34faf91 100644 --- a/cocos2dx/platform/CCPlatformMacros.h +++ b/cocos2dx/platform/CCPlatformMacros.h @@ -82,13 +82,13 @@ public: virtual const varType& get##funName(void); */ #define CC_PROPERTY(varType, varName, funName)\ protected: varType varName;\ -public: virtual varType get##funName(void);\ -public: virtual void set##funName(varType var); +public: varType get##funName(void);\ +public: void set##funName(varType var); #define CC_PROPERTY_PASS_BY_REF(varType, varName, funName)\ protected: varType varName;\ -public: virtual const varType& get##funName(void);\ -public: virtual void set##funName(const varType& var); +public: const varType& get##funName(void);\ +public: void set##funName(const varType& var); /** CC_SYNTHESIZE_READONLY is used to declare a protected variable. We can use getter to read the variable. From fcb2294e20332a7995625a7854c3c0f1a7d98798 Mon Sep 17 00:00:00 2001 From: minggo Date: Wed, 28 Dec 2011 14:47:54 +0800 Subject: [PATCH 02/12] fixed #926: subclass should retain/release when dynamic_cast fail. --- cocos2dx/include/CCTouchDelegateProtocol.h | 11 +++++ cocos2dx/touch_dispatcher/CCTouchHandler.cpp | 52 ++++++++++++++++++-- 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/cocos2dx/include/CCTouchDelegateProtocol.h b/cocos2dx/include/CCTouchDelegateProtocol.h index 6754d610b8..bc6de80643 100755 --- a/cocos2dx/include/CCTouchDelegateProtocol.h +++ b/cocos2dx/include/CCTouchDelegateProtocol.h @@ -66,6 +66,17 @@ public: virtual void ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent) {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);} virtual void ccTouchesCancelled(CCSet *pTouches, CCEvent *pEvent) {CC_UNUSED_PARAM(pTouches); CC_UNUSED_PARAM(pEvent);} + /* + * In TouchesTest, class Padle inherits from CCSprite and CCTargetedTouchDelegate. + * When it invoke CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, true), + * it will crash in CCTouchHandler::initWithDelegate() because of dynamic_cast() on android. + * I don't know why, so add these functions for the subclass to invoke it's know retain() and + * release(). + * More detain info please refer issue #926(cocos2d-x). + */ + virtual void touchDelegateRetain(){} + virtual void touchDelegateRelease(){} + // functions for script call back inline void registerScriptTouchHandler(int eventType, const char* pszScriptFunctionName) { diff --git a/cocos2dx/touch_dispatcher/CCTouchHandler.cpp b/cocos2dx/touch_dispatcher/CCTouchHandler.cpp index ccbe0f4f22..23c94617a0 100644 --- a/cocos2dx/touch_dispatcher/CCTouchHandler.cpp +++ b/cocos2dx/touch_dispatcher/CCTouchHandler.cpp @@ -35,14 +35,34 @@ CCTouchDelegate* CCTouchHandler::getDelegate(void) void CCTouchHandler::setDelegate(CCTouchDelegate *pDelegate) { + /* + * RTTI may return null on android. More info please refer issue #926(cocos2d-x) + */ if (pDelegate) { - (dynamic_cast(pDelegate))->retain(); + if (dynamic_cast(pDelegate)) + { + dynamic_cast(pDelegate)->retain(); + } + else + { + pDelegate->touchDelegateRetain(); + } } + /* + * RTTI may return null on android. More info please refer issue #926(cocos2d-x) + */ if (m_pDelegate) { - (dynamic_cast(m_pDelegate))->release(); + if (dynamic_cast(m_pDelegate)) + { + dynamic_cast(m_pDelegate)->release(); + } + else + { + m_pDelegate->touchDelegateRelease(); + } } m_pDelegate = pDelegate; } @@ -90,7 +110,21 @@ bool CCTouchHandler::initWithDelegate(CCTouchDelegate *pDelegate, int nPriority) { CCAssert(pDelegate != NULL, "touch delegate should not be null"); - m_pDelegate = pDelegate; (dynamic_cast(pDelegate))->retain(); + m_pDelegate = pDelegate; + + + /* + * RTTI may return null on android. More info please refer issue #926(cocos2d-x) + */ + if (dynamic_cast(pDelegate)) + { + dynamic_cast(pDelegate)->retain(); + } + else + { + pDelegate->touchDelegateRetain(); + } + m_nPriority = nPriority; m_nEnabledSelectors = 0; @@ -101,7 +135,17 @@ CCTouchHandler::~CCTouchHandler(void) { if (m_pDelegate) { - (dynamic_cast(m_pDelegate))->release();; + /* + * RTTI may return null on android. More info please refer issue #926(cocos2d-x) + */ + if (dynamic_cast(m_pDelegate)) + { + dynamic_cast(m_pDelegate)->release(); + } + else + { + m_pDelegate->touchDelegateRelease(); + } } } From 08e0be754b87cf051df7483e6f7c0b18e8439808 Mon Sep 17 00:00:00 2001 From: minggo Date: Wed, 28 Dec 2011 15:13:02 +0800 Subject: [PATCH 03/12] fixed #926: retain/release in Paddle --- tests/tests/TouchesTest/Paddle.cpp | 12 +++++++++++- tests/tests/TouchesTest/Paddle.h | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/tests/TouchesTest/Paddle.cpp b/tests/tests/TouchesTest/Paddle.cpp index a6e8d312dd..b5a7532cc2 100644 --- a/tests/tests/TouchesTest/Paddle.cpp +++ b/tests/tests/TouchesTest/Paddle.cpp @@ -81,4 +81,14 @@ void Paddle::ccTouchEnded(CCTouch* touch, CCEvent* event) CCAssert(m_state == kPaddleStateGrabbed, L"Paddle - Unexpected state!"); m_state = kPaddleStateUngrabbed; -} \ No newline at end of file +} + +void Paddle::touchDelegateRetain() +{ + this->retain(); +} + +void Paddle::touchDelegateRelease() +{ + this->release(); +} \ No newline at end of file diff --git a/tests/tests/TouchesTest/Paddle.h b/tests/tests/TouchesTest/Paddle.h index ac9b5fb3a4..0a6e6b051b 100644 --- a/tests/tests/TouchesTest/Paddle.h +++ b/tests/tests/TouchesTest/Paddle.h @@ -27,6 +27,9 @@ public: virtual bool ccTouchBegan(CCTouch* touch, CCEvent* event); virtual void ccTouchMoved(CCTouch* touch, CCEvent* event); virtual void ccTouchEnded(CCTouch* touch, CCEvent* event); + + virtual void touchDelegateRetain(); + virtual void touchDelegateRelease(); static Paddle* paddleWithTexture(CCTexture2D* aTexture); }; From 5c04551567e14f0fc3d86422d0d6e731c4e16484 Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 29 Dec 2011 10:39:46 +0800 Subject: [PATCH 04/12] fixed #910: when create new android project, not delete existing directory --- create-android-project.bat | 3 ++- create-android-project.sh | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/create-android-project.bat b/create-android-project.bat index 184efd4079..6302474da5 100644 --- a/create-android-project.bat +++ b/create-android-project.bat @@ -23,8 +23,9 @@ set _NDKROOT=d:\programe\android\ndk\android-ndk-r6b if not exist "%_NDKROOT%" echo Couldn't find ndk at "%_NDKROOT%" & pause & exit 6 :: create android project -set /P _PACKAGEPATH=Please enter your package path: +set /P _PACKAGEPATH=Please enter your package path. For example: org.cocos2dx.example: set /P _PROJECTNAME=Please enter your project name: +if exist "%CD%\%_PROJECTNAME%" echo "%_PROJECTNAME%" exists, please use another name & pause & exit 7 echo "Now cocos2d-x suppurts Android 2.1-update1, 2.2, 2.3 & 3.0" echo "Other versions have not tested." call "%_ANDROIDTOOLS%\android.bat" list targets diff --git a/create-android-project.sh b/create-android-project.sh index ac03a51590..5f401ff1ad 100755 --- a/create-android-project.sh +++ b/create-android-project.sh @@ -59,6 +59,12 @@ create_android_project(){ echo "input your project name:" read PROJECT_NAME PROJECT_DIR=`pwd`/$PROJECT_NAME + + # check if PROJECT_DIR is exist + if [ -d $PROJECT_DIR ]; then + echo "$PROJECT_DIR is exist, please use another name" + exit + fi $ANDROID_SDK_ROOT_LOCAL/tools/android create project -n $PROJECT_NAME -t $TARGET_ID -k $PACKAGE_PATH -a $PROJECT_NAME -p $PROJECT_DIR } From d6c18ab71c5b741157abd41ade048e0fa1a5ea44 Mon Sep 17 00:00:00 2001 From: dumganhar Date: Thu, 29 Dec 2011 14:54:18 +0800 Subject: [PATCH 05/12] fixed #927: unloadEffect called after stopEffect will cause crash --- CocosDenshion/bada/SimpleAudioEngine.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/CocosDenshion/bada/SimpleAudioEngine.cpp b/CocosDenshion/bada/SimpleAudioEngine.cpp index f222cedb26..9afdc487d4 100644 --- a/CocosDenshion/bada/SimpleAudioEngine.cpp +++ b/CocosDenshion/bada/SimpleAudioEngine.cpp @@ -552,9 +552,14 @@ void SimpleAudioEngine::preloadEffect(const char* pszFilePath) void SimpleAudioEngine::unloadEffect(const char* pszFilePath) { string strFilePath = fullPathFromRelativePath(pszFilePath); - unsigned int nSoundId = _Hash(strFilePath.c_str()); - CCAudioOut*& pPlayer = s_List[nSoundId]; - pPlayer->Stop(); + unsigned int nID = _Hash(strFilePath.c_str()); + EffectList::iterator p = s_List.find(nID); + if (p != s_List.end()) + { + delete p->second; + p->second = NULL; + s_List.erase(nID); + } } } // end of namespace CocosDenshion From 025258d21dc74c591100d81101cf6484ae007544 Mon Sep 17 00:00:00 2001 From: dumganhar Date: Thu, 29 Dec 2011 15:05:38 +0800 Subject: [PATCH 06/12] fixed #928: save pixelformat for each texture, restore the pixelformat after entering foreground --- cocos2dx/textures/CCTextureCache.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cocos2dx/textures/CCTextureCache.cpp b/cocos2dx/textures/CCTextureCache.cpp index 46d6e12047..5dacfd0c70 100644 --- a/cocos2dx/textures/CCTextureCache.cpp +++ b/cocos2dx/textures/CCTextureCache.cpp @@ -646,6 +646,7 @@ void VolatileTexture::addImageTexture(CCTexture2D *tt, const char* imageFileName vt->m_eCashedImageType = kImageFile; vt->m_strFileName = imageFileName; vt->m_FmtImage = format; + vt->m_PixelFormat = CCTexture2D::defaultAlphaPixelFormat(); } void VolatileTexture::addDataTexture(CCTexture2D *tt, void* data, CCTexture2DPixelFormat pixelFormat, const CCSize& contentSize) @@ -735,7 +736,10 @@ void VolatileTexture::reloadAllTextures() if (image.initWithImageData((void*)pBuffer, nSize, vt->m_FmtImage)) { + CCTexture2DPixelFormat oldPixelFormat = CCTexture2D::defaultAlphaPixelFormat(); + CCTexture2D::setDefaultAlphaPixelFormat(vt->m_PixelFormat); vt->texture->initWithImage(&image); + CCTexture2D::setDefaultAlphaPixelFormat(oldPixelFormat); } } break; From 20b625719825223b551c16aa21f872d38f52c777 Mon Sep 17 00:00:00 2001 From: dumganhar Date: Thu, 29 Dec 2011 16:00:36 +0800 Subject: [PATCH 07/12] fixed #928:change 'vt->m_PixelFormat = CCTexture2D::defaultAlphaPixelFormat();' to 'vt->m_PixelFormat = tt->getPixelFormat();' --- cocos2dx/textures/CCTextureCache.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2dx/textures/CCTextureCache.cpp b/cocos2dx/textures/CCTextureCache.cpp index 5dacfd0c70..a71f7bd31e 100644 --- a/cocos2dx/textures/CCTextureCache.cpp +++ b/cocos2dx/textures/CCTextureCache.cpp @@ -646,7 +646,7 @@ void VolatileTexture::addImageTexture(CCTexture2D *tt, const char* imageFileName vt->m_eCashedImageType = kImageFile; vt->m_strFileName = imageFileName; vt->m_FmtImage = format; - vt->m_PixelFormat = CCTexture2D::defaultAlphaPixelFormat(); + vt->m_PixelFormat = tt->getPixelFormat(); } void VolatileTexture::addDataTexture(CCTexture2D *tt, void* data, CCTexture2DPixelFormat pixelFormat, const CCSize& contentSize) From 53fae04ba8060033097c1901604779999bb64894 Mon Sep 17 00:00:00 2001 From: minggo Date: Fri, 30 Dec 2011 15:43:36 +0800 Subject: [PATCH 08/12] fixed #752: make add/remove touch delegate in menu callback function correctly --- cocos2dx/include/CCTouchDispatcher.h | 1 + .../touch_dispatcher/CCTouchDispatcher.cpp | 46 ++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/cocos2dx/include/CCTouchDispatcher.h b/cocos2dx/include/CCTouchDispatcher.h index db1a53bc4a..cdbc9088d7 100755 --- a/cocos2dx/include/CCTouchDispatcher.h +++ b/cocos2dx/include/CCTouchDispatcher.h @@ -149,6 +149,7 @@ protected: void forceAddHandler(CCTouchHandler *pHandler, CCMutableArray *pArray); void forceRemoveAllDelegates(void); void rearrangeHandlers(CCMutableArray *pArray); + CCTouchHandler* findHandler(CCMutableArray *pArray, CCTouchDelegate *pDelegate); protected: CCMutableArray *m_pTargetedHandlers; diff --git a/cocos2dx/touch_dispatcher/CCTouchDispatcher.cpp b/cocos2dx/touch_dispatcher/CCTouchDispatcher.cpp index 40063aed89..f2a8ec425d 100644 --- a/cocos2dx/touch_dispatcher/CCTouchDispatcher.cpp +++ b/cocos2dx/touch_dispatcher/CCTouchDispatcher.cpp @@ -148,6 +148,15 @@ void CCTouchDispatcher::addStandardDelegate(CCTouchDelegate *pDelegate, int nPri } else { + /* If pHandler is contained in m_pHandlersToRemove, if so remove it from m_pHandlersToRemove and retrun. + * Refer issue #752(cocos2d-x) + */ + if (ccCArrayContainsValue(m_pHandlersToRemove, pDelegate)) + { + ccCArrayRemoveValue(m_pHandlersToRemove, pDelegate); + return; + } + m_pHandlersToAdd->addObject(pHandler); m_bToAdd = true; } @@ -162,6 +171,15 @@ void CCTouchDispatcher::addTargetedDelegate(CCTouchDelegate *pDelegate, int nPri } else { + /* If pHandler is contained in m_pHandlersToRemove, if so remove it from m_pHandlersToRemove and retrun. + * Refer issue #752(cocos2d-x) + */ + if (ccCArrayContainsValue(m_pHandlersToRemove, pDelegate)) + { + ccCArrayRemoveValue(m_pHandlersToRemove, pDelegate); + return; + } + m_pHandlersToAdd->addObject(pHandler); m_bToAdd = true; } @@ -185,7 +203,6 @@ void CCTouchDispatcher::forceRemoveDelegate(CCTouchDelegate *pDelegate) } } - // remove handler from m_pTargetedHandlers for (iter = m_pTargetedHandlers->begin(); iter != m_pTargetedHandlers->end(); ++iter) { @@ -211,6 +228,16 @@ void CCTouchDispatcher::removeDelegate(CCTouchDelegate *pDelegate) } else { + /* If pHandler is contained in m_pHandlersToAdd, if so remove it from m_pHandlersToAdd and retrun. + * Refer issue #752(cocos2d-x) + */ + CCTouchHandler *pHandler = findHandler(m_pHandlersToAdd, pDelegate); + if (pHandler) + { + m_pHandlersToAdd->removeObject(pHandler); + return; + } + ccCArrayAppendValue(m_pHandlersToRemove, pDelegate); m_bToRemove = true; } @@ -257,6 +284,23 @@ CCTouchHandler* CCTouchDispatcher::findHandler(CCTouchDelegate *pDelegate) return NULL; } +CCTouchHandler* CCTouchDispatcher::findHandler(CCMutableArray *pArray, CCTouchDelegate *pDelegate) +{ + CCAssert(pArray != NULL && pDelegate != NULL); + + CCMutableArray::CCMutableArrayIterator iter; + + for (iter = pArray->begin(); iter != pArray->end(); ++iter) + { + if ((*iter)->getDelegate() == pDelegate) + { + return *iter; + } + } + + return NULL; +} + void CCTouchDispatcher::rearrangeHandlers(CCMutableArray *pArray) { std::sort(pArray->begin(), pArray->end(), less); From 8c65786dce714409d371494d5e0a16c07c21888c Mon Sep 17 00:00:00 2001 From: dumganhar Date: Sat, 31 Dec 2011 10:10:41 +0800 Subject: [PATCH 09/12] fixed #934: Add 'isEqual' function for CCString, make CCObject::isEqual to virtual function --- cocos2dx/include/CCObject.h | 2 +- cocos2dx/include/CCString.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cocos2dx/include/CCObject.h b/cocos2dx/include/CCObject.h index 15d7fc3b35..567fdca17f 100755 --- a/cocos2dx/include/CCObject.h +++ b/cocos2dx/include/CCObject.h @@ -58,7 +58,7 @@ public: CCObject* copy(void); bool isSingleRefrence(void); unsigned int retainCount(void); - bool isEqual(const CCObject* pObject); + virtual bool isEqual(const CCObject* pObject); friend class CCAutoreleasePool; }; diff --git a/cocos2dx/include/CCString.h b/cocos2dx/include/CCString.h index ff3a212583..5beed298f8 100755 --- a/cocos2dx/include/CCString.h +++ b/cocos2dx/include/CCString.h @@ -63,6 +63,20 @@ namespace cocos2d { { return m_sString.empty(); } + + virtual bool isEqual(const CCObject* pObject) + { + bool bRet = false; + const CCString* pStr = dynamic_cast(pObject); + if (pStr != NULL) + { + if (0 == m_sString.compare(pStr->m_sString)) + { + bRet = true; + } + } + return bRet; + } }; }// namespace cocos2d #endif //__CCSTRING_H__ \ No newline at end of file From 4010733c200f51a0cc11f068ff5459184c0753cf Mon Sep 17 00:00:00 2001 From: dumganhar Date: Sat, 31 Dec 2011 17:44:45 +0800 Subject: [PATCH 10/12] fixed #927: To use 'std::map::find' instead of 'std::map::[]', because '[]' will create a new element with default value. --- CocosDenshion/bada/CCAudioOut.cpp | 65 +-- CocosDenshion/bada/SimpleAudioEngine.cpp | 90 +++- CocosDenshion/bada/vorbis/vorbisfile.c | 22 +- chipmunk/proj.bada/sdk1.0/.cproject | 498 ++++++++++++++++++ .../touch_dispatcher/CCTouchDispatcher.cpp | 4 +- 5 files changed, 600 insertions(+), 79 deletions(-) diff --git a/CocosDenshion/bada/CCAudioOut.cpp b/CocosDenshion/bada/CCAudioOut.cpp index 6d775adcca..8fef5a485e 100644 --- a/CocosDenshion/bada/CCAudioOut.cpp +++ b/CocosDenshion/bada/CCAudioOut.cpp @@ -111,26 +111,24 @@ int CCAudioOut::DecodeOgg(const char *infile) int seekable = 0; int percent = 0; - //AppLog("enter, %s", infile); in = fopen(infile, "rb"); if(!in) { - //AppLog("ERROR: Failed to open input file:\n"); + AppLog("ERROR: Failed to open input file:\n"); return 1; } - //AppLog("enter"); + if(ov_open(in, &vf, NULL, 0) < 0) { - //AppLog("ERROR: Failed to open input as vorbis\n"); + AppLog("ERROR: Failed to open input as vorbis\n"); fclose(in); -// fclose(out); return 1; } - //AppLog("enter"); + if(ov_seekable(&vf)) { seekable = 1; length = ov_pcm_total(&vf, 0); size = 16/8 * ov_info(&vf, 0)->channels; } - //AppLog("enter"); + if (ov_info(&vf,0)->channels == 2) { __sampleChannelType = AUDIO_CHANNEL_TYPE_STEREO; @@ -139,19 +137,19 @@ int CCAudioOut::DecodeOgg(const char *infile) { __sampleChannelType = AUDIO_CHANNEL_TYPE_MONO; } - //AppLog("enter"); + __sampleRate = ov_info(&vf,0)->rate; __sampleBitdepth = AUDIO_TYPE_PCM_S16_LE; - //AppLog("enter"); + while((ret = ov_read(&vf, buf, buflen, 0, 16/8, 1, &bs)) != 0) { if(bs != 0) { - //AppLog("Only one logical bitstream currently supported\n"); + AppLog("Only one logical bitstream currently supported\n"); break; } if(ret < 0) { - //AppLog("Warning: hole in data\n"); + AppLog("Warning: hole in data\n"); continue; } @@ -178,25 +176,18 @@ int CCAudioOut::DecodeOgg(const char *infile) __iAllPcmBufferSize = written; -// if(seekable && !quiet) -// //AppLog("\n"); - -// if(!raw) -// rewrite_header(out, written); /* We don't care if it fails, too late */ - - //AppLog("enter"); ov_clear(&vf); fclose(in); -// fclose(out); + #endif - //AppLog("enter"); + return 0; } CCAudioOut::CCAudioOut() { - //AppLog("Enter"); + __volumeLevel = -1; __pAllPcmBuffer = null; __iAllPcmBufferSize = 0; @@ -214,7 +205,7 @@ CCAudioOut::CCAudioOut() CCAudioOut::~CCAudioOut() { - //AppLog("Enter"); + Finalize(); if(__pAudioOut) { @@ -231,7 +222,7 @@ CCAudioOut::~CCAudioOut() result CCAudioOut::Initialize(const char* pszFilePath) { - //AppLog("Enter"); + // This is called when AudioOut form is moving on the foreground. result r = E_SUCCESS; @@ -255,20 +246,20 @@ result CCAudioOut::Initialize(const char* pszFilePath) __pAudioOut = new AudioOut(); if (!__pAudioOut) { - //AppLog("[E_OUT_OF_MEMORY] m_pAudio new failed\n"); + AppLog("[E_OUT_OF_MEMORY] m_pAudio new failed\n"); return r; } r = __pAudioOut->Construct(*this); if (IsFailed(r)) { - //AppLog("[Error] m_AudioOut.Construct failed"); + AppLog("[Error] m_AudioOut.Construct failed"); return r; } } else { - //AppLog("[Error] __pAudioOut is already existed\n"); + AppLog("[Error] __pAudioOut is already existed\n"); } String strFile(pszFilePath); @@ -279,13 +270,13 @@ result CCAudioOut::Initialize(const char* pszFilePath) __pFile = new File(); if(!__pFile) { - //AppLog("[Error] __pFile new failed\n"); + AppLog("[Error] __pFile new failed\n"); return E_SYSTEM; } r = __pFile->Construct(pszFilePath, L"rb"); if (IsFailed(r)) { - //AppLog("[Error] __pFile.Construct failed : %d \n", r); + AppLog("[Error] __pFile.Construct failed : %d \n", r); return r; } @@ -328,7 +319,7 @@ result CCAudioOut::Initialize(const char* pszFilePath) } else { - //AppLog("not more memory..."); + AppLog("not more memory..."); } } else if (strFile.EndsWith(".ogg")) @@ -344,7 +335,7 @@ result CCAudioOut::Initialize(const char* pszFilePath) r = __pAudioOut->Prepare( __sampleBitdepth, __sampleChannelType, __sampleRate ); if (IsFailed(r)) { - //AppLog("[Error] m_AudioOut.Prepare failed"); + AppLog("[Error] m_AudioOut.Prepare failed"); return r; } @@ -356,7 +347,7 @@ result CCAudioOut::Initialize(const char* pszFilePath) r = __pAudioOut->SetVolume(DEFAULT_VOLUME_LEVEL); if (IsFailed(r)) { - //AppLog("[Error] m_AudioOut.SetVolume failed"); + AppLog("[Error] m_AudioOut.SetVolume failed"); return r; } @@ -366,25 +357,25 @@ result CCAudioOut::Initialize(const char* pszFilePath) r = __byteBuffer[0].Construct(__bufferSize); if (E_SUCCESS != r) { - //AppLog( "[Error] __byteBuffer[0].Construct failed..%d ",r); + AppLog( "[Error] __byteBuffer[0].Construct failed..%d ",r); return E_OUT_OF_MEMORY; } r = __byteBuffer[1].Construct(__bufferSize); if (E_SUCCESS != r) { - //AppLog( "[Error] __byteBuffer[1].Construct failed..%d ",r); + AppLog( "[Error] __byteBuffer[1].Construct failed..%d ",r); return E_OUT_OF_MEMORY; } r = __byteBuffer[2].Construct(__bufferSize); if (E_SUCCESS != r) { - //AppLog( "[Error] __byteBuffer[2].Construct failed..%d ",r); + AppLog( "[Error] __byteBuffer[2].Construct failed..%d ",r); return E_OUT_OF_MEMORY; } r = __byteBuffer[3].Construct(__bufferSize); if (E_SUCCESS != r) { - //AppLog( "[Error] __byteBuffer[3].Construct failed..%d ",r); + AppLog( "[Error] __byteBuffer[3].Construct failed..%d ",r); return E_OUT_OF_MEMORY; } } @@ -491,7 +482,7 @@ result CCAudioOut::ReWriteBuffer(void) r = __pAudioOut->WriteBuffer(__byteBuffer[i]); if (IsFailed(r)) { - //AppLog("[Error] m_AudioOut.WriteBuffer failed : %d\n", r); + AppLog("[Error] m_AudioOut.WriteBuffer failed : %d\n", r); return r; } } @@ -508,7 +499,7 @@ result CCAudioOut::ReWriteBuffer(void) r = __pAudioOut->WriteBuffer(__byteBuffer[i]); if (IsFailed(r)) { - //AppLog("[Error] m_AudioOut.WriteBuffer failed : %d\n", r); + AppLog("[Error] m_AudioOut.WriteBuffer failed : %d\n", r); return r; } } diff --git a/CocosDenshion/bada/SimpleAudioEngine.cpp b/CocosDenshion/bada/SimpleAudioEngine.cpp index 9afdc487d4..3b388506ec 100644 --- a/CocosDenshion/bada/SimpleAudioEngine.cpp +++ b/CocosDenshion/bada/SimpleAudioEngine.cpp @@ -320,7 +320,7 @@ void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop) void SimpleAudioEngine::stopBackgroundMusic(bool bReleaseData) { s_bBackgroundMusicPaused = false; - if (s_pBackPlayer && PLAYER_STATE_PLAYING == s_pBackPlayer->GetState()) + if (s_pBackPlayer != NULL && PLAYER_STATE_PLAYING == s_pBackPlayer->GetState()) { s_pBackPlayer->Stop(); } @@ -328,7 +328,7 @@ void SimpleAudioEngine::stopBackgroundMusic(bool bReleaseData) void SimpleAudioEngine::pauseBackgroundMusic() { - if (s_pBackPlayer && PLAYER_STATE_PLAYING == s_pBackPlayer->GetState()) + if (s_pBackPlayer != NULL && PLAYER_STATE_PLAYING == s_pBackPlayer->GetState()) { s_bBackgroundMusicPaused = true; s_pBackPlayer->Pause(); @@ -337,7 +337,7 @@ void SimpleAudioEngine::pauseBackgroundMusic() void SimpleAudioEngine::resumeBackgroundMusic() { - if (s_pBackPlayer && s_bBackgroundMusicPaused && PLAYER_STATE_PLAYING != s_pBackPlayer->GetState()) + if (s_pBackPlayer != NULL && s_bBackgroundMusicPaused && PLAYER_STATE_PLAYING != s_pBackPlayer->GetState()) { s_bBackgroundMusicPaused = false; s_pBackPlayer->Play(); @@ -347,7 +347,7 @@ void SimpleAudioEngine::resumeBackgroundMusic() void SimpleAudioEngine::rewindBackgroundMusic() { stopBackgroundMusic(); - if (s_pBackPlayer) + if (s_pBackPlayer != NULL) { if (PLAYER_STATE_PLAYING != s_pBackPlayer->GetState()) { @@ -369,12 +369,9 @@ bool SimpleAudioEngine::isBackgroundMusicPlaying() { bool bRet = false; - if (s_pBackPlayer) + if (s_pBackPlayer != NULL && s_pBackPlayer->GetState() == PLAYER_STATE_PLAYING) { - if (s_pBackPlayer->GetState() == PLAYER_STATE_PLAYING) - { - bRet = true; - } + bRet = true; } return bRet; @@ -397,7 +394,7 @@ void SimpleAudioEngine::setBackgroundMusicVolume(float volume) volume = 0.0f; } - if (s_pBackPlayer) + if (s_pBackPlayer != NULL) { s_pBackPlayer->SetVolume((int) (volume * 99)); if (volume > 0.0f && s_pBackPlayer->GetVolume() == 0) @@ -439,6 +436,11 @@ unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop/* EffectList::iterator p = s_List.find(nRet); if (p != s_List.end()) { + if (NULL == p->second) + { + AppLog("CCAudioOut instance must not be NULL, id = %d", p->first); + return 0; + } p->second->SetVolume((int) (s_fEffectsVolume * 99)); int volume = p->second->GetVolume(); @@ -468,19 +470,25 @@ unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop/* void SimpleAudioEngine::stopEffect(unsigned int nSoundId) { - CCAudioOut*& pPlayer = s_List[nSoundId]; - if (pPlayer != NULL) + EffectList::iterator it = s_List.find(nSoundId); + if (it != s_List.end()) { - pPlayer->Stop(); + if (it->second != NULL) + { + it->second->Stop(); + } } } void SimpleAudioEngine::pauseEffect(unsigned int nSoundId) { - CCAudioOut*& pPlayer = s_List[nSoundId]; - if (pPlayer != NULL) + EffectList::iterator it = s_List.find(nSoundId); + if (it != s_List.end()) { - pPlayer->Pause(); + if (it->second != NULL) + { + it->second->Pause(); + } } } @@ -488,16 +496,22 @@ void SimpleAudioEngine::pauseAllEffects() { for (EffectList::iterator it = s_List.begin(); it != s_List.end(); ++it) { - it->second->Pause(); + if (it->second != NULL) + { + it->second->Pause(); + } } } void SimpleAudioEngine::resumeEffect(unsigned int nSoundId) { - CCAudioOut*& pPlayer = s_List[nSoundId]; - if (pPlayer != NULL) + EffectList::iterator it = s_List.find(nSoundId); + if (it != s_List.end()) { - pPlayer->Resume(); + if (it->second != NULL) + { + it->second->Resume(); + } } } @@ -505,7 +519,10 @@ void SimpleAudioEngine::resumeAllEffects() { for (EffectList::iterator it = s_List.begin(); it != s_List.end(); ++it) { - it->second->Resume(); + if (it->second != NULL) + { + it->second->Resume(); + } } } @@ -513,7 +530,10 @@ void SimpleAudioEngine::stopAllEffects() { for (EffectList::iterator it = s_List.begin(); it != s_List.end(); ++it) { - it->second->Stop(); + if (it->second != NULL) + { + it->second->Stop(); + } } } @@ -535,13 +555,17 @@ void SimpleAudioEngine::preloadEffect(const char* pszFilePath) if (s_List.size() >= 64) { // get the first effect, and remove it form list - //AppLog("effect preload more than 64, delete the first effect"); + AppLog("effect preload more than 64, delete the first effect"); pEffectPlayer = s_List.begin()->second; pEffectPlayer->Finalize(); - s_List.erase(s_List.begin()->first); + s_List.erase(s_List.begin()); } - if (pEffectPlayer == NULL) - pEffectPlayer = new CCAudioOut; + + if (NULL == pEffectPlayer) + { + pEffectPlayer = new CCAudioOut(); + } + pEffectPlayer->Initialize(strFilePath.c_str()); s_List.insert(Effect(nRet, pEffectPlayer)); @@ -556,9 +580,17 @@ void SimpleAudioEngine::unloadEffect(const char* pszFilePath) EffectList::iterator p = s_List.find(nID); if (p != s_List.end()) { - delete p->second; - p->second = NULL; - s_List.erase(nID); + if (p->second != NULL) + { + delete p->second; + p->second = NULL; + AppLog("delete CCAudioOut, id = %d", nID); + } + else + { + AppLog("CCAudioOut instance is NULL, id = %d", nID); + } + s_List.erase(p); } } diff --git a/CocosDenshion/bada/vorbis/vorbisfile.c b/CocosDenshion/bada/vorbis/vorbisfile.c index 6e701ccd64..a980f732ba 100644 --- a/CocosDenshion/bada/vorbis/vorbisfile.c +++ b/CocosDenshion/bada/vorbis/vorbisfile.c @@ -881,14 +881,14 @@ static int _ov_open1(void *f,OggVorbis_File *vf,const char *initial, long *serialno_list=NULL; int serialno_list_size=0; int ret; - //AppLog("enter"); + memset(vf,0,sizeof(*vf)); vf->datasource=f; vf->callbacks = callbacks; - //AppLog("enter"); + /* init the framing state */ ogg_sync_init(&vf->oy); - //AppLog("enter"); + /* perhaps some data was previously read into a buffer for testing against other stream types. Allow initialization from this previously read data (especially as we may be reading from a @@ -898,7 +898,7 @@ static int _ov_open1(void *f,OggVorbis_File *vf,const char *initial, memcpy(buffer,initial,ibytes); ogg_sync_wrote(&vf->oy,ibytes); } - //AppLog("enter"); + /* can we seek? Stevens suggests the seek test was portable */ if(offsettest!=-1)vf->seekable=1; @@ -908,15 +908,15 @@ static int _ov_open1(void *f,OggVorbis_File *vf,const char *initial, vf->vi=_ogg_calloc(vf->links,sizeof(*vf->vi)); vf->vc=_ogg_calloc(vf->links,sizeof(*vf->vc)); ogg_stream_init(&vf->os,-1); /* fill in the serialno later */ - //AppLog("enter"); + /* Fetch all BOS pages, store the vorbis header and all seen serial numbers, load subsequent vorbis setup headers */ if((ret=_fetch_headers(vf,vf->vi,vf->vc,&serialno_list,&serialno_list_size,NULL))<0){ - //AppLog("enter"); + vf->datasource=NULL; ov_clear(vf); }else{ - //AppLog("enter"); + /* serial number list for first link needs to be held somewhere for second stage of seekable stream open; this saves having to seek/reread first link's serialnumber data then. */ @@ -933,12 +933,12 @@ static int _ov_open1(void *f,OggVorbis_File *vf,const char *initial, vf->ready_state=PARTOPEN; } if(serialno_list)_ogg_free(serialno_list); - //AppLog("enter"); + return(ret); } static int _ov_open2(OggVorbis_File *vf){ - //AppLog("enter"); + if(vf->ready_state != PARTOPEN) return OV_EINVAL; vf->ready_state=OPENED; if(vf->seekable){ @@ -950,7 +950,7 @@ static int _ov_open2(OggVorbis_File *vf){ return(ret); }else vf->ready_state=STREAMSET; - //AppLog("enter"); + return 0; } @@ -1008,7 +1008,7 @@ int ov_open(FILE *f,OggVorbis_File *vf,const char *initial,long ibytes){ (int (*)(void *)) fclose, (long (*)(void *)) ftell }; - //AppLog("enter"); + return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks); } diff --git a/chipmunk/proj.bada/sdk1.0/.cproject b/chipmunk/proj.bada/sdk1.0/.cproject index acc30c9749..5e48158643 100644 --- a/chipmunk/proj.bada/sdk1.0/.cproject +++ b/chipmunk/proj.bada/sdk1.0/.cproject @@ -307,6 +307,172 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -778,6 +944,172 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1249,6 +1581,172 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cocos2dx/touch_dispatcher/CCTouchDispatcher.cpp b/cocos2dx/touch_dispatcher/CCTouchDispatcher.cpp index f2a8ec425d..66bf9f461c 100644 --- a/cocos2dx/touch_dispatcher/CCTouchDispatcher.cpp +++ b/cocos2dx/touch_dispatcher/CCTouchDispatcher.cpp @@ -30,7 +30,7 @@ THE SOFTWARE. #include "CCTouch.h" #include "CCTexture2D.h" #include "support/data_support/ccCArray.h" - +#include "ccMacros.h" #include /** @@ -286,7 +286,7 @@ CCTouchHandler* CCTouchDispatcher::findHandler(CCTouchDelegate *pDelegate) CCTouchHandler* CCTouchDispatcher::findHandler(CCMutableArray *pArray, CCTouchDelegate *pDelegate) { - CCAssert(pArray != NULL && pDelegate != NULL); + CCAssert(pArray != NULL && pDelegate != NULL, ""); CCMutableArray::CCMutableArrayIterator iter; From 82c978c34e9f5bf3af81e4424ff47b37d8e72fa0 Mon Sep 17 00:00:00 2001 From: dumganhar Date: Sat, 31 Dec 2011 17:53:01 +0800 Subject: [PATCH 11/12] setEffectVolume, apply for all effect instance. --- CocosDenshion/bada/SimpleAudioEngine.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CocosDenshion/bada/SimpleAudioEngine.cpp b/CocosDenshion/bada/SimpleAudioEngine.cpp index 3b388506ec..48f201d166 100644 --- a/CocosDenshion/bada/SimpleAudioEngine.cpp +++ b/CocosDenshion/bada/SimpleAudioEngine.cpp @@ -422,6 +422,14 @@ void SimpleAudioEngine::setEffectsVolume(float volume) } s_fEffectsVolume = volume; + EffectList::iterator it; + for (it = s_List.begin(); it != s_List.end(); ++it) + { + if (it->second != NULL) + { + it->second->SetVolume((int)(s_fEffectsVolume * 99)); + } + } } // for sound effects From 92ea6596a39267bad6ca6f8a2bd342828afbff46 Mon Sep 17 00:00:00 2001 From: dumganhar Date: Sat, 31 Dec 2011 18:08:41 +0800 Subject: [PATCH 12/12] use ceil function to set effect volume --- CocosDenshion/bada/SimpleAudioEngine.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/CocosDenshion/bada/SimpleAudioEngine.cpp b/CocosDenshion/bada/SimpleAudioEngine.cpp index 48f201d166..c14e693228 100644 --- a/CocosDenshion/bada/SimpleAudioEngine.cpp +++ b/CocosDenshion/bada/SimpleAudioEngine.cpp @@ -33,6 +33,7 @@ THE SOFTWARE. #include #include #include +#include using namespace std; using namespace Osp::Media; @@ -396,11 +397,7 @@ void SimpleAudioEngine::setBackgroundMusicVolume(float volume) if (s_pBackPlayer != NULL) { - s_pBackPlayer->SetVolume((int) (volume * 99)); - if (volume > 0.0f && s_pBackPlayer->GetVolume() == 0) - { - s_pBackPlayer->SetVolume(1); - } + s_pBackPlayer->SetVolume(ceil(volume)); } s_fBackgroundMusicVolume = volume; } @@ -421,15 +418,15 @@ void SimpleAudioEngine::setEffectsVolume(float volume) volume = 0.0f; } - s_fEffectsVolume = volume; EffectList::iterator it; for (it = s_List.begin(); it != s_List.end(); ++it) { if (it->second != NULL) { - it->second->SetVolume((int)(s_fEffectsVolume * 99)); + it->second->SetVolume(ceil(volume)); } } + s_fEffectsVolume = volume; } // for sound effects