| 12-07-2006, 10:21 AM | #1 |
I am in the process of creating a dynamic arena for a map im busy with, basically the room is a grid made up of 106 doors, and this trigger opens and closes those doors, however sometimes there is a slight jerk which could effect a player targetting an important spell, can someone please examine this code and suggest ways to optimise it JASS:function Trig_Wall_Shuffle_Conditions takes nothing returns boolean if ( not ( udg_DynamicArenaIsOn == true ) ) then return false endif return true endfunction function Trig_Wall_Shuffle_Func001Func001001 takes nothing returns boolean return ( IsDestructableAliveBJ(GetEnumDestructable()) == true ) endfunction function Trig_Wall_Shuffle_Func002Func001Func001002002 takes nothing returns boolean return ( IsDestructableDeadBJ(GetLastCreatedDestructable()) == true ) endfunction function Trig_Wall_Shuffle_Timer takes nothing returns nothing local timer t = GetExpiredTimer() local integer steps = GetHandleInt(t,"steps") local destructable Destwall = RandomDestructableInRectBJ(gg_rct_Wall_Arena, Condition(function Trig_Wall_Shuffle_Func001Func001001)) local destructable Tempwall = RandomDestructableInRectBJ(gg_rct_Wall_Arena, Condition(function Trig_Wall_Shuffle_Func002Func001Func001002002)) call KillDestructable(Destwall) call DestructableRestoreLife( Tempwall, GetDestructableMaxLife(Tempwall), false ) set steps = steps -1 call SetHandleInt(t,"steps",steps) if steps <=0 then call DestroyTimer(t) endif set Tempwall = null set Destwall = null endfunction function Trig_Wall_Shuffle_Actions takes nothing returns nothing local timer t = CreateTimer() local real duration = 0.10 local integer steps = 150 call SetHandleInt(t,"steps",steps) call TimerStart(t,duration,true,function Trig_Wall_Shuffle_Timer) endfunction //=========================================================================== function InitTrig_Wall_Shuffle takes nothing returns nothing set gg_trg_Wall_Shuffle = CreateTrigger( ) call TriggerRegisterTimerEventPeriodic( gg_trg_Wall_Shuffle,3 ) call TriggerAddCondition( gg_trg_Wall_Shuffle, Condition( function Trig_Wall_Shuffle_Conditions ) ) call TriggerAddAction( gg_trg_Wall_Shuffle, function Trig_Wall_Shuffle_Actions ) endfunction |
| 12-07-2006, 01:17 PM | #2 |
This belongs to the triggers and scripts forum, moved. |
| 12-07-2006, 03:26 PM | #3 |
Stop using BJs; use natives instead. Stop using handle variables; use direct GC, or, even better, some dynamic array system. |
| 12-08-2006, 09:21 AM | #4 |
hiho, I felt nice so I optimized it :D JASS:globals // the global variables used in the following functions boolean udg_DynamicArenaIsOn // added like this to allow JassCraft to run a syntax check destructable array udg_des destructable array udg_res integer udg_randi integer udg_wallnum = 5 // number of doors to be opened each interval rect gg_rct_Wall_Arena // blizzard global endglobals function RandomWallInRect takes nothing returns nothing // this function is basicly what the BJ one does, local destructable d = GetEnumDestructable() // they ran interval*2*150/3 = 10 times/interval, this runs 1 time/interval local integer i = 1 set udg_randi = udg_randi + 1 // iteration if GetDestructableLife(d) > 0 then // if it's alive, add it to possibly be destroyed loop exitwhen i > udg_wallnum set udg_des[i] = d set i = i+1 endloop else // else add it to possibly be ressurrected loop exitwhen i > udg_wallnum set udg_res[i] = d set i = i+1 endloop endif set d=null endfunction function ShuffleWalls takes nothing returns nothing local timer t = GetExpiredTimer() local integer i = 1 if udg_DynamicArenaIsOn then set udg_randi = 0 call EnumDestructablesInRect(gg_rct_Wall_Arena, null, function RandomWallInRect) loop // loop and kill/restore the selected destructables exitwhen i > udg_wallnum call KillDestructable(udg_des[i]) call DestructableRestoreLife(udg_res[i], GetDestructableMaxLife(udg_res[i]), false) set i = i+1 endloop endif set t=null endfunction function ShuffleWallsInit takes nothing returns nothing call TimerStart(GetExpiredTimer(), 0.1, true, function ShuffleWalls) // 0.1 being interval endfunction //=========================================================================== function InitTrig_Wall_Shuffle takes nothing returns nothing call TimerStart(CreateTimer(), 3, false, function ShuffleWallsInit) // 3 being start delay endfunction I added comments to explain things, if there's something you don't understand - just ask (Oh, I haven't actually tested the code but I can't find anything wrong with it) ![]() |
| 12-08-2006, 10:37 AM | #5 |
Thank you for your help, . i do use jasscraft, since i started learning jass. do you perhaps know why only those 2 doors are being opened and closed, iv created all of the globals, and i have tried to set the arrays to both 53 and 106, 106 is the number of doors in the arena, and well, 53 is half that. but for some reason, no matter what i try, only the top 2 doors are affected, i even tried making half of the doors destroyed |
| 12-09-2006, 02:44 PM | #6 |
Sorry for the mistake, i gave you the incorrect trigger, but i applied the same logic to my proper trigger and it works 100% now, with no lag , even when i run both dynamic arenas at the same time, thanks for your help ![]() |
