-
Notifications
You must be signed in to change notification settings - Fork 9
/
Timing.simba
68 lines (59 loc) · 998 Bytes
/
Timing.simba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
type
Timer = record
Tick: Int64;
end;
{*
Start
~~~~~
Starts the timer.
Example:
Timer.Start;
*}
Procedure Timer.Start;
begin
tick := GetTickCount();
end;
{*
ElapsedTime
~~~~~~~~~~~
Returns the time elapsed or the total time on the timer.
Example:
if Timer.ElapsedTime < 100 then
...
*}
Function Timer.ElapsedTime: Int64;
begin
Result := GetTickCount() - self.Tick;
end;
{*
Reset
~~~~~
Resets the timer.
Example:
Timer.Reset
*}
Procedure Timer.Reset();
begin
self.Tick := 0;
end;
{*
R_WaitFunction
~~~~~~~~~~~~~~
Waits until a function is completed. If not completed within the specified time,
it will return false.
Example:
R_WaitFunction(1200, 50, KillNPC());
*}
Function R_WaitFunction(timeout: UInt32; timePerLoop: Int32 = 50; func: Function: Boolean): Boolean;
var
timer: Timer;
begin
timer.Start;
while(not func) do
begin
if timer.ElapsedTime >= timeout then
Exit(False);
Wait(timePerLoop + Random(50));
end;
Result := True;
end;