| 08-15-2006, 09:19 AM | #1 |
I've heard a lot of people mentioning that specific unit events cause much more lag than player events (a.k.a are slower). I've made some drastic tests and I came to the conclusion that this is completely untrue. And now to explain the tests I made. For both tests I moved a wisp in cicles with the following code in order to complicate things a little and see if I notice any lag by adding this. The added units had no model or shadow assigned so that polycount would not be included in this test. JASS:function Rise takes nothing returns nothing call SetUnitX(gg_unit_ewsp_0001, 500.00*Cos(Atan2(GetUnitY(gg_unit_ewsp_0001), GetUnitX(gg_unit_ewsp_0001))+0.05)) call SetUnitY(gg_unit_ewsp_0001, 500.00*Sin(Atan2(GetUnitY(gg_unit_ewsp_0001), GetUnitX(gg_unit_ewsp_0001))+0.05)) endfunction //this comes in actions function of the trigger call TimerStart(udg_tt, 0.035, true, function Rise) 1. First I tried to see if the lag could be caused for a single trigger yet very many units. Of course, many units themselves can cause lag (because each is an object). I created 900 units on the map, and without assigning any event to the units, the game still slightly lagged (almost unoticeable though). I then added the event, "EVENT_PLAYER_UNIT_DEATH",then the infamous "EVENT_UNIT_DAMAGED" and in the end both. I did not notice a difference between the slight lag before adding the events, and after. JASS:local integer i = 900 local player p = Player(1) local trigger t = CreateTrigger() local unit u loop exitwhen i==0 set u = CreateUnit(p, 'nalb',0,0,0) call TriggerRegisterUnitEvent(t, u, EVENT_UNIT_DAMAGED) set i = i - 1 endloop call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_ATTACKED) call DisplayTextToPlayer(Player(0), 0,0,"Done!") 2. This time I tried to have many event initializations to many triggers. So I created this time only 300 units yet 200 triggers. First I assigned the "EVENT_PLAYER_UNIT_DEATH" and then "EVENT_UNIT_DAMAGED", so that each unit would be response to these events for each trigger. Just think that this would be 60000 unit events assigned (limit you could hardly reach). I did not notice significant lag either. In the end of course I tried to add both events for each unit to each trigger. No noticeable difference in contrast with having only one! JASS:function Trig_Melee_Initialization_Actions takes nothing returns nothing local integer i = 300 local integer j = 200 local player p = Player(1) local trigger array t local unit u loop exitwhen j==0 set t[j]=CreateTrigger() set j = j - 1 endloop loop exitwhen i==0 set u = CreateUnit(p, 'nalb',0,0,0) set j = 200 loop exitwhen j==0 call TriggerRegisterUnitEvent(t[j], u, EVENT_UNIT_DAMAGED) set j = j - 1 endloop if ModuloInteger(i,50)==0 then call TriggerSleepAction(0) endif set i = i - 1 endloop set j = 200 loop exitwhen j==0 call TriggerRegisterAnyUnitEventBJ(t[j], EVENT_PLAYER_UNIT_DEATH) set j = j - 1 endloop call DisplayTextToPlayer(Player(0), 0,0,"Done!") endfunction I removed the circling wisp and I noticed that it was the cause of the lag. Without it, the game goes extremely smooth in all tests (added some archers and put them to attack a warden which to which I added all the events mentioned above). As a side note I noticed another interesting problem about assigning events to triggers. Apparently after adding a very large number, the trigger simply stops. I am not sure yet if the limit refers to events/trigger or events in general. However, to avoid this problem you would have to put waits between event assigning (like I did above). But I noticed that the game worked if assigning 13750 events which is a very large number of assignments but again, who knows when this problem could occur? Well, in my opinion, if coded corectly, a "TriggerRegisterAnyUnitDamagedEvent" system should not be problematic. I posted this because a lot of people considered it so, but I personally don't after doing these tests. If you encounter lag, it surely is caused by something else (either you have too many units on the map or triggers, since objects themselves in large numbers cause lag). ~Daelin |
| 08-15-2006, 10:26 AM | #2 |
Well, just to say this. anyunit events are less effiecent than specific. Specific unit event: JASS:native TriggerRegisterUnitEvent takes trigger whichTrigger, unit whichUnit, unitevent whichEvent returns event A native, which is good. JASS:native TriggerRegisterPlayerUnitEvent takes trigger whichTrigger, player whichPlayer, playerunitevent whichPlayerUnitEvent, boolexpr filter returns event Player event Again, native good. And event unit, which isent that great, its using a loop. Still not bad. JASS:function TriggerRegisterAnyUnitEventBJ takes trigger trig, playerunitevent whichEvent returns nothing local integer index set index = 0 loop call TriggerRegisterPlayerUnitEvent(trig, Player(index), whichEvent, null) set index = index + 1 exitwhen index == bj_MAX_PLAYER_SLOTS endloop endfunction So the answer is no, specific units shouldent cause lag whatsoever. If anything, the everyunit event would. |
| 08-15-2006, 10:29 AM | #3 |
You know, I wasn't refering to initialization itself, but on long-term, the fact that the trigger has a new event, and that practically it needs to check for that event somehow. I do not know how eventimential programming is actually programmed so I can't really tell how the whole stuff is happening. So no, I was not refering to "calling the function" itself but to the effect it has during the game. ~Daelin |
| 08-15-2006, 10:36 AM | #4 |
O, sorry. I'v never experienced problems with it in the past, i'v never had a small delay or anything. But it depends if your using the event heavily, like alot of triggers using the same event. |
| 08-15-2006, 10:40 AM | #5 | ||
Quote:
Neither did it happen to me but I heard rumours about this and I was sure they were unfond but I needed to prove it. Quote:
That's what I just proved here, that there is no difference between specific and general event even if the number of triggers+events is bigger! ~Daelin |
| 08-15-2006, 10:59 AM | #6 | |
I suspect results would be significantly different if there were a condition/action. A few lines for a condition for playerevent and a few lines of action for specific event. One would expect playerevents to go O(1) init O(N) when event fires and vice versa for specific. Quote:
|
