Commit c1594bba authored by Chengzhao Li's avatar Chengzhao Li
Browse files

- update version

- update package rate test
- show fps on screen
parent 8835171a
......@@ -849,6 +849,7 @@
CreatedOnToolsVersion = 6.0.1;
};
B77F1B2D17B978D7009739AE = {
DevelopmentTeam = 7RP2QY2JM4;
SystemCapabilities = {
com.apple.GameCenter = {
enabled = 0;
......
......@@ -10,7 +10,7 @@
<false/>
</dict>
<key>UUID</key>
<integer>23</integer>
<integer>25</integer>
<key>centeredOrigin</key>
<false/>
<key>currentResolution</key>
......@@ -1307,8 +1307,6 @@
</array>
</dict>
</array>
<key>selected</key>
<true/>
</dict>
<dict>
<key>UUID</key>
......@@ -3794,6 +3792,422 @@
</dict>
</array>
</dict>
<dict>
<key>UUID</key>
<integer>23</integer>
<key>baseClass</key>
<string>CCLabelTTF</string>
<key>children</key>
<array/>
<key>customClass</key>
<string></string>
<key>displayName</key>
<string>CCLabelTTF</string>
<key>memberVarAssignmentName</key>
<string></string>
<key>memberVarAssignmentType</key>
<integer>1</integer>
<key>properties</key>
<array>
<dict>
<key>name</key>
<string>name</string>
<key>type</key>
<string>StringSimple</string>
<key>value</key>
<string></string>
</dict>
<dict>
<key>name</key>
<string>position</string>
<key>type</key>
<string>Position</string>
<key>value</key>
<array>
<real>6.000030517578125</real>
<real>43</real>
<integer>0</integer>
<integer>0</integer>
<integer>0</integer>
</array>
</dict>
<dict>
<key>name</key>
<string>anchorPoint</string>
<key>type</key>
<string>Point</string>
<key>value</key>
<array>
<real>0.0</real>
<real>1</real>
</array>
</dict>
<dict>
<key>name</key>
<string>scale</string>
<key>type</key>
<string>ScaleLock</string>
<key>value</key>
<array>
<real>1</real>
<real>1</real>
<false/>
<integer>0</integer>
</array>
</dict>
<dict>
<key>name</key>
<string>string</string>
<key>type</key>
<string>Text</string>
<key>value</key>
<array>
<string>Token : </string>
<false/>
</array>
</dict>
<dict>
<key>name</key>
<string>fontName</string>
<key>type</key>
<string>FontTTF</string>
<key>value</key>
<string>Helvetica</string>
</dict>
<dict>
<key>name</key>
<string>fontSize</string>
<key>type</key>
<string>FloatScale</string>
<key>value</key>
<array>
<real>12</real>
<integer>0</integer>
</array>
</dict>
<dict>
<key>name</key>
<string>adjustsFontSizeToFit</string>
<key>type</key>
<string>Check</string>
<key>value</key>
<false/>
</dict>
<dict>
<key>name</key>
<string>dimensions</string>
<key>type</key>
<string>Size</string>
<key>value</key>
<array>
<real>0.0</real>
<real>0.0</real>
<integer>0</integer>
<integer>0</integer>
</array>
</dict>
<dict>
<key>name</key>
<string>horizontalAlignment</string>
<key>type</key>
<string>IntegerLabeled</string>
<key>value</key>
<integer>0</integer>
</dict>
<dict>
<key>name</key>
<string>verticalAlignment</string>
<key>type</key>
<string>IntegerLabeled</string>
<key>value</key>
<integer>0</integer>
</dict>
<dict>
<key>name</key>
<string>fontColor</string>
<key>type</key>
<string>Color4</string>
<key>value</key>
<array>
<real>1</real>
<real>1</real>
<real>1</real>
<real>1</real>
</array>
</dict>
<dict>
<key>name</key>
<string>outlineColor</string>
<key>type</key>
<string>Color4</string>
<key>value</key>
<array>
<real>0.0</real>
<real>0.0</real>
<real>0.0</real>
<real>0.0</real>
</array>
</dict>
<dict>
<key>name</key>
<string>outlineWidth</string>
<key>type</key>
<string>FloatScale</string>
<key>value</key>
<array>
<real>1</real>
<integer>0</integer>
</array>
</dict>
<dict>
<key>name</key>
<string>shadowColor</string>
<key>type</key>
<string>Color4</string>
<key>value</key>
<array>
<real>0.0</real>
<real>0.0</real>
<real>0.0</real>
<real>0.0</real>
</array>
</dict>
<dict>
<key>name</key>
<string>shadowBlurRadius</string>
<key>type</key>
<string>FloatScale</string>
<key>value</key>
<array>
<real>0.0</real>
<integer>0</integer>
</array>
</dict>
<dict>
<key>name</key>
<string>shadowOffset</string>
<key>type</key>
<string>Position</string>
<key>value</key>
<array>
<real>0.0</real>
<real>0.0</real>
<integer>0</integer>
<integer>0</integer>
<integer>0</integer>
</array>
</dict>
</array>
</dict>
<dict>
<key>UUID</key>
<integer>24</integer>
<key>baseClass</key>
<string>CCLabelTTF</string>
<key>children</key>
<array/>
<key>customClass</key>
<string></string>
<key>displayName</key>
<string>CCLabelTTF</string>
<key>memberVarAssignmentName</key>
<string>lbprToken</string>
<key>memberVarAssignmentType</key>
<integer>1</integer>
<key>properties</key>
<array>
<dict>
<key>name</key>
<string>name</string>
<key>type</key>
<string>StringSimple</string>
<key>value</key>
<string></string>
</dict>
<dict>
<key>name</key>
<string>position</string>
<key>type</key>
<string>Position</string>
<key>value</key>
<array>
<real>145.00003051757812</real>
<real>35.5</real>
<integer>0</integer>
<integer>0</integer>
<integer>0</integer>
</array>
</dict>
<dict>
<key>name</key>
<string>anchorPoint</string>
<key>type</key>
<string>Point</string>
<key>value</key>
<array>
<real>0.0</real>
<real>0.5</real>
</array>
</dict>
<dict>
<key>name</key>
<string>scale</string>
<key>type</key>
<string>ScaleLock</string>
<key>value</key>
<array>
<real>1</real>
<real>1</real>
<false/>
<integer>0</integer>
</array>
</dict>
<dict>
<key>name</key>
<string>string</string>
<key>type</key>
<string>Text</string>
<key>value</key>
<array>
<string>0</string>
<false/>
</array>
</dict>
<dict>
<key>name</key>
<string>fontName</string>
<key>type</key>
<string>FontTTF</string>
<key>value</key>
<string>Helvetica</string>
</dict>
<dict>
<key>name</key>
<string>fontSize</string>
<key>type</key>
<string>FloatScale</string>
<key>value</key>
<array>
<real>12</real>
<integer>0</integer>
</array>
</dict>
<dict>
<key>name</key>
<string>adjustsFontSizeToFit</string>
<key>type</key>
<string>Check</string>
<key>value</key>
<false/>
</dict>
<dict>
<key>name</key>
<string>dimensions</string>
<key>type</key>
<string>Size</string>
<key>value</key>
<array>
<real>0.0</real>
<real>0.0</real>
<integer>0</integer>
<integer>0</integer>
</array>
</dict>
<dict>
<key>name</key>
<string>horizontalAlignment</string>
<key>type</key>
<string>IntegerLabeled</string>
<key>value</key>
<integer>0</integer>
</dict>
<dict>
<key>name</key>
<string>verticalAlignment</string>
<key>type</key>
<string>IntegerLabeled</string>
<key>value</key>
<integer>0</integer>
</dict>
<dict>
<key>name</key>
<string>fontColor</string>
<key>type</key>
<string>Color4</string>
<key>value</key>
<array>
<real>1</real>
<real>1</real>
<real>1</real>
<real>1</real>
</array>
</dict>
<dict>
<key>name</key>
<string>outlineColor</string>
<key>type</key>
<string>Color4</string>
<key>value</key>
<array>
<real>0.0</real>
<real>0.0</real>
<real>0.0</real>
<real>0.0</real>
</array>
</dict>
<dict>
<key>name</key>
<string>outlineWidth</string>
<key>type</key>
<string>FloatScale</string>
<key>value</key>
<array>
<real>1</real>
<integer>0</integer>
</array>
</dict>
<dict>
<key>name</key>
<string>shadowColor</string>
<key>type</key>
<string>Color4</string>
<key>value</key>
<array>
<real>0.0</real>
<real>0.0</real>
<real>0.0</real>
<real>0.0</real>
</array>
</dict>
<dict>
<key>name</key>
<string>shadowBlurRadius</string>
<key>type</key>
<string>FloatScale</string>
<key>value</key>
<array>
<real>0.0</real>
<integer>0</integer>
</array>
</dict>
<dict>
<key>name</key>
<string>shadowOffset</string>
<key>type</key>
<string>Position</string>
<key>value</key>
<array>
<real>0.0</real>
<real>0.0</real>
<integer>0</integer>
<integer>0</integer>
<integer>0</integer>
</array>
</dict>
</array>
<key>selected</key>
<true/>
</dict>
</array>
<key>customClass</key>
<string>PackageRateScene</string>
......
......@@ -150,7 +150,7 @@ static MultiplayerController *_sharedMultiplayerController = nil;
[self.currentSession sendData:data toPeers:self.currentSessionPlayerIDs withMode:NCMCSessionSendDataReliable];
}
CCScene *chatScene = [CCBReader loadAsScene:@"ChatRoomScene"];
CCScene *chatScene = [CCBReader loadAsScene:@"PackageRateScene"];
[[CCDirector sharedDirector] replaceScene:chatScene];
}
......
......@@ -25,6 +25,7 @@
CCLabelTTF* lbprTotalCount;
CCLabelTTF* lbprPackageRate;
CCLabelTTF* lbprBandwidth;
CCLabelTTF* lbprToken;
BOOL isPing;
BOOL isPingEnabled;
......@@ -51,8 +52,8 @@
isPing = NO;
isPingEnabled = NO;
btnPRStart.title = @"Start";
messageSize = 0;
isLogEnabled = NO;
messageSize = MessageSizeForPackageRate;
isLogEnabled = YES;
packageRate = 0;
lbprPackageSize.string = [NSString stringWithFormat:@"%d", [self getPackageSize]];
......@@ -86,7 +87,7 @@
- (void)handleReceivedMessageWithNotification:(NSNotification *)notification
{
NSData* msgData = [[notification userInfo] objectForKey:@"data"];
//NSString* name = [[notification userInfo] objectForKey:@"name"];
NSString* name = [[notification userInfo] objectForKey:@"name"];
PingMessage *message = [[PingMessage alloc] initWithData:msgData error:nil];
......@@ -115,7 +116,7 @@
info.currentCount += 1;
receivedCount += 1;
if (isPing) {
if (true) {
lbprPackageSize.string = [NSString stringWithFormat:@"%d", [self getPackageSize]];
lbprCurrentPing.string = [NSString stringWithFormat:@"%f", timeInterval];
lbprReceviedCount.string = [NSString stringWithFormat:@"%d", receivedCount];
......@@ -124,10 +125,12 @@
lbprBandwidth.string = [NSString stringWithFormat:@"%f", [self getBandwidth]];
if (info.totalCount == info.currentCount) {
if (totalCount >= MaxPingCount && receivedCount >= MaxPingCount) {
lbprToken.string = [NSString stringWithFormat:@"%d", info.token];
/*if (totalCount >= MaxPingCount && receivedCount >= MaxPingCount) {
isPingEnabled = NO;
[self calculateResult];
}
}*/
[self calculateResultWithToken:info.token];
}
}
} else if (message.messageType == PingMessage_MsgType_Ping){
......@@ -145,7 +148,8 @@
NCMCSessionSendDataMode mode = message.isReliable ? NCMCSessionSendDataReliable : NCMCSessionSendDataUnreliable;
[[MultiplayerController instance] sendData:sendData toAllwithMode:mode];
//[[MultiplayerController instance] sendData:sendData toAllwithMode:mode];
[[MultiplayerController instance] sendData:sendData to:name withMode:mode];
CCLOG(@"send response to %@ with token : %u, length : %lu and local response time : %f", [[notification userInfo] objectForKey:@"peerName"], message.token, (unsigned long)sendData.length, packet.responseTime);
}
......@@ -234,14 +238,14 @@
totalCount = 0;
receivedCount = 0;
messageSize = 1;
messageSize = MessageSizeForPackageRate;
if (isLogEnabled) {
[self startLog];
}
lastServerBroadcastTime = 0;
packageRate = 1;
packageRate = 30;
isPingEnabled = YES;
}
......@@ -270,7 +274,7 @@
[message appendString:@"a"];
}
int token = totalCount + 1;
int token = ++totalCount;// + 1;
bufMsg.message = message;
bufMsg.token = token;
......@@ -287,16 +291,17 @@
info.token = token;
info.totalCount = [[[[MultiplayerController instance] currentSession] getConnectedPeers] count];
info.currentCount = 0;
info.number = totalCount + 1;
totalCount += info.totalCount;
//info.number = totalCount + 1;
//totalCount += info.totalCount;
info.timeIntervals = [[NSMutableArray alloc]initWithCapacity:info.totalCount];
NSString *t = [NSString stringWithFormat:@"%d", token];
[pingDict setValue:info forKey:t];
/*
if (totalCount >= MaxPingCount) {
isPingEnabled = NO;
}
}*/
}
- (NSNumber *)standardDeviationOf:(NSArray *)array mean:(double)mean
......@@ -318,8 +323,10 @@
- (void)calculateResult
{
NSMutableArray *allTimes = [[NSMutableArray alloc]init];
NSString* token;
for (id key in pingDict) {
PingInfo *info = pingDict[key];
token = key;
for(NSNumber *num in info.timeIntervals) {
[allTimes addObject:num];
......@@ -335,7 +342,8 @@
NSUInteger peerCount = [[[[MultiplayerController instance] currentSession] getConnectedPeers] count];
int realsize = [self getPackageSize];
NSString *log = [[NSString alloc]initWithFormat:@"%d, %d, %.8f, %lu, %.8f, %.8f\n", realsize, packageRate, [self getBandwidth], (unsigned long)peerCount, [average doubleValue], [std doubleValue]];
// NSString *log = [[NSString alloc]initWithFormat:@"%d, %d, %.8f, %lu, %.8f, %.8f\n", realsize, packageRate, [self getBandwidth], (unsigned long)peerCount, [average doubleValue], [std doubleValue]];
NSString *log = [[NSString alloc]initWithFormat:@"%@, %d, %d, %.8f, %lu, %.8f, %.8f\n", token, realsize, packageRate, [self getBandwidth], (unsigned long)peerCount, [average doubleValue], [std doubleValue]];
[self writeLog:log];
}
......@@ -344,8 +352,34 @@
[pingDict removeAllObjects];
receivedCount = 0;
totalCount = 0;
packageRate += 1;
//packageRate += 1;
isPingEnabled = YES;
}
}
- (void)calculateResultWithToken:(int) token
{
NSMutableArray *allTimes = [[NSMutableArray alloc]init];
NSString *t = [NSString stringWithFormat:@"%d", token];
PingInfo *info = pingDict[t];
for(NSNumber *num in info.timeIntervals) {
[allTimes addObject:num];
}
NSNumber *average = [allTimes valueForKeyPath:@"@avg.self"];