Skip to content

Redo asset loading, add a proper loading screen - #80

Merged
jasminegamedev merged 30 commits into
devfrom
2024_04_asset_loader_redo
Apr 26, 2024
Merged

jasminegamedev merged 30 commits into
devfrom
2024_04_asset_loader_redo

Conversation

@axiand

@axiand axiand commented Apr 13, 2024

Copy link
Copy Markdown
Member

Introduces a substantial overhaul of the way asset loading is done:

  • Split up the code into much smaller functions, trying to simplify things where relevant
  • Added a new splash screen/loading screen at the startup scene, letting the user know the status of asset loading (rather than sitting at a blank screen)
  • Mods are now loaded one by one based on a queue system rather than everything being in one place.
  • Hot reloading now only takes into account mods that have been changed, leading to a much faster experience,

Additional features:

  • Added an option to toggle hot reloading on file change
  • Users may now press F5 for a manual reload or Ctrl+F5 for a manual full reload

Things left to do:

  • Test more thoroughly.
  • Fix any bugs that come up.

axiand and others added 13 commits April 13, 2024 00:09
Mod assets are now loaded one by one instead of all at once.
Introduced more APIs for fine-grained control over asset loading.
I noticed that this PR is removing the way it was previously separating things into tasks and loading them after. I think that's fine, but since we're doing that, it actually lets us clean things up and simplify things a little more, so now instead of adding all the assets afterwards, we're able to just do it in place while loading the assets. I also removed the LoadDirectoryRecursive function, because it didn't really feel needed after simplifying. I did have to change the order a little to accommodate this, because it means shaders must be loaded before models.
I also moved the modFs null check to the beginning, since every asset type was checking that, so it's simpler to just do that first.
I also noticed a bug where because of these changes, every mod was adding the vanilla skin. I reworked this, so the vanilla skin is now just set up when we create the vanilla mod.
I also fixed a minor bug, where I think we need to call `Language.Current.Use();` after all mods are loaded, in case any new characters are used that need to be registered.
I also changed it to show the mod name during asset load, instead of the Id. Since this is something that's displayed to the player, I think using the mod name is cleaner here.
Aside from that, I also made a few minor formatting and naming tweaks.
@axiand axiand added this to the 0.7.0 blockers milestone Apr 18, 2024
axiand and others added 5 commits April 25, 2024 19:26
The main optimization here is that we only reload assets for the mod whose assets have been changed. This saves us plenty of time that we spent waiting for unnecessary asset reloads before.
…a setting is changed.

Previously if a mod was enabled or disabled, or if a mod setting was changed that was marked as needing reload, it would always reload all mods. But because of these recent changes, we can change that to only reload mods that were actually touched, which should make that reload happen faster.
I also changed it so disabled mods don't trigger a hot reload if a file is changed, since that file isn't going to be loaded anyways.
And I also added some code to clear out hooks on reload as well.
…eload single mods

Mod dependencies should now be reloaded as well when a mod is changed through hot reloading or through the settings. It also should get handled better when a mod is enabled or disabled and the dependents and dependencies get disabled/enabled as well.
It should load the dependencies similarly to how it does during initial load, so dependencies should get loaded before the mods that depend on them.
I also updated it so enabling and disabling mods should recursively affect dependencies and dependents. Previously, it only went 1 level up or down.

@jasminegamedev jasminegamedev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think I am pretty satisfied with where this is at right now. I've just got one small comment, and if we can get that addressed, then this can probably be merged.

Comment thread Source/Game.cs Outdated
public World? World => Scene as World;

internal bool NeedsReload = false;
internal bool doUpdate = true;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this actually needed for anything? It seems to not be doing anything currently, since it's always true

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's a leftover from an implementation I was working on and subsequently scrapped. It can be safely removed

@axiand

axiand commented Apr 26, 2024

Copy link
Copy Markdown
Member Author

Resolved merge conflicts

Comment thread Source/Game.cs

Log.Info($"--- User has initiated a{(Input.Keyboard.CtrlOrCommand ? " full" : String.Empty)} manual reload. ---");
ReloadAssets(Input.Keyboard.CtrlOrCommand); // F5 - Reload changed; Ctrl + F5 - Reload all
}

@jasminegamedev jasminegamedev Apr 26, 2024

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We actually kind of already have a hotkey for reloading assets, where if you press Ctrl+R it will also call the ReloadAssets function. This actually comes from the base game.
It's a little bit different, because it doesn't let you filter to changed vs all like this, but we probably don't need two different hotkeys for this, since they're kind of doing the same thing.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'd be fine with replacing vanilla's ctrl+r with this implementation.

Comment thread Source/Game.cs
@jasminegamedev

Copy link
Copy Markdown
Collaborator

I think this seems good to me. It is a little bit of a critical area, so we should definitely keep an eye if people run into any asset loading bugs that come out of this, but this is probably good for now.
Merging!

@jasminegamedev
jasminegamedev merged commit 4400967 into dev Apr 26, 2024
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.

2 participants