CCParticleSystemQuad::~CCParticleSystemQuad() { if (NULL == m_pBatchNode) { CC_SAFE_FREE(m_pQuads); CC_SAFE_FREE(m_pIndices); glDeleteBuffers(2, &m_pBuffersVBO[0]); #if CC_TEXTURE_ATLAS_USE_VAO glDeleteVertexArrays(1, &m_uVAOname); #endif } extension::CCNotificationCenter::sharedNotificationCenter()->removeObserver(this, EVNET_COME_TO_FOREGROUND); }
bool CCTextureAtlas::initWithTexture(CCTexture2D *texture, unsigned int capacity) { // CCAssert(texture != NULL, "texture should not be null"); m_uCapacity = capacity; m_uTotalQuads = 0; // retained in property this->m_pTexture = texture; CC_SAFE_RETAIN(m_pTexture); // Re-initialization is not allowed CCAssert(m_pQuads == NULL && m_pIndices == NULL, ""); m_pQuads = (ccV3F_C4B_T2F_Quad*)malloc( m_uCapacity * sizeof(ccV3F_C4B_T2F_Quad) ); m_pIndices = (GLushort *)malloc( m_uCapacity * 6 * sizeof(GLushort) ); if( ! ( m_pQuads && m_pIndices) && m_uCapacity > 0) { //CCLOG("cocos2d: CCTextureAtlas: not enough memory"); CC_SAFE_FREE(m_pQuads); CC_SAFE_FREE(m_pIndices); // release texture, should set it to null, because the destruction will // release it too. see cocos2d-x issue #484 CC_SAFE_RELEASE_NULL(m_pTexture); return false; } memset( m_pQuads, 0, m_uCapacity * sizeof(ccV3F_C4B_T2F_Quad) ); memset( m_pIndices, 0, m_uCapacity * 6 * sizeof(GLushort) ); // listen the event when app go to background extension::CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(CCTextureAtlas::listenBackToForeground), EVNET_COME_TO_FOREGROUND, NULL); this->setupIndices(); #if CC_TEXTURE_ATLAS_USE_VAO setupVBOandVAO(); #else setupVBO(); #endif m_bDirty = true; return true; }
void CCActionManager::deleteHashElement(tHashElement *&pElement) { ccArrayFree(pElement->actions); HASH_DEL(m_pTargets, pElement); pElement->target->release(); CC_SAFE_FREE(pElement); }
jobject CCUtilsAndroid::newIntent(const char* activityName) { // get context jobject context = getContext(); // find constructor JniMethodInfo t; JniHelper::getMethodInfo(t, "android/content/Intent", "<init>", "(Landroid/content/Context;Ljava/lang/Class;)V"); // create activity name size_t len = strlen(activityName); char* jniName = (char*)calloc(len + 1, sizeof(char)); for(int i = 0; i < len; i++) { if(activityName[i] == '.') jniName[i] = '/'; else jniName[i] = activityName[i]; } jclass actClass = t.env->FindClass(jniName); // new intent jobject intent = t.env->NewObject(t.classID, t.methodID, context, actClass); // clear t.env->DeleteLocalRef(actClass); t.env->DeleteLocalRef(context); CC_SAFE_FREE(jniName); t.env->DeleteLocalRef(t.classID); return intent; }
CCTextureAtlas::~CCTextureAtlas() { CCLOGINFO("cocos2d: CCTextureAtlas deallocing %p.", this); CC_SAFE_FREE(m_pQuads); CC_SAFE_FREE(m_pIndices); glDeleteBuffers(2, m_pBuffersVBO); #if CC_TEXTURE_ATLAS_USE_VAO glDeleteVertexArrays(1, &m_uVAOname); #endif CC_SAFE_RELEASE(m_pTexture); extension::CCNotificationCenter::sharedNotificationCenter()->removeObserver(this, EVNET_COME_TO_FOREGROUND); }
bool ImageAlphaLut::initWithFile(const std::string file) { // // 打开文件 // auto fp = fopen(FileUtils::getInstance()->fullPathForFilename(file).c_str(), "rb"); // // 获取文件大小 // fseek(fp, 0, SEEK_END); // long fs = ftell(fp); // rewind(fp); auto data = FileUtils::getInstance()->getDataFromFile(file); auto buff = data.getBytes(); data.fastSet(nullptr, 0); // 分配文件头信息 BUFF // unsigned char * buff = (unsigned char *)malloc(fs); // 读取文件头信息 // size_t rs = fread(buff, sizeof(unsigned char), fs, fp); // CCASSERT(rs == fs, "Read file info error"); // fclose(fp); int * p = (int *)buff; bool b = initWithBuff(++p); CC_SAFE_FREE(buff); return b; }
void ImageAlphaLut::moveBuffer() { // Move buffer // new buffef auto buff = static_cast<unsigned char *>(malloc(getBufferSize())); memset(buff, 0, getBufferSize()); // 计算前面的偏移 auto offsetBuff = _width * _offsetY + _offsetX; for (int i = 0; i < _offsetHeight; ++i) { for (int j = 0; j < _offsetWidth; ++j) { // 复制信息 if (getPixelAlpha(offsetBuff + i * _width + j)) { copyPixelAlpha(i * _offsetWidth + j, buff); } } } // 删除原 BUFF CC_SAFE_FREE(_alphaLut); // 指向偏移 BUFF _alphaLut = buff; buff = nullptr; }
void CC3BitmapFontConfiguration::purgeCharDefDictionary() { CC3BitmapCharDefHashElement *current, *tmp; HASH_ITER(hh, m_charDefDictionary, current, tmp) { HASH_DEL(m_charDefDictionary, current); CC_SAFE_FREE(current); }
ParticleSystemQuad::~ParticleSystemQuad() { if (NULL == _batchNode) { CC_SAFE_FREE(_quads); CC_SAFE_FREE(_indices); glDeleteBuffers(2, &_buffersVBO[0]); #if CC_TEXTURE_ATLAS_USE_VAO glDeleteVertexArrays(1, &_VAOname); GL::bindVAO(0); #endif } #if CC_ENABLE_CACHE_TEXTURE_DATA NotificationCenter::getInstance()->removeObserver(this, EVNET_COME_TO_FOREGROUND); #endif }
bool CNData::init(void) { CC_SAFE_FREE(m_pDataBuffer); m_pDataBuffer = NULL; m_iBufferLength = 0; m_bIsDataValid = false; return true; }
void ParticleSystemQuad::setBatchNode(ParticleBatchNode * batchNode) { if( _batchNode != batchNode ) { ParticleBatchNode* oldBatch = _batchNode; ParticleSystem::setBatchNode(batchNode); // NEW: is self render ? if( ! batchNode ) { allocMemory(); initIndices(); setTexture(oldBatch->getTexture()); if (Configuration::getInstance()->supportsShareableVAO()) { setupVBOandVAO(); } else { setupVBO(); } } // OLD: was it self render ? cleanup else if( !oldBatch ) { // copy current state to batch V3F_C4B_T2F_Quad *batchQuads = _batchNode->getTextureAtlas()->getQuads(); V3F_C4B_T2F_Quad *quad = &(batchQuads[_atlasIndex] ); memcpy( quad, _quads, _totalParticles * sizeof(_quads[0]) ); CC_SAFE_FREE(_quads); CC_SAFE_FREE(_indices); glDeleteBuffers(2, &_buffersVBO[0]); memset(_buffersVBO, 0, sizeof(_buffersVBO)); if (Configuration::getInstance()->supportsShareableVAO()) { glDeleteVertexArrays(1, &_VAOname); GL::bindVAO(0); _VAOname = 0; } } } }
void ImageAlphaLut::resetBuffer() { // 清除之前的 BUFF CC_SAFE_FREE(_alphaLut); // 重新分配 BUFF _alphaLut = static_cast<unsigned char*>(malloc( getBufferSize() )); // 初始化为 0 memset(_alphaLut, 0, getBufferSize()); }
LCWordPuzzleGame::~LCWordPuzzleGame() { CC_SAFE_RELEASE_NULL(m_pLoadedSprites); CC_SAFE_RELEASE_NULL(m_pBlockSprites); CC_SAFE_RELEASE_NULL(m_pCharacterSprites); CC_SAFE_RELEASE_NULL(m_pFinishedCharacterSprites); CC_SAFE_RELEASE_NULL(m_pIndexArray); CC_SAFE_FREE(m_pCurrentWord); }
void PRFilledPolygon::setPoints(Vector2dVector &points) { CC_SAFE_FREE(areaTrianglePoints); CC_SAFE_FREE(textureCoordinates); Vector2dVector triangulatedPoints = PRRatcliffTriangulator::triangulateVertices(points); areaTrianglePointCount = triangulatedPoints.size(); areaTrianglePoints = (CCPoint*) malloc(sizeof(CCPoint) * areaTrianglePointCount); textureCoordinates = (CCPoint*) malloc(sizeof(CCPoint) * areaTrianglePointCount); for (int i = 0; i < areaTrianglePointCount; i++) { Vector2d v = (Vector2d)triangulatedPoints.at(i); areaTrianglePoints[i] = CCPointMake(v.GetX(), v.GetY()); } calculateTextureCoordinates(); }
TextureAtlas::~TextureAtlas() { CCLOGINFO("cocos2d: TextureAtlas deallocing %p.", this); CC_SAFE_FREE(_quads); CC_SAFE_FREE(_indices); glDeleteBuffers(2, _buffersVBO); #if CC_TEXTURE_ATLAS_USE_VAO glDeleteVertexArrays(1, &_VAOname); GL::bindVAO(0); #endif CC_SAFE_RELEASE(_texture); #if CC_ENABLE_CACHE_TEXTURE_DATA NotificationCenter::getInstance()->removeObserver(this, EVNET_COME_TO_FOREGROUND); #endif }
void ProgressTimer::setReverseProgress(bool reverse) { if( _reverseDirection != reverse ) { _reverseDirection = reverse; // release all previous information CC_SAFE_FREE(_vertexData); _vertexDataCount = 0; } }
void CCProgressTimer::setReverseProgress(bool reverse) { if( m_bReverseDirection != reverse ) { m_bReverseDirection = reverse; // release all previous information CC_SAFE_FREE(m_pVertexData); m_nVertexDataCount = 0; } }
int lua_cocos2dx_physics_PhysicsShapePolygon_calculateArea(lua_State* tolua_S) { int argc = 0; bool ok = true; #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; #endif #if COCOS2D_DEBUG >= 1 if (!tolua_isusertable(tolua_S,1,"cc.PhysicsShapePolygon",0,&tolua_err)) goto tolua_lerror; #endif argc = lua_gettop(tolua_S) - 1; if (argc == 1) { cocos2d::Point* arg0; int arg1 = 0; do { ok = luaval_to_array_of_Point(tolua_S, 2, &arg0, &arg1); if (nullptr == arg0){ LUA_PRECONDITION( arg0, "Invalid Native Object"); }} while (0); if(!ok) { CC_SAFE_FREE(arg0); return 0; } double ret = cocos2d::PhysicsShapePolygon::calculateArea(arg0, arg1); CC_SAFE_FREE(arg0); tolua_pushnumber(tolua_S,(lua_Number)ret); return 1; } CCLOG("%s has wrong number of arguments: %d, was expecting %d\n ", "calculateArea",argc, 2); return 0; #if COCOS2D_DEBUG >= 1 tolua_lerror: tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics_PhysicsShapePolygon_calculateArea'.",&tolua_err); #endif return 0; }
void EventDataManager::deleteTalkMap() { for (std::map<int,stTalk *>::iterator _iter = mTalkMap.begin(); _iter != mTalkMap.end() ; _iter++ ) { stTalk *tmpTalk = _iter->second; CC_SAFE_FREE(tmpTalk); } mTalkMap.clear(); }
std::string CCBuffer::readString(unsigned int u_len) { DO_ASSERT(LD(u_len, 0), "LD(u_len, 0)"); std::string str; DO_ASSIGN(char* p_data, (char*)malloc(CA(u_len, 1))); readData(p_data, u_len); DO_ASSIGN(p_data[u_len], 0); str.assign(p_data); CC_SAFE_FREE(p_data); return str; }
static ForceSettingLayer* create(GMXLayer& layer) { auto ret = new (std::nothrow) ForceSettingLayer(layer); if ( ret && ret->init() ) { ret->autorelease(); return ret; } CC_SAFE_FREE(ret); return nullptr; }
CCTextureAtlas::~CCTextureAtlas ( KDvoid ) { CCLOGINFO ( "XMCocos2D : deallocing CCTextureAtlas = %p.", this ); CC_SAFE_FREE ( m_pQuads ); CC_SAFE_FREE ( m_pIndices ); glDeleteBuffers ( 2, m_pBuffersVBO ); #if CC_TEXTURE_ATLAS_USE_VAO glDeleteVertexArrays ( 1, &m_uVAOname ); ccGLBindVAO ( 0 ); #endif CC_SAFE_RELEASE ( m_pTexture ); #if CC_ENABLE_CACHE_TEXTURE_DATA CCNotificationCenter::sharedNotificationCenter ( )->removeObserver ( this, EVENT_COME_TO_FOREGROUND ); #endif }
void EventDataManager::deleteNpcMap() { for (std::map<int,stNPC *>::iterator _iter = mNpcMap.begin(); _iter != mNpcMap.end() ; _iter++ ) { stNPC *tmpNPC = _iter->second; CC_SAFE_FREE(tmpNPC); } mNpcMap.clear(); }
TextureAtlas::~TextureAtlas() { CCLOGINFO("deallocing TextureAtlas: %p", this); CC_SAFE_FREE(_quads); CC_SAFE_FREE(_indices); glDeleteBuffers(2, _buffersVBO); if (Configuration::getInstance()->supportsShareableVAO()) { glDeleteVertexArrays(1, &_VAOname); GL::bindVAO(0); } CC_SAFE_RELEASE(_texture); #if CC_ENABLE_CACHE_TEXTURE_DATA Director::getInstance()->getEventDispatcher()->removeEventListener(_rendererRecreatedListener); #endif }
std::string SimulatorWin::getApplicationExePath() { TCHAR szFileName[MAX_PATH]; GetModuleFileName(NULL, szFileName, MAX_PATH); std::u16string u16ApplicationName; char *applicationExePath = convertTCharToUtf8(szFileName); std::string path(applicationExePath); CC_SAFE_FREE(applicationExePath); return path; }
void EasyPolygon::setPoints(Vector2dVector &points) { if (points.size() <= 0) { areaTrianglePointCount = 0; return; } CC_SAFE_FREE(areaTrianglePoints); CC_SAFE_FREE(textureCoordinates); /*Vector2dVector triangulatedPoints = PRRatcliffTriangulator::triangulateVertices(points); areaTrianglePointCount = (int)triangulatedPoints.size(); areaTrianglePoints = (Point*) malloc(sizeof(Point) * areaTrianglePointCount); textureCoordinates = (Point*) malloc(sizeof(Point) * areaTrianglePointCount); for (int i = 0; i < areaTrianglePointCount; i++) { Vector2d v = (Vector2d)triangulatedPoints.at(i); areaTrianglePoints[i] = Point(v.GetX(), v.GetY()); // printf("x = %f, y = %f\n", v.GetX, v.GetY); }*/ areaTrianglePointCount = 6; areaTrianglePoints = (Point*) malloc(sizeof(Point) * areaTrianglePointCount); textureCoordinates = (Point*) malloc(sizeof(Point) * areaTrianglePointCount); Vector2d v = points.at(0); areaTrianglePoints[0] = Point(v.GetX(), v.GetY()); v = points.at(3); areaTrianglePoints[1] = Point(v.GetX(), v.GetY()); v = points.at(2); areaTrianglePoints[2] = Point(v.GetX(), v.GetY()); v = points.at(2); areaTrianglePoints[3] = Point(v.GetX(), v.GetY()); v = points.at(1); areaTrianglePoints[4] = Point(v.GetX(), v.GetY()); v = points.at(0); areaTrianglePoints[5] = Point(v.GetX(), v.GetY()); calculateTextureCoordinates(); }
void CCParticleSystemQuad::setBatchNode(CCParticleBatchNode * batchNode) { if( m_pBatchNode != batchNode ) { CCParticleBatchNode* oldBatch = m_pBatchNode; CCParticleSystem::setBatchNode(batchNode); // NEW: is self render ? if( ! batchNode ) { allocMemory(); initIndices(); setTexture(oldBatch->getTexture()); #if CC_TEXTURE_ATLAS_USE_VAO setupVBOandVAO(); #else setupVBO(); #endif } // OLD: was it self render ? cleanup else if( !oldBatch ) { // copy current state to batch ccV3F_C4B_T2F_Quad *batchQuads = m_pBatchNode->getTextureAtlas()->getQuads(); ccV3F_C4B_T2F_Quad *quad = &(batchQuads[m_uAtlasIndex] ); memcpy( quad, m_pQuads, m_uTotalParticles * sizeof(m_pQuads[0]) ); CC_SAFE_FREE(m_pQuads); CC_SAFE_FREE(m_pIndices); glDeleteBuffers(2, &m_pBuffersVBO[0]); memset(m_pBuffersVBO, 0, sizeof(m_pBuffersVBO)); #if CC_TEXTURE_ATLAS_USE_VAO glDeleteVertexArrays(1, &m_uVAOname); ccGLBindVAO(0); m_uVAOname = 0; #endif } } }
CCString * CCBReader::concat(CCString * pStringA, CCString * pStringB) { int concatenatedLength = pStringA->length() + pStringB->length(); char* concatenated = (char*) malloc(concatenatedLength+1); CCString* pRet = NULL; strcpy(concatenated, pStringA->getCString()); strcat(concatenated, pStringB->getCString()); concatenated[concatenatedLength] = '\0'; pRet = CCString::create(concatenated); CC_SAFE_FREE(concatenated); return pRet; }
bool CCParticleSystem::initWithTotalParticles(unsigned int numberOfParticles) { m_uTotalParticles = numberOfParticles; CC_SAFE_FREE(m_pParticles); m_pParticles = (tCCParticle*)calloc(m_uTotalParticles, sizeof(tCCParticle)); if( ! m_pParticles ) { CCLOG("Particle system: not enough memory"); this->release(); return false; } m_uAllocatedParticles = numberOfParticles; if (m_pBatchNode) { for (int i = 0; i < m_uTotalParticles; i++) { m_pParticles[i].atlasIndex=i; } } // default, active m_bIsActive = true; // default blend function m_tBlendFunc.src = CC_BLEND_SRC; m_tBlendFunc.dst = CC_BLEND_DST; // default movement type; m_ePositionType = kCCPositionTypeFree; // by default be in mode A: m_nEmitterMode = kCCParticleModeGravity; // default: modulate // XXX: not used // colorModulate = YES; m_bIsAutoRemoveOnFinish = false; // Optimization: compile udpateParticle method //updateParticleSel = @selector(updateQuadWithParticle:newPosition:); //updateParticleImp = (CC_UPDATE_PARTICLE_IMP) [self methodForSelector:updateParticleSel]; //for batchNode m_bTransformSystemDirty = false; // udpate after action in run! this->scheduleUpdateWithPriority(1); return true; }
TMXLayer::~TMXLayer() { CC_SAFE_RELEASE(_tileSet); CC_SAFE_RELEASE(_reusedTile); if (_atlasIndexArray) { ccCArrayFree(_atlasIndexArray); _atlasIndexArray = nullptr; } CC_SAFE_FREE(_tiles); }