Skip to content

Commit

Permalink
Add FDuration<PeriodT>.
Browse files Browse the repository at this point in the history
  • Loading branch information
karnkaul committed Aug 24, 2023
1 parent 815aa97 commit 1da391a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
6 changes: 5 additions & 1 deletion engine/include/le/core/time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ using namespace std::chrono_literals;

namespace le {
using Clock = std::chrono::steady_clock;
using Duration = std::chrono::duration<float>;

template <typename PeriodT = std::ratio<1, 1>>
using FDuration = std::chrono::duration<float, PeriodT>;

using Duration = FDuration<>;

///
/// \brief Stateful delta-time computer.
Expand Down
3 changes: 2 additions & 1 deletion engine/include/le/resources/resources.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include <le/core/mono_instance.hpp>
#include <le/core/ptr.hpp>
#include <le/core/time.hpp>
#include <le/error.hpp>
#include <le/resources/asset.hpp>
#include <le/vfs/uri.hpp>
Expand Down Expand Up @@ -53,7 +54,7 @@ class Resources : public MonoInstance<Resources> {
template <std::derived_from<Asset> Type>
[[nodiscard]] static auto is_ready(std::future<Ptr<Type>> const& future) -> bool {
if (!future.valid()) { return false; }
return future.wait_for(std::chrono::seconds{}) == std::future_status::ready;
return future.wait_for(0s) == std::future_status::ready;
}

auto clear() -> void;
Expand Down
6 changes: 3 additions & 3 deletions engine/src/imcpp/engine_stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ auto EngineStats::draw_to(OpenWindow /*w*/) -> void {
auto const& stats = engine.get_stats();

m_frame_times.data.resize(static_cast<std::size_t>(frame_samples));
m_frame_times.update_offset() = std::chrono::duration<float, std::milli>{stats.frame.time}.count();
m_frame_times.update_offset() = FDuration<std::milli>{stats.frame.time}.count();
m_frame_times.advance();

ImGui::Text("%s", FixedString{"GPU: {}", stats.gpu_name}.c_str());
Expand All @@ -46,8 +46,8 @@ auto EngineStats::draw_to(OpenWindow /*w*/) -> void {
if (auto tn = TreeNode{"frame"}) {
ImGui::Text("%s", FixedString{"count: {}", stats.frame.count}.c_str());
ImGui::Text("%s", FixedString{"draw calls: {}", stats.frame.draw_calls}.c_str());
auto min_ft = std::chrono::duration<float, std::milli>{engine.min_frame_time}.count();
if (ImGui::DragFloat("min frame time", &min_ft, 1.0f, 0.0f, 100.0f)) { engine.min_frame_time = std::chrono::duration<float, std::milli>{min_ft}; }
auto min_ft = FDuration<std::milli>{engine.min_frame_time}.count();
if (ImGui::DragFloat("min frame time", &min_ft, 1.0f, 0.0f, 100.0f)) { engine.min_frame_time = FDuration<std::milli>{min_ft}; }
ImGui::DragInt("samples", &frame_samples, 5.0f, 5, 1000);
auto const overlay_text = FixedString{"{:.1f}ms", m_frame_times.get_current()};
ImGui::PlotLines("time", m_frame_times.data.data(), static_cast<int>(m_frame_times.data.size()), static_cast<int>(m_frame_times.offset),
Expand Down
2 changes: 1 addition & 1 deletion engine/src/resources/resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ auto Resources::try_load(Uri const& uri, Asset& out) -> bool {
g_log.error("failed to load {}: '{}'", out.type_name(), uri.value());
return false;
}
auto const dt = std::chrono::duration<float, std::milli>{delta_time()};
auto const dt = FDuration<std::milli>{delta_time()};
g_log.info("[{:.1f}ms] '{}' {} loaded", dt.count(), uri.value(), out.type_name());
return true;
}
Expand Down

0 comments on commit 1da391a

Please sign in to comment.