zoukankan      html  css  js  c++  java
  • C#游戏开发中精确的时间调配

    方法一:参考《精通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; } } }
    
    
  • 相关阅读:
    项目经验分享(上)
    socket.io实现在线群聊
    socket.io中文文档
    常用的Sublime Text插件及安装方法
    常用的Atom插件
    atom及其插件activate-power-mode下载安装
    jeesite快速开发平台
    js权威指南
    hexSHA1散列加密解密(不可逆)
    腾讯云企业邮箱
  • 原文地址:https://www.cnblogs.com/rainbow70626/p/4553660.html
Copyright © 2011-2022 走看看