![]() |
#1 | ||
Evil Emoticon
Respected User
Project Leader: PoC |
![]() Timed Effects
by moyack. 2009 Introduction So... have you been needing a simple way (or function) to create an effect temporally and don't worry about destroying it? or you're needing that an effect with different animations (birth, stand, death) will show all of them?? if your answer is yes to any of those questions, then you're in the right place. This script is used in my project Power of Corruption, as you'll see, it's simple as hell. Just to point out: this library is very useful with effects that have different animations, so using this library with single animation effect will do the same as call DestroyEffect(AddSpecialEffect(....)) How to use it? Just add an effect as parameter and then you set its duration. Example: call StartTimedEffect(AddSpecialEffect(fx, 0., 0.), 2.) You won't need anything else, the system will care of cleaning the effect properly and recycle the values for you. The code. This library requires TimerUtils ![]() //*********************** //* Timed Effects * //* by moyack. 2011 * //*********************** //* //* Requires Jass NewGen Pack and TimerUtils //* //* Introduction //* ============ //* //* So... have you been needing a simple way (or function) to create an effect temporally //* and don't worry about destroying it? or you're needing that an effect with different //* animations (birth, stand, death) will show all of them?? if your answer is yes to any //* of those questions, then you're in the right place. //* //* This script is used in my project Power of Corruption (http://poc.it.cx), as you'll see, //* it's simple as hell. //* //* Just to point out: this library is very useful with effects that have different //* animations, so using this library with single animation effect will do the same as //* call DestroyEffect(AddSpecialEffect(....)) //* //* How to use it? //* ============== //* - Create a trigger with a convenient name (like Timed Effects :P) //* - Convert the trigger to custom text //* - Copy and paste this code and save your map. //* //* With all this done, you just have to call the function StartTimedEffect(), and as parameters //* an effect and a real value which will be the effect duration. //* //* Example: call StartTimedEffect(AddSpecialEffect(fx, 0., 0.), 2.) //* //* You won't need anything else, the system will care of cleaning the effect properly //* and recycle the values for you. library_once TimedEffects requires TimerUtils private struct data effect f = null timer t static method create takes effect f returns data local data dt = data.allocate() set dt.t = NewTimer() set dt.f = f call SetTimerData(dt.t, integer(dt)) return dt endmethod endstruct private function DestroyTimedEffect takes nothing returns nothing local data d = data(GetTimerData(GetExpiredTimer())) call DestroyEffect(d.f) call ReleaseTimer(d.t) call d.destroy() endfunction function StartTimedEffect takes effect f, real dur returns nothing local data d = data.create(f) call TimerStart(d.t, dur, false, function DestroyTimedEffect) endfunction endlibrary ![]() //*********************** //* Timed Effects * //* by moyack. 2011 * //*********************** //* //* Requires Jass NewGen Pack and TimedLoop by Vexorian //* //* Introduction //* ============ //* //* So... have you been needing a simple way (or function) to create an effect temporally //* and don't worry about destroying it? or you're needing that an effect with different //* animations (birth, stand, death) will show all of them?? if your answer is yes to any //* of those questions, then you're in the right place. //* //* This script is used in my project Power of Corruption (http://poc.it.cx), as you'll see, //* it's simple as hell. //* //* Just to point out: this library is very useful with effects that have different //* animations, so using this library with single animation effect will do the same as //* call DestroyEffect(AddSpecialEffect(....)) //* //* How to use it? //* ============== //* - Create a trigger with a convenient name (like Timed Effects :P) //* - Convert the trigger to custom text //* - Copy and paste this code and save your map. //* //* With all this done, you just have to call the function StartTimedEffect(), and as parameters //* an effect and a real value which will be the effect duration. //* //* Example: call StartTimedEffect(AddSpecialEffect(fx, 0., 0.), 2.) //* //* You won't need anything else, the system will care of cleaning the effect properly //* and recycle the values for you. library_once TimedEffects requires TimedLoop private struct data effect f = null real time = 0. real dur private method onTimedLoop takes nothing returns boolean set .time = .time + TimedLoop_PERIOD if .time > .dur then call DestroyEffect(.f) return TimedLoop_STOP endif return TimedLoop_CONTINUE endmethod implement TimedLoop static method create takes effect f, real t returns thistype local thistype dt = thistype.allocate() set dt.dur = t set dt.f = f call dt.startTimedLoop() return dt endmethod endstruct function StartTimedEffect takes effect f, real dur returns nothing local data d = data.create(f,dur) endfunction endlibrary .:
Now enjoy your new code :) Comments and such are welcome and appreciated. Changelog:
Last edited by moyack : 11-22-2011 at 03:53 AM. |
||
![]() |
![]() |
Sponsored Links - Login to hide this ad! |
|
![]() |
#2 |
Obscurity, the Art
|
![]() Ah yes, now this is about the size a library of this nature should be.
__________________Although, I see lots of flaws in this method versus Deaod's. Firstly, you are dynamically creating timers for use in your code, which is a thing of the past. You should probably use a flavor of TimerUtils for this library, as it will remove that unnecessary and silly step. Additionally, this doesn't allow effects to be created after an X second delay from when the function is called. I think that is a useful quantity to have access to in a library such as this. Finally, I think the mode for calling the code is not as effective as it should be. I recommend the following function form -- ![]() call UnitAddTimedEffect("Some_File_Path.mdx", X, Y, DELAY, DURATION) call UnitAddTimedEffectTarget("Some_File_Path.mdx", SOMEUNIT, DELAY, DURATION) |
![]() |
![]() |
![]() |
#3 | |||
Evil Emoticon
Respected User
Project Leader: PoC |
![]() Quote:
Quote:
Quote:
|
|||
![]() |
![]() |
![]() |
#4 |
Procrastination Incarnate
Development Director
|
![]() Dusk, where do you see dynamic timers being used?
__________________I agree, however, it would be more sensible to code this using TimerUtils. Also, what Dusk said about naming conventions, minus the Unit part which looks like it's just a silly typo. |
![]() |
![]() |
![]() |
#5 | ||
Evil Emoticon
Respected User
Project Leader: PoC |
![]() Quote:
Quote:
|
||
![]() |
![]() |
![]() |
#6 | |
Procrastination Incarnate
Development Director
|
![]() Quote:
I imagine having more timers isn't such a bad thing when it means WC3 doesn't have to execute slow jass code many times per second; it should be the faster solution. The greater precision of having a timer per each effect is entirely undisputed; whether it matters or not is up to debate, but at worst the precision is irrelevant, and at best it's also in favour of a timer per effect method. |
|
![]() |
![]() |
![]() |
#7 | |
Evil Emoticon
Respected User
Project Leader: PoC |
![]() Quote:
I've added in the first post a library extension which allows the delay option and a version that uses TimerUtils. |
|
![]() |
![]() |
![]() |
#8 | ||
Obscurity, the Art
|
![]() Quote:
Quote:
|
||
![]() |
![]() |
![]() |
#9 |
User
Join Date: Aug 2008
Posts: 158
![]() |
![]() If I see rightly, you forgot to add the globals block into the TimerUtils one:
call TimerStart(t, d, false, function End) The variable d isnt existing, thought The rest looks very good, but could you maybe Change the function Name to TimedEffect or something kinda, because StartEffect doesn't say anything 'bout the function, and what its doing, but handling something with effects ![]() Greez |
![]() |
![]() |
![]() |
#11 |
Obscurity, the Art
|
![]() I do still think AddTimedEffect() would be much more practical than TimedEffect. It'd also match closer with AddSpecialEffect(). Also, why in the world do you still have your single timer version? It's much more inefficient than a single timer with one execution after a precise amount of time. Not to mention you never pause the timer even if no effects are loaded to it, which isn't very good.
__________________ |
![]() |
![]() |
![]() |
#13 | |
Procrastination Incarnate
Development Director
|
![]() Quote:
The single-timer version doesn't require other libraries, which could be considered a bonus in the case of any system other than TimerUtils. In the case of such a used library, however, it's pretty inconsequential. If you insist on including a one-timer version then you may do so, but it should be secondary to the TimerUtils one (put it lower in the post, maybe use hiddenjass tags and explain beforehand it's intended for people who for some bizzare reason don't use TimerUtils) and the timer definitely shouldn't be running when there are no effects being timed. Also, I second Dusk on the naming conventions. If you insist on this function format (function taking an already existing effect) at least name it accordingly, something like DestroyEffectDelayed or something. The first post should also note in the introduction that many effects (the ones with a single animation) can be destroyed immediately after they are created. People who don't know that and stumble on this resource might otherwise think they should use it on all their effects. |
|
![]() |
![]() |
![]() |
#14 | |
Evil Emoticon
Respected User
Project Leader: PoC |
![]() Quote:
About naming, don't worry either, AddTimedEffect sounds nice to me, and if you like it, I'll do it. |
|
![]() |
![]() |
![]() |
#15 |
Procrastination Incarnate
Development Director
|
![]() In the post, you say the function is called StartEffect yet in the script it's called TimedEffect. I don't think either is very suitable, though. The function AddTimedEffect sounds good because it's style follows the related Blizzard's function, AddSpecialEffect (perhaps even better would be AddSpecialEffectTimed). The TimedEffect function should be similar to it's native counterpart, DestroyEffect, hence why I think the most suitable name is something like DestroyeffectTimed.
__________________Also, you should include some short documentation on the use of the library in the library itself, not just the post, since users might get your library from maps that use it rather than from here. |
![]() |
![]() |
![]() |
Thread Tools | Search this Thread |
|
|