Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/test/emscripten_request_animation_frame.c
7085 views
1
#include <emscripten/html5.h>
2
#include <assert.h>
3
4
int func1Executed = 0;
5
int func2Executed = 0;
6
7
bool func1(double time, void *userData);
8
9
bool func2(double time, void *userData) {
10
assert((long)userData == 2);
11
assert(time > 0);
12
++func2Executed;
13
14
if (func2Executed == 1) {
15
// Test canceling an animation frame: register rAF() but then cancel it immediately
16
long id = emscripten_request_animation_frame(func1, (void*)2);
17
emscripten_cancel_animation_frame(id);
18
19
emscripten_request_animation_frame(func2, (void*)2);
20
}
21
if (func2Executed == 2) {
22
assert(func1Executed == 1);
23
}
24
return 0;
25
}
26
27
bool func1(double time, void *userData) {
28
assert((long)userData == 1);
29
assert(time > 0);
30
++func1Executed;
31
32
assert(func1Executed == 1);
33
34
emscripten_request_animation_frame(func2, (void*)2);
35
36
return 0;
37
}
38
39
int main() {
40
emscripten_request_animation_frame(func1, (void*)1);
41
}
42
43