Skip to content

Commit

Permalink
Async Loader WIP
Browse files Browse the repository at this point in the history
- Consolidate functions update(), on_end_navigation(), update_to_new_list() into a single function update_to()
  • Loading branch information
oomek committed Apr 10, 2024
1 parent 723cb64 commit 16107b1
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 57 deletions.
6 changes: 4 additions & 2 deletions src/fe_overlay.cpp
Expand Up @@ -562,7 +562,8 @@ int FeOverlay::tags_dialog()
{
if ( m_feSettings.set_current_tag( name, true ) )
{
m_fePresent.update_to_new_list( 0, true ); // changing tag status altered our current list
m_fePresent.update_to( ToNewList, true ); // changing tag status altered our current list
m_fePresent.on_transition( ToNewList, 0 );
m_fePresent.on_transition( ChangedTag, FeRomInfo::Tags );
}
}
Expand All @@ -571,7 +572,8 @@ int FeOverlay::tags_dialog()
{
if ( m_feSettings.set_current_tag( tags_list[sel].first, !(tags_list[sel].second) ) )
{
m_fePresent.update_to_new_list( 0, true ); // changing tag status altered our current list
m_fePresent.update_to( ToNewList, true ); // changing tag status altered our current list
m_fePresent.on_transition( ToNewList, 0 );
m_fePresent.on_transition( ChangedTag, FeRomInfo::Tags );
}
}
Expand Down
94 changes: 47 additions & 47 deletions src/fe_present.cpp
Expand Up @@ -878,7 +878,10 @@ void FePresent::set_filter_index( int idx )
if ( m_feSettings->navigate_filter( new_offset ) )
load_layout();
else
update_to_new_list( new_offset );
{
update_to( ToNewList, false );
on_transition( ToNewList, new_offset );
}
}
}

Expand Down Expand Up @@ -942,12 +945,15 @@ void FePresent::change_selection( int step, bool end_navigation )
on_transition( ToNewSelection, step );

m_feSettings->step_current_selection( step );
update( false );
update_to( ToNewSelection, false );

on_transition( FromOldSelection, -step );

if ( end_navigation )
on_end_navigation();
{
update_to( EndNavigation, false );
on_transition( EndNavigation, 0 );
}
}

bool FePresent::reset_screen_saver()
Expand Down Expand Up @@ -1021,7 +1027,10 @@ bool FePresent::handle_event( FeInputMap::Command c )
if ( m_feSettings->navigate_display( ( c == FeInputMap::NextDisplay ) ? 1 : -1 ) )
load_layout();
else
update_to_new_list( 0, true );
{
update_to( ToNewList, true );
on_transition( ToNewList, 0 );
}

break;

Expand All @@ -1032,7 +1041,10 @@ bool FePresent::handle_event( FeInputMap::Command c )
if ( m_feSettings->navigate_filter( offset ) )
load_layout();
else
update_to_new_list( offset );
{
update_to( ToNewList, false );
on_transition( ToNewList, offset );
}
}
break;

Expand Down Expand Up @@ -1093,44 +1105,37 @@ bool FePresent::handle_event( FeInputMap::Command c )
return true;
}

int FePresent::update( bool new_list, bool new_display )
void FePresent::update_to( FeTransitionType type, bool reset_display )
{
std::vector<FeBaseTextureContainer *>::iterator itc;
std::vector<FeBasePresentable *>::iterator itl;
std::vector<FeMonitor>::iterator itm;

if ( new_list )
switch ( type )
{
for ( itc=m_texturePool.begin(); itc != m_texturePool.end(); ++itc )
(*itc)->on_new_list( m_feSettings, new_display );

for ( itm=m_mon.begin(); itm != m_mon.end(); ++itm )
{
for ( itl=(*itm).elements.begin(); itl != (*itm).elements.end(); ++itl )
(*itl)->on_new_list( m_feSettings );
}
}

for ( itc=m_texturePool.begin(); itc != m_texturePool.end(); ++itc )
(*itc)->on_new_selection( m_feSettings );
case ToNewList:
for ( itc = m_texturePool.begin(); itc != m_texturePool.end(); ++itc )
(*itc)->on_new_list( m_feSettings, reset_display );

for ( itm = m_mon.begin(); itm != m_mon.end(); ++itm )
for ( itl = (*itm).elements.begin(); itl != (*itm).elements.end(); ++itl )
(*itl)->on_new_list( m_feSettings );
// Fallthrough intended

case ToNewSelection:
for ( itc = m_texturePool.begin(); itc != m_texturePool.end(); ++itc )
(*itc)->on_new_selection( m_feSettings );

for ( itm = m_mon.begin(); itm != m_mon.end(); ++itm )
for ( itl = (*itm).elements.begin(); itl != (*itm).elements.end(); ++itl )
(*itl)->on_new_selection( m_feSettings );
break;

for ( itm=m_mon.begin(); itm != m_mon.end(); ++itm )
{
for ( itl=(*itm).elements.begin(); itl != (*itm).elements.end(); ++itl )
(*itl)->on_new_selection( m_feSettings );
case EndNavigation:
for ( itc = m_texturePool.begin(); itc != m_texturePool.end(); ++itc )
(*itc)->on_end_navigation( m_feSettings );
break;
}

return 0;
}

void FePresent::on_end_navigation()
{
std::vector<FeBaseTextureContainer *>::iterator itc;

for ( itc=m_texturePool.begin(); itc != m_texturePool.end(); ++itc )
(*itc)->on_end_navigation( m_feSettings );

on_transition( EndNavigation, 0 );
}

void FePresent::redraw_surfaces()
Expand All @@ -1153,8 +1158,7 @@ bool FePresent::load_intro()
if ( !on_new_layout() )
return false;

// Don't do the StartLayout signal for the intro
update( true, true );
update_to( ToNewList, true );
return ( !m_mon[0].elements.empty() );
}

Expand All @@ -1175,7 +1179,7 @@ void FePresent::load_screensaver()
// if there is no screen saver script then do a blank screen
//
on_transition( StartLayout, FromToNoValue );
update( true, true );
update_to( ToNewList, true );
}

void FePresent::load_layout( bool initial_load )
Expand Down Expand Up @@ -1223,13 +1227,8 @@ void FePresent::load_layout( bool initial_load )
}

on_transition( StartLayout, var );
update_to_new_list( FromToNoValue, true );
}

void FePresent::update_to_new_list( int var, bool reset_display )
{
update( true, reset_display );
on_transition( ToNewList, var );
update_to( ToNewList, true );
on_transition( ToNewList, FromToNoValue );
}

// Only called when Configure Menu is up
Expand Down Expand Up @@ -1385,7 +1384,7 @@ void FePresent::post_run()
#endif

reset_screen_saver();
update( true );
update_to( ToNewList, false );
}

void FePresent::toggle_movie()
Expand Down Expand Up @@ -1588,7 +1587,8 @@ FeShader *FePresent::get_empty_shader()
void FePresent::set_search_rule( const char *s )
{
m_feSettings->set_search_rule( s );
update_to_new_list( 0, true );
update_to( ToNewList, true );
on_transition( ToNewList, 0 );
}

const char *FePresent::get_search_rule()
Expand Down
4 changes: 1 addition & 3 deletions src/fe_present.hpp
Expand Up @@ -167,7 +167,6 @@ class FePresent
void toggle_rotate( FeSettings::RotationState ); // toggle between none and provided state
FeSettings::RotationState get_actual_rotation();
void set_transforms();
int update( bool reload_list=false, bool new_layout=false );

// Overrides from base classes:
//
Expand Down Expand Up @@ -225,8 +224,7 @@ class FePresent
void set_layout_loaded( bool loaded ) { m_layout_loaded = loaded; };
bool is_layout_loaded() { return m_layout_loaded; };

virtual void update_to_new_list( int var=0, bool reset_display=false );
void on_end_navigation();
void update_to( FeTransitionType type, bool reset_display=false );
void redraw_surfaces();

bool tick(); // run vm on_tick and update videos. return true if redraw required
Expand Down
5 changes: 3 additions & 2 deletions src/fe_vm.cpp
Expand Up @@ -473,7 +473,8 @@ void FeVM::update_to_new_list( int var, bool reset_display )
}
}

FePresent::update_to_new_list( var, reset_display );
FePresent::update_to( ToNewList, reset_display );
on_transition( ToNewList, var );
}

namespace
Expand Down Expand Up @@ -1309,7 +1310,7 @@ void FeVM::on_transition(
{
using namespace Sqrat;

FeDebug() << "[Transition] type=" << transitionTypeStrings[t] << ", var=" << var << std::endl;
FeLog() << "[Transition] type=" << transitionTypeStrings[t] << ", var=" << var << std::endl;

sf::Clock clk;
int ttime = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/fe_vm.hpp
Expand Up @@ -121,7 +121,7 @@ class FeVM : public FePresent
bool poll_command( FeInputMap::Command &c, sf::Event &ev, bool &from_ui );
void clear(); // override of base class clear()

void update_to_new_list( int var=0, bool reset_display=false ) override;
void update_to_new_list( int var=0, bool reset_display=false );

// runs .attract/emulators/template/setup.nut to generate default emulator
// configs and detect emulators. Prompts user to automaticallly import emulators
Expand Down
3 changes: 2 additions & 1 deletion src/fe_window.cpp
Expand Up @@ -592,7 +592,8 @@ bool FeWindow::run()
if ( m_fes.update_stats( 1, timer.getElapsedTime().asSeconds() ) )
{
FePresent *fep = FePresent::script_get_fep();
fep->update_to_new_list();
fep->update_to( ToNewList, false );
fep->on_transition( ToNewList, 0 );
}

#if defined(SFML_SYSTEM_LINUX)
Expand Down
5 changes: 4 additions & 1 deletion src/main.cpp
Expand Up @@ -1033,7 +1033,10 @@ int main(int argc, char *argv[])
// "End Navigation" stuff now
//
if ( move_triggered != FeInputMap::LAST_COMMAND )
feVM.on_end_navigation();
{
feVM.update_to( EndNavigation, false );
feVM.on_transition( EndNavigation, 0 );
}

move_state = FeInputMap::LAST_COMMAND;
move_triggered = FeInputMap::LAST_COMMAND;
Expand Down

0 comments on commit 16107b1

Please sign in to comment.