@@ -269,62 +269,61 @@ bool CCParticleSystem::initWithDictionary(CCDictionary *dictionary)
269
269
// don't get the internal texture if a batchNode is used
270
270
if (!m_pBatchNode)
271
271
{
272
- // texture
273
- // Try to get the texture from the cache
274
- const char * textureName = dictionary->valueForKey (" textureFileName" )->getCString ();
275
- std::string fullpath = CCFileUtils::fullPathFromRelativeFile (textureName, m_sPlistFile.c_str ());
276
-
277
- CCTexture2D *tex = NULL ;
278
-
279
- if (strlen (textureName) > 0 )
280
- {
281
- // set not pop-up message box when load image failed
282
- bool bNotify = CCFileUtils::getIsPopupNotify ();
283
- CCFileUtils::setIsPopupNotify (false );
284
- tex = CCTextureCache::sharedTextureCache ()->addImage (fullpath.c_str ());
285
-
286
- // reset the value of UIImage notify
287
- CCFileUtils::setIsPopupNotify (bNotify);
288
- }
289
-
290
- if (tex)
291
- {
292
- setTexture (tex);
293
- }
294
- else
295
- {
296
- const char *textureData = dictionary->valueForKey (" textureImageData" )->getCString ();
297
- CCAssert (textureData, " " );
298
-
299
- int dataLen = strlen (textureData);
300
- if (dataLen != 0 )
272
+ // texture
273
+ // Try to get the texture from the cache
274
+ const char * textureName = dictionary->valueForKey (" textureFileName" )->getCString ();
275
+ std::string fullpath = CCFileUtils::fullPathFromRelativeFile (textureName, m_sPlistFile.c_str ());
276
+
277
+ CCTexture2D *tex = NULL ;
278
+
279
+ if (strlen (textureName) > 0 )
301
280
{
302
- // if it fails, try to get it from the base64-gzipped data
303
- int decodeLen = base64Decode ((unsigned char *)textureData, (unsigned int )dataLen, &buffer);
304
- CCAssert ( buffer != NULL , " CCParticleSystem: error decoding textureImageData" );
305
- CC_BREAK_IF (!buffer);
306
-
281
+ // set not pop-up message box when load image failed
282
+ bool bNotify = CCFileUtils::getIsPopupNotify ();
283
+ CCFileUtils::setIsPopupNotify (false );
284
+ tex = CCTextureCache::sharedTextureCache ()->addImage (fullpath.c_str ());
285
+
286
+ // reset the value of UIImage notify
287
+ CCFileUtils::setIsPopupNotify (bNotify);
288
+ }
289
+
290
+ if (tex)
291
+ {
292
+ setTexture (tex);
293
+ }
294
+ else
295
+ {
296
+ const char *textureData = dictionary->valueForKey (" textureImageData" )->getCString ();
297
+ CCAssert (textureData, " " );
298
+
299
+ int dataLen = strlen (textureData);
300
+ if (dataLen != 0 )
301
+ {
302
+ // if it fails, try to get it from the base64-gzipped data
303
+ int decodeLen = base64Decode ((unsigned char *)textureData, (unsigned int )dataLen, &buffer);
304
+ CCAssert ( buffer != NULL , " CCParticleSystem: error decoding textureImageData" );
305
+ CC_BREAK_IF (!buffer);
306
+
307
307
int deflatedLen = ZipUtils::ccInflateMemory (buffer, decodeLen, &deflated);
308
308
CCAssert ( deflated != NULL , " CCParticleSystem: error ungzipping textureImageData" );
309
309
CC_BREAK_IF (!deflated);
310
310
311
+ // don't delete image, VolatileTexture use it in CCTextureCache::sharedTextureCache()->addUIImage()
311
312
image = new CCImage ();
312
313
bool isOK = image->initWithImageData (deflated, deflatedLen);
313
314
CCAssert (isOK, " CCParticleSystem: error init image with Data" );
314
315
CC_BREAK_IF (!isOK);
315
316
316
317
setTexture (CCTextureCache::sharedTextureCache ()->addUIImage (image, fullpath.c_str ()));
318
+ }
317
319
}
318
- }
319
- CCAssert ( this ->m_pTexture != NULL , " CCParticleSystem: error loading the texture" );
320
-
320
+ CCAssert ( this ->m_pTexture != NULL , " CCParticleSystem: error loading the texture" );
321
321
}
322
322
bRet = true ;
323
323
}
324
324
} while (0 );
325
325
CC_SAFE_DELETE_ARRAY (buffer);
326
326
CC_SAFE_DELETE_ARRAY (deflated);
327
- CC_SAFE_DELETE (image);
328
327
return bRet;
329
328
}
330
329
@@ -470,7 +469,7 @@ void CCParticleSystem::initParticle(tCCParticle* particle)
470
469
float a = CC_DEGREES_TO_RADIANS ( m_fAngle + m_fAngleVar * CCRANDOM_MINUS1_1 () );
471
470
472
471
// Mode Gravity: A
473
- if ( m_nEmitterMode == kCCParticleModeGravity )
472
+ if ( m_nEmitterMode == kCCParticleModeGravity )
474
473
{
475
474
CCPoint v (cosf ( a ), sinf ( a ));
476
475
float s = modeA.speed + modeA.speedVar * CCRANDOM_MINUS1_1 ();
@@ -488,17 +487,22 @@ void CCParticleSystem::initParticle(tCCParticle* particle)
488
487
}
489
488
490
489
// Mode Radius: B
491
- else {
490
+ else
491
+ {
492
492
// Set the default diameter of the particle from the source position
493
493
float startRadius = modeB.startRadius + modeB.startRadiusVar * CCRANDOM_MINUS1_1 ();
494
494
float endRadius = modeB.endRadius + modeB.endRadiusVar * CCRANDOM_MINUS1_1 ();
495
495
496
496
particle->modeB .radius = startRadius;
497
497
498
- if ( modeB.endRadius == kCCParticleStartRadiusEqualToEndRadius )
498
+ if (modeB.endRadius == kCCParticleStartRadiusEqualToEndRadius )
499
+ {
499
500
particle->modeB .deltaRadius = 0 ;
501
+ }
500
502
else
503
+ {
501
504
particle->modeB .deltaRadius = (endRadius - startRadius) / particle->timeToLive ;
505
+ }
502
506
503
507
particle->modeB .angle = a;
504
508
particle->modeB .degreesPerSecond = CC_DEGREES_TO_RADIANS (modeB.rotatePerSecond + modeB.rotatePerSecondVar * CCRANDOM_MINUS1_1 ());
@@ -532,7 +536,7 @@ void CCParticleSystem::update(ccTime dt)
532
536
{
533
537
CC_PROFILER_START_CATEGORY (kCCProfilerCategoryParticles , " CCParticleSystem - update" );
534
538
535
- if ( m_bIsActive && m_fEmissionRate )
539
+ if ( m_bIsActive && m_fEmissionRate)
536
540
{
537
541
float rate = 1 .0f / m_fEmissionRate;
538
542
// issue #1201, prevent bursts of particles, due to too high emitCounter
@@ -541,14 +545,14 @@ void CCParticleSystem::update(ccTime dt)
541
545
m_fEmitCounter += dt;
542
546
}
543
547
544
- while ( m_uParticleCount < m_uTotalParticles && m_fEmitCounter > rate )
548
+ while ( m_uParticleCount < m_uTotalParticles && m_fEmitCounter > rate)
545
549
{
546
550
this ->addParticle ();
547
551
m_fEmitCounter -= rate;
548
552
}
549
553
550
554
m_fElapsed += dt;
551
- if (m_fDuration != -1 && m_fDuration < m_fElapsed)
555
+ if (m_fDuration != -1 && m_fDuration < m_fElapsed)
552
556
{
553
557
this ->stopSystem ();
554
558
}
@@ -557,35 +561,37 @@ void CCParticleSystem::update(ccTime dt)
557
561
m_uParticleIdx = 0 ;
558
562
559
563
CCPoint currentPosition = CCPointZero;
560
- if ( m_ePositionType == kCCPositionTypeFree )
564
+ if ( m_ePositionType == kCCPositionTypeFree )
561
565
{
562
566
currentPosition = this ->convertToWorldSpace (CCPointZero);
563
567
}
564
- else if ( m_ePositionType == kCCPositionTypeRelative )
568
+ else if (m_ePositionType == kCCPositionTypeRelative )
565
569
{
566
570
currentPosition = m_tPosition;
567
571
}
568
572
569
573
if (m_bIsVisible)
570
574
{
571
- while ( m_uParticleIdx < m_uParticleCount )
575
+ while ( m_uParticleIdx < m_uParticleCount)
572
576
{
573
577
tCCParticle *p = &m_pParticles[m_uParticleIdx];
574
578
575
579
// life
576
580
p->timeToLive -= dt;
577
581
578
- if ( p->timeToLive > 0 )
582
+ if ( p->timeToLive > 0 )
579
583
{
580
584
// Mode A: gravity, direction, tangential accel & radial accel
581
- if ( m_nEmitterMode == kCCParticleModeGravity )
585
+ if ( m_nEmitterMode == kCCParticleModeGravity )
582
586
{
583
587
CCPoint tmp, radial, tangential;
584
588
585
589
radial = CCPointZero;
586
590
// radial acceleration
587
- if (p->pos .x || p->pos .y )
591
+ if (p->pos .x || p->pos .y )
592
+ {
588
593
radial = ccpNormalize (p->pos );
594
+ }
589
595
tangential = radial;
590
596
radial = ccpMult (radial, p->modeA .radialAccel );
591
597
@@ -604,7 +610,8 @@ void CCParticleSystem::update(ccTime dt)
604
610
}
605
611
606
612
// Mode B: radius movement
607
- else {
613
+ else
614
+ {
608
615
// Update the angle and radius of the particle.
609
616
p->modeB .angle += p->modeB .degreesPerSecond * dt;
610
617
p->modeB .radius += p->modeB .deltaRadius * dt;
@@ -632,7 +639,7 @@ void CCParticleSystem::update(ccTime dt)
632
639
633
640
CCPoint newPos;
634
641
635
- if ( m_ePositionType == kCCPositionTypeFree || m_ePositionType == kCCPositionTypeRelative )
642
+ if ( m_ePositionType == kCCPositionTypeFree || m_ePositionType == kCCPositionTypeRelative )
636
643
{
637
644
CCPoint diff = ccpSub ( currentPosition, p->startPos );
638
645
newPos = ccpSub (p->pos , diff);
@@ -655,7 +662,6 @@ void CCParticleSystem::update(ccTime dt)
655
662
656
663
// update particle counter
657
664
++m_uParticleIdx;
658
-
659
665
}
660
666
else
661
667
{
@@ -687,8 +693,10 @@ void CCParticleSystem::update(ccTime dt)
687
693
} // while
688
694
m_bTransformSystemDirty = false ;
689
695
}
690
- if (!m_pBatchNode)
696
+ if (! m_pBatchNode)
697
+ {
691
698
postStep ();
699
+ }
692
700
693
701
CC_PROFILER_STOP_CATEGORY (kCCProfilerCategoryParticles , " CCParticleSystem - update" );
694
702
}
0 commit comments