EventSceneLoadPlus
EventSceneLoadPlus is a modified version of MacGruber's EventSceneLoad LogicBrick that adds a second trigger for image/texture loading completion.
VaM's normal scene-loaded event can fire well before all of a scene's images have finished loading. In texture-heavy scenes, this can leave actions tied to OnSceneLoad running while VaM is still processing the image queue.
This can give scene creators the ability to more accurately time actions like animations or screen fade-ins to when the scene is actually finished loading, rather than triggering them prematurely while several gigs worth of textures are still loading in the queue.
EventSceneLoadPlus provides two independent triggers:
OnSceneLoad
Behaves identically to MacGruber's original EventSceneLoad trigger and fires when VaM reports that the scene has finished loading. (The first trigger in the plugin)
OnTexturesLoad
Fires after the images already queued at scene-load completion have finished processing. (The second trigger in the plugin)
This makes it useful for scene initialization that shouldn't happen until textures are actually ready, without relying on an arbitrary fixed delay.
How it works
When VaM reports that the scene has loaded, EventSceneLoadPlus adds a small sentinel request to the end of VaM's existing image-loading queue. When that sentinel is reached, everything that was ahead of it in the queue has finished processing, and a callback is fired, triggering the OnTexturesLoad actions.
If there are no outstanding images, the second trigger fires almost immediately after OnSceneLoad. If texture loading continues for another 15 seconds, it waits for those 15 seconds.
Usage
Add EventSceneLoadPlus to an atom and configure either or both Actions OnTrigger sections just like other MacGruber LogicBricks.
Use the first section for actions that should occur at normal scene-load completion. Use the second for actions that need to wait for texture loading to finish.
Current limitation
OnTexturesLoad detects completion of image requests already queued when the sentinel is added on OnSceneLoad. A plugin that responds to scene loading by subsequently adding more images to the queue could therefore load images after OnTexturesLoad has fired.
I have not yet encountered this in normal scene use, but it's worth keeping in mind when combining the plugin with other load-time systems.
Attribution
This plugin is wholly dependent on @MacGruber's original work on his LogicBricks plugin suite. It would have taken me a lot longer to get this working properly without the foundation he already built.
His Utils.cs is included unedited, as it is required by the original logic of the EventSceneLoad plugin.
The original logic, lifecycle management, and edge-case handling from EventSceneLoad also remain unchanged, aside from renaming a few methods and variables to make the addition of a second trigger more manageable and robust.
My contribution primarily adds the second image-load trigger and the sentinel mechanism used to determine when VaM's queued image loading has completed.
The key idea of adding a dummy image to the end of the queue and using its callback was suggested to me by @meshedvr.
Thanks for the massive foundation you laid down so many years ago, @MacGruber! VaM wouldn't be what it is today without your contributions.