aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code/Classes/UTime.pas
diff options
context:
space:
mode:
authorjaybinks <jaybinks@b956fd51-792f-4845-bead-9b4dfca2ff2c>2007-10-11 08:11:47 +0000
committerjaybinks <jaybinks@b956fd51-792f-4845-bead-9b4dfca2ff2c>2007-10-11 08:11:47 +0000
commitd123263213fba448d5695df35660f7de4cbed433 (patch)
treeef0bb01727be4b38a44a84ef6bef8224ee38d9b2 /Game/Code/Classes/UTime.pas
parent48676faa6c0da1eb77999512322896840ea13cb1 (diff)
downloadusdx-d123263213fba448d5695df35660f7de4cbed433.tar.gz
usdx-d123263213fba448d5695df35660f7de4cbed433.tar.xz
usdx-d123263213fba448d5695df35660f7de4cbed433.zip
modified UTime to utilise SDL timer...
this allows for reliable cross platform timers. Tested working on linux. Modified UVideo and screens to get Video playback working on linux currently only video stream... no audio.. but I Will be working towards this, for all audio playback ( at least for linux ) git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@501 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to '')
-rw-r--r--Game/Code/Classes/UTime.pas142
1 files changed, 79 insertions, 63 deletions
diff --git a/Game/Code/Classes/UTime.pas b/Game/Code/Classes/UTime.pas
index c197a70f..edd65b7e 100644
--- a/Game/Code/Classes/UTime.pas
+++ b/Game/Code/Classes/UTime.pas
@@ -6,6 +6,9 @@ interface
{$MODE Delphi}
{$ENDIF}
+{$DEFINE SDLTimer}
+{$UNDEF DebugDisplay}
+
type
TTime = class
constructor Create;
@@ -15,7 +18,6 @@ type
procedure CountSkipTimeSet;
procedure CountSkipTime;
procedure CountMidTime;
-procedure TimeSleep(ms: real);
var
USTime: TTime;
@@ -36,21 +38,22 @@ uses
libc,
time,
{$ENDIF}
+ sysutils,
+ {$IFDEF SDLTimer}
+ sdl,
+ {$ENDIF}
ucommon;
-
-
-// -- ON Linux it MAY Be better to use ... clock_gettime() instead of CurrentSec100OfDay
-// who knows how fast or slow that function is !
-// but this gets a compile for now .. :)
+
+const
+ cSDLCorrectionRatio = 1000;
(*
-msec( )
-{
- struct timeval tv;
- gettimeofday( &tv, NULL );
- return (int64_t)tv.tv_sec * (int64_t)1000000 + (int64_t)tv.tv_usec;
-}
+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
*)
@@ -59,86 +62,99 @@ begin
CountSkipTimeSet;
end;
+
procedure CountSkipTimeSet;
begin
- {$IFDEF win32}
- QueryPerformanceFrequency(TimeFreq);
- QueryPerformanceCounter(TimeNew);
+ {$IFDEF SDLTimer}
+ TimeNew := SDL_GetTicks(); // / cSDLCorrectionRatio
+ TimeFreq := 0;
{$ELSE}
- TimeNew := CurrentSec100OfDay(); // TODO - JB_Linux will prob need looking at
- TimeFreq := 0;
+ {$IFDEF win32}
+ QueryPerformanceFrequency(TimeFreq);
+ QueryPerformanceCounter(TimeNew);
+ {$ELSE}
+ TimeNew := CurrentSec100OfDay(); // TODO - JB_Linux will prob need looking at
+ TimeFreq := 0;
+ {$ENDIF}
+ {$ENDIF}
+
+ {$IFDEF DebugDisplay}
+ Writeln( 'CountSkipTimeSet : ' + inttostr(trunc(TimeNew)) );
{$ENDIF}
end;
+
procedure CountSkipTime;
begin
TimeOld := TimeNew;
- {$IFDEF win32}
- QueryPerformanceCounter(TimeNew);
+ {$IFDEF SDLTimer}
+ TimeNew := SDL_GetTicks();
+ TimeSkip := (TimeNew-TimeOld) / cSDLCorrectionRatio;
{$ELSE}
- TimeNew := CurrentSec100OfDay(); // TODO - JB_Linux will prob need looking at
+ {$IFDEF win32}
+ QueryPerformanceCounter(TimeNew);
+
+ if ( TimeNew-TimeOld > 0 ) AND
+ ( TimeFreq > 0 ) THEN
+ begin
+ TimeSkip := (TimeNew-TimeOld)/TimeFreq;
+ end;
+
+ {$ELSE}
+ TimeNew := CurrentSec100OfDay(); // TODO - JB_Linux will prob need looking at
+ TimeSkip := (TimeNew-TimeOld);
+ {$ENDIF}
{$ENDIF}
-
- if ( TimeNew-TimeOld > 0 ) AND
- ( TimeFreq > 0 ) THEN
- begin
- TimeSkip := (TimeNew-TimeOld)/TimeFreq;
- end;
-end;
-procedure CountMidTime;
-begin
- {$IFDEF win32}
- QueryPerformanceCounter(TimeMidTemp);
- TimeMid := (TimeMidTemp-TimeNew)/TimeFreq;
- {$ELSE}
- TimeMidTemp := CurrentSec100OfDay();
- TimeMid := (TimeMidTemp-TimeNew); // TODO - JB_Linux will prob need looking at
+ {$IFDEF DebugDisplay}
+ Writeln( 'TimeNew : ' + inttostr(trunc(TimeNew)) );
+ Writeln( 'CountSkipTime : ' + inttostr(trunc(TimeSkip)) );
{$ENDIF}
end;
-procedure TimeSleep(ms: real);
-var
- TimeStart: int64;
- TimeHalf: int64;
- Time: real;
- Stop: boolean;
+
+procedure CountMidTime;
begin
- {$IFDEF win32}
- QueryPerformanceCounter(TimeStart);
+ {$IFDEF SDLTimer}
+ TimeMidTemp := SDL_GetTicks();
+ TimeMid := (TimeMidTemp - TimeNew) / cSDLCorrectionRatio;
{$ELSE}
- TimeStart := CurrentSec100OfDay(); // TODO - JB_Linux will prob need looking at
- {$ENDIF}
-
-
- Stop := false;
- while (not Stop) do
- begin
{$IFDEF win32}
- QueryPerformanceCounter(TimeHalf);
- Time := 1000 * (TimeHalf-TimeStart)/TimeFreq;
+ QueryPerformanceCounter(TimeMidTemp);
+ TimeMid := (TimeMidTemp-TimeNew)/TimeFreq;
{$ELSE}
- TimeHalf := CurrentSec100OfDay();
- Time := 1000 * (TimeHalf-TimeStart); // TODO - JB_Linux will prob need looking at
+ TimeMidTemp := CurrentSec100OfDay();
+ TimeMid := (TimeMidTemp-TimeNew); // TODO - JB_Linux will prob need looking at
{$ENDIF}
+ {$ENDIF}
- if Time > ms then
- Stop := true;
- end;
-
+ {$IFDEF DebugDisplay}
+ Writeln( 'TimeNew : ' + inttostr(trunc(TimeNew)) );
+ Writeln( 'CountMidTime : ' + inttostr(trunc(TimeMid)) );
+ {$ENDIF}
end;
+
function TTime.GetTime: real;
var
TimeTemp: int64;
begin
- {$IFDEF win32}
- QueryPerformanceCounter(TimeTemp);
- Result := TimeTemp / TimeFreq;
+ {$IFDEF SDLTimer}
+ TimeTemp := SDL_GetTicks();
+ Result := TimeTemp / cSDLCorrectionRatio; // TODO - JB_Linux will prob need looking at
{$ELSE}
- TimeTemp := CurrentSec100OfDay();
- Result := TimeTemp; // TODO - JB_Linux will prob need looking at
+ {$IFDEF win32}
+ QueryPerformanceCounter(TimeTemp);
+ Result := TimeTemp / TimeFreq;
+ {$ELSE}
+ TimeTemp := CurrentSec100OfDay();
+ Result := TimeTemp; // TODO - JB_Linux will prob need looking at
+ {$ENDIF}
+ {$ENDIF}
+
+ {$IFDEF DebugDisplay}
+ Writeln( 'GetTime : ' + inttostr(trunc(Result)) );
{$ENDIF}
end;