DoubleX RMMV Preloaded Resources

Purpose
Lets you sets some audios/images to be loaded upon game start
This should boost the FPS on phones noticeably if there's enough memory

Parameters
  1. * @param IsPreloadAudio
  2.  * @type boolean
  3.  * @desc Sets whether the specified audios will be preloaded
  4.  * @default true
  5.  *
  6.  * @param preloadAudioMSInterval
  7.  * @parent IsPreloadAudio
  8.  * @type number
  9.  * @desc Sets the number of milliseconds to wait before loading the
  10.  * next audio included by the same parameter(0 means no wait)
  11.  * @default 0
  12.  *
  13.  * @param preloadedBGMs
  14.  * @parent IsPreloadAudio
  15.  * @type file[]
  16.  * @dir audio/bgm/
  17.  * @desc Sets the list of BGMs to be preloaded
  18.  * @default []
  19.  *
  20.  * @param preloadedBGSs
  21.  * @parent IsPreloadAudio
  22.  * @type file[]
  23.  * @dir audio/bgs/
  24.  * @desc Sets the list of BGSs to be preloaded
  25.  * @default []
  26.  *
  27.  * @param preloadedMEs
  28.  * @parent IsPreloadAudio
  29.  * @type file[]
  30.  * @dir audio/me/
  31.  * @desc Sets the list of MEs to be preloaded
  32.  * @default []
  33.  *
  34.  * @param preloadedSEs
  35.  * @parent IsPreloadAudio
  36.  * @type file[]
  37.  * @dir audio/se/
  38.  * @desc Sets the list of SEs to be preloaded
  39.  * @default []
  40.  *
  41.  * @param preloadedStaticSEs
  42.  * @parent IsPreloadAudio
  43.  * @type file[]
  44.  * @dir audio/se/
  45.  * @desc Sets the list of static SEs to be preloaded
  46.  * @default []
  47.  *
  48.  * @param preloadedMiscAudios
  49.  * @parent IsPreloadAudio
  50.  * @type file[]
  51.  * @dir audio/
  52.  * @desc Sets the list of other audio files to be preloaded
  53.  * @default []
  54.  *
  55.  * @param IsPreloadImage
  56.  * @type boolean
  57.  * @desc Sets whether the specified images will be preloaded
  58.  * @default true
  59.  *
  60.  * @param preloadImageMSInterval
  61.  * @parent IsPreloadImage
  62.  * @type number
  63.  * @desc Sets the number of milliseconds to wait before loading the
  64.  * next hue and image under the same parameter(0 means no wait)
  65.  * @default 0
  66.  *
  67.  * @param preloadedAnimations
  68.  * @parent IsPreloadImage
  69.  * @type struct<PreloadedAnimation>[]
  70.  * @desc Sets the list of animations to be preloaded
  71.  * @default []
  72.  *
  73.  * @param preloadedBattleBack1s
  74.  * @parent IsPreloadImage
  75.  * @type struct<PreloadedBattleBack1>[]
  76.  * @desc Sets the list of 1st battle backs to be preloaded
  77.  * @default []
  78.  *
  79.  * @param preloadedBattleBack2s
  80.  * @parent IsPreloadImage
  81.  * @type struct<PreloadedBattleBack2>[]
  82.  * @desc Sets the list of 2nd battle backs to be preloaded
  83.  * @default []
  84.  *
  85.  * @param preloadedCharacters
  86.  * @parent IsPreloadImage
  87.  * @type struct<PreloadedCharacter>[]
  88.  * @desc Sets the list of characters to be preloaded
  89.  * @default []
  90.  *
  91.  * @param preloadedEnemies
  92.  * @parent IsPreloadImage
  93.  * @type struct<PreloadedEnemy>[]
  94.  * @desc Sets the list of enemies to be preloaded
  95.  * @default []
  96.  *
  97.  * @param preloadedFaces
  98.  * @parent IsPreloadImage
  99.  * @type struct<PreloadedFace>[]
  100.  * @desc Sets the list of faces to be preloaded
  101.  * @default []
  102.  *
  103.  * @param preloadedParallaxes
  104.  * @parent IsPreloadImage
  105.  * @type struct<PreloadedParallax>[]
  106.  * @desc Sets the list of parallaxes to be preloaded
  107.  * @default []
  108.  *
  109.  * @param preloadedPictures
  110.  * @parent IsPreloadImage
  111.  * @type struct<PreloadedPicture>[]
  112.  * @desc Sets the list of pictures to be preloaded
  113.  * @default []
  114.  *
  115.  * @param preloadedSVActors
  116.  * @parent IsPreloadImage
  117.  * @type struct<PreloadedSVActor>[]
  118.  * @desc Sets the list of sideview actors to be preloaded
  119.  * @default []
  120.  *
  121.  * @param preloadedSVEnemies
  122.  * @parent IsPreloadImage
  123.  * @type struct<PreloadedSVEnemy>[]
  124.  * @desc Sets the list of sideview enemies to be preloaded
  125.  * @default []
  126.  *
  127.  * @param preloadedSystem
  128.  * @parent IsPreloadImage
  129.  * @type struct<PreloadedSystem>[]
  130.  * @desc Sets the list of system images to be preloaded
  131.  * @default []
  132.  *
  133.  * @param preloadedTilesets
  134.  * @parent IsPreloadImage
  135.  * @type struct<PreloadedTileset>[]
  136.  * @desc Sets the list of tilesets to be preloaded
  137.  * @default []
  138.  *
  139.  * @param preloadedTitles1
  140.  * @parent IsPreloadImage
  141.  * @type struct<PreloadedTitle1>[]
  142.  * @desc Sets the list of 1st titles to be preloaded
  143.  * @default []
  144.  *
  145.  * @param preloadedTitles2
  146.  * @parent IsPreloadImage
  147.  * @type struct<PreloadedTitle2>[]
  148.  * @desc Sets the list of 2nd titles to be preloaded
  149.  * @default []
  150.  *
  151.  * @param preloadedMiscImages
  152.  * @parent IsPreloadImage
  153.  * @type struct<PreloadedMiscImage>[]
  154.  * @desc Sets the list of other image files to be preloaded
  155.  * @default []
Expand to see the code.


Help
  1. * 1. You should only preload resources that are actually used or the game can
  2.  *    take an excessively and unnecessarily long time to start
  3.  * 2. You might have to test the values of preloadAudioMSInterval and
  4.  *    preloadImageMSInterval to have the optimal preload time for your project
  5.  * 3. Setting preloadAudioMSInterval/preloadImageMSInterval as 0 might block
  6.  *    the UI thread for too long and thus crashing/freezing the game in phones
  7.  * 4. You should consider not preloading resources that are only rarely used
  8.  *    in case the preloading times are still too long
  9.  * 5. Some plugins might use HTML5Audio instead of WebAudio, and preloading
  10.  *    audios using HTML5Audio is meaningless HTML5Audio is a static class
  11.  *    having nothing to preload
  12.  * 6. You should compress the resources to be preoloaded for phones or the
  13.  *    extra memory consumption from preloading them can quickly crash/free the
  14.  *    game there
  15.  * 7. No identical resource should be duplicated in the same parameter or
  16.  *    across parameters(this plugin won't explicitly skip those duplicates as
  17.  *    simplifying the codes this way can actually reduce preload time)
  18.  * 8. If you want to keep the current parameter values in the plugin manager
  19.  *    upon using a newer version, you can do the following:
  20.  *    - Renames the newer version to be that of the older version
  21.  *    - Edits the value of DoubleX_RMMV.Preloaded_Resources_File to be the
  22.  *      filename of the older version, which must be done via opening this
  23.  *      plugin js file directly
  24.  * 9. (Advanced)By default, the images are cached upon first used, and the
  25.  *    cache is a Least Recently Used(LRU) cache. This plugin reserves all
  26.  *    preloaded images so the LRU will never release them unless they're
  27.  *    explicitly told to be released via a script call
Expand to see the code.


Script Call Info
  1. *    # Image manipulations
  2.  *      1. ImageManager.releasePreloadedFolderImg(param, filename, hue)
  3.  *         - Releases the image with the filename filename and hue hue
  4.  *           specified in parameter param
  5.  *         - This can be useful when an image becomes rarely used and/or the
  6.  *           preloaded images are consuming too much memory
  7.  *         - Please note that using this script call doesn't always remove the
  8.  *           image from the LRU cache instantly as it's still up to the LRU
  9.  *           cache to determine when to remove that image now that it can be
  10.  *           removed due to no longer being reserved
  11.  *         - param and filename are supposed to be String
  12.  *         - hue is supposed to be an integer from 0 to 360 inclusive
  13.  *         - The script call's supposed to be Idempotent
  14.  *      2. ImageManager.releasePreloadedMiscImg(path, hue, smooth)
  15.  *         - Releases the image with the path path, hue hue and smooth smooth
  16.  *         - This can be useful when an image becomes rarely used and/or the
  17.  *           preloaded images are consuming too much memory
  18.  *         - Please note that using this script call doesn't always remove the
  19.  *           image from the LRU cache instantly as it's still up to the LRU
  20.  *           cache to determine when to remove that image now that it can be
  21.  *           removed due to no longer being reserved
  22.  *         - path is supposed to be a String
  23.  *         - hue is supposed to be an integer from 0 to 360 inclusive
  24.  *         - smooth is supposed to be a Boolean
  25.  *         - The script call's supposed to be Idempotent
  26.  *    # Audio manipulations
  27.  *      1. AudioManager.invalidateCachedWebAudio(folder, name)
  28.  *         - Releases the audio with folder folder and filename name from the
  29.  *           audio cache
  30.  *         - This only works for non static SE audio loaded as WebAudio
  31.  *         - folder is supposed to be a String
  32.  *         - name is supposed to be a String
  33.  *         - The script call's supposed to be Idempotent
Expand to see the code.


Prerequisites
  1. Abilities:
  2. 1. Nothing special for most ordinary cases
  3. (No capability on Javascript ES5 experience but can still make reasonable guesses on readable novice codes up to 100 LoC scale)
  4. 2. Little RMMV plugin development proficiency to fully utilize this plugin in intended ways
  5. (Elementary Javascript ES5 exposures being able to write beginner codes up to 300LoC scale )[/SPOILER]
  6.  
  7. Instructions
  8. 1. The default plugin parameters file name is doublex rmmv preloaded resources v100a
  9. If you want to change that, you must edit the value of DoubleX_RMMV.Preloaded_Resources_File, which must be done via opening this plugin js file directly
Expand to see the code.


Terms Of Use
  1. 1. Commercial use's always allowed and crediting me's always optional.
  2. 2. You shall keep this plugin's Plugin Info part's contents intact.
  3. 3. You shalln't claim that this plugin's written by anyone other than DoubleX or my aliases. I always reserve the right to deny you from using any of my plugins anymore if you've violated this.
  4. 4. If you repost this plugin directly(rather than just linking back), you shall inform me of these direct repostings. I always reserve the right to request you to edit those direct repostings.
  5. 5. CC BY 4.0, except those conflicting with any of the above, applies to this plugin, unless you've my permissions not needing follow so.
  6. 6. I always reserve the right to deny you from using this plugin anymore if you've violated any of the above.
Expand to see the code.


Contributors
  1. Authors:
  2. 1. DoubleX
  3. Plugin Development Collaborators:
  4. - None So Far
  5. Bug Reporters:
  6. - None So Far
  7. Compatibility Issue Raisers:
  8. - None So Far
  9. Feature Requesters:
  10. - None So Far
Expand to see the code.


Changelog
  1. v1.00a(GMT 1500 7-Jul-2020):
  2. 1. 1st version of this plugin finished[/SPOILER]
Expand to see the code.


Download Link
Pastebin

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=80223