tw2274.pp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. { Source provided for Free Pascal Bug Report 2274 }
  2. { Submitted by "Sergey Kosarevsky" on 2002-12-21 }
  3. { e-mail: [email protected] }
  4. Unit tw2274;
  5. {$STATIC ON}
  6. Interface
  7. Type Lfloat=Single;
  8. Type pTimer=^tTimer;
  9. tTimer=Object
  10. Private
  11. RecepCyclesPerSecond:Lfloat;Static; // 1/CyclesPerSecond
  12. OldCycles:Int64;
  13. NewCycles:Int64;
  14. WorldUpTime:Lfloat;
  15. Public
  16. Constructor Init;
  17. // tTimer
  18. Function GetDeltaSeconds:Lfloat;
  19. Function GetWorldTime:Lfloat; // in seconds
  20. Function GetCycles:Int64;Static;
  21. Function GetSeconds:Lfloat;
  22. End;
  23. Implementation
  24. Constructor tTimer.Init;
  25. Begin
  26. RecepCyclesPerSecond:=0;
  27. OldCycles:=GetCycles;
  28. End;
  29. Function tTimer.GetWorldTime:Lfloat;
  30. Begin
  31. Exit(GetSeconds-WorldUpTime);
  32. End;
  33. Function tTimer.GetCycles:Int64;
  34. begin
  35. GetCycles:=0;
  36. End;
  37. Function tTimer.GetDeltaSeconds:Lfloat;
  38. Begin
  39. NewCycles:=GetCycles;
  40. GetDeltaSeconds:=(NewCycles-OldCycles)*RecepCyclesPerSecond;
  41. OldCycles:=NewCycles;
  42. End;
  43. Function tTimer.GetSeconds:Lfloat;
  44. Begin
  45. Exit(GetCycles*RecepCyclesPerSecond);
  46. End;
  47. Begin
  48. End.