forked from ceu-lang/ceu-sdl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sim-tst.ceu
147 lines (127 loc) · 3.26 KB
/
sim-tst.ceu
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
input void SDL_QUIT_;
input int SDL_DT, SDL_DT_;
input void SDL_REDRAW;
input _SDL_KeyboardEvent* SDL_KEYDOWN_;
input _SDL_KeyboardEvent* SDL_KEYUP_;
class App with
var int v = 0;
do
v = 0;
every 1s do
this.v = this.v + 1;
end
end
var App app;
#define TM_INPUT_DT SDL_DT
#define TM_INPUT_REDRAW SDL_REDRAW
#define TM_QUEUE_MAX 60*60*1000 \
* sizeof(tceu_queue) \
/ 30 * 2
/*
// 60min*60sec*1000ms=(1h in ms)
// * minimum size of an event
// 30FPS * 2events/frame
// 1h of events with 2 events/frame
// 3600*1000 = 3600000 =>/30 = 120000 =>2 = 240000 = 240K events
*/
#define TM_SNAP
#define TM_SNAP_MS 200
#define TM_SNAP_N 6*60
#include "timemachine.ceu"
class IOTimeMachine with
interface IIOTimeMachine;
do
par do
loop do
// starts off
watching this.go_on do
await FOREVER;
/*
par do
var _SDL_KeyboardEvent* key;
every key in SDL_KEYDOWN do
_queue_put(_CEU_IN_SDL_KEYDOWN, _CEU_EVTP(null),
sizeof(_SDL_KeyboardEvent), (byte*)key);
end
with
var _SDL_KeyboardEvent* key;
every key in SDL_KEYUP do
_queue_put(_CEU_IN_SDL_KEYUP, _CEU_EVTP(null),
sizeof(_SDL_KeyboardEvent), (byte*)key);
end
end
*/
end
await this.go_off;
end
with
await FOREVER;
/*
var _tceu_queue[] qu; // TODO: ptr across await p/ else/if
every qu in this.go_queue do
if qu:evt == _CEU_IN_SDL_KEYDOWN then
async(qu) do
emit SDL_KEYDOWN => qu:param.ptr;
end
else/if qu:evt == _CEU_IN_SDL_KEYUP then
async(qu) do
emit SDL_KEYUP => qu:param.ptr;
end
else
_assert(0);
end
end
*/
end
end
var IOTimeMachine io;
var TimeMachine tm with
this.app = app;
this.io = io;
end;
_printf("= 0:\n");
await 1s500ms_;
_printf("= 1.5: %d\n", app.v);
_assert(app.v == 1);
await 1s_;
_printf("= 2.5: %d\n", app.v);
_assert(app.v == 2);
await 1s_;
_printf("= 3.5: %d\n", app.v);
_assert(app.v == 3);
emit tm.go_on;
await 1ms_;
_printf("= TM ON\n");
emit tm.go_seek => 0;
TM_AWAIT_SEEK(tm);
_assert(_QUEUE_get == 0);
_printf("= seek: %d\n", app.v);
_assert(app.v == 0);
await 1ms_;
_printf("= 0:\n");
emit tm.go_forward => 2;
_printf("= fwd: %d\n", app.v);
_assert(app.v == 0);
await 1s100ms_;
_printf("= 1: %d\n", app.v);
_assert(app.v == 2);
await 500ms_;
_printf("= 1.5: %d\n", app.v);
_assert(app.v == 3);
emit tm.go_seek => tm.time_total;
TM_AWAIT_SEEK(tm);
_printf("= END %d:\n", app.v);
_assert(app.v == 3);
emit tm.go_backward => 2;
_printf("= bak: %d\n", app.v);
_assert(app.v == 3);
await 1s1ms_;
_printf("= -1: %d\n", app.v);
_assert(app.v == 1);
await 500ms_;
_printf("= -1.5: %d\n", app.v);
_assert(app.v == 0);
await 1s_;
_printf("= -2.5: %d\n", app.v);
_assert(app.v == 0);
escape 0;