From c990f1293229f54fab44a9e151980d2fb2e8fee7 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Wed, 23 Mar 2011 04:31:00 +0000 Subject: [PATCH] Eliminate ini file loading in the paint, sort, and tooltip events. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7403 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/DolphinWX/Src/GameListCtrl.cpp | 126 ++++++++------------- Source/Core/DolphinWX/Src/GameListCtrl.h | 10 ++ Source/Core/DolphinWX/Src/ISOFile.cpp | 10 ++ Source/Core/DolphinWX/Src/ISOFile.h | 7 +- 4 files changed, 73 insertions(+), 80 deletions(-) diff --git a/Source/Core/DolphinWX/Src/GameListCtrl.cpp b/Source/Core/DolphinWX/Src/GameListCtrl.cpp index e311135a95..5ad6eab314 100644 --- a/Source/Core/DolphinWX/Src/GameListCtrl.cpp +++ b/Source/Core/DolphinWX/Src/GameListCtrl.cpp @@ -30,7 +30,6 @@ #include "Blob.h" #include "Core.h" #include "ISOProperties.h" -#include "IniFile.h" #include "FileUtil.h" #include "CDUtils.h" #include "WxUtils.h" @@ -149,11 +148,7 @@ CGameListCtrl::~CGameListCtrl() if (m_imageListSmall) delete m_imageListSmall; - while (!m_ISOFiles.empty()) // so lazy - { - delete m_ISOFiles.back(); - m_ISOFiles.pop_back(); - } + ClearIsoFiles(); } void CGameListCtrl::InitBitmaps() @@ -359,41 +354,37 @@ std::string CGameListCtrl::GetGameNames() const // This draws our icons on top of the gamelist, it's only used on Windows void CGameListCtrl::OnPaintDrawImages(wxPaintEvent& event) { - int i = 0, nState = 0; - IniFile ini; - wxRect itemRect; wxPaintDC dc(this); // Calls the default drawing code wxControl::OnPaint(event); // Draw the flags, platform icons and emustate icons on top if there's games to show - if (m_ISOFiles.size() != 0) + + // Retrieve the topmost shown item and get drawing offsets + const long + top_item = GetTopItem(), + bottom_item = std::min(top_item + GetCountPerPage() + 2, (long)GetItemCount()); + + int flagOffset = GetColumnWidth(0) + GetColumnWidth(1) + + GetColumnWidth(2) + GetColumnWidth(3); + int stateOffset = flagOffset + GetColumnWidth(4) + GetColumnWidth(5); + + // Only redraw shown lines + for (long i = top_item; i != bottom_item; ++i) { - // Retrieve the topmost shown item and get drawing offsets - long top = GetTopItem(); - int flagOffset = GetColumnWidth(0) + GetColumnWidth(1) + - GetColumnWidth(2) + GetColumnWidth(3); - int stateOffset = flagOffset + GetColumnWidth(4) + GetColumnWidth(5); - - // Only redraw shown lines - for (i = top; i < top + GetCountPerPage() + 2; i++) + wxRect itemRect; + if (GetItemRect(i, itemRect)) { - if (GetItemRect(i, itemRect)) - { - int itemY = itemRect.GetTop(); - const GameListItem& rISOFile = *m_ISOFiles[GetItemData(i)]; + const int itemY = itemRect.GetTop(); + const GameListItem& rISOFile = *m_ISOFiles[GetItemData(i)]; - m_imageListSmall->Draw(m_PlatformImageIndex[rISOFile.GetPlatform()], - dc, itemRect.GetX()+3, itemY); - m_imageListSmall->Draw(m_FlagImageIndex[rISOFile.GetCountry()], - dc, flagOffset, itemY); - - ini.Load(File::GetUserPath(D_GAMECONFIG_IDX) + rISOFile.GetUniqueID() + ".ini"); - ini.Get("EmuState", "EmulationStateId", &nState); - m_imageListSmall->Draw(m_EmuStateImageIndex[nState], - dc, stateOffset, itemY); - } + m_imageListSmall->Draw(m_PlatformImageIndex[rISOFile.GetPlatform()], + dc, itemRect.GetX()+3, itemY); + m_imageListSmall->Draw(m_FlagImageIndex[rISOFile.GetCountry()], + dc, flagOffset, itemY); + m_imageListSmall->Draw(m_EmuStateImageIndex[rISOFile.GetEmuState()], + dc, stateOffset, itemY); } } } @@ -494,16 +485,8 @@ void CGameListCtrl::InsertItemInReportView(long _Index) } #ifndef _WIN32 - // Load the INI file for columns that read from it - IniFile ini; - ini.Load(File::GetUserPath(D_GAMECONFIG_IDX) + rISOFile.GetUniqueID() + ".ini"); - - // Emulation status - int nState; - ini.Get("EmuState", "EmulationStateId", &nState); - // Emulation state - SetItemColumnImage(_Index, COLUMN_EMULATION_STATE, m_EmuStateImageIndex[nState]); + SetItemColumnImage(_Index, COLUMN_EMULATION_STATE, m_EmuStateImageIndex[rISOFile.GetEmuState()]); // Country SetItemColumnImage(_Index, COLUMN_COUNTRY, m_FlagImageIndex[rISOFile.GetCountry()]); @@ -543,7 +526,8 @@ void CGameListCtrl::SetBackgroundColor() void CGameListCtrl::ScanForISOs() { - m_ISOFiles.clear(); + ClearIsoFiles(); + CFileSearch::XStringVector Directories(SConfig::GetInstance().m_ISOFolder); if (SConfig::GetInstance().m_RecursiveISOFolder) @@ -619,7 +603,7 @@ void CGameListCtrl::ScanForISOs() if (!Cont) break; - GameListItem* const iso_file = new GameListItem(rFilenames[i]); + std::auto_ptr iso_file(new GameListItem(rFilenames[i])); const GameListItem& ISOFile = *iso_file; if (ISOFile.IsValid()) @@ -674,7 +658,7 @@ void CGameListCtrl::ScanForISOs() } if (list) - m_ISOFiles.push_back(iso_file); + m_ISOFiles.push_back(iso_file.release()); } } } @@ -786,24 +770,21 @@ int wxCALLBACK wxListCompare(long item1, long item2, long sortData) if(iso1->GetPlatform() < iso2->GetPlatform()) return -1 * t; return 0; + case CGameListCtrl::COLUMN_EMULATION_STATE: - IniFile ini; - int nState1 = 0, nState2 = 0; - std::string GameIni1 = File::GetUserPath(D_GAMECONFIG_IDX) + - iso1->GetUniqueID() + ".ini"; - std::string GameIni2 = File::GetUserPath(D_GAMECONFIG_IDX) + - iso2->GetUniqueID() + ".ini"; + { + const int + nState1 = iso1->GetEmuState(), + nState2 = iso2->GetEmuState(); - ini.Load(GameIni1.c_str()); - ini.Get("EmuState", "EmulationStateId", &nState1); - ini.Load(GameIni2.c_str()); - ini.Get("EmuState", "EmulationStateId", &nState2); - - if(nState1 > nState2) + if (nState1 > nState2) return 1 * t; - if(nState1 < nState2) + if (nState1 < nState2) return -1 * t; - return 0; + else + return 0; + } + break; } return 0; @@ -891,7 +872,7 @@ void CGameListCtrl::OnMouseMotion(wxMouseEvent& event) { int flags; long subitem = 0; - long item = HitTest(event.GetPosition(), flags, &subitem); + const long item = HitTest(event.GetPosition(), flags, &subitem); static int lastItem = -1; if (GetColumnCount() <= 1) @@ -917,30 +898,19 @@ void CGameListCtrl::OnMouseMotion(wxMouseEvent& event) return; } + // Emulation status + static const char* const emuState[] = { "Broken", "Intro", "In-Game", "Playable", "Perfect" }; + const GameListItem& rISO = *m_ISOFiles[GetItemData(item)]; - IniFile ini; - ini.Load(File::GetUserPath(D_GAMECONFIG_IDX) + rISO.GetUniqueID() + ".ini"); - - // Emulation status - std::string emuState[5] = { - "Broken", - "Intro", - "In-Game", - "Playable", - "Perfect" - }; - std::string issues; - - int nState; - ini.Get("EmuState", "EmulationStateId", &nState); - ini.Get("EmuState", "EmulationIssues", &issues, ""); + const int emu_state = rISO.GetEmuState(); + const std::string& issues = rISO.GetIssues(); // Show a tooltip containing the EmuState and the state description - if (nState > 0 && nState < 6) + if (emu_state > 0 && emu_state < 6) { char temp[2048]; - sprintf(temp, "^ %s%s%s", emuState[nState -1].c_str(), + sprintf(temp, "^ %s%s%s", emuState[emu_state - 1], issues.size() > 0 ? " :\n" : "", issues.c_str()); toolTip = new wxEmuStateTip(this, wxString(temp, *wxConvCurrent), &toolTip); } @@ -1062,7 +1032,7 @@ const GameListItem * CGameListCtrl::GetSelectedISO() { long item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (item == wxNOT_FOUND) - return new GameListItem(""); + return new GameListItem(""); // TODO: wtf is this else { // Here is a little workaround for multiselections: diff --git a/Source/Core/DolphinWX/Src/GameListCtrl.h b/Source/Core/DolphinWX/Src/GameListCtrl.h index 84f4c5e284..3d02830f72 100644 --- a/Source/Core/DolphinWX/Src/GameListCtrl.h +++ b/Source/Core/DolphinWX/Src/GameListCtrl.h @@ -18,6 +18,7 @@ #ifndef __GAMELIST_CTRL_H_ #define __GAMELIST_CTRL_H_ +#include #include #include @@ -73,6 +74,15 @@ private: std::vector m_EmuStateImageIndex; std::vector m_ISOFiles; + void ClearIsoFiles() + { + while (!m_ISOFiles.empty()) // so lazy + { + delete m_ISOFiles.back(); + m_ISOFiles.pop_back(); + } + } + // NetPlay string for the gamelist std::string m_gameList; std::string m_gamePath; diff --git a/Source/Core/DolphinWX/Src/ISOFile.cpp b/Source/Core/DolphinWX/Src/ISOFile.cpp index 8af27a432d..cf9810b9bf 100644 --- a/Source/Core/DolphinWX/Src/ISOFile.cpp +++ b/Source/Core/DolphinWX/Src/ISOFile.cpp @@ -27,6 +27,7 @@ #include "ISOFile.h" #include "StringUtil.h" #include "Hash.h" +#include "IniFile.h" #include "Filesystem.h" #include "BannerLoader.h" @@ -47,6 +48,7 @@ GameListItem::GameListItem(const std::string& _rFileName) , m_FileSize(0) , m_Valid(false) , m_BlobCompressed(false) + , m_emu_state(0) { if (LoadFromCache()) { @@ -126,6 +128,14 @@ GameListItem::GameListItem(const std::string& _rFileName) } } + if (IsValid()) + { + IniFile ini; + ini.Load(File::GetUserPath(D_GAMECONFIG_IDX) + m_UniqueID + ".ini"); + ini.Get("EmuState", "EmulationStateId", &m_emu_state); + ini.Get("EmuState", "EmulationIssues", &m_issues); + } + if (!m_pImage.empty()) { m_Image.Create(DVD_BANNER_WIDTH, DVD_BANNER_HEIGHT, &m_pImage[0], true); diff --git a/Source/Core/DolphinWX/Src/ISOFile.h b/Source/Core/DolphinWX/Src/ISOFile.h index 7392a4fcf1..35cec18772 100644 --- a/Source/Core/DolphinWX/Src/ISOFile.h +++ b/Source/Core/DolphinWX/Src/ISOFile.h @@ -41,7 +41,8 @@ public: const std::string GetWiiFSPath() const; DiscIO::IVolume::ECountry GetCountry() const {return m_Country;} int GetPlatform() const {return m_Platform;} - const std::string& GetIssues() const {return m_Issues;} + const std::string& GetIssues() const { return m_issues; } + int GetEmuState() const { return m_emu_state; } bool IsCompressed() const {return m_BlobCompressed;} u64 GetFileSize() const {return m_FileSize;} u64 GetVolumeSize() const {return m_VolumeSize;} @@ -65,7 +66,9 @@ private: std::string m_Company; std::string m_Description[6]; std::string m_UniqueID; - std::string m_Issues; + + std::string m_issues; + int m_emu_state; u64 m_FileSize; u64 m_VolumeSize;