/* * 离开战斗场景 */ void BattleScene::onExit() { CCScene::onExit(); CCNotificationCenter* pCCNotificationCenter = CCNotificationCenter::sharedNotificationCenter(); pCCNotificationCenter->removeObserver(this, ON_MESSAGE_SUMMARY_STRING); pCCNotificationCenter->removeObserver(this, ON_MESSAGE_LOADING_BATTLE); pCCNotificationCenter->removeObserver(this, ON_MESSAGE_SHUTDOWN_BATTLE); pCCNotificationCenter->removeObserver(this, ON_MESSAGE_NETWORK_EXCEPTION); pCCNotificationCenter->removeObserver(this, ON_MESSAGE_PVP_SUMMARY_STRING); }
void CCLobbyView::onExit() { CCLayer::onExit(); CCNotificationCenter* publisher = CCNotificationCenter::sharedNotificationCenter(); publisher->removeObserver( this, PhotonNoteKey::getString(PhotonNoteKey::CreateRoomReturn) ); publisher->removeObserver( this, PhotonNoteKey::getString(PhotonNoteKey::JoinSpecificRoomReturn) ); publisher->removeObserver( this, PhotonNoteKey::getString(PhotonNoteKey::JoinRandomRoomReturn) ); CocosNetworkLogic* network = CocosNetworkLogic::getInstance(); network->setDelegate(NULL); // network->setDidCreateGame( false ); }
void CCLobbyView::onEnter() { CCLayer::onEnter(); CocosNetworkLogic* network = CocosNetworkLogic::getInstance(); network->setDelegate(NULL); network->setDidCreateGame( false ); CCNotificationCenter* publisher = CCNotificationCenter::sharedNotificationCenter(); publisher->addObserver( this, callfuncO_selector( CCLobbyView::eventCreatedRoom ), PhotonNoteKey::getString(PhotonNoteKey::CreateRoomReturn), network ); publisher->addObserver( this, callfuncO_selector( CCLobbyView::eventJoinSpecificRoom ), PhotonNoteKey::getString(PhotonNoteKey::JoinSpecificRoomReturn), network ); publisher->addObserver( this, callfuncO_selector( CCLobbyView::eventJoinRandomRoom ), PhotonNoteKey::getString(PhotonNoteKey::JoinRandomRoomReturn), network ); }
MCTaskManager * MCTaskManager::sharedTaskManager() { if (__shared_task_manager == NULL) { __shared_task_manager = new MCTaskManager; __shared_task_manager->loadTasks(); CCNotificationCenter *notificationCenter = CCNotificationCenter::sharedNotificationCenter(); notificationCenter->addObserver(__shared_task_manager, callfuncO_selector(MCTaskManager::taskDidFinish), kMCTaskDidFinishNotification, NULL); } return __shared_task_manager; }
CURLHandler() : m_ctx(NULL), m_curl(NULL), m_done(false), m_responseCode(500), isHttpDidReceiveResponseDelivered(false), isHeaderAllReceived(false), m_headers(NULL) { m_data = new CBData(); CCDirector::sharedDirector()->getScheduler()->scheduleSelector(schedule_selector(CURLHandler::dispatchNotification), this, 0, kCCRepeatForever, 0, false); // listener to some internal notification CCNotificationCenter* nc = CCNotificationCenter::sharedNotificationCenter(); nc->addObserver(this, callfuncO_selector(CURLHandler::onCancelAll), kCCNotificationHttpCancelAll, NULL); nc->addObserver(this, callfuncO_selector(CURLHandler::onCancelOne), kCCNotificationHttpCancelOne, NULL); }
/// dispatch end notification void dispatchNotification(float delta) { // notification center CCNotificationCenter* nc = CCNotificationCenter::sharedNotificationCenter(); // check pthread_mutex_lock(&m_mutex); // header notification if(!isHttpDidReceiveResponseDelivered && isHeaderAllReceived) { isHttpDidReceiveResponseDelivered = true; nc->postNotification(kCCNotificationHttpDidReceiveResponse, m_ctx->response); } // notification if(m_data->getSize() > 0) { m_ctx->response->setData(m_data); nc->postNotification(kCCNotificationHttpDataReceived, m_ctx->response); // recreate a new data CC_SAFE_RELEASE(m_data); m_data = new CBData(); } // is done? if(m_done) { // notification nc->postNotification(kCCNotificationHttpRequestCompleted, m_ctx->response); // unlistener internal notification nc->removeObserver(this, kCCNotificationHttpCancelAll); nc->removeObserver(this, kCCNotificationHttpCancelOne); // balance retain in httpThreadEntry autorelease(); // unschedule dispatcher CCDirector::sharedDirector()->getScheduler()->unscheduleSelector(schedule_selector(CURLHandler::dispatchNotification), this); } pthread_mutex_unlock(&m_mutex); }
/* * 进入战斗场景 */ void BattleScene::onEnter() { CCScene::onEnter(); CCNotificationCenter* pCCNotificationCenter = CCNotificationCenter::sharedNotificationCenter(); pCCNotificationCenter->addObserver(this, callfuncO_selector(BattleScene::onBattleSummary), ON_MESSAGE_SUMMARY_STRING, NULL); pCCNotificationCenter->addObserver(this, callfuncO_selector(BattleScene::showLoading), ON_MESSAGE_LOADING_BATTLE, NULL); pCCNotificationCenter->addObserver(this, callfuncO_selector(BattleScene::closeLoading), ON_MESSAGE_SHUTDOWN_BATTLE, NULL); pCCNotificationCenter->addObserver(this, callfuncO_selector(BattleScene::network_exception), ON_MESSAGE_NETWORK_EXCEPTION, NULL); pCCNotificationCenter->addObserver(this, callfuncO_selector(BattleScene::onPvpBattleSummary), ON_MESSAGE_PVP_SUMMARY_STRING, NULL); }