• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vJASS] (Optimizer32) code help

Status
Not open for further replies.
Level 9
Joined
Jun 21, 2012
Messages
432
someone tell me that this wrong in this code pls :ogre_rage:

JASS:
library Optimizer32
/*********************************************************************************
*
*   Optimizer32
*   ___________
*   v1.0.0.0
*   by Thelordmarshall
*   
*   Description: Coming soon.   
*
*   Credits:
*   ________
*       - 
*
*   Notes:
*   ______
*       - All suggestions are welcome
*   
*   Copyright © 2015.
*********************************************************************************/
    struct Timer32
        static constant real PERIOD=.031250000
        private static timer t32=CreateTimer()
        private static integer array list
        private static integer array timerList
        private static integer size=0
        private static integer timerSize=0
        private static integer instanceData=0
        private trigger t
        private integer data
        private real duration
        private boolean active
        private boolean periodic
        private triggercondition tc
        
        private static method loop32 takes nothing returns nothing
            local integer i=0
            local integer c=0
            local thistype this
            loop
                exitwhen(i==timerSize)
                set this=timerList[i]
                if(.active)then
                    set instanceData=.data
                    if(not.periodic)then
                        set .duration=.duration-PERIOD
                        if(.duration<=0.)then
                            call TriggerEvaluate(.t)
                            call .stop()
                        endif
                    else
                        call TriggerEvaluate(.t)
                    endif
                    set c=c+1
                endif
                set i=i+1
            endloop
            set timerSize=c
            if(c==0)then
                //call BJDebugMsg("t32 paused")
                call PauseTimer(t32)
            endif
        endmethod
        
        static method getData takes nothing returns integer
            return instanceData
        endmethod
        
        static method start takes integer data, real duration, code c returns Timer32
            local thistype this=list[0]
            if(this==0)then
                set this=size+1
                set size=this
            else
                set list[0]=list[this]
            endif
            if(not.active)then
                set .t=CreateTrigger()
                set .data=data
                set .active=true
                set .duration=duration
                set .periodic=(.duration==0)
                set .tc=TriggerAddCondition(.t,Condition(c))
                set timerList[timerSize]=this
                set timerSize=timerSize+1
                if(timerSize==1)then
                    call TimerStart(t32,PERIOD,true,function thistype.loop32)
                endif
            endif
            return this
        endmethod
        
        method stop takes nothing returns nothing
            set list[this]=list[0]
            set list[0]=this
            set timerList[timerSize]=timerList[0]
            set timerList[0]=timerSize
            set .active=false
            set .periodic=false
            call TriggerRemoveCondition(.t,.tc)
            call DestroyTrigger(.t)
            set .t=null
            set .tc=null
        endmethod
    endstruct
endlibrary
 
Last edited:
Level 9
Joined
Jun 21, 2012
Messages
432
I could fix the code as follows:

JASS:
library Optimizer32
/*********************************************************************************
*
*   Optimizer32
*   ___________
*   v1.0.0.0
*   by Thelordmarshall
*   
*   Description: Coming soon.   
*
*   Credits:
*   ________
*       - 
*
*   Notes:
*   ______
*       - All suggestions are welcome
*   
*   Copyright © 2015.
*********************************************************************************/
    struct Timer32
        static constant real PERIOD=.031250000
        private static timer t32=CreateTimer()
        private static boolean timerActive=false
        private static integer instanceData=0
        private static integer array size
        private trigger t
        private integer data
        private real duration
        private boolean active
        private boolean periodic
        private triggercondition tc
        
        private static method loop32 takes nothing returns nothing
            local integer i=0
            local thistype this
            loop
                exitwhen(i>size[2])
                set this=i
                if(.active)then
                    set instanceData=.data
                    if(not.periodic)then
                        set .duration=.duration-PERIOD
                        if(.duration<=0.)then
                            call TriggerEvaluate(.t)
                            call .stop()
                        endif
                    else
                        call TriggerEvaluate(.t)
                    endif
                endif
                set i=i+1
            endloop
            if(size[1]==0)then
                //call BJDebugMsg("t32 paused")
                set timerActive=false
                call PauseTimer(t32)
            endif
        endmethod
        
        static method getData takes nothing returns integer
            return instanceData
        endmethod
        
        static method start takes integer data, real duration, code c returns Timer32
            local thistype this
            set size[1]=size[1]+1
            set size[2]=size[2]+1
            set this=size[2]
            if(not.active)then
                set .t=CreateTrigger()
                set .data=data
                set .active=true
                set .duration=duration
                set .periodic=(.duration==0)
                set .tc=TriggerAddCondition(.t,Condition(c))
                if(not timerActive)then
                    //call BJDebugMsg("t32 started")
                    set timerActive=true
                    call TimerStart(t32,PERIOD,true,function thistype.loop32)
                endif
            endif
            return this
        endmethod
        
        method stop takes nothing returns nothing
            set size[1]=size[1]-1
            if(size[1]==0)then
                set size[2]=0
            endif
            set .active=false
            set .periodic=false
            call TriggerRemoveCondition(.t,.tc)
            call DestroyTrigger(.t)
            set .t=null
            set .tc=null
        endmethod
    endstruct
endlibrary
 
Status
Not open for further replies.
Top