show time limit in sanity timer
This commit is contained in:
parent
785b507330
commit
b0e718876a
@ -15,14 +15,18 @@ static struct sigaction sa;
|
|||||||
static struct sigevent sev;
|
static struct sigevent sev;
|
||||||
|
|
||||||
static bool created;
|
static bool created;
|
||||||
|
static uint64_t used_milliseconds_to_expire;
|
||||||
|
|
||||||
|
#define SANITY_TIMER_MESSAGE_FMT "Game tick exeeded its allocated time (%lu milliseconds), application is closing"
|
||||||
|
|
||||||
/* stop application */
|
/* stop application */
|
||||||
static void sanity_timer_handler(int sig, siginfo_t *si, void *uc) {
|
static void sanity_timer_handler(int sig, siginfo_t *si, void *uc) {
|
||||||
(void)uc; (void)sig; (void)si;
|
(void)uc; (void)sig; (void)si;
|
||||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
|
size_t text_str_len = snprintf(NULL, 0, SANITY_TIMER_MESSAGE_FMT, used_milliseconds_to_expire) + 1;
|
||||||
"sanity timer", "Your game tick exceeded its allocated time, application is closing",
|
char *text_str = SDL_malloc(text_str_len);
|
||||||
ctx.window);
|
snprintf(text_str, text_str_len, SANITY_TIMER_MESSAGE_FMT, used_milliseconds_to_expire);
|
||||||
|
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "sanity timer", text_str, ctx.window);
|
||||||
|
SDL_free(text_str);
|
||||||
raise(SIGKILL);
|
raise(SIGKILL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,6 +59,8 @@ bool start_sanity_timer(uint64_t milliseconds_to_expire) {
|
|||||||
if (timer_settime(timerid, 0, &its, NULL) == -1)
|
if (timer_settime(timerid, 0, &its, NULL) == -1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
used_milliseconds_to_expire = milliseconds_to_expire;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user