int OSystem_SDL::mySDL_PollEvent(SDL_Event *event) { int r = SDL_PollEvent(event); if (!r) return 0; if (event->type == SDL_ACTIVEEVENT){ if (event->active.state == SDL_APPINPUTFOCUS && !event->active.gain){ bool st_pause = st_pause_ticks_started(); if (!st_pause) st_pause_ticks_start(); suspendAudio(); for(;;){ printf("wait\n"); r = SDL_WaitEvent(event); printf("wait done\n"); if (!r) continue; if (event->type == SDL_QUIT) return 1; if (event->type != SDL_ACTIVEEVENT) continue; if (event->active.state == SDL_APPINPUTFOCUS && event->active.gain){ resumeAudio(); if (!st_pause) st_pause_ticks_stop(); return 1; } } } } return r; } unsigned int st_pause_ticks, st_pause_count; unsigned int st_get_ticks(void) { if (st_pause_count != 0) return /*SDL_GetTicks()*/ - st_pause_ticks /*- SDL_GetTicks()*/ + st_pause_count; else return SDL_GetTicks() - st_pause_ticks; } void st_pause_ticks_init(void) { st_pause_ticks = 0; st_pause_count = 0; } void st_pause_ticks_start(void) { if (st_pause_count == 0) st_pause_count = SDL_GetTicks(); } void st_pause_ticks_stop(void) { if (st_pause_count == 0) return; st_pause_ticks += SDL_GetTicks() - st_pause_count; st_pause_count = 0; } bool st_pause_ticks_started(void) { if (st_pause_count == 0) return false; else return true; } void OSystem_SDL::suspendAudio() { // if (audioSuspended) return; SDL_CloseAudio(); audioSuspended = true; } int OSystem_SDL::resumeAudio() { if (!audioSuspended) return -2; if (SDL_OpenAudio(&obtained, NULL) < 0){ printf("audio resumed\n"); return -1; } SDL_PauseAudio(0); audioSuspended = false; return 0; }