~ubuntu-branches/ubuntu/trusty/openbve/trusty

« back to all changes in this revision

Viewing changes to openBVE/OpenBve/Timers.cs

  • Committer: Bazaar Package Importer
  • Author(s): Paul Sladen
  • Date: 2009-08-06 02:05:00 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090806020500-tld4d1b8vl3vhroz
Tags: 1.2.0.3-0ubuntu1
* New upstream stable version (1.2.0.3)
* debian/copyright: update to reflect minor wording changes
* debian/rules: "./rules fetch-html" for {changelog,releasenotes}.html
* changelog.html: update (1.2.0.3)
* releasenotes.html: update (1.2.0.0)
* debian/rules: DEBUG_CONFIGURATION=Release to switch codepaths used
* debian/control: openbve-data (>= 1.2.0.3+dfsg)

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
namespace OpenBve {
5
5
        internal static class Timers {
6
6
 
7
 
                // win32-specific api-declarations
8
 
                [System.Runtime.InteropServices.DllImport("kernel32.dll")]
9
 
                private static extern bool QueryPerformanceFrequency(out long lpFrequency);
10
 
                [System.Runtime.InteropServices.DllImport("kernel32.dll")]
11
 
                private static extern bool QueryPerformanceCounter(out long lpPerformanceCount);
12
 
 
13
7
                // members
14
 
                private static bool WindowsHighPrecisionTimer = false;
15
 
                private static double WindowsHighPrecisionTimerInverseFrequency = 0.0;
16
 
                private static long WindowsHighPrecisionTimerCounter = 0;
17
8
                private static double SdlTime = 0.0;
18
9
 
19
10
                // initialize
20
11
                internal static void Initialize() {
21
 
                        if (Program.CurrentPlatform == Program.Platform.Windows) {
22
 
                                long f; if (QueryPerformanceFrequency(out f)) {
23
 
                                        WindowsHighPrecisionTimerInverseFrequency = 1.0 / (double)f;
24
 
                                        QueryPerformanceCounter(out WindowsHighPrecisionTimerCounter);
25
 
                                        WindowsHighPrecisionTimer = true;
26
 
                                }
27
 
                        }
28
 
                        if (!WindowsHighPrecisionTimer) {
29
 
                                SdlTime = 0.001 * (double)Sdl.SDL_GetTicks();
30
 
                        }
 
12
                        SdlTime = 0.001 * (double)Sdl.SDL_GetTicks();
31
13
                }
32
14
 
33
15
                // get elapsed time
34
16
                internal static double GetElapsedTime() {
35
 
                        if (WindowsHighPrecisionTimer) {
36
 
                                long a; QueryPerformanceCounter(out a);
37
 
                                long d = a - WindowsHighPrecisionTimerCounter;
38
 
                                WindowsHighPrecisionTimerCounter = a;
39
 
                                return (double)d * WindowsHighPrecisionTimerInverseFrequency;
40
 
                        } else {
41
 
                                double a = 0.001 * (double)Sdl.SDL_GetTicks();
42
 
                                double d = a - SdlTime;
43
 
                                SdlTime = a;
44
 
                                return d;
45
 
                        }
 
17
                        double a = 0.001 * (double)Sdl.SDL_GetTicks();
 
18
                        double d = a - SdlTime;
 
19
                        SdlTime = a;
 
20
                        return d;
46
21
                }
47
22
 
48
23
        }