Skip to content

Commit b777bb9

Browse files
committed
Merge branch 'develop' of github.com:cocos2d/cocos2d-iphone into develop
2 parents 87c9c79 + ba06fbe commit b777bb9

File tree

147 files changed

+28611
-2943
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+28611
-2943
lines changed

Resources/Images/planet1.png

76.3 KB
Loading
3.42 KB
Loading

Resources/Images/sphere-23.png

13.8 KB
Loading

Resources/Images/starynight.png

14.8 KB
Loading

UnitTests/CCPhysicsTests.m

Lines changed: 151 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,6 @@ -(void)testBodyEachCollisionPair
776776
[physicsNode onExit];
777777
}
778778

779-
780779
//Focusing on Position.
781780
-(void)testKineticBodyBasic1
782781
{
@@ -942,7 +941,7 @@ -(void)testKineticNodeActionsBasic1
942941
for(int i = 0; i < 100; i++)
943942
{
944943
float desired = (float)i * 0.1f * 100.0f/10.0f + (float)i * 0.1f * 200.0f/10.0f;
945-
NSLog(@"node1.position.x= %0.2f desired = %0.2f",body1.absolutePosition.x, desired);
944+
//NSLog(@"node1.position.x= %0.2f desired = %0.2f",body1.absolutePosition.x, desired);
946945
XCTAssertEqualWithAccuracy(body1.absolutePosition.x, desired , accuracy, @"Not in the write position");
947946
[scheduler update:0.10f];
948947
}
@@ -954,6 +953,156 @@ -(void)testKineticNodeActionsBasic1
954953

955954

956955

956+
-(void)testApplyImpulse
957+
{
958+
CCPhysicsNode *physics = [CCPhysicsNode node];
959+
[physics onEnter];
960+
961+
{
962+
CCNode *node = [CCNode node];
963+
[physics addChild:node];
964+
965+
node.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius:1 andCenter:CGPointZero];
966+
node.physicsBody.mass = 5;
967+
968+
node.physicsBody.velocity = ccp(10, 10);
969+
[node.physicsBody applyImpulse:ccp(5, 5)];
970+
XCTAssert(ccpDistance(ccp(11, 11), node.physicsBody.velocity) < 1e-5, @"");
971+
}{
972+
CCNode *node = [CCNode node];
973+
node.rotation = 90;
974+
[physics addChild:node];
975+
976+
node.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius:1 andCenter:CGPointZero];
977+
node.physicsBody.mass = 5;
978+
979+
node.physicsBody.velocity = ccp(10, 10);
980+
[node.physicsBody applyImpulse:ccp(5, 5)];
981+
XCTAssert(ccpDistance(ccp(11, 11), node.physicsBody.velocity) < 1e-5, @"");
982+
}{
983+
CCNode *node = [CCNode node];
984+
node.position = ccp(20, 20);
985+
[physics addChild:node];
986+
987+
node.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius:1 andCenter:CGPointZero];
988+
node.physicsBody.mass = 5;
989+
990+
node.physicsBody.velocity = ccp(10, 10);
991+
[node.physicsBody applyImpulse:ccp(5, 5) atWorldPoint:node.position];
992+
XCTAssert(ccpDistance(ccp(11, 11), node.physicsBody.velocity) < 1e-5, @"");
993+
}{
994+
CCNode *node = [CCNode node];
995+
node.position = ccp(20, 20);
996+
[physics addChild:node];
997+
998+
node.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius:1 andCenter:CGPointZero];
999+
node.physicsBody.mass = 5;
1000+
1001+
node.physicsBody.velocity = ccp(10, 10);
1002+
[node.physicsBody applyImpulse:ccp(5, 5) atLocalPoint:ccp(0, 0)];
1003+
XCTAssert(ccpDistance(ccp(11, 11), node.physicsBody.velocity) < 1e-5, @"");
1004+
}{
1005+
CCNode *node = [CCNode node];
1006+
node.position = ccp(20, 20);
1007+
node.rotation = 90;
1008+
[physics addChild:node];
1009+
1010+
node.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius:1 andCenter:CGPointZero];
1011+
node.physicsBody.mass = 5;
1012+
1013+
node.physicsBody.velocity = ccp(10, 10);
1014+
[node.physicsBody applyImpulse:ccp(5, 0) atLocalPoint:ccp(0, 0)];
1015+
XCTAssert(ccpDistance(ccp(10, 9), node.physicsBody.velocity) < 1e-5, @"");
1016+
}{
1017+
CCNode *node = [CCNode node];
1018+
node.position = ccp(20, 20);
1019+
node.rotation = 180;
1020+
[physics addChild:node];
1021+
1022+
node.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius:1 andCenter:CGPointZero];
1023+
node.physicsBody.mass = 5;
1024+
1025+
node.physicsBody.velocity = ccp(10, 10);
1026+
[node.physicsBody applyImpulse:ccp(5, 0) atLocalPoint:ccp(0, 1)];
1027+
XCTAssert(ccpDistance(ccp(9, 10), node.physicsBody.velocity) < 1e-5, @"");
1028+
XCTAssertEqualWithAccuracy(node.physicsBody.angularVelocity, -2, 1e-5, @"");
1029+
}
1030+
1031+
[physics onExit];
1032+
}
1033+
1034+
-(void)testApplyForce
1035+
{
1036+
CCPhysicsNode *physics = [CCPhysicsNode node];
1037+
[physics onEnter];
1038+
1039+
{
1040+
CCNode *node = [CCNode node];
1041+
[physics addChild:node];
1042+
1043+
node.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius:1 andCenter:CGPointZero];
1044+
node.physicsBody.mass = 5;
1045+
1046+
[node.physicsBody applyForce:ccp(5, 5)];
1047+
XCTAssert(ccpDistance(ccp(5, 5), node.physicsBody.force) < 1e-5, @"");
1048+
}{
1049+
CCNode *node = [CCNode node];
1050+
node.rotation = 90;
1051+
[physics addChild:node];
1052+
1053+
node.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius:1 andCenter:CGPointZero];
1054+
node.physicsBody.mass = 5;
1055+
1056+
[node.physicsBody applyForce:ccp(5, 5)];
1057+
XCTAssert(ccpDistance(ccp(5, 5), node.physicsBody.force) < 1e-5, @"");
1058+
}{
1059+
CCNode *node = [CCNode node];
1060+
node.position = ccp(20, 20);
1061+
[physics addChild:node];
1062+
1063+
node.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius:1 andCenter:CGPointZero];
1064+
node.physicsBody.mass = 5;
1065+
1066+
[node.physicsBody applyForce:ccp(5, 5) atWorldPoint:node.position];
1067+
XCTAssert(ccpDistance(ccp(5, 5), node.physicsBody.force) < 1e-5, @"");
1068+
}{
1069+
CCNode *node = [CCNode node];
1070+
node.position = ccp(20, 20);
1071+
[physics addChild:node];
1072+
1073+
node.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius:1 andCenter:CGPointZero];
1074+
node.physicsBody.mass = 5;
1075+
1076+
[node.physicsBody applyForce:ccp(5, 5) atLocalPoint:ccp(0, 0)];
1077+
XCTAssert(ccpDistance(ccp(5, 5), node.physicsBody.force) < 1e-5, @"");
1078+
}{
1079+
CCNode *node = [CCNode node];
1080+
node.position = ccp(20, 20);
1081+
node.rotation = 90;
1082+
[physics addChild:node];
1083+
1084+
node.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius:1 andCenter:CGPointZero];
1085+
node.physicsBody.mass = 5;
1086+
1087+
[node.physicsBody applyForce:ccp(5, 0) atLocalPoint:ccp(0, 0)];
1088+
XCTAssert(ccpDistance(ccp(0, -5), node.physicsBody.force) < 1e-5, @"");
1089+
}{
1090+
CCNode *node = [CCNode node];
1091+
node.position = ccp(20, 20);
1092+
node.rotation = 180;
1093+
[physics addChild:node];
1094+
1095+
node.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius:1 andCenter:CGPointZero];
1096+
node.physicsBody.mass = 5;
1097+
1098+
[node.physicsBody applyForce:ccp(5, 0) atLocalPoint:ccp(0, 1)];
1099+
XCTAssert(ccpDistance(ccp(-5, 0), node.physicsBody.force) < 1e-5, @"");
1100+
XCTAssertEqualWithAccuracy(node.physicsBody.torque, -5, 1e-5, @"");
1101+
}
1102+
1103+
[physics onExit];
1104+
}
1105+
9571106
// TODO
9581107
// * Check that body and shape settings are preserved through multiple add/remove cycles and are actually applied to the cpBody.
9591108
// * Check that changing properties before and after adding to an active physics node updates the properties correctly.

UnitTests/CCReaderTest.m

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
//
88

99
#import <XCTest/XCTest.h>
10+
#import "cocos2d.h"
11+
#import "CCBReader.h"
12+
#include <mach/mach.h>
13+
#include <mach/mach_time.h>
1014

1115
@interface CCReaderTest : XCTestCase
1216

@@ -20,6 +24,53 @@ - (void)setUp
2024
// Put setup code here; it will be run once, before the first test case.
2125
}
2226

27+
double machGetClockS()
28+
{
29+
static bool init = 0 ;
30+
static mach_timebase_info_data_t tbInfo ;
31+
static double conversionFactor ;
32+
if(!init)
33+
{
34+
init = 1 ;
35+
// get the time base
36+
mach_timebase_info( &tbInfo ) ;
37+
conversionFactor = tbInfo.numer / (1e9*tbInfo.denom) ; // ns->s
38+
}
39+
40+
return mach_absolute_time() * conversionFactor ; // seconds
41+
}
42+
43+
double machGetClockDiffS()
44+
{
45+
static double lastTime = 0;
46+
47+
double currentTime = machGetClockS() ;
48+
49+
double diff = currentTime - lastTime ;
50+
51+
lastTime = currentTime ; // update for next call
52+
53+
return diff ; // that's your answer
54+
}
55+
56+
-(void)testReaderPerformance
57+
{
58+
NSString *filePath =[[NSBundle mainBundle] pathsForResourcesOfType:@"ccbi" inDirectory:@"Resources-shared/Tests"][0];
59+
XCTAssertNotNil(filePath);
60+
61+
NSData * fileData = [[NSData alloc] initWithContentsOfFile:filePath];
62+
63+
CCBReader * ccbReader = [[CCBReader alloc] init];
64+
65+
machGetClockDiffS();
66+
for (int i = 0; i < 100; i++)
67+
{
68+
[ccbReader loadWithData:fileData owner:self];
69+
}
70+
71+
NSLog(@"TimeToRun: %0.8f", machGetClockDiffS());
72+
}
73+
2374
- (void)tearDown
2475
{
2576
// Put teardown code here; it will be run once, after the last test case.

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.0
1+
3.1.0

0 commit comments

Comments
 (0)