Skip to content

Commit

Permalink
[共通] Timer の残り時間(秒)を切り上げて取得する Timer::s_ceil() #1233
Browse files Browse the repository at this point in the history
  • Loading branch information
Reputeless committed Jun 12, 2024
1 parent f10b18a commit 0c576d4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Siv3D/include/Siv3D/Timer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,18 @@ namespace s3d
[[nodiscard]]
double usF() const;

/// @brief 残り時間を [秒] で返します。小数点以下は切り上げられます。
/// @remark 例えば、残り 2.1 秒の場合は 3 を返します
/// @return 残り時間 [秒]
[[nodiscard]]
int32 s_ceil() const;

/// @brief 残り時間を [秒] で返します。小数点以下は切り上げられます。
/// @remark 例えば、残り 2.1 秒の場合は 3 を返します
/// @return 残り時間 [秒]
[[nodiscard]]
int64 s64_ceil() const;

/// @brief 設定されているカウントダウン時間を返します。
/// @return 設定されているカウントダウン時間
[[nodiscard]]
Expand Down
10 changes: 10 additions & 0 deletions Siv3D/src/Siv3D/Timer/SivTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,16 @@ namespace s3d
return static_cast<double>(us());
}

int32 Timer::s_ceil() const
{
return static_cast<int32>(s64_ceil());
}

int64 Timer::s64_ceil() const
{
return static_cast<int64>(std::ceil(usF() / (1000LL * 1000LL)));
}

Duration Timer::duration() const
{
return SecondsF{ m_durationMicrosec / static_cast<double>(1000LL * 1000LL) };
Expand Down

0 comments on commit 0c576d4

Please sign in to comment.