glfw: force init in time.zig
This commit is contained in:
parent
1c33e85af3
commit
4e22d5811e
1 changed files with 15 additions and 20 deletions
|
|
@ -4,6 +4,8 @@ const c = @import("c.zig").c;
|
||||||
const Error = @import("errors.zig").Error;
|
const Error = @import("errors.zig").Error;
|
||||||
const getError = @import("errors.zig").getError;
|
const getError = @import("errors.zig").getError;
|
||||||
|
|
||||||
|
const internal_debug = @import("internal_debug.zig");
|
||||||
|
|
||||||
/// Returns the GLFW time.
|
/// Returns the GLFW time.
|
||||||
///
|
///
|
||||||
/// This function returns the current GLFW time, in seconds. Unless the time
|
/// This function returns the current GLFW time, in seconds. Unless the time
|
||||||
|
|
@ -26,13 +28,9 @@ const getError = @import("errors.zig").getError;
|
||||||
///
|
///
|
||||||
/// see also: time
|
/// see also: time
|
||||||
pub inline fn getTime() f64 {
|
pub inline fn getTime() f64 {
|
||||||
|
internal_debug.assertInitialized();
|
||||||
const time = c.glfwGetTime();
|
const time = c.glfwGetTime();
|
||||||
|
getError() catch unreachable; // Only error 'GLFW_NOT_INITIALIZED' is impossible
|
||||||
// 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 time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -55,9 +53,14 @@ pub inline fn getTime() f64 {
|
||||||
/// base time is not atomic, so it needs to be externally synchronized with calls to glfw.getTime.
|
/// base time is not atomic, so it needs to be externally synchronized with calls to glfw.getTime.
|
||||||
///
|
///
|
||||||
/// see also: time
|
/// see also: time
|
||||||
pub inline fn setTime(time: f64) Error!void {
|
pub inline fn setTime(time: f64) error{ InvalidValue }!void {
|
||||||
|
internal_debug.assertInitialized();
|
||||||
c.glfwSetTime(time);
|
c.glfwSetTime(time);
|
||||||
try getError();
|
getError() catch |err| return switch (err) {
|
||||||
|
// TODO: Consider whether to use GLFW error handling, or assert that 'time' is a valid value
|
||||||
|
Error.InvalidValue => err,
|
||||||
|
else => unreachable,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the current value of the raw timer.
|
/// Returns the current value of the raw timer.
|
||||||
|
|
@ -71,13 +74,9 @@ pub inline fn setTime(time: f64) Error!void {
|
||||||
///
|
///
|
||||||
/// see also: time, glfw.getTimerFrequency
|
/// see also: time, glfw.getTimerFrequency
|
||||||
pub inline fn getTimerValue() u64 {
|
pub inline fn getTimerValue() u64 {
|
||||||
|
internal_debug.assertInitialized();
|
||||||
const value = c.glfwGetTimerValue();
|
const value = c.glfwGetTimerValue();
|
||||||
|
getError() catch unreachable; // Only error 'GLFW_NOT_INITIALIZED' is impossible
|
||||||
// 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;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -91,13 +90,9 @@ pub inline fn getTimerValue() u64 {
|
||||||
///
|
///
|
||||||
/// see also: time, glfw.getTimerValue
|
/// see also: time, glfw.getTimerValue
|
||||||
pub inline fn getTimerFrequency() u64 {
|
pub inline fn getTimerFrequency() u64 {
|
||||||
|
internal_debug.assertInitialized();
|
||||||
const frequency = c.glfwGetTimerFrequency();
|
const frequency = c.glfwGetTimerFrequency();
|
||||||
|
getError() catch unreachable; // Only error 'GLFW_NOT_INITIALIZED' is impossible
|
||||||
// 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 frequency;
|
return frequency;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue