-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
76 lines (61 loc) · 2.2 KB
/
main.cpp
File metadata and controls
76 lines (61 loc) · 2.2 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
#include <cstdio>
#include <SDL2/SDL.h>
#include <webgpu/webgpu.h>
#include <sdl2webgpu/sdl2webgpu.h>
#include "random"
#include <iostream>
#include "src/app/app.h"
auto app = new App();
void Draw() {
SDL_Event event;
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
exit(1);
}
}
app->RenderPhase();
}
#ifdef __cplusplus
extern "C" {
#endif
int init(const int width, const int height, bool debug) {
app->Init(width,height);
#ifdef EMSCRIPTEN
emscripten_set_mousedown_callback("#canvas", nullptr, 0,
[](int k,const EmscriptenMouseEvent *e,void * u) -> EM_BOOL{
return app->mouseControlDown(k,e,u);
});
emscripten_set_mouseup_callback("#canvas", nullptr, 0, [](int k,const EmscriptenMouseEvent *e,void * u) -> EM_BOOL{
return app->mouseControlUp(k,e,u);
});
emscripten_set_mousemove_callback("#canvas", nullptr, 0,
[](int k,const EmscriptenMouseEvent *e,void * u) -> EM_BOOL{
return app->mouseControlMove(k,e,u);
});
// emscripten_set_wheel_callback("#canvas", nullptr, 0, [](int k,const EmscriptenWheelEvent *e,void * u) -> EM_BOOL{
// return app->mouseControlWheel(k,e,u);
// });
// emscripten_set_keydown_callback("#canvas", nullptr, 0,
// [](int k,const EmscriptenKeyboardEvent *e,void * u) -> EM_BOOL{
// return app->keyboarControl(k,e,u);
// });
emscripten_set_main_loop(Draw, 0, true);
#else
while (true) {
Draw();
}
#endif
return true;
}
#ifdef __cplusplus
}
#endif
int main(int argc, char **argv) {
for (int i = 0; i < argc; i++) {
std::cout<< argv[i] << std::endl;
}
// Seed the random number generator with the current time
std::srand(static_cast<unsigned>(std::time(nullptr)));
init(640, 480, true);
return 1;
}