@@ -29,6 +29,27 @@ class FunscriptSpline
2929 return glm::catmullRom (v0, v1, v2, v3, time).x ;
3030 }
3131
32+ static inline float catmul_rom_spline_alt (const FunscriptArray& actions, int32_t i, float time) noexcept
33+ {
34+ OFS_PROFILE (__FUNCTION__);
35+ int i0 = glm::clamp<int >(i - 1 , 0 , actions.size () - 1 );
36+ int i1 = glm::clamp<int >(i, 0 , actions.size () - 1 );
37+ int i2 = glm::clamp<int >(i + 1 , 0 , actions.size () - 1 );
38+ int i3 = glm::clamp<int >(i + 2 , 0 , actions.size () - 1 );
39+
40+ if (actions[i1].pos == actions[i2].pos ) return actions[i1].pos / 100 .f ;
41+
42+ glm::vec1 v0 (actions[i0].pos / 100 .f );
43+ glm::vec1 v1 (actions[i1].pos / 100 .f );
44+ glm::vec1 v2 (actions[i2].pos / 100 .f );
45+ glm::vec1 v3 (actions[i3].pos / 100 .f );
46+
47+ time -= actions[i1].atS ;
48+ time /= actions[i2].atS - actions[i1].atS ;
49+
50+ return glm::catmullRom (v0, v1, v2, v3, time).x ;
51+ }
52+
3253 inline float Sample (const FunscriptArray& actions, float time) noexcept
3354 {
3455 OFS_PROFILE (__FUNCTION__);
@@ -38,12 +59,12 @@ class FunscriptSpline
3859
3960 if (actions[cacheIdx].atS <= time && actions[cacheIdx + 1 ].atS >= time) {
4061 // cache hit!
41- return catmull_rom_spline (actions, cacheIdx, time);
62+ return catmul_rom_spline_alt (actions, cacheIdx, time);
4263 }
4364 else if (cacheIdx + 2 < actions.size () && actions[cacheIdx+1 ].atS <= time && actions[cacheIdx+2 ].atS >= time) {
4465 // sort of a cache hit
4566 cacheIdx += 1 ;
46- return catmull_rom_spline (actions, cacheIdx, time);
67+ return catmul_rom_spline_alt (actions, cacheIdx, time);
4768 }
4869 else {
4970 // cache miss
@@ -59,7 +80,7 @@ class FunscriptSpline
5980 it--;
6081 // cache index
6182 cacheIdx = std::distance (actions.begin (), it);
62- return catmull_rom_spline (actions, cacheIdx, time);
83+ return catmul_rom_spline_alt (actions, cacheIdx, time);
6384 }
6485
6586 return 0 .f ;
0 commit comments