System Constant Timer Loop 32

Nestharus

o-o
Reaction score
84
JASS:

library CTL /* v1.1.0.0
	*************************************************************************************
	*
	*	CTL or Constant Timer Loop provides a loop for constant merged timers of timeout .03125
	*
	*	Similar to T32 but pauses timer when no structs have instances and removes structs
	*	from timer trigger when those structs have no instances. 
	*
	*	This can also create new timers after destroying a previous timer and generates less 
	*	code in the module. It also generates no triggers so long as the module is implemented 
	*	at the top of the struct.
	*
	************************************************************************************
	*
	*	static method create takes nothing returns thistype
	*		-	CTL
	*		-	Creates new timer
	*
	*	method destroy takes nothing returns nothing
	*		-	CTL
	*		-	Destroys created timer
	*
	*		Module
	*
	*			module CTL
	*				-	Declare locals in here
	*				-	Run ini code
	*			module CTLExpire
	*				-	Run timer code
	*				-
	*				-	thistype this		refers to current expiring timer\
	*			module CTLNull
	*				-	Null locals here
	*			module CTLEnd
	*
	*			Example of Constant Timer Loop 32
	*				struct MyTimer extends array
	*					integer myValue
	*					implement CTL
	*						local string s="My value is "
	*					implement CTLExpire
	*						call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,s+I2S(myValue))
	*						call destroy()
	*					implement CTLNull
	*						set s=null			//pointless, but shows how to use null block
	*					implement CTLEnd
	*				endstruct
	*
	*				set MyTimer.create().myValue=16 //will display "My value is 16" in 5 seconds
	*
	*			module CT32
	*				-	A constant running timer. Useful when the timer is pretty much never ever
	*				-	going to stop. Also allows control over loop (just provides an expiring timer).
	*				-	Code goes in between two methods
	*			module CT32End
	*
	*			Example of Constant Timer 32
	*
	*				//Displays
	*				//			1
	*				//			2
	*				//			3
	*				struct MyTimers extends array
	*					integer myValue
	*					thistype next
	*					implement CTL2
	*						local thistype this=thistype(0).next
	*						loop
	*							exitwhen 0==this
	*							call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,s+I2S(myValue))
	*							set this=next
	*						endloop
	*					implement CTL2End
	*					private static method onInit takes nothing returns nothing
	*						set thistype(0).next=1
	*						set thistype(1).next=2
	*						set thistype(2).next=3
	*						set thistype(1).myValue=1
	*						set thistype(2).myValue=2
	*						set thistype(3).myValue=3
	*					endmethod
	*				endstruct
	*
	************************************************************************************/
	globals
		private integer ic=0					//instance count
		private integer tc=0					//timer count
		private integer array rf				//root first
		private integer array n					//next
		private integer array p					//previous
		private integer array th				//timer head
		private integer array ns				//next stack
		private trigger t=CreateTrigger()
		private timer m=CreateTimer()
		private triggercondition array ct
		private conditionfunc array rc
	endglobals
	private function E takes nothing returns nothing
		local integer i=ns[0]
		set ns[0]=0
		loop
			exitwhen 0==i
			if (0==p<i>) then
				if (0==n<i>) then
					call TriggerRemoveCondition(t,ct[th<i>])
					set ct[th<i>]=null
					set tc=tc-1
					set rf[th<i>]=0
				else
					set rf[th<i>]=n<i>
					set p[n<i>]=0
				endif
			else
				set p[n<i>]=p<i>
				set n[p<i>]=n<i>
			endif
			set n<i>=n[0]
			set n[0]=i
			set i=ns<i>
		endloop
		if (0==tc) then
			call PauseTimer(m)
		else
			call TriggerEvaluate(t)
		endif
	endfunction
	private function CT takes integer r returns integer
		local integer i
		local integer f
		if (0==n[0]) then
			set i=ic+1
			set ic=i
		else
			set i=n[0]
			set n[0]=n<i>
		endif
		set th<i>=r
		set ns<i>=-1
		set f=rf[r]
		if (0==f) then
			set n<i>=0
			set p<i>=0
			set rf[r]=i
			set ct[r]=TriggerAddCondition(t,rc[r])
			if (0==tc) then
				call TimerStart(m,.031250000,true,function E)
			endif
			set tc=tc+1
		else
			set n<i>=f
			set p<i>=0
			set p[f]=i
			set rf[r]=i
		endif
		return i
	endfunction
	private function DT takes integer t returns nothing
		debug if (0&gt;ns[t]) then
			set ns[t]=ns[0]
			set ns[0]=t
		debug else
			debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,&quot;TIMER LOOP ERROR: ATTEMPT TO DESTROY NULL TIMER&quot;)
		debug endif
	endfunction
	private keyword r
	private keyword e
	module CTL
		static integer r
		static method create takes nothing returns thistype
			return CT(r)
		endmethod
		method destroy takes nothing returns nothing
			call DT(this)
		endmethod
		static method e takes nothing returns boolean
			local thistype this=rf[r]
	endmodule
	module CTLExpire
			loop
				exitwhen 0==this
	endmodule
	module CTLNull
				set this=n[this]
			endloop
	endmodule
	module CTLEnd
			return false
		endmethod
		private static method onInit takes nothing returns nothing
			set r=ic+1
			set ic=r
			set rc[r]=Condition(function thistype.e)
		endmethod
	endmodule
	module CT32
		static method e takes nothing returns boolean
	endmodule
	module CT32End
			return false
		endmethod
		private static method onInit takes nothing returns nothing
			call TriggerAddCondition(t,Condition(function thistype.e))
			if (0==tc) then
				call TimerStart(m,.031250000,true,function E)
			endif
			set tc=tc+1
		endmethod
	endmodule
endlibrary
</i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i>


Demo
JASS:

struct MyTimerLoop extends array
    integer value
    implement CTL
        local string s=&quot;My Value: &quot;
    implement CTLExpire
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,s+I2S(value))
    implement CTLNull
        set s=null //pointless, but shows how to use null block
    implement CTLEnd
    private static method onInit takes nothing returns nothing
        set create().value=1
    endmethod
endstruct


Constant Timer 32 Demo
JASS:

struct MyTimers extends array
	integer myValue
	thistype next
	implement CT32
		local thistype this=thistype(0).next
		loop
            exitwhen 0==this
            call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,I2S(myValue))
            set this=next
        endloop
	implement CT32End
	private static method onInit takes nothing returns nothing
		set thistype(0).next=1
		set thistype(1).next=2
		set thistype(2).next=3
		set thistype(1).myValue=1
		set thistype(2).myValue=2
		set thistype(3).myValue=3
	endmethod
endstruct
 
what happen with the inline? lol

I can't read your code, now its impossible -.-
 
Not sure about you guys, but I can actually read this code (albeit it's only because it's short :|).

At any rate, it looks pretty cool.

Too bad I moved away from JASS :p
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good
  • The Helper The Helper:
    I would like to see it again like Ghan had it the first time with pagination though - without the pagination that view will not work but with pagination it just might...
  • The Helper The Helper:
    This drink recipe I have had more than a few times back in the day! Mind Eraser https://www.thehelper.net/threads/cocktail-mind-eraser.194720/
  • The Helper The Helper:
    Happy Thursday!

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top