| 07-05-2004, 04:18 AM | #1 |
I have a map that im messing with possible pathing triggers/summoning triggers to reduce the lag as much as possible. Im experiencing lag everytime I summon. Any ideas? Also. There can be as much as 1 - 500 units on the map. But EVERY time i summon, it creates lag. Code:
Pathing
Events
Time - Every 120.00 seconds of game time
Conditions
Actions
For each (Integer A) from 1 to 5, do (Actions)
Loop - Actions
Unit Group - Pick every unit in (Units owned by Player 11 (Dark Green) matching ((((Matching unit) is A structure) Equal to False) and ((Custom value of (Matching unit)) Equal to (100 + (Integer A))))) and do (Actions)
Loop - Actions
Unit - Order (Picked unit) to Attack-Move To (Center of Team 2 Castle <gen>)
Unit - Set the custom value of (Picked unit) to ((Custom value of (Matching unit)) - 100)
Unit Group - Pick every unit in (Units owned by Player 11 (Dark Green) matching ((((Matching unit) is A structure) Equal to False) and ((Custom value of (Matching unit)) Equal to (300 + (Integer A))))) and do (Actions)
Loop - Actions
Unit - Order (Picked unit) to Attack-Move To (Center of Team 2 Castle <gen>)
Unit - Set the custom value of (Picked unit) to ((Custom value of (Matching unit)) - 300)
For each (Integer B) from 6 to 10, do (Actions)
Loop - Actions
Unit Group - Pick every unit in (Units owned by Player 12 (Brown) matching ((((Matching unit) is A structure) Equal to False) and ((Custom value of (Matching unit)) Equal to (100 + (Integer A))))) and do (Actions)
Loop - Actions
Unit - Order (Picked unit) to Attack-Move To (Center of Team 1 Castle <gen>)
Unit - Set the custom value of (Picked unit) to ((Custom value of (Matching unit)) - 100)
Unit Group - Pick every unit in (Units owned by Player 12 (Brown) matching ((((Matching unit) is A structure) Equal to False) and ((Custom value of (Matching unit)) Equal to (300 + (Integer B))))) and do (Actions)
Loop - Actions
Unit - Order (Picked unit) to Attack-Move To (Center of Team 1 Castle <gen>)
Unit - Set the custom value of (Picked unit) to ((Custom value of (Matching unit)) - 300)Code:
Debug Pathing
Events
Unit - A unit enters Whole Battlefield <gen>
Conditions
Actions
Trigger - Run Pathing <gen> (ignoring conditions)Code:
Detecting Idle
Events
Time - Every 0.50 seconds of game time
Conditions
Actions
Unit Group - Pick every unit in (Units owned by Player 11 (Dark Green) matching ((((Matching unit) is A structure) Equal to False) and (((Current order of (Matching unit)) Equal to (Order(stop))) or ((Current order of (Matching unit)) Equal to (Order(idle)))))) and do (Actions)
Loop - Actions
Unit - Set the custom value of (Picked unit) to (300 + (Custom value of (Picked unit)))
Unit Group - Pick every unit in (Units owned by Player 12 (Brown) matching ((((Matching unit) is A structure) Equal to False) and (((Current order of (Matching unit)) Equal to (Order(stop))) or ((Current order of (Matching unit)) Equal to (Order(idle)))))) and do (Actions)
Loop - Actions
Unit - Set the custom value of (Picked unit) to (300 + (Custom value of (Picked unit)))Code:
Summoning 2
Events
Time - Every 0.30 seconds of game time
Conditions
Actions
Set PlayerUS[1] = (Units in Red 1 <gen>((((Matching unit) is A melee attacker) Equal to True) or (((Matching unit) is A ranged attacker) Equal to True)))
Set PlayerUS[2] = (Units in Blue 2 <gen>((((Matching unit) is A melee attacker) Equal to True) or (((Matching unit) is A ranged attacker) Equal to True)))
Set PlayerUS[3] = (Units in Teal 3 <gen>((((Matching unit) is A melee attacker) Equal to True) or (((Matching unit) is A ranged attacker) Equal to True)))
Set PlayerUS[4] = (Units in Purple 4 <gen>((((Matching unit) is A melee attacker) Equal to True) or (((Matching unit) is A ranged attacker) Equal to True)))
Set PlayerUS[5] = (Units in Yellow 5 <gen>((((Matching unit) is A melee attacker) Equal to True) or (((Matching unit) is A ranged attacker) Equal to True)))
Unit Group - Pick every unit in PlayerUS[1] and do (Actions)
Loop - Actions
Unit - Move (Picked unit) instantly to (Random point in Team 1 Castle <gen>)
Unit - Change ownership of (Picked unit) to Player 11 (Dark Green) and Retain color
Unit - Set the custom value of (Picked unit) to 101
Unit Group - Pick every unit in PlayerUS[2] and do (Actions)
Loop - Actions
Unit - Move (Picked unit) instantly to (Random point in Team 1 Castle <gen>)
Unit - Change ownership of (Picked unit) to Player 11 (Dark Green) and Retain color
Unit - Set the custom value of (Picked unit) to 102
Unit Group - Pick every unit in PlayerUS[3] and do (Actions)
Loop - Actions
Unit - Move (Picked unit) instantly to (Random point in Team 1 Castle <gen>)
Unit - Change ownership of (Picked unit) to Player 11 (Dark Green) and Retain color
Unit - Set the custom value of (Picked unit) to 103
Unit Group - Pick every unit in PlayerUS[4] and do (Actions)
Loop - Actions
Unit - Move (Picked unit) instantly to (Random point in Team 1 Castle <gen>)
Unit - Change ownership of (Picked unit) to Player 11 (Dark Green) and Retain color
Unit - Set the custom value of (Picked unit) to 104
Unit Group - Pick every unit in PlayerUS[5] and do (Actions)
Loop - Actions
Unit - Move (Picked unit) instantly to (Random point in Team 1 Castle <gen>)
Unit - Change ownership of (Picked unit) to Player 11 (Dark Green) and Retain color
Unit - Set the custom value of (Picked unit) to 105
Set PlayerUS[6] = (Units in Orange 6 <gen>((((Matching unit) is A melee attacker) Equal to True) or (((Matching unit) is A ranged attacker) Equal to True)))
Set PlayerUS[7] = (Units in Green 7 <gen>((((Matching unit) is A melee attacker) Equal to True) or (((Matching unit) is A ranged attacker) Equal to True)))
Set PlayerUS[8] = (Units in Pink 8 <gen>((((Matching unit) is A melee attacker) Equal to True) or (((Matching unit) is A ranged attacker) Equal to True)))
Set PlayerUS[9] = (Units in Gray 9 <gen>((((Matching unit) is A melee attacker) Equal to True) or (((Matching unit) is A ranged attacker) Equal to True)))
Set PlayerUS[10] = (Units in Light Blue 10 <gen>((((Matching unit) is A melee attacker) Equal to True) or (((Matching unit) is A ranged attacker) Equal to True)))
Unit Group - Pick every unit in PlayerUS[6] and do (Actions)
Loop - Actions
Unit - Move (Picked unit) instantly to (Random point in Team 2 Castle <gen>)
Unit - Change ownership of (Picked unit) to Player 12 (Brown) and Retain color
Unit - Set the custom value of (Picked unit) to 106
Unit Group - Pick every unit in PlayerUS[7] and do (Actions)
Loop - Actions
Unit - Move (Picked unit) instantly to (Random point in Team 2 Castle <gen>)
Unit - Change ownership of (Picked unit) to Player 12 (Brown) and Retain color
Unit - Set the custom value of (Picked unit) to 107
Unit Group - Pick every unit in PlayerUS[8] and do (Actions)
Loop - Actions
Unit - Move (Picked unit) instantly to (Random point in Team 2 Castle <gen>)
Unit - Change ownership of (Picked unit) to Player 12 (Brown) and Retain color
Unit - Set the custom value of (Picked unit) to 108
Unit Group - Pick every unit in PlayerUS[9] and do (Actions)
Loop - Actions
Unit - Move (Picked unit) instantly to (Random point in Team 2 Castle <gen>)
Unit - Change ownership of (Picked unit) to Player 12 (Brown) and Retain color
Unit - Set the custom value of (Picked unit) to 109
Unit Group - Pick every unit in PlayerUS[10] and do (Actions)
Loop - Actions
Unit - Move (Picked unit) instantly to (Random point in Team 2 Castle <gen>)
Unit - Change ownership of (Picked unit) to Player 12 (Brown) and Retain color
Unit - Set the custom value of (Picked unit) to 110 |
| 07-05-2004, 07:57 AM | #2 |
Code:
Debug Pathing
Events
Unit - A unit enters Whole Battlefield <gen>
Conditions
Actions
Trigger - Run Pathing <gen> (ignoring conditions)And whole battlefield is playable map? Then this trigger will repeat hell of a lot when ppl create units and stuff? But, if "Whole battlefield" is not what i think, nvm. Another thing you could try is just spawning them with a slight delay between each. Instead of BOOM 500 units, take 5 seconds and create one unit each 0.01 sec. Dunno if thats better though.... Or maybe if you explani what you have thought (sp?) about all this? I know what they do, but i dunno what YOU made it for.... Why all this altering custom values? |
| 07-05-2004, 08:13 AM | #3 |
This is not related to your problem, but you should really use some loops, it would shorten your code considerably, making it easier to read. For example, in the last trigger, where you have 4 lines of code for every player, make a "for loop integer A" instead that goes from 1 to 5 and replace "PlayerUS[1]", "PlayerUS[2]", ... with PlayerUS[(Integer A)], and the "set custom value" to "arithmetic function: (100 + (Integer A))". Bam, you compress 25 lines of code into 6. But anyway, your triggers seem laggy, all that picking every unit... I don't know how many units actually get picked every time, but if you run that trigger whenever a unit comes into the game... Also, you must read a tutorial on memory leaks (look in the tutorials section, cubasis has written a good tutorial on the topic), there's quite some of them in your triggers (namely, unit group objects (pick every unit...) and location objects (center of region...)). |
| 07-07-2004, 06:21 AM | #4 | |
Quote:
|
| 07-07-2004, 02:50 PM | #5 |
Not as many as you could. Loop functions cut down on the amount of raw text that goes into your triggers therefore making your maps smaller while still using pretty much the same processing time as writing it out manually. If you need nested loop,s you can always use the integer B loop. That last trigger is probably the one causing trouble because you're picking and issuing orders to basically all the units in the map every 0.3 seconds... That's the equivalent of bashing your skull into a wall 300 times a minute. |
| 07-07-2004, 09:35 PM | #6 |
You use a lot of Unit groups, they must be destroyed, after each of the Unit group functions insert this line of custom scrypt: Custom script: call DestroyGroup(GetLastCreatedGroup()) I think this shall reduce your lag. |
| 07-09-2004, 01:25 AM | #7 | |
Quote:
uhh. I don't think so. It issues orders to units that players are creating (Summoning). So every unit that a player creates will be sent to their castle, changed color, added a custom value (their player number). Then it reselects the new units that the player keeps summoning basicly every .3 seconds. |
| 07-09-2004, 05:47 AM | #8 |
.3 seconds is way too fast. Fiddle with the time and you'll find that something longer works just as well. And you ARE killing a lot of CPU time with those unit groups. |
| 07-09-2004, 06:48 AM | #9 |
If it is just meant for units that the players summon, couldn't you just run the trigger whenever a player summons a unit and move only that specific unit about, instead of creating all those unit groups? And also, do check out a tutorial on removing memory leaks. Sure, leaking an object handle will only waste a byte or two of memory, but with periodic triggers, that quickly mounts up to precious megabytes. |
| 07-09-2004, 08:27 PM | #10 |
I never really understand why do i have to set unit groups to variables til now. I compared it to windows. If you use a program a lot like WC3, the game is gonna get more and more fragments making the game run slower or the computer go slower. So everytime the trigger runs, everytime you run that option, its gonna make the map run slower and slower every single time it runs. So deleting it will make it not run slower and slower every single time it runs because its like you are using a different option every time. Im setting Unit groups to a variable, but will this action leak? "Pick every unit in Pathing(1) and issue picked unit to Castle[2]" AND call DestroyGroup( udg_Pathing[1] ) is that right ? Im not to positive on the array if its right. I couldn't find anything in Jass that had an array so I had to guess. Heres the new Pathing trigger. Code:
Pathing
Events
Time - Every 120.00 seconds of game time
Conditions
Actions
For each (Integer A) from 1 to 5, do (Actions)
Loop - Actions
Set Pathing[1] = (Units owned by Player 11 (Dark Green) matching ((((Matching unit) is A structure) Equal to False) or ((Custom value of (Matching unit)) Equal to (100 + (Integer A)))))
Set TeamCastle[2] = Team 2 Castle <gen>
Unit Group - Pick every unit in Pathing[1] and do (Actions)
Loop - Actions
Unit - Order (Picked unit) to Attack-Move To (Center of TeamCastle[2])
Unit - Set the custom value of (Picked unit) to ((Custom value of (Picked unit)) - 100)
Custom script: call DestroyGroup( udg_Pathing[1] )
Custom script: call RemoveRect( udg_TeamCastle[2] )
Set Pathing[2] = (Units owned by Player 11 (Dark Green) matching ((((Matching unit) is A structure) Equal to False) or ((Custom value of (Matching unit)) Equal to (300 + (Integer A)))))
Set TeamCastle[2] = Team 2 Castle <gen>
Unit Group - Pick every unit in Pathing[2] and do (Actions)
Loop - Actions
Unit - Order (Picked unit) to Attack-Move To (Center of TeamCastle[2])
Unit - Set the custom value of (Picked unit) to ((Custom value of (Picked unit)) - 300)
Custom script: call DestroyGroup( udg_Pathing[2] )
Custom script: call RemoveRect( udg_TeamCastle[2] )
For each (Integer B) from 6 to 10, do (Actions)
Loop - Actions
Set Pathing[3] = (Units owned by Player 12 (Brown) matching ((((Matching unit) is A structure) Equal to False) or ((Custom value of (Matching unit)) Equal to (100 + (Integer B)))))
Set TeamCastle[1] = Team 1 Castle <gen>
Unit Group - Pick every unit in Pathing[3] and do (Actions)
Loop - Actions
Unit - Order (Picked unit) to Attack-Move To (Center of TeamCastle[1])
Unit - Set the custom value of (Picked unit) to ((Custom value of (Picked unit)) - 100)
Custom script: call DestroyGroup( udg_Pathing[3] )
Custom script: call RemoveRect( udg_TeamCastle[1] )
Set Pathing[4] = (Units owned by Player 12 (Brown) matching ((((Matching unit) is A structure) Equal to False) or ((Custom value of (Matching unit)) Equal to (300 + (Integer B)))))
Set TeamCastle[1] = Team 1 Castle <gen>
Unit Group - Pick every unit in Pathing[4] and do (Actions)
Loop - Actions
Unit - Order (Picked unit) to Attack-Move To (Center of TeamCastle[1])
Unit - Set the custom value of (Picked unit) to ((Custom value of (Picked unit)) - 300)
Custom script: call DestroyGroup( udg_Pathing[4] )
Custom script: call RemoveRect( udg_TeamCastle[1] )New Summoning Trigger Code:
Summoning 3
Events
Time - Every 1.50 seconds of game time
Conditions
Actions
Set ColorRect[1] = Red 1 <gen>
Set ColorRect[2] = Blue 2 <gen>
Set ColorRect[3] = Teal 3 <gen>
Set ColorRect[4] = Purple 4 <gen>
Set ColorRect[5] = Yellow 5 <gen>
Set ColorRect[6] = Orange 6 <gen>
Set ColorRect[7] = Green 7 <gen>
Set ColorRect[8] = Pink 8 <gen>
Set ColorRect[9] = Gray 9 <gen>
Set ColorRect[10] = Light Blue 10 <gen>
Set TeamCastle[1] = Team 1 Castle <gen>
Set TeamCastle[2] = Team 2 Castle <gen>
For each (Integer C) from 1 to 5, do (Actions)
Loop - Actions
Set PlayerUS[C] = (Units in ColorRect[C]((((Matching unit) is A melee attacker) Equal to True) or (((Matching unit) is A ranged attacker) Equal to True)))
Unit Group - Pick every unit in PlayerUS[C] and do (Actions)
Loop - Actions
Unit - Move (Picked unit) instantly to (Random point in TeamCastle[1])
Unit - Change ownership of (Picked unit) to Player 11 (Dark Green) and Retain color
Unit - Set the custom value of (Picked unit) to (100 + C)
Custom script: call DestroyGroup( udg_PlayerUS[udg_C] )
Custom script: call RemoveRect( udg_TeamCastle[1] )
For each (Integer D) from 6 to 10, do (Actions)
Loop - Actions
Set PlayerUS[C] = (Units in ColorRect[C]((((Matching unit) is A melee attacker) Equal to True) or (((Matching unit) is A ranged attacker) Equal to True)))
Unit Group - Pick every unit in PlayerUS[C] and do (Actions)
Loop - Actions
Unit - Move (Picked unit) instantly to (Random point in TeamCastle[2])
Unit - Change ownership of (Picked unit) to Player 12 (Brown) and Retain color
Unit - Set the custom value of (Picked unit) to (100 + D)
Custom script: call DestroyGroup( udg_PlayerUS[udg_D] )
Custom script: call RemoveRect( udg_TeamCastle[2] ) |
| 07-09-2004, 10:20 PM | #11 |
Nono, don't use region variables, you don't need those. The regions are static, they are predefined, they aren't going anywhere. It's the points we have to worry about, like (Center of TeamCastle[2]), that's a point object, and because it doesn't exist yet, the game makes it, and that's what leaks in the end, the objects that the game makes while playing. The regions, however, are there from the start of the map, and whenever you reference them, there's no leak, because the game doesn't make a new object. Next, I noticed that you create and destroy a lot without needing to. You use variables to point to your object so that you can destroy it when you don't need it anymore. However, in your case, you need these objects constantly; the point objects you use are the same all the time (because you use a different variable for every object). That means there's no need to destroy them and recreate them constantly. You can just set your point variables at map initialization and then use the same objects throughout the game. You only need to destroy the object when you're done with it, when you want to put a different value into your variable. It would be different, of course, if you had only a single point variable, like tempPoint. Then, you would need to destroy the objects right after you used them, because you would be using the variable for something else after that. It's different with unit groups, because they are changing. You must destroy them, because the next time you use one, it won't be the same group, you'll be making a new one. Code:
Set Pathing[1] = (Units owned by Player 11 (Dark Green) matching ((((Matching unit) is A structure) Equal to False) or ((Custom value of (Matching unit)) Equal to (100 + (Integer A)))))
Set TeamCastle[2] = Team 2 Castle <gen>
Unit Group - Pick every unit in Pathing[1] and do (Actions)
Loop - Actions
Unit - Order (Picked unit) to Attack-Move To (Center of TeamCastle[2])
Unit - Set the custom value of (Picked unit) to ((Custom value of (Picked unit)) - 100)
Custom script: call DestroyGroup( udg_Pathing[1] )
Custom script: call RemoveRect( udg_TeamCastle[2] )And one more thing, it happens in more than one place: you destroy the objects too soon, because the actions to destroy them are in the "pick every unit..." loop, so they will be destroyed already when the game picks the first unit, instead of at the end, when the game is done with the whole group. This is how it should look like (with also corrected the point-stuff): Code:
[i]Do this in another trigger, at map initialization, along with the other points:[/i]
Set pointVariableTeamCastle[2] = Center of (Team 2 Castle <gen>)
[i]Correction of the part of your trigger (the unit group variable "pathing" doesn't need to be an array, you can use the same variable for all unitgroups, because you destroy them right away and then your variable is free):[/i]
Set Pathing = (Units owned by Player 11 (Dark Green) matching ((((Matching unit) is A structure) Equal to False) or ((Custom value of (Matching unit)) Equal to (100 + (Integer A)))))
Unit Group - Pick every unit in Pathing and do (Actions)
Loop - Actions
Unit - Order (Picked unit) to Attack-Move To pointVariableTeamCastle[2]
Unit - Set the custom value of (Picked unit) to ((Custom value of (Picked unit)) - 100)
Custom script: call DestroyGroup( udg_Pathing ) |
| 07-10-2004, 06:57 AM | #12 |
If you are still having other problems with lag on your maps, there are other "destroy functions", like destroytrigger(use the name of the trigger), and destroy location(for points, use getlastcreatedlocation, or a variable). |
| 07-10-2004, 02:58 PM | #13 |
I can't really understand why people have such problems with spawning, It's the most simple thing ever! It seems to me that you are making it a bit to advanced. The trigger need not be that big at all. |
