backend-infra-engineer: Release v0.3.3 snapshot
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#define YAZE_APP_CORE_TIMING_H
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace yaze {
|
||||
@@ -9,7 +10,7 @@ namespace yaze {
|
||||
/**
|
||||
* @class TimingManager
|
||||
* @brief Provides accurate timing for animations and frame pacing
|
||||
*
|
||||
*
|
||||
* This class solves the issue where ImGui::GetIO().DeltaTime only updates
|
||||
* when events are processed (mouse movement, etc). It uses SDL's performance
|
||||
* counter to provide accurate timing regardless of input events.
|
||||
@@ -28,18 +29,18 @@ class TimingManager {
|
||||
float Update() {
|
||||
uint64_t current_time = SDL_GetPerformanceCounter();
|
||||
float delta_time = 0.0f;
|
||||
|
||||
|
||||
if (last_time_ > 0) {
|
||||
delta_time = (current_time - last_time_) / static_cast<float>(frequency_);
|
||||
|
||||
|
||||
// Clamp delta time to prevent huge jumps (e.g., when debugging)
|
||||
if (delta_time > 0.1f) {
|
||||
delta_time = 0.1f;
|
||||
}
|
||||
|
||||
|
||||
accumulated_time_ += delta_time;
|
||||
frame_count_++;
|
||||
|
||||
|
||||
// Update FPS counter once per second
|
||||
if (accumulated_time_ >= 1.0f) {
|
||||
fps_ = static_cast<float>(frame_count_) / accumulated_time_;
|
||||
@@ -47,35 +48,32 @@ class TimingManager {
|
||||
accumulated_time_ = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
last_time_ = current_time;
|
||||
last_delta_time_ = delta_time;
|
||||
return delta_time;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get the last frame's delta time in seconds
|
||||
*/
|
||||
float GetDeltaTime() const {
|
||||
return last_delta_time_;
|
||||
}
|
||||
|
||||
float GetDeltaTime() const { return last_delta_time_; }
|
||||
|
||||
/**
|
||||
* @brief Get current FPS
|
||||
*/
|
||||
float GetFPS() const {
|
||||
return fps_;
|
||||
}
|
||||
|
||||
float GetFPS() const { return fps_; }
|
||||
|
||||
/**
|
||||
* @brief Get total elapsed time since first update
|
||||
*/
|
||||
float GetElapsedTime() const {
|
||||
if (last_time_ == 0) return 0.0f;
|
||||
if (last_time_ == 0)
|
||||
return 0.0f;
|
||||
uint64_t current_time = SDL_GetPerformanceCounter();
|
||||
return (current_time - first_time_) / static_cast<float>(frequency_);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Reset the timing state
|
||||
*/
|
||||
@@ -114,4 +112,3 @@ class TimingManager {
|
||||
} // namespace yaze
|
||||
|
||||
#endif // YAZE_APP_CORE_TIMING_H
|
||||
|
||||
|
||||
Reference in New Issue
Block a user