@name keyf_test3
@inputs 
@outputs AnimNext AnimPrev Loop Loops
@persist [AnimDuration] Anim:table [AnimFrame AnimTween AnimNext AnimPrev] [CurTime DeltaTime] Offt Temp Loop
@trigger none


if (first()) {
    
    #- Settings
    AnimDuration = 1
    AnimTween    = 500

    Anim = table(
        0 = ang(),
        1 = ang(45,0,0),
        2 = ang(90,0,0),
        3 = ang(135,0,0),
        4 = ang(135,90,0)
    )
    
    #- Vars
    AnimFrame = 0
    AnimNext = 1
    
    CurTime = curtime()
    Temp = curtime()

    holoCreate(1)
    holoModel(1, "models/sprops/misc/origin.mdl")
}

interval(90)

DeltaTime = curtime() - CurTime
CurTime   = curtime()

if (AnimFrame == AnimTween) {
    AnimPrev  = AnimNext                        # Previous keyframe
    AnimNext  = (AnimNext + 1) % Anim:count()   # Next keyframe
    AnimFrame = 0                               # Reset tween frames
    
    Loop++
    if (Loop == Anim:count()) {
        Loop = 0
        Loops++    
    }
}

Rate = ((Anim:count() / AnimDuration)*AnimTween)*DeltaTime
AnimFrame = min(AnimFrame + Rate, AnimTween)

Off = (Anim[AnimNext, angle] - Anim[AnimPrev, angle]) * (AnimFrame / AnimTween) + Anim[AnimPrev, angle]

holoAng(1, Off)

if (changed(Loops)) {
    print( curtime() - Temp )
    Temp = curtime()
    Offt = 1   
}


#[if (CurFrame == FrameInStep) {
    CurFrame = 0
    AnimStepPrev = AnimStep
    AnimStep = (AnimStep + 1) % Anim:count()
}]#
