29 lines
672 B
C++
29 lines
672 B
C++
#include "core/Frame.hpp"
|
|
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
|
|
namespace tahgibu {
|
|
|
|
float Frame::clampFps(float fps) noexcept {
|
|
if (!std::isfinite(fps)) {
|
|
return kDefaultFps;
|
|
}
|
|
return std::clamp(fps, kMinFps, kMaxFps);
|
|
}
|
|
|
|
void Frame::setFpsOverride(float fps) noexcept {
|
|
fpsOverride_ = clampFps(fps);
|
|
}
|
|
|
|
float Frame::effectiveFps(float baseFps) const noexcept {
|
|
return fpsOverride_ ? *fpsOverride_ : clampFps(baseFps);
|
|
}
|
|
|
|
double Frame::durationSeconds(float baseFps) const noexcept {
|
|
// effectiveFps() >= kMinFps, así que nunca se divide por cero.
|
|
return 1.0 / static_cast<double>(effectiveFps(baseFps));
|
|
}
|
|
|
|
} // namespace tahgibu
|