Skip to content

Commit bc40f27

Browse files
committed
Core: Add core_time_now() and core_time_since_start()
1 parent b1a7bd0 commit bc40f27

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

Libraries/Core/Time.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,17 @@ f64 time(void)
1212
}
1313

1414
}
15+
16+
C_API f64 core_time_now()
17+
{
18+
return Core::time();
19+
}
20+
21+
C_API f64 core_time_since_start()
22+
{
23+
static f64 start;
24+
if (start == 0.0) {
25+
start = core_time_now();
26+
}
27+
return core_time_now() - start;
28+
}

Libraries/Core/Time.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ auto benchmark(F callback)
3333
}
3434

3535
}
36+
37+
C_API f64 core_time_now();
38+
C_API f64 core_time_since_start();

Tools/shadertoy.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ ErrorOr<int> Main::main(int argc, char const* argv[])
112112
auto ratio = ui_window_pixel_ratio(window);
113113
render_set_resolution(render, size * ratio);
114114

115-
auto begin = Core::time();
116115
while (!ui_window_should_close(window)) {
117116
ui_application_poll_events(app);
118117

@@ -125,8 +124,8 @@ ErrorOr<int> Main::main(int argc, char const* argv[])
125124
else log->warning("could not reload shaders");
126125
}
127126

128-
render_set_time(render, (f32)(Core::time() - begin));
129127
ui_window_gl_make_current_context(window);
128+
render_set_time(render, core_time_since_start());
130129
ui_frame(&context);
131130
render_flush(render);
132131
ui_window_gl_flush(window);

0 commit comments

Comments
 (0)