| 08-31-2008, 05:35 AM | #1 |
Mind you, my code will make your eyes bleed with how bad it is (which is why I ask for help). None of this works to the actual way it's supposed to just yet, I'm just trying to get it into conditions that are testable so I can continue editing it. The kind of lag I'm getting isn't BOOM you're in and your lag is lethal. For the first 5 or 6 seconds it's fine, then it starts piling on very quickly. Though it's horrible at the moment and at the moment I'm just trying to cure lag, what this is supposed to do is make standing on hills make you slide down slowly and make movement uphill hard and for testing's sake make it work downhill, too. So yeah, could someone assist me in finding my lag-inducer so I can continue to edit this? Take a look if you dare... to help me, :D :function TideAE_HS_Accuracy takes nothing returns real return 16. endfunction function Trig_TideAE_Hill_System_Actions takes nothing returns nothing local real x1 = 0. local real y1 = 0. local real z1 = 0. local real x2 = 0. local real y2 = 0. local real z2 = 0. local real x3 = 0. local real y3 = 0. local real div = 360/TideAE_HS_Accuracy() local real ang = 0 local real dis = 50. local real cnt = 0 local real slope = 0. local real dist = 0. local group g = CreateGroup() local unit u local rect r = Rect(-2048, -2048, 2048, 2048) call GroupEnumUnitsInRect(g, r, null) loop set u = FirstOfGroup(g) set cnt = 0 set x1 = GetUnitX(u) set y1 = GetUnitY(u) set z1 = GetLocationZ(Location(x1, y1)) if GetUnitMoveSpeed(u)>0 and GetUnitFlyHeight(u)==0 then loop set cnt = cnt + 1 set ang = div*cnt set x2 = x1 + dis*(Cos(ang*bj_DEGTORAD)) set y2 = y1 + dis*(Sin(ang*bj_DEGTORAD)) set z2 = GetLocationZ(Location(x2, y2)) set slope = (z2 - z1)/(50.) call BJDebugMsg("Gradient: "+R2S(slope)) if slope>0.2 or slope<0.2 then set ang = ang + 180 set dist = slope*5 set x3 = x1 + dist*(Cos(ang*bj_DEGTORAD)) set y3 = y1 + dist*(Sin(ang*bj_DEGTORAD)) call SetUnitX(u, x3) call SetUnitY(u, y3) endif exitwhen cnt==TideAE_HS_Accuracy() endloop endif call GroupRemoveUnit(g, u) exitwhen u==null endloop call DestroyGroup(g) set u = null call RemoveRect(r) endfunction //=========================================================================== function InitTrig_TideAE_Hill_System takes nothing returns nothing set gg_trg_TideAE_Hill_System = CreateTrigger( ) call TriggerRegisterTimerEventPeriodic( gg_trg_TideAE_Hill_System, 0.02 ) call TriggerAddAction( gg_trg_TideAE_Hill_System, function Trig_TideAE_Hill_System_Actions ) endfunction Thanks ahead. (If you have comments about how this isn't so great, please put it in hidden tags so I can cry about it after I get this fixed up.) |
| 08-31-2008, 05:50 AM | #2 |
you are massively leaking locations here set z2 = GetLocationZ(Location(x2, y2)) Maybe make GetLocationZ take 2 real arguments instead of location? set z2 = GetLocationZ(x2, y2) |
| 08-31-2008, 05:52 AM | #3 |
| 08-31-2008, 05:58 AM | #4 |
Actually you can use only one global location that you create on startup and you just move it around (with MoveLocation ofc) |
| 08-31-2008, 06:07 AM | #5 |
I'll try that... EDIT! I did something wrong and I don't know what, the "slope" always returns 0... JASS:function Trig_TideAE_Hill_System_Actions takes nothing returns nothing local real x1 = 0. local real y1 = 0. local real z1 = 0. local real x2 = 0. local real y2 = 0. local real z2 = 0. local real x3 = 0. local real y3 = 0. local real div = 360/TideAE_HS_Accuracy() local real ang = 0 local real dis = 50. local real cnt = 0 local real slope = 0. local real dist = 0. local group g = CreateGroup() local unit u local rect r = Rect(-2048, -2048, 2048, 2048) call GroupEnumUnitsInRect(g, r, null) loop set u = FirstOfGroup(g) set cnt = 0 set x1 = GetUnitX(u) set y1 = GetUnitY(u) call MoveLocation(udg_ZPoint, x1, y1) set z1 = GetLocationZ(udg_ZPoint) if GetUnitMoveSpeed(u)>0 and GetUnitFlyHeight(u)==0 then loop set cnt = cnt + 1 set ang = div*cnt set x2 = x1 + dis*(Cos(ang*bj_DEGTORAD)) set y2 = y1 + dis*(Sin(ang*bj_DEGTORAD)) call MoveLocation(udg_ZPoint, x2, y2) set z2 = GetLocationZ(udg_ZPoint) set slope = (z2 - z1)/(50.) call BJDebugMsg("Gradient: "+R2S(slope)) if slope>0.2 or slope<0.2 then set ang = ang + 180 set dist = slope*5 set x3 = x1 + dist*(Cos(ang*bj_DEGTORAD)) set y3 = y1 + dist*(Sin(ang*bj_DEGTORAD)) call SetUnitX(u, x3) call SetUnitY(u, y3) endif exitwhen cnt==TideAE_HS_Accuracy() endloop endif call GroupRemoveUnit(g, u) exitwhen u==null endloop call DestroyGroup(g) set u = null call RemoveRect(r) endfunction I've heard of MoveLocation before but I'm definitely not sure I'm using it right. EDIT! Hahahaha it was the debug that was leaking the most... lag stopped as soon as I //'d it... thanks for the help, though. At least that's some leaks fixed. |
| 08-31-2008, 10:34 AM | #6 |
0.02 is too fast for triggers (50 fps too much), lower bound is 0.0314 |
| 08-31-2008, 10:45 AM | #7 |
0.03125 |
| 08-31-2008, 11:04 AM | #8 |
12 |
| 08-31-2008, 11:43 AM | #9 |
In the "finalized" version I can run it 50 times p/s but I might lower it to 33.3• times p/s for online play. |
