HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Why is this lagging?

04-20-2008, 04:21 PM#1
rulerofiron99
Making a small system that moves unit a unit to a point based on the location of the previous unit in the convoy, making a snake-like movement.

For some reason it lags, but I've had much worse triggers than this and many more things happening per second causing much less lag.

This first trigger creates the convoy units.

Trigger:
start
Collapse Events
Map initialization
Conditions
Collapse Actions
Collapse For each (Integer A) from 1 to 12, do (Actions)
Collapse Loop - Actions
Set l[0] = (Player 1 (Red) start location)
Unit - Create 1 Shaman for Player 1 (Red) at l[0] facing Default building facing degrees
Custom script: call RemoveLocation(udg_l[0])
Set formLimit = (formLimit + 1)
Set formUnit[formLimit] = (Last created unit)

The second trigger moves them. I used SetUnitX/Y instead of Unit - Move Instantly to prevent the stopping of attacks and stuff.

Trigger:
convoy
Collapse Events
Time - Every 0.05 seconds of game time
Conditions
Collapse Actions
Collapse For each (Integer A) from 1 to (formLimit - 1), do (Actions)
Collapse Loop - Actions
Set l[0] = (Position of formUnit[(Integer A)])
Set l[1] = (Position of formUnit[((Integer A) + 1)])
Set l[2] = (l[0] offset by 128.00 towards (Angle from l[0] to l[1]) degrees)
Set r[0] = (X of l[2])
Set r[1] = (Y of l[2])
Custom script: call SetUnitX(udg_formUnit[GetForLoopIndexA() + 1], udg_r[0])
Custom script: call SetUnitY(udg_formUnit[GetForLoopIndexA() + 1], udg_r[1])
Custom script: call RemoveLocation(udg_l[0])
Custom script: call RemoveLocation(udg_l[1])
Custom script: call RemoveLocation(udg_l[2])

Any help or pointing out of noobishness would be greatly appreciated.
04-20-2008, 04:31 PM#2
Troll-Brain
you should use GetUnitX and GetUnitY for avoid the creation/destruction of locations.
also instead of use point with polar offset use directly the formula
04-20-2008, 04:32 PM#3
PurgeandFire111
Beat to the post...

Yeah, try to use direct JASS... The only thing I can see that would cause the lag is the fact that there are a bunch of executions at that instance each time, but I don't think that would explain the lag... :\
04-20-2008, 04:58 PM#4
rulerofiron99
So it all comes down to mathematics then?
04-20-2008, 05:23 PM#5
Troll-Brain
i think it's because the creation/destruction and also using fuction with locations, which are slower than the functions using X/Y.

and when you use the polar offset you call a function, the same for angle beetween points.
it's very slower than use directly this :
Collapse JASS:
local real xa = GetUnitX(<yourUnit>)
local real ya = GetUnitY(<yourUnit>)
local real xb = GetUnitX(<yourUnit>)
local real yb = GetUnitY(<yourUnit>)
local real angle = Atan2(yb- ya, xb - xa)

    set x = x + 128.0 * Cos(angle)
    set y = y + 128.0 * Sin(angle)
04-20-2008, 05:33 PM#6
Rising_Dusk
I can't imagine this being a math problem. Might have something to do with allocating 36 locations every 20th of a second, even if they are properly removed.
04-20-2008, 08:56 PM#7
PurgeandFire111
Quote:
Originally Posted by Rising_Dusk
I can't imagine this being a math problem. Might have something to do with allocating 36 locations every 20th of a second, even if they are properly removed.

That is what I think is the problem. Real coordinates are accurate and don't need to be removed. But the math could be part of the problem. I don't think that Cos and Sin are the fastest functions in the world, are they not?

Even in JASS, I think it would still lag a bit but still probably reduce it a bit. On a scale of 1-10, how bad is the lag? (1 = Hardly Noticeable 10 = Extremely choppy movements and extremely laggy)
04-21-2008, 04:34 AM#8
rulerofiron99
It varies. It runs fine for about 3 out of 10 seconds, then get's bad when the units start attacking.

EDIT: Changed the trigger into the JASS version with full math, seems like it has reduced the lag, but now I get a 'necklace' instead of a 'snake'.
04-21-2008, 12:33 PM#9
Vexorian
You made the conversion wrong then.

I seriously doubt this trigger is the reason for your lag. Specially if the lag is not constant.