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

luorax

Invasion in Duskwood
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:

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"


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.


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.


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.



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

luorax

Invasion in Duskwood
Updated; now it mentions[ljass]ExecuteFunc[/ljass]/[ljass]TriggerRegisterVariableEvent[/ljass].
 
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
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.
 
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
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.
  • Varine Varine:
    They aren't cutting my responsibilities or interjecting in my management abilities or anything, it's just stupid shit that comes up. And they don't exactly have people lining up for my job, there's not that many people applying for the positions I hire
  • Varine Varine:
    Eh, whatever. Thanks for listening guys
  • jonas jonas:
    Sure :) Let us know how it ends
  • Varine Varine:
    All of these things will end happily, they're just stressful. And I still lack many good friends that I can go to, and the ones I can are preoccupied with similar things. Thus general chit chat, cuz for some reason TH and Ghan and Tom all actively keep it up.
  • Varine Varine:
    Just gotta keep Miss Mazie up through the week until her shock wears off and she realizes that she still has family all around her, and bossman will do whatever he's going to do and I'll respond appropriately when it happens. Thank you all for the support, I do very much appreciate everyone being here for me through the years
    +3
  • vypur85 vypur85:
    Best of luck Varine!
  • vypur85 vypur85:
    I just gotten myself an offer to work in China. The pay quadruples my current one. Damn.... Not really ready to start a new life there in China.
  • The Helper The Helper:
    I have heard that they pay pretty good to English teachers in China - you would be an expat
  • jonas jonas:
    Cool, what kind of job?
  • Accname Accname:
    I would be careful with jobs in China. They can be hit and miss depending on where in China you go. Places like hong kong / Shengzen / Beijing can be neat. Other places not so much.
  • Accname Accname:
    I would recommend searching for some first person experiences for the city you got the offer in. Especially now when the political situation in China is deteriorating.
  • jonas jonas:
    Accname, long time no see
  • jonas jonas:
    What have you been up to
  • tom_mai78101 tom_mai78101:
    Hey Accname, welcome back.
  • Accname Accname:
    Not much. Working in the Renewable Energy Sector as an IT Consultant. Its okay, but I think I preferred working at the university. It was more relaxed and you met all kinds of crazy people there.
  • vypur85 vypur85:
    I gotten a teaching position for Biology in a college in Wuhan (yes, there)... I suppose it should be fine there (I hope). Many of my ex colleagues are teaching in China as well currently (none in Wuhan though)
  • vypur85 vypur85:
    And I signed the contract already. I guess there's no turning back....
  • jonas jonas:
    @Accname how many hours do you work? I heard in some sectors IT consultants rack up insane hours
  • jonas jonas:
    @vypur85 sounds nice, have fun : )
  • Accname Accname:
    I am supposed to work 40 hrs a week, but I can work more if I like and I will be paid for those hours (as long as I don't go too far, there are laws and company policies, etc)
  • Accname Accname:
    In practice its basically work as much as you like, as long as the job gets done in time.
  • jonas jonas:
    Haha, my job is like that as well... that usually means I have a few 70-80 hours weeks a year, and lots of 20 hours weeks...
  • jonas jonas:
    a few weeks ago, one of my friends basically said "jonas, I received an invitation to submit something to conference X but I'm too lazy to do it and also the conference isn't advanced enough for my high level of research*, why don't you write something? Oh by the way, the deadline is in two weeks. Enjoy!" so I got two 80 hour weeks out of that kind offer. (*of course he didn't say those parts, but it's a better story this way)
  • jonas jonas:
    now I'll have next week off to make up for overtime :p and I'll play some good old gothic 2
  • The Helper The Helper:
    Hope you are enjoying that gothic 2~

    Members online

    No members online now.

    Affiliates

    Hive Workshop NUON Dome
    Top