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

feat: add system params for iterating over asset packs #482

Merged
merged 3 commits into from
Oct 11, 2024

Conversation

nelson137
Copy link
Contributor

Closes #272

Changes

  • Add system param Packs -- an iterator over asset pack roots
  • Add system param AllPacksData -- a flattened, chained iterator over listwise data from core and supplementary asset packs
    • AllPacksData::iter_with takes 2 args: (1) a closure that takes a ref to the core meta and returns an iterator, (2) a closure takes a ref to a (supplementary) pack meta and returns an iterator

Application

AllPacksData will be most the most useful of the 2 in Jumpy. There are a few locations where we iterate over
a list from the core meta and do something, then we iterate over the packs and for each one iterate over a list. Since AllPacksData is a flattened, chained iterator of all of those sub-iterators, we can turn this:

fn maps_sys(asset_server: Res<AssetServer>, game: Root<GameMeta>) {
    for handle in game.core.stable_maps.iter().copied() {
        let map_meta = asset_server.get(handle);
        /* do stuff... */
    }

    for pack in asset_server.packs() {
        let pack_meta = asset_server.get(pack.root.typed::<PackMeta>());
        for handle in pack_meta.maps.iter().copied() {
            let map_meta = asset_server.get(handle);
            /* do stuff... */
        }
    }
}

Into this:

fn maps_sys(asset_server: Res<AssetServer>, all_packs: AllPacksData<GameMeta, PackMeta>) {
    for handle in all_packs.iter_with(
    	|game| game.core.stable_maps.iter().copied(),
    	|pack| pack.maps.iter().copied(),
    ) {
        let map_meta = asset_server.get(handle);
        /* do stuff... */
    }
}

Copy link
Collaborator

@MaxCWhitehead MaxCWhitehead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this definitely is an improvement, thanks!

@MaxCWhitehead MaxCWhitehead added this pull request to the merge queue Oct 11, 2024
Merged via the queue into fishfolk:main with commit 560c259 Oct 11, 2024
10 checks passed
@nelson137 nelson137 deleted the feat/packs-root-iter branch October 11, 2024 04:41
MaxCWhitehead added a commit that referenced this pull request Oct 13, 2024
The new system param integration tests added in #482 [fail in
miri](https://github.com/fishfolk/bones/actions/runs/11285906933/job/31389426144)
due to features unavailable in isolation mode. Disable those tests since
there isn't a good way to fix this.

---------

Co-authored-by: Max Whitehead <max.blackllama.alt3@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create Convenient Way to Iterate Over Casted Asset Packs
2 participants