@@ -102,21 +102,6 @@ var CCB_SIZETYPE_MULTIPLY_RESOLUTION = 5;
102
102
var CCB_SCALETYPE_ABSOLUTE = 0 ;
103
103
var CCB_SCALETYPE_MULTIPLY_RESOLUTION = 1 ;
104
104
105
- cc . BuilderFile = cc . Node . extend ( {
106
- _ccbFileNode :null ,
107
-
108
- getCCBFileNode :function ( ) {
109
- return this . _ccbFileNode ;
110
- } ,
111
- setCCBFileNode :function ( node ) {
112
- this . _ccbFileNode = node ;
113
- }
114
- } ) ;
115
-
116
- cc . BuilderFile . create = function ( ) {
117
- return new cc . BuilderFile ( ) ;
118
- } ;
119
-
120
105
/**
121
106
* Parse CCBI file which is generated by CocosBuilder
122
107
*/
@@ -340,13 +325,31 @@ cc.BuilderReader = cc.Class.extend({
340
325
341
326
readInt : function ( signed ) {
342
327
var numBits = 0 ;
343
- while ( ! this . _getBit ( ) ) {
328
+ var data = this . _data [ this . _currentByte ] ;
329
+ var bit = ! ! ( data & ( 1 << this . _currentBit ++ ) ) ;
330
+ while ( ! bit ) {
344
331
numBits ++ ;
332
+ bit = ! ! ( data & ( 1 << this . _currentBit ++ ) ) ;
333
+ if ( this . _currentBit >= 8 ) {
334
+ this . _currentBit = 0 ;
335
+ this . _currentByte ++ ;
336
+ data = this . _data [ this . _currentByte ] ;
337
+ if ( this . _currentByte > this . _data . length )
338
+ throw new Error ( "out of the data bound" ) ;
339
+ }
345
340
}
346
341
347
342
var current = 0 ;
348
343
for ( var a = numBits - 1 ; a >= 0 ; a -- ) {
349
- if ( this . _getBit ( ) ) {
344
+ bit = ! ! ( data & ( 1 << this . _currentBit ++ ) ) ;
345
+ if ( this . _currentBit >= 8 ) {
346
+ this . _currentBit = 0 ;
347
+ this . _currentByte ++ ;
348
+ data = this . _data [ this . _currentByte ] ;
349
+ if ( this . _currentByte > this . _data . length )
350
+ throw new Error ( "out of the data bound" ) ;
351
+ }
352
+ if ( bit ) {
350
353
current |= 1 << a ;
351
354
}
352
355
}
@@ -364,7 +367,10 @@ cc.BuilderReader = cc.Class.extend({
364
367
num = current - 1 ;
365
368
}
366
369
367
- this . _alignBits ( ) ;
370
+ if ( this . _currentBit ) {
371
+ this . _currentBit = 0 ;
372
+ this . _currentByte ++ ;
373
+ }
368
374
369
375
return num ;
370
376
} ,
@@ -376,11 +382,11 @@ cc.BuilderReader = cc.Class.extend({
376
382
} ,
377
383
378
384
readBool : function ( ) {
379
- return ( 0 !== this . readByte ( ) ) ;
385
+ return ! ! this . _data [ this . _currentByte ++ ] ;
380
386
} ,
381
387
382
388
readFloat : function ( ) {
383
- var type = this . readByte ( ) ;
389
+ var type = this . _data [ this . _currentByte ++ ] ;
384
390
385
391
switch ( type ) {
386
392
case CCB_FLOAT0 :
@@ -406,7 +412,9 @@ cc.BuilderReader = cc.Class.extend({
406
412
_decodeFloat : function ( precisionBits , exponentBits ) {
407
413
var length = precisionBits + exponentBits + 1 ;
408
414
var size = length >> 3 ;
409
- this . _checkSize ( length ) ;
415
+ if ( this . _currentByte + size >= this . _data . length ) {
416
+ throw new Error ( "Index out of bound" ) ;
417
+ }
410
418
411
419
var bias = Math . pow ( 2 , exponentBits - 1 ) - 1 ;
412
420
var signal = this . _readBitsOnly ( precisionBits + exponentBits , 1 , size ) ;
@@ -415,7 +423,7 @@ cc.BuilderReader = cc.Class.extend({
415
423
var divisor = 2 ;
416
424
var curByte = 0 ; //length + (-precisionBits >> 3) - 1;
417
425
do {
418
- var byteValue = this . _readByteOnly ( ++ curByte , size ) ;
426
+ var byteValue = this . _data [ this . _currentByte + size - ( ++ curByte ) - 1 ] ;
419
427
var startBit = precisionBits % 8 || 8 ;
420
428
var mask = 1 << startBit ;
421
429
while ( mask >>= 1 ) {
@@ -440,34 +448,26 @@ cc.BuilderReader = cc.Class.extend({
440
448
var lastByte = size + ( - ( start + length ) >> 3 ) ;
441
449
var diff = curByte - lastByte ;
442
450
443
- var sum = ( this . _readByteOnly ( curByte , size ) >> offsetRight ) & ( ( 1 << ( diff ? 8 - offsetRight : length ) ) - 1 ) ;
451
+ var sum = ( this . _data [ this . _currentByte + size - curByte - 1 ] >> offsetRight ) & ( ( 1 << ( diff ? 8 - offsetRight : length ) ) - 1 ) ;
444
452
445
453
if ( diff && offsetLeft ) {
446
- sum += ( this . _readByteOnly ( lastByte ++ , size ) & ( ( 1 << offsetLeft ) - 1 ) ) << ( diff -- << 3 ) - offsetRight ;
454
+ sum += ( this . _data [ this . _currentByte + size - lastByte - 1 ] & ( ( 1 << offsetLeft ) - 1 ) ) << ( diff -- << 3 ) - offsetRight ;
455
+ lastByte ++ ;
447
456
}
448
457
449
458
while ( diff ) {
450
- sum += this . _shl ( this . _readByteOnly ( lastByte ++ , size ) , ( diff -- << 3 ) - offsetRight ) ;
459
+ sum += this . _shl ( this . _data [ this . _currentByte + size - lastByte - 1 ] , ( diff -- << 3 ) - offsetRight ) ;
460
+ lastByte ++ ;
451
461
}
452
462
453
463
return sum ;
454
464
} ,
455
465
456
- _readByteOnly : function ( i , size ) {
457
- return this . _data [ this . _currentByte + size - i - 1 ] ;
458
- } ,
459
-
460
466
_shl : function ( a , b ) {
461
467
for ( ++ b ; -- b ; a = ( ( a %= 0x7fffffff + 1 ) & 0x40000000 ) === 0x40000000 ? a * 2 : ( a - 0x40000000 ) * 2 + 0x7fffffff + 1 ) ;
462
468
return a ;
463
469
} ,
464
470
465
- _checkSize : function ( neededBits ) {
466
- if ( ! ( this . _currentByte + Math . ceil ( neededBits / 8 ) < this . _data . length ) ) {
467
- throw new Error ( "Index out of bound" ) ;
468
- }
469
- } ,
470
-
471
471
readCachedString : function ( ) {
472
472
return this . _stringCache [ this . readInt ( false ) ] ;
473
473
} ,
@@ -670,12 +670,11 @@ cc.BuilderReader = cc.Class.extend({
670
670
keyframe . setEasingOpt ( easingOpt ) ;
671
671
672
672
if ( type === CCB_PROPTYPE_CHECK ) {
673
- value = this . readBool ( ) ;
673
+ value = ! ! this . _data [ this . _currentByte ++ ] ;
674
674
} else if ( type === CCB_PROPTYPE_BYTE ) {
675
- value = this . readByte ( ) ;
675
+ value = this . _data [ this . _currentByte ++ ] ;
676
676
} else if ( type === CCB_PROPTYPE_COLOR3 ) {
677
- var c = cc . color ( this . readByte ( ) , this . readByte ( ) , this . readByte ( ) ) ;
678
- value = cc . Color3BWapper . create ( c ) ;
677
+ value = cc . color ( this . _data [ this . _currentByte ++ ] , this . _data [ this . _currentByte ++ ] , this . _data [ this . _currentByte ++ ] ) ;
679
678
} else if ( type === CCB_PROPTYPE_FLOATXY ) {
680
679
value = [ this . readFloat ( ) , this . readFloat ( ) ] ;
681
680
} else if ( type === CCB_PROPTYPE_DEGREES ) {
@@ -727,7 +726,7 @@ cc.BuilderReader = cc.Class.extend({
727
726
return false ;
728
727
}
729
728
730
- this . _jsControlled = this . readBool ( ) ;
729
+ this . _jsControlled = ! ! this . _data [ this . _currentByte ++ ] ;
731
730
this . _animationManager . _jsControlled = this . _jsControlled ;
732
731
// no need to set if it is "jscontrolled". It is obvious.
733
732
return true ;
@@ -736,13 +735,13 @@ cc.BuilderReader = cc.Class.extend({
736
735
_readStringFromBytes : function ( startIndex , strLen , reverse ) {
737
736
reverse = reverse || false ;
738
737
var strValue = "" ;
739
- var i , locData = this . _data , locCurrentByte = this . _currentByte ;
738
+ var i , locData = this . _data ;
740
739
if ( reverse ) {
741
740
for ( i = strLen - 1 ; i >= 0 ; i -- )
742
- strValue += String . fromCharCode ( locData [ locCurrentByte + i ] ) ;
741
+ strValue += String . fromCharCode ( locData [ startIndex + i ] ) ;
743
742
} else {
744
743
for ( i = 0 ; i < strLen ; i ++ )
745
- strValue += String . fromCharCode ( locData [ locCurrentByte + i ] ) ;
744
+ strValue += String . fromCharCode ( locData [ startIndex + i ] ) ;
746
745
}
747
746
return strValue ;
748
747
} ,
@@ -755,8 +754,8 @@ cc.BuilderReader = cc.Class.extend({
755
754
} ,
756
755
757
756
_readStringCacheEntry : function ( ) {
758
- var b0 = this . readByte ( ) ;
759
- var b1 = this . readByte ( ) ;
757
+ var b0 = this . _data [ this . _currentByte ++ ] ;
758
+ var b1 = this . _data [ this . _currentByte ++ ] ;
760
759
761
760
var numBytes = b0 << 8 | b1 ;
762
761
@@ -838,9 +837,9 @@ cc.BuilderReader = cc.Class.extend({
838
837
ccNodeLoader . parseProperties ( node , parent , this ) ;
839
838
840
839
//handle sub ccb files(remove middle node)
841
- var isCCBFileNode = node instanceof cc . BuilderFile ;
840
+ var isCCBFileNode = ! ! node . ccbFileNode ;
842
841
if ( isCCBFileNode ) {
843
- var embeddedNode = node . getCCBFileNode ( ) ;
842
+ var embeddedNode = node . ccbFileNode ;
844
843
embeddedNode . setPosition ( node . getPosition ( ) ) ;
845
844
embeddedNode . setRotation ( node . getRotation ( ) ) ;
846
845
embeddedNode . setScaleX ( node . getScaleX ( ) ) ;
@@ -850,7 +849,7 @@ cc.BuilderReader = cc.Class.extend({
850
849
//embeddedNode.ignoreAnchorPointForPosition(node.isIgnoreAnchorPointForPosition());
851
850
852
851
locActionManager . moveAnimationsFromNode ( node , embeddedNode ) ;
853
- node . setCCBFileNode ( null ) ;
852
+ node . ccbFileNode = null ;
854
853
node = embeddedNode ;
855
854
}
856
855
var target = null , locMemberAssigner = null ;
@@ -926,27 +925,7 @@ cc.BuilderReader = cc.Class.extend({
926
925
return node ;
927
926
} ,
928
927
929
- _getBit :function ( ) {
930
- var bit = ( this . _data [ this . _currentByte ] & ( 1 << this . _currentBit ) ) !== 0 ;
931
- this . _currentBit ++ ;
932
-
933
- if ( this . _currentBit >= 8 ) {
934
- this . _currentBit = 0 ;
935
- this . _currentByte ++ ;
936
- if ( this . _currentByte > this . _data . length )
937
- throw new Error ( "out of the data bound" ) ;
938
- }
939
- return bit ;
940
- } ,
941
-
942
- _alignBits :function ( ) {
943
- if ( this . _currentBit ) {
944
- this . _currentBit = 0 ;
945
- this . _currentByte ++ ;
946
- }
947
- } ,
948
-
949
- _readUTF8 :function ( ) {
928
+ _readUTF8 : function ( ) {
950
929
}
951
930
} ) ;
952
931
0 commit comments