]> icculus.org git repositories - btb/d2x.git/blob - arch/win32/timer.c
fixed stupid win32 network bug
[btb/d2x.git] / arch / win32 / timer.c
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
11 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14 // File nearly completely rewritten by dph-man
15
16 #include <windows.h>
17 #include <mmsystem.h> // DPH: We use timeGetTime from here...
18
19 #include "types.h"
20 #include "maths.h"
21 #include "timer.h"
22
23 static int Installed = 0;
24
25 static unsigned long old_tv;
26
27 fix timer_get_fixed_seconds()
28 {
29         fix x;
30
31         //Ye good olde unix:
32         //Ye bad olde Windows DPH:-)
33 /* DPH: Using timeGetTime will fail approximately 47 days after Windows was
34    started as the timer wraps around to 0. Ever had Windows not crash for 47
35    consecutive days? Thought not. */
36
37         unsigned long tv_now=timeGetTime()-old_tv;
38         x=i2f(tv_now/1000) | fixdiv(i2f(tv_now % 1000),i2f(1000));
39         return x;
40 }
41
42 void delay(int d_time)
43 {
44         fix t, total;
45         
46         total = (F1_0 * d_time) / 1000;
47         t = timer_get_fixed_seconds();
48         while (timer_get_fixed_seconds() - t < total) ;
49 }
50
51 void timer_close()
52 {
53  Installed = 0;
54 }
55
56 void timer_init()
57 {
58
59         if (Installed)
60                 return;
61         Installed = 1;          
62
63 /* DPH: Using timeGetTime will fail approximately 47 days after Windows was
64    started as the timer wraps around to 0. Ever had Windows not crash for 47
65    consecutive days? Thought not. */
66  old_tv=timeGetTime();
67
68 }
69
70 // NOTE: This C file has been "neutered" by dph-man. If someone wants to work
71 // on this, feel free. I don't use joystick :-)