collinsmith / riiablo

Diablo II remade using Java and LibGDX
http://riiablo.com
Apache License 2.0
884 stars 101 forks source link

DT1 resource asset streaming #13

Closed collinsmith closed 4 years ago

collinsmith commented 5 years ago

All DT1s for a given act are currently loaded before the Map instance is even built (Map dependencies need to be declared before MapLoader is called, and since MapLoader builds the Map instance, we don't know what those are until after it's called). I think this approach is a bit too intensive for mobile, since at least on my device, loading takes ~12-15 seconds (I'm only using a subset of an act's DT1s to avoid this issue right now to get me ~6-7 seconds load time). I would like to look into the possibility of streaming these assets more efficiently or add hidden loading screens (fade in from black) to hide the loading. I think it's plausible to make the loading screen the bare minimum assets, e.g., the subset of DT1s that belong in the current level type (i.e., if you switch to a different act waypoint, load that level type DT1s first over the town's), but when building the Map instance, the required DT1s must be loaded into memory since they contain stuff like walkable tile flags.

I'd also like to note that the current loading method would likely benefit largely by #8 and even #7 since each area's main DT1 is about 2 MB.

collinsmith commented 4 years ago

I rewrote Map and optimized it a bit and decoupled it from MapLoader. This means that hopefully the same Map instance can remain in memory the entire game and just add/remove zones as necessary. It still only works for act 1 and loads all zones together, but it loads significantly faster now that I can delay loading until I know what I actually want to load instead of loading everything.

The finish loading and generations step will need to change if zones are to be streamed properly, but the groundwork is laid. In the meantime, it may be acceptable for performance to load all map zones whenever the act is changed (changing the act at runtime isn't supported yet -- does not load new assets itself, this is done through the GameLoadingScreen, so a new instance should be generated or reused to display while loading). I can't say how much of a change for the engine changing acts will require -- accommodations for server instances must be accounted for, i.e., entities should persist if leaving an act and returning and obviously entities should remain within their act.

collinsmith commented 4 years ago

Integration of above changes went well, and steaming should work alright. I'm going to close this for now.