• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece!🔗 Click here to enter!

(For Each Integer) VS (Player Group)

Status
Not open for further replies.
Level 15
Joined
Oct 29, 2012
Messages
1,474
Hi guys.

So this is a question about efficiency.
Everyone knows that Player Groups (Force Groups) leak, I am using some trigger that picks players from some filtered Player Group (Not all players ofc), and I can't really destroy that group. The question is :

Which of these two is most efficient ?! Knowing that I use this PERIODICALLY.

For Each Integer VS Player Group

============ THIS IS THE EVENT ============
  • Events
    • Time - Every 0.05 seconds of game time
====================== Rivalry Actions =====================
  • For each (Integer i) from 1 to 12, do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Player(i)) slot status) Equal to Is playing
        • Then - Actions
        • Else - Actions
======================= OR ========================
  • Player Group - Pick every player in FilteredForce and do (Actions)
    • Loop - Actions

Thank you very much.
 
The more players the player group has the less efficient it is against a custom loop.
But in your you also use a "unfiltered" integer bounds for loop. So you might have 11 not needed checks in theory.
Then the player group would be cooler.

Basicly it doesn't matter too much. Do what looks cleaner, easier to work with, and what you personaly prefer.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
and I can't really destroy that group.
Noob :xxd:
You can destroy the group, you just dont want to.


As IcemanBo said, it doesnt really matter at this point.
Player groups only contain up to 16 players and looping through that doesnt really have any efficiency problems by far.

The only differences you should be considering is wether you want to adress the players by integer or by handle, wether or not you want to be able to use "Skip Remaining Actions" (aka return), what approach is easier to understand and/or maintain, etc.

(Also FilteredForce isnt really a descriptive name imo... I would call it PlayingPlayers... which can be used by many scripts for localplayer stuff, cinematics, dialogs, etc.)
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
Like mentioned before it depends on the size of the force ( player group ).

Also using the player group outperforms the loop, because you
don't need to check for the player status. Just add only those players to the
player group, which are actually playing.

For good cleanup you can detect the player leave game event and eventually
remove a player from the player group.

Just for the sake completeness:
Even faster is a linked list you loop over and the fastest is a stack.
Linked lists require a lot of special knowledge for GUIers, a stack
would be how we normally code MUI spells.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
The loop approach is inefficient as it has to constantly filter players. An integer approach using an integer list would be as efficient as the player group, in such a case both are viable implementation strategies.

For GUI I would personally recommend the player group approach since it is more readable and easier to understand.
 
Level 15
Joined
Oct 29, 2012
Messages
1,474
The loop approach is inefficient as it has to constantly filter players. An integer approach using an integer list would be as efficient as the player group, in such a case both are viable implementation strategies.

For GUI I would personally recommend the player group approach since it is more readable and easier to understand.

I heard that I can't use waits under the "loop actions" of a Player Group.
I am more into Indexing and stuff so it's easy for me to switch between both methods.
I have even changed every "Group" action (Units, Destructibles, Players) with an indexed Integer loop.

Seems like everything is going fine by now.

Thanks.
 
I heard that I can't use waits under the "loop actions" of a Player Group.

That's right. Enums and boolexprs create a different kind of execution thread than triggeractions and ExecuteFunc. In the latter, you can use waits. World Editor GUI used to only allow one action per enum and to date its GUI does not let you insert actions into conditions. Its original designers had tried to prevent users from getting caught up in bugs like this.
 

Wrda

Spell Reviewer
Level 26
Joined
Nov 18, 2012
Messages
1,893
Use the integer loop. It's cleaner and faster, as a ForForce enumeration will open a new thread for every player. The extra condition in the integer loop will most likely not offset the performance hit of ForForce.
Such a speedfreak...
But yes, integer loop is personally easier to use because it is more readable and faster to use.
By the way, you can add waits "indirectly" in loops of player group or unit groups:
  • Untitled Trigger 001
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • -------- Some Stuff --------
          • Trigger - Run Untitled Trigger 002 <gen> (ignoring conditions)
  • Untitled Trigger 002
    • Events
    • Conditions
    • Actions
      • Wait 1.00 seconds
      • Unit Group - Pick every unit in (Units owned by (Picked player)) and do (Actions)
        • Loop - Actions
          • Unit - Kill (Picked unit)

This kills all units after 1 second, not 1 by 1.
 
Such a speedfreak...
Wait, you say that to me of all people? I'm constantly preaching that readability trumphs speed in most cases and even use struct extends struct despite it spamming trigger evaluations just because it looks neat.

I just answered the TO's question. Looping an integer has many advantages over a ForForce loop, especially as it allows using local variables inside the loop and doesn't block out Waits like a ForForce call does.
 
Status
Not open for further replies.
Top