Mercurial > projects > hoofbaby
comparison deps/Platinum/ThirdParty/Neptune/Source/System/Win32/NptWin32System.cpp @ 0:3425707ddbf6
Initial import (hopefully this mercurial stuff works...)
author | fraserofthenight |
---|---|
date | Mon, 06 Jul 2009 08:06:28 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3425707ddbf6 |
---|---|
1 /***************************************************************** | |
2 | | |
3 | Neptune - System :: Win32 Implementation | |
4 | | |
5 | (c) 2001-2006 Gilles Boccon-Gibod | |
6 | Author: Gilles Boccon-Gibod (bok@bok.net) | |
7 | | |
8 ****************************************************************/ | |
9 | |
10 /*---------------------------------------------------------------------- | |
11 | includes | |
12 +---------------------------------------------------------------------*/ | |
13 #if defined(_XBOX) | |
14 #include <xtl.h> | |
15 #else | |
16 #include <windows.h> | |
17 #endif | |
18 | |
19 #if !defined(_WIN32_WCE) | |
20 #include <sys/timeb.h> | |
21 #endif | |
22 | |
23 #include "NptConfig.h" | |
24 #include "NptTypes.h" | |
25 #include "NptSystem.h" | |
26 #include "NptResults.h" | |
27 #include "NptDebug.h" | |
28 | |
29 /*---------------------------------------------------------------------- | |
30 | NPT_System::GetProcessId | |
31 +---------------------------------------------------------------------*/ | |
32 NPT_Result | |
33 NPT_System::GetProcessId(NPT_UInt32& id) | |
34 { | |
35 //id = getpid(); | |
36 id = 0; | |
37 return NPT_SUCCESS; | |
38 } | |
39 | |
40 #if defined(_WIN32_WCE) | |
41 /*---------------------------------------------------------------------- | |
42 | NPT_System::GetCurrentTimeStamp | |
43 +---------------------------------------------------------------------*/ | |
44 NPT_Result | |
45 NPT_System::GetCurrentTimeStamp(NPT_TimeStamp& now) | |
46 { | |
47 SYSTEMTIME stime; | |
48 FILETIME ftime; | |
49 __int64 time64; | |
50 GetSystemTime(&stime); | |
51 SystemTimeToFileTime(&stime, &ftime); | |
52 | |
53 /* convert to 64-bits 100-nanoseconds value */ | |
54 time64 = (((unsigned __int64)ftime.dwHighDateTime)<<32) | ((unsigned __int64)ftime.dwLowDateTime); | |
55 time64 -= 116444736000000000; /* convert from the Windows epoch (Jan. 1, 1601) to the | |
56 * Unix epoch (Jan. 1, 1970) */ | |
57 | |
58 now.m_Seconds = (NPT_Int32)(time64/10000000); | |
59 now.m_NanoSeconds = 100*(NPT_Int32)(time64-((unsigned __int64)now.m_Seconds*10000000)); | |
60 | |
61 return NPT_SUCCESS; | |
62 } | |
63 #else | |
64 /*---------------------------------------------------------------------- | |
65 | NPT_System::GetCurrentTimeStamp | |
66 +---------------------------------------------------------------------*/ | |
67 NPT_Result | |
68 NPT_System::GetCurrentTimeStamp(NPT_TimeStamp& now) | |
69 { | |
70 struct _timeb time_stamp; | |
71 | |
72 #if defined(_MSC_VER) && (_MSC_VER >= 1400) | |
73 _ftime_s(&time_stamp); | |
74 #else | |
75 _ftime(&time_stamp); | |
76 #endif | |
77 now.m_Seconds = (long)time_stamp.time; | |
78 now.m_NanoSeconds = (long)time_stamp.millitm*1000000; | |
79 | |
80 return NPT_SUCCESS; | |
81 } | |
82 #endif | |
83 | |
84 /*---------------------------------------------------------------------- | |
85 | NPT_System::Sleep | |
86 +---------------------------------------------------------------------*/ | |
87 NPT_Result | |
88 NPT_System::Sleep(const NPT_TimeInterval& duration) | |
89 { | |
90 DWORD milliseconds = 1000*duration.m_Seconds + duration.m_NanoSeconds/1000000; | |
91 ::Sleep(milliseconds); | |
92 | |
93 return NPT_SUCCESS; | |
94 } | |
95 | |
96 /*---------------------------------------------------------------------- | |
97 | NPT_System::SleepUntil | |
98 +---------------------------------------------------------------------*/ | |
99 NPT_Result | |
100 NPT_System::SleepUntil(const NPT_TimeStamp& when) | |
101 { | |
102 NPT_TimeStamp now; | |
103 GetCurrentTimeStamp(now); | |
104 if (when > now) { | |
105 NPT_TimeInterval duration = when-now; | |
106 return Sleep(duration); | |
107 } else { | |
108 return NPT_SUCCESS; | |
109 } | |
110 } | |
111 | |
112 /*---------------------------------------------------------------------- | |
113 | NPT_System::SetRandomSeed | |
114 +---------------------------------------------------------------------*/ | |
115 NPT_Result | |
116 NPT_System::SetRandomSeed(unsigned int seed) | |
117 { | |
118 srand(seed); | |
119 return NPT_SUCCESS; | |
120 } | |
121 | |
122 /*---------------------------------------------------------------------- | |
123 | NPT_System::NPT_System | |
124 +---------------------------------------------------------------------*/ | |
125 NPT_UInt32 | |
126 NPT_System::GetRandomInteger() | |
127 { | |
128 static bool seeded = false; | |
129 if (seeded == false) { | |
130 NPT_TimeStamp now; | |
131 GetCurrentTimeStamp(now); | |
132 srand(now.m_NanoSeconds); | |
133 seeded = true; | |
134 } | |
135 | |
136 return rand(); | |
137 } | |
138 |