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; } } }
    
    
  • 相关阅读:
    做代码的曲线问题
    全书目录
    关于《Delphi源代码分析》的讨论
    说说“从编程到工程”专栏的由来
    CF285E Positions in Permutations
    CF264B Good Sequences
    CF115E Linear Kingdom Races
    CF633F The Chocolate Spree
    CF767C Garland
    CF559C Gerald and Giant Ches
  • 原文地址:https://www.cnblogs.com/rainbow70626/p/4553660.html
Copyright © 2011-2022 走看看