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

GWT possibility to lazy load assets #5677

Merged
merged 7 commits into from Aug 29, 2020

Conversation

MrStahlfelge
Copy link
Member

@MrStahlfelge MrStahlfelge commented Jun 19, 2019

Based on the idea of #4265, I implemented a solution to skip the GWT preloader if it is not needed.

The preloader prefetches all assets before the game is started. That's useful for all assets that are accessed directly from the render thread and can't get fetched asynchronously, but assets that are loaded via AssetManager don't need to be preloaded.

This PR extends the AssetFilter with a new method that can be overriden to filter assets that don't need to be preloaded, and changes the Preloader to respect this setting and the AssetManager (via AssetLoadingTask) to download the asset if not already done.

To test this, specify an own AssetFilter in your game (as described here) and override the preload() method. Only return false for assets that are only loaded via AssetManager and not with AssetManager.finishLoading[Asset]. :)

Runnable demo game: Lazy loading version - open the developer network tab, you'll see that the game load its assets on level start.

For those wanting to try or to use this in existing games: you can find Jitpack dependencies to use with libGDX 1.9.8 (working with 1.9.9, too), 1.9.10 and 1.9.11 here.

# Conflicts:
#	backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/preloader/Preloader.java
#	backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/preloader/PreloaderBundleGenerator.java
Copy link
Member

@tommyettinger tommyettinger left a comment

Choose a reason for hiding this comment

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

Like the WebAudio PR, this has been tested for years and is known to work. I'm not sure if I could just merge this now? Should I hold off until there are more reviews?

I should mention that I don't currently use an AssetManager, so my review can't really cover any technical details.

@MrStahlfelge
Copy link
Member Author

We don't need to wait for other reviews, but I need to update CHANGES, make a comment on the main Asset manager to note that there is an emu (and compare them for changes) and will transfer the information from the first comment to the wiki. So it's good you waited. :-)

Copy link
Contributor

@raeleus raeleus left a comment

Choose a reason for hiding this comment

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

I didn't notice any issues testing this locally or with a project uploaded to Itch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement gwt non-breaking Label for non-breaking PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants