2026-05-11 23:06:39 +03:00
|
|
|
/*
|
|
|
|
|
* InfiniPaint
|
|
|
|
|
* Copyright (C) 2025-2026 Yousef Khadadeh
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2025-07-06 20:43:53 +03:00
|
|
|
#include "TimePoint.hpp"
|
|
|
|
|
|
|
|
|
|
TimePoint::TimePoint():
|
|
|
|
|
tp(std::chrono::steady_clock::now()),
|
|
|
|
|
timeSince(0.0f)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
void TimePoint::update_time_point() {
|
|
|
|
|
tp = std::chrono::steady_clock::now();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TimePoint::update_time_since() {
|
|
|
|
|
timeSince = std::chrono::duration_cast<std::chrono::duration<float>>(std::chrono::steady_clock::now() - tp).count();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float TimePoint::get_time_since() const {
|
|
|
|
|
return timeSince;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TimePoint::operator float() const {
|
|
|
|
|
return get_time_since();
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-09 10:20:40 +03:00
|
|
|
bool smooth_two_way_animation_time_check_for_change(float& timeToUpdate, float deltaTime, bool isWay1, float animDuration) {
|
2026-04-08 17:34:50 +03:00
|
|
|
float newTimeToUpdate = std::clamp(isWay1 ? (timeToUpdate + deltaTime) : (timeToUpdate - deltaTime), 0.0f, animDuration);
|
|
|
|
|
if(newTimeToUpdate != timeToUpdate) {
|
|
|
|
|
timeToUpdate = newTimeToUpdate;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2025-07-06 20:43:53 +03:00
|
|
|
}
|
|
|
|
|
|
2026-04-09 10:20:40 +03:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-06 20:43:53 +03:00
|
|
|
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)};
|
|
|
|
|
}
|