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

How to reduce lag, "many units move to"

Status
Not open for further replies.
Level 1
Joined
Jun 13, 2008
Messages
132
Hi there, I'm making a map and units spawn in different buildings and at that moment they are ordered to move to the objective, I'm using "TempPoint" variables and the custom script to remove the lag of leaks, but the more units are ordered, the more lag, I would like to know if there is a better system to make them move to the objective.
In other games I had a different system to move units, a "TempGroup" was set and cleaned with the script every 0,03 seconds, units that didn't have the "Move to" buff were taken inside and a "TempUnit" randomly selected from the group was chosen and a 5 second buff was applied to that unit and at that moment I ordered it to go to the objective. I would like to know what do you think about it.
Finally, I would like to know how many units a map should have, to balance the respawn timer.
 
Level 12
Joined
May 22, 2015
Messages
1,051
I think around 80 or so units for a player chokes the pathing algorithm. Basically, each player is limited by only their own units (it is just how the unit pathing works - I could go into more detail if you want). You can see this if one player has a couple hundred units trying to move and then you move some of your own units and they are fine. You will see it where units take turns to move and they spend a long time just looking where they want to go next.

Is the objective always the same point? You could save this point into a variable called ObjectivePoint at the start of the map and never remove that point. Just reuse it every time. I have several points like this in my own map.

In my own map, the enemy player (computer controlled) has a limit of 100 units or something like that (I may have lowered it a little). It just stops spawning units when it hits the limit. Only bosses are allowed to spawn if the unit limit is reached.

You can increase this unit cap by adding another player for the spawning units (basically splitting the pathing to two players), but this could force a major refactor of all your triggers. I know this is a problem in my map, but I think it's better to try to use less units as much as possible just as a general rule.

Anyway, I do not find such large lag happening when I tell lots of units to move. It is more likely a problem from spawning the units (which causes lag). I think the lag from spawning units can also be a problem if the units are spawning on top of each other one at a time. I think it needs to do a lot of checking to see where the unit can be placed.
 
Level 1
Joined
Jun 13, 2008
Messages
132
I think around 80 or so units for a player chokes the pathing algorithm. Basically, each player is limited by only their own units (it is just how the unit pathing works - I could go into more detail if you want). You can see this if one player has a couple hundred units trying to move and then you move some of your own units and they are fine. You will see it where units take turns to move and they spend a long time just looking where they want to go next.

Is the objective always the same point? You could save this point into a variable called ObjectivePoint at the start of the map and never remove that point. Just reuse it every time. I have several points like this in my own map.

In my own map, the enemy player (computer controlled) has a limit of 100 units or something like that (I may have lowered it a little). It just stops spawning units when it hits the limit. Only bosses are allowed to spawn if the unit limit is reached.

You can increase this unit cap by adding another player for the spawning units (basically splitting the pathing to two players), but this could force a major refactor of all your triggers. I know this is a problem in my map, but I think it's better to try to use less units as much as possible just as a general rule.

Anyway, I do not find such large lag happening when I tell lots of units to move. It is more likely a problem from spawning the units (which causes lag). I think the lag from spawning units can also be a problem if the units are spawning on top of each other one at a time. I think it needs to do a lot of checking to see where the unit can be placed.

That is gold to me, all the buildings are from each player, but the spawned units are only for player 11 and 12, so that must be what produces "lag" in their behaviours.
And related to the spawning, I should remake the system to spawn the units in intervals of 0,03, not instantly? might be tricky...

So I need to create the units for the players and make them ignore any order from the player so they go like if they had AI.
 
Level 12
Joined
May 22, 2015
Messages
1,051
That is gold to me, all the buildings are from each player, but the spawned units are only for player 11 and 12, so that must be what produces "lag" in their behaviours.
And related to the spawning, I should remake the system to spawn the units in intervals of 0,03, not instantly? might be tricky...

So I need to create the units for the players and make them ignore any order from the player so they go like if they had AI.

0.03 probably won't help too much. The units before them would still be in the way. I think if you spawn them all together, it should be okay. I haven't seen or done any speed tests on it though. Maybe there are just too many in general.

How many units are you making? Most likely you need to have less units.

I am not sure how to prevent players from giving orders to their units. I would probably just use a separate team like you are as well. Others may have a good solution, though.
 
Level 1
Joined
Jun 13, 2008
Messages
132
Well if you order a unit every 0.03 seconds you're doing it wrong.

Order once per unit when they are spawned. If that lags you're also doing something wrong, in which case you should post the triggers used.

You didn't understand, I had a trigger that gives orders to units that do not have a buff, the buff that is given when I give orders and lasts 5 seconds, and it works wonders, but as usual, I try to improve my knowledge and create new mechanisms or use ones that other people did.
 
Level 16
Joined
Mar 27, 2011
Messages
1,349
Not sure what exactly is causing your lag so I'll mention a couple of points:


  • If too many units from the same player are moving, they will begin to stutter. The more units moving at a time, the more they will stutter. This is not lag, but a restriction Warcraft 3 makes. To fix this, either make less units move at a time, or add more players to the game to move these units.

  • One map I made involved me moving a lot (maybe 95 units) every 5 seconds to a random spot within a region. This caused an annoying lag spike every 5 seconds. I had to optimize my code to fix this lag. The action "Pick every unit within region" must take a lot of processing power. So I saved all the necessary units into a group when they were created.

    • Unit Group - Pick every unit in Enemies and do (Actions)
      • Loop - Actions
        • Set TempPoint = (Random point in Battle Order <gen>)
        • Unit - Order (Picked unit) to Patrol To TempPoint
        • Custom script: call RemoveLocation (udg_TempPoint)
    See here I'm not picking a new unit group, I'm just picking an already created unit group. This fixed the lag problem. I also had to make a trigger to remove units from this group when they died.
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
You didn't understand, I had a trigger that gives orders to units that do not have a buff, the buff that is given when I give orders and lasts 5 seconds, and it works wonders, but as usual, I try to improve my knowledge and create new mechanisms or use ones that other people did.

If you order a unit to attack move to a location you only need to order once because it will attack everything on the way automatically. So doing it every 5 seconds is still a bad way.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,191
WC3 path finder can only manage so many units moving per player at a give time. I think it issues 1 micro move order every internal frame. How many units can move is dependant on how many unit on unit collisions occur (cancels a micro move order) and how complex the pathing being moved through is (complex pathing can cause shorter micro move orders). If too many units are moving at once most will appear to stand around doing nothing and only occasionally move as they are waiting for their turn to have a micro move order issued.

Issuing a move order to a unit that is moving cancels its current micro move order meaning it needs to wait until the path finder next visits it to begin moving again. This means that if you were to order a few units to move every 0.01 seconds or so they might end up standing around forever. This applies to players as well, with the rate move orders are issued to a group directly affecting average group speed.

You can test this yourself by racing two peasants to around the same location. One of them you order and discard, the other you repeatedly order to the location. The one you ordered and discarded will gradually gain a lead over the one you continuously order, despite both units having the same speed.

If you are referring to lag as in low frame rate then that is the result of the game failing to be scheduled in real time. In order to keep the game advancing at the same speed it will start skipping frame render ticks (drop frames) so that the CPU time can be devoted to catching up the game state. Eventually when the system becomes completely unschedulable the game is forced to drop practically every frame (I think it still forces one to be rendered every second or so) and even game state advancement slows down. The only solution to this is to reduce the computational complexity you require so that less computational resources are required to update the game state. Basically do less stuff or do stuff more efficiently.

When spawning units, the freshly created unit is subjected to displacement so that it tries not to spawn inside something. This displacement job has a very unpredictable duration and can be extremely long compared with other jobs. If you create 20 or 50 units which have collision on top of each other at the same location it is almost guaranteed to cause multiple frames to be dropped as the game tries to displace them all. However if you were to create these 20 or 50 units uniformly distributed over a huge area then there is a good chance that no frames will be dropped at all. As such a good trick with spawns is to make them occur in areas (low chance of collision, and even then displacement is usually quick to resolve) or to spread them over time allowing the spawn site to clear.

There is also a problem with state complexity. If your map has thousands of units on it at a time it is highly likely to suffer from bad performance. Not only do the large number of units potentially make some unit related jobs longer to execute, but each unit might result in new jobs being scheduled. This makes the some total of the task take longer and longer until real time scheduling is no longer possible so frames have to be dropped. The only solution to this is to simplify game state, using less units, creating simpler jobs etc.

When spawning units you should consider a reasonable limit. A common problem I see is that if players fail to kill units fast enough, units start to "backlog" so the number of active units on the map can reach hundreds, thousands and eventually even crash the slide show called a game. If these spawns were limited to 100 or 200 then the map would remain quite playable and probably even have a good frame rate. Of course you do not want to reward players for playing badly, so consider punishing them if they hit the spawn limit by making some of the spawns better, or imposing a time limit. Also avoid cases where progression means more. Spawning 500 Footman for a late game wave is asking for performance problems with both the path finder and frame rate. On the other hand spawning 50 knights or 5 super knights will barely tax computational resources at all.

In RPGs, especially those using inflated terrain sizes like 480*480, it is important that you only spawn units that are directly interactable by the player. Having thousands of units filling your huge land will cause the game to crawl and worse is that most of the time players may never interact with them during the entire session. Instead spawn units only in areas that players are actually using. When players leave an area for an extended time consider removing the units to free up resources. You might find your massive 2,000+ unit RPG falls down to under 100 units active at any given time with out any change in user experience, great computational savings.
 
Last edited:
Level 1
Joined
Jun 13, 2008
Messages
132
My map is about building buildings that spawn units every set ammount of time, two teams of 5 players and 50 max food (max buildings you can have), also that food is reduced for every player in the same team, for balance purposes and lag, a king has to be defeated to win the game, it starts with a timer of 15 minutes and when this reaches 0, both kings start moving towards the other, this forces the end of the game. Of course you have a hero to help too, but most of your sucess depend on your strategy.

Main problem was that all the summoned units were for player 11 and 12, that caused them to behave slowly, but now, I'm going to remake my respawn system. For instance, I'm going to make the buildings spawn the units only when they have full mana and it is in a specific minute of the game and units are going to be created in intervals of 0,03 seconds with no given order but an aura that slows them in 100% up to the second specific minute when all the auras that slow are going to be removed. Since auras do not make units forget their orders, compared with stuns, I can make my 0,03 orders, checking if the units have the buff of course, so when the aura is removed they will go to where they are supposed to go. Other important aspect of giving the order this way is that if the units are stunned in the way, they will forget to go to the objective, but this way they are going to get the order again once the buff dispels.

What do you think?
 
Level 12
Joined
May 22, 2015
Messages
1,051
My map is about building buildings that spawn units every set ammount of time, two teams of 5 players and 50 max food (max buildings you can have), also that food is reduced for every player in the same team, for balance purposes and lag, a king has to be defeated to win the game, it starts with a timer of 15 minutes and when this reaches 0, both kings start moving towards the other, this forces the end of the game. Of course you have a hero to help too, but most of your sucess depend on your strategy.

Main problem was that all the summoned units were for player 11 and 12, that caused them to behave slowly, but now, I'm going to remake my respawn system. For instance, I'm going to make the buildings spawn the units only when they have full mana and it is in a specific minute of the game and units are going to be created in intervals of 0,03 seconds with no given order but an aura that slows them in 100% up to the second specific minute when all the auras that slow are going to be removed. Since auras do not make units forget their orders, compared with stuns, I can make my 0,03 orders, checking if the units have the buff of course, so when the aura is removed they will go to where they are supposed to go. Other important aspect of giving the order this way is that if the units are stunned in the way, they will forget to go to the objective, but this way they are going to get the order again once the buff dispels.

What do you think?

That sounds really confusing.

I am still confused about the "0,03 orders". Do you mean you are telling the units to do something every 0.03 seconds, as in over 30 times a second? That is almost guaranteed to not be necessary and actually would contribute to the units stuttering (telling them to do something again might cause them to recalculate their pathing).

The auras part sounds like it could work depending on what you are trying to do. Does this cause the units to pile up and then move out? Is that what you want? Unless you are spawning many many units, it shouldn't be a problem to have lots of units all moving. I don't know if immobilizing them would stop them from choking up the pathing either.
 
Level 11
Joined
Jun 2, 2013
Messages
613
For spawning the way you are talking about couldn't you just use the "Unit - Enter's Playable Map Area" event and issue the patrol/move/attack order to the entering unit? Just add the condition for the owner of entering unit = player 11 or 12

You could also have a trigger that runs if a unit owned by player 11 or 12 are issued the stop order, to re-order their movement.
 
Status
Not open for further replies.
Top