glfw: add glfw.getTimerValue

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2021-10-16 17:48:54 -07:00 committed by Stephen Gutekanst
parent 3c7117381f
commit 14c88e8db0

View file

@ -30,7 +30,7 @@ const getError = @import("errors.zig").getError;
pub inline fn getTime() f64 { pub inline fn getTime() f64 {
const time = c.glfwGetTime(); const time = c.glfwGetTime();
// The only error shouldClose could return would be glfw.Error.NotInitialized, which should // The only error this could return would be glfw.Error.NotInitialized, which should
// definitely have occurred before calls to this. Returning an error here makes the API // definitely have occurred before calls to this. Returning an error here makes the API
// awkward to use, so we discard it instead. // awkward to use, so we discard it instead.
getError() catch {}; getError() catch {};
@ -62,26 +62,30 @@ pub inline fn setTime(time: f64) Error!void {
try getError(); try getError();
} }
// 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 `1/frequency` seconds. To
// /// This function returns the current value of the raw timer, measured in /// get the frequency, call glfw.getTimerFrequency.
// /// 1&nbsp;/&nbsp;frequency seconds. To get the frequency, call @ref ///
// /// glfwGetTimerFrequency. /// @return The value of the timer, or zero if an error occurred.
// /// ///
// /// @return The value of the timer, or zero if an /// Possible errors include glfw.Error.NotInitialized.
// /// error occurred. ///
// /// /// @thread_safety This function may be called from any thread.
// /// Possible errors include glfw.Error.NotInitialized. ///
// /// /// see also: time, glfw.getTimerFrequency
// /// @thread_safety This function may be called from any thread. pub inline fn getTimerValue() u64 {
// /// const value = c.glfwGetTimerValue();
// /// see also: time, glfwGetTimerFrequency
// ///
// ///
// /// @ingroup input
// GLFWAPI uint64_t glfwGetTimerValue(void);
// The only error this could return would be glfw.Error.NotInitialized, which should
// definitely have occurred before calls to this. Returning an error here makes the API
// awkward to use, so we discard it instead.
getError() catch {};
return value;
}
// TODO(time):
// /// Returns the frequency, in Hz, of the raw timer. // /// Returns the frequency, in Hz, of the raw timer.
// /// // ///
// /// This function returns the frequency, in Hz, of the raw timer. // /// This function returns the frequency, in Hz, of the raw timer.
@ -107,10 +111,18 @@ test "getTime" {
_ = getTime(); _ = getTime();
} }
test "getTime" { test "setTime" {
const glfw = @import("main.zig"); const glfw = @import("main.zig");
try glfw.init(); try glfw.init();
defer glfw.terminate(); defer glfw.terminate();
_ = getTime(); _ = try glfw.setTime(1234);
}
test "getTimerValue" {
const glfw = @import("main.zig");
try glfw.init();
defer glfw.terminate();
_ = glfw.getTimerValue();
} }