| ... | ... |
@@ -88,21 +88,23 @@ stdin_handler(void *p) |
| 88 | 88 |
(void)p; |
| 89 | 89 |
} |
| 90 | 90 |
|
| 91 |
-static Uint32 |
|
| 92 |
-redraw_handler(Uint32 interval, void *p) |
|
| 91 |
+static int |
|
| 92 |
+redraw_handler(void *p) |
|
| 93 | 93 |
{
|
| 94 |
- static int dropped_frames = 0; |
|
| 95 |
- static unsigned int bump_interval = 0; |
|
| 96 |
- SDL_Event event; |
|
| 97 |
- if(SDL_HasEvent(redraw_event) == SDL_FALSE) {
|
|
| 98 |
- event.type = redraw_event; |
|
| 99 |
- dropped_frames = 0; |
|
| 100 |
- } else if(++dropped_frames == TIMEOUT_FRAMES) {
|
|
| 101 |
- event.type = interrupt_event; |
|
| 94 |
+ int dropped_frames = 0, stop = 0; |
|
| 95 |
+ SDL_Event event, interrupt; |
|
| 96 |
+ event.type = redraw_event; |
|
| 97 |
+ interrupt.type = interrupt_event; |
|
| 98 |
+ while(!stop) {
|
|
| 99 |
+ SDL_Delay(16); |
|
| 100 |
+ if(SDL_HasEvent(redraw_event) == SDL_FALSE) {
|
|
| 101 |
+ stop = SDL_PushEvent(&event) < 0; |
|
| 102 |
+ dropped_frames = 0; |
|
| 103 |
+ } else if(++dropped_frames == TIMEOUT_FRAMES) {
|
|
| 104 |
+ stop = SDL_PushEvent(&interrupt) < 0; |
|
| 105 |
+ } |
|
| 102 | 106 |
} |
| 103 |
- SDL_PushEvent(&event); |
|
| 104 |
- return 16 + (bump_interval++ % 3 == 0); |
|
| 105 |
- (void)interval; |
|
| 107 |
+ return 0; |
|
| 106 | 108 |
(void)p; |
| 107 | 109 |
} |
| 108 | 110 |
|
| ... | ... |
@@ -158,7 +160,7 @@ init(void) |
| 158 | 160 |
as.callback = audio_callback; |
| 159 | 161 |
as.samples = 512; |
| 160 | 162 |
as.userdata = NULL; |
| 161 |
- if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_TIMER) < 0) |
|
| 163 |
+ if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0) |
|
| 162 | 164 |
return error("sdl", SDL_GetError());
|
| 163 | 165 |
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);
|
| 164 | 166 |
if(gWindow == NULL) |
| ... | ... |
@@ -177,7 +179,7 @@ init(void) |
| 177 | 179 |
redraw_event = SDL_RegisterEvents(1); |
| 178 | 180 |
interrupt_event = SDL_RegisterEvents(1); |
| 179 | 181 |
SDL_DetachThread(SDL_CreateThread(stdin_handler, "stdin", NULL)); |
| 180 |
- SDL_AddTimer(16, redraw_handler, NULL); |
|
| 182 |
+ SDL_DetachThread(SDL_CreateThread(redraw_handler, "redraw", NULL)); |
|
| 181 | 183 |
SDL_StartTextInput(); |
| 182 | 184 |
SDL_ShowCursor(SDL_DISABLE); |
| 183 | 185 |
SDL_EventState(SDL_DROPFILE, SDL_ENABLE); |