diff options
author | mogguh <mogguh@b956fd51-792f-4845-bead-9b4dfca2ff2c> | 2008-02-13 19:58:44 +0000 |
---|---|---|
committer | mogguh <mogguh@b956fd51-792f-4845-bead-9b4dfca2ff2c> | 2008-02-13 19:58:44 +0000 |
commit | 949fea202f6c963ad6c8a40040e1e9e6f909161b (patch) | |
tree | 9f6f683d203d55e41e5b7483b4038103d471ce76 /Game/Code/Classes/UTime.pas | |
parent | 1a7da68ae6e1368dae25821b15318bd1d2d9f88e (diff) | |
parent | efe5b06fd5715f550334692d28c2218896b62ce1 (diff) | |
download | usdx-949fea202f6c963ad6c8a40040e1e9e6f909161b.tar.gz usdx-949fea202f6c963ad6c8a40040e1e9e6f909161b.tar.xz usdx-949fea202f6c963ad6c8a40040e1e9e6f909161b.zip |
First multi platform version, works on Linux and Windows
git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/branches/1.1@855 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'Game/Code/Classes/UTime.pas')
-rw-r--r-- | Game/Code/Classes/UTime.pas | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/Game/Code/Classes/UTime.pas b/Game/Code/Classes/UTime.pas new file mode 100644 index 00000000..3b7749a2 --- /dev/null +++ b/Game/Code/Classes/UTime.pas @@ -0,0 +1,102 @@ +unit UTime; + +interface + +{$IFDEF FPC} + {$MODE Delphi} +{$ENDIF} +{$I switches.inc} + +{$UNDEF DebugDisplay} + +type + TTime = class + constructor Create; + function GetTime: real; + end; + +procedure CountSkipTimeSet; +procedure CountSkipTime; +procedure CountMidTime; + +var + USTime: TTime; + + TimeNew: int64; + TimeOld: int64; + TimeSkip: real; + TimeMid: real; + TimeMidTemp: int64; + +implementation + +uses +// sysutils, + sdl, + ucommon; + +const + cSDLCorrectionRatio = 1000; + +(* +BEST Option now ( after discussion with whiteshark ) seems to be to use SDL +timer functions... + +SDL_delay +SDL_GetTicks +http://www.gamedev.net/community/forums/topic.asp?topic_id=466145&whichpage=1%EE%8D%B7 +*) + + +constructor TTime.Create; +begin + CountSkipTimeSet; +end; + + +procedure CountSkipTimeSet; +begin + TimeNew := SDL_GetTicks(); + + {$IFDEF DebugDisplay} + Writeln( 'CountSkipTimeSet : ' + inttostr(trunc(TimeNew)) ); + {$ENDIF} +end; + + +procedure CountSkipTime; +begin + TimeOld := TimeNew; + TimeNew := SDL_GetTicks(); + TimeSkip := (TimeNew-TimeOld) / cSDLCorrectionRatio; + + {$IFDEF DebugDisplay} + Writeln( 'TimeNew : ' + inttostr(trunc(TimeNew)) ); + Writeln( 'CountSkipTime : ' + inttostr(trunc(TimeSkip)) ); + {$ENDIF} +end; + + +procedure CountMidTime; +begin + TimeMidTemp := SDL_GetTicks(); + TimeMid := (TimeMidTemp - TimeNew) / cSDLCorrectionRatio; + + {$IFDEF DebugDisplay} + Writeln( 'TimeNew : ' + inttostr(trunc(TimeNew)) ); + Writeln( 'CountMidTime : ' + inttostr(trunc(TimeMid)) ); + {$ENDIF} +end; + + +function TTime.GetTime: real; +begin + Result := SDL_GetTicks() / cSDLCorrectionRatio; + + {$IFDEF DebugDisplay} + Writeln( 'GetTime : ' + inttostr(trunc(Result)) ); + {$ENDIF} +end; + + +end. |