aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code/Classes/UTime.pas
diff options
context:
space:
mode:
authorwhiteshark0 <whiteshark0@b956fd51-792f-4845-bead-9b4dfca2ff2c>2007-03-21 19:19:04 +0000
committerwhiteshark0 <whiteshark0@b956fd51-792f-4845-bead-9b4dfca2ff2c>2007-03-21 19:19:04 +0000
commit5ed6620bad808381fce94f2cd67ee911b4d45bff (patch)
treebfe0fe2041260620f88f8161922ee90c034d7d73 /Game/Code/Classes/UTime.pas
downloadusdx-5ed6620bad808381fce94f2cd67ee911b4d45bff.tar.gz
usdx-5ed6620bad808381fce94f2cd67ee911b4d45bff.tar.xz
usdx-5ed6620bad808381fce94f2cd67ee911b4d45bff.zip
git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to '')
-rw-r--r--Game/Code/Classes/UTime.pas81
1 files changed, 81 insertions, 0 deletions
diff --git a/Game/Code/Classes/UTime.pas b/Game/Code/Classes/UTime.pas
new file mode 100644
index 00000000..29e972ae
--- /dev/null
+++ b/Game/Code/Classes/UTime.pas
@@ -0,0 +1,81 @@
+unit UTime;
+
+interface
+
+type
+ TTime = class
+ constructor Create;
+ function GetTime: real;
+ end;
+
+procedure CountSkipTimeSet;
+procedure CountSkipTime;
+procedure CountMidTime;
+procedure TimeSleep(ms: real);
+
+var
+ USTime: TTime;
+
+ TimeFreq: int64;
+ TimeNew: int64;
+ TimeOld: int64;
+ TimeSkip: real;
+ TimeMid: real;
+ TimeMidTemp: int64;
+
+implementation
+
+uses Windows;
+
+constructor TTime.Create;
+begin
+ CountSkipTimeSet;
+end;
+
+procedure CountSkipTimeSet;
+begin
+ QueryPerformanceFrequency(TimeFreq);
+ QueryPerformanceCounter(TimeNew);
+end;
+
+procedure CountSkipTime;
+begin
+ TimeOld := TimeNew;
+ QueryPerformanceCounter(TimeNew);
+ TimeSkip := (TimeNew-TimeOld)/TimeFreq;
+end;
+
+procedure CountMidTime;
+begin
+ QueryPerformanceCounter(TimeMidTemp);
+ TimeMid := (TimeMidTemp-TimeNew)/TimeFreq;
+end;
+
+procedure TimeSleep(ms: real);
+var
+ TimeStart: int64;
+ TimeHalf: int64;
+ Time: real;
+ Stop: boolean;
+begin
+ QueryPerformanceCounter(TimeStart);
+
+ Stop := false;
+ while (not Stop) do begin
+ QueryPerformanceCounter(TimeHalf);
+ Time := 1000 * (TimeHalf-TimeStart)/TimeFreq;
+ if Time > ms then Stop := true;
+ end;
+
+end;
+
+function TTime.GetTime: real;
+var
+ TimeTemp: int64;
+begin
+ QueryPerformanceCounter(TimeTemp);
+ Result := TimeTemp/TimeFreq;
+end;
+
+
+end.