DestroyEffectTimed

Doomhammer

Bob Kotick - Gamers' corporate spoilsport No. 1
Reaction score
67
some weeks ago, we had this discussion about my lousy way of destroying effects after a certain amount of time in situations where you actually can't have TriggerSleepAction(), such as functions directly processing picked units in a group. (ref.: http://www.thehelper.net/forums/showthread.php?t=61263)

so now, I've had another go, making use of CSC and CSSafety. It still looks somewhat...maybe not ideal yet. I mean, timers are a great thing, but it's more effort to make things "clean" again as opposed to a simple wait. Either way, I'd be delighted to have some opinions and suggestions for improvement.


JASS:
function KillEffect takes nothing returns nothing
    local timer t=GetExpiredTimer()
    call DestroyEffect(GetAttachedEffect(t,"timed_effect"))
    call AttachObject(t,"timed_effect",null)
    call ReleaseTimer(t)
endfunction

function DestroyEffectTimed takes effect fx, real s returns nothing
    local timer t=NewTimer()
    call AttachObject(t, "timed_effect", fx)
    call TimerStart(t, s, false, function KillEffect)
endfunction


example:
JASS:
call DestroyEffectTimed(AddSpecialEffectTarget("Abilities\\Spells\\Items\\AIhe\\AIheTarget.mdl",u,"origin"),1.3)
 

emjlr3

Change can be a good thing
Reaction score
395
could try

JASS:

globals
  effect sfx
  real timed
endglobals
function remove_effect_time_child takes nothing returns nothing
  local effect e = sfx
  call PolledWait(timed)
  call DestroyEffect(e)
  set e = null
endfunction
function remove_effect_time takes effect e, real time returns nothing
  set sfx = e
  set timed = time
  call ExecuteFunc("remove_effect_time_child")
endfunction


not as accurate, but who really cares, not me, plus its more efficient by far

btw, in urs u dont null ur timer nor do youneed to set ur attached effect to null
 

Arkan

Nobody rides for free
Reaction score
92
Can you really pass arguments like that by using ExecuteFunc? I only thought it worked with GetEnumUnit() and such...
 

Arkan

Nobody rides for free
Reaction score
92
Ah didn't notice, well then it may screw up if 2 different calls are made in a short period of time. Maybe that's not much of a problem...
 

Doomhammer

Bob Kotick - Gamers' corporate spoilsport No. 1
Reaction score
67
I'm using timers from a stack, so there shouldn't be need to null them when using ReleaseTimer instead. And I thought I better set the attached object to null, so all this attached stuff is cleaned again before the timer is released. Is that a bad idea?

I'd like to test the performance of different variations. Do you have any idea how to do that?
 

emjlr3

Change can be a good thing
Reaction score
395
i store the temp global as a local in the new function immediatly following the run, as well as call the polled wait with the other temp global, no overwriting can occur

using timers from a stack is the same as creating new ones, well not really, but as logn as you clear the stored info, no need to null anything, just clear the stored cache, i alterted the release timer function to do it for me everytime, so i dont have to manually

mine will be faster, obviosly, no GC, you can use Grim and its custom timer native to time the speeds if you want, but I dont know how it works
 

grim001

New Member
Reaction score
10
Ah didn't notice, well then it may screw up if 2 different calls are made in a short period of time. Maybe that's not much of a problem...

It's not a problem, JASS only runs 1 thread at a time, so it's impossible for this to happen
 

N-a-z-g-u-l

New Member
Reaction score
30
dont use polled wait... i used to do that with times like 20 seconds, for about 100 effects at the same time, 100 threads opened... the wait loop makes the game lagg then, now i use timers and the lagg is reduced a lot (well, i changed different things, but im pretty sure that was it^^)
 

Doomhammer

Bob Kotick - Gamers' corporate spoilsport No. 1
Reaction score
67
structs are faster than gamecache, right?
any idea how to rewrite this thingy using structs?
 

emjlr3

Change can be a good thing
Reaction score
395
basically the same way I did, with a timer, and the globals replaced with a struct

JASS:

struct timed_sfx
  effect sfx
endstruct
function blarg_child takes nothing returns nothing
  local timer t = GetExpiredTimer()
  local timed_sfx data = GetData(t)

  call DestroyEffect(data.sfx)

  call data.destroy()
  call EndTimer(t)

  set t = null
endfunction
function blarg takes effect sfx, real time returns nothing
  local timer t = GetTimer()
  local timed_sfx data = timed_sfx.create()

  set data.sfx = sfx
  call TimerStart(t,time,false,function blarg_child)
  call SetData(t,data)

  set t = null
endfunction
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top