diff --git a/cocos2dx/CCDirector.cpp b/cocos2dx/CCDirector.cpp index f835f7eb7f..5e1b874ac0 100644 --- a/cocos2dx/CCDirector.cpp +++ b/cocos2dx/CCDirector.cpp @@ -44,6 +44,7 @@ THE SOFTWARE. #include "CCLabelTTF.h" #include "CCConfiguration.h" #include "CCKeypadDispatcher.h" +#include "CCAccelerometer.h" #include "CCGL.h" #include "CCAnimationCache.h" #include "CCTouch.h" @@ -85,6 +86,11 @@ CCDirector* CCDirector::sharedDirector(void) return &s_sharedDirector; } +CCDirector::CCDirector(void) +{ + +} + bool CCDirector::init(void) { CCLOG("cocos2d: %s", cocos2dVersion()); @@ -133,6 +139,15 @@ bool CCDirector::init(void) // action manager m_pActionManager = new CCActionManager(); m_pScheduler->scheduleUpdateForTarget(m_pActionManager, kCCActionManagerPriority, false); + // touchDispatcher + m_pTouchDispatcher = new CCTouchDispatcher(); + m_pTouchDispatcher->init(); + + // KeypadDispatcher + m_pKeypadDispatcher = new CCKeypadDispatcher(); + + // Accelerometer + m_pAccelerometer = new CCAccelerometer(); // create autorelease pool CCPoolManager::getInstance()->push(); @@ -153,15 +168,14 @@ CCDirector::~CCDirector(void) CC_SAFE_RELEASE(m_pobScenesStack); CC_SAFE_RELEASE(m_pScheduler); CC_SAFE_RELEASE(m_pActionManager); - + CC_SAFE_RELEASE(m_pTouchDispatcher); + CC_SAFE_RELEASE(m_pKeypadDispatcher); + CC_SAFE_DELETE(m_pAccelerometer); // pop the autorelease pool CCPoolManager::getInstance()->pop(); // delete m_pLastUpdate CC_SAFE_DELETE(m_pLastUpdate); - - CCKeypadDispatcher::purgeSharedDispatcher(); - // delete fps string delete []m_pszFPS; } @@ -300,9 +314,8 @@ void CCDirector::setOpenGLView(CC_GLVIEW *pobOpenGLView) updateContentScaleFactor(); } - CCTouchDispatcher *pTouchDispatcher = CCTouchDispatcher::sharedDispatcher(); - m_pobOpenGLView->setTouchDelegate(pTouchDispatcher); - pTouchDispatcher->setDispatchEvents(true); + m_pobOpenGLView->setTouchDelegate(m_pTouchDispatcher); + m_pTouchDispatcher->setDispatchEvents(true); } } @@ -577,7 +590,7 @@ void CCDirector::resetDirector() { // don't release the event handlers // They are needed in case the director is run again - CCTouchDispatcher::sharedDispatcher()->removeAllDelegates(); + m_pTouchDispatcher->removeAllDelegates(); if (m_pRunningScene) { @@ -613,7 +626,7 @@ void CCDirector::purgeDirector() { // don't release the event handlers // They are needed in case the director is run again - CCTouchDispatcher::sharedDispatcher()->removeAllDelegates(); + m_pTouchDispatcher->removeAllDelegates(); if (m_pRunningScene) { @@ -927,6 +940,44 @@ CCActionManager* CCDirector::getActionManager() return m_pActionManager; } +void CCDirector::setTouchDispatcher(CCTouchDispatcher* pTouchDispatcher) +{ + CC_SAFE_RETAIN(pTouchDispatcher); + CC_SAFE_RELEASE(m_pTouchDispatcher); + m_pTouchDispatcher = pTouchDispatcher; +} + +CCTouchDispatcher* CCDirector::getTouchDispatcher() +{ + return m_pTouchDispatcher; +} + +void CCDirector::setKeypadDispatcher(CCKeypadDispatcher* pKeypadDispatcher) +{ + CC_SAFE_RETAIN(pKeypadDispatcher); + CC_SAFE_RELEASE(m_pKeypadDispatcher); + m_pKeypadDispatcher = pKeypadDispatcher; +} + +CCKeypadDispatcher* CCDirector::getKeypadDispatcher() +{ + return m_pKeypadDispatcher; +} + +void CCDirector::setAccelerometer(CCAccelerometer* pAccelerometer) +{ + if (m_pAccelerometer != pAccelerometer) + { + CC_SAFE_DELETE(m_pAccelerometer); + m_pAccelerometer = pAccelerometer; + } +} + +CCAccelerometer* CCDirector::getAccelerometer() +{ + return m_pAccelerometer; +} + /*************************************************** * implementation of DisplayLinkDirector **************************************************/ diff --git a/cocos2dx/include/CCDirector.h b/cocos2dx/include/CCDirector.h index d6205e969b..7f6fb98a01 100755 --- a/cocos2dx/include/CCDirector.h +++ b/cocos2dx/include/CCDirector.h @@ -142,6 +142,10 @@ class CCDirectorDelegate; class CCNode; class CCScheduler; class CCActionManager; +class CCTouchDispatcher; +class CCKeypadDispatcher; +class CCAccelerometer; + /** @brief Class that creates and handle the main Window and manages how and when to execute the Scenes. @@ -164,10 +168,10 @@ and when to execute the Scenes. */ class CC_DLL CCDirector : public CCObject { -public: - virtual bool init(void); +public: + CCDirector(void); virtual ~CCDirector(void); - CCDirector(void) {} + virtual bool init(void); // attribute @@ -393,6 +397,21 @@ public: */ CC_PROPERTY(CCActionManager*, m_pActionManager, ActionManager); + /** CCTouchDispatcher associated with this director + @since v2.0 + */ + CC_PROPERTY(CCTouchDispatcher*, m_pTouchDispatcher, TouchDispatcher); + + /** CCKeypadDispatcher associated with this director + @since v2.0 + */ + CC_PROPERTY(CCKeypadDispatcher*, m_pKeypadDispatcher, KeypadDispatcher); + + /** CCAccelerometer associated with this director + @since v2.0 + */ + CC_PROPERTY(CCAccelerometer*, m_pAccelerometer, Accelerometer); + /** returns a shared instance of the director */ static CCDirector* sharedDirector(void); void resetDirector(); diff --git a/cocos2dx/include/CCKeypadDispatcher.h b/cocos2dx/include/CCKeypadDispatcher.h index 6c79cb753c..521d6365b4 100755 --- a/cocos2dx/include/CCKeypadDispatcher.h +++ b/cocos2dx/include/CCKeypadDispatcher.h @@ -47,16 +47,6 @@ public: CCKeypadDispatcher(); ~CCKeypadDispatcher(); - /** - @brief Returns the shared CCKeypadDispatcher object for the system. - */ - static CCKeypadDispatcher* sharedDispatcher(); - - /** - @brief Release the shared CCKeypadDispatcher object from the system. - */ - static void purgeSharedDispatcher(); - /** @brief add delegate to concern keypad msg */ diff --git a/cocos2dx/include/CCTouchDispatcher.h b/cocos2dx/include/CCTouchDispatcher.h index b0a6ba5bab..0ccf8e4f21 100755 --- a/cocos2dx/include/CCTouchDispatcher.h +++ b/cocos2dx/include/CCTouchDispatcher.h @@ -140,10 +140,7 @@ public: virtual void touchesCancelled(CCSet* touches, CCEvent* pEvent); public: - /** singleton of the CCTouchDispatcher */ - static CCTouchDispatcher* sharedDispatcher(); CCTouchHandler* findHandler(CCTouchDelegate *pDelegate); - protected: void forceRemoveDelegate(CCTouchDelegate *pDelegate); void forceAddHandler(CCTouchHandler *pHandler, CCArray* pArray); diff --git a/cocos2dx/keypad_dispatcher/CCKeypadDispatcher.cpp b/cocos2dx/keypad_dispatcher/CCKeypadDispatcher.cpp index 65b2244cc8..96fc6d20e2 100644 --- a/cocos2dx/keypad_dispatcher/CCKeypadDispatcher.cpp +++ b/cocos2dx/keypad_dispatcher/CCKeypadDispatcher.cpp @@ -27,7 +27,6 @@ THE SOFTWARE. namespace cocos2d { -static CCKeypadDispatcher* s_KeypadDispatcher = NULL; //------------------------------------------------------------------ // // CCKeypadDispatcher @@ -59,25 +58,6 @@ CCKeypadDispatcher::~CCKeypadDispatcher() } } -CCKeypadDispatcher* CCKeypadDispatcher::sharedDispatcher() -{ - if (! s_KeypadDispatcher) - { - s_KeypadDispatcher = new CCKeypadDispatcher; - } - - return s_KeypadDispatcher; -} - -void CCKeypadDispatcher::purgeSharedDispatcher() -{ - if (s_KeypadDispatcher) - { - s_KeypadDispatcher->release(); - s_KeypadDispatcher = NULL; - } -} - void CCKeypadDispatcher::removeDelegate(CCKeypadDelegate* pDelegate) { if (!pDelegate) diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp index f4c209e64a..492f259f7b 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp +++ b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp @@ -92,23 +92,24 @@ CCLayer *CCLayer::node() void CCLayer::registerWithTouchDispatcher() { + CCDirector* pDirector = CCDirector::sharedDirector(); if (m_pScriptHandlerEntry) { if (m_pScriptHandlerEntry->getIsMultiTouches()) { - CCTouchDispatcher::sharedDispatcher()->addStandardDelegate(this, 0); + pDirector->getTouchDispatcher()->addStandardDelegate(this, 0); LUALOG("[LUA] Add multi-touches event handler: %d", m_pScriptHandlerEntry->getHandler()); } else { - CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, + pDirector->getTouchDispatcher()->addTargetedDelegate(this, m_pScriptHandlerEntry->getPriority(), m_pScriptHandlerEntry->getSwallowsTouches()); LUALOG("[LUA] Add touch event handler: %d", m_pScriptHandlerEntry->getHandler()); } return; } - CCTouchDispatcher::sharedDispatcher()->addStandardDelegate(this,0); + pDirector->getTouchDispatcher()->addStandardDelegate(this,0); } void CCLayer::registerScriptTouchHandler(int nHandler, bool bIsMultiTouches, int nPriority, bool bSwallowsTouches) @@ -157,7 +158,8 @@ void CCLayer::setIsTouchEnabled(bool enabled) else { // have problems? - CCTouchDispatcher::sharedDispatcher()->removeDelegate(this); + CCDirector* pDirector = CCDirector::sharedDirector(); + pDirector->getTouchDispatcher()->removeDelegate(this); } } } @@ -177,13 +179,14 @@ void CCLayer::setIsAccelerometerEnabled(bool enabled) if (m_bIsRunning) { + CCDirector* pDirector = CCDirector::sharedDirector(); if (enabled) { - CCAccelerometer::sharedAccelerometer()->setDelegate(this); + pDirector->getAccelerometer()->setDelegate(this); } else { - CCAccelerometer::sharedAccelerometer()->setDelegate(NULL); + pDirector->getAccelerometer()->setDelegate(NULL); } } } @@ -203,13 +206,14 @@ void CCLayer::setIsKeypadEnabled(bool enabled) if (m_bIsRunning) { + CCDirector* pDirector = CCDirector::sharedDirector(); if (enabled) { - CCKeypadDispatcher::sharedDispatcher()->addDelegate(this); + pDirector->getKeypadDispatcher()->addDelegate(this); } else { - CCKeypadDispatcher::sharedDispatcher()->removeDelegate(this); + pDirector->getKeypadDispatcher()->removeDelegate(this); } } } @@ -218,6 +222,7 @@ void CCLayer::setIsKeypadEnabled(bool enabled) /// Callbacks void CCLayer::onEnter() { + CCDirector* pDirector = CCDirector::sharedDirector(); // register 'parent' nodes first // since events are propagated in reverse order if (m_bIsTouchEnabled) @@ -231,34 +236,35 @@ void CCLayer::onEnter() // add this layer to concern the Accelerometer Sensor if (m_bIsAccelerometerEnabled) { - CCAccelerometer::sharedAccelerometer()->setDelegate(this); + pDirector->getAccelerometer()->setDelegate(this); } // add this layer to concern the kaypad msg if (m_bIsKeypadEnabled) { - CCKeypadDispatcher::sharedDispatcher()->addDelegate(this); + pDirector->getKeypadDispatcher()->addDelegate(this); } } void CCLayer::onExit() { + CCDirector* pDirector = CCDirector::sharedDirector(); if( m_bIsTouchEnabled ) { - CCTouchDispatcher::sharedDispatcher()->removeDelegate(this); + pDirector->getTouchDispatcher()->removeDelegate(this); unregisterScriptTouchHandler(); } // remove this layer from the delegates who concern Accelerometer Sensor if (m_bIsAccelerometerEnabled) { - CCAccelerometer::sharedAccelerometer()->setDelegate(NULL); + pDirector->getAccelerometer()->setDelegate(NULL); } // remove this layer from the delegates who concern the kaypad msg if (m_bIsKeypadEnabled) { - CCKeypadDispatcher::sharedDispatcher()->removeDelegate(this); + pDirector->getKeypadDispatcher()->removeDelegate(this); } CCNode::onExit(); @@ -268,7 +274,8 @@ void CCLayer::onEnterTransitionDidFinish() { if (m_bIsAccelerometerEnabled) { - CCAccelerometer::sharedAccelerometer()->setDelegate(this); + CCDirector* pDirector = CCDirector::sharedDirector(); + pDirector->getAccelerometer()->setDelegate(this); } CCNode::onEnterTransitionDidFinish(); diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCTransition.cpp b/cocos2dx/layers_scenes_transitions_nodes/CCTransition.cpp index 4a6990094f..3337fc7280 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCTransition.cpp +++ b/cocos2dx/layers_scenes_transitions_nodes/CCTransition.cpp @@ -92,7 +92,8 @@ bool CCTransitionScene::initWithDuration(ccTime t, CCScene *scene) CCAssert( m_pInScene != m_pOutScene, "Incoming scene must be different from the outgoing scene" ); // disable events while transitions - CCTouchDispatcher::sharedDispatcher()->setDispatchEvents(false); + CCDirector* pDirector = CCDirector::sharedDirector(); + pDirector->getTouchDispatcher()->setDispatchEvents(false); this->sceneOrder(); return true; @@ -153,7 +154,7 @@ void CCTransitionScene::setNewScene(ccTime dt) m_bIsSendCleanupToScene = director->isSendCleanupToScene(); director->replaceScene(m_pInScene); // enable events while transitions - CCTouchDispatcher::sharedDispatcher()->setDispatchEvents(true); + director->getTouchDispatcher()->setDispatchEvents(true); // issue #267 m_pOutScene->setIsVisible(true); } diff --git a/cocos2dx/menu_nodes/CCMenu.cpp b/cocos2dx/menu_nodes/CCMenu.cpp index 8e01403e26..25ba55fa83 100644 --- a/cocos2dx/menu_nodes/CCMenu.cpp +++ b/cocos2dx/menu_nodes/CCMenu.cpp @@ -160,7 +160,8 @@ namespace cocos2d{ //Menu - Events void CCMenu::registerWithTouchDispatcher() { - CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, kCCMenuTouchPriority, true); + CCDirector* pDirector = CCDirector::sharedDirector(); + pDirector->getTouchDispatcher()->addTargetedDelegate(this, kCCMenuTouchPriority, true); } bool CCMenu::ccTouchBegan(CCTouch* touch, CCEvent* event) diff --git a/cocos2dx/platform/android/CCAccelerometer_android.cpp b/cocos2dx/platform/android/CCAccelerometer_android.cpp index c5cd8cc9ee..d6ad3917ab 100644 --- a/cocos2dx/platform/android/CCAccelerometer_android.cpp +++ b/cocos2dx/platform/android/CCAccelerometer_android.cpp @@ -32,26 +32,13 @@ THE SOFTWARE. namespace cocos2d { - CCAccelerometer* CCAccelerometer::m_spCCAccelerometer = NULL; - CCAccelerometer::CCAccelerometer() : m_pAccelDelegate(NULL) { } CCAccelerometer::~CCAccelerometer() { - m_spCCAccelerometer = NULL; - } - CCAccelerometer* CCAccelerometer::sharedAccelerometer() - { - - if (m_spCCAccelerometer == NULL) - { - m_spCCAccelerometer = new CCAccelerometer(); - } - - return m_spCCAccelerometer; } void CCAccelerometer::setDelegate(CCAccelerometerDelegate* pDelegate) diff --git a/cocos2dx/platform/android/CCAccelerometer_android.h b/cocos2dx/platform/android/CCAccelerometer_android.h index e2d85cbde5..90ed905ed7 100644 --- a/cocos2dx/platform/android/CCAccelerometer_android.h +++ b/cocos2dx/platform/android/CCAccelerometer_android.h @@ -36,13 +36,10 @@ public: CCAccelerometer(); ~CCAccelerometer(); - static CCAccelerometer* sharedAccelerometer(); - void setDelegate(CCAccelerometerDelegate* pDelegate); void update(float x, float y, float z, long sensorTimeStamp); private: - static CCAccelerometer* m_spCCAccelerometer; CCAccelerometerDelegate* m_pAccelDelegate; CCAcceleration m_obAccelerationValue; }; diff --git a/cocos2dx/platform/android/jni/SensorJni.cpp b/cocos2dx/platform/android/jni/SensorJni.cpp index d9f523019f..f6d5560ce4 100644 --- a/cocos2dx/platform/android/jni/SensorJni.cpp +++ b/cocos2dx/platform/android/jni/SensorJni.cpp @@ -29,7 +29,7 @@ THE SOFTWARE. #include "JniHelper.h" #include #include - +#include "CCDirector.h" #if 0 #define LOG_TAG "SensorJni" @@ -56,7 +56,8 @@ extern "C" // (y - rcRect.origin.y) / fScreenScaleFactor, // z, // timeStamp); - cocos2d::CCAccelerometer::sharedAccelerometer()->update(x, y, z, timeStamp); + CCDirector* pDirector = CCDirector::sharedDirector(); + pDirector->getAccelerometer()->update(x, y, z, timeStamp); } void enableAccelerometerJNI() diff --git a/cocos2dx/platform/bada/CCAccelerometer_bada.cpp b/cocos2dx/platform/bada/CCAccelerometer_bada.cpp index aa91376db5..4d8db9dc06 100644 --- a/cocos2dx/platform/bada/CCAccelerometer_bada.cpp +++ b/cocos2dx/platform/bada/CCAccelerometer_bada.cpp @@ -45,12 +45,6 @@ CCAccelerometer::~CCAccelerometer() CC_SAFE_DELETE(m_pSensor); } -CCAccelerometer* CCAccelerometer::sharedAccelerometer() -{ - static CCAccelerometer s_CCAccelerometer; - return &s_CCAccelerometer; -} - void CCAccelerometer::setDelegate(CCAccelerometerDelegate* pDelegate) { m_pAccelDelegate = pDelegate; diff --git a/cocos2dx/platform/bada/CCAccelerometer_bada.h b/cocos2dx/platform/bada/CCAccelerometer_bada.h index cce75b5dd2..8a7a0bcce1 100644 --- a/cocos2dx/platform/bada/CCAccelerometer_bada.h +++ b/cocos2dx/platform/bada/CCAccelerometer_bada.h @@ -40,7 +40,6 @@ class CC_DLL CCAccelerometer : public: CCAccelerometer(); ~CCAccelerometer(); - static CCAccelerometer* sharedAccelerometer(); void setDelegate(CCAccelerometerDelegate* pDelegate); virtual void OnDataReceived(Osp::Uix::SensorType sensorType, Osp::Uix::SensorData& sensorData , result r); diff --git a/cocos2dx/platform/ios/CCAccelerometer_ios.h b/cocos2dx/platform/ios/CCAccelerometer_ios.h index 52d5c22a8f..a88f7b0824 100644 --- a/cocos2dx/platform/ios/CCAccelerometer_ios.h +++ b/cocos2dx/platform/ios/CCAccelerometer_ios.h @@ -35,12 +35,7 @@ public: CCAccelerometer(); ~CCAccelerometer(); - static CCAccelerometer* sharedAccelerometer(); - void setDelegate(CCAccelerometerDelegate* pDelegate); - -private: - static CCAccelerometer* m_spUIAccelerometer; }; }//namespace cocos2d diff --git a/cocos2dx/platform/ios/CCAccelerometer_ios.mm b/cocos2dx/platform/ios/CCAccelerometer_ios.mm index ad372f92dd..178c1d6a27 100644 --- a/cocos2dx/platform/ios/CCAccelerometer_ios.mm +++ b/cocos2dx/platform/ios/CCAccelerometer_ios.mm @@ -27,8 +27,6 @@ namespace cocos2d { - CCAccelerometer* CCAccelerometer::m_spUIAccelerometer = NULL; - CCAccelerometer::CCAccelerometer() { } @@ -37,15 +35,6 @@ namespace cocos2d { { } - CCAccelerometer* CCAccelerometer::sharedAccelerometer() - { - if (m_spUIAccelerometer == NULL) { - m_spUIAccelerometer = new CCAccelerometer(); - } - - return m_spUIAccelerometer; - } - void CCAccelerometer::setDelegate(CCAccelerometerDelegate* pDelegate) { [[AccelerometerDispatcher sharedAccelerometerDispather] addDelegate:pDelegate]; diff --git a/cocos2dx/platform/linux/CCAccelerometer_linux.h b/cocos2dx/platform/linux/CCAccelerometer_linux.h index e0b7a41514..10717de60c 100644 --- a/cocos2dx/platform/linux/CCAccelerometer_linux.h +++ b/cocos2dx/platform/linux/CCAccelerometer_linux.h @@ -18,8 +18,6 @@ public: CCAccelerometer(); ~CCAccelerometer(); - static CCAccelerometer* sharedAccelerometer() { return NULL; }; - void removeDelegate(CCAccelerometerDelegate* pDelegate) {CC_UNUSED_PARAM(pDelegate);}; void addDelegate(CCAccelerometerDelegate* pDelegate) {CC_UNUSED_PARAM(pDelegate);}; void setDelegate(CCAccelerometerDelegate* pDelegate) {CC_UNUSED_PARAM(pDelegate);} diff --git a/cocos2dx/platform/marmalade/CCAccelerometer_marmalade.cpp b/cocos2dx/platform/marmalade/CCAccelerometer_marmalade.cpp index 4f072bd419..fd6455ebee 100644 --- a/cocos2dx/platform/marmalade/CCAccelerometer_marmalade.cpp +++ b/cocos2dx/platform/marmalade/CCAccelerometer_marmalade.cpp @@ -28,29 +28,12 @@ namespace cocos2d { -CCAccelerometer* CCAccelerometer::m_spCCAccelerometer = NULL; - CCAccelerometer::CCAccelerometer() : m_pAccelDelegate(NULL) { } CCAccelerometer::~CCAccelerometer() { - if( m_spCCAccelerometer ) { - delete m_spCCAccelerometer ; - m_spCCAccelerometer = NULL; - } -} - -CCAccelerometer* CCAccelerometer::sharedAccelerometer() -{ - - if (m_spCCAccelerometer == NULL) - { - m_spCCAccelerometer = new CCAccelerometer(); - } - - return m_spCCAccelerometer; } void CCAccelerometer::setDelegate(CCAccelerometerDelegate* pDelegate) diff --git a/cocos2dx/platform/marmalade/CCAccelerometer_marmalade.h b/cocos2dx/platform/marmalade/CCAccelerometer_marmalade.h index 42c4584995..45fed40e72 100644 --- a/cocos2dx/platform/marmalade/CCAccelerometer_marmalade.h +++ b/cocos2dx/platform/marmalade/CCAccelerometer_marmalade.h @@ -42,16 +42,11 @@ public: CCAccelerometer(); ~CCAccelerometer(); - /** - @brief Returns the shared accelerometer object for the system. - */ - static CCAccelerometer* sharedAccelerometer(); - void setDelegate(CCAccelerometerDelegate* pDelegate); void update(float x, float y, float z, uint64 sensorTimeStamp); private: - static CCAccelerometer* m_spCCAccelerometer; + CCAccelerometerDelegate* m_pAccelDelegate; CCAcceleration m_obAccelerationValue; }; diff --git a/cocos2dx/platform/marmalade/CCApplication_marmalade.cpp b/cocos2dx/platform/marmalade/CCApplication_marmalade.cpp index f5a86d0f1f..00b4a4b07e 100644 --- a/cocos2dx/platform/marmalade/CCApplication_marmalade.cpp +++ b/cocos2dx/platform/marmalade/CCApplication_marmalade.cpp @@ -126,7 +126,8 @@ void CCApplication::ccAccelerationUpdate() { // Accelerometer doesn't work on Marmalade X86 MacOS-X simulator #if !(defined(__APPLE__) && defined(I3D_ARCH_X86)) - CCAccelerometer::sharedAccelerometer()->update(s3eAccelerometerGetX(),s3eAccelerometerGetY(),s3eAccelerometerGetZ(),s3eTimerGetMs()); + CCDirector* pDirector = CCDirector::sharedDirector(); + pDirector->getAccelerometer()->update(s3eAccelerometerGetX(),s3eAccelerometerGetY(),s3eAccelerometerGetZ(),s3eTimerGetMs()); #endif } diff --git a/cocos2dx/platform/qnx/CCAccelerometer_qnx.cpp b/cocos2dx/platform/qnx/CCAccelerometer_qnx.cpp index 5418dc7a22..9d1562920e 100644 --- a/cocos2dx/platform/qnx/CCAccelerometer_qnx.cpp +++ b/cocos2dx/platform/qnx/CCAccelerometer_qnx.cpp @@ -33,7 +33,6 @@ THE SOFTWARE. namespace cocos2d { - CCAccelerometer* CCAccelerometer::m_spCCAccelerometer = NULL; int CCAccelerometer::m_initialOrientationAngle = 0; CCAccelerometer::CCAccelerometer() @@ -49,14 +48,6 @@ namespace cocos2d } - CCAccelerometer* CCAccelerometer::sharedAccelerometer() - { - if (m_spCCAccelerometer == NULL) - m_spCCAccelerometer = new CCAccelerometer(); - - return m_spCCAccelerometer; - } - void CCAccelerometer::setDelegate(CCAccelerometerDelegate* pDelegate) { m_pAccelDelegate = pDelegate; diff --git a/cocos2dx/platform/qnx/CCAccelerometer_qnx.h b/cocos2dx/platform/qnx/CCAccelerometer_qnx.h index 0ca8650648..274a105ea6 100644 --- a/cocos2dx/platform/qnx/CCAccelerometer_qnx.h +++ b/cocos2dx/platform/qnx/CCAccelerometer_qnx.h @@ -37,14 +37,10 @@ public: CCAccelerometer(); ~CCAccelerometer(); - static CCAccelerometer* sharedAccelerometer(); - void setDelegate(CCAccelerometerDelegate* pDelegate); void update(long sensorTimeStamp); private: - - static CCAccelerometer* m_spCCAccelerometer; CCAccelerometerDelegate* m_pAccelDelegate; CCAcceleration m_accelerationValue; static int m_initialOrientationAngle; diff --git a/cocos2dx/platform/qnx/CCApplication_qnx.cpp b/cocos2dx/platform/qnx/CCApplication_qnx.cpp index dde9ae42dc..7bf797048f 100644 --- a/cocos2dx/platform/qnx/CCApplication_qnx.cpp +++ b/cocos2dx/platform/qnx/CCApplication_qnx.cpp @@ -60,8 +60,9 @@ int CCApplication::run() { update_time = current_time; - CCAccelerometer::sharedAccelerometer()->update(current_time); - CCDirector::sharedDirector()->mainLoop(); + CCDirector* pDirector = CCDirector::sharedDirector(); + pDirector->getAccelerometer()->update(current_time); + pDirector->mainLoop(); } else { diff --git a/cocos2dx/platform/win32/CCAccelerometer_win32.cpp b/cocos2dx/platform/win32/CCAccelerometer_win32.cpp index c2c0bf22f5..06d75c877d 100644 --- a/cocos2dx/platform/win32/CCAccelerometer_win32.cpp +++ b/cocos2dx/platform/win32/CCAccelerometer_win32.cpp @@ -109,7 +109,7 @@ namespace void myAccelerometerKeyHook( UINT message,WPARAM wParam,LPARAM lParam ) { - cocos2d::CCAccelerometer *pAccelerometer=cocos2d::CCAccelerometer::sharedAccelerometer(); + cocos2d::CCAccelerometer *pAccelerometer = cocos2d::CCDirector::sharedDirector()->getAccelerometer(); bool sendUpdate=false; switch( message ) { @@ -148,9 +148,6 @@ namespace namespace cocos2d { -// static members -CCAccelerometer* CCAccelerometer::m_spCCAccelerometer = NULL; - CCAccelerometer::CCAccelerometer() : m_pAccelDelegate(NULL) { @@ -158,21 +155,7 @@ CCAccelerometer::CCAccelerometer() : CCAccelerometer::~CCAccelerometer() { - if( m_spCCAccelerometer ) - { - delete m_spCCAccelerometer ; - m_spCCAccelerometer = NULL; - } -} -// static -CCAccelerometer* CCAccelerometer::sharedAccelerometer() -{ - if (m_spCCAccelerometer == NULL) - { - m_spCCAccelerometer = new CCAccelerometer(); - } - return m_spCCAccelerometer; } void CCAccelerometer::setDelegate(CCAccelerometerDelegate* pDelegate) diff --git a/cocos2dx/platform/win32/CCAccelerometer_win32.h b/cocos2dx/platform/win32/CCAccelerometer_win32.h index 002fa90d49..ff0b626faf 100644 --- a/cocos2dx/platform/win32/CCAccelerometer_win32.h +++ b/cocos2dx/platform/win32/CCAccelerometer_win32.h @@ -35,11 +35,9 @@ public: CCAccelerometer(); ~CCAccelerometer(); - static CCAccelerometer* sharedAccelerometer(); void setDelegate(CCAccelerometerDelegate* pDelegate); void update( double x,double y,double z,double timestamp ); private: - static CCAccelerometer* m_spCCAccelerometer; CCAccelerometerDelegate* m_pAccelDelegate; CCAcceleration m_obAccelerationValue; }; diff --git a/cocos2dx/platform/win32/CCEGLView_win32.cpp b/cocos2dx/platform/win32/CCEGLView_win32.cpp index 6b9fe4a3ef..5c0a195545 100644 --- a/cocos2dx/platform/win32/CCEGLView_win32.cpp +++ b/cocos2dx/platform/win32/CCEGLView_win32.cpp @@ -327,8 +327,9 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) case WM_KEYDOWN: if (wParam == VK_F1 || wParam == VK_F2) { + CCDirector* pDirector = CCDirector::sharedDirector(); if (GetKeyState(VK_LSHIFT) < 0 || GetKeyState(VK_RSHIFT) < 0 || GetKeyState(VK_SHIFT) < 0) - CCKeypadDispatcher::sharedDispatcher()->dispatchKeypadMSG(wParam == VK_F1 ? kTypeBackClicked : kTypeMenuClicked); + pDirector->getKeypadDispatcher()->dispatchKeypadMSG(wParam == VK_F1 ? kTypeBackClicked : kTypeMenuClicked); } if ( m_lpfnAccelerometerKeyHook!=NULL ) { diff --git a/cocos2dx/touch_dispatcher/CCTouchDispatcher.cpp b/cocos2dx/touch_dispatcher/CCTouchDispatcher.cpp index da82b2b182..c84ca0e7bb 100644 --- a/cocos2dx/touch_dispatcher/CCTouchDispatcher.cpp +++ b/cocos2dx/touch_dispatcher/CCTouchDispatcher.cpp @@ -53,20 +53,6 @@ void CCTouchDispatcher::setDispatchEvents(bool bDispatchEvents) m_bDispatchEvents = bDispatchEvents; } -static CCTouchDispatcher *pSharedDispatcher = NULL; - -CCTouchDispatcher* CCTouchDispatcher::sharedDispatcher(void) -{ - // synchronized ?? - if (pSharedDispatcher == NULL) - { - pSharedDispatcher = new CCTouchDispatcher(); - pSharedDispatcher->init(); - } - - return pSharedDispatcher; -} - /* +(id) allocWithZone:(CCZone *)zone { diff --git a/tests/tests/Box2DTestBed/Box2dView.cpp b/tests/tests/Box2DTestBed/Box2dView.cpp index 26936a9e9d..23bb39cd7a 100644 --- a/tests/tests/Box2DTestBed/Box2dView.cpp +++ b/tests/tests/Box2DTestBed/Box2dView.cpp @@ -119,7 +119,8 @@ void MenuLayer::backCallback(CCObject* sender) void MenuLayer::registerWithTouchDispatcher() { - CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, true); + CCDirector* pDirector = CCDirector::sharedDirector(); + pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, true); } bool MenuLayer::ccTouchBegan(CCTouch* touch, CCEvent* event) @@ -214,7 +215,8 @@ Box2DView::~Box2DView() void Box2DView::registerWithTouchDispatcher() { // higher priority than dragging - CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, -10, true); + CCDirector* pDirector = CCDirector::sharedDirector(); + pDirector->getTouchDispatcher()->addTargetedDelegate(this, -10, true); } bool Box2DView::ccTouchBegan(CCTouch* touch, CCEvent* event) diff --git a/tests/tests/ChipmunkAccelTouchTest/ChipmunkAccelTouchTest.cpp b/tests/tests/ChipmunkAccelTouchTest/ChipmunkAccelTouchTest.cpp index 18a5c3b4e6..12cdffc722 100644 --- a/tests/tests/ChipmunkAccelTouchTest/ChipmunkAccelTouchTest.cpp +++ b/tests/tests/ChipmunkAccelTouchTest/ChipmunkAccelTouchTest.cpp @@ -224,8 +224,6 @@ void ChipmunkAccelTouchTestLayer::addNewSpriteAtPosition(CCPoint pos) void ChipmunkAccelTouchTestLayer::onEnter() { CCLayer::onEnter(); - -// CCAccelerometer::sharedAccelerometer()->setUpdateInterval:(1.0 / 60)]; } void ChipmunkAccelTouchTestLayer::ccTouchesEnded(CCSet* touches, CCEvent* event) diff --git a/tests/tests/LayerTest/LayerTest.cpp b/tests/tests/LayerTest/LayerTest.cpp index ac647cc674..1d157b1c18 100644 --- a/tests/tests/LayerTest/LayerTest.cpp +++ b/tests/tests/LayerTest/LayerTest.cpp @@ -161,7 +161,8 @@ void LayerTest1::onEnter() void LayerTest1::registerWithTouchDispatcher() { - CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, kCCMenuTouchPriority + 1, true); + CCDirector* pDirector = CCDirector::sharedDirector(); + pDirector->getTouchDispatcher()->addTargetedDelegate(this, kCCMenuTouchPriority + 1, true); } void LayerTest1::updateSize(CCTouch*touch) diff --git a/tests/tests/MenuTest/MenuTest.cpp b/tests/tests/MenuTest/MenuTest.cpp index 7fe7d8d55c..1d153a3ab6 100644 --- a/tests/tests/MenuTest/MenuTest.cpp +++ b/tests/tests/MenuTest/MenuTest.cpp @@ -111,7 +111,8 @@ MenuLayer1::MenuLayer1() void MenuLayer1::registerWithTouchDispatcher() { - CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, kCCMenuTouchPriority+1, true); + CCDirector* pDirector = CCDirector::sharedDirector(); + pDirector->getTouchDispatcher()->addTargetedDelegate(this, kCCMenuTouchPriority+1, true); } bool MenuLayer1::ccTouchBegan(CCTouch *touch, CCEvent * pEvent) @@ -148,7 +149,8 @@ void MenuLayer1::menuCallbackConfig(CCObject* sender) void MenuLayer1::allowTouches(ccTime dt) { - CCTouchDispatcher::sharedDispatcher()->setPriority(kCCMenuTouchPriority+1, this); + CCDirector* pDirector = CCDirector::sharedDirector(); + pDirector->getTouchDispatcher()->setPriority(kCCMenuTouchPriority+1, this); unscheduleAllSelectors(); CCLog("TOUCHES ALLOWED AGAIN"); } @@ -156,7 +158,8 @@ void MenuLayer1::allowTouches(ccTime dt) void MenuLayer1::menuCallbackDisabled(CCObject* sender) { // hijack all touch events for 5 seconds - CCTouchDispatcher::sharedDispatcher()->setPriority(kCCMenuTouchPriority-1, this); + CCDirector* pDirector = CCDirector::sharedDirector(); + pDirector->getTouchDispatcher()->setPriority(kCCMenuTouchPriority-1, this); schedule(schedule_selector(MenuLayer1::allowTouches), 5.0f); CCLog("TOUCHES DISABLED FOR 5 SECONDS"); } diff --git a/tests/tests/ParallaxTest/ParallaxTest.cpp b/tests/tests/ParallaxTest/ParallaxTest.cpp index da4055986d..b19865ac70 100644 --- a/tests/tests/ParallaxTest/ParallaxTest.cpp +++ b/tests/tests/ParallaxTest/ParallaxTest.cpp @@ -134,7 +134,8 @@ Parallax2::Parallax2() void Parallax2::registerWithTouchDispatcher() { - CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, true); + CCDirector* pDirector = CCDirector::sharedDirector(); + pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, true); } bool Parallax2::ccTouchBegan(CCTouch* touch, CCEvent* event) diff --git a/tests/tests/ParticleTest/ParticleTest.cpp b/tests/tests/ParticleTest/ParticleTest.cpp index 4c75d2bb51..a4b7eb05eb 100644 --- a/tests/tests/ParticleTest/ParticleTest.cpp +++ b/tests/tests/ParticleTest/ParticleTest.cpp @@ -1125,7 +1125,8 @@ std::string ParticleDemo::title() void ParticleDemo::registerWithTouchDispatcher() { - CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, false); + CCDirector* pDirector = CCDirector::sharedDirector(); + pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, false); } bool ParticleDemo::ccTouchBegan(CCTouch* touch, CCEvent* event) diff --git a/tests/tests/PerformanceTest/PerformanceTouchesTest.cpp b/tests/tests/PerformanceTest/PerformanceTouchesTest.cpp index 994f98c631..d2b8759bb5 100644 --- a/tests/tests/PerformanceTest/PerformanceTouchesTest.cpp +++ b/tests/tests/PerformanceTest/PerformanceTouchesTest.cpp @@ -99,7 +99,8 @@ std::string TouchesPerformTest1::title() void TouchesPerformTest1::registerWithTouchDispatcher() { - CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, true); + CCDirector* pDirector = CCDirector::sharedDirector(); + pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, true); } bool TouchesPerformTest1::ccTouchBegan(CCTouch* touch, CCEvent* event) @@ -141,7 +142,8 @@ std::string TouchesPerformTest2::title() void TouchesPerformTest2::registerWithTouchDispatcher() { - CCTouchDispatcher::sharedDispatcher()->addStandardDelegate(this, 0); + CCDirector* pDirector = CCDirector::sharedDirector(); + pDirector->getTouchDispatcher()->addStandardDelegate(this, 0); } void TouchesPerformTest2::ccTouchesBegan(CCSet* touches, CCEvent* event) diff --git a/tests/tests/TextInputTest/TextInputTest.cpp b/tests/tests/TextInputTest/TextInputTest.cpp index 0cecc0e85b..c8ec349731 100644 --- a/tests/tests/TextInputTest/TextInputTest.cpp +++ b/tests/tests/TextInputTest/TextInputTest.cpp @@ -157,7 +157,8 @@ KeyboardNotificationLayer::KeyboardNotificationLayer() void KeyboardNotificationLayer::registerWithTouchDispatcher() { - CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, false); + CCDirector* pDirector = CCDirector::sharedDirector(); + pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, false); } void KeyboardNotificationLayer::keyboardWillShow(CCIMEKeyboardNotificationInfo& info) diff --git a/tests/tests/TileMapTest/TileMapTest.cpp b/tests/tests/TileMapTest/TileMapTest.cpp index 803c3b3c35..bc180e1e87 100644 --- a/tests/tests/TileMapTest/TileMapTest.cpp +++ b/tests/tests/TileMapTest/TileMapTest.cpp @@ -1346,7 +1346,8 @@ void TileDemo::backCallback(CCObject* pSender) void TileDemo::registerWithTouchDispatcher() { - CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, true); + CCDirector* pDirector = CCDirector::sharedDirector(); + pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, true); } bool TileDemo::ccTouchBegan(CCTouch* touch, CCEvent* event) diff --git a/tests/tests/TouchesTest/Paddle.cpp b/tests/tests/TouchesTest/Paddle.cpp index 38441b9743..1e2c4ddf23 100644 --- a/tests/tests/TouchesTest/Paddle.cpp +++ b/tests/tests/TouchesTest/Paddle.cpp @@ -35,13 +35,15 @@ bool Paddle::initWithTexture(CCTexture2D* aTexture) void Paddle::onEnter() { - CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, true); + CCDirector* pDirector = CCDirector::sharedDirector(); + pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, true); CCSprite::onEnter(); } void Paddle::onExit() { - CCTouchDispatcher::sharedDispatcher()->removeDelegate(this); + CCDirector* pDirector = CCDirector::sharedDirector(); + pDirector->getTouchDispatcher()->removeDelegate(this); CCSprite::onExit(); }