Skip to content

Commit

Permalink
Fixed an integer promotion issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Ge0rges committed Feb 22, 2017
1 parent cb430c2 commit 4ef4df6
Show file tree
Hide file tree
Showing 10 changed files with 5 additions and 5 deletions.
Binary file modified Synaction Product/libSynaction.a
Binary file not shown.
Binary file not shown.
10 changes: 5 additions & 5 deletions Synaction/Synaction.m
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ - (uint64_t)currentNetworkTime {// https://developer.apple.com/library/content/q
}

uint64_t timeNanoSeconds = baseTime * sTimebaseInfo.numer / sTimebaseInfo.denom;
return timeNanoSeconds - self.hostTimeOffset;
return (int64_t)timeNanoSeconds - self.hostTimeOffset;
}

- (void)atExactTime:(uint64_t)val runBlock:(dispatch_block_t _Nonnull)block {
Expand All @@ -108,8 +108,8 @@ - (void)atExactTime:(uint64_t)val runBlock:(dispatch_block_t _Nonnull)block {
dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, DISPATCH_TIMER_STRICT, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0));
dispatch_source_set_event_handler(timer, ^{
dispatch_source_cancel(timer); // one shot timer
while (val > [self currentNetworkTime]) {
[NSThread sleepForTimeInterval:0];
while (val > [self currentNetworkTime]+(uint64_t)1) {
sleep(0);
}
block();
});
Expand Down Expand Up @@ -162,8 +162,8 @@ - (void)session:(MCSession *)session didReceiveData:(NSData *)data fromPeer:(MCP
//uint64_t latencyWithHost = ([self currentNetworkTime] - timePingSent)/2;// Calculates the estimated latency for one way travel

int64_t calculatedOffset = ((int64_t)[self currentNetworkTime] + (int64_t)timePingSent - (2*(int64_t)timeHostReceivedPing))/2; // WAY 1. Best because it doesn't depend on latency
//calculatedOffset2 = latencyWithHost - timeHostReceivedPing + timePingSent;// WAY 2
//calculatedOffset3 = -latencyWithHost - timeHostReceivedPing + [self currentNetworkTime];// WAY 3
//calculatedOffset2 = (int64_t)latencyWithHost - (int64_t)timeHostReceivedPing + (int64_t)timePingSent;// WAY 2
//calculatedOffset3 = -(int64_t)latencyWithHost - (int64_t)timeHostReceivedPing + (int64_t)[self currentNetworkTime];// WAY 3

[calculatedOffsets addObject:[NSNumber numberWithLongLong:calculatedOffset]];

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified build/Synaction.build/Debug-iphoneos/Synaction.build/dgph
Binary file not shown.
Binary file not shown.
Binary file modified build/Synaction.build/Debug-iphonesimulator/Synaction.build/dgph
Binary file not shown.

0 comments on commit 4ef4df6

Please sign in to comment.