• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] Periodic systems

Status
Not open for further replies.
Level 4
Joined
May 23, 2010
Messages
83
I'm working on a camera system and my doubt is about how I'll do the periodic call.

Should I use

JASS:
function TriggerRegisterTimerEventPeriodic takes trigger trig, real timeout returns event

or

JASS:
 native CreateTimer takes nothing returns timer
?

Which one is better and why? And which one is faster (if there's difference)?

I'm kinda new on vJASS, I used to work with jass, but I felt limited then I started learning vJASS to expand my codes.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
I would go for timer, not because of speedfreak attitude, just because it's more flexible (once the event registred, you can disable or detroy the trigger but that's pretty all you can do, while with the the timer you can change the period, stop it, destroy it, ...) and less verbose.

On an irrevelant note, it also creates less handles.
 
Level 11
Joined
May 31, 2008
Messages
698
I believe that native functions (the purple ones) are more efficient than the red ones. This is because the red ones are just built in functions that are composed of native functions.

I think the most efficient way to make a periodic event would be to make a timer then use:
native TimerStart takes timer whichTimer, real timeout, boolean periodic, code handlerFunc returns nothing

But honestly, it probably doesn't even matter, im sure TriggerRegisterTimerEventPeriodic would work fine.

But if you have a lot of code and want to make it as efficient as possible then i would try to eliminate all of the red functions and only use native functions, this is probably a good habit to get into anyways because it also shows you how everything works and lets you understand your own code better.

If you have NewGen, the function list (which is right above where you actually type your code) can be very helpful to convert all the red functions to native ones because it shows you how all of these functions are composed. You can pretty much just copy and paste all of the native functions that make up the red function and replace the function in your code with that and fill in all the values you need to use.

This is probly more info than you needed but i hope it helps :)

Edit:
Heres an example that just proves native functions are more efficient than the red ones

JASS:
function TriggerRegisterTimerEventPeriodic takes trigger trig, real timeout returns event
    return TriggerRegisterTimerEvent(trig, timeout, true)
endfunction

This is what happens every time you call TriggerRegisterTimerEventPeriodic, you can see why it would be more efficient to simply use TriggerRegisterTimerEvent in your code
 
Level 4
Joined
May 23, 2010
Messages
83
wolfman, I know what BJ's are made of and I also know what natives are too, but my doubt was about the pros/cons using timers or trigger events. And, as Troll-Brain said, I'll go for timers because you can stop/restart/destroy/pause them, as you can't pause a trigger.

Thanks for the help, you 3 guys got constructive arguments and I'll rep+.
 
Level 6
Joined
Jun 16, 2007
Messages
235
This is what happens every time you call TriggerRegisterTimerEventPeriodic, you can see why it would be more efficient to simply use TriggerRegisterTimerEvent in your code

This is a classic example of BJ-ism. (belief in imaginary optimizations)

Registering periodic timers happens on map init and there is an average of 10-30 of those per map.
So wolfman would have you waste 10 minutes of your life tracking down those red functions just so you can save your computer 10-30 nanoseconds of work that happens only when your map loads.
 
Level 11
Joined
May 31, 2008
Messages
698
This is a classic example of BJ-ism. (belief in imaginary optimizations)

Registering periodic timers happens on map init and there is an average of 10-30 of those per map.
So wolfman would have you waste 10 minutes of your life tracking down those red functions just so you can save your computer 10-30 nanoseconds of work that happens only when your map loads.

Actually, converting the BJ's to natives can help a lot and i can say this from experience. Your right that it normally wont even make a noticeable difference at all, thats why i said its good to do when you have LOTS of code, but mostly on functions that run extremely frequently (hundreds of times a second). I have made projectile systems and other kinds of code that run every .03 seconds on multiple instances and when i used BJ's it would lag, but after cleaning it up and changing everything to natives the lag was eliminated. And like i said, it never hurts to see how the BJ functions are composed so you can better understand how they actually work. This probably isnt too applicable for timers because they're pretty simple, but i was just talking about any kind of code in general
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
You can disable a trigger with DisableTrigger, a disabled trigger can still be evaluated and executed with TriggerEvaluate and TriggerExecute, but you can use the function IsTriggerEnabled.

In fact a disabled trigger ignores the events registred to him, no more, no less.

Also note that trigger actions will be performed only if TriggerExecute is call, or if a event registred fires the trigger and all conditions return true, but not by TriggerEvaluate itself.

You still can use it like that though : if TriggerEvaluate(...) then ... TriggerExecute(...)

Now, many of us use only conditions and no trigger actions because :

- They are faster.
- In case you want to destroy the trigger later, you don't have to remove the conditions (no leak involved), while you have to do it for trigger actions.
More, TriggerClearActions don't free up the memory, you have to use TriggerRemoveAction and so attach your actions to your trigger.

Now, i'm agree that always use a boolean function could be weird.
And most of time speed is not an issue, it's jass anyway.

Some actions can't be used in a trigger condition (TriggerSleepAction, duh ... and so neither PolledWait, there is also PauseGame and probably few other ones).

A timer expiration is halt while the game is paused, while it's not the case with TriggerSleepAction.
A timer expiration is accurate, while it's random and inaccurate with a TSA.

That was far off-topic but still good to know.
 
Status
Not open for further replies.
Top