Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filters update late after setting Display #65

Open
Chadnaut opened this issue Apr 12, 2024 · 3 comments
Open

Filters update late after setting Display #65

Chadnaut opened this issue Apr 12, 2024 · 3 comments
Labels
question Further information is requested

Comments

@Chadnaut
Copy link
Collaborator

Using ::fe.set_display sometimes fails to update ::fe.filters immediately.
Calling ::fe.set_display a second time fixes ::fe.filters.
Occurs on Windows 10, cannot reproduce in Ubuntu 22.04.4.

The loop is intended to scrape display filters to generate global stats.

layout.nut

local f_names = function() { local n = ""; foreach (f in ::fe.filters) n += f.name + ", "; return n; }
local nv_key = "STATS_RUNNING";
if (!(nv_key in ::fe.nv)) ::fe.nv[nv_key] <- false;
if (!::fe.nv[nv_key]) {
    local original = ::fe.list.display_index;
    local f1, f2, data = [];
    foreach (i, display in ::fe.displays) {
        ::fe.set_display(i, false, false);
        f1 = f_names();
        data.push(format("Before %d: '%s' (%d filters)    %s", ::fe.list.display_index, display.name, ::fe.filters.len(), f1));

        ::fe.set_display(i, false, false); // hack
        f2 = f_names();
        data.push(format("After  %d: '%s' (%d filters)%s %s", ::fe.list.display_index, display.name, ::fe.filters.len(), f1 != f2 ? "<--" : "   ", f2));
    }
    ::fe.set_display(original, false, false);
    ::fe.nv[nv_key] <- true;
    foreach (item in data) ::fe.log(item);
} else {
    delete ::fe.nv[nv_key];
}

last_run.log

Before 0: 'Mame' (6 filters)    All, Favourites, 2UP, MameFilter, Top, 4UP, 
After  0: 'Mame' (6 filters)    All, Favourites, 2UP, MameFilter, Top, 4UP, 
Before 1: 'C64' (6 filters)    All, Favourites, 2UP, MameFilter, Top, 4UP, 
After  1: 'C64' (5 filters)<-- All, Favourites, Extra, More, C64Filter, 
Before 2: 'MD' (4 filters)    All, Favourites, Extra, MDFilter, 
After  2: 'MD' (4 filters)    All, Favourites, Extra, MDFilter, 
Before 3: 'N64' (4 filters)    All, Favourites, Extra, MDFilter, 
After  3: 'N64' (4 filters)<-- All, Favourites, More, N64Filter, 
Before 4: 'SMS' (4 filters)    All, Favourites, More, N64Filter, 
After  4: 'SMS' (5 filters)<-- All, Favourites, More, Extra, SMSFilter, 
Before 5: 'SNES' (4 filters)    All, Favourites, Extra, SNESFilter, 
After  5: 'SNES' (4 filters)    All, Favourites, Extra, SNESFilter, 

The arrows <-- indicate where ::fe.filters has changed on the second call.

Attract-Mode Plus v3.0.8

@oomek
Copy link
Owner

oomek commented Oct 6, 2024

I think it's the time to consider adding the filters table to fe.Displays that would have size field for each filter and make it cached, so the filter's list is not regenerated on every display change unless the cfg file has changed.
Catch me up on Discord so we can discuss the details.

@oomek
Copy link
Owner

oomek commented Oct 6, 2024

I could fix the above code, but it's just a workaround for a long overdue AM shortcoming.

@oomek oomek added the question Further information is requested label Oct 6, 2024
@Chadnaut
Copy link
Collaborator Author

The loop is an edge-case, a non-standard (ab)use of AM, and is unlikely to occur "in the wild".
Not essential to fix, just keep it in mind if you ever refactor the lists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants