-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/guillaumeblanc/flip
- Loading branch information
Showing
19 changed files
with
128 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,4 +77,4 @@ class SgAsyncImage { | |
AsyncBuffer buffer_; | ||
}; | ||
|
||
} // namespace flip | ||
} // namespace flip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#pragma once | ||
|
||
namespace flip { | ||
|
||
struct Time { | ||
float elapsed; | ||
float dt; | ||
float inv_dt; | ||
}; | ||
|
||
class TimeControl { | ||
public: | ||
Time Update(float _dt); | ||
|
||
bool Gui(); | ||
|
||
private: | ||
// Current time, including scaling and freezes.. | ||
float elapsed_ = 0.f; | ||
|
||
// Update time scale factor. | ||
float scale_ = 1; | ||
|
||
// Update time freeze state. | ||
bool freeze_ = false; | ||
|
||
// Fixed update rate, only applies to application update dt, not the real fps. | ||
const float kFixedRateDefault = 60.f; | ||
float fixed_rate_ = kFixedRateDefault; | ||
|
||
// Fixes update rat to a fixed value, instead of real_time. | ||
bool fix_rate_ = false; | ||
}; | ||
|
||
} // namespace flip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include "flip/utils/time.h" | ||
|
||
#include "imgui/imgui.h" | ||
|
||
namespace flip { | ||
|
||
Time TimeControl::Update(float _dt) { | ||
auto dt = 0.f; | ||
if (!freeze_) { | ||
if (fix_rate_) { | ||
dt = scale_ / fixed_rate_; | ||
} else { | ||
dt = _dt * scale_; | ||
} | ||
} | ||
elapsed_ += dt; | ||
|
||
return {elapsed_, dt, dt == 0.f ? 0.f : (1.f / dt)}; | ||
} | ||
|
||
bool TimeControl::Gui() { | ||
ImGui::Checkbox("Freeze", &freeze_); | ||
ImGui::SameLine(); | ||
ImGui::Checkbox("Fix update rate", &fix_rate_); | ||
if (ImGui::Button("Reset")) { | ||
fixed_rate_ = kFixedRateDefault; | ||
scale_ = 1.f; | ||
} | ||
ImGui::SameLine(); | ||
if (fix_rate_) { | ||
ImGui::SliderFloat("Update rate", &fixed_rate_, 1.f, 200.f, "%.2f fps"); | ||
} else { | ||
ImGui::SliderFloat("Time scale", &scale_, -10.f, 10.f, "%.2f", | ||
ImGuiSliderFlags_Logarithmic); | ||
} | ||
return true; | ||
} | ||
|
||
} // namespace flip |