diff --git a/src/DrawCamera.cpp b/src/DrawCamera.cpp index 2757ff2..092ec2b 100755 --- a/src/DrawCamera.cpp +++ b/src/DrawCamera.cpp @@ -3,6 +3,7 @@ #include "Helpers/FixedPoint.hpp" #include "Helpers/MathExtras.hpp" #include "MainProgram.hpp" +#include "TimePoint.hpp" #include "World.hpp" #include "InputManager.hpp" #include @@ -65,7 +66,7 @@ void DrawCamera::scale_up(World& w, const WorldScalar& scaleUpAmount) { void DrawCamera::update_main(World& w) { if(smoothMove.occurring) { BezierEasing zoomAnim{w.main.conf.jumpTransitionEasing}; - float smoothTime = smooth_two_way_time(smoothMove.moveTime, w.main.deltaTime, true, w.main.conf.jumpTransitionTime); + float smoothTime = smooth_two_way_animation_time_get_lerp(smoothMove.moveTime, w.main.deltaTime, true, w.main.conf.jumpTransitionTime); float lerpTime; float rotationLerpTime = zoomAnim(smoothTime); lerpTime = zoomAnim(smoothTime); diff --git a/src/GUIStuff/Elements/CheckBox.cpp b/src/GUIStuff/Elements/CheckBox.cpp index 3f87057..2bf2456 100644 --- a/src/GUIStuff/Elements/CheckBox.cpp +++ b/src/GUIStuff/Elements/CheckBox.cpp @@ -21,7 +21,7 @@ void CheckBox::layout(const Clay_ElementId& id, const std::function& isT } void CheckBox::update() { - if(smooth_two_way_time(hoverAnimation, gui.io.deltaTime, mouseHovering, CHECKBOX_ANIMATION_TIME)) + if(smooth_two_way_animation_time_check_for_change(hoverAnimation, gui.io.deltaTime, mouseHovering, CHECKBOX_ANIMATION_TIME)) gui.invalidate_draw_element(this); if(oldIsTicked != isTicked()) { gui.invalidate_draw_element(this); diff --git a/src/GUIStuff/Elements/NumberSlider.hpp b/src/GUIStuff/Elements/NumberSlider.hpp index 22e615a..1728713 100644 --- a/src/GUIStuff/Elements/NumberSlider.hpp +++ b/src/GUIStuff/Elements/NumberSlider.hpp @@ -34,8 +34,8 @@ template class NumberSlider : public Element { } virtual void update() { - smooth_two_way_time(dd.holdAnimation, gui.io.deltaTime, dd.isHeld, HOLD_ANIMATION_TIME); - smooth_two_way_time(dd.hoverAnimation, gui.io.deltaTime, mouseHovering, gui.io.theme->hoverExpandTime); + smooth_two_way_animation_time(dd.holdAnimation, gui.io.deltaTime, dd.isHeld, HOLD_ANIMATION_TIME); + smooth_two_way_animation_time(dd.hoverAnimation, gui.io.deltaTime, mouseHovering, gui.io.theme->hoverExpandTime); if(oldDD != dd) { gui.invalidate_draw_element(this, { .top = 10.0f, diff --git a/src/GUIStuff/Elements/RadioButton.cpp b/src/GUIStuff/Elements/RadioButton.cpp index 83ef17d..70327ed 100644 --- a/src/GUIStuff/Elements/RadioButton.cpp +++ b/src/GUIStuff/Elements/RadioButton.cpp @@ -19,7 +19,7 @@ void RadioButton::layout(const Clay_ElementId& id, const std::function& } void RadioButton::update() { - if(smooth_two_way_time(hoverAnimation, gui.io.deltaTime, mouseHovering, RADIOBUTTON_ANIMATION_TIME)) + if(smooth_two_way_animation_time_check_for_change(hoverAnimation, gui.io.deltaTime, mouseHovering, RADIOBUTTON_ANIMATION_TIME)) gui.invalidate_draw_element(this); if(oldIsTicked != isTicked()) { gui.invalidate_draw_element(this); diff --git a/src/MainProgram.cpp b/src/MainProgram.cpp index 66b598f..61f2ec0 100755 --- a/src/MainProgram.cpp +++ b/src/MainProgram.cpp @@ -71,11 +71,11 @@ void MainProgram::update() { while(std::chrono::duration_cast>(std::chrono::steady_clock::now() - lastFrameTime).count() < 1.0 / conf.fpsLimit); lastFrameTime = std::chrono::steady_clock::now(); - input.update(); - deltaTime.update_time_since(); deltaTime.update_time_point(); + input.update(); + g.update(); toolbar.update(); diff --git a/src/TimePoint.cpp b/src/TimePoint.cpp index a60dfa9..390ae8b 100644 --- a/src/TimePoint.cpp +++ b/src/TimePoint.cpp @@ -21,7 +21,7 @@ TimePoint::operator float() const { return get_time_since(); } -bool smooth_two_way_time(float& timeToUpdate, float deltaTime, bool isWay1, float animDuration) { +bool smooth_two_way_animation_time_check_for_change(float& timeToUpdate, float deltaTime, bool isWay1, float animDuration) { float newTimeToUpdate = std::clamp(isWay1 ? (timeToUpdate + deltaTime) : (timeToUpdate - deltaTime), 0.0f, animDuration); if(newTimeToUpdate != timeToUpdate) { timeToUpdate = newTimeToUpdate; @@ -30,6 +30,15 @@ bool smooth_two_way_time(float& timeToUpdate, float deltaTime, bool isWay1, floa return false; } +float smooth_two_way_animation_time_get_lerp(float& timeToUpdate, float deltaTime, bool isWay1, float animDuration) { + timeToUpdate = std::clamp(isWay1 ? (timeToUpdate + deltaTime) : (timeToUpdate - deltaTime), 0.0f, animDuration); + return timeToUpdate / animDuration; +} + +void smooth_two_way_animation_time(float& timeToUpdate, float deltaTime, bool isWay1, float animDuration) { + timeToUpdate = std::clamp(isWay1 ? (timeToUpdate + deltaTime) : (timeToUpdate - deltaTime), 0.0f, animDuration); +} + WorldVec lerp_world_vec_double(const WorldVec& v1, const WorldVec& v2, double t) { return {FixedPoint::lerp_double(v1.x(), v2.x(), t), FixedPoint::lerp_double(v1.y(), v2.y(), t)}; } diff --git a/src/TimePoint.hpp b/src/TimePoint.hpp index e4ca49a..6f2ba95 100644 --- a/src/TimePoint.hpp +++ b/src/TimePoint.hpp @@ -30,7 +30,9 @@ template SkColor4f lerp_vec(const SkColor4f& t1, const SkColo std::lerp(t1[3], t2[3], t)}; } -bool smooth_two_way_time(float& timeToUpdate, float deltaTime, bool isWay1, float animDuration); +bool smooth_two_way_animation_time_check_for_change(float& timeToUpdate, float deltaTime, bool isWay1, float animDuration); +float smooth_two_way_animation_time_get_lerp(float& timeToUpdate, float deltaTime, bool isWay1, float animDuration); +void smooth_two_way_animation_time(float& timeToUpdate, float deltaTime, bool isWay1, float animDuration); class TimePoint { public: