Switch to SDL Timer for redraw handler.
This commit is contained in:
parent
a35ef6b242
commit
96f4510a03
32
src/uxnemu.c
32
src/uxnemu.c
|
@ -88,23 +88,21 @@ stdin_handler(void *p)
|
||||||
(void)p;
|
(void)p;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static Uint32
|
||||||
redraw_handler(void *p)
|
redraw_handler(Uint32 interval, void *p)
|
||||||
{
|
{
|
||||||
int dropped_frames = 0, stop = 0;
|
static int dropped_frames = 0;
|
||||||
SDL_Event event, interrupt;
|
static unsigned int bump_interval = 0;
|
||||||
event.type = redraw_event;
|
SDL_Event event;
|
||||||
interrupt.type = interrupt_event;
|
if(SDL_HasEvent(redraw_event) == SDL_FALSE) {
|
||||||
while(!stop) {
|
event.type = redraw_event;
|
||||||
SDL_Delay(16);
|
dropped_frames = 0;
|
||||||
if(SDL_HasEvent(redraw_event) == SDL_FALSE) {
|
} else if(++dropped_frames == TIMEOUT_FRAMES) {
|
||||||
stop = SDL_PushEvent(&event) < 0;
|
event.type = interrupt_event;
|
||||||
dropped_frames = 0;
|
|
||||||
} else if(++dropped_frames == TIMEOUT_FRAMES) {
|
|
||||||
stop = SDL_PushEvent(&interrupt) < 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
SDL_PushEvent(&event);
|
||||||
|
return 16 + (bump_interval++ % 3 == 0);
|
||||||
|
(void)interval;
|
||||||
(void)p;
|
(void)p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,7 +158,7 @@ init(void)
|
||||||
as.callback = audio_callback;
|
as.callback = audio_callback;
|
||||||
as.samples = 512;
|
as.samples = 512;
|
||||||
as.userdata = NULL;
|
as.userdata = NULL;
|
||||||
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0)
|
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_TIMER) < 0)
|
||||||
return error("sdl", SDL_GetError());
|
return error("sdl", SDL_GetError());
|
||||||
gWindow = SDL_CreateWindow("Uxn", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, (WIDTH + PAD * 2) * zoom, (HEIGHT + PAD * 2) * zoom, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
|
gWindow = SDL_CreateWindow("Uxn", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, (WIDTH + PAD * 2) * zoom, (HEIGHT + PAD * 2) * zoom, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
|
||||||
if(gWindow == NULL)
|
if(gWindow == NULL)
|
||||||
|
@ -179,7 +177,7 @@ init(void)
|
||||||
redraw_event = SDL_RegisterEvents(1);
|
redraw_event = SDL_RegisterEvents(1);
|
||||||
interrupt_event = SDL_RegisterEvents(1);
|
interrupt_event = SDL_RegisterEvents(1);
|
||||||
SDL_DetachThread(SDL_CreateThread(stdin_handler, "stdin", NULL));
|
SDL_DetachThread(SDL_CreateThread(stdin_handler, "stdin", NULL));
|
||||||
SDL_DetachThread(SDL_CreateThread(redraw_handler, "redraw", NULL));
|
SDL_AddTimer(16, redraw_handler, NULL);
|
||||||
SDL_StartTextInput();
|
SDL_StartTextInput();
|
||||||
SDL_ShowCursor(SDL_DISABLE);
|
SDL_ShowCursor(SDL_DISABLE);
|
||||||
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
|
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
|
||||||
|
|
Loading…
Reference in New Issue