Exemplo n.º 1
0
	CCTMXLayer::~CCTMXLayer()
	{
		CC_SAFE_RELEASE(m_pTileSet);
		CC_SAFE_RELEASE(m_pReusedTile);
		CC_SAFE_RELEASE(m_pProperties);

		if( m_pAtlasIndexArray )
		{
			ccCArrayFree(m_pAtlasIndexArray);
			m_pAtlasIndexArray = NULL;
		}

		CC_SAFE_DELETE_ARRAY(m_pTiles);
	}
void CARenderImage::end()
{
    GLubyte *pBuffer = pBuffer = new GLubyte[m_uPixelsWide * m_uPixelsHigh * 4];
    GLubyte *pTempData = new GLubyte[m_uPixelsWide * m_uPixelsHigh * 4];
    
    glPixelStorei(GL_PACK_ALIGNMENT, 1);
    glReadPixels(0, 0, m_uPixelsWide, m_uPixelsHigh, GL_RGBA, GL_UNSIGNED_BYTE, pTempData);
    glBindFramebuffer(GL_FRAMEBUFFER, m_nOldFBO);

    CAApplication::getApplication()->setViewport();

    kmGLMatrixMode(KM_GL_PROJECTION);
	kmGLPopMatrix();
	kmGLMatrixMode(KM_GL_MODELVIEW);
	kmGLPopMatrix();

    m_pImage = new CAImage();
    m_pImage->initWithRawData(pTempData, CAImage::PixelFormat_RGBA8888, m_uPixelsWide, m_uPixelsHigh);
    m_pImageView->setImage(m_pImage);
    m_pImage->release();
    CC_SAFE_DELETE_ARRAY(pBuffer);
    CC_SAFE_DELETE_ARRAY(pTempData);
}
Exemplo n.º 3
0
bool PhysicsShapeEdgePolygon::init(const Point* points, int count, const PhysicsMaterial& material/* = MaterialDefault*/, float border/* = 1*/)
{
    cpVect* vec = nullptr;
    do
    {
        CC_BREAK_IF(!PhysicsShape::init(Type::EDGEPOLYGEN));
        
        vec = new cpVect[count];
        PhysicsHelper::points2cpvs(points, vec, count);
        _center = PhysicsHelper::cpv2point(cpCentroidForPoly(count, vec));
        
        int i = 0;
        for (; i < count; ++i)
        {
            cpShape* shape = cpSegmentShapeNew(_info->getSharedBody(), vec[i], vec[(i+1)%count],
                                               PhysicsHelper::float2cpfloat(border));
            CC_BREAK_IF(shape == nullptr);
			cpShapeSetElasticity(shape, 1.0f);
			cpShapeSetFriction(shape, 1.0f);
            _info->add(shape);
        }
        CC_SAFE_DELETE_ARRAY(vec);
        
        CC_BREAK_IF(i < count);
        
        _mass = PHYSICS_INFINITY;
        _moment = PHYSICS_INFINITY;
        
        setMaterial(material);
        
        return true;
    } while (false);
    
    CC_SAFE_DELETE_ARRAY(vec);
    
    return false;
}
CCDictionary* createCCDictionaryWithData(unsigned char* data)
{
    CCAssert((data),"data must not be NULL!!!");
    
    CCDictMaker tMaker;
	CCDictionary* dict = tMaker.dictionaryWithData(data);
	
    if (dict != NULL)
    {
        dict->autorelease();
    }
	CC_SAFE_DELETE_ARRAY(data);
	
	return dict;
}
Exemplo n.º 5
0
bool PhysicsShapeEdgePolygon::init(const Vec2* points, int count, const PhysicsMaterial& material/* = MaterialDefault*/, float border/* = 1*/)
{
    cpVect* vec = nullptr;
    do
    {
        _type = Type::EDGEPOLYGEN;
        
        vec = new (std::nothrow) cpVect[count];
        PhysicsHelper::points2cpvs(points, vec, count);
        
        int i = 0;
        for (; i < count; ++i)
        {
            auto shape = cpSegmentShapeNew(s_sharedBody, vec[i], vec[(i + 1) % count], border);
            CC_BREAK_IF(shape == nullptr);
            cpShapeSetUserData(shape, this);
            cpShapeSetElasticity(shape, 1.0f);
            cpShapeSetFriction(shape, 1.0f);
            addShape(shape);
        }
        CC_SAFE_DELETE_ARRAY(vec);
        
        CC_BREAK_IF(i < count);
        
        _mass = PHYSICS_INFINITY;
        _moment = PHYSICS_INFINITY;
        
        setMaterial(material);
        
        return true;
    } while (false);
    
    CC_SAFE_DELETE_ARRAY(vec);
    
    return false;
}
CCArray* createCCArrayWithData(unsigned char* data)
{
    CCAssert((data),"data must not be NULL!!!");
    
    CCDictMaker tMaker;
	CCArray* array = tMaker.arrayWithData(data);
    
    if (array != NULL)
    {
        array->autorelease();
    }
    CC_SAFE_DELETE_ARRAY(data);
    
    return array;
}
Exemplo n.º 7
0
HpCharactor* HpCharactorBinParser::parse(const char* p_file)
{
    
    m_cur_chara = new HpCharactor();
    HpBinaryReader* reader = NULL;
    
    const string& full_path = CCFileUtils::sharedFileUtils()->fullPathForFilename(p_file);
    
    unsigned long size = 0;
    char* pBuffer = (char*)CCFileUtils::sharedFileUtils()->getFileData(full_path.c_str(), "rt", &size);
    if (pBuffer != NULL && size > 0)
    {
        reader = new HpBinaryReader(pBuffer, size);
    }
    
    char buffer[128] = {0};
    
    reader->ReadChars(buffer, 3);
    if (strncasecmp(buffer, "CHR", 3) != 0) return NULL;
    
    ChrReadingVersion = reader->ReadByte();
    
    if (ChrReadingVersion > ChrReadingVersionMax) {
        CCLOG("HpCharactorBinParser max reader version is %d, but the file version is %d", ChrReadingVersionMax, ChrReadingVersion);
        CCAssert(0, "");
        return NULL;
    }
    
    Byte plist_count = reader->ReadByte();
    for(int i=0; i<plist_count;i++)
    {
        reader->ReadString(buffer);
        char* p = strrchr(buffer, '\\');
        m_cur_chara->getPLists()->addObject(CCString::create(p ? p+1 : buffer));
    }
    
    unsigned short anim_count = reader->ReadUInt16();
    for(int i=0; i<anim_count; i++) {
        readAnimation(reader, buffer);
    }
    
    reader->Close();
    CC_SAFE_DELETE(reader);
    CC_SAFE_DELETE_ARRAY(pBuffer);
    
    
    return m_cur_chara;
}
Exemplo n.º 8
0
void ObstacleManager::ReadFile(std::string fileName , std::string &obsPattern , int index)
{
    
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    {
        std::ifstream fin;
        std::string thisline;
        
        fin.open(CCFileUtils::sharedFileUtils()->fullPathForFilename(fileName.c_str()).c_str());
        fin>>thisline; //reading pattern Distance..
        
        allObstacleChunks[index].patternDistance = atoi(thisline.c_str()); //assigning
        
        fin>>thisline;
        obsPattern = thisline;
        fin.close();
        
    }
#else
    {
        unsigned long size = 0;
        char* pBuffer = (char*)CCFileUtils::sharedFileUtils()->getFileData(fileName.c_str(), "rt", &size);
        int count = 0;
        std::string patternDistance = "";
        for (int i = count ; pBuffer[i] != '\n' ; i++ )
        {
            patternDistance += pBuffer[i];
            count++;
        }
        
        count++;
        
        allObstacleChunks[index].patternDistance = atoi(patternDistance.c_str());
        

        std::string line = "";
        for (int j = count ; pBuffer[j] != '\n' ; j++ )
        {
            line += pBuffer[j];
            count++;
        }
        count++;
        coinPattern = line.c_str();

        CC_SAFE_DELETE_ARRAY(pBuffer);
    }
#endif
}
Exemplo n.º 9
0
bool CCParticleSystem::initWithTotalParticles(unsigned int numberOfParticles)
{
	m_uTotalParticles = numberOfParticles;

    CC_SAFE_DELETE_ARRAY(m_pParticles);
	
	m_pParticles = new tCCParticle[m_uTotalParticles];

	if( ! m_pParticles )
	{
		CCLOG("Particle system: not enough memory");
		this->release();
		return false;
	}

	// 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;

	// profiling
#if CC_ENABLE_PROFILERS
	/// @todo _profilingTimer = [[CCProfiler timerWithName:@"particle system" andInstance:self] retain];
#endif

	// Optimization: compile udpateParticle method
	//updateParticleSel = @selector(updateQuadWithParticle:newPosition:);
	//updateParticleImp = (CC_UPDATE_PARTICLE_IMP) [self methodForSelector:updateParticleSel];

	// udpate after action in run!
	this->scheduleUpdateWithPriority(1);

	return true;
}
Exemplo n.º 10
0
const char* Utils::readRC4LuaFile(const char* fileName)
{
	readFromFile
    unsigned long size = 0;
    unsigned char* pData = cocos2d::CCFileUtils::sharedFileUtils()->getFileData(fileName, "rb", &size);
    
    std::string OUTKEY = Utils::getOutKeyFile();
    char *temp = new char[size + 1];
	memset(temp, 0, size + 1);
    rc4_state state;
    rc4_init(&state, (const u_char *)OUTKEY.c_str(), OUTKEY.size());
    rc4_crypt(&state, (const u_char *)pData, (u_char *)temp, size);
    
    CC_SAFE_DELETE_ARRAY(pData);
    return temp;
}
Exemplo n.º 11
0
void CC3GLSLUniform::populateFromGL()
{
	if ( _program == NULL )
		return;

	GLint maxNameLen = _program->getMaxUniformNameLength();
	char* cName = new char[maxNameLen];

	glGetActiveUniform( _program->getProgramID(), _index, maxNameLen, NULL, &_size, &_type, cName );

	_location = glGetUniformLocation( _program->getProgramID(), cName );

	_name = cName;

	CC_SAFE_DELETE_ARRAY( cName );
}
Exemplo n.º 12
0
bool CCComAttribute::parse(const std::string &jsonPath)
{
    bool bRet = false;
    unsigned long size = 0;
    unsigned char *pBytes = NULL;
    do {
          pBytes = cocos2d::CCFileUtils::sharedFileUtils()->getFileData(jsonPath.c_str(), "r", &size);
          CC_BREAK_IF(pBytes == NULL || strcmp((char*)pBytes, "") == 0);
          std::string load_str((const char*)pBytes, size);
          CC_SAFE_DELETE_ARRAY(pBytes);
          _doc.Parse<0>(load_str.c_str());
          CC_BREAK_IF(_doc.HasParseError());
          bRet = true;
        } while (0);
    return bRet;
}
Exemplo n.º 13
0
// Load local file "text_[LanguageCode].json"
bool THLocalizer::load()
{
    // Load file
    std::string fileName = this->withLocaleString("pkg_common/json/text.json");

    /*
     * cocos2dx v2.1.4 deplicated CCFileUtils::fullPathFromRelativePath()
     * CCFileUtils::fullPathFromRelativePath() is not thread-safe, it use autorelease().
     *
     * std::string path = cocos2d::CCFileUtils::sharedFileUtils()->
     * fullPathFromRelativePath(fileName.c_str());
     */
    std::string path = cocos2d::CCFileUtils::sharedFileUtils()->fullPathForFilename(fileName.c_str());



    // When localization file is not exists
//	if(!THFileUtil::existFile(path.c_str()))
//	{
//		return false;
//	}
    // in android, doesn't work.

    unsigned long nSize = 0;
    unsigned char* pBuffer =
        cocos2d::CCFileUtils::sharedFileUtils()->getFileData(
            path.c_str(),
            "rb",
            &nSize
        );

    // Parse user default file
    std::string textString(reinterpret_cast<const char *>(pBuffer), nSize);

    // Add LeeYJ, Memory leak.
    CC_SAFE_DELETE_ARRAY(pBuffer);

    Json::Reader jsonReader;
    bool isParsed = jsonReader.parse(textString.c_str(), m_tLocalizeData);
    if(!isParsed)
    {
        m_tLocalizeData = 0;
        return false;
    }

    return true;
}
Exemplo n.º 14
0
void ccDrawCardinalSpline( CCPointArray *config, float tension,  unsigned int segments )
{
    lazy_init();

    ccVertex2F* vertices = new ccVertex2F[segments + 1];

    unsigned int p;
    float lt;
    float deltaT = 1.0f / config->count();

    for( unsigned int i=0; i < segments+1; i++) {

        float dt = (float)i / segments;

        // border
        if( dt == 1 ) {
            p = config->count() - 1;
            lt = 1;
        } else {
            p = dt / deltaT;
            lt = (dt - deltaT * (float)p) / deltaT;
        }

        // Interpolate
        CCPoint pp0 = config->getControlPointAtIndex(p-1);
        CCPoint pp1 = config->getControlPointAtIndex(p+0);
        CCPoint pp2 = config->getControlPointAtIndex(p+1);
        CCPoint pp3 = config->getControlPointAtIndex(p+2);

        CCPoint newPos = ccCardinalSplineAt( pp0, pp1, pp2, pp3, tension, lt);
        vertices[i].x = newPos.x;
        vertices[i].y = newPos.y;
    }

    s_pShader->use();
    s_pShader->setUniformsForBuiltins();
    s_pShader->setUniformLocationWith4fv(s_nColorLocation, (GLfloat*)&s_tColor.r, 1);

    ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );

    glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, vertices);
    glDrawArrays(GL_LINE_STRIP, 0, (GLsizei) segments + 1);

    CC_SAFE_DELETE_ARRAY(vertices);
    CC_INCREMENT_GL_DRAWS(1);
}
Exemplo n.º 15
0
void drawPoints( const Vec2 *points, unsigned int numberOfPoints )
{
    lazy_init();

    GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION );
    s_shader->use();
    s_shader->setUniformsForBuiltins();
    s_shader->setUniformLocationWith4fv(s_colorLocation, (GLfloat*) &s_color.r, 1);
    s_shader->setUniformLocationWith1f(s_pointSizeLocation, s_pointSize);

    // FIXME: Mac OpenGL error. arrays can't go out of scope before draw is executed
    Vec2* newPoints = new (std::nothrow) Vec2[numberOfPoints];

    // iPhone and 32-bit machines optimization
    if( sizeof(Vec2) == sizeof(Vec2) )
    {
#ifdef EMSCRIPTEN
        setGLBufferData((void*) points, numberOfPoints * sizeof(Vec2));
        glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
#else
        glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, points);
#endif // EMSCRIPTEN
    }
    else
    {
        // Mac on 64-bit
        for( unsigned int i=0; i<numberOfPoints;i++) {
            newPoints[i].x = points[i].x;
            newPoints[i].y = points[i].y;
        }
#ifdef EMSCRIPTEN
        // Suspect Emscripten won't be emitting 64-bit code for a while yet,
        // but want to make sure this continues to work even if they do.
        setGLBufferData(newPoints, numberOfPoints * sizeof(Vec2));
        glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
#else
        glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, newPoints);
#endif // EMSCRIPTEN
    }

    glDrawArrays(GL_POINTS, 0, (GLsizei) numberOfPoints);

    CC_SAFE_DELETE_ARRAY(newPoints);

    CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, numberOfPoints);
}
Exemplo n.º 16
0
void EffectManager::readData(const char* filename)
{
	ssize_t fileLen = 0;
	unsigned char *fileData = NULL;
	fileData = CCFileUtils::sharedFileUtils()->getFileData(CCFileUtils::sharedFileUtils()->fullPathForFilename(filename).c_str(), "rb", (ssize_t *)(&fileLen));
	unsigned char* temp = fileData;
	unsigned long pos = 0;
	while (pos<(fileLen-1))
	{
		EffectConfigData configData;
		configData.encode(fileData, pos);

		effctConfigDataDic.insert(std::map<std::string, EffectConfigData>::value_type(configData.m_effectName, configData));
	}

	CC_SAFE_DELETE_ARRAY(temp);
}
void ccDrawPoints( const CCPoint *points, unsigned int numberOfPoints )
{
    lazy_init();

    ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );
    s_pShader->use();
    s_pShader->setUniformsForBuiltins();
    s_pShader->setUniformLocationWith4fv(s_nColorLocation, (GLfloat*) &s_tColor.r, 1);
    s_pShader->setUniformLocationWith1f(s_nPointSizeLocation, s_fPointSize);

    // XXX: Mac OpenGL error. arrays can't go out of scope before draw is executed
    ccVertex2F* newPoints = new ccVertex2F[numberOfPoints];

    // iPhone and 32-bit machines optimization
    if( sizeof(CCPoint) == sizeof(ccVertex2F) )
    {
#ifdef EMSCRIPTEN
        setGLBufferData((void*) points, numberOfPoints * sizeof(CCPoint));
        glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, 0);
#else
        glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, points);
#endif // EMSCRIPTEN
    }
    else
    {
        // Mac on 64-bit
        for( unsigned int i=0; i<numberOfPoints;i++) {
            newPoints[i].x = points[i].x;
            newPoints[i].y = points[i].y;
        }
#ifdef EMSCRIPTEN
        // Suspect Emscripten won't be emitting 64-bit code for a while yet,
        // but want to make sure this continues to work even if they do.
        setGLBufferData(newPoints, numberOfPoints * sizeof(ccVertex2F));
        glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, 0);
#else
        glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, newPoints);
#endif // EMSCRIPTEN
    }

    glDrawArrays(GL_POINTS, 0, (GLsizei) numberOfPoints);

    CC_SAFE_DELETE_ARRAY(newPoints);

    CC_INCREMENT_GL_DRAWS(1);
}
CCBReader::~CCBReader() {
    CC_SAFE_DELETE_ARRAY(this->mBytes);

    this->mCCNodeLoaderLibrary->release();

    /* Clear string cache. */
    std::vector<CCString *>::iterator stringCacheIterator;
    for (stringCacheIterator = this->mStringCache.begin(); stringCacheIterator != this->mStringCache.end(); stringCacheIterator++) {
        (*stringCacheIterator)->release();
    }
    this->mStringCache.clear();
    
    if(this->mRootCCBReader) {
        /* Clear loaded spritesheets. */
        this->mLoadedSpriteSheets.clear();
    }
}
Exemplo n.º 19
0
    void CCLabelTTF::setFontSize(float fontSize)
    {
        if (m_fFontSize != fontSize * CC_CONTENT_SCALE_FACTOR())
        {
            m_fFontSize = fontSize * CC_CONTENT_SCALE_FACTOR();

            // Force update
            if (m_pString&& m_pString->size() > 0)
            {
                const char* str = m_pString->c_str();
                char* tmp = new char[strlen(str)+1];
                strcpy(tmp,str);
                this->setString(tmp);
                CC_SAFE_DELETE_ARRAY(tmp);
            }
        }
    }
void drawCardinalSpline( PointArray *config, float tension,  unsigned int segments )
{
    lazy_init();

    Vec2* vertices = new (std::nothrow) Vec2[segments + 1];

    ssize_t p;
    float lt;
    float deltaT = 1.0f / config->count();

    for( unsigned int i=0; i < segments+1;i++) {

        float dt = (float)i / segments;

        // border
        if( dt == 1 ) {
            p = config->count() - 1;
            lt = 1;
        } else {
            p = dt / deltaT;
            lt = (dt - deltaT * (float)p) / deltaT;
        }

        // Interpolate
        Vec2 pp0 = config->getControlPointAtIndex(p-1);
        Vec2 pp1 = config->getControlPointAtIndex(p+0);
        Vec2 pp2 = config->getControlPointAtIndex(p+1);
        Vec2 pp3 = config->getControlPointAtIndex(p+2);

        Vec2 newPos = ccCardinalSplineAt( pp0, pp1, pp2, pp3, tension, lt);
        vertices[i].x = newPos.x;
        vertices[i].y = newPos.y;
    }

    s_shader->use();
    s_shader->setUniformsForBuiltins();
    s_shader->setUniformLocationWith4fv(s_colorLocation, (GLfloat*)&s_color.r, 1);

    GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION );

    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
    glDrawArrays(GL_LINE_STRIP, 0, (GLsizei) segments + 1);

    CC_SAFE_DELETE_ARRAY(vertices);
    CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,segments+1);
}
Exemplo n.º 21
0
void ParticleFactory::InitXML()
{
	std::string pPath = 
		GameResourceManager::sharedManager()->storedFullPathFromRelativePath("Data/particles.xml");

	unsigned long	_size;
	char			*_pFileContent = (char*)CCFileUtils::sharedFileUtils()->getFileData(pPath.c_str() , "r", &_size);
	TiXmlDocument	*_document = new TiXmlDocument();
	_document->Parse(_pFileContent, 0, TIXML_ENCODING_UTF8);

	CC_SAFE_DELETE_ARRAY(_pFileContent);

	TiXmlElement *RootElement = _document->RootElement();
	if (RootElement)
	{
		TiXmlElement *childElement = RootElement->FirstChildElement();
		while (0 != childElement)
		{
			OneParticleInfo oneParticleInfo;
			TiXmlAttribute* pAttribute = childElement->FirstAttribute();
			while(pAttribute)
			{
				std::string strName(pAttribute->Name());
				std::string content = childElement->Attribute(strName.c_str());
				if (strName == "ID")
				{
					unsigned int id = atoi(content.c_str());
					oneParticleInfo.id = id;
				}
				else if (strName == "fileName")
				{
					oneParticleInfo.fileName = content;
				}
				pAttribute = pAttribute->Next();
			}
			m_particleListInfo.insert(std::make_pair(oneParticleInfo.id,oneParticleInfo));

			childElement = childElement->NextSiblingElement();
		}

		TiXmlDocument *doc = RootElement->GetDocument();
		doc->Clear();
		CC_SAFE_DELETE(doc);
	}
}
Exemplo n.º 22
0
bool CCComRender::readJson(const char *pszFileName, rapidjson::Document &doc)
{
    bool bRet = false;
    unsigned long size = 0;
    unsigned char *pBytes = NULL;
    do {
        CC_BREAK_IF(pszFileName == NULL);
        std::string jsonpath = CCFileUtils::sharedFileUtils()->fullPathForFilename(pszFileName);
        pBytes = cocos2d::CCFileUtils::sharedFileUtils()->getFileData(jsonpath.c_str(), "r", &size);
        CC_BREAK_IF(pBytes == NULL || strcmp((char*)pBytes, "") == 0);
        std::string load_str((const char*)pBytes, size);
        CC_SAFE_DELETE_ARRAY(pBytes);
        doc.Parse<0>(load_str.c_str());
        CC_BREAK_IF(doc.HasParseError());
        bRet = true;
    } while (0);
    return bRet;
}
Exemplo n.º 23
0
float PhysicsShapePolygon::calculateDefaultMoment()
{
    if(_mass == PHYSICS_INFINITY)
    {
        return PHYSICS_INFINITY;
    }
    else
    {
        auto shape = _cpShapes.front();
        int count = cpPolyShapeGetCount(shape);
        cpVect* vecs = new cpVect[count];
        for(int i=0;i<count;++i)
            vecs[i] = cpPolyShapeGetVert(shape, i);
        float moment = PhysicsHelper::cpfloat2float(cpMomentForPoly(_mass, count, vecs, cpvzero, cpPolyShapeGetRadius(shape)));
        CC_SAFE_DELETE_ARRAY(vecs);
        return moment;
    }
}
Exemplo n.º 24
0
GameScene::~GameScene()
{
    CC_SAFE_DELETE(_background1);
    CC_SAFE_DELETE(_background2);
    CC_SAFE_DELETE(_background3);
    CC_SAFE_DELETE(_background4);
    CC_SAFE_DELETE(_backgroundNode);
    CC_SAFE_DELETE(_flyingChickenNode);
    CC_SAFE_DELETE(_gameBatchNode);
    CC_SAFE_DELETE(_gameLogic);
    CC_SAFE_DELETE(_GUINode);
    CC_SAFE_DELETE(_player);
    CC_SAFE_DELETE(_rotatingShell);
    CC_SAFE_DELETE_ARRAY(_rotatingShells);
    CC_SAFE_DELETE(_sky);
    
    
}
Exemplo n.º 25
0
void GameData::readQuestsDataFile()
{
	std::string jsonPath = QUESTS_DATA_PATH;
	rapidjson::Document _doc;
	ssize_t size = 0;
	unsigned char *pBytes = NULL;
	do {
		pBytes = FileUtils::getInstance()->getFileData(jsonPath, "r", &size);
		CC_BREAK_IF(pBytes == NULL || strcmp((char*)pBytes, "") == 0);
		std::string load_str((const char*)pBytes, size);
		CC_SAFE_DELETE_ARRAY(pBytes);
		_doc.Parse<0>(load_str.c_str());
		CC_BREAK_IF(_doc.HasParseError());
		// 判断是否为一个数组
		if (!_doc.IsArray())
			return;
		const rapidjson::Value& pArray = _doc;
		for (rapidjson::SizeType i = 0; i < pArray.Size(); i++)
		{
			QuestListData* data = new QuestListData();
			const rapidjson::Value &value = pArray[i];  // value为一个对象
			data->id = value["id"].GetInt();
			data->level = value["level"].GetInt();
			data->mapID = value["mapID"].GetInt();
			data->title = value["title"].GetString();
			data->instruct = value["instruct"].GetString();
			data->type = value["type"].GetInt();
			data->status = value["status"].GetInt();
			const rapidjson::Value &mArray = value["mons_id"];
			for (int i = 0; i < mArray.Size(); i++) {
				data->mons_id.push_back(mArray[i].GetInt());
			}

			const rapidjson::Value &fArray = value["forgeID"];
			for (int i = 0; i < fArray.Size(); i++) {
				data->forgeID.push_back(fArray[i].GetInt());
			}

			data->targetNpc = value["targetNpc"].GetString();
			data->launchNpc = value["launchNpc"].GetString();
			addDataToQuestsData(data);
		}
	} while (0);
}
Exemplo n.º 26
0
// DOMString? getShaderSource(WebGLShader? shader);
JSBool JSB_glGetShaderSource(JSContext *cx, uint32_t argc, jsval *vp)
{
    JSB_PRECONDITION2( argc == 1, cx, JS_FALSE, "Invalid number of arguments" );
    jsval *argvp = JS_ARGV(cx,vp);
    JSBool ok = JS_TRUE;
    uint32_t arg0;

    ok &= jsval_to_uint( cx, *argvp++, &arg0 );
    JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");

    GLsizei length;
    glGetShaderiv(arg0, GL_SHADER_SOURCE_LENGTH, &length);
    GLchar* src = new GLchar[length];
    glGetShaderSource(arg0, length, NULL, src);

    JS_SET_RVAL(cx, vp, charptr_to_jsval(cx, src));
    CC_SAFE_DELETE_ARRAY(src);
    return JS_TRUE;
}
void ccDrawSolidPoly( const CCPoint *poli, unsigned int numberOfPoints, ccColor4F color )
{
    lazy_init();

    s_pShader->use();
    s_pShader->setUniformsForBuiltins();
    s_pShader->setUniformLocationWith4fv(s_nColorLocation, (GLfloat*) &color.r, 1);

    ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );

    // XXX: Mac OpenGL error. arrays can't go out of scope before draw is executed
    ccVertex2F* newPoli = new ccVertex2F[numberOfPoints];

    // iPhone and 32-bit machines optimization
    if( sizeof(CCPoint) == sizeof(ccVertex2F) )
    {
#ifdef EMSCRIPTEN
        setGLBufferData((void*) poli, numberOfPoints * sizeof(CCPoint));
        glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, 0);
#else
        glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, poli);
#endif // EMSCRIPTEN
    }
    else
    {
        // Mac on 64-bit
        for( unsigned int i=0; i<numberOfPoints;i++)
        {
            newPoli[i] = vertex2( poli[i].x, poli[i].y );
        }
#ifdef EMSCRIPTEN
        setGLBufferData(newPoli, numberOfPoints * sizeof(ccVertex2F));
        glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, 0);
#else
        glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, newPoli);
#endif // EMSCRIPTEN
    }    

    glDrawArrays(GL_TRIANGLE_FAN, 0, (GLsizei) numberOfPoints);

    CC_SAFE_DELETE_ARRAY(newPoli);
    CC_INCREMENT_GL_DRAWS(1);
}
Exemplo n.º 28
0
// DOMString? getShaderSource(WebGLShader? shader);
bool JSB_glGetShaderSource(JSContext *cx, uint32_t argc, jsval *vp)
{
    JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" );
    JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
    bool ok = true;
    uint32_t arg0;

    ok &= jsval_to_uint( cx, args.get(0), &arg0 );
    JSB_PRECONDITION2(ok, cx, false, "Error processing arguments");

    GLsizei length;
    glGetShaderiv(arg0, GL_SHADER_SOURCE_LENGTH, &length);
    GLchar* src = new (std::nothrow) GLchar[length];
    glGetShaderSource(arg0, length, NULL, src);

    args.rval().set(charptr_to_jsval(cx, src));
    CC_SAFE_DELETE_ARRAY(src);
    return true;
}
Exemplo n.º 29
0
void drawSolidPoly(const Vec2 *poli, unsigned int numberOfPoints, Color4F color)
{
    lazy_init();

    s_shader->use();
    s_shader->setUniformsForBuiltins();
    s_shader->setUniformLocationWith4fv(s_colorLocation, (GLfloat*) &color.r, 1);

    GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION );

    // FIXME: Mac OpenGL error. arrays can't go out of scope before draw is executed
    Vec2* newPoli = new (std::nothrow) Vec2[numberOfPoints];

    // iPhone and 32-bit machines optimization
    if (sizeof(Vec2) == sizeof(Vec2))
    {
#ifdef EMSCRIPTEN
        setGLBufferData((void*) poli, numberOfPoints * sizeof(Vec2));
        glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
#else
        glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, poli);
#endif // EMSCRIPTEN
    }
    else
    {
        // Mac on 64-bit
        for(unsigned int i = 0; i < numberOfPoints; i++)
        {
            newPoli[i] = Vec2( poli[i].x, poli[i].y );
        }
#ifdef EMSCRIPTEN
        setGLBufferData(newPoli, numberOfPoints * sizeof(Vec2));
        glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
#else
        glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, newPoli);
#endif // EMSCRIPTEN
    }    

    glDrawArrays(GL_TRIANGLE_FAN, 0, (GLsizei) numberOfPoints);

    CC_SAFE_DELETE_ARRAY(newPoli);
    CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, numberOfPoints);
}
Exemplo n.º 30
0
void 
CPrimitiveScene::draw()
{    
    CCCamera* pCamera = CCDirector::sharedDirector()->getRunningScene()->getCamera();
    pCamera->setEyeXYZ(0,0,10);
    pCamera->setCenterXYZ(-50.0f, -50.0f, 0);

    // open yellow poly
    ccDrawColor4B(255, 255, 0, 255);
    glLineWidth(10);
    ccVertex3F vertices[] = { vertex3(0,0,0), vertex3(50,50,0), vertex3(100,50,0), vertex3(100,100,0), vertex3(50,100,0.1) };
        
    s_pShader->use();
    s_pShader->setUniformForModelViewProjectionMatrix();
    s_pShader->setUniformLocationWith4fv(s_nColorLocation, (GLfloat*) &s_tColor.r, 1);

    ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );


    int numberOfPoints = 5;
    // XXX: Mac OpenGL error. arrays can't go out of scope before draw is executed
    ccVertex3F* newPoli = new ccVertex3F[numberOfPoints];

    // iPhone and 32-bit machines optimization
    if( sizeof(CCPoint) == sizeof(ccVertex3F) )
    {
        glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, 0, vertices);
    }
    else
    {
        // Mac on 64-bit
        for( unsigned int i=0; i<numberOfPoints;i++)
        {
            newPoli[i] = vertex3( vertices[i].x, vertices[i].y, vertices[i].z );
        }
        glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, 0, newPoli);
    }    

    glDrawArrays(GL_TRIANGLE_FAN, 0, (GLsizei) numberOfPoints);

    CC_SAFE_DELETE_ARRAY(newPoli);
    CC_INCREMENT_GL_DRAWS(1);
}