Is std::clock() reliable accross Windows, Mac and Linux?
I want to use this开发者_Go百科 as a means to compare how long since my last update in my game. Is the precision of it pretty consistent across these platforms.
Thanks
What has this to do with the Standard? That is totally dependent on the underlying implementation, also, the clock can be skewed by battery, drifts, underlying operating systems etc...
Really, for a game, you should be using a multimedia timer mechanism, that would be part of a multimedia library, to get the precision you want, or perhaps use a better but portable framework such as SDL for example.
It's very difficult to say, largely because different people have radically different ideas of what "pretty consistent" would mean. For some people, 1 ms drift is absolutely intolerable. For others, anything within a minute or so is fine. Some also depends on how frequently you're willing to update their clocks from a dependable time source. If they're on the Internet, you can (pretty easily) add code to get use SNTP to get the time quite accurately (if it's really necessary). Most of them are set up to synchronize their clocks that they'll typically stay within a few seconds or so of the correct time (unless the user has disabled that, which is fairly unusual).
精彩评论