void wait_wgets() { if (counter++ == 60) { printf("%d\n", get_count); counter = 0; } if (get_count == 6) { static bool fired = false; if (!fired) { fired = true; emscripten_async_wget_data( "http://localhost:8888/screenshot.png", (void*)135, onLoadedData, onErrorData); emscripten_async_wget_data( "http://localhost:8888/fail_me", (void*)246, onLoadedData, onErrorData); } } else if (get_count == 8) { assert(IMG_Load("/tmp/screen_shot.png")); assert(data_ok == 1 && data_bad == 1); emscripten_cancel_main_loop(); REPORT_RESULT(); } assert(get_count <= 8); }
void EMSCRIPTEN_KEEPALIVE main_loop(void) { time_t now = time(NULL); static time_t graph_update; char url[64]; static int tatami = 1; static time_t forced_update; #if 1 SDL_Event event; while (SDL_PollEvent(&event)) { switch(event.type) { case SDL_MOUSEBUTTONDOWN: { SDL_MouseButtonEvent *m = (SDL_MouseButtonEvent*)&event; //printf("button down: %d,%d %d,%d\n", m->button, m->state, m->x, m->y); button_pressed(m->x, m->y); break; } } } if (now > next_update || now > forced_update + 3 || icontimer == 1) { refresh_window(); forced_update = now; } timeout_ask_for_data(NULL); if (now > graph_update+2) { graph_update = now; emscripten_async_wget_data("matchinfo?t=0", NULL, onloadabstract, onerror); } mouse_move(); if (icontimer > 0) { icontimer--; } SDL_Rect dest; dest.x = dest.y = dest.w = dest.h = 0; //dest.y = icontimer - 50; //if (dest.y > 0) dest.y = 0; if (menuicon && icontimer > 2) { SDL_BlitSurface(menuicon, NULL, darea, &dest); } if (menu_on && menubg) { icontimer = 50; show_menu(); } #endif }
int main(int argc, char* argv[]) { const char* default_filename = "main.lua"; char* filename = NULL; const char* zipname = "game.zip"; int r; bool is_arg[argc]; int ziplen = strlen("--zip="); for (int i = 1; i < argc; i++) { is_arg[i] = false; if (!strncmp(argv[i], "--zip=", ziplen)) { zipname = argv[i] + ziplen; } else if (!filename) { filename = xstrdup(argv[i]); } else { is_arg[i] = true; } } if (!filename) { filename = xstrdup(default_filename); } else if (is_directory(filename)) { char* newfilename; if (endswith(filename, "/")) { newfilename = strjoin(filename, default_filename, NULL); } else { newfilename = strjoin(filename, "/", default_filename, NULL); } free(filename); filename = newfilename; } r = engine_init(filename, 60); if (r < 0) { return EXIT_FAILURE; } for (int i = 1; i < argc; i++) { if (is_arg[i]) { dlua_add_arg(argv[i]); } } log_info("Downloading %s...", zipname); emscripten_async_wget_data(zipname, NULL, on_zip_downloaded, on_zip_fail); emscripten_set_main_loop(loop, 0, true); return 0; }
void onloadabstract(void *arg, void *buf, int len) { char *b = buf; int n, t, crc; static int last_crc[NUM_TATAMIS]; while (b) { n = sscanf(b, "%d,%d", &t, &crc); if (n == 2 && t >= 1 && t <= NUM_TATAMIS) { if (last_crc[t-1] != crc) { char url[64]; last_crc[t-1] = crc; snprintf(url, sizeof(url), "matchinfo?t=%d", t); emscripten_async_wget_data(url, NULL, onload, onerror); } } else break; b = strchr(b, '\n'); if (b) b++; } }