码迷,mamicode.com
首页 > Windows程序 > 详细

C#游戏开发中精确的时间调配

时间:2015-06-05 08:43:28      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:

方法一:参考《精通C#游戏编程》一书。根据学习WorldWind源码可知,WorldWind中采用的方法与该方法基本一致。

using
System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; namespace GameLoop//根据需要修改名称空间 { public class PreciseTimer { [System.Security.SuppressUnmanagedCodeSecurity] [DllImport("kernel32")] private static extern bool QueryPerformanceFrequency(ref long PerformanceFrequency); [System.Security.SuppressUnmanagedCodeSecurity] [DllImport("kernel32")] private static extern bool QueryPerformanceCounter(ref long PerformanceCount); long _ticksPerSecond = 0; long _previousElapsedTime = 0; public PreciseTimer() { QueryPerformanceFrequency(ref _ticksPerSecond); GetElapsedTime(); // Get rid of first rubbish result } public double GetElapsedTime() { long time = 0; QueryPerformanceCounter(ref time); double elapsedTime = (double)(time - _previousElapsedTime) / (double)_ticksPerSecond; _previousElapsedTime = time; return elapsedTime; } } }

C#游戏开发中精确的时间调配

标签:

原文地址:http://www.cnblogs.com/rainbow70626/p/4553660.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!