Skip to content

Commit

Permalink
Async Loader WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
oomek committed Feb 23, 2024
1 parent a5785e7 commit b2b8716
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 12 deletions.
63 changes: 52 additions & 11 deletions src/fe_settings.cpp
Expand Up @@ -264,7 +264,6 @@ FeSettings::FeSettings( const std::string &config_path )
m_current_layout_params( FeLayoutInfo::Layout ),
m_display_menu_per_display_params( FeLayoutInfo::Menu ),
m_current_display( -1 ),
m_selected_display( 0 ),
m_current_config_object( NULL ),
m_ssaver_time( 600 ),
m_last_launch_display( 0 ),
Expand All @@ -275,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 @@ -343,6 +343,7 @@ void FeSettings::clear()

void FeSettings::load()
{
FeLog() << "\nload()" << std::endl;
clear();

std::string load_language( "en" );
Expand Down Expand Up @@ -389,7 +390,8 @@ void FeSettings::load()
load_state();

// TODO: check if it can be moved outside load()
m_selected_display = m_current_display;
FeLog() << " m_current_display_index = m_current_display " << m_current_display_index << " = " << m_current_display << std::endl;
m_current_display_index = m_current_display;
if ( get_startup_mode() == ShowDisplaysMenu )
m_current_display = -1;

Expand Down Expand Up @@ -585,6 +587,7 @@ int FeSettings::process_setting( const std::string &setting,

void FeSettings::init_display()
{
FeLog() << "\ninit_display()" << std::endl;
m_loaded_game_extras = false;

//
Expand Down Expand Up @@ -629,7 +632,8 @@ void FeSettings::init_display()
set_search_rule( "" );
m_current_search_index = temp_idx;

m_current_search_index = m_selected_display;
FeLog() << " m_current_search_index = m_current_display_index " << m_current_search_index << " = " << m_current_display_index << std::endl;
m_current_search_index = m_current_display_index; // This needs to be here

// Setup m_current_layout_params with all the parameters for our current layout, including
// the 'per_display' layout parameters that are stored separately but that get merged in here
Expand Down Expand Up @@ -721,7 +725,10 @@ void FeSettings::save_state()
display_idx = m_display_stack.front();

if ( display_idx < 0 )
{
FeLog() << " display_idx = m_current_search_index " << display_idx << " = " << m_current_search_index << std::endl;
display_idx = m_current_search_index;
}

m_rl.save_state();

Expand Down Expand Up @@ -952,15 +959,20 @@ int FeSettings::get_filter_size( int filter_index ) const

int FeSettings::get_rom_index( int filter_index, int offset ) const
{
FeLog() << "\nget_rom_index()" << std::endl;
int retval, rl_size;
if ( m_current_display < 0 )
{
retval = m_current_search_index;
// FeLog() << " retval = m_current_search_index " << retval << " = " << m_current_search_index << std::endl;
// retval = m_current_search_index; //dupa
FeLog() << " retval = m_current_display_index " << retval << " = " << m_current_display_index << std::endl;
retval = m_current_display_index;
rl_size = m_rl.filter_size( filter_index );
}
else if ( !m_current_search.empty()
&& ( get_current_filter_index() == filter_index ))
{
FeLog() << " retval = m_current_search_index " << retval << " = " << m_current_search_index << std::endl;
retval = m_current_search_index;
rl_size = m_current_search.size();
}
Expand Down Expand Up @@ -1027,6 +1039,7 @@ void FeSettings::set_search_rule( const std::string &rule_str )

bool FeSettings::switch_to_clone_group( int idx )
{
FeLog() << "\nswitch_to_clone_group()" << std::endl;
// check if we aren't grouping clones of if we are already showing
// the clone list (in which case we return false)
if (( !m_group_clones ) || ( m_clone_index >= 0 ))
Expand Down Expand Up @@ -1064,19 +1077,24 @@ bool FeSettings::switch_to_clone_group( int idx )

if ( idx >= 0 )
{
FeLog() << " m_current_search_index = idx " << m_current_search_index << " = " << idx << std::endl;
// if a specific idx value was provided, select that index
m_current_search_index = idx;
}
else
{
FeLog() << " m_current_search_index = 0 " << m_current_search_index << " = " << "0" << std::endl;
// if no idx was provided, default select the entry with the same
// title as the clone group
m_current_search_index=0;

for ( int i=0; i < group.size(); i++ )
{
if ( t.compare( group[i]->get_info( FeRomInfo::Title ) ) == 0 )
{
FeLog() << " m_current_search_index = i " << m_current_search_index << " = " << i << std::endl;
m_current_search_index = i;
}
}
}

Expand Down Expand Up @@ -1442,6 +1460,7 @@ int FeSettings::display_menu_get_current_selection_as_absolute_display_index()
{
ASSERT( m_current_display < 0 );

FeLog() << "display_menu_get_current_selection_as_absolute_display_index() m_current_search_index = " << m_current_search_index << std::endl;
if (( m_current_search_index < 0 ) || ( m_current_search_index >= (int)m_display_menu.size() ))
return -1;

Expand All @@ -1450,6 +1469,7 @@ int FeSettings::display_menu_get_current_selection_as_absolute_display_index()

bool FeSettings::set_display( int index, bool stack_previous )
{
FeLog() << "\nset_display()" << std::endl;
std::string old_path, old_file;

get_path( Layout, old_path, old_file );
Expand All @@ -1465,33 +1485,47 @@ bool FeSettings::set_display( int index, bool stack_previous )
m_display_stack.pop_back();
}
else
index = m_selected_display;
{
FeLog() << " index = m_current_display_index " << index << " = " << m_current_display_index << std::endl;
index = m_current_display_index;
}
}
else if (( m_current_display != index ) && ( m_current_display >= 0 ))
{
m_selected_display = m_current_display;
FeLog() << " m_current_display_index = m_current_display " << m_current_display_index << " = " << m_current_display << std::endl;
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 );
{
// FeLog() << " m_current_search_index = find(m_current_display) " << m_current_search_index << " = " << m_current_display << std::endl;
// m_current_search_index = find_idx_in_vec( m_current_display, m_display_menu ); //dupa
FeLog() << " m_current_display_index = find(m_current_display) " << m_current_display_index << " = " << m_current_display << std::endl;
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();
}

FeLog() << " m_current_display = index " << m_current_display << " = " << index << std::endl;
m_current_display = index;

m_rl.save_state();
init_display();

// FeLog() << " m_current_display_index = index " << m_current_display_index << " = " << index << std::endl;
// m_current_display_index = index; // TODO: this was the fix, investigate if m_current_display_index is necessary

std::string new_path, new_file;
get_path( Layout, new_path, new_file );

m_selected_display = index; // TODO: this was the fix, investigate if m_selected_display is necessary
// FeLog() << "3 ***** " << m_current_display_index << " " << m_current_display << std::endl;
// m_current_display_index = index; // TODO: this was the fix, investigate if m_current_display_index is necessary
//
// returning true triggers a full reload of the layout. We do this only if the
// layout file has changed or if the layout parameters have changed (which can happen
Expand Down Expand Up @@ -1584,10 +1618,17 @@ 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 ) //dupa, separated and seems to work
{
// FeLog() << " m_current_search_index = rom_index " << m_current_search_index << " = " << rom_index << std::endl;
// m_current_search_index = rom_index; //dupa
FeLog() << " m_current_display_index = rom_index " << m_current_display_index << " = " << rom_index << std::endl;
m_current_display_index = rom_index;

}
else if (( !m_current_search.empty() && ( get_current_filter_index() == filter_index )))
{
FeLog() << " m_current_search_index = rom_index " << m_current_search_index << " = " << rom_index << std::endl;
m_current_search_index = rom_index;
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/fe_settings.hpp
Expand Up @@ -206,7 +206,6 @@ class FeSettings : public FeBaseConfigurable
sf::IntRect m_mousecap_rect;

int m_current_display; // -1 if we are currently showing the 'displays menu' w/ custom layout
int m_selected_display; // display selected on displays list
FeBaseConfigurable *m_current_config_object;
int m_ssaver_time;
int m_last_launch_display;
Expand All @@ -217,6 +216,7 @@ class FeSettings : public FeBaseConfigurable
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_display_index;
bool m_displays_menu_exit;
bool m_hide_brackets;
bool m_group_clones;
Expand Down

0 comments on commit b2b8716

Please sign in to comment.