Laiev
Hey Listen!!
- Reaction score
- 188
try to make that struct private (don't forget to put then inside a scope/library)
native GetMouseTerrainY takes nothing returns real
native GetMouseTerrainX takes nothing returns real
scope Dash
private struct Dash
real dx
real dy
unit subject
private method periodic takes nothing returns nothing
call SetUnitX(subject, GetUnitX(subject) + dx)
call SetUnitY(subject, GetUnitY(subject) + dy)
endmethod
implement T32x
private static method create takes unit which, real speed, returns thistype
local thistype this = thistype.allocate()
set this.dx = speed*1000 * T32_PERIOD
set this.dy = (1-speed)*100 * T32_PERIOD
set this.subject = which
call this.startPeriodic()
return thistype
endmethod
private method destroy takes nothing returns nothing
call this.stopPeriodic()
call this.deallocate()
endmethod
endstruct
private function Conditions takes nothing returns boolean
if ( not ( GetSpellAbilityId() == 'A002' ) ) then
return false
endif
return true
endfunction
private function Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
local real speed = (GetUnitX(u)-GetMouseTerrainX()) / ((GetUnitY(u)-GetMouseTerrainY())
local Slide s = Slide.create(u, speed)
endfunction
//===========================================================================
function InitTrig_Dash takes nothing returns nothing
local trigger Dash = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( Dash, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( Dash, Condition( function Conditions ) )
call TriggerAddAction( Dash, function Actions )
endfunction
endscope
private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == 039;A002039;
endfunction
JASS:library foo requires TimerUtils private struct Data private integer tick=0 private unit killer private method periodic takes nothing returns nothing set this.tick=.tick+T32_PERIOD if(tick==T32_FPS*5(then if (UnitAlive(this.killer)) then call KillUnit(this.killer) call this.stopPeriodic() endif endif endmethod private static method actions takes nothing returns nothing local thistype this=thistype.create() set this.killer=GetKillingUnit() call this.startPeriodic() endmethod private static method onInit takes nothing returns nothing // register a death event // register thistype.actions as a callback endmethod implement T32x // <--- that is what actually adds it endstruct endlibrary
:thup:
library foo requires TimerUtils
private function Actions takes nothing returns nothing
call Slide.create(GetTriggerUnit(),(GetUnitX(u)-GetMouseTerrainX())/((GetUnitY(u)-GetMouseTerrainY()))
endfunction
Dude.your current value is .031250002.
Your logic is right but your conclusion is not - T32x has a faster iteration speed than T32, which occurs many times compared to the once the proxy call to .stopPeriodic() is made. That makes T32x faster in general, I'd say. Obviously there is a measurable number of ticks at which this occurs in reality, but considering these things fire 32 times per second...T32 is faster than T32x because people would only call .stopPeriodic() from the .periodic method which generates function proxies that get evaluated through triggers instead of called naturally.
I strongly disagree. Combining TU and T32 to make effects last x seconds is probably a nice solution to all of this (call .stopPeriodic() from TU callback).people would only call .stopPeriodic() from the .periodic method
I like the idea, especially in SpellStruct or something. Really neat code, with that.I see the advantage of that; more optimal than comparing an array to track the duration, just kill it when the timer actually expires.
GetHandleId(t)-OFFSET
loop
exitwhen i>N
set D=struct
// use D
set i=i+1
endloop
call TriggerEvaluate(T)
loop
exitwhen i>N
call useData()
// do some more overhead jibberish
set i=i+1
endloop
module StructTimer
private static method onInit takes nothing returns nothing
call TriggerAddCondition(Trig,Condition(function thistype.periodicLoop))
endmethod
endmodule
Yo HeyZeus, or someone in the know, please enlighten me
How is this faster then a struct array stack? (assuming only 1 spell, aka 1 timer)
It was always common knowledge that the struct array stack trumpt all other timer attachment like systems
but then I always had a problem with that from the get go, for instance, lets say I was one spell, one instance - the overhead for say timerUtils red data retrieval is:JASS:GetHandleId(t)-OFFSET
where as with say a struct array stack, the overhead would be:
JASS:loop exitwhen i>N set D=struct // use D set i=i+1 endloop
for one instance of that one spell. I'd imagine the array would do more work (or take more time), where as lets say you had 8 or 10 going at once, then you can start to see the additive speed increase by eliminating the now native h2i (which maybe is fast now?) and the multiple timer events - but at what point does the overlap take place? who knows?
having said that, the loop overhead still exists in this system, as well as one trigger evaluation and then a function call for each instance (along with some other jibberish I don't get), something like this:
JASS:call TriggerEvaluate(T) loop exitwhen i>N call useData() // do some more overhead jibberish set i=i+1 endloop
any who, where does the speed increase come from, or is it simply from less periodic timer events firing?
having said that, the loop overhead still exists in this system, as well as one trigger evaluation and then a function call for each instance (along with some other jibberish I don't get), something like this:
Supposedly one timer expiring constitutes the overhead of a trigger evaluation, but Timer32 also uses trigger evaluation to fire for all structs, so I also fail to notice the speed difference.
If Jesus4Lyf plans to do any updates, allowing users to have direct access to the evaluated method will allow greater control, such as declaring locals in the evaluated method instead of declaring them from the periodic method... if there are lots of local variables, it becomes more efficient to just use a single timer manually.
The module could be "StructTimer" and look like this:
JASS:module StructTimer private static method onInit takes nothing returns nothing call TriggerAddCondition(Trig,Condition(function thistype.periodicLoop)) endmethod endmodule
All of that is good, but the bolded part is the key. All the "struct stack loops" are added to once trigger, which gets evaluated, which is the lowest overhead you can have on a function call, off memory. One timer per loop makes overhead of the timer expiring + function call, with T32 there is only one timer firing and the function calls all come from one trigger evaluate, in other words machine code loops through the loops and calls them each instead of jass code (inside the TriggerEvaluate).Even for one instance, this is pretty fast. However, remember that that is not the only thing to consider. There is also the release() method (which is a lot faster than TimerUtils) and the create() method (which is also faster than creating a timer). Overall, for a standard timer utils kind of system, you would first have to use NewTimer() and then use SetTimerData(). On the loop, you would have to then use GetTimerData() per loop. In the end, you would also have to use ReleaseTimer(). Internally, those functions call other natives, while Timer32 simply sets variables and does array look-ups. So I'd say the difference would kick in even during the first instance.
However, that is when comparing to TimerUtils. When comparing it to a standard struct stack, it also has a better means of setting and retrieving data. (there are no arithmetic operations)
The system does it a little differently. Also, the number of trigger evaluations is actually 1 per loop of the timer, not 1 per instance.
To answer this more directly, it's probably much the same. Function call vs generally faster looping method.Yo HeyZeus, or someone in the know, please enlighten me
How is this faster then a struct array stack? (assuming only 1 spell, aka 1 timer)