Skip to content

Commit 9fb24c2

Browse files
committed
Split the CCAction.h header into a public/private one. CCAction.tag -> CCAction.name.
1 parent 0fd5789 commit 9fb24c2

22 files changed

+193
-138
lines changed

UnitTests/CCActionTest.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,6 @@ - (void)testCopyActionClearsState
323323
XCTAssertEqualWithAccuracy(actionCopy.elapsed, 0.0f, accuracy, @"Elapsed time was not reset.");
324324
XCTAssertEqualWithAccuracy(actionCopy.duration, 1.0f, accuracy, @"Duration should have been copied.");
325325
XCTAssertNil(actionCopy.target, @"Target not reset");
326-
XCTAssertNil(actionCopy.originalTarget, @"originalTarget not reset");
327326
}
328327

329328
- (void)testCopyActionClearsStateForCompletedActions
@@ -340,7 +339,6 @@ - (void)testCopyActionClearsStateForCompletedActions
340339
XCTAssertEqualWithAccuracy(actionCopy.elapsed, 0.0f, accuracy, @"Elapsed time was not reset.");
341340
XCTAssertEqualWithAccuracy(actionCopy.duration, 1.0f, accuracy, @"Duration should have been copied.");
342341
XCTAssertNil(actionCopy.target, @"Target not reset");
343-
XCTAssertNil(actionCopy.originalTarget, @"originalTarget not reset");
344342
}
345343

346344

cocos2d-ui/CCBReader/CCAnimationManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
NSMutableDictionary* _nodeSequences;
6060
NSMutableDictionary* _baseValues;
6161

62-
NSInteger _animationManagerId;
62+
NSString *_animationManagerId;
6363
CCBSequence* _runningSequence;
6464
CCBSequence* _lastSequence;
6565

cocos2d-ui/CCBReader/CCAnimationManager.m

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#import "CCDirector_Private.h"
3030
#import "CCBReader_Private.h"
3131
#import "CCScheduler_Private.h"
32+
#import "CCAction_Private.h"
3233

3334
#import "CCBKeyframe.h"
3435
#import "CCBSequence.h"
@@ -66,7 +67,7 @@ - (id)init {
6667
self = [super init];
6768
if (!self) return NULL;
6869

69-
_animationManagerId = ccbAnimationManagerID;
70+
_animationManagerId = [NSString stringWithFormat:@"%ld", (long)ccbAnimationManagerID];
7071
ccbAnimationManagerID++;
7172

7273
_sequences = [[NSMutableArray alloc] init];
@@ -268,7 +269,7 @@ - (void)setAnimatedProperty:(NSString*)name forNode:(CCNode*)node toValue:(id)va
268269
kf1.easingType = kCCBKeyframeEasingLinear;
269270

270271
CCActionInterval* tweenAction = [self actionFromKeyframe0:NULL andKeyframe1:kf1 propertyName:name node:node];
271-
tweenAction.tag = (int)_animationManagerId;
272+
tweenAction.name = _animationManagerId;
272273
[tweenAction startWithTarget:node];
273274
[_currentActions addObject:tweenAction];
274275
} else {
@@ -428,7 +429,7 @@ - (void)runActionsForNode:(CCNode*)node sequenceProperty:(CCBSequenceProperty*)s
428429
[actions addObject:nextKeyFrameBlock];
429430

430431
CCActionSequence* seq = [CCActionSequence actionWithArray:actions];
431-
seq.tag = _animationManagerId;
432+
seq.name = _animationManagerId;
432433
[seq startWithTarget:node];
433434
if(kf0.time > 0) { // Ensure Sync
434435
[seq step:0];
@@ -569,7 +570,7 @@ - (void)addSequenceCallBacks:(int)seqId tweenDuration:(float)tweenDuration start
569570
CCActionSequence* completeAction = [CCActionSequence
570571
actionOne:[CCActionDelay actionWithDuration:seq.duration+tweenDuration-time]
571572
two:[CCActionCallFunc actionWithTarget:self selector:@selector(sequenceCompleted)]];
572-
completeAction.tag = (int)_animationManagerId;
573+
completeAction.name = _animationManagerId;
573574
[completeAction startWithTarget:self.rootNode];
574575
[_currentActions addObject:completeAction];
575576

@@ -578,7 +579,7 @@ - (void)addSequenceCallBacks:(int)seqId tweenDuration:(float)tweenDuration start
578579
// Build sound actions for channel
579580
CCAction* action = [self actionForCallbackChannel:seq.callbackChannel];
580581
if (action) {
581-
action.tag = (int)_animationManagerId;
582+
action.name = _animationManagerId;;
582583
[action startWithTarget:self.rootNode];
583584
[_currentActions addObject:action];
584585
}
@@ -588,7 +589,7 @@ - (void)addSequenceCallBacks:(int)seqId tweenDuration:(float)tweenDuration start
588589
// Build sound actions for channel
589590
CCAction* action = [self actionForSoundChannel:seq.soundChannel];
590591
if (action) {
591-
action.tag = (int)_animationManagerId;
592+
action.name = _animationManagerId;;
592593
[action startWithTarget:self.rootNode];
593594
[_currentActions addObject:action];
594595
}
@@ -807,7 +808,7 @@ - (void) timeSeekForSequenceId:(int)seqId time:(float)time {
807808
CCActionSequence* animSequence = [CCActionSequence actions:action, nextKeyFrameBlock,nil];
808809

809810
// Fast forward to time point
810-
[animSequence setTag:_animationManagerId];
811+
animSequence.name = _animationManagerId;
811812
[animSequence startWithTarget:node];
812813
[animSequence step:0]; // First Tick
813814
[animSequence step:timeFoward];
@@ -881,7 +882,7 @@ - (CCActionSequence*)createActionForNode:(CCNode*)node sequenceProperty:(CCBSequ
881882
[actions addObject:action];
882883

883884
seq = [CCActionSequence actionWithArray:actions];
884-
seq.tag = _animationManagerId;
885+
seq.name = _animationManagerId;
885886
}
886887

887888

cocos2d-ui/CCScrollView.m

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424

2525
#import "ccMacros.h"
26+
#import "CCAction_Private.h"
2627

2728
#if __CC_PLATFORM_IOS
2829
#import <UIKit/UIGestureRecognizerSubclass.h>
@@ -54,8 +55,8 @@
5455
#define kCCScrollViewMaxOuterDistBeforeBounceBack 50.0
5556
#define kCCScrollViewMinVelocityBeforeBounceBack 100.0
5657

57-
#define kCCScrollViewActionXTag 8080
58-
#define kCCScrollViewActionYTag 8081
58+
#define CCScrollViewActionXTag @"CCScrollViewActionXTag"
59+
#define CCScrollViewActionYTag @"CCScrollViewActionYTag"
5960

6061
#pragma mark -
6162
#pragma mark Helper classes
@@ -418,7 +419,7 @@ - (void) setScrollPosition:(CGPoint)newPos animated:(BOOL)animated
418419
}] rate:2];
419420
CCActionCallFunc* callFunc = [CCActionCallFunc actionWithTarget:self selector:@selector(xAnimationDone)];
420421
action = [CCActionSequence actions:action, callFunc, nil];
421-
action.tag = kCCScrollViewActionXTag;
422+
action.name = CCScrollViewActionXTag;
422423
[self.camera runAction:action];
423424
}
424425
if (yMoved)
@@ -434,7 +435,7 @@ - (void) setScrollPosition:(CGPoint)newPos animated:(BOOL)animated
434435
}] rate:2];
435436
CCActionCallFunc* callFunc = [CCActionCallFunc actionWithTarget:self selector:@selector(yAnimationDone)];
436437
action = [CCActionSequence actions:action, callFunc, nil];
437-
action.tag = kCCScrollViewActionYTag;
438+
action.name = CCScrollViewActionYTag;
438439
[self.camera runAction:action];
439440
}
440441
}
@@ -443,8 +444,8 @@ - (void) setScrollPosition:(CGPoint)newPos animated:(BOOL)animated
443444
#if __CC_PLATFORM_MAC
444445
_lastPosition = self.scrollPosition;
445446
#endif
446-
[self.camera stopActionByTag:kCCScrollViewActionXTag];
447-
[self.camera stopActionByTag:kCCScrollViewActionYTag];
447+
[self.camera stopActionByName:CCScrollViewActionXTag];
448+
[self.camera stopActionByName:CCScrollViewActionYTag];
448449
self.camera.position = newPos;
449450
}
450451
}
@@ -638,8 +639,8 @@ - (void) touchBeganAtTranslation:(CGPoint) rawTranslation
638639
_startScrollPos = self.scrollPosition;
639640

640641
_isPanning = YES;
641-
[self.camera stopActionByTag:kCCScrollViewActionXTag];
642-
[self.camera stopActionByTag:kCCScrollViewActionYTag];
642+
[self.camera stopActionByName:CCScrollViewActionXTag];
643+
[self.camera stopActionByName:CCScrollViewActionYTag];
643644

644645
}
645646

cocos2d.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,7 @@
909909
D3A2E7D2181E12750033614C /* CCPhysicsShape.h in Headers */ = {isa = PBXBuildFile; fileRef = D3A2E7D0181E12750033614C /* CCPhysicsShape.h */; };
910910
D3A2E7D3181E12750033614C /* CCPhysicsShape.m in Sources */ = {isa = PBXBuildFile; fileRef = D3A2E7D1181E12750033614C /* CCPhysicsShape.m */; };
911911
D3BEEFA419CFE8730055B624 /* CCRendererBasicTypes.m in Sources */ = {isa = PBXBuildFile; fileRef = D34CAD6819C3A7B3009BED7A /* CCRendererBasicTypes.m */; };
912+
D3D976361A896AC000462614 /* CCAction_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = D3D976351A896AC000462614 /* CCAction_Private.h */; };
912913
D3E3752F19CC842A0076CDBB /* CCRendererSharedTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = D3E3752E19CC842A0076CDBB /* CCRendererSharedTypes.h */; };
913914
E01E6D8C121F130E001A484F /* CCLabelBMFont.h in Headers */ = {isa = PBXBuildFile; fileRef = E01E6D8A121F130E001A484F /* CCLabelBMFont.h */; };
914915
E01E6D8D121F130E001A484F /* CCLabelBMFont.m in Sources */ = {isa = PBXBuildFile; fileRef = E01E6D8B121F130E001A484F /* CCLabelBMFont.m */; };
@@ -1446,6 +1447,7 @@
14461447
D3A2E7D0181E12750033614C /* CCPhysicsShape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPhysicsShape.h; sourceTree = "<group>"; };
14471448
D3A2E7D1181E12750033614C /* CCPhysicsShape.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCPhysicsShape.m; sourceTree = "<group>"; };
14481449
D3C12815199D40AC005D2119 /* CCShaders.metal */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.metal; path = CCShaders.metal; sourceTree = "<group>"; };
1450+
D3D976351A896AC000462614 /* CCAction_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCAction_Private.h; sourceTree = "<group>"; };
14491451
D3E3752E19CC842A0076CDBB /* CCRendererSharedTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCRendererSharedTypes.h; sourceTree = "<group>"; };
14501452
DCF7B34D1A1D426000E0EEAF /* API-Index.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "API-Index.md"; sourceTree = "<group>"; };
14511453
E01E6D8A121F130E001A484F /* CCLabelBMFont.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = CCLabelBMFont.h; sourceTree = "<group>"; };
@@ -1752,6 +1754,7 @@
17521754
isa = PBXGroup;
17531755
children = (
17541756
5018F2520DFDEAFF00C013A5 /* CCAction.h */,
1757+
D3D976351A896AC000462614 /* CCAction_Private.h */,
17551758
5018F2530DFDEAFF00C013A5 /* CCAction.m */,
17561759
5018F2580DFDEAFF00C013A5 /* CCActionInstant.h */,
17571760
5018F2590DFDEAFF00C013A5 /* CCActionInstant.m */,
@@ -2325,6 +2328,7 @@
23252328
9D856721191B019900573093 /* CCEffectContrast.h in Headers */,
23262329
50F9E8170E1AA34E000E7616 /* ccTypes.h in Headers */,
23272330
D3A2E7D2181E12750033614C /* CCPhysicsShape.h in Headers */,
2331+
D3D976361A896AC000462614 /* CCAction_Private.h in Headers */,
23282332
D2AB4B411A63C7400019215E /* CCGLFence.h in Headers */,
23292333
D24160FD1958F6EE003673BD /* CCAnimationManager_Private.h in Headers */,
23302334
506602110E38A70D000B500E /* CCScheduler.h in Headers */,

cocos2d/CCAction.h

Lines changed: 15 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@
2727

2828
#import "ccTypes.h"
2929

30-
enum {
31-
//! Default tag
32-
kCCActionTagInvalid = -1,
33-
};
3430

3531
/**
3632
CCAction is an abstract base class for all actions. Actions animate nodes by manipulating node properties over time
@@ -53,11 +49,7 @@ enum {
5349
- CCActionInterval
5450
5551
*/
56-
@interface CCAction : NSObject <NSCopying> {
57-
id __unsafe_unretained _originalTarget;
58-
id __unsafe_unretained _target;
59-
NSInteger _tag;
60-
}
52+
@interface CCAction : NSObject <NSCopying>
6153

6254

6355

@@ -75,13 +67,6 @@ enum {
7567
*/
7668
+ (id)action;
7769

78-
/**
79-
* Initializes and returns an action object.
80-
*
81-
* @return An initialized CCAction Object.
82-
*/
83-
- (id)init;
84-
8570

8671
/// -----------------------------------------------------------------------
8772
/// @name Action Targets
@@ -91,24 +76,15 @@ enum {
9176
The "target" is typically the node instance that received the [CCNode runAction:] message.
9277
The action will modify the target properties. The target will be set with the 'startWithTarget' method.
9378
When the 'stop' method is called, target will be set to nil.
94-
95-
@warning The target is 'assigned' (unsafe unretained), it is not 'retained' nor managed by ARC.
9679
*/
97-
@property (nonatomic,readonly,unsafe_unretained) id target;
98-
99-
/** The original target, since target can be nil. */
100-
@property (nonatomic,readonly,unsafe_unretained) id originalTarget;
80+
@property (nonatomic, readonly, unsafe_unretained) id target;
10181

10282
/// -----------------------------------------------------------------------
10383
/// @name Identifying an Action
10484
/// -----------------------------------------------------------------------
10585

106-
/** The action tag. An identifier of the action. */
107-
@property (nonatomic,readwrite,assign) NSInteger tag;
108-
109-
// NSCopying support.
110-
- (id)copyWithZone:(NSZone*) zone;
111-
86+
/** The action's name. An identifier of the action. */
87+
@property (nonatomic, readwrite, copy) NSString *name;
11288

11389
/// -----------------------------------------------------------------------
11490
/// @name Action Methods Implemented by Subclasses
@@ -122,15 +98,14 @@ enum {
12298
- (BOOL)isDone;
12399

124100
/**
125-
* Assigns a target to the action
126-
* Called before the action is started.
101+
* Overridden by subclasses to set up an action before it runs.
127102
*
128-
* @param target Target to assign to action (weak reference).
103+
* @param target Target the action will run on.
129104
*/
130105
- (void)startWithTarget:(id)target;
131106

132107
/**
133-
* Stops the action
108+
* Overriden by subclasses to clean up an action.
134109
* Called after the action has finished. Will assign the internal target reference to nil.
135110
* Note:
136111
* You should never call this method directly.
@@ -139,11 +114,11 @@ enum {
139114
- (void)stop;
140115

141116
/**
142-
* Steps the action.
143-
* Called for every frame with step interval.
117+
* Overridden by subclasses to update the target.
118+
* Called every frame with the time delta.
144119
*
145120
* Note:
146-
* Do not override unless you know what you are doing.
121+
* Do not call this method directly. Actions are automatically stepped when used with [CCNode runAction:].
147122
*
148123
* @param dt Ellapsed interval since last step.
149124
*/
@@ -177,15 +152,12 @@ enum {
177152
- CCActionInterval
178153
179154
*/
180-
@interface CCActionFiniteTime : CCAction <NSCopying> {
181-
// Duration in seconds.
182-
CCTime _duration;
183-
}
155+
@interface CCActionFiniteTime : CCAction
184156

185157
/** @name Duration */
186158

187159
/** Duration of the action in seconds. */
188-
@property (nonatomic,readwrite) CCTime duration;
160+
@property (nonatomic, readwrite) CCTime duration;
189161

190162
/** @name Reversing an Action */
191163

@@ -211,9 +183,7 @@ enum {
211183
* @note This action can not be used within a CCActionSequence because it is not an CCActionInterval action.
212184
* However you can use CCActionRepeatForever to repeat a CCActionSequence.
213185
*/
214-
@interface CCActionRepeatForever : CCAction <NSCopying> {
215-
CCActionInterval *_innerAction;
216-
}
186+
@interface CCActionRepeatForever : CCAction
217187

218188
// purposefully undocumented: user does not need to access inner action
219189
/* Inner action. */
@@ -283,10 +253,7 @@ enum {
283253
@note CCActionSpeed can not be added to a CCActionSequence because it does not inherit from CCActionFiniteTime.
284254
It can however be used to control the speed of an entire CCActionSequence.
285255
*/
286-
@interface CCActionSpeed : CCAction <NSCopying> {
287-
CCActionInterval *_innerAction;
288-
CGFloat _speed;
289-
}
256+
@interface CCActionSpeed : CCAction
290257

291258
/// -----------------------------------------------------------------------
292259
/// @name Creating a Speed Action
@@ -356,27 +323,7 @@ enum {
356323
Whenever `playerNode` changes its position, the position of `gameLayerNode` will be updated (moved in the opposite direction)
357324
to keep `playerNode` centered.
358325
*/
359-
@interface CCActionFollow : CCAction <NSCopying> {
360-
361-
// Node to follow.
362-
CCNode *_followedNode;
363-
364-
// Whether camera should be limited to certain area.
365-
BOOL _boundarySet;
366-
367-
// If screen-size is bigger than the boundary - update not needed.
368-
BOOL _boundaryFullyCovered;
369-
370-
// Fast access to the screen dimensions.
371-
CGPoint _halfScreenSize;
372-
CGPoint _fullScreenSize;
373-
374-
// World boundaries.
375-
float _leftBoundary;
376-
float _rightBoundary;
377-
float _topBoundary;
378-
float _bottomBoundary;
379-
}
326+
@interface CCActionFollow : CCAction
380327

381328
/// -----------------------------------------------------------------------
382329
/// @name Creating a Follow Action

0 commit comments

Comments
 (0)