diff --git a/Runtime/Actions/Delay.cs b/Runtime/Actions/Time/Delay.cs similarity index 100% rename from Runtime/Actions/Delay.cs rename to Runtime/Actions/Time/Delay.cs diff --git a/Runtime/Actions/Time/DelayedList.cs b/Runtime/Actions/Time/DelayedList.cs new file mode 100644 index 0000000..2724cba --- /dev/null +++ b/Runtime/Actions/Time/DelayedList.cs @@ -0,0 +1,57 @@ + +using Godot; + +using System.Collections.Generic; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class DelayedList : Action + { + [Export] + public float durationInbetween = 0.1f; + + [Export] + public float growDuration = 0.0f; + + [Export] + public TimeLine timeLine; + + [Export] + public Action[] actions; + + /** Whether to execute Action child nodes*/ + [Export] + public bool triggerDirectChildren = true; + + protected override void _OnTrigger() + { + var list = new List(); + + list.AddRange( actions ); + + if ( triggerDirectChildren ) + { + list.AddRange( Nodes.GetDirectChildren( this ) ); + } + + var offset = 0f; + var grow = 0f; + + for ( int i = 0; i < list.Count; i++ ) + { + TimeLineScheduler.ScheduleEventIn( timeLine, offset, + id => + { + Action.Trigger( list[ i ] ); + } + ); + + grow += growDuration; + offset += durationInbetween + grow; + + } + } + } +} \ No newline at end of file diff --git a/Runtime/Actions/Time/Repeat.cs b/Runtime/Actions/Time/Repeat.cs new file mode 100644 index 0000000..35bf2d3 --- /dev/null +++ b/Runtime/Actions/Time/Repeat.cs @@ -0,0 +1,57 @@ + +using Godot; + + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class Repeat : Action + { + + [Export] + public float duration; + + [Export] + public int numRepeats; + + [Export] + public TimeLine timeLine; + + [Export] + public Action action; + + [Export] + public Action onBeforeFirst; + + [Export] + public Action onAfterLast; + + + protected override void _OnTrigger() + { + for ( int i = 0; i < numRepeats; i++ ) + { + TimeLineScheduler.ScheduleEventIn( timeLine, i * duration, + id => + { + if ( i == 0 ) + { + Action.Trigger( onBeforeFirst ); + } + + Action.Trigger( action ); + + if ( i == ( numRepeats - 1 ) ) + { + Action.Trigger( onAfterLast ); + } + } + + ); + + + } + } + } +} \ No newline at end of file diff --git a/Runtime/Actions/Time/TimeLooper.cs b/Runtime/Actions/Time/TimeLooper.cs new file mode 100644 index 0000000..45738da --- /dev/null +++ b/Runtime/Actions/Time/TimeLooper.cs @@ -0,0 +1,73 @@ + +using Godot; + + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class TimeLooper : Node + { + + + bool _active = false; + + [Export] + public bool active + { + get => _active; + set + { + SetActive( value ); + } + } + + [Export] + public float duration; + + [Export] + public float offset; + + [Export] + public TimeLine timeLine; + + [Export] + public Action action; + + int _eventID = -1; + + void SetActive( bool active ) + { + if ( active == _active || Engine.IsEditorHint() ) + { + return; + } + + _active = active; + + if ( _active ) + { + if ( _eventID != -1 ) + { + TimeLineScheduler.RemoveEvent( timeLine, _eventID ); + return; + } + + _eventID = TimeLineScheduler.ScheduleLoopEvent( timeLine, duration, offset, id => Action.Trigger( action ) ); + } + else + { + if ( _eventID == -1 ) + { + return; + } + + TimeLineScheduler.RemoveEvent( timeLine, _eventID ); + _eventID = -1; + } + + + + } + } +} \ No newline at end of file diff --git a/Runtime/Animation/Follow.cs b/Runtime/Animation/Follow.cs index cf03b6a..a01ede2 100644 --- a/Runtime/Animation/Follow.cs +++ b/Runtime/Animation/Follow.cs @@ -43,11 +43,12 @@ namespace Rokojori if ( positionSmoothing != null && positionSmoothing is FrameSmoothing fra ) { + if ( _lastFrames != fra.frames ) { _lastFrames = fra.frames; - var coefficient = fra.GetCoefficientForFrames( fra.frames ); + var coefficient = FrameSmoothing.GetCoefficientForFrames( fra.frames ); var framesOn60hz = fra.frames * ( 1f / 60f ); diff --git a/Runtime/Animation/Smoothing/ExpSmoothing.cs b/Runtime/Animation/Smoothing/ExpSmoothing.cs index 709fab5..4fb553c 100644 --- a/Runtime/Animation/Smoothing/ExpSmoothing.cs +++ b/Runtime/Animation/Smoothing/ExpSmoothing.cs @@ -22,5 +22,32 @@ namespace Rokojori exp.coefficient = coefficient; return exp.ComputeDuration(); } + + + public static float ComputeCoefficientForFrames( int numFrames, float treshold = 1f/60f * 0.02f ) + { + + var lowDurationCoefficient = 500f; + var highDurationCoefficient = 0.1f; + + if ( numFrames < 1 ) + { + return lowDurationCoefficient; + } + + var framesDuration = numFrames * 1/60f; + + + var minMaxSearch = new MinMaxSearch( + ( a, b, t ) => Mathf.Lerp( a, b, t ), + ( c ) => ExpSmoothing.GetDurationForCoefficient( c ) + ); + + var coefficient = minMaxSearch.Find( framesDuration, lowDurationCoefficient, highDurationCoefficient, treshold ); + + + return coefficient; + + } } } \ No newline at end of file diff --git a/Runtime/Animation/Smoothing/FrameSmoothing.cs b/Runtime/Animation/Smoothing/FrameSmoothing.cs index 5c1c636..8d97209 100644 --- a/Runtime/Animation/Smoothing/FrameSmoothing.cs +++ b/Runtime/Animation/Smoothing/FrameSmoothing.cs @@ -10,57 +10,24 @@ namespace Rokojori { [Export( PropertyHint.Range, "0,600")] public int frames = 10; - - static Dictionary _framesToCoefficient = new Dictionary(); - + protected override float _ComputeInterpolationAmount( float delta ) { + frames = Mathf.Clamp( frames, 0, 600 ); + if ( frames <= 0 ) { return 1; - } + } var coefficient = GetCoefficientForFrames( frames ); return 1f - Mathf.Exp( -coefficient * delta ); } - public float GetCoefficientForFrames( int frames ) + public static float GetCoefficientForFrames( int frames ) { - if ( ! _framesToCoefficient.ContainsKey( frames ) ) - { - _framesToCoefficient[ frames ] = ComputeCoefficientForFrames( frames ); - } - - return _framesToCoefficient[ frames ]; + return FrameSmoothingTable.Get( frames ); } - static float ComputeCoefficientForFrames( int numFrames, float treshold = 1f/60f * 0.1f ) - { - - var framesDuration = numFrames * 1/60f; - - - var minMaxSearch = new MinMaxSearch( - ( a, b, t ) => Mathf.Lerp( a, b, t ), - ( c ) => ExpSmoothing.GetDurationForCoefficient( c ) - ); - - var lowDurationCoefficient = 100000f; - var highDurationCoefficient = 0.1f; - - - RJLog.Log( "Finding coefficient for frames", numFrames, ">>", framesDuration, "s" ); - - var coefficient = minMaxSearch.Find( framesDuration, lowDurationCoefficient, highDurationCoefficient, treshold ); - - RJLog.Log( "Found coefficient:", coefficient, ">> duration", ExpSmoothing.GetDurationForCoefficient( coefficient )._FF(), "s" ); - - return coefficient; - - } - - - - } } \ No newline at end of file diff --git a/Runtime/Animation/Smoothing/FrameSmoothingTable.cs b/Runtime/Animation/Smoothing/FrameSmoothingTable.cs new file mode 100644 index 0000000..4737634 --- /dev/null +++ b/Runtime/Animation/Smoothing/FrameSmoothingTable.cs @@ -0,0 +1,633 @@ +using System.Collections; +using System.Collections.Generic; +using Godot; + +namespace Rokojori +{ + public class FrameSmoothingTable + { + public const int num = 601; + + public static float Get( int key ) + { + return data[ key ]; + } + + public static void ComputeAndSaveTable( string path ) + { + var computed = new float[ FrameSmoothingTable.num ]; + + for ( int i = 0; i < num; i++ ) + { + computed[ i ] = ExpSmoothing.ComputeCoefficientForFrames( i ); + } + + FilesSync.SaveUTF8( path, Lists.Join( Lists.From( computed ), "f,\n" ) ); + } + + static readonly float[] data = new float[] + { + 500f, + 283.581298828125f, + 139.73373413085938f, + 92.77377319335938f, + 69.44607543945312f, + 55.49477767944336f, + 46.21171569824219f, + 39.58964157104492f, + 34.627803802490234f, + 30.771270751953125f, + 27.687593460083008f, + 25.16560173034668f, + 23.06490135192871f, + 21.287748336791992f, + 19.7650146484375f, + 18.445554733276367f, + 17.291311264038086f, + 16.27288246154785f, + 15.367767333984375f, + 14.558114051818848f, + 13.829330444335938f, + 13.170221328735352f, + 12.57108211517334f, + 12.024028778076172f, + 11.522516250610352f, + 11.061280250549316f, + 10.63553524017334f, + 10.241303443908691f, + 9.87530517578125f, + 9.534504890441895f, + 9.216452598571777f, + 8.918947219848633f, + 8.640054702758789f, + 8.378063201904297f, + 8.131572723388672f, + 7.899065971374512f, + 7.679544448852539f, + 7.471868515014648f, + 7.275096893310547f, + 7.088548183441162f, + 6.911216735839844f, + 6.7425761222839355f, + 6.58193302154541f, + 6.428795337677002f, + 6.282650947570801f, + 6.1429643630981445f, + 6.009374618530273f, + 5.881429195404053f, + 5.758898735046387f, + 5.641271591186523f, + 5.528425216674805f, + 5.41996431350708f, + 5.3156914710998535f, + 5.215364456176758f, + 5.118772029876709f, + 5.0256500244140625f, + 4.935863971710205f, + 4.849242210388184f, + 4.765618801116943f, + 4.684786319732666f, + 4.6067047119140625f, + 4.5311479568481445f, + 4.458031177520752f, + 4.387297630310059f, + 4.3186798095703125f, + 4.252230644226074f, + 4.18775749206543f, + 4.1252570152282715f, + 4.064601898193359f, + 4.005623817443848f, + 3.948420763015747f, + 3.8927950859069824f, + 3.8386731147766113f, + 3.7860772609710693f, + 3.7349131107330322f, + 3.6851160526275635f, + 3.636634349822998f, + 3.589371681213379f, + 3.5433261394500732f, + 3.4984500408172607f, + 3.4547362327575684f, + 3.41206955909729f, + 3.3704464435577393f, + 3.329827070236206f, + 3.2901761531829834f, + 3.251462697982788f, + 3.213653802871704f, + 3.176679849624634f, + 3.1405816078186035f, + 3.105264902114868f, + 3.070765256881714f, + 3.0370264053344727f, + 3.003992795944214f, + 2.9717040061950684f, + 2.940070390701294f, + 2.9091360569000244f, + 2.8788161277770996f, + 2.8491201400756836f, + 2.820035696029663f, + 2.791569709777832f, + 2.763646364212036f, + 2.7362406253814697f, + 2.709437608718872f, + 2.6831271648406982f, + 2.6572930812835693f, + 2.6320114135742188f, + 2.6071770191192627f, + 2.582808494567871f, + 2.5588653087615967f, + 2.5353894233703613f, + 2.512341022491455f, + 2.489710807800293f, + 2.4674808979034424f, + 2.445652723312378f, + 2.4241487979888916f, + 2.403071403503418f, + 2.382392168045044f, + 2.3620100021362305f, + 2.3419981002807617f, + 2.3223023414611816f, + 2.3029582500457764f, + 2.2839038372039795f, + 2.265169858932495f, + 2.2467894554138184f, + 2.228628396987915f, + 2.210813045501709f, + 2.1932532787323f, + 2.1759724617004395f, + 2.1590123176574707f, + 2.142235279083252f, + 2.125772714614868f, + 2.109534740447998f, + 2.0935709476470947f, + 2.077817678451538f, + 2.0623042583465576f, + 2.047018051147461f, + 2.0319600105285645f, + 2.0171475410461426f, + 2.00252366065979f, + 1.9881082773208618f, + 1.9739007949829102f, + 1.9598971605300903f, + 1.9460855722427368f, + 1.932471752166748f, + 1.9190549850463867f, + 1.905813455581665f, + 1.8927764892578125f, + 1.8798773288726807f, + 1.8671958446502686f, + 1.8546583652496338f, + 1.8422939777374268f, + 1.8300729990005493f, + 1.8180501461029053f, + 1.8061472177505493f, + 1.794433355331421f, + 1.7828596830368042f, + 1.771410346031189f, + 1.7601466178894043f, + 1.7490057945251465f, + 1.7379857301712036f, + 1.7271277904510498f, + 1.7163945436477661f, + 1.7058008909225464f, + 1.6953409910202026f, + 1.685006022453308f, + 1.6747899055480957f, + 1.6646863222122192f, + 1.6547212600708008f, + 1.6448748111724854f, + 1.63514244556427f, + 1.6255245208740234f, + 1.6160211563110352f, + 1.606610894203186f, + 1.5973433256149292f, + 1.5881503820419312f, + 1.5790756940841675f, + 1.570091724395752f, + 1.5612257719039917f, + 1.5524506568908691f, + 1.5437687635421753f, + 1.5351957082748413f, + 1.5267354249954224f, + 1.5183507204055786f, + 1.510025143623352f, + 1.5018233060836792f, + 1.493721842765808f, + 1.4856828451156616f, + 1.4777395725250244f, + 1.4698690176010132f, + 1.462095022201538f, + 1.4544039964675903f, + 1.4467787742614746f, + 1.4392509460449219f, + 1.431795358657837f, + 1.4244188070297241f, + 1.4171051979064941f, + 1.409865140914917f, + 1.4027140140533447f, + 1.3956362009048462f, + 1.388612985610962f, + 1.3816556930541992f, + 1.3748058080673218f, + 1.3679734468460083f, + 1.3612393140792847f, + 1.3545730113983154f, + 1.3479712009429932f, + 1.3414026498794556f, + 1.334961175918579f, + 1.3285306692123413f, + 1.3221654891967773f, + 1.3158795833587646f, + 1.3096164464950562f, + 1.303462028503418f, + 1.297347068786621f, + 1.291259765625f, + 1.2852731943130493f, + 1.2793049812316895f, + 1.2734116315841675f, + 1.2675613164901733f, + 1.2617697715759277f, + 1.2560545206069946f, + 1.2503502368927002f, + 1.2447389364242554f, + 1.2391352653503418f, + 1.233640432357788f, + 1.228132724761963f, + 1.2227063179016113f, + 1.2173126935958862f, + 1.2119815349578857f, + 1.2066696882247925f, + 1.2014259099960327f, + 1.1962333917617798f, + 1.19107186794281f, + 1.1859670877456665f, + 1.1808918714523315f, + 1.1758713722229004f, + 1.1708842515945435f, + 1.165951132774353f, + 1.1610461473464966f, + 1.1561956405639648f, + 1.1513667106628418f, + 1.14658522605896f, + 1.1418571472167969f, + 1.1371469497680664f, + 1.132511854171753f, + 1.1278595924377441f, + 1.1233044862747192f, + 1.1187365055084229f, + 1.114235520362854f, + 1.1097650527954102f, + 1.1053249835968018f, + 1.1008992195129395f, + 1.096550464630127f, + 1.0922147035598755f, + 1.0879191160202026f, + 1.0836459398269653f, + 1.0793945789337158f, + 1.075201392173767f, + 1.0710294246673584f, + 1.0668925046920776f, + 1.0627957582473755f, + 1.0587204694747925f, + 1.0546735525131226f, + 1.0506591796875f, + 1.0466867685317993f, + 1.042757511138916f, + 1.0388169288635254f, + 1.0349215269088745f, + 1.0310591459274292f, + 1.0272457599639893f, + 1.0234252214431763f, + 1.019643783569336f, + 1.015916347503662f, + 1.0121873617172241f, + 1.0084819793701172f, + 1.0048153400421143f, + 1.0011717081069946f, + 0.9975594282150269f, + 0.9939855337142944f, + 0.9903967976570129f, + 0.9868771433830261f, + 0.9833724498748779f, + 0.9798818826675415f, + 0.9764040112495422f, + 0.9729690551757812f, + 0.9695543050765991f, + 0.9661747813224792f, + 0.9627928733825684f, + 0.9594693183898926f, + 0.9561452269554138f, + 0.9528394341468811f, + 0.9495774507522583f, + 0.946311354637146f, + 0.9431012272834778f, + 0.9398893117904663f, + 0.9366958737373352f, + 0.933527946472168f, + 0.9303995370864868f, + 0.9272783994674683f, + 0.9241516590118408f, + 0.9210768342018127f, + 0.9180124998092651f, + 0.9149739146232605f, + 0.9119710922241211f, + 0.9089577198028564f, + 0.9059733748435974f, + 0.903017520904541f, + 0.9000647664070129f, + 0.8971512317657471f, + 0.8942551016807556f, + 0.8913599848747253f, + 0.8884860873222351f, + 0.8856471180915833f, + 0.8828186392784119f, + 0.880012035369873f, + 0.8772291541099548f, + 0.8744516372680664f, + 0.8716967701911926f, + 0.8689366579055786f, + 0.8662132620811462f, + 0.8635026216506958f, + 0.860801100730896f, + 0.858134925365448f, + 0.8554983735084534f, + 0.8528401255607605f, + 0.8502227663993835f, + 0.8476150035858154f, + 0.8450098633766174f, + 0.8424324989318848f, + 0.8398773074150085f, + 0.837332010269165f, + 0.8348090052604675f, + 0.8322899341583252f, + 0.8297901153564453f, + 0.8272949457168579f, + 0.8248292803764343f, + 0.8223952651023865f, + 0.8199321627616882f, + 0.8175209164619446f, + 0.8151203393936157f, + 0.8127100467681885f, + 0.8103369474411011f, + 0.8079510927200317f, + 0.8055998086929321f, + 0.8032541275024414f, + 0.8009384870529175f, + 0.7986142039299011f, + 0.7963138222694397f, + 0.794023871421814f, + 0.7917568683624268f, + 0.7894957065582275f, + 0.7872359752655029f, + 0.7850046753883362f, + 0.7827632427215576f, + 0.780563235282898f, + 0.7783754467964172f, + 0.7761781811714172f, + 0.7739938497543335f, + 0.7718440890312195f, + 0.7696950435638428f, + 0.7675509452819824f, + 0.7654231190681458f, + 0.7633078694343567f, + 0.7612106800079346f, + 0.7591174244880676f, + 0.7570306062698364f, + 0.7549625039100647f, + 0.7529008984565735f, + 0.7508677244186401f, + 0.7488330602645874f, + 0.7467980980873108f, + 0.7447925806045532f, + 0.74278724193573f, + 0.7408173680305481f, + 0.7388277649879456f, + 0.7368583679199219f, + 0.7348807454109192f, + 0.7329365015029907f, + 0.7310168743133545f, + 0.7290605902671814f, + 0.7271442413330078f, + 0.7252537608146667f, + 0.723365068435669f, + 0.7214744687080383f, + 0.7195754647254944f, + 0.717719554901123f, + 0.7158574461936951f, + 0.713990330696106f, + 0.712158203125f, + 0.7103239893913269f, + 0.7085238099098206f, + 0.7066835165023804f, + 0.7048863768577576f, + 0.703105628490448f, + 0.7013306617736816f, + 0.6995511651039124f, + 0.6977716684341431f, + 0.6960317492485046f, + 0.6942790746688843f, + 0.6925272941589355f, + 0.6907827854156494f, + 0.689068615436554f, + 0.687347412109375f, + 0.6856591105461121f, + 0.683970034122467f, + 0.682276725769043f, + 0.6805812120437622f, + 0.6789281964302063f, + 0.6772623658180237f, + 0.6756013631820679f, + 0.6739364862442017f, + 0.6722993850708008f, + 0.6706674098968506f, + 0.6690364480018616f, + 0.6674287915229797f, + 0.6658235192298889f, + 0.6642293334007263f, + 0.6626189351081848f, + 0.6610497236251831f, + 0.6594691276550293f, + 0.6578971147537231f, + 0.656342625617981f, + 0.6547721028327942f, + 0.6532281041145325f, + 0.6517037749290466f, + 0.6501580476760864f, + 0.6486419439315796f, + 0.6471200585365295f, + 0.6455984711647034f, + 0.6440840363502502f, + 0.6425923109054565f, + 0.6411044597625732f, + 0.6396147012710571f, + 0.6381545066833496f, + 0.6366636753082275f, + 0.6352079510688782f, + 0.6337451338768005f, + 0.6323150396347046f, + 0.6308498382568359f, + 0.6294164061546326f, + 0.6279890537261963f, + 0.6265745759010315f, + 0.6251498460769653f, + 0.6237500905990601f, + 0.6223452091217041f, + 0.6209344267845154f, + 0.6195322275161743f, + 0.6181548833847046f, + 0.6167780756950378f, + 0.6154120564460754f, + 0.6140302419662476f, + 0.6126852035522461f, + 0.6113117337226868f, + 0.6099634766578674f, + 0.6086242198944092f, + 0.6072999835014343f, + 0.6059572696685791f, + 0.6046338677406311f, + 0.6033122539520264f, + 0.6020045876502991f, + 0.6006863713264465f, + 0.5994002223014832f, + 0.5980745553970337f, + 0.5967887043952942f, + 0.5955021977424622f, + 0.5942328572273254f, + 0.5929514765739441f, + 0.5916818976402283f, + 0.5904273390769958f, + 0.5891685485839844f, + 0.5879052877426147f, + 0.5866508483886719f, + 0.5854105949401855f, + 0.5841827392578125f, + 0.5829448103904724f, + 0.5817262530326843f, + 0.5804857015609741f, + 0.5792888402938843f, + 0.5780552625656128f, + 0.5768483877182007f, + 0.5756462216377258f, + 0.5744789242744446f, + 0.5732737183570862f, + 0.5720958113670349f, + 0.5708903074264526f, + 0.5697146058082581f, + 0.5685422420501709f, + 0.5673736333847046f, + 0.5662209391593933f, + 0.5650529861450195f, + 0.5639082789421082f, + 0.5627579092979431f, + 0.5616170167922974f, + 0.5604658722877502f, + 0.5593448281288147f, + 0.558205246925354f, + 0.5570909976959229f, + 0.5559751987457275f, + 0.5548509359359741f, + 0.5537335872650146f, + 0.552649974822998f, + 0.5515282154083252f, + 0.5504438877105713f, + 0.5493456721305847f, + 0.5482402443885803f, + 0.5471789240837097f, + 0.5460887551307678f, + 0.5449970960617065f, + 0.5439370274543762f, + 0.5428534150123596f, + 0.5417964458465576f, + 0.5407297015190125f, + 0.5396756529808044f, + 0.538644552230835f, + 0.5375834703445435f, + 0.5365545749664307f, + 0.5354890823364258f, + 0.5344588160514832f, + 0.53342604637146f, + 0.5324010848999023f, + 0.5313923954963684f, + 0.5303633809089661f, + 0.5293594002723694f, + 0.5283269286155701f, + 0.5273261070251465f, + 0.5263199210166931f, + 0.5253220200538635f, + 0.5243186950683594f, + 0.5233476758003235f, + 0.5223479866981506f, + 0.5213702917098999f, + 0.5203649401664734f, + 0.5193970799446106f, + 0.5184254050254822f, + 0.5174447298049927f, + 0.516491711139679f, + 0.5155284404754639f, + 0.514551043510437f, + 0.5136093497276306f, + 0.5126588344573975f, + 0.5117171406745911f, + 0.5107676386833191f, + 0.5098287463188171f, + 0.5088873505592346f, + 0.5079407095909119f, + 0.5070165395736694f, + 0.5060779452323914f, + 0.5051640868186951f, + 0.5042357444763184f, + 0.503326952457428f, + 0.5024080872535706f, + 0.5014938712120056f, + 0.5005781054496765f, + 0.49968376755714417f, + 0.49877265095710754f, + 0.4978860020637512f, + 0.49696969985961914f, + 0.4960835874080658f, + 0.49519139528274536f, + 0.4943094551563263f, + 0.4934454560279846f, + 0.4925616383552551f, + 0.4916682839393616f, + 0.4908157289028168f, + 0.4899247884750366f, + 0.4890671372413635f, + 0.48820558190345764f, + 0.48733872175216675f, + 0.4864858090877533f, + 0.48562294244766235f, + 0.4847657382488251f, + 0.4839414954185486f, + 0.4830806255340576f, + 0.4822426438331604f, + 0.48139166831970215f, + 0.480558305978775f, + 0.47972649335861206f, + 0.4788912832736969f, + 0.4780619144439697f, + 0.47723937034606934f, + 0.47642940282821655f, + 0.4756017029285431f, + 0.47477471828460693f, + 0.4739650785923004f, + 0.4731660485267639f, + 0.4723406136035919f, + 0.4715345501899719f, + 0.47073766589164734f, + 0.4699311852455139f, + 0.46913012862205505f, + 0.4683624804019928f, + 0.46754929423332214f, + 0.46675416827201843f, + 0.4659850001335144f, + 0.4651834964752197f, + 0.4644103944301605f, + 0.46363675594329834f, + 0.46285971999168396f, + 0.4620875120162964f, + 0.4613165557384491f, + 0.4605373442173004f + }; + } +} \ No newline at end of file diff --git a/Runtime/Animation/Smoothing/FrameSmoothingTableGenerator.cs b/Runtime/Animation/Smoothing/FrameSmoothingTableGenerator.cs new file mode 100644 index 0000000..5f7a0ff --- /dev/null +++ b/Runtime/Animation/Smoothing/FrameSmoothingTableGenerator.cs @@ -0,0 +1,30 @@ +using System.Collections; +using System.Collections.Generic; +using Godot; + +namespace Rokojori +{ + [Tool] + [GlobalClass] + public partial class FrameSmoothingTableGenerator:Node + { + [Export] + public string path; + + [Export] + public bool compute + { + get { return false; } + set + { + if ( ! value ) + { + return; + } + + FrameSmoothingTable.ComputeAndSaveTable( path ); + } + } + + } +} \ No newline at end of file diff --git a/Runtime/Animation/Smoothing/Smoothing.cs b/Runtime/Animation/Smoothing/Smoothing.cs index 36f02b8..f04a69a 100644 --- a/Runtime/Animation/Smoothing/Smoothing.cs +++ b/Runtime/Animation/Smoothing/Smoothing.cs @@ -4,8 +4,6 @@ using Godot; namespace Rokojori { - [Tool] - [GlobalClass] public partial class Smoothing: Resource { float _currentFloat = 0; @@ -99,7 +97,7 @@ namespace Rokojori return 0; } - public virtual float ComputeDuration( float delta = 1f/240f, float tresholdValue = 0.05f ) + public virtual float ComputeDuration( float delta = 1f/480f, float tresholdValue = 0.01f ) { var cached = _currentFloat; diff --git a/Runtime/Audio/MathAudio.cs b/Runtime/Audio/MathAudio.cs index b9a4eec..4870f1e 100644 --- a/Runtime/Audio/MathAudio.cs +++ b/Runtime/Audio/MathAudio.cs @@ -111,5 +111,23 @@ namespace Rokojori return samples * OneSampleToBeats( bpm, sampleRate ); } + + public static float GetNextLoopPosition( float position, float loopDuration, float loopOffset ) + { + position -= loopOffset; + + position = Mathf.CeilToInt( position / loopDuration ) * loopDuration; + + return position + loopOffset; + } + + public static float GetPreviousLoopPosition( float position, float loopDuration, float loopOffset ) + { + position -= loopOffset; + + position = Mathf.FloorToInt( position / loopDuration ) * loopDuration; + + return position + loopOffset; + } } } \ No newline at end of file diff --git a/Runtime/Time/TimeLineEvent.cs b/Runtime/Time/TimeLineEvent.cs index c672edf..c1be354 100644 --- a/Runtime/Time/TimeLineEvent.cs +++ b/Runtime/Time/TimeLineEvent.cs @@ -14,5 +14,19 @@ namespace Rokojori public bool persistent; public float position; public bool wasInside = false; + public bool looping = false; + public float loopDuration = 0; + + + public float GetNextLoopPosition( float timelinePosition ) + { + return MathAudio.GetNextLoopPosition( timelinePosition, loopDuration, position ); + } + + public float GetPreviousLoopPosition( float timelinePosition ) + { + return MathAudio.GetPreviousLoopPosition( timelinePosition, loopDuration, position ); + } + } } \ No newline at end of file diff --git a/Runtime/Time/TimeLineManager.cs b/Runtime/Time/TimeLineManager.cs index 9e324ac..c863cf7 100644 --- a/Runtime/Time/TimeLineManager.cs +++ b/Runtime/Time/TimeLineManager.cs @@ -163,9 +163,6 @@ namespace Rokojori var normalized = MathX.Normalize( time, start, end ); return normalized; } - - - public void ScheduleEvent( int timeLineIndex, float position, int callbackID, bool isPersistent ) { @@ -173,6 +170,19 @@ namespace Rokojori runner.ScheduleEvent( position, callbackID, isPersistent ); } + public void ScheduleLoopEvent( int timeLineIndex, float loopDuration, float loopOffset, int callbackID, bool isPersistent ) + { + var runner = _runners[ timeLineIndex ]; + runner.ScheduleLoopEvent( loopDuration, loopOffset, callbackID, isPersistent ); + } + + public void RemoveEvent( int timeLineIndex, int eventID ) + { + var runner = _runners[ timeLineIndex ]; + runner.RemoveEvent( eventID ); + } + + public void ScheduleSpan( int timeLineIndex, float start, float end, int callbackID, bool isPersistent ) { var runner = _runners[ timeLineIndex ]; diff --git a/Runtime/Time/TimeLineRunner.cs b/Runtime/Time/TimeLineRunner.cs index f1e1bb1..702c2b1 100644 --- a/Runtime/Time/TimeLineRunner.cs +++ b/Runtime/Time/TimeLineRunner.cs @@ -120,6 +120,13 @@ namespace Rokojori void ProcessForward( TimeLineManager manager ) { + if ( requestedRemovals.Count > 0 ) + { + requestedRemovals.Sort(); + Lists.RemoveIncreasingSortedIndices( events, requestedRemovals ); + requestedRemovals.Clear(); + } + List eventRemovals = null; List spanRemovals = null; @@ -129,10 +136,20 @@ namespace Rokojori for ( int i = 0; i < events.Count; i++ ) { var eventPosition = events[ i ].position; + + if ( events[ i ].looping ) + { + var next = events[ i ].GetNextLoopPosition( lastPosition ); + var previous = events[ i ].GetPreviousLoopPosition( position ); - // 0 1 2 3 4 5 - // Last 3, Position 4 - // + if ( next != previous ) + { + continue; + } + + eventPosition = next; + } + if ( ! RangeDouble.ContainsExclusiveMax( lastPosition, position, eventPosition ) ) { if ( events[ i ].wasInside ) @@ -148,6 +165,13 @@ namespace Rokojori "now:", position, "event:", eventPosition ); + + + + // 0 1 2 3 4 5 + // Last 3, Position 4 + // + // manager.EmitSignal( TimeLineManager.SignalName.OnEvent, events[ i ].id ); manager.onEvent.DispatchEvent( events[ i ].id ); @@ -222,6 +246,14 @@ namespace Rokojori } } + List requestedRemovals = new List(); + + public void RemoveEvent( int eventID ) + { + requestedRemovals.Add( eventID ); + } + + public void ScheduleEvent( float position, int callbackID, bool isPersistent ) { var tle = new TimeLineEvent(); @@ -232,6 +264,18 @@ namespace Rokojori events.Add( tle ); } + public void ScheduleLoopEvent( float loopDuration, float loopOffset, int callbackID, bool isPersistent ) + { + var tle = new TimeLineEvent(); + tle.position = loopOffset; + tle.looping = true; + tle.loopDuration = loopDuration; + tle.id = callbackID; + tle.persistent = isPersistent; + + events.Add( tle ); + } + public void ScheduleSpan( float start, float end, int callbackID, bool isPersistent ) { var tse = new TimeLineSpan(); diff --git a/Runtime/Time/TimeLineScheduler.cs b/Runtime/Time/TimeLineScheduler.cs index b42d72b..41b920c 100644 --- a/Runtime/Time/TimeLineScheduler.cs +++ b/Runtime/Time/TimeLineScheduler.cs @@ -17,14 +17,21 @@ namespace Rokojori return scheduler._ScheduleEventIn( timeLine, offset, action, persistent ); } + int _ScheduleEventIn( TimeLine timeLine, float offset, Action action, bool persistent = false ) + { + var tm = Unique.Get(); + var tIndex = tm.GetTimeLineIndex( timeLine ); + var position = tm.GetPosition( tIndex ) + offset; + return _ScheduleEventAt( timeLine, position, action, persistent ); + } + + public static int ScheduleEventAt( TimeLine timeLine, float position, Action action, bool persistent = false ) { var scheduler = Unique.Get(); return scheduler._ScheduleEventAt( timeLine, position, action, persistent ); } - - int _ScheduleEventAt( TimeLine timeLine, float position, Action action, bool persistent = false ) { AttachListeners(); @@ -36,12 +43,28 @@ namespace Rokojori return id; } - int _ScheduleEventIn( TimeLine timeLine, float offset, Action action, bool persistent = false ) + public static int ScheduleLoopEvent( TimeLine timeLine, float loopDuration, float loopOffset, Action action, bool persistent = false ) + { + var scheduler = Unique.Get(); + return scheduler._ScheduleLoopEvent( timeLine, loopDuration, loopOffset, action, persistent ); + } + + int _ScheduleLoopEvent( TimeLine timeLine, float loopDuration, float loopOffset, Action action, bool persistent = false ) + { + AttachListeners(); + var tm = Unique.Get(); + var tIndex = tm.GetTimeLineIndex( timeLine ); + var id = tm.CreateID(); + _eventActions[ id ] = action; + tm.ScheduleLoopEvent( tIndex, loopDuration, loopOffset, id, persistent ); + return id; + } + + public static void RemoveEvent( TimeLine timeLine, int id ) { var tm = Unique.Get(); var tIndex = tm.GetTimeLineIndex( timeLine ); - var position = tm.GetPosition( tIndex ) + offset; - return _ScheduleEventAt( timeLine, position, action, persistent ); + tm.RemoveEvent( tIndex, id ); } diff --git a/Runtime/Tools/Lists.cs b/Runtime/Tools/Lists.cs index eb9022c..b95c5b7 100644 --- a/Runtime/Tools/Lists.cs +++ b/Runtime/Tools/Lists.cs @@ -8,8 +8,9 @@ namespace Rokojori { - public class Lists + public static class Lists { + public static void Sort( List data, Func getValue ) { ValueSorter.SortList( data, getValue ); @@ -303,6 +304,11 @@ namespace Rokojori } + /*public static string Join( this List list, string seperator = "," ) + { + var sb = new StringBuilder(); + }*/ + public static string Join( List array, string seperator = ", " ) {