我试图用新的函数替换Xcode中一些不推荐使用的函数,尽管我似乎不太清楚如何使其正常工作:
AbsoluteTime startTime = UpTime();
float frameTime = UnsignedWideToUInt64(AbsoluteDeltaToNanoseconds(UpTime(),startTime))/1E9;
我收到了两个警告:
'UpTime' is deprecated: first deprecated in macOS 10.8
'AbsoluteDeltaToNanoseconds' is deprecated: first deprecated in macOS 10.8
我在这里查看了各种其他线程,并尝试使用:
NSTimeInterval systemUptime = [[NSProcessInfo processInfo] systemUptime] / 1E9;
不过,它似乎没有返回相同的结果:
1: 0.011983 // deprecated function
2: 0.000431 // replacement function
1: 0.007218
2: 0.000431
1: 0.007084
2: 0.000431
我想我还需要做其他事情来获得新函数的正确值?
[[NSProcessInfo processInfo] systemUptime]
以秒为单位返回正常运行时间,它不能替代UpTime()
。CCD_ 3应该是CCD_ 4的简单替代品。
至于AbsoluteDeltaToNanoseconds()
,您只需编写代码来计算时间戳之间的绝对差,我相信mach_absolute_time()
在macOS上已经是纳秒了(但您应该验证这一点)。然后,只要在执行除法时正确地将值强制转换为(uint64_t),那么在浮点结果中应该具有相同的精度。