From 38e24736a00a13a796fbd01ded0b476694e85ad4 Mon Sep 17 00:00:00 2001 From: kohait Date: Thu, 21 Jul 2011 14:24:14 +0000 Subject: [PATCH] rainbow: LinuxFb & SDLFb TimerProc fix, keeping message que busy git-svn-id: svn://ultimatepp.org/upp/trunk@3686 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- rainbow/LinuxFb/Win.cpp | 5 +++++ rainbow/SDLFb/SDLFbLocal.h | 1 + rainbow/SDLFb/Win.cpp | 27 +++++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/rainbow/LinuxFb/Win.cpp b/rainbow/LinuxFb/Win.cpp index b6270d097..7a0485251 100644 --- a/rainbow/LinuxFb/Win.cpp +++ b/rainbow/LinuxFb/Win.cpp @@ -49,6 +49,11 @@ bool FBProcessEvent(bool *quit) void FBSleep(int ms) { pend = readevents(ms); //interruptable sleep + + //keep queue busy, see SDLFb/Win.cpp for why + //this indicates that some stuff is pending, returning true in FBProcessEvent + //while nothing is actually processed + pend |= 4; } void FBUpdate(const Rect& inv) diff --git a/rainbow/SDLFb/SDLFbLocal.h b/rainbow/SDLFb/SDLFbLocal.h index 53e260146..51ec5a8c5 100644 --- a/rainbow/SDLFb/SDLFbLocal.h +++ b/rainbow/SDLFb/SDLFbLocal.h @@ -13,6 +13,7 @@ extern int videoflags; extern int height; extern int width; extern int bpp; +extern SDL_TimerID waketimer_id; SDL_Surface *CreateScreen(int w, int h, int bpp, int flags); dword fbKEYtoK(dword chr); diff --git a/rainbow/SDLFb/Win.cpp b/rainbow/SDLFb/Win.cpp index 3a45bdb94..3fceecd4d 100644 --- a/rainbow/SDLFb/Win.cpp +++ b/rainbow/SDLFb/Win.cpp @@ -10,6 +10,20 @@ int height = 0; int width = 0; int bpp = 0; +SDL_TimerID waketimer_id = 0; +Uint32 WakeCb(Uint32 interval, void *param) +{ + //wake up message que, FIXME maybe it can be done better? + SDL_Event event; + event.type=SDL_USEREVENT; + SDL_PushEvent(&event); + return 0; +} +void ScheduleWakup() +{ + waketimer_id = SDL_AddTimer(20, WakeCb, NULL); +} + void FBQuitSession() { SDL_Event event; @@ -39,7 +53,15 @@ bool FBProcessEvent(bool *quit) void FBSleep(int ms) { - Sleep(ms); //sleep should be wakeable with input + SDL_Delay(ms); //sleep should be wakeable with input + //ProcessEvents needs to process sth from queue each now and then. + //if no input is generated, no TimerProc call is performed, because queue ws empty. + //win32 backend has WM_TIMER message, that gets posted automatically into queue each 10ms. + //we dont have means to define a 'background' timer in an efficient way + //which could wakeup queue with smaller intervall (10ms) than sleep (20ms). + //we could go long way with a rescheduled timer (expensive) + //or the short way, keeping queue busy after each sleep + WakeCb(0,0); } void FBUpdate(const Rect& inv) @@ -82,7 +104,7 @@ void FBInit() Ctrl::InitFB(); - if(SDL_Init(SDL_INIT_VIDEO) < 0) + if(SDL_Init(SDL_INIT_VIDEO/* | SDL_INIT_TIMER*/) < 0) //timer not needed, we post to queue directly { Cout() << Format("Couldn't initialize SDL: %s\n", SDL_GetError()); return; @@ -110,6 +132,7 @@ void FBInit() void FBDeInit() { + SDL_RemoveTimer(waketimer_id); Ctrl::ExitFB(); SDL_FreeSurface(screen); SDL_Quit();