[Log in / Register]
| News | Chat | Pastebin | Donations | Tutorials | Rules | Forums |
| Maps | Skins | Icons | Models | Spells | Tools | Jass | Packs | Hosted Projects | Starcraft II Modding | Starcraft II Resources | Galaxy Wiki |
(Keeps Hive Alive)
Go Back   The Hive Workshop > Warcraft III Modding > JASS Resources > Submissions > "Graveyard"


"Graveyard" Resources which were not approved are moved to this section.

 
 
Thread Tools
Old 06-15-2012, 03:50 PM   #1 (permalink)
Registered User mckill2009
SSJ99999 Pinoy!
 
mckill2009's Avatar
 
Join Date: Mar 2009
Posts: 4,380
mckill2009 is a splendid one to behold (847)mckill2009 is a splendid one to behold (847)mckill2009 is a splendid one to behold (847)mckill2009 is a splendid one to behold (847)mckill2009 is a splendid one to behold (847)
[Snippet] Dynamic Timer

The are many timer systems out there and I dont want to compete with them as it spams a lot nowadays and this is heavily
inspired by Nesthauru's CTL except it uses different intervals instead of only 0.03125 or constant, the cons of
this one is that it creates multiple timers like TimedLoop (by vexorian)...

The difference is that you dont need to manually deallocate the instance and this uses only 3 implementations, 1 is optional...

DynamicTimer

Jass:
/*
===Dynamic Timer v1.2
===Created by Mckill2009

INPIRED BY:
- CTL by Nesthaurus
- Dynamic GUI Indexing by Hanky

API: Module
    implement DTloop
        - Not optional, this needs to be on TOP of implementations
        - You may declare your locals here
        - This is where your condition is generated/running, this by default is TRUE
        - If it encounters FALSE on the first "if", statement, it will automatically deindexed
        - Take note that you dont need to put an "endif" to your condition
                            Sample:
                                implement DTloop
                                    local unit x = GetUnitX(.hero)
                                    local unit y = GetUnitY(.hero)
                                    if UnitAlive(.hero) then
                                        YOUR ACTIONS HERE!
                                implement DTend                              
   
    implement DTnulls
        - Optional, used to null your local variables created via DTloop
   
    implement DTend
        - Not optional, this needs to be BELOW of DTloop or implementations
        - This calls the "create(real variable)", this is where a timer interval is dynamic      

API: Methods
    static method create takes real interval returns thistype
        - By default, timer runs at INTERVAL (0.03125)
        - The "interval" simply delays the 0.03125

CREDITS:
- Deaod for suggesting standard methods
*/


library DynamicTimer

globals
    //These should NOT be modified
    private constant integer MAX_INDEX = 8190
    private constant real INTERVAL = 0.03125
endglobals

module DTloop //not optional
    readonly boolean bol
    readonly real gap
    readonly real in
    static boolean chkindex = true
    static integer index1 = 0 //
    static integer array indexAr
    static timer t
   
    method chk takes nothing returns boolean
endmodule

module DTnulls //optional
            return true
        endif
endmodule

module DTend //not optional
                implement DT_DO_NOT_IMPLEMENT_THIS
                endif
            endif
            set looper = looper + 1
            exitwhen looper > index1
        endloop
    endmethod

    static method create takes real interval returns thistype
        local thistype this
        if (index1 < MAX_INDEX) then
            set this = allocate()
            set .gap = 0
            set .in = interval
            set .bol = true
            if index1==0 then
                set t = CreateTimer()
                call TimerStart(t,INTERVAL,true,function thistype.looper)
            endif
            set index1 = index1 + 1
            set indexAr[index1] = this
        elseif chkindex then
            set chkindex = false
            debug call BJDebugMsg("ERROR: Struct has "+ I2S(MAX_INDEX)+ " index, unable to allocate!: TIMER DESTROYED.")
            call PauseTimer(t)
            call DestroyTimer(t)
        endif      
        return this
    endmethod
endmodule

//NEVER IMPLEMENT THIS
module DT_DO_NOT_IMPLEMENT_THIS //XD
    implement DTnulls
        set .bol = false
        return .bol
    endmethod
   
    static method looper takes nothing returns nothing
        local thistype this
        local integer looper = 1
        loop
            set this = indexAr[looper]
            set .gap = .gap + INTERVAL
            if .gap > .in then
                set .gap = 0
                call chk()
                if not .bol then
                    call .destroy()
                    set indexAr[looper] = indexAr[index1]
                    set index1 = index1 - 1    
                    if index1==0 then
                        call PauseTimer(t)
                        call DestroyTimer(t)
                    endif
endmodule

endlibrary


Sample

Jass:
library DT uses DynamicTimer optional Alloc

native UnitAlive takes unit u returns boolean

struct DT //extends array
    //you may also use custom allocators
    //implement Alloc
    unit u
    real dur
    static thistype d
    static real interval = 1.8
   
    method destroy takes nothing returns nothing
        call BJDebugMsg("HERO NAME ====="+GetUnitName(.u))
        set .u = null
        call BJDebugMsg("HERO NAME ====="+GetUnitName(.u))
        call .deallocate()
    endmethod

    implement DTloop
        local texttag tag
        local real du
        if .dur > 0 and UnitAlive(.u) then
            set .dur = .dur - 0.5
            set du = .dur
            set tag = CreateTextTag()
            call SetTextTagPosUnit(tag, .u, 0)
            call SetTextTagText(tag, R2S(du), 0.025)
            call SetTextTagPermanent(tag, false)
            call SetTextTagVelocity(tag, 0.03, 0.03)
            call SetTextTagLifespan(tag, 3)
            call SetTextTagFadepoint(tag, 0.01)
            //or best to null the local "tag" here XD
            set tag = null
        //no need to put "endif" coz if this will encounter FALSE
        //it will automatically be deindexed
       
    implement DTnulls //optional
        //null locals here
        set tag = null
   
    implement DTend
 
    static method cast takes nothing returns boolean
        local thistype this
        local unit hero = GetTriggerUnit()
        local unit first
        call GroupEnumUnitsInRange(bj_lastCreatedGroup,GetUnitX(hero),GetUnitY(hero),1000.,null)
        loop
            set first = FirstOfGroup(bj_lastCreatedGroup)
            exitwhen first==null
            if interval > 0.3 then
                set interval = interval - 0.3
            endif
            set this = create(interval)
            set .u = first
            set .dur = GetRandomReal(5.,10.)
            call GroupRemoveUnit(bj_lastCreatedGroup,first)
        endloop
        return false
    endmethod
   
    private static method onInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(t, Condition(function thistype.cast))
    endmethod
endstruct

endlibrary


Changelogs

v1.1
- Changed many API name and structures
- Automatically deallocates instance when done
- Added optional nulling of locals and instance

v1.2
- API name changed so that it can use standard and custom allocators
- DTendnulls removed, codes shortened
__________________
My Resources:
My Maps
My Systems/Spells

Your ideas tend to result in unnecessary violence so shut the F*** up!

Last edited by mckill2009; 06-18-2012 at 01:52 AM.
mckill2009 is offline  
Old 06-15-2012, 05:31 PM   #2 (permalink)
Forum Moderator Magtheridon96
JESUS MAN
 
Magtheridon96's Avatar
Resource Moderator
 
Join Date: Dec 2008
Posts: 5,699
Magtheridon96 has a brilliant future (1809)
Merit Badge - Level 0: This user has proven to be extremely valuable to the Warcraft III Modding Community. 
TimerTools does this too :|
__________________
Magtheridon96 is offline  
Old 06-16-2012, 02:57 AM   #3 (permalink)
Registered User mckill2009
SSJ99999 Pinoy!
 
mckill2009's Avatar
 
Join Date: Mar 2009
Posts: 4,380
mckill2009 is a splendid one to behold (847)mckill2009 is a splendid one to behold (847)mckill2009 is a splendid one to behold (847)mckill2009 is a splendid one to behold (847)mckill2009 is a splendid one to behold (847)
TT is way too complicated plus it uses hashtables, nothing wrong with HT, but to try a
different way in an easy way to read plus very simple implementation is worth it...

Im planning to expand it by adding a method condition above the looper static method, like
T32...
__________________
My Resources:
My Maps
My Systems/Spells

Your ideas tend to result in unnecessary violence so shut the F*** up!
mckill2009 is offline  
Old 06-16-2012, 06:53 AM   #4 (permalink)
Registered User Nestharus
User
 
Nestharus's Avatar
 
Join Date: Jul 2007
Posts: 4,909
Nestharus has disabled reputation
It only uses one hashtable read in the root call for all merged timers ; |.
__________________

Anime-Planet.com - anime | manga | reviews
Nestharus is offline  
Old 06-16-2012, 09:28 AM   #5 (permalink)
Forum Moderator Bribe
Keep it simple
 
Bribe's Avatar
Spells, Help Zones & JASS Moderator
 
Join Date: Sep 2009
Posts: 5,581
Bribe has much of which to be proud (1209)Bribe has much of which to be proud (1209)
PayPal Donor: This user has donated to The Hive. 
What happened to private methods/members and the ban on creating even more timer systems?
__________________
How to post your triggers on the Hive Workshop.
JPAG - Bettering the cause of readable source code.

Bribe is offline  
Old 06-16-2012, 10:18 PM   #6 (permalink)
Registered User Deaod
GUI sucks. Don't use it.
 
Join Date: Nov 2007
Posts: 832
Deaod has disabled reputation
Just use the following code in the future.

Unlike this submission, it works reliably, doesnt fuck with your mind, and actually has meaningful names (which are unlikely to collide within the namespace).

It also is customizable should you need a solution more specific to your problem.

Jass:
library SpellTemplate
   
    private struct Data
        //
        // actual struct members
        //
       
        private integer loopIndex
       
        private static thistype array loopInstances
        private static integer loopInstancesCount=0
        private static timer LOOP_TIMER=CreateTimer()
        private static constant real LOOP_TICK = 1./40
       
        private method destroy takes nothing returns nothing
            //
            // clean your struct here
            //
            set loopInstancesCount=loopInstancesCount-1
            set loopInstances[loopIndex]=loopInstances[loopInstancesCount]
            set loopInstances[loopIndex].loopIndex=loopIndex
            if loopInstancesCount==0 then
                call PauseTimer(LOOP_TIMER)
            endif
            call deallocate()
        endmethod
       
        private static method callback takes nothing returns nothing
        local integer i=loopInstancesCount-1
        local thistype this
            loop
                exitwhen i<0
                set this=loopInstances[i]
                //
                // do your things here, dont forget to call destroy() somewhen
                //
                set i=i-1
            endloop
        endmethod
       
        static method create takes nothing returns thistype
        local thistype this=allocate()
            //
            // initialize the struct here
            //
            set loopInstances[loopInstancesCount]=this
            set loopIndex=loopInstancesCount
            if loopInstancesCount==0 then
                call TimerStart(LOOP_TIMER, LOOP_TICK, true, function thistype.callback)
            endif
            set loopInstancesCount=loopInstancesCount+1
            return this
        endmethod
    endstruct

endlibrary
Deaod is offline  
Old 06-17-2012, 12:11 AM   #7 (permalink)
Registered User mckill2009
SSJ99999 Pinoy!
 
mckill2009's Avatar
 
Join Date: Mar 2009
Posts: 4,380
mckill2009 is a splendid one to behold (847)mckill2009 is a splendid one to behold (847)mckill2009 is a splendid one to behold (847)mckill2009 is a splendid one to behold (847)mckill2009 is a splendid one to behold (847)
@Deaod
the code you gave doesnt work on extended aray unless you implement custom allocators,
mine does, besides its a pain in the yes to cnp all those codes than just implementing ;)...
Jass:
struct SpellTest extends array
    // declare members
    implement DTloop
        //declare locals
        if true then
            //running conditions
            //no need to put endif for the first IF statement    
            //if it encounters false, it will be deindexed  
    implement DTend
        //no need to put anything below this implementation

    static method cast takes nothing returns nothing
        local thistype this = getIndex(0.5)
        //declare instance
    endmethod
endstruct

@Bribe
private gives error, if I put it inside the module...about the ban, oh well, I
would like to improve this and be glad to put in the graveyard :)...

@Nes
Like I said, there's nothing wrong with HT...


====
Updated v1.1
__________________
My Resources:
My Maps
My Systems/Spells

Your ideas tend to result in unnecessary violence so shut the F*** up!
mckill2009 is offline  
Old 06-17-2012, 12:25 AM   #8 (permalink)
Registered User Deaod
GUI sucks. Don't use it.
 
Join Date: Nov 2007
Posts: 832
Deaod has disabled reputation
I can adjust the code to use an array struct. Try adjusting your code so it works side by side with standard allocators.
Deaod is offline  
Old 06-17-2012, 12:40 AM   #9 (permalink)
Registered User mckill2009
SSJ99999 Pinoy!
 
mckill2009's Avatar
 
Join Date: Mar 2009
Posts: 4,380
mckill2009 is a splendid one to behold (847)mckill2009 is a splendid one to behold (847)mckill2009 is a splendid one to behold (847)mckill2009 is a splendid one to behold (847)mckill2009 is a splendid one to behold (847)
One of the reasons that I made this is to get away from standards to be different from
some points, but I might consider making it create/destroy...
__________________
My Resources:
My Maps
My Systems/Spells

Your ideas tend to result in unnecessary violence so shut the F*** up!
mckill2009 is offline  
Old 06-17-2012, 12:47 AM   #10 (permalink)
Forum Moderator Bribe
Keep it simple
 
Bribe's Avatar
Spells, Help Zones & JASS Moderator
 
Join Date: Sep 2009
Posts: 5,581
Bribe has much of which to be proud (1209)Bribe has much of which to be proud (1209)
PayPal Donor: This user has donated to The Hive. 
@mckill, declare private keywords with the method names then, it will make them private but still be able to interlink
__________________
How to post your triggers on the Hive Workshop.
JPAG - Bettering the cause of readable source code.

Bribe is offline  
Old 06-17-2012, 12:51 AM   #11 (permalink)
Registered User Deaod
GUI sucks. Don't use it.
 
Join Date: Nov 2007
Posts: 832
Deaod has disabled reputation
Yeah, lets all create our own standards.

XKCD
Deaod is offline  
Old 06-17-2012, 12:54 AM   #12 (permalink)
Forum Moderator Magtheridon96
JESUS MAN
 
Magtheridon96's Avatar
Resource Moderator
 
Join Date: Dec 2008
Posts: 5,699
Magtheridon96 has a brilliant future (1809)
Merit Badge - Level 0: This user has proven to be extremely valuable to the Warcraft III Modding Community. 
That's why I just go with the best standard, which is a combination of code clarity, code efficiency, code beauty and code simplicity.
Pretty much the same standards Nestharus has.

Nestharus' new comment-style makes this very easy.
__________________
Magtheridon96 is offline  
Old 06-17-2012, 06:40 AM   #13 (permalink)
Forum Moderator Bribe
Keep it simple
 
Bribe's Avatar
Spells, Help Zones & JASS Moderator
 
Join Date: Sep 2009
Posts: 5,581
Bribe has much of which to be proud (1209)Bribe has much of which to be proud (1209)
PayPal Donor: This user has donated to The Hive. 
Mag, one does not simply mention "Nestharus" to prove a point about "code beauty". Yes he may finally be back to coding with real names but still much of his JASS work on this site is full of omgwtfbbq. Yours had been just like it in the past before realizing the optimizer is no longer broken.
__________________
How to post your triggers on the Hive Workshop.
JPAG - Bettering the cause of readable source code.

Bribe is offline  
Old 06-17-2012, 10:31 AM   #14 (permalink)
Forum Moderator Magtheridon96
JESUS MAN
 
Magtheridon96's Avatar
Resource Moderator
 
Join Date: Dec 2008
Posts: 5,699
Magtheridon96 has a brilliant future (1809)
Merit Badge - Level 0: This user has proven to be extremely valuable to the Warcraft III Modding Community. 
Good point.
Well, the past is behind me :/
I now like readability more than speed.
__________________
Magtheridon96 is offline  
Old 06-17-2012, 08:57 PM   #15 (permalink)
Registered User Troll-Brain
cool != useful
 
Troll-Brain's Avatar
 
Join Date: Apr 2008
Posts: 1,937
Troll-Brain is just really nice (371)Troll-Brain is just really nice (371)Troll-Brain is just really nice (371)Troll-Brain is just really nice (371)
^
from the guy who abuse module and custom struct allocators and struct extends array.

We don't have the same definition of readability :o
__________________
- There are bugs with wc3, but most of time, the bug is between the keyboard and the chair.
- Never believe some warcraft "fact" without a proof, even from an "experienced" user, that's how myths & legends born.

You spam "...", "lol", and smilies such as "; p", "^)^",">.>"? You think you're the best and all other ones are stupids or at least less clever than you ? You think your errors are funny, while the other ones are incredibly lame ?
Maybe you've too much ego,or worse, you're a douchebag
Troll-Brain is offline  
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


All times are GMT. The time now is 07:41 AM.





Powered by vBulletin
Copyright 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.5.1 PL2
Copyright © Ralle