Preload Manager

Galenmereth

Retired
Veteran
Joined
May 15, 2013
Messages
2,248
Reaction score
2,141
First Language
English
Primarily Uses
N/A
@MikeMakes: This will preload the parallax image specified on a map automatically on map preload, yes. It preloads any and all resources used on a map when it loads the map. You can also make it preload specified parallax images (and other resources) on game startup if you want using the advanced configuration.

@Fernyfer775: This could be because the resource is not found. In the update I'm working on it will print an error message to the screen if such a thing happens. You might want to try the maps this happens in while test playing and opening the console using F8 to see if any errors are printed out.
 

orlando

Veteran
Veteran
Joined
May 24, 2014
Messages
177
Reaction score
85
Great work !!
 
However, I found a small issue:
 
Preloading title music seems not to work properly: I put the music into TDDP.bootPreloadBGM. Indeed I can see the HTTP request going off in the browser debugger/inspect mode during the initial loading screen and it seems to download fully (takes some time to complete and gets HTTP 200 OK as response), however when the title screen is shown I can see the BGM for the title being requested again and I still get a huge delay for the title music playing, probably caused by the game redownloading it on-the-fly instead of using the previously preloaded version.

If this is fixed and PreloadManager does then indeed preload all BGMs of all maps including those used in events, it could make this bug http://forums.rpgmakerweb.com/index.php?/topic/51186-any-solution-for-the-music-delays/ (generally huge delays before playing BGM in the original unaltered RPG Maker MV game code) much more bearable, so I'm hoping that you'll find a way to fix it :)
 

Galenmereth

Retired
Veteran
Joined
May 15, 2013
Messages
2,248
Reaction score
2,141
First Language
English
Primarily Uses
N/A
@blubberblubb: Is this when your game is played in a web browser, or when running the game from the .exe or in local testplay? And if local, what OS are you on and is it 64 bit?

To answer what is going on (regardless of platform, but when played non-locally in a web browser it becomes an actual problem): The HTML5 audio object doesn't support caching audio. Neither does the alternative WebAudio object. In both instances it's up to the browser which it's run in to get the file to cache it and load the file when requested again from cache.

When playing your game locally using the compiled .exe / .app or in test play, the game is run in a dedicated self-contained webkit browser instance that usually does the caching right. But when playing games on the web this cache is in an unknown flux, and depending on the user's environment, browser and amount of open tabs / other running websites or webapps, audio is often "forgotten" once played. Right now I know of no good way to solve this for web play except trickery like encoding audio into an image format and tricking the browser, and then decoding it again. Or similarly exotic solutions. But to do things like that you need to know the host platform, and I'm unsure about performance when it comes to larger and multiple audio tracks.

In short preloading audio should help in web play but it appears to not always work as it should. If it doesn't work in local test play I'm a bit more confused, as that runs fine from my tests. This is still an issue I'm looking into, but it's sadly a bigger problem than I thought it would be :|
 

orlando

Veteran
Veteran
Joined
May 24, 2014
Messages
177
Reaction score
85
No, it doesn't even work locally.

You can easily test by replacing your js/main.js contents with those:

//=============================================================================// main.js//=============================================================================PluginManager.setup($plugins);window.onload = function() {    Graphics._cancelFullScreen();    require('nw.gui').Window.get().showDevTools();    setTimeout(function() {        SceneManager.run(Scene_Boot);    }, 5000);};Then in the Inspect window, click "Network" before the 5 seconds have passed.
You can now see the entire loading process of the game. If you put the title background music into the TDDP.bootPreloadBGM, you can easily see it gets preloaded - and then loaded again at the very end when the actual title screen shows, with considerable time delay :-/ which I'm now pretty certain is what we are all seeing with those god awful BGM play delays.

Edit: at least it doesn't work for me when I'm testing it, since you said it worked locally for you. Even when running in nwjs-win and not in a browser, BGM appears to be always re-requested despite a preloading attempt, at least as far as the title screen piece is concerned

Edit 2: I have an idea: is WebAudio capable of streaming? Right now, I get the feeling the entire song is downloaded. Maybe a code change could convince RPG Maker MV to stream it? While that wouldn't solve the lack of caching, it might considerably lower the delay for many people
 
Last edited by a moderator:

orlando

Veteran
Veteran
Joined
May 24, 2014
Messages
177
Reaction score
85
<sry for double post please remove>
 
Last edited by a moderator:

Galenmereth

Retired
Veteran
Joined
May 15, 2013
Messages
2,248
Reaction score
2,141
First Language
English
Primarily Uses
N/A
Edit: at least it doesn't work for me when I'm testing it, since you said it worked locally for you. Even when running in nwjs-win and not in a browser, BGM appears to be always re-requested despite a preloading attempt, at least as far as the title screen piece is concerned

Edit 2: I have an idea: is WebAudio capable of streaming? Right now, I get the feeling the entire song is downloaded. Maybe a code change could convince RPG Maker MV to stream it? While that wouldn't solve the lack of caching, it might considerably lower the delay for many people
You are correct, it does get re-requested. But when I test it, a re-request is significantly faster than the original request: https://tdscreenshots.s3.amazonaws.com/random/audio_rerequest_preload.PNG Do note that it does not say it fetches it from cache, yet it's much faster. Since there is no official cache functionality for audio in webkit I'm not entirely sure why this works the way it does. I really wish I did, but audio is a problematic area for html5 development still. 

Streaming audio is how the engine does it by default, which causes a longer delay in playback locally, while saving some time on the web. In both instances it causes an unknown wait time before audio starts playing, usually.

Is your OS 64 bit or 32 bit? This is relevant to some reports I've had.
 
Last edited by a moderator:

orlando

Veteran
Veteran
Joined
May 24, 2014
Messages
177
Reaction score
85
The re-request is also a bit quicker here, but with 200ms it still seems somewhat sluggish (and this is under low system load, I can imagine it being slower when more things are going on).


I'm testing with nwjs-win running in wine on a 64bit Linux, although let me remark that I doubt wine changes much since it usually just breaks things using advanced graphics effects or obscure WinApi functions, and nwjs-win/webkit has its own caching and HTTP implementation in the application and most likely it doesn't rely for this on anything notable in wine. If at all, it probably just slows down everything a bit, evenly.


Edit: let me stress this a bit more, 200ms seems really long for something fetched from memory for something as small as a single sound file, even if it's a bit lengthier like a 5 minutes song. I can imagine this response time from a quick disk cache for a 5mb file being read back under good circumstances (maybe a bit slower on a HDD), but not if it's memory cached... (unless the memory cache is a really badly written cache that wastes a lot of computing time doing nothing)


Edit 2: and WebAudio does the decoding, right? So all the cache has to do is spill out the .OGG undecoded again in garbled original data without processing or decoding it to usable audio in any way. If it's truly stored in memory, 200ms really seems way too slow.
 
Last edited by a moderator:

Galenmereth

Retired
Veteran
Joined
May 15, 2013
Messages
2,248
Reaction score
2,141
First Language
English
Primarily Uses
N/A
I've taken another detailed gander at how MV handles this and I see that we can solve this, but it requires me to rewrite how MV handles audio. Right now it requests a new WebAudio object (except for Android, where it uses HTML5 audio for bgm) for every se, me, bgm and bgs. With no caching whatsoever. Not only is this obviously bad for audio playback, it's even worse for performant. WebAudio is a "heavyweight" object for the browser. If you were to make MV play a few too many sfx at once, most people running a 32bit OS would have it crash, for instance.

I am going to implement audio caching in this plugin asap :) Watch this space.
 

orlando

Veteran
Veteran
Joined
May 24, 2014
Messages
177
Reaction score
85
I just implemented a plugin which works together with your current Preload Manager and which seems to solve it: http://forums.rpgmakerweb.com/index.php?/topic/51422-webaudio-cache-experimental/


It caches the decoded audio, therefore retrieval out of the cache is very fast. On each map load, it throws away cached audio older than 5 minutes (which is supposed to get rid of everything pre-map load to clean up memory).


Of course you are still free to write something similar directly into Preload Manager, if you wish to do so. However, it has a very permissive license so it should be ok for everybody to use it in their projects with no trouble (combined with your latest Preload Manager release).
 
Last edited by a moderator:

Galenmereth

Retired
Veteran
Joined
May 15, 2013
Messages
2,248
Reaction score
2,141
First Language
English
Primarily Uses
N/A
Sweet stuff @blubberblubb. I'm going to take a look at this tomorrow :)
 

orlando

Veteran
Veteran
Joined
May 24, 2014
Messages
177
Reaction score
85
Unrelated suggestion:


You might want to add an

ImageManager.clear()to each map change. (A map change can be detected by hooking into DataManager.loadMap() and remembering the last map id that was loaded, and when it changes the player has changed the map)
You could then of course also throw away/reset your

PreloadManager._sessionRequestedImagesaccordingly to reflect the change of loaded images.
If you do this right before you do your own map load stuff, not only would PreloadManager load all the needed resources for each new map, it would also enforce throwing the old ones away. (my experimental WebAudioCache also already does this on map change for its own audio cache)


While this change would slightly slow down changing between two maps quickly, but ensure that really huge games don't run out of memory eventually because of all the cached images.


(as far as I'm aware, ImageManager never seems to clear its own cache at any point, nor does any of the RPG Maker MV original code do this)


Edit/Note: ... unless doing so causes massive bugs of course :) but so far my tests haven't indicated major problems. I suppose if people stuff runtime-created graphics in there and then the code is surprised that they are suddenly gone it might be problematic though
 
Last edited by a moderator:

Galenmereth

Retired
Veteran
Joined
May 15, 2013
Messages
2,248
Reaction score
2,141
First Language
English
Primarily Uses
N/A
That is a good point, but the tradeoff is that map loads will always take long, even if the map has been loaded previously and recently in your session, as you point out. Perhaps implementing an age check on the ImageManager's cache functionality is a better solution; any image that hasn't been requested for a specific period of time is cleared on map change. I'll look into this too.

It is disappointing that the core MV code is so lacking in these areas.
 
Last edited by a moderator:

orlando

Veteran
Veteran
Joined
May 24, 2014
Messages
177
Reaction score
85
To be frank, I really don't mind long map loads. What I hate is out of memory, sound delays or ANY delays while I'm playing on the map and otherwise I'm simple to please :)


Maybe make it an option? I would certainly prefer a clean purge on map change (to guarantee stability on long game sessions and even with larger maps), but maybe others would like to have some longer caching. I guess people with smaller maps could easily enable a longer cache
 
Last edited by a moderator:

Galenmereth

Retired
Veteran
Joined
May 15, 2013
Messages
2,248
Reaction score
2,141
First Language
English
Primarily Uses
N/A
An option wouldn't be problematic at all and the best solution, so absolutely :)
 

Cinnamon

Veteran
Veteran
Joined
Jun 20, 2014
Messages
605
Reaction score
209
First Language
English
Primarily Uses
Hi! I have a request to make: is it possible to preload just certain files?

You don't have to make it a clean and hard-to-make update, if you can just nudge me in the right direction I can add the stuff to the plugin myself without having to use commands etc. =)
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
862
First Language
German
Primarily Uses
Advanced configuration is on the plugin file itself. Just search for "BOOT PRELOAD CONFIG -- ADVANCED USERS".


Regarding this a small suggestion: Users usually don't like to edit the plugin file itself, but are used to notetags and since you are already waiting for DataManager.isDatabaseLoaded, you could (ab)use a common event to store all files to be loaded as notetags, like "<preload animation myAnimation>".
 

Cinnamon

Veteran
Veteran
Joined
Jun 20, 2014
Messages
605
Reaction score
209
First Language
English
Primarily Uses
Oh, nice let me check it out! Thanks.

Is that second comment directed at me? Because I have no idea what DataManager.isDatabaseLoaded is and I have no problem editing plugins. I actually prefer it. x)
 
Last edited by a moderator:

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
862
First Language
German
Primarily Uses
Ah, no sorry, that was for Galenmereth ^^ Not everyone likes handling with source files, so i thought it might be a nice idea.
 

Cinnamon

Veteran
Veteran
Joined
Jun 20, 2014
Messages
605
Reaction score
209
First Language
English
Primarily Uses
Gotcha! No problem. ^_^  

EDIT

2 issues.

1) There's an incompatibility with "Yami_SkipTitle". By skipping the title screen, I get this error:

Uncaught TypeError: Cannot read property 'note' of null

2) Is there a way to JUST load on BOOT the stuff I defined? Because this giant "Loading" lag at the start of each map is too big. I just want to preload a couple of sprites for cutscenes, that's it.

Thank you! ^_^ 

Yami_SkipTitle:

Code:
/*: * @plugindesc Skip the title scene for testing purpose. * @version 1.0 */(function() {    Scene_Boot.prototype.start = function() {        Scene_Base.prototype.start.call(this);        SoundManager.preloadImportantSounds();        if (DataManager.isBattleTest()) {            DataManager.setupBattleTest();            SceneManager.goto(Scene_Battle);        } else {            this.checkPlayerLocation();            DataManager.setupNewGame();            SceneManager.goto(Scene_Map);        }        this.updateDocumentTitle();    };})();
 
Last edited by a moderator:

orlando

Veteran
Veteran
Joined
May 24, 2014
Messages
177
Reaction score
85
@Galenmereth: is it possible you're not loading the battle music right now? (Neither the default one from the System tab, nor the one used from events on the map that launch a battle) I did a quick check on the code and can't see any attempts to load it..

It would be very useful if that could be added :)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

10/24 done :3 Maybe I can finish 11 and 12 this weekend^^
Been updating my game's control scheme to optionally use a mouse. Now the player pixel moves towards the mouse destination, which looks super sweet with the sparkles. Also turns out I made a Mouse Common Event plugin at some point... Thanks past me. :LZSexcite: Now the mouse wheel cycles different forms, and the right mouse button activates that form's special. :LZScool:
Oh man the controls in Mario Sunshine are pretty awful and I haven't even witnessed the controls without FLUDD

Forum statistics

Threads
102,957
Messages
996,257
Members
134,420
Latest member
MxMachine
Top