Repository navigation
Expand file tree
/
Copy pathsim.ceu
More file actions
241 lines (221 loc) · 7.04 KB
/
Copy pathsim.ceu
File metadata and controls
241 lines (221 loc) · 7.04 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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
// - bug play no inicio
// - async vs async_ (testar async no jogo!)
// - tests para pause/async
// - outros jogos
// BUG tempo
// BUG pause/if
input void SDL_QUIT, SDL_QUIT_;
input int SDL_DT, SDL_DT_;
input _SDL_KeyboardEvent* SDL_KEYDOWN, SDL_KEYDOWN_;
input _SDL_KeyboardEvent* SDL_KEYUP, SDL_KEYUP_;
input _SDL_MouseButtonEvent* SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONDOWN_;
input _SDL_MouseMotionEvent* SDL_MOUSEMOTION, SDL_MOUSEMOTION_;
#include "c.ceu"
#include "sdl.ceu"
native do
##include <time.h>
unsigned int* RAND_SEED;
#define rand() rand_r(RAND_SEED)
end
class App with
event int ok;
do
var uint seed = _time(null);
_RAND_SEED := &seed;
_srand(seed);
#define srand(x)
#define _SDL_RenderPresent(x) nothing
var int ret = do
#define _STRINGIFY(X) #X
#define STRINGIFY(X) _STRINGIFY(X)
#include STRINGIFY(CEUFILE)
end;
emit this.ok => ret;
#undef _SDL_RenderPresent
end
var App app;
_printf("APP %d\n", sizeof(_CEU_App));
#define TM_INPUT_DT SDL_DT
#define TM_INPUT_REDRAW SDL_REDRAW
//#define TM_DELAY(v) _SDL_Delay(v)
#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 2000 /* 10s = 30*10 = at most 300 frames to traverse */
/* 0 means "do not take snaps" */
#define TM_SNAP_N 6*60 /* 10s*6*60=1h (360*56K-rocks = 1.8Mb) */
#include "timemachine.ceu"
#include "ui-timemachine.ceu"
class IOTimeMachine with
interface IIOTimeMachine;
do
par do
loop do
// starts off
watching this.go_on do
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
with
var _SDL_MouseButtonEvent* mse;
every mse in SDL_MOUSEBUTTONDOWN do
_queue_put(_CEU_IN_SDL_MOUSEBUTTONDOWN, _CEU_EVTP(null),
sizeof(_SDL_MouseButtonEvent), (byte*)mse);
end
with
var _SDL_MouseMotionEvent* mse;
every mse in SDL_MOUSEMOTION do
_queue_put(_CEU_IN_SDL_MOUSEMOTION, _CEU_EVTP(null),
sizeof(_SDL_MouseMotionEvent), (byte*)mse);
end
end
end
await this.go_off;
end
with
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/if qu:evt == _CEU_IN_SDL_MOUSEBUTTONDOWN then
async(qu) do
emit SDL_MOUSEBUTTONDOWN => qu:param.ptr;
end
else/if qu:evt == _CEU_IN_SDL_MOUSEMOTION then
async(qu) do
emit SDL_MOUSEMOTION => qu:param.ptr;
end
else
_assert(0);
end
end
end
end
var IOTimeMachine io;
/* The "Time Machine" must be declared after "The Application".
* The "tm" must record the events *after* the "app" reacts to them.
*/
var TimeMachine tm with
this.app = app;
this.io = io;
end;
var UITimeMachine uitm with
this.tm = tm;
end;
event bool in_tm?;
var bool blur? = false;
par/or do
await SDL_QUIT_;
//_dump();
with
loop do
var _SDL_KeyboardEvent* key = await SDL_KEYDOWN_;
var int sym = key:keysym.sym;
if sym == _SDLK_ESCAPE then
emit in_tm? => true;
emit tm.go_on;
emit uitm.go_on;
key = await SDL_KEYDOWN_ until key:keysym.sym == _SDLK_ESCAPE;
emit uitm.go_off;
emit tm.go_off;
emit in_tm? => false;
else/if sym==_SDLK_LALT then
blur? = true;
emit in_tm? => true;
emit tm.go_on;
par/or do
key = await SDL_KEYUP_
until key:keysym.sym == _SDLK_LALT;
with
loop do
key = await SDL_KEYDOWN_;
var int sym2 = key:keysym.sym;
if sym2 == _SDLK_LEFT then
emit tm.go_backward => 2;
else/if sym2 == _SDLK_RIGHT then
emit tm.go_forward => 2;
end
key = await SDL_KEYUP_ until key:keysym.sym == sym2;
emit tm.go_pause;
end
end
TM_AWAIT_SEEK(tm);
emit tm.go_off;
emit in_tm? => false;
blur? = false;
end
end
with
var int ren_w, ren_h;
_SDL_GetRendererOutputSize(_REN, &ren_w, &ren_h);
every SDL_REDRAW do
emit uitm.go_redraw;
if blur? then
_boxRGBA(_REN, 0, 0, ren_w, ren_h, 0xAA,0x88,0x88,0x88);
end
_SDL_RenderPresent(_REN);
end
#if 0
with
loop do
var _SDL_KeyboardEvent* key = await SDL_KEYDOWN_
until key:keysym.sym == _SDLK_LCTRL;
var bool ok? =
par do
key = await SDL_KEYUP_ until key:keysym.sym == _SDLK_LCTRL;
escape false;
with
await 1s;
escape true;
end;
if not ok? then
continue;
end
_CEU_TIMEMACHINE_ON = _CEU_TIMEMACHINE_ON + 1;
finalize with
_CEU_TIMEMACHINE_ON = _CEU_TIMEMACHINE_ON - 1;
end
pause/if in_tm? do
par/or do
loop do
key = await SDL_KEYDOWN_
until key:keysym.sym == _SDLK_LCTRL;
par/or do
key = await SDL_KEYUP_
until key:keysym.sym == _SDLK_LCTRL;
with
await 1s;
break;
end
end
with
#include "input.ceu"
end
end
end
#endif
end
escape 0;