MZ Best practice for image-intensive custom scenes?

So one of the ongoing commissions I have at the moment is a menu overhaul for a game, and it involves a lot of visual elements for window backgrounds, face frames made up of several separate images, several possible images that represent different command selection states etc.

The way I did it initially was that for anything where it was created as a new sprite, I just set the bitmap directly because that handles the loading automatically and there's no issue with displaying it. But for doing a block transfer from a source to a destination bitmap, it needs to be preloaded otherwise it won't show up the first time the scene is accessed. For those, I added load listeners to the bitmaps to ensure that processing only continued when they finished loading.

I'm working on refactoring finished menu plugins at the moment, and as part of that one idea I've had is to add an image loading function that iterates through all the image filenames needed for the menu in its start function and adds a load listener where it loads the next one.

However, the client has asked that I go with "the standard way" of doing this. So for those with experience or knowledge of custom scenes that use a lot of images, how do you handle loading them?
I am not sure if i understand the question correctly, and i am not using mz ..(but JS related that should not make a big difference to mv i guess)
-also i am pretty sure your JS knowlegde is higher than mine^^

But perhaps thats helpfull cos its related to add imgs to windows: (to any window you want)
Do you know this plugin??
Nasty Replace Window with Picture.js

edit:
added link
I am not sure if i understand the question correctly, and i am not using mz ..(but JS related that should not make a big difference to mv i guess)
-also i am pretty sure your JS knowlegde is higher than mine^^

But perhaps thats helpfull cos its related to add imgs to windows: (to any window you want)
Do you know this plugin??
Nasty Replace Window with Picture.js

edit:
added link
I appreciate the suggestion, but that doesn't help me because it uses the method I outlined that I'm already using and doesn't involve block transfers, which is the part I'm trying to decide on an approach for.
Hi there!

and as part of that one idea I've had is to add an image loading function that iterates through all the image filenames needed for the menu in its start function and adds a load listener where it loads the next one.
That would be an approach I would do too. Maybe instead of loading a bitmap and on the load listener, loading the next one, I would add a kind of counter.

When it loads a bitmap add + 1 to that counter. When that counter reaches the same number that the total of bitmap, then the block transfer stuff could start happening.

Meanwhile, if there are many bitmaps to the point that can take longer to open the menu, a loading bar could be added?

However, the client has asked that I go with "the standard way" of doing this.
- Why the client said that? xD

I guess my main concern and saying that as both coder and client, with the approach above, is a delay to open the menu.

I don't know if there is a way to do that without preloading the images first or doing the load listener approach.

Maybe search for an advanced PIXI way to solve that, without relying on the default Bitmap process of RPG Maker?
Hi there!


That would be an approach I would do too. Maybe instead of loading a bitmap and on the load listener, loading the next one, I would add a kind of counter.

When it loads a bitmap add + 1 to that counter. When that counter reaches the same number that the total of bitmap, then the block transfer stuff could start happening.

Meanwhile, if there are many bitmaps to the point that can take longer to open the menu, a loading bar could be added?


- Why the client said that? xD

I guess my main concern and saying that as both coder and client, with the approach above, is a delay to open the menu.

I don't know if there is a way to do that without preloading the images first or doing the load listener approach.

Maybe search for an advanced PIXI way to solve that, without relying on the default Bitmap process of RPG Maker?
My current tests are coming up at around 10-15ms for the image loading, so the delay is almost imperceptible.
Short opinion: preload big static stuff and block transfer sources, use on-demand async for the rest.

...to add an image loading function that iterates through all the image filenames needed for the menu in its start function and adds a load listener where it loads the next one.
Load listeners for blit sources: yes, definitely. Chain-loading images on-demand: unsure. It would make certain you know the load order of images, if that's important? If you want to count them rather than just rely on ImageManager.isReady then you could attach the same load listener to all of them, a la if (!--count) // finished. However, I think chaining calls would technically be slower than just requesting everything at once, via the usual async XHR/fetch, and letting them pop in when they're ready. (No idea if that difference would be noticeable at runtime, though.)

For example, internally SSDs are highly parallel: the output is a serial bus, but read/write requests can be executed on each die independently. Even with an HDD you'd probably lose a tiny bit of time between requests with chaining, because you're waiting for a full file to be returned before you send the signal to load the next.

Ideally you'd have all necessary images preloaded so that disk access never blocks the main thread while in-game. Obviously that's a balancing act, though: if they're not in RAM indefinitely, there needs to be some criteria to determine when to (un)load them. You could compromise: preload constants (e.g. background image) and load the stuff that changes mid-playthrough on demand. Also, it's possible to cover brief load times with distractions, e.g. fancy transitions.

Images could be loaded before the scene starts (e.g. create) or after. Before is more typical; after would allow seamless scene transition and improved responsiveness at the cost of (perhaps) some images briefly not displaying.

Also, remember that load times are system-dependent. If it's a web game (depends on the client's usage), network bandwidth is also a factor.
Short opinion: preload big static stuff and block transfer sources, use on-demand async for the rest.


Load listeners for blit sources: yes, definitely. Chain-loading images on-demand: unsure. It would make certain you know the load order of images, if that's important? If you want to count them rather than just rely on ImageManager.isReady then you could attach the same load listener to all of them, a la if (!--count) // finished. However, I think chaining calls would technically be slower than just requesting everything at once, via the usual async XHR/fetch, and letting them pop in when they're ready. (No idea if that difference would be noticeable at runtime, though.)

For example, internally SSDs are highly parallel: the output is a serial bus, but read/write requests can be executed on each die independently. Even with an HDD you'd probably lose a tiny bit of time between requests with chaining, because you're waiting for a full file to be returned before you send the signal to load the next.

Ideally you'd have all necessary images preloaded so that disk access never blocks the main thread while in-game. Obviously that's a balancing act, though: if they're not in RAM indefinitely, there needs to be some criteria to determine when to (un)load them. You could compromise: preload constants (e.g. background image) and load the stuff that changes mid-playthrough on demand. Also, it's possible to cover brief load times with distractions, e.g. fancy transitions.

Images could be loaded before the scene starts (e.g. create) or after. Before is more typical; after would allow seamless scene transition and improved responsiveness at the cost of (perhaps) some images briefly not displaying.

Also, remember that load times are system-dependent. If it's a web game (depends on the client's usage), network bandwidth is also a factor.
It's not a web game, it's a standalone but there is a mobile version. And the main reason I'm considering this is because there is occasionally a minor bit of flicker as images load in.
Wait, flickering? Like, rapidly alternating between different appearances? Z-fighting? Not sure why that would be happening.

If it's just a delay before some things appear, then as mentioned, I think the only options are:
  1. Delay the scene's appearance - e.g. load images in the scene's create method; and/or
  2. Have it already in memory (preloaded).
Option 1 is how the core scripts do things.

Spoiler: delay explanation & test case
A scene's isReady method needs to return true before the SceneManager will run that scene's start method. Scene_Base#isReady relies on ImageManager.isReady, so while it's loading any image, the scene won't start. The SceneManager will not update scenes (visually or otherwise, including child elements) until they have started, and calls create before start.

For example, the default Scene_Menu implicitly makes use of this: it refreshes the status window (the only one with images) in its start method. The faces get loaded via Window_MenuStatus#initialize, because it attempts to blit from the associated ImageManager.loadFace. By the time the scene's start method is called, the ImageManager must no longer be busy, therefore the faces should be loaded and the refresh can go ahead.

I did a sort of half-test by patching Scene_Menu#create to load a bunch of stuff through the ImageManager: the 100+ FV enemy sprites present in a new project. On my system (HDD), the pause menu is delayed by a second or so the first time it's called per session (as usual, images get cached, so the delay is gone for subsequent menu calls).
Spoiler: test
JavaScript:
void (alias => {
  Scene_Menu.prototype.create = function() {
    alias.apply(this, arguments);
    const list = require('fs').readdirSync('./img/enemies/', {}, () => {})
                              .map(s => s.slice(0, s.length - 4));
    for (const f of list) ImageManager.loadEnemy(f);
  }
})(Scene_Menu.prototype.create);
Wait, flickering? Like, rapidly alternating between different appearances? Z-fighting? Not sure why that would be happening.

If it's just a delay before some things appear, then as mentioned, I think the only options are:
  1. Delay the scene's appearance - e.g. load images in the scene's create method; and/or
  2. Have it already in memory (preloaded).
Option 1 is how the core scripts do things.

Spoiler: delay explanation & test case
A scene's isReady method needs to return true before the SceneManager will run that scene's start method. The SceneManager will not update scenes (visually or otherwise, including child elements) until they have started, and calls create before start.

For example, the default Scene_Menu implicitly makes use of this: it refreshes the status window (the only one with images) in its start method. The faces get loaded via Window_MenuStatus#initialize, because it attempts to blit from the associated ImageManager.loadFace. By the time the scene's start method is called, the ImageManager must no longer be busy, therefore the faces should be loaded and the refresh can go ahead.

I did a sort of half-test by patching Scene_Menu#create to load a bunch of stuff through the ImageManager: the 100+ FV enemy sprites present in a new project. On my system (HDD), the pause menu is delayed by a second or so the first time it's called per session (as usual, images get cached, so the delay is gone for subsequent menu calls).
Spoiler: test
JavaScript:
void (alias => {
  Scene_Menu.prototype.create = function() {
    alias.apply(this, arguments);
    const list = require('fs').readdirSync('./img/enemies/', {}, () => {})
                              .map(s => s.slice(0, s.length - 4));
    for (const f of list) ImageManager.loadEnemy(f);
  }
})(Scene_Menu.prototype.create);
No, just a brief delay in stuff appearing. I did actually do some digging and found where Window_BattleStatus does something similar in preparePartyRefresh, which was enough to convince my client it's the way to go so that's how I'm doing it.

Original thread: https://forums.rpgmakerweb.com/threads/best-practice-for-image-intensive-custom-scenes.152217/