glfw: add glfw.getTime
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
c0dc10c33a
commit
e2b65c6fb9
1 changed files with 34 additions and 32 deletions
|
@ -10,8 +10,8 @@ const getError = @import("errors.zig").getError;
|
||||||
/// has been set using @ref glfwSetTime it measures time elapsed since GLFW was
|
/// has been set using @ref glfwSetTime it measures time elapsed since GLFW was
|
||||||
/// initialized.
|
/// initialized.
|
||||||
///
|
///
|
||||||
/// This function and @ref glfwSetTime are helper functions on top of @ref
|
/// This function and @ref glfwSetTime are helper functions on top of glfw.getTimerFrequency
|
||||||
/// glfwGetTimerFrequency and @ref glfwGetTimerValue.
|
/// and glfw.getTimerValue.
|
||||||
///
|
///
|
||||||
/// The resolution of the timer is system dependent, but is usually on the order
|
/// The resolution of the timer is system dependent, but is usually on the order
|
||||||
/// of a few micro- or nanoseconds. It uses the highest-resolution monotonic
|
/// of a few micro- or nanoseconds. It uses the highest-resolution monotonic
|
||||||
|
@ -27,9 +27,6 @@ const getError = @import("errors.zig").getError;
|
||||||
/// externally synchronized with calls to @ref glfwSetTime.
|
/// externally synchronized with calls to @ref glfwSetTime.
|
||||||
///
|
///
|
||||||
/// see also: time
|
/// see also: time
|
||||||
///
|
|
||||||
///
|
|
||||||
/// @ingroup input
|
|
||||||
pub inline fn getTime() f64 {
|
pub inline fn getTime() f64 {
|
||||||
const time = c.glfwGetTime();
|
const time = c.glfwGetTime();
|
||||||
|
|
||||||
|
@ -41,34 +38,31 @@ pub inline fn getTime() f64 {
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(time):
|
/// Sets the GLFW time.
|
||||||
// /// Sets the GLFW time.
|
///
|
||||||
// ///
|
/// This function sets the current GLFW time, in seconds. The value must be a positive finite
|
||||||
// /// This function sets the current GLFW time, in seconds. The value must be
|
/// number less than or equal to 18446744073.0, which is approximately 584.5 years.
|
||||||
// /// a positive finite number less than or equal to 18446744073.0, which is
|
///
|
||||||
// /// approximately 584.5 years.
|
/// This function and @ref glfwGetTime are helper functions on top of glfw.getTimerFrequency and
|
||||||
// ///
|
/// glfw.getTimerValue.
|
||||||
// /// This function and @ref glfwGetTime are helper functions on top of @ref
|
///
|
||||||
// /// glfwGetTimerFrequency and @ref glfwGetTimerValue.
|
/// @param[in] time The new value, in seconds.
|
||||||
// ///
|
///
|
||||||
// /// @param[in] time The new value, in seconds.
|
/// Possible errors include glfw.Error.NotInitialized and glfw.Error.InvalidValue.
|
||||||
// ///
|
///
|
||||||
// /// Possible errors include glfw.Error.NotInitialized and glfw.Error.InvalidValue.
|
/// The upper limit of GLFW time is calculated as `floor((2^64 - 1) / 10^9)` and is due to
|
||||||
// ///
|
/// implementations storing nanoseconds in 64 bits. The limit may be increased in the future.
|
||||||
// /// The upper limit of GLFW time is calculated as
|
///
|
||||||
// /// floor((2<sup>64</sup> - 1) / 10<sup>9</sup>) and is due to implementations
|
/// @thread_safety This function may be called from any thread. Reading and writing of the internal
|
||||||
// /// storing nanoseconds in 64 bits. The limit may be increased in the future.
|
/// base time is not atomic, so it needs to be externally synchronized with calls to glfw.getTime.
|
||||||
// ///
|
///
|
||||||
// /// @thread_safety This function may be called from any thread. Reading and
|
/// see also: time
|
||||||
// /// writing of the internal base time is not atomic, so it needs to be
|
pub inline fn setTime(time: f64) Error!void {
|
||||||
// /// externally synchronized with calls to @ref glfwGetTime.
|
c.glfwSetTime(time);
|
||||||
// ///
|
try getError();
|
||||||
// /// see also: time
|
}
|
||||||
// ///
|
|
||||||
// ///
|
|
||||||
// /// @ingroup input
|
|
||||||
// GLFWAPI void glfwSetTime(double time);
|
|
||||||
|
|
||||||
|
// TODO(time):
|
||||||
// /// Returns the current value of the raw timer.
|
// /// Returns the current value of the raw timer.
|
||||||
// ///
|
// ///
|
||||||
// /// This function returns the current value of the raw timer, measured in
|
// /// This function returns the current value of the raw timer, measured in
|
||||||
|
@ -112,3 +106,11 @@ test "getTime" {
|
||||||
|
|
||||||
_ = getTime();
|
_ = getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "getTime" {
|
||||||
|
const glfw = @import("main.zig");
|
||||||
|
try glfw.init();
|
||||||
|
defer glfw.terminate();
|
||||||
|
|
||||||
|
_ = getTime();
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue