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
This commit is contained in:
Jordan Woyak 2011-03-23 04:31:00 +00:00
parent 668d335181
commit c990f12932
4 changed files with 73 additions and 80 deletions

View File

@ -30,7 +30,6 @@
#include "Blob.h" #include "Blob.h"
#include "Core.h" #include "Core.h"
#include "ISOProperties.h" #include "ISOProperties.h"
#include "IniFile.h"
#include "FileUtil.h" #include "FileUtil.h"
#include "CDUtils.h" #include "CDUtils.h"
#include "WxUtils.h" #include "WxUtils.h"
@ -149,11 +148,7 @@ CGameListCtrl::~CGameListCtrl()
if (m_imageListSmall) if (m_imageListSmall)
delete m_imageListSmall; delete m_imageListSmall;
while (!m_ISOFiles.empty()) // so lazy ClearIsoFiles();
{
delete m_ISOFiles.back();
m_ISOFiles.pop_back();
}
} }
void CGameListCtrl::InitBitmaps() 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 // This draws our icons on top of the gamelist, it's only used on Windows
void CGameListCtrl::OnPaintDrawImages(wxPaintEvent& event) void CGameListCtrl::OnPaintDrawImages(wxPaintEvent& event)
{ {
int i = 0, nState = 0;
IniFile ini;
wxRect itemRect;
wxPaintDC dc(this); wxPaintDC dc(this);
// Calls the default drawing code // Calls the default drawing code
wxControl::OnPaint(event); wxControl::OnPaint(event);
// Draw the flags, platform icons and emustate icons on top if there's games to show // 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 wxRect itemRect;
long top = GetTopItem(); if (GetItemRect(i, itemRect))
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++)
{ {
if (GetItemRect(i, itemRect)) const int itemY = itemRect.GetTop();
{ const GameListItem& rISOFile = *m_ISOFiles[GetItemData(i)];
int itemY = itemRect.GetTop();
const GameListItem& rISOFile = *m_ISOFiles[GetItemData(i)];
m_imageListSmall->Draw(m_PlatformImageIndex[rISOFile.GetPlatform()], m_imageListSmall->Draw(m_PlatformImageIndex[rISOFile.GetPlatform()],
dc, itemRect.GetX()+3, itemY); dc, itemRect.GetX()+3, itemY);
m_imageListSmall->Draw(m_FlagImageIndex[rISOFile.GetCountry()], m_imageListSmall->Draw(m_FlagImageIndex[rISOFile.GetCountry()],
dc, flagOffset, itemY); dc, flagOffset, itemY);
m_imageListSmall->Draw(m_EmuStateImageIndex[rISOFile.GetEmuState()],
ini.Load(File::GetUserPath(D_GAMECONFIG_IDX) + rISOFile.GetUniqueID() + ".ini"); dc, stateOffset, itemY);
ini.Get("EmuState", "EmulationStateId", &nState);
m_imageListSmall->Draw(m_EmuStateImageIndex[nState],
dc, stateOffset, itemY);
}
} }
} }
} }
@ -494,16 +485,8 @@ void CGameListCtrl::InsertItemInReportView(long _Index)
} }
#ifndef _WIN32 #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 // Emulation state
SetItemColumnImage(_Index, COLUMN_EMULATION_STATE, m_EmuStateImageIndex[nState]); SetItemColumnImage(_Index, COLUMN_EMULATION_STATE, m_EmuStateImageIndex[rISOFile.GetEmuState()]);
// Country // Country
SetItemColumnImage(_Index, COLUMN_COUNTRY, m_FlagImageIndex[rISOFile.GetCountry()]); SetItemColumnImage(_Index, COLUMN_COUNTRY, m_FlagImageIndex[rISOFile.GetCountry()]);
@ -543,7 +526,8 @@ void CGameListCtrl::SetBackgroundColor()
void CGameListCtrl::ScanForISOs() void CGameListCtrl::ScanForISOs()
{ {
m_ISOFiles.clear(); ClearIsoFiles();
CFileSearch::XStringVector Directories(SConfig::GetInstance().m_ISOFolder); CFileSearch::XStringVector Directories(SConfig::GetInstance().m_ISOFolder);
if (SConfig::GetInstance().m_RecursiveISOFolder) if (SConfig::GetInstance().m_RecursiveISOFolder)
@ -619,7 +603,7 @@ void CGameListCtrl::ScanForISOs()
if (!Cont) if (!Cont)
break; break;
GameListItem* const iso_file = new GameListItem(rFilenames[i]); std::auto_ptr<GameListItem> iso_file(new GameListItem(rFilenames[i]));
const GameListItem& ISOFile = *iso_file; const GameListItem& ISOFile = *iso_file;
if (ISOFile.IsValid()) if (ISOFile.IsValid())
@ -674,7 +658,7 @@ void CGameListCtrl::ScanForISOs()
} }
if (list) 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()) if(iso1->GetPlatform() < iso2->GetPlatform())
return -1 * t; return -1 * t;
return 0; return 0;
case CGameListCtrl::COLUMN_EMULATION_STATE: case CGameListCtrl::COLUMN_EMULATION_STATE:
IniFile ini; {
int nState1 = 0, nState2 = 0; const int
std::string GameIni1 = File::GetUserPath(D_GAMECONFIG_IDX) + nState1 = iso1->GetEmuState(),
iso1->GetUniqueID() + ".ini"; nState2 = iso2->GetEmuState();
std::string GameIni2 = File::GetUserPath(D_GAMECONFIG_IDX) +
iso2->GetUniqueID() + ".ini";
ini.Load(GameIni1.c_str()); if (nState1 > nState2)
ini.Get("EmuState", "EmulationStateId", &nState1);
ini.Load(GameIni2.c_str());
ini.Get("EmuState", "EmulationStateId", &nState2);
if(nState1 > nState2)
return 1 * t; return 1 * t;
if(nState1 < nState2) if (nState1 < nState2)
return -1 * t; return -1 * t;
return 0; else
return 0;
}
break;
} }
return 0; return 0;
@ -891,7 +872,7 @@ void CGameListCtrl::OnMouseMotion(wxMouseEvent& event)
{ {
int flags; int flags;
long subitem = 0; long subitem = 0;
long item = HitTest(event.GetPosition(), flags, &subitem); const long item = HitTest(event.GetPosition(), flags, &subitem);
static int lastItem = -1; static int lastItem = -1;
if (GetColumnCount() <= 1) if (GetColumnCount() <= 1)
@ -917,30 +898,19 @@ void CGameListCtrl::OnMouseMotion(wxMouseEvent& event)
return; return;
} }
// Emulation status
static const char* const emuState[] = { "Broken", "Intro", "In-Game", "Playable", "Perfect" };
const GameListItem& rISO = *m_ISOFiles[GetItemData(item)]; const GameListItem& rISO = *m_ISOFiles[GetItemData(item)];
IniFile ini; const int emu_state = rISO.GetEmuState();
ini.Load(File::GetUserPath(D_GAMECONFIG_IDX) + rISO.GetUniqueID() + ".ini"); const std::string& issues = rISO.GetIssues();
// 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, "");
// Show a tooltip containing the EmuState and the state description // 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]; 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()); issues.size() > 0 ? " :\n" : "", issues.c_str());
toolTip = new wxEmuStateTip(this, wxString(temp, *wxConvCurrent), &toolTip); 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); long item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
if (item == wxNOT_FOUND) if (item == wxNOT_FOUND)
return new GameListItem(""); return new GameListItem(""); // TODO: wtf is this
else else
{ {
// Here is a little workaround for multiselections: // Here is a little workaround for multiselections:

View File

@ -18,6 +18,7 @@
#ifndef __GAMELIST_CTRL_H_ #ifndef __GAMELIST_CTRL_H_
#define __GAMELIST_CTRL_H_ #define __GAMELIST_CTRL_H_
#include <memory>
#include <vector> #include <vector>
#include <wx/listctrl.h> #include <wx/listctrl.h>
@ -73,6 +74,15 @@ private:
std::vector<int> m_EmuStateImageIndex; std::vector<int> m_EmuStateImageIndex;
std::vector<GameListItem*> m_ISOFiles; std::vector<GameListItem*> m_ISOFiles;
void ClearIsoFiles()
{
while (!m_ISOFiles.empty()) // so lazy
{
delete m_ISOFiles.back();
m_ISOFiles.pop_back();
}
}
// NetPlay string for the gamelist // NetPlay string for the gamelist
std::string m_gameList; std::string m_gameList;
std::string m_gamePath; std::string m_gamePath;

View File

@ -27,6 +27,7 @@
#include "ISOFile.h" #include "ISOFile.h"
#include "StringUtil.h" #include "StringUtil.h"
#include "Hash.h" #include "Hash.h"
#include "IniFile.h"
#include "Filesystem.h" #include "Filesystem.h"
#include "BannerLoader.h" #include "BannerLoader.h"
@ -47,6 +48,7 @@ GameListItem::GameListItem(const std::string& _rFileName)
, m_FileSize(0) , m_FileSize(0)
, m_Valid(false) , m_Valid(false)
, m_BlobCompressed(false) , m_BlobCompressed(false)
, m_emu_state(0)
{ {
if (LoadFromCache()) 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()) if (!m_pImage.empty())
{ {
m_Image.Create(DVD_BANNER_WIDTH, DVD_BANNER_HEIGHT, &m_pImage[0], true); m_Image.Create(DVD_BANNER_WIDTH, DVD_BANNER_HEIGHT, &m_pImage[0], true);

View File

@ -41,7 +41,8 @@ public:
const std::string GetWiiFSPath() const; const std::string GetWiiFSPath() const;
DiscIO::IVolume::ECountry GetCountry() const {return m_Country;} DiscIO::IVolume::ECountry GetCountry() const {return m_Country;}
int GetPlatform() const {return m_Platform;} 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;} bool IsCompressed() const {return m_BlobCompressed;}
u64 GetFileSize() const {return m_FileSize;} u64 GetFileSize() const {return m_FileSize;}
u64 GetVolumeSize() const {return m_VolumeSize;} u64 GetVolumeSize() const {return m_VolumeSize;}
@ -65,7 +66,9 @@ private:
std::string m_Company; std::string m_Company;
std::string m_Description[6]; std::string m_Description[6];
std::string m_UniqueID; std::string m_UniqueID;
std::string m_Issues;
std::string m_issues;
int m_emu_state;
u64 m_FileSize; u64 m_FileSize;
u64 m_VolumeSize; u64 m_VolumeSize;