Time in milliseconds is difference across platforms

I’m trying to create timestamps for messages being sent across a network. I’m currently testing the game on an Android device and the iPhone emulator on macOS.

Using the cocos2dx function

cocos2d::utils::getTimeInMilliseconds();

gives me different results depending on the platform. The iPhone emulator values are always less than the Android device which is causing resolution errors when I compare them to try and find the earliest event time.

What can I use to get correct millisecond/microsecond time values across multiple devices?

I use the std::chrono api

I’ve tried chrono and the time values are still off, even more so than the cocos2dx API.

Can you be more specific with an example to demonstrate successfully syncing both systems to the same value?

The solution I have in mind to sync both systems over a network would be to timestamp each event on a system in relation to the start of the game session. Comparing the deltas on the other system would then give an indication as to who created the event first. A and B hit button X. A records 1568 milliseconds since the start of the game, B records 1789 since the start of the game. Send deltas to other systems, systems compare values.

This sounds like a very ugly problem to try and solve, good luck. What you’re suggesting seems like a good idea, but if you see the state of the game start to drift between the two devices I’d consider sync’ing up at multiple times during the game session, instead of just once at the beginning.

I agree its pretty ugly and non-trivial, the best kind of problem! :slight_smile: I’ve implemented at least 4 different “solutions” so far with poor results. The variance between sample deltas on each individual device/OS makes it near impossible to sync the results tied with a varying framework fps and the compiler results/optimisations for iOS/macOS/NDK. The error margin ranges from 300 to 900 milliseconds which is too much for comparing the values when there are conflicts.