-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.flow
More file actions
78 lines (67 loc) · 1.87 KB
/
Copy pathtimer.flow
File metadata and controls
78 lines (67 loc) · 1.87 KB
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
69
70
71
72
73
74
75
76
77
78
# Timer functions, ported from i_timer.c to Flow.
#
# Uses Flow runtime clock / sleep (flow_rt_time_ms / flow_rt_usleep) so
# the generated C TU does not need POSIX headers.
extern { function flow_rt_time_ms() -> u32 }
extern { function flow_rt_usleep(usec: i32) -> void }
# TICRATE from i_timer.h.
const TICRATE: i32 = 35
let mut basetime: u32 = 0
@flow_api
function DG_GetTicksMs() -> u32 {
return flow_rt_time_ms()
}
@flow_api
function I_GetTicks() -> i32 {
return flow_rt_time_ms() as i32
}
# Returns time in 1/35th second tics. The multiply and divide stay in
# uint32, wrapping exactly as the C version does.
@flow_api
function I_GetTime() -> i32 {
let mut ticks: u32 = flow_rt_time_ms()
if basetime == 0 {
basetime = ticks
}
ticks = ticks - basetime
return ((ticks * (TICRATE as u32)) / (1000 as u32)) as i32
}
# Same as I_GetTime, but in milliseconds.
@flow_api
function I_GetTimeMS() -> i32 {
let ticks: u32 = flow_rt_time_ms()
if basetime == 0 {
basetime = ticks
}
return (ticks - basetime) as i32
}
@flow_api
function DG_SleepMs(ms: u32) -> void {
# Safe once D_DoomMain has returned: main's loop is the only ASYNCIFY
# caller depth we need. usleep → emscripten_sleep under wasm.
if ms == 0 {
return
}
flow_rt_usleep((ms * (1000 as u32)) as i32)
}
@flow_api
function I_Sleep(ms: i32) -> void {
# Prefer real sleep (ASYNCIFY) so the browser clock runs. Do not call
# this from inside D_DoomMain — D_DoomLoop returns before the first tick.
if ms <= 0 {
return
}
flow_rt_usleep(ms * 1000)
}
# No-op in doomgeneric (the SDL sleep is commented out there too).
@flow_api
function I_WaitVBL(count: i32) -> void {
if count == 0 {
return
}
}
# No-op in doomgeneric; there is no SDL timer subsystem to initialize.
@flow_api
function I_InitTimer() -> void {
return
}