3838
3939#import " CCTexture_Private.h"
4040
41- #define kProgressTextureCoordsCount 4
42- // kProgressTextureCoords holds points {0,1} {0,0} {1,0} {1,1} we can represent it as bits
43- const char kCCProgressTextureCoords = 0x4b ;
44-
45- @interface CCProgressNode () {
41+ @implementation CCProgressNode {
4642 CCProgressNodeType _type;
4743 float _percentage;
4844 CCSprite *_sprite;
@@ -57,15 +53,6 @@ @interface CCProgressNode () {
5753 BOOL _needsUpdateProgress;
5854}
5955
60- -(void )updateProgress ;
61- -(void )updateBar ;
62- -(void )updateRadial ;
63- -(void )updateColor ;
64- -(CGPoint)boundaryTexCoord : (char )index ;
65- @end
66-
67-
68- @implementation CCProgressNode
6956@synthesize percentage = _percentage;
7057@synthesize sprite = _sprite;
7158@synthesize type = _type;
@@ -200,8 +187,6 @@ -(GLKVector2)textureCoordFromAlphaPoint:(CGPoint) alpha
200187 CC_SWAP (alpha.x , alpha.y );
201188 }
202189
203- // As of 3.1, the x alpha needs to be flipped. Not really sure why.
204- alpha.x = 1.0 - alpha.x ;
205190 return GLKVector2Make (min.x * (1 .f - alpha.x ) + max.x * alpha.x , min.y * (1 .f - alpha.y ) + max.y * alpha.y );
206191}
207192
@@ -271,6 +256,13 @@ -(void)setMidpoint:(CGPoint)midPoint
271256 _midpoint = ccpClamp (midPoint, CGPointZero, ccp (1 ,1 ));
272257}
273258
259+ static inline CGPoint
260+ BoundryTexCoord (int index)
261+ {
262+ static const CGPoint points[] = {{1 ,1 }, {1 ,0 }, {0 ,0 }, {0 ,1 }};
263+ return points[index];
264+ }
265+
274266// /
275267// Update does the work of mapping the texture onto the triangles
276268// It now doesn't occur the cost of free/alloc data every update cycle.
@@ -317,11 +309,11 @@ -(void)updateRadial
317309
318310 float min_t = FLT_MAX;
319311
320- for (int i = 0 ; i <= kProgressTextureCoordsCount ; ++i) {
321- int pIndex = (i + ( kProgressTextureCoordsCount - 1 ))% kProgressTextureCoordsCount ;
312+ for (int i = 0 ; i <= 4 ; ++i) {
313+ int pIndex = (i + 3 )% 4 ;
322314
323- CGPoint edgePtA = [ self boundaryTexCoord: i % kProgressTextureCoordsCount ] ;
324- CGPoint edgePtB = [ self boundaryTexCoord: pIndex] ;
315+ CGPoint edgePtA = BoundryTexCoord ( i % 4 ) ;
316+ CGPoint edgePtB = BoundryTexCoord ( pIndex) ;
325317
326318 // Remember that the top edge is split in half for the 12 o'clock position
327319 // Let's deal with that here by finding the correct endpoints
@@ -391,7 +383,7 @@ -(void)updateRadial
391383 _verts[1 ].position = [self vertexFromAlphaPoint: topMid];
392384
393385 for (int i = 0 ; i < index; ++i){
394- CGPoint alphaPoint = [ self boundaryTexCoord: i] ;
386+ CGPoint alphaPoint = BoundryTexCoord (i) ;
395387 _verts[i+2 ].texCoord1 = [self textureCoordFromAlphaPoint: alphaPoint];
396388 _verts[i+2 ].position = [self vertexFromAlphaPoint: alphaPoint];
397389 }
@@ -504,18 +496,6 @@ -(void)updateBar
504496 [self updateColor ];
505497}
506498
507- -(CGPoint)boundaryTexCoord : (char )index
508- {
509- if (index < kProgressTextureCoordsCount ) {
510- if (_reverseDirection) {
511- return ccp ((kCCProgressTextureCoords >>(7 -(index<<1 )))&1 ,(kCCProgressTextureCoords >>(7 -((index<<1 )+1 )))&1 );
512- } else {
513- return ccp ((kCCProgressTextureCoords >>((index<<1 )+1 ))&1 ,(kCCProgressTextureCoords >>(index<<1 ))&1 );
514- }
515- }
516- return CGPointZero;
517- }
518-
519499-(void )visit : (CCRenderer *)renderer parentTransform : (const GLKMatrix4 *)parentTransform
520500{
521501 [super visit: renderer parentTransform: parentTransform];
0 commit comments