Skip to content

Commit dd31ff8

Browse files
author
Thayer J Andrews
committed
Merge branch 'develop' into thayer/effectFunctionRebuilding
2 parents 2df048a + eb18943 commit dd31ff8

File tree

10 files changed

+62
-20
lines changed

10 files changed

+62
-20
lines changed

cocos2d-ui/CCBReader/CCAnimationManager.m

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ - (id)init {
5252
_nodeSequences = [[NSMutableDictionary alloc] init];
5353
_baseValues = [[NSMutableDictionary alloc] init];
5454

55-
// Scheduler
56-
_scheduler = [[CCDirector sharedDirector] scheduler];
57-
[_scheduler scheduleTarget:self];
58-
[_scheduler setPaused:NO target:self];
59-
6055
// Current Sequence Actions
6156
_currentActions = [[NSMutableArray alloc] init];
6257
_playbackSpeed = 1.0f;
@@ -81,6 +76,13 @@ - (CGSize)containerSize:(CCNode*)node {
8176
}
8277
}
8378

79+
-(void) onEnter {
80+
// Setup Scheduler
81+
_scheduler = [[CCDirector sharedDirector] scheduler];
82+
[_scheduler scheduleTarget:self];
83+
[_scheduler setPaused:NO target:self];
84+
}
85+
8486
- (void)addNode:(CCNode*)node andSequences:(NSDictionary*)seq
8587
{
8688
#ifdef DEBUG
@@ -199,7 +201,7 @@ - (CCActionInterval*)actionFromKeyframe0:(CCBKeyframe*)kf0 andKeyframe1:(CCBKeyf
199201
} else if ([name isEqualToString:@"rotationalSkewY"]) {
200202
return [CCActionRotateTo actionWithDuration:duration angleY:[kf1.value floatValue]];
201203
} else if ([name isEqualToString:@"opacity"]) {
202-
return [CCActionFadeTo actionWithDuration:duration opacity:[kf1.value intValue]];
204+
return [CCActionFadeTo actionWithDuration:duration opacity:[kf1.value floatValue]];
203205
} else if ([name isEqualToString:@"color"]) {
204206
CCColor* color = kf1.value;
205207
return [CCActionTintTo actionWithDuration:duration color:color];

cocos2d-ui/CCBReader/CCBReader.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1339,7 +1339,7 @@ - (CCNode*) readNodeGraphParent:(CCNode*)parent
13391339
embeddedNode.scaleX = ccbFileNode.scaleX;
13401340
embeddedNode.scaleY = ccbFileNode.scaleY;
13411341
embeddedNode.name = ccbFileNode.name;
1342-
embeddedNode.visible = YES;
1342+
embeddedNode.visible = ccbFileNode.visible;
13431343
//embeddedNode.ignoreAnchorPointForPosition = ccbFileNode.ignoreAnchorPointForPosition;
13441344

13451345
[animationManager moveAnimationsFromNode:ccbFileNode toNode:embeddedNode];

cocos2d/CCActionInstant.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,12 @@
184184
* This action allows a custom function to be called.
185185
*/
186186
@interface CCActionCallFunc : CCActionInstant <NSCopying> {
187-
id _targetCallback;
187+
__weak id _targetCallback;
188188
SEL _selector;
189189
}
190190

191191
/** Target function that will be called. */
192-
@property (nonatomic, readwrite, strong) id targetCallback;
192+
@property (nonatomic, readwrite, weak) id targetCallback;
193193

194194

195195
/// -----------------------------------------------------------------------

cocos2d/CCLabelTTF.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,12 @@ - (void) setTextureDirty
332332
-(CCRenderState *)renderState
333333
{
334334
if(_renderState == nil){
335+
// Allowing the uniforms to be copied speeds up the rendering by making the render state immutable.
336+
// Copy the uniforms if custom uniforms are not being used.
337+
BOOL copyUniforms = self.hasDefaultShaderUniforms;
338+
335339
// Create an uncached renderstate so the texture can be released before the renderstate cache is flushed.
336-
_renderState = [[CCRenderState alloc] initWithBlendMode:_blendMode shader:_shader shaderUniforms:self.shaderUniforms];
340+
_renderState = [[CCRenderState alloc] initWithBlendMode:_blendMode shader:_shader shaderUniforms:self.shaderUniforms copyUniforms:copyUniforms];
337341
}
338342

339343
return _renderState;

cocos2d/CCNode.m

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,10 @@ -(void) onEnter
11081108
[[CCDirector sharedDirector].actionManager migrateActions:self from:[CCDirector sharedDirector].actionManagerFixed];
11091109
[self setActionManager:[CCDirector sharedDirector].actionManager];
11101110
}
1111+
1112+
if(_animationManager) {
1113+
[_animationManager performSelector:@selector(onEnter)];
1114+
}
11111115

11121116
[self wasRunning:wasRunning];
11131117
}
@@ -1761,7 +1765,7 @@ -(CCRenderState *)renderState
17611765
_shaderUniforms = nil;
17621766
} else {
17631767
// Since the node has unique uniforms, it cannot be batched or use the fast path.
1764-
_renderState = [[CCRenderState alloc] initWithBlendMode:_blendMode shader:_shader shaderUniforms:_shaderUniforms];
1768+
_renderState = [[CCRenderState alloc] initWithBlendMode:_blendMode shader:_shader shaderUniforms:_shaderUniforms copyUniforms:NO];
17651769
}
17661770
}
17671771

@@ -1784,6 +1788,19 @@ -(CCBlendMode *)blendMode
17841788
return _blendMode;
17851789
}
17861790

1791+
-(BOOL)hasDefaultShaderUniforms
1792+
{
1793+
CCTexture *texture = (_texture ?: [CCTexture none]);
1794+
if(CheckDefaultUniforms(_shaderUniforms, texture)){
1795+
// If the uniform dictionary was set, it was the default. Throw it away.
1796+
_shaderUniforms = nil;
1797+
1798+
return YES;
1799+
} else {
1800+
return NO;
1801+
}
1802+
}
1803+
17871804
-(NSMutableDictionary *)shaderUniforms
17881805
{
17891806
if(_shaderUniforms == nil){

cocos2d/CCNode_Private.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ CGAffineTransform CGAffineTransformMakeRigid(CGPoint translate, CGFloat radians)
4343
CCTexture *_texture;
4444
}
4545

46+
/// Returns true if the node is not using custom uniforms.
47+
-(BOOL)hasDefaultShaderUniforms;
48+
4649
/// Cache and return the current render state.
4750
/// Should be set to nil whenever changing a property that affects the renderstate.
4851
@property(nonatomic, strong) CCRenderState *renderState;

cocos2d/CCRenderTexture.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ typedef NS_ENUM(NSInteger, CCRenderTextureImageFormat)
5959
@interface CCRenderTexture : CCNode
6060

6161
/** The CCSprite that is used for rendering.
62-
A sublte change introduced in v3.1.1 is that this sprite is rendered explicitly and is not a child of the render texture.
62+
A subtle change introduced in v3.1.1 is that this sprite is rendered explicitly and is not a child of the render texture.
6363
*/
6464
@property (nonatomic,readwrite, strong) CCSprite* sprite;
6565

cocos2d/CCRenderTexture.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,12 @@ @implementation CCRenderTextureSprite
5656
-(CCRenderState *)renderState
5757
{
5858
if(_renderState == nil){
59+
// Allowing the uniforms to be copied speeds up the rendering by making the render state immutable.
60+
// Copy the uniforms if custom uniforms are not being used.
61+
BOOL copyUniforms = self.hasDefaultShaderUniforms;
62+
5963
// Create an uncached renderstate so the texture can be released before the renderstate cache is flushed.
60-
_renderState = [[CCRenderState alloc] initWithBlendMode:_blendMode shader:_shader shaderUniforms:self.shaderUniforms];
64+
_renderState = [[CCRenderState alloc] initWithBlendMode:_blendMode shader:_shader shaderUniforms:self.shaderUniforms copyUniforms:copyUniforms];
6165
}
6266

6367
return _renderState;

cocos2d/CCRenderer.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,12 @@ extern const NSString *CCBlendEquationAlpha;
172172
/// Create a cached blending mode for a given blending mode, shader and main texture.
173173
+(instancetype)renderStateWithBlendMode:(CCBlendMode *)blendMode shader:(CCShader *)shader mainTexture:(CCTexture *)mainTexture;
174174

175+
/// Create an uncached blending mode for a given blending mode, shader and set of uncopied uniform values.
176+
-(instancetype)initWithBlendMode:(CCBlendMode *)blendMode shader:(CCShader *)shader shaderUniforms:(NSDictionary *)shaderUniforms __deprecated;
177+
175178
/// Create an uncached blending mode for a given blending mode, shader and set of uniform values.
176-
-(instancetype)initWithBlendMode:(CCBlendMode *)blendMode shader:(CCShader *)shader shaderUniforms:(NSDictionary *)shaderUniforms;
179+
/// Allowing the uniform dictionary to be copied allows the render state to be immutable and used more optimally.
180+
-(instancetype)initWithBlendMode:(CCBlendMode *)blendMode shader:(CCShader *)shader shaderUniforms:(NSDictionary *)shaderUniforms copyUniforms:(BOOL)copyUniforms;
177181

178182
@end
179183

cocos2d/CCRenderer.m

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ -(void)flush
263263

264264
@implementation CCRenderState {
265265
CCTexture *_mainTexture;
266+
BOOL _immutable;
266267

267268
@public
268269
CCBlendMode *_blendMode;
@@ -280,11 +281,19 @@ +(void)initialize
280281
}
281282

282283
-(instancetype)initWithBlendMode:(CCBlendMode *)blendMode shader:(CCShader *)shader shaderUniforms:(NSDictionary *)shaderUniforms
284+
{
285+
return [self initWithBlendMode:blendMode shader:shader shaderUniforms:shaderUniforms copyUniforms:NO];
286+
}
287+
288+
-(instancetype)initWithBlendMode:(CCBlendMode *)blendMode shader:(CCShader *)shader shaderUniforms:(NSDictionary *)shaderUniforms copyUniforms:(BOOL)copyUniforms
283289
{
284290
if((self = [super init])){
285291
_blendMode = blendMode;
286292
_shader = shader;
287-
_shaderUniforms = shaderUniforms;
293+
_shaderUniforms = (copyUniforms ? [shaderUniforms copy] : shaderUniforms);
294+
295+
// The renderstate as a whole is immutable if the uniforms are copied.
296+
_immutable = copyUniforms;
288297
}
289298

290299
return self;
@@ -297,25 +306,24 @@ +(instancetype)renderStateWithBlendMode:(CCBlendMode *)blendMode shader:(CCShade
297306
mainTexture = [CCTexture none];
298307
}
299308

300-
CCRenderState *renderState = [[self alloc] initWithBlendMode:blendMode shader:shader shaderUniforms:@{CCShaderUniformMainTexture: mainTexture}];
309+
CCRenderState *renderState = [[self alloc] initWithBlendMode:blendMode shader:shader shaderUniforms:@{CCShaderUniformMainTexture: mainTexture} copyUniforms:YES];
301310
renderState->_mainTexture = mainTexture;
302311

303312
return [CCRENDERSTATE_CACHE objectForKey:renderState];
304313
}
305314

306315
-(id)copyWithZone:(NSZone *)zone
307316
{
308-
NSDictionary *shaderUniforms = [_shaderUniforms copy];
309-
if(shaderUniforms == _shaderUniforms){
317+
if(_immutable){
310318
return self;
311319
} else {
312-
return [[CCRenderState allocWithZone:zone] initWithBlendMode:_blendMode shader:_shader shaderUniforms:shaderUniforms];
320+
return [[CCRenderState allocWithZone:zone] initWithBlendMode:_blendMode shader:_shader shaderUniforms:_shaderUniforms copyUniforms:YES];
313321
}
314322
}
315323

316324
-(NSUInteger)hash
317325
{
318-
NSAssert(_mainTexture, @"Attempting to cache a renderstate without a mainTexture value.");
326+
NSAssert(_mainTexture, @"Attempting to cache a renderstate that was nort created with renderStateWithBlendMode.");
319327

320328
// Not great, but acceptable. All values are unique by pointer.
321329
return ((NSUInteger)_blendMode ^ (NSUInteger)_shader ^ (NSUInteger)_mainTexture);

0 commit comments

Comments
 (0)