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

luorax

Invasion in Duskwood
Reaction score
67
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:
attachment.php

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"

attachment.php

3, Open the generated script file. Natives must be directly under global declaration, after the keyword [ljass]endglobals[/ljass]. 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.

attachment.php

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.

attachment.php

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.

attachment.php

attachment.php

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 [ljass].evaluate/.execute[/ljass] functions
  • Evaluate triggers manually.
  • Use this snippet.

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

Attachments

  • Tutorial 6.jpg
    Tutorial 6.jpg
    154.3 KB · Views: 842
  • Tutorial 5.jpg
    Tutorial 5.jpg
    208.2 KB · Views: 855
  • Tutorial 4.jpg
    Tutorial 4.jpg
    156.8 KB · Views: 818
  • Tutorial 3.jpg
    Tutorial 3.jpg
    17 KB · Views: 813
  • Tutorial 2.jpg
    Tutorial 2.jpg
    15.7 KB · Views: 803
  • Tutorial 1.jpg
    Tutorial 1.jpg
    330.1 KB · Views: 836

luorax

Invasion in Duskwood
Reaction score
67
Updated; now it mentions[ljass]ExecuteFunc[/ljass]/[ljass]TriggerRegisterVariableEvent[/ljass].
 

Laiev

Hey Listen!!
Reaction score
188
Attach the images here and use it, it don't work using the attachment of Hive.
 

luorax

Invasion in Duskwood
Reaction score
67
Well, they worked fine for me - but okay, why not? I changed it.
 

Nestharus

o-o
Reaction score
84
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.
 

Bribe

vJass errors are legion
Reaction score
67
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.
 

Nestharus

o-o
Reaction score
84
So will it compress 0 function names?
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.

Because my save/load stuff does use ExecuteFunc with non constant function names >.<.
 

Bribe

vJass errors are legion
Reaction score
67
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(&quot;Actions&quot;+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(&quot;Environment\\DNC\\DNCFelwood\\DNCFelwoodTerrain\\DNCFelwoodTerrain.mdl&quot;,&quot;Environment\\DNC\\DNCFelwood\\DNCFelwoodUnit\\DNCFelwoodUnit.mdl&quot;)
call NewSoundEnvironment(&quot;Default&quot;)
call SetAmbientDaySound(&quot;FelwoodDay&quot;)
call SetAmbientNightSound(&quot;FelwoodNight&quot;)
call SetMapMusic(&quot;Music&quot;,true,0)
call InitBlizzard()
call ExecuteFunc(&quot;e&quot;)
set v=0
call ExecuteFunc(&quot;Actions&quot;+I2S(4))
endfunction
function config takes nothing returns nothing
call SetMapName(&quot;TRIGSTR_001&quot;)
call SetMapDescription(&quot;TRIGSTR_003&quot;)
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
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top