• 🏆 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!

OCRE timers

Level 3
Joined
Sep 6, 2008
Messages
45
Ocre

Now the system has been changed, the last version was bad i know, but i think this one is much better, just give feedback.

Changes:

3.14
Now uses 1 trigger, and conditions to evaluate, it must be faster now

1.00
- Now its a global timer use system, but with some extras against some others already made.

Features:

- No H2I
- Allows you to specify period
- Easy to use ( Start / GetData / Stop )
- Uses only 1 trigger to evaluate the conditions

Important:

- Remember when you are done with your function use return true, if not use return false

Functions:
JASS:
function Ocre_Start takes function FUNC, integer DATA, real PERIOD returns nothing
JASS:
function Ocre_GetData takes nothing returns integer

JASS:
library Ocre initializer init

globals

  //========================================================================
    public constant real PERIOD = 0.025
  //========================================================================
  
    private timer TIMER
    
    private integer RUN = 0

    public real array periodz
    public real array maxperiodz
    
    public integer Data
    public integer Index

    private triggercondition array TC
    private conditionfunc array CF
    private trigger Trig
    
    private integer array DATAS
endglobals

//==================================================================================================================
// Timerz System
//==================================================================================================================

public function GetData takes nothing returns integer // GetValue func
    return Data
endfunction

public function GetIndex takes nothing returns integer // GetIndex func
    return Index
endfunction

private function onLoop takes nothing returns nothing
    local integer count = RUN
    local boolean B
    
    loop
    exitwhen count <= 0
    
    set count:periodz = count:periodz-PERIOD
    
    set Data = count:DATAS
    set Index = count
    
    if count:periodz <= 0 then
    
    set count:periodz = count:maxperiodz
    
    set count:TC = TriggerAddCondition(Trig, count:CF)
    set B = TriggerEvaluate(Trig)
    call TriggerRemoveCondition(Trig, count:TC)

    if B == true then
        set count:CF = RUN:CF
        set count:TC = null
        set count:DATAS = RUN:DATAS
        set count:periodz = RUN:periodz
        set count:maxperiodz = RUN:maxperiodz
        set RUN = RUN-1
    endif
endif
        set count = count-1
    endloop

endfunction

public function Start takes code func, integer data, real period returns integer

    set RUN = RUN + 1

    set RUN:CF = Condition(func)
    set RUN:DATAS = data
    set RUN:periodz= period
    set RUN:maxperiodz = period

    return RUN
endfunction

private function init takes nothing returns nothing
    set Trig = CreateTrigger()
    set TIMER = CreateTimer()
    call TimerStart( TIMER, PERIOD, true, function onLoop)
endfunction

endlibrary
 
Last edited:
Level 3
Joined
Sep 6, 2008
Messages
45
Damn, i only want feedback, i don't want noob comments, i don't have said its for use, maybe someone like it, it's for testing

And vs timerutils this doesn't use H2I or has a 256 maxtimer limit
 
Level 11
Joined
Nov 4, 2007
Messages
337
If its not for use, why do you release it?
TimerUtils has a limitof timers used at the SAME TIME that is CHANGEABLE and TimerUtils has GREAT DEBUG MESSAGES.
But..
YOu want feedback :)

-The code looks like spaghetti. Choose everything except globals blocks and functions and press TAB!
-That is doesn't use H2I is not a feature. You have to save the Index of the timer. That makes the whole system completely useless. You can also save the data directly Oo.


local integer y = 0

loop
exitwhen t == y:Timers or y > MAX
set y = y+1
endloop

return y:IndexTim


What's the sense behind this`?

FAIL!
 
Level 3
Joined
Sep 6, 2008
Messages
45
It's for use if someone wants to use it, althought i think no one will use it but well
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
The great thing about timer utils is its standardised interface. The least you should do is stick to this interface so users could easily swap between this system and TimerUtils.

I also don't see any advantages that would make me prefer this system above the already existing timerutils.
 
Level 11
Joined
Nov 4, 2007
Messages
337
Yep.
Let me rewrite your system:
JASS:
struct OCRE
    integer value = 0
    timer ocreTimer = CreateTimer()
    
    static method NewIndex takes nothing returns OCRE
        return OCRE.create()
    endfunction

    method SetIndexVal takes integer val returns nothing
        set .value = val
    endmethod
    
    method GetIndexVal takes nothing returns nothing
        return .value
    endmethod
    
    method ConvertIndex takes nothing returns timer
        return .ocreTimer
    endmethod
    
    static method onDestroy takes nothing returns nothing
        call DestroyTimer(this.ocreTimer)
    endmethod
endstruct

So.. This is a struct with preloaded timers?
 
Level 3
Joined
Sep 6, 2008
Messages
45
Yep.
Let me rewrite your system:
JASS:
struct OCRE
    integer value = 0
    timer ocreTimer = CreateTimer()
    
    static method NewIndex takes nothing returns OCRE
        return OCRE.create()
    endfunction

    method SetIndexVal takes integer val returns nothing
        set .value = val
    endmethod
    
    method GetIndexVal takes nothing returns nothing
        return .value
    endmethod
    
    method ConvertIndex takes nothing returns timer
        return .ocreTimer
    endmethod
    
    static method onDestroy takes nothing returns nothing
        call DestroyTimer(this.ocreTimer)
    endmethod
endstruct

So.. This is a struct with preloaded timers?

That version is creating a timer every time a struct is created, also timers are destroyed instead of reciclyed. Also how do you get an struct from a timer in that way?
 
Level 11
Joined
Nov 4, 2007
Messages
337
JASS:
library OCRE
    globals
        private timer array Handle
        private integer Wanted = 0
    endglobals
    
private function New takes nothing returns timer
     if ( Wanted<1 ) then
        return CreateTimer()
    endif

        set Wanted = Wanted - 1
        return Handle[Wanted]
endfunction

private function Release takes timer which returns nothing
    set Handle[Wanted] = which
    set Wanted = Wanted + 1
    call PauseTimer(which)
endfunction

struct OCRE
    integer value = 0
    timer ocreTimer
    
    static method create takes nothing returns OCRE
        local OCRE a = OCRE.allocate()
        set a.ocreTimer = New()
        return a
    endmethod

    static method onDestroy takes nothing returns nothing
        call Release(this.ocreTimer)
    endmethod
    
endstruct
endlibrary
 
Level 3
Joined
Sep 6, 2008
Messages
45
Nice, but, im still wanting how do you get the struct with the value from the timer once you run another func
 
Level 11
Joined
Nov 4, 2007
Messages
337
ExecuteFunc is slow. Slower than TriggerEvaluate. And if you really need something like that, use KeyTimers2, since that one is the fastest one to my knowledge (and tbh, i dont think we need yet another timer system).

As he wrote.
[x] trash and use TimerUtils or KT or TimedLoop or Struct Iteration ...
 
Level 3
Joined
Sep 6, 2008
Messages
45
Now uses 1 trigger with conditions being evaluated. Now talk about the system i want to know what to improve, no more trash comments please.
 
Level 14
Joined
Nov 18, 2007
Messages
816
Depending on how far you want to go with optimizing this system, youll end up with either a copy of TT or with a copy of KT2.

Really, this thing has been invented a hundred times already.

Still, if you want to know what to improve, look at one (or even both) of the systems i mentioned earlier.
 
Top