//Poll and notify main thread if responses exists in queue void CCHttpRequest::httpRequestCallback(float delta) { delta; std::queue<HttpResponsePacket *> *pQueue = s_responseQueue; pthread_mutex_lock(&s_responseQueueMutex); if (pQueue->empty()) { pthread_mutex_unlock(&s_responseQueueMutex); } else { HttpResponsePacket *packet = pQueue->front(); pQueue->pop(); pthread_mutex_unlock(&s_responseQueueMutex); --s_asyncRequestCount; if (0 == s_asyncRequestCount) { CCDirector::sharedDirector()->getScheduler()->unscheduleSelector(schedule_selector(CCHttpRequest::httpRequestCallback), this); } HttpRequestPacket *orgRequest = packet->request; CCObject *pTarget = orgRequest->pTarget; SEL_CallFuncND pSelector = orgRequest->pSelector; if (pTarget && pSelector) { (pTarget->*pSelector)((CCNode *)this, packet); pTarget->release(); } delete orgRequest; delete packet; } }
void NDKHelper::HandleMessage(json_t *methodName, json_t* methodParams) { if (methodName == NULL) return; const char *methodNameStr = json_string_value(methodName); for (unsigned int i = 0; i < NDKHelper::selectorList.size(); ++i) { if (NDKHelper::selectorList[i].getName().compare(methodNameStr) == 0) { CCObject *dataToPass = NDKHelper::GetCCObjectFromJson(methodParams); if (dataToPass != NULL) dataToPass->retain(); SEL_CallFuncND sel = NDKHelper::selectorList[i].getSelector(); CCNode *target = NDKHelper::selectorList[i].getTarget(); CCFiniteTimeAction* action = CCSequence::create(CCCallFuncND::create(target, sel, (void*)dataToPass), NULL); target->runAction(action); if (dataToPass != NULL) dataToPass->autorelease(); break; } } }
void CCPrettyPrinter::visit(const CCArray *p) { _result += "\n"; _result += _indentStr; _result += "<array>\n"; setIndentLevel(_indentLevel+1); CCObject* obj; int i = 0; char buf[50] = {0}; CCARRAY_FOREACH(p, obj) { if (i > 0) { _result += "\n"; } sprintf(buf, "%s%02d: ", _indentStr.c_str(), i); _result += buf; CCPrettyPrinter v(_indentLevel); obj->acceptVisitor(v); _result += v.getResult(); i++; } setIndentLevel(_indentLevel-1); _result += "\n"; _result += _indentStr; _result += "</array>"; }
void NDKHelper::HandleMessage(json_t *methodName, json_t* methodParams) { if (methodName == NULL) return; const char *methodNameStr = json_string_value(methodName); for (unsigned int i = 0; i < selectorList.size(); ++i) { if (selectorList[i].getName().compare(methodNameStr) == 0) { CCObject *dataToPass = NDKHelper::GetCCObjectFromJson(methodParams); if (dataToPass != NULL) dataToPass->retain(); SEL_CallFuncO sel = selectorList[i].getSelector(); CCObject *target = selectorList[i].getTarget(); callfuncs->addObject(CCCallFuncO::create(target, sel, dataToPass)); CCDirector::sharedDirector()->getScheduler()->scheduleSelector(schedule_selector(NDKHelper::ExecuteCallfuncs), this, 0, 0, 0, false); if (dataToPass != NULL) dataToPass->autorelease(); break; } } }
void CObjectBase::update(float dt) { CCArray* children = getChildren(); CCObject* pObj; CCARRAY_FOREACH(children, pObj) { pObj->update(dt); }
void CCNotificationHandler::postNotificationOnMainThread(const char *name, CCObject *object) { CCObject *target = new CCNotificationHandler(name, object); target->retain(); target->autorelease(); CCDirector::sharedDirector()->getScheduler()->scheduleSelector(schedule_selector(CCNotificationHandler::postNotification), target, 0, 0, 0, false); }
virtual void visit(const CCArray *p) { cJSON *json = cJSON_CreateArray(); CCObject *obj = NULL; CCARRAY_FOREACH(p, obj){ obj->acceptVisitor(*this); if (m_json) cJSON_AddItemToArray(json, m_json); }
void Facade::clear() { map<int,CCObject*>::iterator iter; for (iter=mediatorVector.begin();iter!=mediatorVector.end();iter++) { CCObject* r = iter->second; r->release(); } mediatorVector.clear(); }
DBData::~DBData() { CCDictElement* pElement = NULL; CCDICT_FOREACH(m_dic, pElement) { CCObject* pObj = pElement->getObject(); if (pObj) { pObj->release(); } }
void CCJSONConverter::convertJsonToDictionary(cJSON *json, CCDictionary *dictionary) { dictionary->removeAllObjects(); cJSON * j = json->child; while (j) { CCObject * obj = getJsonObj(j); dictionary->setObject(obj, j->string); obj->release(); j = j->next; } }
CCDictionary* CAUIHelper::createCAWidgetWithJsonFile(const char *filename) { std::string fullpath= CCFileUtils::sharedFileUtils()->fullPathForFilename(filename); CCLog("%s",fullpath.c_str()); unsigned long size = 0; char *des = (char*) CCFileUtils::sharedFileUtils()->getFileData(filename, "r", &size); CSJson::Reader reader; CSJson::Value root; CSJson::Value description; CSJson::Value rect; CCObject *ui = new CCObject(); if (!reader.parse(des, root)) { CCLog("error"); return NULL; } CCLog("%s",des); for (int i = 0; i<root.size(); i++) { description = root[i]; CAType type = (CAType)description["typeMode"].asInt(); rect = description["rect"]; std::string name = description["name"].asString(); float width = rect["width"].asFloat(); float height = rect["height"].asFloat(); float x = rect["x"].asFloat(); float y = rect ["y"].asFloat(); CCRect uirect = CCRectMake(x, y, width, height); // ui=CAButton::createWithFrame(CCRectMake(x, y, width, height)); if (type == CATypeButton) { ui = addButton(description, uirect); } else if(type == CATypeLabel) { ui = addLabel(description, uirect); } else if(type == CATypeImage) { } m_UIDictionary->setObject(ui, name.c_str()); } ui->release(); return m_UIDictionary; }
void FloatTips::clear() { if(ftPool) { CCObject* ft; int count = ftPool->count(); for (int i = 0; i < count; i++) { ft = ftPool->objectAtIndex(i); //谁retain谁就负责release ft->release(); CCLOG("retainCount %i", ft->retainCount()); } ftPool->removeAllObjects(); } }
void CCSceneBase::renderObjects(const CCCameraBase *inCamera, const CCRenderPass pass, const bool alpha) { #if defined PROFILEON CCProfiler profile( "CCSceneBase::renderObjects()" ); #endif for( int i=0; i<objects.length; ++i ) { CCObject *object = objects.list[i]; if( object->renderPass == pass ) { if( object->isActive() && ( object->octreeRender == false ) ) { object->renderObject( inCamera, alpha ); } } } }
void AsyncLoadPlist::loadPlistAsyncCallBack(float dt) { // the image is generated in loading thread std::queue<ImageInfo*> *imagesQueue = s_pImageQueue; pthread_mutex_lock(&s_ImageInfoMutex); if (imagesQueue->empty()) { pthread_mutex_unlock(&s_ImageInfoMutex); } else { ImageInfo *pImageInfo = imagesQueue->front(); imagesQueue->pop(); pthread_mutex_unlock(&s_ImageInfoMutex); LoadStruct *pLoadStruct = pImageInfo->loadStruct; CCImage *pImage = pImageInfo->image; CCObject *target = pLoadStruct->target; SEL_CallFuncO selector = pLoadStruct->selector; std::string texturePath = pLoadStruct->texturePath; // 从texturePath中取文件名 如/../../filename.png 则filename.png std::string textureFileName = texturePath.substr(texturePath.rfind('/') + 1); CCTextureCache::sharedTextureCache()->addUIImage(pImage, textureFileName.c_str()); if (target && selector) { (target->*selector)(CCString::create(pLoadStruct->plistFileName)); target->release(); } pImage->release(); delete pLoadStruct; delete pImageInfo; --s_nAsyncRefCount; if (0 == s_nAsyncRefCount) { CCDirector::sharedDirector()->getScheduler()->unscheduleSelector(schedule_selector(AsyncLoadPlist::loadPlistAsyncCallBack), this); } } }
bool CCSceneBase::updateScene(const CCTime &time) { bool updated = false; for( int i=0; i<objects.length; ++i ) { CCObject *object = objects.list[i]; if( object->isActive() ) { updated |= object->update( time ); } else if( object->deleteMe > 0 ) { if( --object->deleteMe == 0 ) { DELETE_OBJECT( object ); --i; } } } return updated; }
WebSocket::~WebSocket(){ if(readyState != CLOSED){ this->fire("close", NULL); this->proxy_fire("close", NULL); readyState = CLOSED; } CCAssert(!pthread_equal(m_networkThread, pthread_self()), "websocket instance should not release in sub thread!"); pthread_mutex_lock(&m_responseQueueMutex); CCObject* obj; CCARRAY_FOREACH(m_responseMessage, obj){ obj->release(); } m_responseMessage->release(); pthread_mutex_unlock(&m_responseQueueMutex); pthread_mutex_destroy(&m_responseQueueMutex); if(NULL != s_pool && s_pool->containsObject(this)){ pthread_mutex_lock(&s_socketsMutex); s_pool->removeObject(this); pthread_mutex_unlock(&s_socketsMutex); } if(NULL != s_pool && s_pool->count() <= 0){ pthread_mutex_lock(&s_requestQueueMutex); //s_requestMessageQueue->removeAllObjects(); CCObject* obj; CCARRAY_FOREACH(s_requestMessageQueue, obj){ s_requestMessageQueue->removeObject(obj); JsonData* msg = (JsonData*)obj; CC_SAFE_DELETE(msg); }
void CCMsgManager::update() { // >> locked m_bDispatchMsgLocked = true; if(!m_vMsgQueue.empty()) { vector<ccMESSAGE4>::iterator citr = m_vMsgQueue.begin(); vector<ccMESSAGE4>::iterator cend = m_vMsgQueue.end(); for(; citr != cend; ++citr ) { ccMESSAGE4& tagMsg = *citr; vector<CCMsgDelegate*>::iterator hitr = m_vMsgDelegates.begin(); vector<CCMsgDelegate*>::iterator hend = m_vMsgDelegates.end(); for(; hitr != hend; ++hitr ) { (*hitr)->onMessage(tagMsg.uMsg, tagMsg.pMsgObj, tagMsg.wParam, tagMsg.lParam); } CC_SAFE_RELEASE(tagMsg.pMsgObj); } m_vMsgQueue.clear(); } if(!m_vTargetMsgQueue.empty()) { vector<ccTARGETMESSAGE4>::iterator citr = m_vTargetMsgQueue.begin(); vector<ccTARGETMESSAGE4>::iterator cend = m_vTargetMsgQueue.end(); for(; citr != cend; ++citr ) { ccTARGETMESSAGE4& tagTarget = *citr; ccMESSAGE4& tagMsg = tagTarget.tMessage; tagTarget.pDelegate->onMessage(tagMsg.uMsg, tagMsg.pMsgObj, tagMsg.wParam, tagMsg.lParam); CCObject* pObj = dynamic_cast<CCObject*>(tagTarget.pDelegate); CC_SAFE_RELEASE(pObj); CC_SAFE_RELEASE(tagMsg.pMsgObj); } m_vTargetMsgQueue.clear(); } m_bDispatchMsgLocked = false; // << unlocked while(!m_vMsgDelegatesAdded.empty()) { CCMsgDelegate* pDelegate = m_vMsgDelegatesAdded.front(); m_vMsgDelegates.insert(m_vMsgDelegates.begin(), pDelegate); m_vMsgDelegatesAdded.erase(m_vMsgDelegatesAdded.begin()); } while(!m_vMsgDelegatesRemoved.empty()) { CCMsgDelegate* pDelegate = m_vMsgDelegatesRemoved.front(); vector<CCMsgDelegate*>::iterator itr = std::find(m_vMsgDelegates.begin(),m_vMsgDelegates.end(),pDelegate); if( itr != m_vMsgDelegates.end() ) { m_vMsgDelegates.erase(itr); } CCObject* pObject = dynamic_cast<CCObject*>(pDelegate); pObject->release(); m_vMsgDelegatesRemoved.erase(m_vMsgDelegatesRemoved.begin()); } if(!m_vMsgTemps.empty()) { m_vMsgQueue.insert(m_vMsgQueue.end(), m_vMsgTemps.begin(), m_vMsgTemps.end()); m_vMsgTemps.clear(); } if(!m_vTargetMsgTemps.empty()) { m_vTargetMsgQueue.insert(m_vTargetMsgQueue.end(), m_vTargetMsgTemps.begin(), m_vTargetMsgTemps.end()); m_vTargetMsgTemps.clear(); } }
void AGSDeSerializer::Unserialize(int index, const char *objectType, const char *serializedData, int dataSize) { if (strcmp(objectType, "GUIObject") == 0) { ccDynamicGUIObject.Unserialize(index, serializedData, dataSize); } else if (strcmp(objectType, "Character") == 0) { ccDynamicCharacter.Unserialize(index, serializedData, dataSize); } else if (strcmp(objectType, "Hotspot") == 0) { ccDynamicHotspot.Unserialize(index, serializedData, dataSize); } else if (strcmp(objectType, "Region") == 0) { ccDynamicRegion.Unserialize(index, serializedData, dataSize); } else if (strcmp(objectType, "Inventory") == 0) { ccDynamicInv.Unserialize(index, serializedData, dataSize); } else if (strcmp(objectType, "Dialog") == 0) { ccDynamicDialog.Unserialize(index, serializedData, dataSize); } else if (strcmp(objectType, "GUI") == 0) { ccDynamicGUI.Unserialize(index, serializedData, dataSize); } else if (strcmp(objectType, "Object") == 0) { ccDynamicObject.Unserialize(index, serializedData, dataSize); } else if (strcmp(objectType, "String") == 0) { ScriptString *scf = new ScriptString(); scf->Unserialize(index, serializedData, dataSize); } else if (strcmp(objectType, "File") == 0) { // files cannot be restored properly -- so just recreate // the object; attempting any operations on it will fail sc_File *scf = new sc_File(); ccRegisterUnserializedObject(index, scf, scf); } else if (strcmp(objectType, "Overlay") == 0) { ScriptOverlay *scf = new ScriptOverlay(); scf->Unserialize(index, serializedData, dataSize); } else if (strcmp(objectType, "DateTime") == 0) { ScriptDateTime *scf = new ScriptDateTime(); scf->Unserialize(index, serializedData, dataSize); } else if (strcmp(objectType, "ViewFrame") == 0) { ScriptViewFrame *scf = new ScriptViewFrame(); scf->Unserialize(index, serializedData, dataSize); } else if (strcmp(objectType, "DynamicSprite") == 0) { ScriptDynamicSprite *scf = new ScriptDynamicSprite(); scf->Unserialize(index, serializedData, dataSize); } else if (strcmp(objectType, "DrawingSurface") == 0) { ScriptDrawingSurface *sds = new ScriptDrawingSurface(); sds->Unserialize(index, serializedData, dataSize); if (sds->isLinkedBitmapOnly) { dialogOptionsRenderingSurface = sds; } } else if (strcmp(objectType, "DialogOptionsRendering") == 0) { ccDialogOptionsRendering.Unserialize(index, serializedData, dataSize); } else if (!unserialize_audio_script_object(index, objectType, serializedData, dataSize)) { // check if the type is read by a plugin for (int ii = 0; ii < numPluginReaders; ii++) { if (strcmp(objectType, pluginReaders[ii].type) == 0) { pluginReaders[ii].reader->Unserialize(index, serializedData, dataSize); return; } } quitprintf("Unserialise: unknown object type: '%s'", objectType); } }