Worldedit
  Worldedit
Le site sur l'éditeur de warcraft 3 !
 
  FAQFAQ   RechercherRechercher   Liste des MembresListe des Membres    Groupes d'utilisateursGroupes d'utilisateurs   medals.phpMédailles   S'enregistrerS'enregistrer 
 ProfilProfil   Se connecter pour vérifier ses messages privésSe connecter pour vérifier ses messages privés   ConnexionConnexion 
  FAQFAQ World Editor   UploadUploader une map ou une image    UploadAjouter sa map à l'annuaire   UploadConsulter l'annuaire

Anozer timer System, yeah !

 
Poster un nouveau sujet   Répondre au sujet    Worldedit Index du Forum -> Aide sur les déclencheurs
Voir le sujet précédent :: Voir le sujet suivant  
Auteur Message
 Troll-Brain
Ri1kamoua


Inscrit le: 23 Aoû 2007
Messages: 7146
Sujets: 147
Spécialité en worldedit: le troll, le flood, la vulgarité, mon coeur balance
Médailles: 2 (En savoir plus...)
Rédacteur de tuto #3 (Quantité : 1) Grand mage créateur de sort (Quantité : 1)

MessagePosté le: 08/11/08 12:21    Sujet du message: Anozer timer System, yeah ! Citer

Comme c'est la mode de faire ses propres systèmes, j'ai créé mon propre système de timer.
Le but est d'utiliser un seul compteur plutôt que X compteurs pour des faibles périodes (jor 0.02 s).

Secret:

Jass:
library OneTimer initializer init uses EditedTimersUtils

    globals
        private constant real  TIME_OUT= 0.02
        private triggercondition array Trig_Cond
        private trigger Trig
        private timer Tim
        private integer I
        private timer Tim_temp
        private integer array Link
       
    // Theses variable are publics, cause we can't actually inline two, or more lines functions.
    // but don't use them !
        public integer Count= 0
        public integer Index= -1
    endglobals
   
    // You MUST use this textmacro ONE TIME at the begin of your Condition
    // ( just after the locals declaration )
   
    //! textmacro OT_Init
        set OneTimer_Index= OneTimer_Index+1
        if OneTimer_Index>= OneTimer_Count then
            set OneTimer_Index= 0
        endif
    //! endtextmacro
   
  private function Remove takes nothing returns nothing
        set Tim_temp= GetExpiredTimer()
        set I= GetTimerData(Tim_temp)
        call TriggerRemoveCondition(Trig,Trig_Cond[i])
        call ReleaseTimer(Tim_temp)
        set Count= Count-1
       
        if Count== 0 then
            call PauseTimer(Tim)
        endif
       
        loop
        exitwhen I== Count

            set Trig_Cond[i]= Trig_Cond[I+1]
            set Link[i]= Link[I+1]
           
        set I= I+1
        endloop
       
    endfunction
   
    function OT_Add takes conditionfunc cond , integer value returns nothing // use this function to add your condition to the timer expiration
        if Count==0 then
            call TimerStart(Tim,TIME_OUT,true,null)
        endif
        set Count= Count+1
        set Trig_Cond[Count-1]= TriggerAddCondition(Trig,cond)
        set Link[Count-1]= value
    endfunction
   
    function OT_End takes nothing returns nothing // use this function in your condition to remove it
        call TimerStart(NewTimer(Count-1),0.0,false,function Remove)
    endfunction
   
    function OT_GetLink takes nothing returns integer // use this function to get the integer attached to the condition
        return Link[OneTimer_Index]
    endfunction
   
    public function init takes nothing returns nothing
        set Trig= CreateTrigger()
        set Tim= CreateTimer()
        call TriggerRegisterTimerExpireEvent(Trig,Tim)
    endfunction
   
endlibrary



Secret:

Jass:
library EditedTimersUtils initializer init uses Functions

///////////// TimerUtils (Red Favor)
   
//*********************************************************************

   
    globals
        private constant integer QUANTITY   = 256
        private constant integer ARRAY_SIZE = 8191 //changing this to a higher value would effectively
                                                   //cripple the performance making this thing irrelevant
    endglobals

    //==================================================================================================
    globals
        private integer array data[ARRAY_SIZE]
        private integer OFFSET
    endglobals

    //It is dependent on jasshelper's recent inlining optimization in order to perform correctly.
    function SetTimerData takes timer t, integer value returns nothing
        debug if(H2I(t)-OFFSET<0) then
        debug     call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
        debug endif
        set data[H2I(t)-OFFSET]=value
    endfunction

    function GetTimerData takes timer t returns integer
        debug if(H2I(t)-OFFSET<0) then
        debug     call BJDebugMsg("GetTimerData: Wrong handle id, only use GetTimerData on timers created by NewTimer")
        debug endif

        return data[H2I(t)-OFFSET]
    endfunction

    //==========================================================================================
    globals
        private timer array tT
        private integer tN = 0
        private constant integer HELD=0x28829022
        //use a totally random number here, the more improbable someone uses it, the better.
    endglobals

    //==========================================================================================
    function NewTimer takes integer data returns timer
        if (tN==0) then
            //If this happens then the QUANTITY rule has already been broken, try to fix the
            // issue, else fail.
            debug call BJDebugMsg("NewTimer: Warning, Exceeding TimerUtils_QUANTITY, please increase it for your map, fix your map's timer leaks or switch to blue flavor when applicable")
            set tT[0]=CreateTimer()
            if (H2I(tT[0])-OFFSET<0) or (H2I(tT[0])-OFFSET>=ARRAY_SIZE) then
                //all right, couldn't fix it
                call BJDebugMsg("NewTimer: Unable to allocate a timer, you should probably switch to the blue flavor or fix timer leaks.")
                return null
            endif
        else
            set tN=tN-1
        endif
        call SetTimerData(tT[tN],data)
     return tT[tN]
    endfunction

    //==========================================================================================
    function ReleaseTimer takes timer t returns nothing
        if(t==null) then
            debug call BJDebugMsg("Warning: attempt to release a null timer")
            return
        endif
        if (tN==8191) then
            debug call BJDebugMsg("Warning: Timer stack is full, destroying timer!!")

            //stack is full, the map already has much more troubles than the chance of bug
            call DestroyTimer(t)
        else
            if(GetTimerData(t)==HELD) then
                debug call BJDebugMsg("Warning: ReleaseTimer: Double free!")
                return
            endif
            call PauseTimer(t)
            call SetTimerData(t,HELD)
            set tT[tN]=t
            set tN=tN+1
        endif   
    endfunction
   
    public function init takes nothing returns nothing
        local integer i
        local integer last
        local boolean correct
     
        loop
            set tT[0] = CreateTimer()
            set OFFSET=H2I(tT[0] )
            set i=1
            set correct=true
            loop
                exitwhen (i==QUANTITY)
                set tT[i] = CreateTimer()
                if(H2I(tT[i])-OFFSET<0) or (H2I(tT[i])-OFFSET>=ARRAY_SIZE) then
                    debug call BJDebugMsg("TimerUtils_redInit: Failed a initializing attempt")
                    set correct=false
                    exitwhen true
                endif
                set i=i+1
            endloop
            exitwhen correct
        endloop
        set tN=QUANTITY
    endfunction
   
endlibrary



Je n'attend pas vraiment de réactions enfin si je voudrais le comparer à TT et à Rapid Timers (dispo sur wc3campaigns.net) mais ce n'est pas le même principe, je voudrais donc savoir si vous avez une idée pour une comparaison valable.

Contrairement à TT et Rapid Timers, je n'appelle pas de fonctions pour toutes les conditions liées au timer, les conditions sont ajoutées au trigger et le trigger est évalué périodiquement grâce à l'expiration du timer périodique unique (event timer expire).

Donc je peux comparer les temps pour add/remove une condition mais difficilement le temps d'évaluation de toutes les conditions liées.
Car à ce que je sache un TriggerEvaluate doit être plus lent qu'une évaluation du trigger avec un event qui se déclenche, ou me fourvoie je?

PS : Je ne peux utiliser les natives de japi StopWatch... mais je ferais comme si, il me suffit de poster le code de test et quelqu'un fera le benchmark pour moi.

PS2 : Je ne posterais pas ceci comme ressource même si c'est le timer system le plus rapide jamais créé, pour plusieurs raisons que je ne citerais pas car j'ai la flemme Razz
Mais je donne le lien sur wc3campaigns ou j'explique pourquoi :
http://www.wc3campaigns.net/showthread.php?t=103292
_________________
Le violet, c'est moche.
Revenir en haut
Voir le profil de l'utilisateur Envoyer un message privé
Montrer les messages depuis:   
Poster un nouveau sujet   Répondre au sujet    Worldedit Index du Forum -> Aide sur les déclencheurs Toutes les heures sont au format GMT + 1 Heure
Page 1 sur 1

 
Sauter vers:  
Vous ne pouvez pas poster de nouveaux sujets dans ce forum
Vous ne pouvez pas répondre aux sujets dans ce forum
Vous ne pouvez pas éditer vos messages dans ce forum
Vous ne pouvez pas supprimer vos messages dans ce forum
Vous ne pouvez pas voter dans les sondages de ce forum


Powered by phpBB © 2001, 2005 phpBB Group
Traduction par : phpBB-fr.com