Questions about Preloading...

Level 7
Joined
Sep 10, 2022
Messages
101
I started digging through the AI script files and found preload files there. After reading scattered posts on the hive and some outside of it, I don't really understand what preload files are for and how to use them. Are they still relevant?

When I opened the .pld file, I saw quite understandable functions, but I can't figure out what the PreloadEnd() function is, which takes a real value as a parameter. What does this function do..?

Also, if it's worth doing a preload, then in what cases? For example, if I have units pre-placed on the map before the map starts, should I load textures for them like mdx. and blp?

Example:
JASS:
function PreloadFiles takes nothing returns nothing

    call Preload( "Buildings\\Undead\\AltarOfDarkness\\AltarOfDarkness.mdx" )
    call Preload( "Buildings\\Undead\\AltarOfDarkness\\AltarOfDarknessDeath.mdx" )
    call Preload( "Buildings\\Undead\\AltarOfDarkness\\AltarOfDarkness_Portrait.mdx" )
    call Preload( "Buildings\\Undead\\BoneYard\\BoneYard.mdx" )
    call Preload( "Buildings\\Undead\\BoneYard\\BoneyardDeath.mdx" )
    call Preload( "Buildings\\Undead\\BoneYard\\BoneYard_Portrait.mdx" )
    call Preload( "Buildings\\Undead\\Crypt\\Crypt.mdx" )
    call Preload( "Buildings\\Undead\\Crypt\\CryptDeath.mdx" )
    call Preload( "Buildings\\Undead\\Crypt\\Crypt_Portrait.mdx" )
    call Preload( "Buildings\\Undead\\GargoyleSpire\\GargoyleSpire.mdx" )
    call Preload( "Buildings\\Undead\\GargoyleSpire\\GargoyleSpire_Portrait.mdx" )
    call Preload( "Buildings\\Undead\\Graveyard\\Graveyard.mdx" )
    call Preload( "Buildings\\Undead\\Graveyard\\GraveyardDeath.mdx" )
    call Preload( "Buildings\\Undead\\Graveyard\\Graveyard_Portrait.mdx" )
    call Preload( "Buildings\\Undead\\HauntedMine\\HauntedGoldMineDeath.mdx" )
    call Preload( "Buildings\\Undead\\HauntedMine\\HauntedMine.mdx" )
    call Preload( "Buildings\\Undead\\HauntedMine\\HauntedMine_Portrait.mdx" )
    call Preload( "Buildings\\Undead\\Necropolis\\BlackCitadelBirth.mdx" )
    call Preload( "Buildings\\Undead\\Necropolis\\BlackCitadelDeath.mdx" )
    call Preload( "Buildings\\Undead\\Necropolis\\HallsOfTheDeadBirth.mdx" )
    call Preload( "Buildings\\Undead\\Necropolis\\HallsOfTheDeadDeath.mdx" )
    call Preload( "Buildings\\Undead\\Necropolis\\Necropolis.mdx" )
    call Preload( "Buildings\\Undead\\Necropolis\\NecropolisDeath.mdx" )
    call Preload( "Buildings\\Undead\\Necropolis\\Necropolis_Portrait.mdx" )
    call Preload( "Buildings\\Undead\\SacrificialPit\\SacrificialPit.mdx" )
    call Preload( "Buildings\\Undead\\SacrificialPit\\SacrificialPitDeath.mdx" )
    call Preload( "Buildings\\Undead\\SacrificialPit\\SacrificialPit_Portrait.mdx" )
    call Preload( "Buildings\\Undead\\SlaughterHouse\\SlaughterHouse.mdx" )
    call Preload( "Buildings\\Undead\\SlaughterHouse\\SlaughterHouseDeath.mdx" )
    call Preload( "Buildings\\Undead\\SlaughterHouse\\SlaughterHouse_Portrait.mdx" )
    call Preload( "Buildings\\Undead\\TempleOfTheDamned\\TempleOfTheDamned.mdx" )
    call Preload( "Buildings\\Undead\\TempleOfTheDamned\\TempleOfTheDamnedDeath.mdx" )
    call Preload( "Buildings\\Undead\\TempleOfTheDamned\\TempleOfTheDamned_Portrait.mdx" )
    call Preload( "Buildings\\Undead\\TombOfRelics\\TombOfRelics.mdx" )
    call Preload( "Buildings\\Undead\\TombOfRelics\\TombOfRelicsDeath.mdx" )
    call Preload( "Buildings\\Undead\\TombOfRelics\\TombOfRelics_Portrait.mdx" )
    call Preload( "Buildings\\Undead\\UBirth\\UBirth.mdx" )
    call Preload( "Buildings\\Undead\\Ziggurat\\NerubianTowerDeath.mdx" )
    call Preload( "Buildings\\Undead\\Ziggurat\\SpiritTowerDeath.mdx" )
    call Preload( "Buildings\\Undead\\Ziggurat\\Ziggurat.mdx" )
    call Preload( "Buildings\\Undead\\Ziggurat\\ZigguratDeath.mdx" )
    call Preload( "Buildings\\Undead\\Ziggurat\\Ziggurat_Portrait.mdx" )
    call Preload( "Abilities\\Spells\\Undead\\UndeadMine\\AcolyteMining.wav" )
    call Preload( "Abilities\\Spells\\Undead\\UndeadMine\\MineDomeLoop1.wav" )
    call Preload( "abilities\\Spells\\Undead\\UndeadMine\\SummonRune1.blp" )
    call Preload( "Abilities\\Spells\\Undead\\UndeadMine\\UndeadMineCircle.mdx" )
    call Preload( "buildings\\Undead\\AltarOfDarkness\\CreepyAltarOfDark.blp" )
    call Preload( "buildings\\Undead\\AltarOfDarkness\\NewCrypt.blp" )
    call Preload( "buildings\\undead\\Crypt\\Crypt.mdx" )
    call Preload( "Buildings\\Undead\\Crypt\\CryptWhat.wav" )
    call Preload( "buildings\\Undead\\Crypt\\NewCreepyScaryCrypt.blp" )
    call Preload( "buildings\\Undead\\Necropolis\\CreepyNecropolis.blp" )
    call Preload( "buildings\\undead\\Necropolis\\Necropolis.mdx" )
    call Preload( "Buildings\\Undead\\Necropolis\\NecropolisWhat.wav" )
    call Preload( "buildings\\Undead\\Ziggurat\\UBirth.mdx" )
    call Preload( "Buildings\\Undead\\Ziggurat\\ZigguratWhat.wav" )
    call Preload( "Environment\\BlightDoodad\\BlightDoodad.mdx" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNAcolyte.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNAltarOfDarkness.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNAttack.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNBoneyard.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNCancel.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNCannibalize.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNCrypt.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNCryptFiend.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNCryptFiendBurrow.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNFrostTower.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNGargoyle.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNGatherGold.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNGhoul.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNGhoulFrenzy.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNGoldMine.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNGraveyard.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNHallOfTheDead.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNHeroCryptLord.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNHeroDeathKnight.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNHeroDreadLord.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNHeroLich.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNHoldPosition.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNMove.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNNecropolis.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNPackBeast.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNPatrol.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNRallyPointUndead.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNRepairOn.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNSacrifice.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNSacrificialPit.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNScourgeBuild.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNSkillz.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNSlaughterhouse.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNStoneForm.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNStop.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNTempleOfTheDamned.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNTombOfRelics.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNUnsummonBuilding.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNWeb.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNZiggurat.blp" )
    call Preload( "ReplaceableTextures\\CommandButtons\\BTNZigguratUpgrade.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNAcolyte.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNAltarOfDarkness.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNAttack.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNBoneyard.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNCancel.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNCannibalize.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNCrypt.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNCryptFiend.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNCryptFiendBurrow.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNFrostTower.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNGargoyle.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNGatherGold.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNGhoul.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNGhoulFrenzy.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNGoldMine.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNGraveyard.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNHallOfTheDead.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNHeroCryptLord.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNHeroDeathKnight.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNHeroDreadLord.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNHeroLich.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNHoldPosition.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNMove.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNNecropolis.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNPackBeast.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNPatrol.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNRallyPointUndead.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNRepairOn.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNSacrifice.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNSacrificialPit.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNScourgeBuild.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNSkillz.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNSlaughterhouse.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNStoneForm.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNStop.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNTempleOfTheDamned.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNTombOfRelics.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNUnsummonBuilding.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNWeb.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNZiggurat.blp" )
    call Preload( "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNZigguratUpgrade.blp" )
    call Preload( "ReplaceableTextures\\Shadows\\ShadowAltarOfDarkness.blp" )
    call Preload( "ReplaceableTextures\\Shadows\\ShadowCrypt.blp" )
    call Preload( "ReplaceableTextures\\Shadows\\ShadowNecropolis.blp" )
    call Preload( "ReplaceableTextures\\Shadows\\ShadowZiggurat.blp" )
    call Preload( "ReplaceableTextures\\Splats\\UndeadUberSplat.blp" )
    call Preload( "SharedModels\\UBirth.mdx" )
    call Preload( "SharedModels\\UndeadBirth.blp" )
    call Preload( "Sound\\Buildings\\Undead\\AcolyteBuildingComplete1.wav" )
    call Preload( "Sound\\Buildings\\Undead\\UndeadBuildingBirth1.wav" )
    call Preload( "Sound\\Buildings\\Undead\\UndeadBuildingBirth2.wav" )
    call Preload( "Sound\\Buildings\\Undead\\UndeadBuildingBirth3.wav" )
    call Preload( "Sound\\Buildings\\Undead\\UndeadBuildingBirth4.wav" )
    call Preload( "Sound\\Buildings\\Undead\\UndeadBuildingBirthWhat1.wav" )
    call Preload( "Textures\\Acolyte.blp" )
    call Preload( "Textures\\AuraRune7Green.blp" )
    call Preload( "Textures\\BlueSqGlow.blp" )
    call Preload( "Textures\\DemonRune3.blp" )
    call Preload( "Textures\\GenericGlow5.blp" )
    call Preload( "Textures\\Ghost2.blp" )
    call Preload( "Textures\\grad2b.blp" )
    call Preload( "Textures\\GraveYardGhost.blp" )
    call Preload( "Textures\\NewZigguratscarycreepytex.blp" )
    call Preload( "Textures\\Peasant.blp" )
    call Preload( "Textures\\star2_32.blp" )
    call Preload( "Textures\\Star8b.blp" )
    call Preload( "Textures\\Tornado2b.blp" )
    call Preload( "Textures\\UndeadBirth.blp" )
    call Preload( "units\\undead\\Acolyte\\Acolyte.mdx" )
    call Preload( "units\\undead\\Acolyte\\Acolyte_portrait.mdx" )
    call Preload( "Units\\Undead\\Acolyte\\AcolyteReady1.wav" )
    call Preload( "Units\\Undead\\Acolyte\\AcolyteWhat1.wav" )
    call Preload( "Units\\Undead\\Acolyte\\AcolyteWhat2.wav" )
    call Preload( "Units\\Undead\\Acolyte\\AcolyteWhat3.wav" )
    call Preload( "Units\\Undead\\Acolyte\\AcolyteWhat4.wav" )
    call Preload( "Units\\Undead\\Acolyte\\AcolyteWhat5.wav" )
    call Preload( "Units\\Undead\\Acolyte\\AcolyteYes1.wav" )
    call Preload( "Units\\Undead\\Acolyte\\AcolyteYes2.wav" )
    call Preload( "Units\\Undead\\Acolyte\\AcolyteYes3.wav" )
    call Preload( "Units\\Undead\\Acolyte\\AcolyteYes4.wav" )
    call Preload( "units\\Undead\\Ghoul\\Ghoul.blp" )
    call Preload( "units\\undead\\Ghoul\\Ghoul.mdx" )
    call Preload( "units\\undead\\Ghoul\\Ghoul_portrait.mdx" )
    call Preload( "Units\\Undead\\Ghoul\\GhoulReady1.wav" )
    call Preload( "Units\\Undead\\Ghoul\\GhoulWhat1.wav" )
    call Preload( "Units\\Undead\\Ghoul\\GhoulWhat2.wav" )
    call Preload( "Units\\Undead\\Ghoul\\GhoulWhat3.wav" )
    call Preload( "Units\\Undead\\Ghoul\\GhoulYes1.wav" )
    call Preload( "Units\\Undead\\Ghoul\\GhoulYes2.wav" )
    call Preload( "Units\\Undead\\Ghoul\\GhoulYes3.wav" )
    call PreloadEnd( 6.5 )

endfunction
 
Level 29
Joined
Sep 26, 2009
Messages
2,594
As stated in docs Doc - Preload
Preload files instruct the game to pre-read a file/resources to avoid freezes/stutter during gameplay. It's done to move the file into OS cache. Blizzard used preload files to load all required files at map init. See blizzard.j or campaign maps.
It has no effect for preplaced units, because their data is loaded during map initialization.
But spawning a completely new unit that has not yet appeared in the game is followed by a short freeze. Preloading gets rid of that freeze.

As for PreloadEnd, see docs: Doc - PreloadEnd - my guess would be that the time in PreloadEnd is max time that the entire loading should take so that it does not unnecessarily slow down map start.

Also, if it's worth doing a preload, then in what cases?
I believe it is worth preloading things any time those units are not preplaced in map.
For example consider that you make a custom race for melee maps - your custom race starts only with workers and town hall. Any first-time creation of any other structure/unit would cause that short freeze I've mentioned before - in that case, it makes sense to preload everything related to that custom race so as to avoid any stutter during gameplay.
 
Level 7
Joined
Sep 10, 2022
Messages
101
As stated in docs Doc - Preload

It has no effect for preplaced units, because their data is loaded during map initialization.
But spawning a completely new unit that has not yet appeared in the game is followed by a short freeze. Preloading gets rid of that freeze.

As for PreloadEnd, see docs: Doc - PreloadEnd - my guess would be that the time in PreloadEnd is max time that the entire loading should take so that it does not unnecessarily slow down map start.


I believe it is worth preloading things any time those units are not preplaced in map.
For example consider that you make a custom race for melee maps - your custom race starts only with workers and town hall. Any first-time creation of any other structure/unit would cause that short freeze I've mentioned before - in that case, it makes sense to preload everything related to that custom race so as to avoid any stutter during gameplay.
That is, for example, I recently created a naga race for melee, and every time a new unit/hero is built from the local "barracks/altar", it is advisable to pre-load files such as mdx and blp? And this also applies to models, for example, a skin for a grunt or something similar...?
 
Level 29
Joined
Sep 26, 2009
Messages
2,594
Preload is used not for unit itself, but for models/assets that the unit uses. You can see in your own example:
JASS:
call Preload( "Buildings\\Undead\\AltarOfDarkness\\AltarOfDarkness.mdx" )
The path is not to a unit, spell or anything like that. The path leads to a model that needs to be loaded.

This applies also for example to special effect created via triggers. Simply put, special effects create some model somewhere.
So game tries to use that model for first time -> model data are not loaded into memory -> game has to load the data from the path specified by the model -> causes stutter until loading is complete
The second time game tries to use that same model -> model is already loaded into memory -> no stutter.
So it is enough to preload models only once. It has no effect doing it multiple times.

Preloading should be part of map initialization
 
Top