mirror of https://github.com/PCSX2/pcsx2.git
UI: Refactored plugin loops to use lambdas. (#3569)
This commit is contained in:
parent
79f2468952
commit
2849776054
|
@ -943,12 +943,12 @@ void SysCorePlugins::Load( const wxString (&folders)[PluginId_Count] )
|
|||
Console.WriteLn(Color_StrongBlue, L"\nLoading plugins from %s...", WX_STR(g_Conf->Folders[FolderId_Plugins].ToString()));
|
||||
|
||||
ConsoleIndentScope indent;
|
||||
const PluginInfo* pi = tbl_PluginInfo; do
|
||||
{
|
||||
|
||||
ForPlugins([&] (const PluginInfo * pi) {
|
||||
Load( pi->id, folders[pi->id] );
|
||||
pxYield( 2 );
|
||||
});
|
||||
|
||||
} while( ++pi, pi->shortname != NULL );
|
||||
indent.LeaveScope();
|
||||
|
||||
// Hack for PAD's stupid parameter passed on Init
|
||||
|
@ -1126,7 +1126,7 @@ void SysCorePlugins::Open()
|
|||
|
||||
SendSettingsFolder();
|
||||
|
||||
const PluginInfo* pi = tbl_PluginInfo; do {
|
||||
ForPlugins([&] (const PluginInfo * pi) {
|
||||
Open( pi->id );
|
||||
// If GS doesn't support GSopen2, need to wait until call to GSopen
|
||||
// returns to populate pDsp. If it does, can initialize other plugins
|
||||
|
@ -1140,7 +1140,7 @@ void SysCorePlugins::Open()
|
|||
#else
|
||||
if (pi->id == PluginId_GS && !GSopen2) GetMTGS().WaitForOpen();
|
||||
#endif
|
||||
} while( ++pi, pi->shortname != NULL );
|
||||
});
|
||||
|
||||
if (GSopen2) GetMTGS().WaitForOpen();
|
||||
|
||||
|
@ -1283,9 +1283,10 @@ bool SysCorePlugins::Init()
|
|||
if( !NeedsInit() ) return false;
|
||||
|
||||
Console.WriteLn( Color_StrongBlue, "Initializing plugins..." );
|
||||
const PluginInfo* pi = tbl_PluginInfo; do {
|
||||
|
||||
ForPlugins([&] (const PluginInfo * pi) {
|
||||
Init( pi->id );
|
||||
} while( ++pi, pi->shortname != NULL );
|
||||
});
|
||||
|
||||
if( SysPlugins.Mcd == NULL )
|
||||
{
|
||||
|
@ -1501,10 +1502,10 @@ bool SysCorePlugins::KeyEvent( const keyEvent& evt )
|
|||
// pick up the key and return "true" (for handled) will cause the loop to break.
|
||||
// The current version of PS2E doesn't support it yet, though.
|
||||
|
||||
const PluginInfo* pi = tbl_PluginInfo; do {
|
||||
ForPlugins([&] (const PluginInfo * pi) {
|
||||
if( pi->id != PluginId_PAD && m_info[pi->id] )
|
||||
m_info[pi->id]->CommonBindings.KeyEvent( const_cast<keyEvent*>(&evt) );
|
||||
} while( ++pi, pi->shortname != NULL );
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -1514,9 +1515,9 @@ void SysCorePlugins::SendSettingsFolder()
|
|||
ScopedLock lock( m_mtx_PluginStatus );
|
||||
if( m_SettingsFolder.IsEmpty() ) return;
|
||||
|
||||
const PluginInfo* pi = tbl_PluginInfo; do {
|
||||
ForPlugins([&] (const PluginInfo * pi) {
|
||||
if( m_info[pi->id] ) m_info[pi->id]->CommonBindings.SetSettingsDir( m_SettingsFolder.utf8_str() );
|
||||
} while( ++pi, pi->shortname != NULL );
|
||||
});
|
||||
}
|
||||
|
||||
void SysCorePlugins::SetSettingsFolder( const wxString& folder )
|
||||
|
@ -1538,9 +1539,9 @@ void SysCorePlugins::SendLogFolder()
|
|||
ScopedLock lock( m_mtx_PluginStatus );
|
||||
if( m_LogFolder.IsEmpty() ) return;
|
||||
|
||||
const PluginInfo* pi = tbl_PluginInfo; do {
|
||||
ForPlugins([&] (const PluginInfo * pi) {
|
||||
if( m_info[pi->id] ) m_info[pi->id]->CommonBindings.SetLogDir( m_LogFolder.utf8_str() );
|
||||
} while( ++pi, pi->shortname != NULL );
|
||||
});
|
||||
}
|
||||
|
||||
void SysCorePlugins::SetLogFolder( const wxString& folder )
|
||||
|
@ -1577,11 +1578,10 @@ bool SysCorePlugins::AreLoaded() const
|
|||
bool SysCorePlugins::AreOpen() const
|
||||
{
|
||||
ScopedLock lock( m_mtx_PluginStatus );
|
||||
const PluginInfo* pi = tbl_PluginInfo; do {
|
||||
if( !IsOpen(pi->id) ) return false;
|
||||
} while( ++pi, pi->shortname != NULL );
|
||||
|
||||
return true;
|
||||
return IfPlugins([&] (const PluginInfo * pi) {
|
||||
return !IsOpen(pi->id);
|
||||
});
|
||||
}
|
||||
|
||||
bool SysCorePlugins::AreAnyLoaded() const
|
||||
|
@ -1598,11 +1598,10 @@ bool SysCorePlugins::AreAnyLoaded() const
|
|||
bool SysCorePlugins::AreAnyInitialized() const
|
||||
{
|
||||
ScopedLock lock( m_mtx_PluginStatus );
|
||||
const PluginInfo* pi = tbl_PluginInfo; do {
|
||||
if( IsInitialized(pi->id) ) return true;
|
||||
} while( ++pi, pi->shortname != NULL );
|
||||
|
||||
return false;
|
||||
return IfPlugins([&] (const PluginInfo * pi) {
|
||||
return IsInitialized(pi->id);
|
||||
});
|
||||
}
|
||||
|
||||
bool SysCorePlugins::IsOpen( PluginsEnum_t pid ) const
|
||||
|
@ -1627,60 +1626,49 @@ bool SysCorePlugins::IsLoaded( PluginsEnum_t pid ) const
|
|||
|
||||
bool SysCorePlugins::NeedsLoad() const
|
||||
{
|
||||
const PluginInfo* pi = tbl_PluginInfo; do {
|
||||
if( !IsLoaded(pi->id) ) return true;
|
||||
} while( ++pi, pi->shortname != NULL );
|
||||
|
||||
return false;
|
||||
return IfPlugins([&] (const PluginInfo * pi) {
|
||||
return !IsLoaded(pi->id);
|
||||
});
|
||||
}
|
||||
|
||||
bool SysCorePlugins::NeedsUnload() const
|
||||
{
|
||||
const PluginInfo* pi = tbl_PluginInfo; do {
|
||||
if( IsLoaded(pi->id) ) return true;
|
||||
} while( ++pi, pi->shortname != NULL );
|
||||
|
||||
return false;
|
||||
return IfPlugins([&] (const PluginInfo * pi) {
|
||||
return IsLoaded(pi->id);
|
||||
});
|
||||
}
|
||||
|
||||
bool SysCorePlugins::NeedsInit() const
|
||||
{
|
||||
ScopedLock lock( m_mtx_PluginStatus );
|
||||
|
||||
const PluginInfo* pi = tbl_PluginInfo; do {
|
||||
if( !IsInitialized(pi->id) ) return true;
|
||||
} while( ++pi, pi->shortname != NULL );
|
||||
|
||||
return false;
|
||||
return IfPlugins([&] (const PluginInfo * pi) {
|
||||
return !IsInitialized(pi->id);
|
||||
});
|
||||
}
|
||||
|
||||
bool SysCorePlugins::NeedsShutdown() const
|
||||
{
|
||||
ScopedLock lock( m_mtx_PluginStatus );
|
||||
|
||||
const PluginInfo* pi = tbl_PluginInfo; do {
|
||||
if( IsInitialized(pi->id) ) return true;
|
||||
} while( ++pi, pi->shortname != NULL );
|
||||
|
||||
return false;
|
||||
return IfPlugins([&] (const PluginInfo * pi) {
|
||||
return IsInitialized(pi->id);
|
||||
});
|
||||
}
|
||||
|
||||
bool SysCorePlugins::NeedsOpen() const
|
||||
{
|
||||
const PluginInfo* pi = tbl_PluginInfo; do {
|
||||
if( !IsOpen(pi->id) ) return true;
|
||||
} while( ++pi, pi->shortname != NULL );
|
||||
|
||||
return false;
|
||||
return IfPlugins([&] (const PluginInfo * pi) {
|
||||
return !IsOpen(pi->id);
|
||||
});
|
||||
}
|
||||
|
||||
bool SysCorePlugins::NeedsClose() const
|
||||
{
|
||||
const PluginInfo* pi = tbl_PluginInfo; do {
|
||||
if( IsOpen(pi->id) ) return true;
|
||||
} while( ++pi, pi->shortname != NULL );
|
||||
|
||||
return false;
|
||||
return IfPlugins([&] (const PluginInfo * pi) {
|
||||
return IsOpen(pi->id);
|
||||
});
|
||||
}
|
||||
|
||||
const wxString SysCorePlugins::GetName( PluginsEnum_t pid ) const
|
||||
|
|
|
@ -421,6 +421,30 @@ protected:
|
|||
|
||||
extern const PluginInfo tbl_PluginInfo[];
|
||||
|
||||
template<typename Func>
|
||||
static void ForPlugins(const Func& f)
|
||||
{
|
||||
const PluginInfo* pi = tbl_PluginInfo;
|
||||
|
||||
do
|
||||
{
|
||||
f(pi);
|
||||
} while(++pi, pi->shortname != nullptr);
|
||||
}
|
||||
|
||||
template<typename Func>
|
||||
static bool IfPlugins(const Func& f)
|
||||
{
|
||||
const PluginInfo* pi = tbl_PluginInfo;
|
||||
|
||||
do
|
||||
{
|
||||
if (f(pi)) return true;
|
||||
} while(++pi, pi->shortname != nullptr);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// GetPluginManager() is a required external implementation. This function is *NOT*
|
||||
// provided by the PCSX2 core library. It provides an interface for the linking User
|
||||
// Interface apps or DLLs to reference their own instance of SysCorePlugins (also allowing
|
||||
|
|
|
@ -88,13 +88,12 @@ static void PostPluginStatus( PluginEventType pevt )
|
|||
|
||||
static void ConvertPluginFilenames( wxString (&passins)[PluginId_Count] )
|
||||
{
|
||||
const PluginInfo* pi = tbl_PluginInfo; do
|
||||
{
|
||||
ForPlugins([&] (const PluginInfo * pi) {
|
||||
passins[pi->id] = wxGetApp().Overrides.Filenames[pi->id].GetFullPath();
|
||||
|
||||
if( passins[pi->id].IsEmpty() || !wxFileExists( passins[pi->id] ) )
|
||||
passins[pi->id] = g_Conf->FullpathTo( pi->id );
|
||||
} while( ++pi, pi->shortname != NULL );
|
||||
});
|
||||
}
|
||||
|
||||
typedef void (AppCorePlugins::*FnPtr_AppPluginManager)();
|
||||
|
@ -335,12 +334,6 @@ void AppCorePlugins::Open()
|
|||
{
|
||||
AffinityAssert_AllowFrom_CoreThread();
|
||||
|
||||
/*if( !GetSysExecutorThread().IsSelf() )
|
||||
{
|
||||
GetSysExecutorThread().ProcessEvent( new SysExecEvent_AppPluginManager( &AppCorePlugins::Open ) );
|
||||
return;
|
||||
}*/
|
||||
|
||||
SetLogFolder( GetLogFolder().ToString() );
|
||||
SetSettingsFolder( GetSettingsFolder().ToString() );
|
||||
|
||||
|
@ -547,7 +540,6 @@ void SysExecEvent_SaveSinglePlugin::InvokeEvent()
|
|||
s_DisableGsWindow = true; // keeps the GS window smooth by avoiding closing the window
|
||||
|
||||
ScopedCoreThreadPause paused_core;
|
||||
//_LoadPluginsImmediate();
|
||||
|
||||
if( CorePlugins.AreLoaded() )
|
||||
{
|
||||
|
@ -569,8 +561,6 @@ void SysExecEvent_SaveSinglePlugin::InvokeEvent()
|
|||
Console.WriteLn( Color_Green, L"Recovering single plugin: " + tbl_PluginInfo[m_pid].GetShortname() );
|
||||
memLoadingState load( plugstore.get() );
|
||||
GetCorePlugins().Freeze( m_pid, load );
|
||||
// GS plugin suspend / resume hack. Removed in r4363, hopefully never to return :p
|
||||
//GetCorePlugins().Close( m_pid ); // hack for stupid GS plugins.
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -243,11 +243,11 @@ void Pcsx2App::OnInitCmdLine( wxCmdLineParser& parser )
|
|||
|
||||
parser.AddSwitch( wxEmptyString,L"profiling", _("update options to ease profiling (debug)") );
|
||||
|
||||
const PluginInfo* pi = tbl_PluginInfo; do {
|
||||
ForPlugins([&] (const PluginInfo * pi) {
|
||||
parser.AddOption( wxEmptyString, pi->GetShortname().Lower(),
|
||||
pxsFmt( _("specify the file to use as the %s plugin"), WX_STR(pi->GetShortname()) )
|
||||
);
|
||||
} while( ++pi, pi->shortname != NULL );
|
||||
});
|
||||
|
||||
parser.SetSwitchChars( L"-" );
|
||||
}
|
||||
|
@ -261,6 +261,7 @@ bool Pcsx2App::OnCmdLineError( wxCmdLineParser& parser )
|
|||
bool Pcsx2App::ParseOverrides( wxCmdLineParser& parser )
|
||||
{
|
||||
wxString dest;
|
||||
bool parsed = true;
|
||||
|
||||
if (parser.Found( L"cfgpath", &dest ) && !dest.IsEmpty())
|
||||
{
|
||||
|
@ -287,10 +288,9 @@ bool Pcsx2App::ParseOverrides( wxCmdLineParser& parser )
|
|||
if (parser.Found(L"fullscreen")) Overrides.GsWindowMode = GsWinMode_Fullscreen;
|
||||
if (parser.Found(L"windowed")) Overrides.GsWindowMode = GsWinMode_Windowed;
|
||||
|
||||
const PluginInfo* pi = tbl_PluginInfo; do
|
||||
ForPlugins([&] (const PluginInfo * pi) {
|
||||
if (parser.Found( pi->GetShortname().Lower(), &dest))
|
||||
{
|
||||
if( !parser.Found( pi->GetShortname().Lower(), &dest ) ) continue;
|
||||
|
||||
if( wxFileExists( dest ) )
|
||||
Console.Warning( pi->GetShortname() + L" override: " + dest );
|
||||
else
|
||||
|
@ -307,14 +307,14 @@ bool Pcsx2App::ParseOverrides( wxCmdLineParser& parser )
|
|||
okcan += okcan.GetCharHeight();
|
||||
okcan += okcan.Heading(AddAppName(_("Press OK to use the default configured plugin, or Cancel to close %s.")));
|
||||
|
||||
if( wxID_CANCEL == pxIssueConfirmation( okcan, MsgButtons().OKCancel() ) ) return false;
|
||||
if( wxID_CANCEL == pxIssueConfirmation( okcan, MsgButtons().OKCancel() ) ) parsed = false;
|
||||
}
|
||||
|
||||
Overrides.Filenames.Plugins[pi->id] = dest;
|
||||
if (parsed) Overrides.Filenames.Plugins[pi->id] = dest;
|
||||
}
|
||||
});
|
||||
|
||||
} while( ++pi, pi->shortname != NULL );
|
||||
|
||||
return true;
|
||||
return parsed;
|
||||
}
|
||||
|
||||
bool Pcsx2App::OnCmdLineParsed( wxCmdLineParser& parser )
|
||||
|
|
|
@ -356,8 +356,7 @@ Panels::PluginSelectorPanel::ComboBoxPanel::ComboBoxPanel( PluginSelectorPanel*
|
|||
s_plugin.SetFlexibleDirection( wxHORIZONTAL );
|
||||
s_plugin.AddGrowableCol( 1 ); // expands combo boxes to full width.
|
||||
|
||||
const PluginInfo* pi = tbl_PluginInfo; do
|
||||
{
|
||||
ForPlugins([&] (const PluginInfo * pi) {
|
||||
const PluginsEnum_t pid = pi->id;
|
||||
|
||||
m_combobox[pid] = new wxComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY );
|
||||
|
@ -368,7 +367,7 @@ Panels::PluginSelectorPanel::ComboBoxPanel::ComboBoxPanel( PluginSelectorPanel*
|
|||
s_plugin += Label( pi->GetShortname() ) | pxBorder( wxTOP | wxLEFT, 2 );
|
||||
s_plugin += m_combobox[pid] | pxExpand;
|
||||
s_plugin += m_configbutton[pid];
|
||||
} while( ++pi, pi->shortname != NULL );
|
||||
});
|
||||
|
||||
// if (InstallationMode != InstallMode_Portable)
|
||||
m_FolderPicker.SetStaticDesc( _("Click the Browse button to select a different folder for PCSX2 plugins.") );
|
||||
|
@ -396,17 +395,16 @@ void Panels::PluginSelectorPanel::DispatchEvent( const PluginEventType& evt )
|
|||
|
||||
if( IsBeingDeleted() ) return;
|
||||
|
||||
const PluginInfo* pi = tbl_PluginInfo; do
|
||||
{
|
||||
ForPlugins([&] (const PluginInfo * pi) {
|
||||
wxComboBox& box( m_ComponentBoxes->Get(pi->id) );
|
||||
int sel = box.GetSelection();
|
||||
if( sel == wxNOT_FOUND ) continue;
|
||||
|
||||
if (sel != wxNOT_FOUND) {
|
||||
m_ComponentBoxes->GetConfigButton(pi->id).Enable(
|
||||
(m_FileList==NULL || m_FileList->Count() == 0) ? false :
|
||||
g_Conf->FullpathMatchTest( pi->id,(*m_FileList)[((uptr)box.GetClientData(sel))] )
|
||||
);
|
||||
} while( ++pi, pi->shortname != NULL );
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
@ -460,8 +458,7 @@ void Panels::PluginSelectorPanel::Apply()
|
|||
|
||||
AppConfig curconf( *g_Conf );
|
||||
|
||||
const PluginInfo* pi = tbl_PluginInfo; do
|
||||
{
|
||||
ForPlugins([&] (const PluginInfo * pi) {
|
||||
const PluginsEnum_t pid = pi->id;
|
||||
int sel = m_ComponentBoxes->Get(pid).GetSelection();
|
||||
if( sel == wxNOT_FOUND )
|
||||
|
@ -474,7 +471,7 @@ void Panels::PluginSelectorPanel::Apply()
|
|||
}
|
||||
|
||||
g_Conf->BaseFilenames.Plugins[pid] = GetFilename((uptr)m_ComponentBoxes->Get(pid).GetClientData(sel));
|
||||
} while( ++pi, pi->shortname != NULL );
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Make sure folders are up to date, and try to load/reload plugins if needed...
|
||||
|
@ -484,7 +481,9 @@ void Panels::PluginSelectorPanel::Apply()
|
|||
// Need to unload the current emulation state if the user changed plugins, because
|
||||
// the whole plugin system needs to be re-loaded.
|
||||
|
||||
pi = tbl_PluginInfo; do {
|
||||
const PluginInfo* pi = tbl_PluginInfo;
|
||||
|
||||
do {
|
||||
if( g_Conf->FullpathTo( pi->id ) != curconf.FullpathTo( pi->id ) )
|
||||
break;
|
||||
} while( ++pi, pi->shortname != NULL );
|
||||
|
@ -592,8 +591,7 @@ void Panels::PluginSelectorPanel::OnPluginSelected( wxCommandEvent& evt )
|
|||
{
|
||||
if( IsBeingDeleted() || m_ComponentBoxes->IsBeingDeleted() ) return;
|
||||
|
||||
const PluginInfo* pi = tbl_PluginInfo; do
|
||||
{
|
||||
IfPlugins([&] (const PluginInfo * pi) {
|
||||
wxComboBox& box( m_ComponentBoxes->Get(pi->id) );
|
||||
if ( box.GetId() == evt.GetId() )
|
||||
{
|
||||
|
@ -605,9 +603,10 @@ void Panels::PluginSelectorPanel::OnPluginSelected( wxCommandEvent& evt )
|
|||
m_ComponentBoxes->GetConfigButton( pi->id ).Enable( isSame );
|
||||
|
||||
if( !isSame ) evt.Skip(); // enabled Apply button! :D
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
} while( ++pi, pi->shortname != NULL );
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
void Panels::PluginSelectorPanel::OnConfigure_Clicked( wxCommandEvent& evt )
|
||||
|
@ -788,8 +787,7 @@ void Panels::PluginSelectorPanel::OnProgress( wxCommandEvent& evt )
|
|||
|
||||
EnumeratedPluginInfo& result( m_EnumeratorThread->Results[evtidx] );
|
||||
|
||||
const PluginInfo* pi = tbl_PluginInfo; do
|
||||
{
|
||||
ForPlugins([&] (const PluginInfo * pi) {
|
||||
const PluginsEnum_t pid = pi->id;
|
||||
if( result.TypeMask & pi->typemask )
|
||||
{
|
||||
|
@ -807,7 +805,7 @@ void Panels::PluginSelectorPanel::OnProgress( wxCommandEvent& evt )
|
|||
}
|
||||
}
|
||||
}
|
||||
} while( ++pi, pi->shortname != NULL );
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
@ -835,8 +833,8 @@ void Panels::PluginSelectorPanel::EnumThread::DoNextPlugin( int curidx )
|
|||
PluginEnumerator penum( m_master.GetFilename( curidx ) );
|
||||
|
||||
result.Name = penum.GetName();
|
||||
const PluginInfo* pi = tbl_PluginInfo; do
|
||||
{
|
||||
|
||||
ForPlugins([&] (const PluginInfo * pi) {
|
||||
const PluginsEnum_t pid = pi->id;
|
||||
result.TypeMask |= pi->typemask;
|
||||
if( penum.CheckVersion( pid ) )
|
||||
|
@ -844,7 +842,7 @@ void Panels::PluginSelectorPanel::EnumThread::DoNextPlugin( int curidx )
|
|||
result.PassedTest |= tbl_PluginInfo[pid].typemask;
|
||||
penum.GetVersionString( result.Version[pid], pid );
|
||||
}
|
||||
} while( ++pi, pi->shortname != NULL );
|
||||
});
|
||||
}
|
||||
catch (Exception::NotEnumerablePlugin& ex)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue