• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Mapping] How to get the "Compress Names" optimizer function work

Level 16
Joined
Aug 7, 2009
Messages
1,403
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 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.

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 to 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.
Getting rid of those ExecuteFunc/TriggerRegisterVariableEvent calls is simple, you have many options:
  • Use either .evaluate or .evaluate;
  • Evaluate triggers manually;
  • Use this snippet.

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

Attachments

  • Tutorial 1.jpg
    Tutorial 1.jpg
    330.1 KB · Views: 502
  • Tutorial 2.jpg
    Tutorial 2.jpg
    15.7 KB · Views: 384
  • Tutorial 3.jpg
    Tutorial 3.jpg
    17 KB · Views: 360
  • Tutorial 4.jpg
    Tutorial 4.jpg
    156.8 KB · Views: 401
  • Tutorial 5.jpg
    Tutorial 5.jpg
    208.2 KB · Views: 405
  • Tutorial 6.jpg
    Tutorial 6.jpg
    154.3 KB · Views: 372
Last edited:
Level 16
Joined
Aug 7, 2009
Messages
1,403
Well, I wanted to include them too, but they were working fine for me. These didn't break my map:

JASS:
private function Foo takes nothing returns nothing
    call ExecuteFunc(SCOPE_PRIVATE+"Test")
    call ExecuteFunc("Temp"+"Test")
    call TriggerRegisterVariableEvent(CreateTrigger(),SCOPE_PRIVATE,EQUAL,100)
endfunction

Of course if you can tell me in which situations they fail to work, I'll include them too.

I gotta try Ladik's MPQ Editor, looks pretty sweet!

Yea, I've encountered many MPQ editors, this one was the only one that worked so far - and not even it's older versions.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
Those two won't stop your map from opening or loading, it's just that Vexorian's Optimizer compresses the name of the function/variable but does not identify the string concatenators.

There is no quick & dirty fix to make it work. Your only chance is to go through the entire map script and make some manual adjustments. Good luck finding all functions/variables and what their original names were. Oh wait, 99.99% of maps won't be doing this crazy concatenation stuff any way. Unless you use Nestharus' Event library and register triggers instead of boolexpr.
 
Level 16
Joined
Aug 7, 2009
Messages
1,403
Yea, I see - you're right, it was "Foo__Test" passed to the ExecuteFunc call, however that function did not even exist anymore. I just didn't pay attention to it.
So, in that case, it's not the tutorials task to cover them; plus, on the other hand, as Bribe said, noone uses them - they can also be avoided easily.

EDIT: okay, I did mention them in the tutorial, and added a few ways to avoid them. Anything else left I should do?
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
Well, ExecuteFunc with I2S concatenation is a rare but sometimes used utility. I saw a guy who wrote an AI script which used this technique, it was the function name + a unit raw code, but he could have made a long if/then/else block to handle this process so it was not really a problem.

Besides, each ExecuteFunc call has the weight of like 300 function calls. So a huge if/then/else block will still be wildly more efficient.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
I suppose that TriggerRegisterVariableEvent is not that much efficient neither, but the good thing with it : it's a real event, so you can disable the custom event based on it simply by turning off the trigger (no need of extra checks IsTriggerEnabled, or check if the trigger was destroyed, like Event by Jesus4Lyf).
 
Level 12
Joined
Mar 11, 2004
Messages
600
Well, I wanted to include them too, but they were working fine for me. These didn't break my map:

JASS:
private function Foo takes nothing returns nothing
    call ExecuteFunc(SCOPE_PRIVATE+"Test")
    call ExecuteFunc("Temp"+"Test")
    call TriggerRegisterVariableEvent(CreateTrigger(),SCOPE_PRIVATE,EQUAL,100)
endfunction

Of course if you can tell me in which situations they fail to work, I'll include them too.



Yea, I've encountered many MPQ editors, this one was the only one that worked so far - and not even it's older versions.

SCOPE_PRIVATE is a constant. And when Jasshelper sees something like "constant"+"constant", it actually evaluates it to "constantconstant". You would have to test with some variables.
 
Level 16
Joined
Aug 7, 2009
Messages
1,403
Hmm, that's true - forgot about constant inlining.

BTW, considering you're here: why don't you fix the optimizer? These are minor things to fix and yet major problems; just check any of Nestharus' snippets and you'll see why. Many, many people would appreciate it.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
He updated the optimizer to 5, but 5 still has broken compress names... not sure what the bug is if $ is valid for hexadecimal.

Also, for some reason, it adds bj code... I ran it w/ bj optimizer disabled and 0 bj code in the entire map. I looked at the original script and typed bj_ to see if there was any and found none (the war3map.j file in the mpq archive). I looked in the optimized map and typed bj_ and found tons... I also tried it with bj optimizer enabled and the exact same added code was there.

So optimizer now has additional problems ; ). I'm not sure if the old version did this or not as I never looked ;o.


Btw, 5 also failed to remove all of the non handle constants =o.
 
Level 12
Joined
Mar 11, 2004
Messages
600
-- It does , at least I know SCOPE_PREFIX is concatenated to allow the optimizer to work.

Hmm, that's true - forgot about constant inlining.

BTW, considering you're here: why don't you fix the optimizer? These are minor things to fix and yet major problems; just check any of Nestharus' snippets and you'll see why. Many, many people would appreciate it.

Because nobody reports problems the required way. That dude out there would rather find any excuse to begin coding short variable names rather than report anything.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
That dude out there would rather find any excuse to begin coding short variable names rather than report anything.

Believe, I would rather code long. My scripts start out with normal names and are only later changed to short names.


I also recall reporting this 1 year ago with Bribe. After a few months, we just assumed that you were never going to fix it ;p.
 
As for the tutorial, it is nice. However, are the images not showing up for anyone else? Or is it just me?

It's hard and time-consuming.
Fixing it is simple; you have many options:

Heh, this line is a bit confusing. You say it is hard yet simple. ;) Unless you are referring to something else.

I'll approve this soon after confirming a few things.

As for the actual problem with the optimizer, I recommend that someone make a test map with a script that does not work properly after being optimized. (post the options used and everything) That way, if Vexorian wants to fix it, then he can use that as a test map to confirm whether the changes made fix the problem. (unless he does not have wc3 installed anymore)
 
Is there another way to allow the "Compress names" checkbox on but still don't break executeFunc?
How does this identifier stuff work?
All my executeFuncs start with a proper keyword...

If I simply add "Creep_" and "Spell_" to the identifier list (which are my executeFunc prefixes), will it ignore all functions that contain these words?
If so, that would be awesome, because it would save me like 200 kb of map space.
 
Last edited:
Level 16
Joined
Aug 7, 2009
Messages
1,403
As for the tutorial, it is nice. However, are the images not showing up for anyone else? Or is it just me?

Heh, this line is a bit confusing. You say it is hard yet simple. ;) Unless you are referring to something else.

Well, now that you mention it and I read it again, I must admit that it was confusing for sure :) Fixed it.

As for the pictures, well, all I can show you is this: http://img708.imageshack.us/img708/4237/scrcy.png
So yea, they do work for me. They're all attached to the main post, there shouldn't be problems with it in my opinion.
 
Top