2020-02-02 23:33:07 +00:00
|
|
|
( timer + lerping )
|
|
|
|
: clamp0 ( range val -- i )
|
|
|
|
2dup <= if drop else
|
|
|
|
dup 0 <= if drop drop 0 else
|
|
|
|
swap drop then then ;
|
|
|
|
: >ratio ( range value -- f )
|
|
|
|
over swap clamp0 swap />ratio ;
|
|
|
|
: <ratio ( range ratio -- v ) *<ratio ;
|
|
|
|
: >range ( start end -- start range ) over - ;
|
|
|
|
: <range ( start range -- start end ) over + ;
|
|
|
|
: lerpr ( start end ratio ) >r >range <r <ratio + ;
|
|
|
|
: lerpn ( start1 end1 start2 end2 val )
|
|
|
|
>r >range <r <rot - >ratio lerpr ;
|
|
|
|
: lerp ( start end duration start -- i )
|
|
|
|
ticks udelta ( start end duration delta )
|
|
|
|
>ratio lerpr ;
|
|
|
|
|
|
|
|
: triggered ( duration timer -- b )
|
|
|
|
dup >r @ ticks udelta ( duration delta )
|
|
|
|
2dup <= if drop <r +! 1 else drop drop rdrop 0 then ;
|
|
|
|
|
|
|
|
: now! ( timer -- ) ticks swap ! ;
|
|
|
|
: advance! ( timer -- delta )
|
|
|
|
dup @ ticks udelta ( timer delta )
|
|
|
|
dup <rot +! ;
|
|
|
|
|
|
|
|
: move-to ( target speed p -- )
|
|
|
|
dup >r @ >rot ticks ( from to duration start )
|
|
|
|
begin
|
|
|
|
4dup lerp r@ !
|
|
|
|
<rot dup r@ @ != ( from duration start to !done )
|
|
|
|
while
|
|
|
|
>rot suspend
|
|
|
|
repeat rdrop drop drop drop drop ;
|
|
|
|
|
2020-03-07 23:55:18 +00:00
|
|
|
: still-waiting? ( count ticks-start -- ) ticks udelta u> ;
|
2020-02-02 23:33:07 +00:00
|
|
|
: sleep ( count -- )
|
2020-03-07 23:55:18 +00:00
|
|
|
ticks begin 2dup still-waiting? while suspend repeat drop drop ;
|