Skip to content

CCDirector Refactoring and un-singletoning #1174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 63 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
d1a6ca9
Prevent CCScenes from being added to other scenes
andykorth Dec 31, 2014
575418f
Merge branch 'develop-v4' of github.com:cocos2d/cocos2d-swift into CC…
andykorth Dec 31, 2014
bc31b1f
Extracting scheduler and actionManager from CCDirector
andykorth Jan 2, 2015
d0e1982
Tracking down action failure in a clip node.
andykorth Jan 2, 2015
f3a7456
Fix stencil node and several tests, parenting behavior.
andykorth Jan 5, 2015
55a5c94
Adding support for multiple CCViews
osinoleg Jan 12, 2015
a464362
Accessing views and directors from CCNode.
andykorth Jan 12, 2015
7618f97
CCScene's reference to director should be weak
andykorth Jan 12, 2015
7386c4c
Replaced the use of [CCDirector sharedDirector] wherever possible, wi…
osinoleg Jan 14, 2015
5a30cad
Separate CCScheduler into public and private headers
andykorth Jan 14, 2015
7d8fdc6
Simplify fixed mode of CCActionManager in new CCDirector.
andykorth Jan 14, 2015
499e1a8
Merge and add test comments.
andykorth Jan 14, 2015
6b3897f
merge
andykorth Jan 14, 2015
9f2d814
Merge branch 'CCDirectorRefactorActionManagerChanges' into CCDirector…
andykorth Jan 14, 2015
d10b412
Merge branch 'develop-v4' of github.com:cocos2d/cocos2d-swift into CC…
andykorth Jan 14, 2015
7701a45
Added a currentDirector method that uses thread local storage, replac…
osinoleg Jan 15, 2015
98026ff
Changed CCDirector access inside CCAction.
osinoleg Jan 15, 2015
31455c3
Remove unneeded method from private header
andykorth Jan 16, 2015
8007ad3
Add new CCAction tests, including a performance test.
andykorth Jan 16, 2015
59d76dd
Rename SchedulerTarget to SchedulableTarget to reduce confusion with …
andykorth Jan 16, 2015
cf386c1
Initial working commit of merged action and scheduler.
andykorth Jan 16, 2015
2d50358
Remove old ActionManager references. Ensure actions can pause
andykorth Jan 16, 2015
b5e5c92
merge
andykorth Jan 19, 2015
7e264f7
CCScheduledTarget work
andykorth Jan 19, 2015
43ae637
copy on write arrays for scheduler
andykorth Jan 19, 2015
fa29a69
profiling, performance adjustments, fix removals
andykorth Jan 19, 2015
9e35aac
CCScheduler is noarc
andykorth Jan 19, 2015
f820e2c
CCScheduler cleanup and some fixes.
slembcke Jan 20, 2015
51f21da
CopyOnWriteArray comments and fixes.
slembcke Jan 20, 2015
ebdff72
More scheduled target refactoring
slembcke Jan 20, 2015
02336b5
Merge pull request #2 from slembcke/MergeSchedulerAndActionManager
andykorth Jan 20, 2015
6061b89
Replaced O(n) removal with constant time remove from target.
andykorth Jan 20, 2015
46ee642
Remove __bridge from no-arc file
andykorth Jan 20, 2015
64761fa
Scheduler and action performance tests
andykorth Jan 20, 2015
e6c0734
Respect paused state when adding actions
andykorth Jan 20, 2015
c98c15c
Provide different backing data structures to scheduler's copy on writ…
andykorth Jan 20, 2015
c9747b7
Conflicts:
krazyeom Apr 6, 2014
c820b05
Update mac ccview
andykorth Jan 21, 2015
a922e75
Merge branch 'CCDirectorRefactorSchedulerChanges' into MacKeyboard
andykorth Jan 21, 2015
b20d4e4
Quick Mac keyboard support.
andykorth Jan 21, 2015
99f00ff
Merge branch 'MacKeyboard' into CCDirector/MergeSchedulerAndActionMan…
andykorth Jan 21, 2015
2bbf148
Merge remote-tracking branch 'cocos/develop' into CCDirector/MergeSch…
andykorth Jan 21, 2015
c9ea8f3
Merge remote-tracking branch 'oleg/ccview_refactor_v4' into CCDirecto…
andykorth Jan 21, 2015
af226bc
Missed a conflict.
andykorth Jan 21, 2015
aeb528e
1 director per view.
slembcke Jan 21, 2015
b912ab6
Merge branch 'CCDirectorUpdates' into CCDirector/MergeSchedulerAndAct…
andykorth Jan 21, 2015
854de32
Update tests for new scheduler location
andykorth Jan 21, 2015
1cc54fb
Merge remote-tracking branch 'scottLocal/CCDirector' into CCDirector/…
andykorth Jan 21, 2015
0041c59
Fixes and assertions for failed responder stuff
andykorth Jan 21, 2015
a899a01
Scene transitions need the right director setup.
andykorth Jan 21, 2015
668d36a
Tests for action queueing.
andykorth Jan 21, 2015
804ecb4
Queue actions if they can't be added immediately
andykorth Jan 21, 2015
bedca73
Change how scenes access non-singleton director
andykorth Jan 22, 2015
8e0ad70
Plugging leaks
andykorth Jan 22, 2015
1ccc631
Ensure TTF labels work with the new director changes
andykorth Jan 22, 2015
a488fd0
Use presentScene exclusively to change scenes. Refactor duplicate and…
andykorth Jan 22, 2015
383824f
Rename start/stopAnimation to start/stopRunLoop, to reflect its actua…
andykorth Jan 22, 2015
b710945
Fixing unit tests. Disabling package tests for now
andykorth Jan 22, 2015
62f0a0d
Merge branch 'develop' of github.com:cocos2d/cocos2d-swift into CCDir…
andykorth Jan 22, 2015
971277e
Fix mac and android build targets
andykorth Jan 22, 2015
a7214d4
Mac director fixes
andykorth Jan 22, 2015
3c425d8
Main loop refactor. Fixes for Mac window/view size
andykorth Jan 23, 2015
45d0184
Remove a layer of indirection with mac NSResponder methods. Do the di…
andykorth Jan 23, 2015
29419ac
Code review cleanup
andykorth Jan 26, 2015
8495c01
Merge branch 'develop' of github.com:cocos2d/cocos2d-swift into CCDir…
andykorth Jan 26, 2015
9d157af
Clarifying CCDirectorDelegate and its purpose
andykorth Jan 26, 2015
13d3a94
Fix iOS CCDirector references.
andykorth Jan 26, 2015
924bedc
Fix iOS startup.
andykorth Jan 27, 2015
ed4d792
Merge branch 'develop' of github.com:cocos2d/cocos2d-swift into CCDir…
andykorth Jan 27, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CCRendererGLSupport.m
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,10 @@ -(void)bindWithClear:(GLbitfield)mask color:(GLKVector4)color4 depth:(GLclampf)d
}
}

-(void)syncWithView:(CC_VIEW<CCDirectorView> *)view;
-(void)syncWithView:(CC_VIEW<CCView> *)view;
{
[super syncWithView:view];
_fbo = [(CCGLView *)view fbo];
_fbo = [view fbo];
}

@end
3 changes: 2 additions & 1 deletion UnitTests/CCActionTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ - (void)setUp
[super setUp];

scene = [CCScene node];
[scene onEnter];

startPos = ccp(0,0);
endPos = ccp(2.0f,1.0f);
Expand Down Expand Up @@ -83,7 +84,7 @@ - (void)testSimpleAction
[action step: 0.5f];
XCTAssertEqualWithAccuracy(action.elapsed, 0.5f, accuracy, @"Elapsed time incorrect after stepping.");

XCTAssertTrue( (ccpDistance(node.position, startPos) - ccpDistance(startPos, endPos)) / 2.0f < accuracy, @"Node should have moved half the distance between start and end.");
XCTAssertEqualWithAccuracy( ccpDistance(node.position, startPos), ccpDistance(startPos, endPos) / 2.0f, accuracy, @"Node should have moved half the distance between start and end.");

//Step the action to completion.
[action step: 0.5f];
Expand Down
37 changes: 26 additions & 11 deletions UnitTests/CCEffectTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,31 @@
#import <XCTest/XCTest.h>
#import "cocos2d.h"
#import "CCEffectUtils.h"
#import "CCDirector_Private.h"

@interface CCEffectTests : XCTestCase
@end

@implementation CCEffectTests


-(void) setUp
{
CCDirector *director = [CCDirector director];
//director.
[CCDirector bindDirector: director];
}

-(void)tearDown
{
[CCDirector bindDirector:nil];
}


-(void)testNodeAncestry
{
CCSprite *s1 = [CCSprite spriteWithImageNamed:@"f1.png"];
CCSprite *s2 = [CCSprite spriteWithImageNamed:@"f1.png"];
CCRenderableNode *s1 = [CCRenderableNode node];
CCRenderableNode *s2 = [CCRenderableNode node];

BOOL commonAncestor = NO;

Expand All @@ -31,7 +46,7 @@ -(void)testNodeAncestry

-(void)testSameNode
{
CCSprite *s1 = [CCSprite spriteWithImageNamed:@"f1.png"];
CCRenderableNode *s1 = [CCRenderableNode node];

BOOL commonAncestor = NO;
GLKMatrix4 transform;
Expand Down Expand Up @@ -62,25 +77,25 @@ -(void)testSameNode

-(void)testSiblingTransforms
{
CCSprite *root = [CCSprite spriteWithImageNamed:@"f1.png"];
CCRenderableNode *root = [CCRenderableNode node];
root.name = @"root";
root.positionType = CCPositionTypePoints;
root.position = ccp(0.0f, 0.0f);
root.anchorPoint = ccp(0.0f, 0.0f);

CCSprite *s1 = [CCSprite spriteWithImageNamed:@"f1.png"];
CCRenderableNode *s1 = [CCRenderableNode node];
s1.name = @"s1";
s1.positionType = CCPositionTypePoints;
s1.position = ccp(10.0f, 10.0f);
s1.anchorPoint = ccp(0.0f, 0.0f);

CCSprite *s2 = [CCSprite spriteWithImageNamed:@"f1.png"];
CCRenderableNode *s2 = [CCRenderableNode node];
s2.name = @"s2";
s2.positionType = CCPositionTypePoints;
s2.position = ccp(100.0f, 100.0f);
s2.anchorPoint = ccp(0.0f, 0.0f);

CCSprite *s3 = [CCSprite spriteWithImageNamed:@"f1.png"];
CCRenderableNode *s3 = [CCRenderableNode node];
s3.name = @"s3";
s3.positionType = CCPositionTypePoints;
s3.position = ccp(1000.0f, 1000.0f);
Expand Down Expand Up @@ -176,25 +191,25 @@ -(void)testSiblingTransforms

- (void)testAncestorTransforms
{
CCSprite *root = [CCSprite spriteWithImageNamed:@"f1.png"];
CCSprite *root = [CCRenderableNode node];
root.name = @"root";
root.positionType = CCPositionTypePoints;
root.position = ccp(0.0f, 0.0f);
root.anchorPoint = ccp(0.0f, 0.0f);

CCSprite *s1 = [CCSprite spriteWithImageNamed:@"f1.png"];
CCSprite *s1 = [CCRenderableNode node];
s1.name = @"s1";
s1.positionType = CCPositionTypePoints;
s1.position = ccp(10.0f, 10.0f);
s1.anchorPoint = ccp(0.0f, 0.0f);

CCSprite *s2 = [CCSprite spriteWithImageNamed:@"f1.png"];
CCSprite *s2 = [CCRenderableNode node];
s2.name = @"s2";
s2.positionType = CCPositionTypePoints;
s2.position = ccp(100.0f, 100.0f);
s2.anchorPoint = ccp(0.0f, 0.0f);

CCSprite *s3 = [CCSprite spriteWithImageNamed:@"f1.png"];
CCSprite *s3 = [CCRenderableNode node];
s3.name = @"s3";
s3.positionType = CCPositionTypePoints;
s3.position = ccp(1000.0f, 1000.0f);
Expand Down
28 changes: 15 additions & 13 deletions UnitTests/CCNodeTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@
#import "cocos2d.h"
#import "CCDirector_Private.h"
#import "CCNode_Private.h"
#import "CCScheduler_Private.h"

@interface CCNodeTests : XCTestCase

@end

@interface CCDirector()
+(void) resetSingleton;
@end

@implementation CCNodeTests

-(void) setUp
{
// force creation of a new sharedDirector or state will leak between each test.
[CCDirector resetSingleton];
[CCDirector bindDirector: [CCDirector director]];
}

-(void)tearDown
{
[CCDirector bindDirector:nil];
}

-(void)testGetChildByName
Expand Down Expand Up @@ -137,7 +139,7 @@ -(void)testNodeCleanupUnschedulesBlocks{

XCTAssertTrue(!firstActionOccured, @"No action should happen yet!");

[[[CCDirector sharedDirector] scheduler] update: 1.0];
[scene.scheduler update: 1.0];

XCTAssertTrue(!firstActionOccured, @"Should not occur since this node had cleanup called on it.");
}
Expand Down Expand Up @@ -172,7 +174,7 @@ -(void)testRemovingScheduledNodes
[scene removeChild:first cleanup:NO];
[scene removeChild:second cleanup:YES];

[[[CCDirector sharedDirector] scheduler] update: 1.0];
[scene.scheduler update: 1.0];

XCTAssertTrue(firstActionOccured);
XCTAssertTrue(!secondActionOccured, @"Cleaned up action should have unscheduled itself and should not occur.");
Expand Down Expand Up @@ -233,7 +235,7 @@ -(void)testCCNodePositionTypeUIPointsUnscaled
-(void)testCCNodePositionTypePointsScaled
{
// let's say our scale was set the same way since we launched the app.
[CCDirector sharedDirector].UIScaleFactor = 2.0;
[CCDirector currentDirector].UIScaleFactor = 2.0;

CCScene *scene = [CCScene node];

Expand All @@ -260,7 +262,7 @@ -(void)testCCNodePositionTypePointsScaled
-(void)testCCNodePositionTypeUIPointsScaled
{
// let's say our scale was set the same way since we launched the app.
[CCDirector sharedDirector].UIScaleFactor = 2.0;
[CCDirector currentDirector].UIScaleFactor = 2.0;

CCScene *scene = [CCScene node];

Expand Down Expand Up @@ -330,7 +332,7 @@ -(void)testCCNodeUIScaleFactorShouldDoNothingToMeasurementsInPoints
XCTAssertEqual(first.contentSizeInPoints.width, (CGFloat) 1.0, @"");
XCTAssertEqual(first.contentSizeInPoints.height, (CGFloat) 2.0, @"");

[CCDirector sharedDirector].UIScaleFactor = 2.0;
[CCDirector currentDirector].UIScaleFactor = 2.0;
// Since our positionInPoints are not UIPoints (we didn't change the position type), changing the UIScaleFactor has no effect.

XCTAssertEqual(first.position.x, (CGFloat) 10.0f, @"");
Expand Down Expand Up @@ -368,7 +370,7 @@ -(void)testCCNodePositionTypeChangeToUIPoints
XCTAssertEqual(first.contentSizeInPoints.width, (CGFloat) 1.0, @"");
XCTAssertEqual(first.contentSizeInPoints.height, (CGFloat) 2.0, @"");

[CCDirector sharedDirector].UIScaleFactor = 2.0;
[CCDirector currentDirector].UIScaleFactor = 2.0;

XCTAssertEqual(first.positionInPoints.x, (CGFloat) 20.0, @"");
XCTAssertEqual(first.positionInPoints.y, (CGFloat) 30.0, @"");
Expand Down Expand Up @@ -403,7 +405,7 @@ -(void)testCCNodeChangingPositionType
XCTAssertEqual(first.contentSizeInPoints.width, (CGFloat) 1.0, @"");
XCTAssertEqual(first.contentSizeInPoints.height, (CGFloat) 2.0, @"");

[CCDirector sharedDirector].UIScaleFactor = 2.0;
[CCDirector currentDirector].UIScaleFactor = 2.0;

XCTAssertEqual(first.positionInPoints.x, (CGFloat) 20.0, @"");
XCTAssertEqual(first.positionInPoints.y, (CGFloat) 30.0, @"");
Expand Down Expand Up @@ -445,7 +447,7 @@ -(void)testCCNodeChangingScaleType
XCTAssertEqual(first.scaleXInPoints, (CGFloat) 1.0, @"");
XCTAssertEqual(first.scaleYInPoints, (CGFloat) 1.0, @"");

[CCDirector sharedDirector].UIScaleFactor = 2.0;
[CCDirector currentDirector].UIScaleFactor = 2.0;

XCTAssertEqual(first.positionInPoints.x, (CGFloat) 10.0, @"");
XCTAssertEqual(first.positionInPoints.y, (CGFloat) 15.0, @"");
Expand Down
2 changes: 1 addition & 1 deletion UnitTests/CCPackageDownloadManagerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ - (void)setUp

[(AppController *)[UIApplication sharedApplication].delegate configureCocos2d];
// Stop the normal cocos2d main loop from happening during the tests. We will step it manually.
[[CCDirector sharedDirector] stopAnimation];
[[CCDirector currentDirector] stopRunLoop];

[NSURLProtocol registerClass:[CCPackageDownloadManagerTestURLProtocol class]];

Expand Down
4 changes: 2 additions & 2 deletions UnitTests/CCPackageDownloadTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ - (void)setUp

[(AppController *)[UIApplication sharedApplication].delegate configureCocos2d];
// Stop the normal cocos2d main loop from happening during the tests. We will step it manually.
[[CCDirector sharedDirector] stopAnimation];
[[CCDirector currentDirector] stopRunLoop];

[NSURLProtocol registerClass:[CCPackageDownloadTestURLProtocol class]];

Expand Down Expand Up @@ -162,7 +162,7 @@ - (void)tearDown
{
[NSURLProtocol unregisterClass:[CCPackageDownloadTestURLProtocol class]];

[[CCDirector sharedDirector] startAnimation];
[[CCDirector currentDirector] startRunLoop];

[super tearDown];
}
Expand Down
2 changes: 1 addition & 1 deletion UnitTests/CCPackageManagerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ - (void)setUp

[(AppController *)[UIApplication sharedApplication].delegate configureCocos2d];
// Stop the normal cocos2d main loop from happening during the tests. We will step it manually.
[[CCDirector sharedDirector] stopAnimation];
[[CCDirector currentDirector] stopRunLoop];

self.packageManager = [[CCPackageManager alloc] init];
_packageManager.delegate = self;
Expand Down
11 changes: 7 additions & 4 deletions UnitTests/CCPhysicsTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#import "CCPhysics+ObjectiveChipmunk.h"
#import "CCDirector_Private.h"
#import "CCScheduler_Private.h"
#import "AppDelegate.h"

@interface CCScheduler(Test)
Expand All @@ -31,7 +32,7 @@ - (void)setUp
[super setUp];

[(AppController *)[UIApplication sharedApplication].delegate configureCocos2d];
[[CCDirector sharedDirector] startAnimation];
[[CCDirector currentDirector] startRunLoop];
}

static void
Expand Down Expand Up @@ -911,6 +912,8 @@ -(void)testKineticBodyBasic2
//it subsuquently posesses are changed to fixed scheduled.
-(void)testKineticNodeActionsBasic1
{
CCScene *scene = [CCScene node];

CCPhysicsNode *physicsNode = [CCPhysicsNode node];
physicsNode.collisionDelegate = self;
physicsNode.gravity = ccp(0, 0);
Expand Down Expand Up @@ -940,9 +943,9 @@ -(void)testKineticNodeActionsBasic1
[node1 runAction:[CCActionMoveBy actionWithDuration:10 position:ccp(100, 0)]];

// Force entering the scene to set up the physics objects.
[physicsNode onEnter];
[scene addChild:physicsNode];

CCScheduler * scheduler = [CCDirector sharedDirector].scheduler;
CCScheduler * scheduler = physicsNode.scene.scheduler;
scheduler.fixedUpdateInterval = 0.1f;
[scheduler update:0.10f];// first tick
const float accuracy = 1e-4;
Expand All @@ -951,7 +954,7 @@ -(void)testKineticNodeActionsBasic1
{
float desired = (float)i * 0.1f * 100.0f/10.0f + (float)i * 0.1f * 200.0f/10.0f;
//NSLog(@"node1.position.x= %0.2f desired = %0.2f",body1.absolutePosition.x, desired);
XCTAssertEqualWithAccuracy(body1.absolutePosition.x, desired , accuracy, @"Not in the write position");
XCTAssertEqualWithAccuracy(body1.absolutePosition.x, desired , accuracy, @"Not in the right position");
[scheduler update:0.10f];
}
}
Expand Down
19 changes: 12 additions & 7 deletions UnitTests/CCRendererTests.m
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
//
// CCFileUtilTests
//
// Created by Andy Korth on December 6th, 2013.
//
//

#import <XCTest/XCTest.h>
#import "cocos2d.h"

#import "CCRenderer_private.h"

#import "CCDirector_Private.h"

@interface NSValue()
-(size_t)CCRendererSizeOf;
Expand All @@ -21,6 +15,17 @@ @interface CCRendererTests : XCTestCase

@implementation CCRendererTests

-(void) setUp
{
[CCDirector bindDirector: [CCDirector director]];
}

-(void)tearDown
{
[CCDirector bindDirector:nil];
}


-(void)testBlendModeCacheInterning
{
NSDictionary *options = @{
Expand Down
Loading