From 2d188fd2b232aebaf7f4a5552bc567f02a87e349 Mon Sep 17 00:00:00 2001 From: emb <> Date: Tue, 27 Oct 2015 22:42:15 -0500 Subject: [PATCH] Support for checking for new keypresses. Fix playlist updating bug. --- .../Collection/CollectionInfoBuilder.cpp | 39 +++++++++++++------ RetroFE/Source/Control/UserInput.cpp | 14 ++++++- RetroFE/Source/Control/UserInput.h | 3 +- RetroFE/Source/RetroFE.cpp | 6 +-- 4 files changed, 44 insertions(+), 18 deletions(-) diff --git a/RetroFE/Source/Collection/CollectionInfoBuilder.cpp b/RetroFE/Source/Collection/CollectionInfoBuilder.cpp index 79be5c1..65b5518 100644 --- a/RetroFE/Source/Collection/CollectionInfoBuilder.cpp +++ b/RetroFE/Source/Collection/CollectionInfoBuilder.cpp @@ -231,6 +231,7 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me DIR *dp; struct dirent *dirp; std::string path = info->listpath; + std::map allMap; std::map includeFilter; std::map favoritesFilter; std::map excludeFilter; @@ -261,7 +262,6 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me { Logger::write(Logger::ZONE_INFO, "CollectionInfoBuilder", "Checking for \"" + includeFile + "\""); ImportBasicList(info, includeFile, includeFilter); - ImportBasicList(info, favoritesFile, favoritesFilter); ImportBasicList(info, excludeFile, excludeFilter); } @@ -269,9 +269,6 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me std::vector::iterator extensionsIt; info->extensionList(extensions); - info->playlists["all"] = &info->items; - info->playlists["favorites"] = new std::vector(); - dp = opendir(path.c_str()); @@ -279,7 +276,6 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me if(dp == NULL) { Logger::write(Logger::ZONE_INFO, "CollectionInfoBuilder", "Could not read directory \"" + path + "\". Ignore if this is a menu."); - return false; } if(showMissing) @@ -292,13 +288,8 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me } } } - // add the favorites list - for(std::map::iterator it = favoritesFilter.begin(); it != favoritesFilter.end(); it++) - { - info->playlists["favorites"]->push_back(it->second); - } - while((dirp = readdir(dp)) != NULL) + while(dp != NULL && (dirp = readdir(dp)) != NULL) { std::string file = dirp->d_name; @@ -333,7 +324,10 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me } } - closedir(dp); + if(dp != NULL) + { + closedir(dp); + } while(includeFilter.size() > 0) { @@ -352,6 +346,27 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me excludeFilter.erase(it); } + for(std::vector::iterator it = info->items.begin(); it != info->items.end(); it++) { + allMap[(*it)->fullTitle] = *it; + } + + + ImportBasicList(info, favoritesFile, favoritesFilter); + info->playlists["all"] = &info->items; + info->playlists["favorites"] = new std::vector(); + + // add the favorites list + for(std::map::iterator it = favoritesFilter.begin(); it != favoritesFilter.end(); it++) + { + std::map::iterator itemit = allMap.find(it->first); + + if(itemit != allMap.end()) + { + info->playlists["favorites"]->push_back(itemit->second); + } + } + + metaDB_.injectMetadata(info); return true; diff --git a/RetroFE/Source/Control/UserInput.cpp b/RetroFE/Source/Control/UserInput.cpp index e3f89c2..310c0c6 100644 --- a/RetroFE/Source/Control/UserInput.cpp +++ b/RetroFE/Source/Control/UserInput.cpp @@ -30,6 +30,7 @@ UserInput::UserInput(Configuration &c) for(unsigned int i = 0; i < KeyCodeMax; ++i) { keyHandlers_[i] = NULL; + currentKeyState_[i] = false; lastKeyState_[i] = false; } } @@ -234,6 +235,9 @@ void UserInput::resetStates() bool UserInput::update(SDL_Event &e) { bool updated = false; + + memcpy(lastKeyState_, currentKeyState_, sizeof(lastKeyState_)); + for(unsigned int i = 0; i < KeyCodeMax; ++i) { InputHandler *h = keyHandlers_[i]; @@ -241,7 +245,7 @@ bool UserInput::update(SDL_Event &e) { if(h->update(e)) updated = true; - lastKeyState_[i] = h->pressed(); + currentKeyState_[i] = h->pressed(); } } @@ -250,5 +254,11 @@ bool UserInput::update(SDL_Event &e) bool UserInput::keystate(KeyCode_E code) { - return lastKeyState_[code]; + return currentKeyState_[code]; } + +bool UserInput::newKeyPressed(KeyCode_E code) +{ + return currentKeyState_[code] && !lastKeyState_[code]; +} + diff --git a/RetroFE/Source/Control/UserInput.h b/RetroFE/Source/Control/UserInput.h index feaffc5..92f9684 100644 --- a/RetroFE/Source/Control/UserInput.h +++ b/RetroFE/Source/Control/UserInput.h @@ -55,6 +55,7 @@ public: void resetStates(); bool update(SDL_Event &e); bool keystate(KeyCode_E); + bool newKeyPressed(KeyCode_E code); private: bool MapKey(std::string keyDescription, KeyCode_E key); @@ -63,5 +64,5 @@ private: std::vector joysticks_; InputHandler *keyHandlers_[KeyCodeMax]; bool lastKeyState_[KeyCodeMax]; - + bool currentKeyState_[KeyCodeMax]; }; diff --git a/RetroFE/Source/RetroFE.cpp b/RetroFE/Source/RetroFE.cpp index 855d2d8..394d596 100644 --- a/RetroFE/Source/RetroFE.cpp +++ b/RetroFE/Source/RetroFE.cpp @@ -480,15 +480,15 @@ RetroFE::RETROFE_STATE RetroFE::processUserInput(Page *page) { page->letterScroll(Page::ScrollDirectionForward); } - if(input_.keystate(UserInput::KeyCodeNextPlaylist)) + if(input_.newKeyPressed(UserInput::KeyCodeNextPlaylist)) { page->nextPlaylist(); } - if(input_.keystate(UserInput::KeyCodeRemovePlaylist)) + if(input_.newKeyPressed(UserInput::KeyCodeRemovePlaylist)) { page->removePlaylist(); } - if(input_.keystate(UserInput::KeyCodeAddPlaylist)) + if(input_.newKeyPressed(UserInput::KeyCodeAddPlaylist)) { page->addPlaylist(); }