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