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
|
#include "common.h"
#include <signal.h>
#include <time.h>
char *va(const char *fmt, ...)
{
va_list vl;
static char buffer[4096];
va_start(vl, fmt);
vsnprintf(buffer, sizeof(buffer), fmt, vl);
va_end(vl);
return buffer;
}
int64_t get_time(void)
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return ts.tv_sec * 1000000000 + ts.tv_nsec;
}
void itc_test(void);
int main(void)
{
int rv = 0;
r_window *first_window;
phy_sim sim;
SDL_Thread *sim_thread;
if (r_init()) {
con_printf("fatal error: renderer initialization failed\n");
rv = 1;
goto quit;
}
if (ui_init()) {
con_printf("fatal error: UI initialization failed\n");
rv = 1;
goto quit;
}
signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL);
first_window = r_window_create();
if (!first_window) {
con_printf("fatal error: couldn't open first window\n");
rv = 1;
goto quit;
}
ui_renderer_window_register(first_window);
if (phy_sim_create(&sim)) {
con_printf("fatal error: phy_sim_create failed\n");
rv = 1;
goto quit;
}
sim_thread = SDL_CreateThread((SDL_ThreadFunction)phy_thread,
"phy_thread", &sim);
if (!sim_thread) {
con_printf("fatal error: SDL_CreateThread failed: %s\n",
SDL_GetError());
rv = 1;
goto quit;
}
while (1) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT)
goto quit;
else
ui_event(&event);
}
ui_draw(&sim);
}
quit:
con_printf("main: exitting, rv=%i\n", rv);
itc_chan_push(&sim.ctl, PHY_CMD_QUIT, NULL);
SDL_WaitThread(sim_thread, NULL);
phy_sim_destroy(&sim);
ui_quit();
r_quit();
SDL_Quit();
return rv;
}
|