From ac2fa73962d4c25ca805a03ba77f5556732b05cd Mon Sep 17 00:00:00 2001 From: Ulrich Hecht Date: Sun, 20 Jun 2010 13:01:50 +0200 Subject: [PATCH] don't waste CPU redrawing the screen when there's no input Signed-off-by: Ulrich Hecht --- src/gmenu2x.cpp | 5 ++--- src/inputmanager.cpp | 5 ++++- src/inputmanager.h | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index 230e235..3cbc640 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -940,7 +940,8 @@ void GMenu2X::main() { } //#ifdef TARGET_GP2X - input.update(); + while (!input.update()) + usleep(LOOP_DELAY); if ( input[ACTION_B] && menu->selLink()!=NULL ) menu->selLink()->run(); else if ( input[ACTION_START] ) options(); else if ( input[ACTION_SELECT] ) contextMenu(); @@ -993,8 +994,6 @@ void GMenu2X::main() { offset = menu->sectionLinks()->size()>linksPerPage ? 2 : 6; } } - - usleep(LOOP_DELAY); } } diff --git a/src/inputmanager.cpp b/src/inputmanager.cpp index 3803682..58014f7 100644 --- a/src/inputmanager.cpp +++ b/src/inputmanager.cpp @@ -128,7 +128,8 @@ void InputManager::setActionsCount(int count) { } } -void InputManager::update() { +bool InputManager::update() { + bool anyactions = false; SDL_JoystickUpdate(); events.clear(); @@ -145,11 +146,13 @@ void InputManager::update() { if (tick-actionTick[x]>interval[x]) { actions[x] = true; actionTick[x] = tick; + anyactions = true; } } else { actionTick[x] = 0; } } + return anyactions; } int InputManager::count() { diff --git a/src/inputmanager.h b/src/inputmanager.h index 9e65614..11a08b2 100644 --- a/src/inputmanager.h +++ b/src/inputmanager.h @@ -78,7 +78,7 @@ public: vector actions; vector mappings; - void update(); + bool update(); int count(); void setActionsCount(int count); void setInterval(int ms, int action = -1);