• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Easiest way to preload objects?

Status
Not open for further replies.
Level 13
Joined
Jul 15, 2007
Messages
763
As my project has grown in size, it has approximately 1800 custom objects. A majority of these are used in gameplay and i'd like to start preloading them during gametime rather than map init to reduce the map's loading time. Currently i only preload important things (i.e. the big lag spike offenders such as abilities with many levels) and anything else is loaded on the go. However the map still suffers from some incidences of lag spikes when units are spawned for the first time etc which is why i want to update my preloading method.

I could be stooooopid but anything preloading related on the hive requires you to list things to be preloaded manually (e.g. preloadunit[1] = footman, preloadunit[2] = archer and so forth) which isn't exactly practical given i have 1800 things that would need to be loaded.

From what i have gathered is that things like unit types have an integer ID but i'm assuming this isn't as simple as 1, 2, 3 meaning you can't loop-create units, and i'm not sure if items or abilities also have an integer ID for the same method.

Is there a time-efficient, easy solution out there?
 
If you don't want big lists, one could loop the custom objects by mimicing the way world editor uses the 4 digit number system (assuming you did not alter the ids they are using).

The whole 4 digit thing is based on ascii with base 256

World Editor only uses index 48 to 57 ("0" to "9") then jumps to 65 using upto to 90 ("A" to "Z") then jumps 256 up (or more if the second/third digit changes, but to make is simple don't enumerate over such points) to the next index 48 ("0"), sounds wierd but in 4 digit writing it doesn't look so wierd anymore. Numbers used from that asciitable.
'A000' <- '0' = 48
'A009' <- '9' = 57
now jumps to
'A00A' <- 'A' = 65
upto
'A00Z' <- 'Z' = 90
now jumps one digit up to
'A010' <- lowest index again 48
and so on, but the only thing mattering to us is the last digit.

wrote bullshit there sry, if the second or third digit jumps the function loads alot of bullshit, see the two lines below.
in world Editor next after 'A09Z' is 'A0A0'
next after 'A0ZZ' is 'A100'
In function 'A09Z' -> 'A0:0' which is not used by world editor. fixed​



this jass code should do the trick looping ids from a starting id to a included endId.
Edit: there would be surly a more efficent way by predefing for each remain its index and its next number, but that you have to do yourself or find it insde the jass section (not sure about that one).
Edit: Updated the function to be more intuitve to use.
Edit: Supports now jumps from 'A0ZZ' -> 'A100' or 'A8ZZ' -> 'A900'; 'A9ZZ' -> 'AA00' not supported (which is a absurd amount of objects to begin with).
JASS:
//id is the starting number, idEnd is the last id enumerated.
//evoke this with call PreaLoadIds('A000', 'A010'), will print the id with their names.
//this funktion does not consider jumpes of 'A9ZZ' to 'AA00' (which shouldn't be possible to reach in any real case), we talk here about over 10k objects of one type.
function PreLoadIds takes integer id, integer idEnd returns integer
   local integer rest = ModuloInteger(id, 256)
   local integer digit00XX
   // easy to use variables for later
   local integer bj_256power2 = 256 * 256
   local integer bj_ZZ = 256 * 90 + 90
   local integer bj_00 = 47 + 48 * 256
   local integer bj_9Z = 256 * 57 + 90
   local integer bj_A0 = 256 * 65 + 47
   loop
       exitwhen id > idEnd
       //Number 0 to 9                       A to Z
       if (rest >= 48 and rest <= 57 ) or ( rest >= 65 and rest <= 90)  then
           //Instead of Debug you would have to add remove ability or create Items/Units.       
           call Debug(I2S(id)+": "+GetObjectName(id))
            //call UnitAddAbility(udg_Preloader, id)
            //call UnitRemoveAbility(udg_Preloader, id)
            //call RemoveUnit( CreateUnit(Player(15), id, 0, 0, 0))
            //call RemoveItem(CreateItem(id, 0,0))
           set id = id + 1
           set rest = rest +1
       //move 1 expo up and jump to 0
       elseif rest > 90 then
           set digit00XX = ModuloInteger(id, bj_256power2)
           // 'ZZ', push 1 digit up.?
           if digit00XX > bj_ZZ then
               set id = id + bj_256power2 - bj_ZZ + bj_00   //'00' has to be added.
           //skip value between 'A09Z' and 'A0A0'?
           elseif digit00XX > bj_9Z then
               set id = id + (bj_A0  - bj_9Z)
           else
               set id =  id + (256 - rest + 48)
           endif
           set rest = 48
       //skip values between 9 and A
       elseif rest > 57 then
           set id =  id + (65 - rest)
           set rest = 65
       endif
   endloop
   return id
endfunction

Using later: Loop custom clones of human units 'h000' to 'h030' including 'h030'
  • Custom script: call PreLoadIds('h000', 'h030')
Some less technical way would be prelace all objects onto the map on map start remove all for loadup preplaced stuff.

Edit: To the units lag, you could try writing down a preloader file (.pld) loading up all imported models, icon and textures. (i think such a file could be auto created, if one has a list of the imports of your map. Gainable by using a mpq Editor)

Edit: Seems like such a objectId was done in the vjass section [vJASS] - BJObjectId.
 
Last edited:
Status
Not open for further replies.
Top