Skip to content

Commit

Permalink
Async Loader WIP
Browse files Browse the repository at this point in the history
- Decouple m_current_display and m_current_search_index
- Add m_current_display_index instead
- Move ShowDisplaysMenu handling from main.cpp to fe_settings.cpp
  • Loading branch information
oomek committed Apr 10, 2024
1 parent 7d1b886 commit 723cb64
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/fe_present.cpp
Expand Up @@ -1232,7 +1232,7 @@ void FePresent::update_to_new_list( int var, bool reset_display )
on_transition( ToNewList, var );
}

// Only called wnen menu is up
// Only called when Configure Menu is up
bool FePresent::tick()
{
bool ret_val = false;
Expand Down
29 changes: 20 additions & 9 deletions src/fe_settings.cpp
Expand Up @@ -274,6 +274,7 @@ FeSettings::FeSettings( const std::string &config_path )
m_joy_thresh( 75 ),
m_mouse_thresh( 10 ),
m_current_search_index( 0 ),
m_current_display_index( 0 ),
m_displays_menu_exit( true ),
m_hide_brackets( false ),
m_group_clones( false ),
Expand Down Expand Up @@ -386,6 +387,11 @@ void FeSettings::load()
FeRomListSorter::init_title_rex( rex_str );

load_state();

m_current_display_index = m_current_display;
if ( get_startup_mode() == ShowDisplaysMenu )
m_current_display = -1;

init_display();

// Make sure we have some keyboard mappings
Expand Down Expand Up @@ -712,7 +718,7 @@ void FeSettings::save_state()
display_idx = m_display_stack.front();

if ( display_idx < 0 )
display_idx = m_current_search_index;
display_idx = m_current_display_index;

m_rl.save_state();

Expand Down Expand Up @@ -946,7 +952,7 @@ int FeSettings::get_rom_index( int filter_index, int offset ) const
int retval, rl_size;
if ( m_current_display < 0 )
{
retval = m_current_search_index;
retval = m_current_display_index;
rl_size = m_rl.filter_size( filter_index );
}
else if ( !m_current_search.empty()
Expand Down Expand Up @@ -1433,10 +1439,10 @@ int FeSettings::display_menu_get_current_selection_as_absolute_display_index()
{
ASSERT( m_current_display < 0 );

if (( m_current_search_index < 0 ) || ( m_current_search_index >= (int)m_display_menu.size() ))
if (( m_current_display_index < 0 ) || ( m_current_display_index >= (int)m_display_menu.size() ))
return -1;

return m_display_menu[ m_current_search_index ];
return m_display_menu[ m_current_display_index ];
}

bool FeSettings::set_display( int index, bool stack_previous )
Expand All @@ -1456,16 +1462,19 @@ bool FeSettings::set_display( int index, bool stack_previous )
m_display_stack.pop_back();
}
else
index = m_current_display;
index = m_current_display_index;
}
else if (( m_current_display != index ) && ( m_current_display >= 0 ))
{
m_current_display_index = m_current_display;
m_display_stack.push_back( m_current_display );
}

}
else
{
if ( index < 0 )
m_current_search_index = find_idx_in_vec( m_current_display, m_display_menu );
m_current_display_index = find_idx_in_vec( m_current_display, m_display_menu );

// If not stacking, clear the existing back stack (if any)
m_display_stack.clear();
Expand Down Expand Up @@ -1571,9 +1580,11 @@ void FeSettings::set_current_selection( int filter_index, int rom_index )
{
// handle situation where we are currently showing a search result or clone group
//
if (( m_current_display < 0 )
|| ( !m_current_search.empty()
&& ( get_current_filter_index() == filter_index )))
if ( m_current_display < 0 )
{
m_current_display_index = rom_index;
}
else if (( !m_current_search.empty() && ( get_current_filter_index() == filter_index )))
{
m_current_search_index = rom_index;
}
Expand Down
4 changes: 3 additions & 1 deletion src/fe_settings.hpp
Expand Up @@ -215,7 +215,8 @@ class FeSettings : public FeBaseConfigurable
int m_clone_index; // >= 0 if a clone group is being shown, otherwise -1
int m_joy_thresh; // [1..100], 100=least sensitive
int m_mouse_thresh; // [1..100], 100=least sensitive
int m_current_search_index; // used when custom searching *AND* when showing 'Displays Menu' w/ custom layout
int m_current_search_index; // used when custom searching
int m_current_display_index; // used as an index of currently selected display in displays menu
bool m_displays_menu_exit;
bool m_hide_brackets;
bool m_group_clones;
Expand Down Expand Up @@ -582,6 +583,7 @@ class FeSettings : public FeBaseConfigurable
std::vector<int> &indices,
int &current_idx ) const;

// Used only when Edit Game is pressed in Displays Menu
int display_menu_get_current_selection_as_absolute_display_index();

FeDisplayInfo *get_display( int index );
Expand Down
18 changes: 2 additions & 16 deletions src/main.cpp
Expand Up @@ -198,8 +198,6 @@ int main(int argc, char *argv[])
break;

case FeSettings::ShowDisplaysMenu:
feSettings.set_display(-1);
FeVM::cb_signal( "displays_menu" );
break;

default:
Expand Down Expand Up @@ -549,24 +547,12 @@ int main(int argc, char *argv[])
move_triggered = FeInputMap::LAST_COMMAND;
move_last_triggered = 0;

feVM.load_layout( true );

switch ( feSettings.get_startup_mode() )
if ( feSettings.get_startup_mode() == FeSettings::LaunchLastGame )
{
case FeSettings::LaunchLastGame:
feVM.load_layout( true );
feSettings.select_last_launch();
launch_game=true;
break;

case FeSettings::ShowDisplaysMenu:
if ( feSettings.get_current_display_index() != -1 )
feSettings.set_display(-1);
feVM.load_layout( true );
break;

default:
feVM.load_layout( true );
break;
}

redraw=true;
Expand Down

0 comments on commit 723cb64

Please sign in to comment.