Tutorial How to get the "Compress Names" optimizer function work

Discussion in 'Graveyard' started by luorax, Mar 3, 2012.

  1. luorax

    luorax Invasion in Duskwood

    Ratings:
    +67 / 0 / -0
    Introduction
    Short variable names are not only faster, but reduce the script's total size. It's a known fact. But nowadays many people write their submissed systems/snippets - even the complicited ones - that takes more time understing, than writing, because of the super-annoying short names. Their reason(/excuse): The "Compress Names" function of Vexorian's optimizer is broken, and as said above, it's faster this way. Well, this little tutorial will show you how you can get it work, so that this annoying habit can finally go to an end.

    Tools Needed
    1. Wc3mapoptimizer
    2. Ladik's MPQ Editor
    3. Notepad++ (Optional)

    Let's Begin!

    1, First of all, we need a map. Open the optimizer, browse the map, and set it up according to your liking. I'll make it like this:
    [​IMG]

    2, Click "Save optimized as..." and save it. This will optimize everything and create two files: the optimized map, and the script file. Go and rename it immediately to "war3map.j"

    [​IMG]

    3, Open the generated script file. Natives must be directly under global declaration, after the keyword endglobals. The optimizer generates some garbage functions and places them inbetween the two of them; locate all the custom declared natives and move them where they belong.

    [​IMG]

    4, Open Ladik's awesome MPQ editor. We know how big our script file is; sort files by file size, locate the script file, and delete it. If you're not sure it's the right file, open it by double-clicking on it.

    [​IMG]

    5, Go to Operations -> Add File(S), or press Ctrl+A. Locate our fixed script file, and import it. When the window pops up, select "Compress+Encrypt" and "Zlib" compression. Then go File -> Close all MPQ's.

    [​IMG]
    [​IMG]

    6, Open your WarCraft 3 and test it. It should work by now.


    ExecuteFunc/TriggerRegisterVariableEvent natives
    Those two natives have a string parameter; one of them is a function name, the other one is a variable name. If you pass a concatenated string, the optimizer will just ignore it. It can also be fixed by editing the "war3map.j" script file, when fixing the native bug, but you have to go through the entire file and find all these function calls, plus their arguments' shortened names. It's hard and time-consuming.
    Fixing it is simple; you have many options:
    • Don't use those natives; use either JASSHelper's .evaluate/.execute functions
    • Evaluate triggers manually.
    • Use this snippet.

    Credits
    • BBQ, for revealing why natives break maps
    • Vexorian & Ladik, for their tools
     

    Attached Files:

  2. luorax

    luorax Invasion in Duskwood

    Ratings:
    +67 / 0 / -0
  3. Laiev

    Laiev Hey Listen!!

    Ratings:
    +187 / 0 / -0
    Attach the images here and use it, it don't work using the attachment of Hive.
     
  4. luorax

    luorax Invasion in Duskwood

    Ratings:
    +67 / 0 / -0
    Well, they worked fine for me - but okay, why not? I changed it.
     
  5. Nestharus

    Nestharus o-o

    Ratings:
    +83 / 0 / -0
    This is no longer enough to get compressed names to work with the latest map optimizer. Compressed names for natives now work, but the values for constants don't work... furthermore, the optimizer now adds tons of useless bj code.
     
  6. Bribe

    Bribe vJass errors are legion

    Ratings:
    +67 / 0 / -0
    For future readers, the reason for optimizer not inlining some constant real values was given by Vexorian and it's working as intended.

    Also, Vexorian fixed the script so that it recognizes if you don't want to inline BJ's, in which case it doesn't inline things like InitBlizzard.

    The only thing the optimizer doesn't do (and no optimizer could reasonably predict), is if you use non-constant strings with ExecuteFunc (for example function names concatenated with I2S). However, there is a half dozen better ways to do this and that's also a ridiculously slow way to execute a function.
     
  7. luorax

    luorax Invasion in Duskwood

    Ratings:
    +67 / 0 / -0
    Yea, it's ready to be graveyarded.
     
  8. Nestharus

    Nestharus o-o

    Ratings:
    +83 / 0 / -0
    So will it compress 0 function names?
    Because my save/load stuff does use ExecuteFunc with non constant function names >.<.
     
  9. Bribe

    Bribe vJass errors are legion

    Ratings:
    +67 / 0 / -0
    Looks like when the optimizer recognizes non-constant things, that it just doesn't compress names of unknown functions. For example, it shortened normal variable names and jasshelper_initstructs1203954385489 but not functions that the ExecuteFunc MIGHT be calling:

    JASS:
    globals
    real v=0
    endglobals
    function InitGlobals takes nothing returns nothing
    endfunction
    function Actions4 takes nothing returns nothing
    endfunction
    function InitTrig_Untitled_Trigger_004 takes nothing returns nothing
    call ExecuteFunc("Actions"+I2S(4))
    endfunction
    function InitCustomTeams takes nothing returns nothing
    call SetPlayerTeam(Player(0),0)
    endfunction
    function main takes nothing returns nothing
    call SetCameraBounds(-1280.+GetCameraMargin(CAMERA_MARGIN_LEFT),-3584.+GetCameraMargin(CAMERA_MARGIN_BOTTOM),1280.-GetCameraMargin(CAMERA_MARGIN_RIGHT),3072.-GetCameraMargin(CAMERA_MARGIN_TOP),-1280.+GetCameraMargin(CAMERA_MARGIN_LEFT),3072.-GetCameraMargin(CAMERA_MARGIN_TOP),1280.-GetCameraMargin(CAMERA_MARGIN_RIGHT),-3584.+GetCameraMargin(CAMERA_MARGIN_BOTTOM))
    call SetDayNightModels("Environment\\DNC\\DNCFelwood\\DNCFelwoodTerrain\\DNCFelwoodTerrain.mdl","Environment\\DNC\\DNCFelwood\\DNCFelwoodUnit\\DNCFelwoodUnit.mdl")
    call NewSoundEnvironment("Default")
    call SetAmbientDaySound("FelwoodDay")
    call SetAmbientNightSound("FelwoodNight")
    call SetMapMusic("Music",true,0)
    call InitBlizzard()
    call ExecuteFunc("e")
    set v=0
    call ExecuteFunc("Actions"+I2S(4))
    endfunction
    function config takes nothing returns nothing
    call SetMapName("TRIGSTR_001")
    call SetMapDescription("TRIGSTR_003")
    call SetPlayers(1)
    call SetTeams(1)
    call SetGamePlacement(MAP_PLACEMENT_USE_MAP_SETTINGS)
    call DefineStartLocation(0,-128.,.0)
    call SetPlayerStartLocation(Player(0),0)
    call SetPlayerColor(Player(0),ConvertPlayerColor(0))
    call SetPlayerRacePreference(Player(0),RACE_PREF_HUMAN)
    call SetPlayerRaceSelectable(Player(0),true)
    call SetPlayerController(Player(0),MAP_CONTROL_USER)
    call SetPlayerSlotAvailable(Player(0),MAP_CONTROL_USER)
    call InitGenericPlayerSlots()
    endfunction
    function e takes nothing returns nothing
    endfunction
     

Share This Page