aboutsummaryrefslogtreecommitdiff
path: root/src/sfml/system/Clock.zig
diff options
context:
space:
mode:
authortslil clingman <>2021-10-30 16:54:03 -0400
committertslil clingman <>2021-10-30 16:56:41 -0400
commit6ead90c0f0e9b9a44c7c1f7137f437faa29fa750 (patch)
tree38cbaff4f606689a149865d5708dadac47ee43db /src/sfml/system/Clock.zig
parent48dee0817f5fe8c09a085f0150e0c6b4a699ab7c (diff)
Switched to tracking zig-sfml-wrapper as submodule
Diffstat (limited to 'src/sfml/system/Clock.zig')
-rw-r--r--src/sfml/system/Clock.zig59
1 files changed, 0 insertions, 59 deletions
diff --git a/src/sfml/system/Clock.zig b/src/sfml/system/Clock.zig
deleted file mode 100644
index 74b73ab..0000000
--- a/src/sfml/system/Clock.zig
+++ /dev/null
@@ -1,59 +0,0 @@
-//! Utility class that measures the elapsed time.
-
-const sf = struct {
- pub usingnamespace @import("../sfml.zig");
- pub usingnamespace sf.system;
- pub usingnamespace sf.graphics;
-};
-
-const Clock = @This();
-
-// Constructor/destructor
-
-/// Inits a clock. The clock will have its time set at 0 at this point, and automatically starts
-/// Std.time timer also is a good alternative
-pub fn create() !Clock {
- var clock = sf.c.sfClock_create();
- if (clock == null)
- return sf.Error.nullptrUnknownReason;
-
- return Clock{ ._ptr = clock.? };
-}
-
-/// Destroys this clock
-pub fn destroy(self: *Clock) void {
- sf.c.sfClock_destroy(self._ptr);
-}
-
-// Clock control
-/// Gets the elapsed seconds
-pub fn getElapsedTime(self: Clock) sf.Time {
- var time = sf.c.sfClock_getElapsedTime(self._ptr).microseconds;
- return sf.Time{ .us = time };
-}
-
-/// Gets the elapsed seconds and restarts the timer
-pub fn restart(self: *Clock) sf.Time {
- var time = sf.c.sfClock_restart(self._ptr).microseconds;
- return sf.Time{ .us = time };
-}
-
-/// Pointer to the csfml structure
-_ptr: *sf.c.sfClock,
-
-test "clock: sleep test" {
- const tst = @import("std").testing;
-
- // This tests just sleeps and check what the timer measured (not very accurate but eh)
- var clk = try Clock.create();
- defer clk.destroy();
-
- sf.Time.milliseconds(500).sleep();
-
- try tst.expectApproxEqAbs(@as(f32, 0.5), clk.getElapsedTime().asSeconds(), 0.1);
-
- sf.Time.sleep(sf.Time.seconds(0.2));
-
- try tst.expectApproxEqAbs(@as(f32, 0.7), clk.restart().asSeconds(), 0.1);
- try tst.expectApproxEqAbs(@as(f32, 0), clk.getElapsedTime().asSeconds(), 0.01);
-}