• 🏆 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!

Optimize GUI code - how to?

Status
Not open for further replies.
Level 8
Joined
Sep 30, 2012
Messages
205
For now i'm doing GUI, after some more testing and changes i'm going to translate and optimize it into vjass..

however i already wanted to optimize the GUI code a bit now..

So i got some questions:

Is a if-then-else tree like this good?
So basically it will checks for the right condition till it is found?

  • Untitled Trigger 001
    • Events
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Integer Equal to 1
        • Then - Actions
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Integer Equal to 2
            • Then - Actions
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Integer Equal to 3
                • Then - Actions
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Integer Equal to 4
                    • Then - Actions
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • Integer Equal to 5
                        • Then - Actions
                        • Else - Actions
or is this better?
kinda trying to get to my final questions faster, by adding some questions down at the root of the three. Like if integer is bigger than, or smaller.
So the question is can more code, be more efficient?

  • Untitled Trigger 001
    • Events
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Integer Less than or equal to 2
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Integer Greater than 1
            • Then - Actions
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Integer Equal to 2
                • Then - Actions
                • Else - Actions
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Integer Greater than or equal to 3
            • Then - Actions
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Integer Equal to 3
                • Then - Actions
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Integer Equal to 4
                    • Then - Actions
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • Integer Equal to 5
                        • Then - Actions
                        • Else - Actions
and if checking for unit types does the order make a difference?
Like is he counting up? - asking for: if its 'h001', then 'h002' and then 'h003' in that order anyway? So it would be important that i ask for those units also in that order?

otherwise if i ask for 'h003' at start - would he have already checked 'h001' and 'h002' anyway?
 
or now i'm doing GUI, after some more testing and changes i'm going to translate and optimize it into vjass..
You obviously mean JASS here. vJASS is just again an other abstraction of JASS.

If really you really need like 5-6 "elseif"s just check them in a linear way. (in JASS it looks better than in GUI :p)
There is a more efficient way, if you have quite a lot linear checks. You always split the amount of needed checks in middle, but this will get more unreadable and you won't have too much benefits.

But when ever you can, you should try to avoid many nested if/then/else blocks and use a shorter, more readable loop instead... and using indices within.

I'm not really sure I understand your second question about unit type comparisson.
Are you talking about GUI or JASS? Because in GUI you can only compare if two types are equal or not.
In JASS you can use unitTypes like what they actually are (integers). So then you of course also can make comparissons with "<" and ">".
 
Level 8
Joined
Sep 30, 2012
Messages
205
okay thanks good to know i got like 20-30 if-then-else trees

3. i meant if you got 3 custom units and their "raw-data" name is h001, h002 and h003.

should i check them in that order?
like if he would check for h001, and counts up, and its not h001, does the pc then proceeds, still counting up from h001? so it would be faster to get them already in the right order? so is it a bit like teletext?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
There is a more efficient way, if you have quite a lot linear checks. You always split the amount of needed checks in middle, but this will get more unreadable and you won't have too much benefits.
Ah the good old case statement! Too bad JASS has no case statement lol...

Depending on the sort of data being checked and what you want done you could create a data fed system to manage it. It might have more overhead but it will scale a lot better and be maintainable.

For example, if you testing unit types for specific values then you could use a hashtable where the unit type is an index and the value stored is your value. Hashtables have very good O(1) style performance up to a reasonable number (several thousand) of entries. This will be far faster than any kind of tree structure of comparisons as the JASS interpreter overhead is so high.

You can represent dynamic code as triggers. Speed wise it does have some overhead running the trigger but this is highly flexible and often more scalable. You can pass arguments to the dynamic code using global variables as registers as WC3 is single threaded so has well defined execution order with no pre-emptive capabilities.
 
Status
Not open for further replies.
Top