diff options
author | Mitya Selivanov <automainint@guattari.tech> | 2025-02-02 14:38:13 +0100 |
---|---|---|
committer | Mitya Selivanov <automainint@guattari.tech> | 2025-02-02 14:38:13 +0100 |
commit | 27b4343c2a7e2583881485a5ac667894fec729f0 (patch) | |
tree | 018df2c4df87ef39f9c828a1d6e255825ee7ed9b /examples/julia_set.c | |
parent | bc9e6042e709b7790f2f130dde08b13c929653b1 (diff) | |
download | reduced_system_layer-perf.zip |
Refactor, renaming (work in progress)perf
Diffstat (limited to 'examples/julia_set.c')
-rw-r--r-- | examples/julia_set.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/examples/julia_set.c b/examples/julia_set.c index 288dac2..81aa02c 100644 --- a/examples/julia_set.c +++ b/examples/julia_set.c @@ -11,6 +11,13 @@ f64 radius = 2.; i64 limit = 1024; i64 time_0; +void inc_f64(f64 *x, i8 s) { + u64 *u = (u64 *) x; + if (((*u >> 52) & 2047) == 2047) + return; + *u += *x > 0 ? s : -s; +} + void apply_scale(f64 delta) { while (delta > SCALE_LIMIT) { apply_scale(SCALE_LIMIT); @@ -22,21 +29,24 @@ void apply_scale(f64 delta) { } f64 ds = view_s * delta * .1; - if (view_s + ds < 1e-12) + if (view_s + ds <= 0.0) return; f64 dx = (g_platform.cursor_x * 1. - g_platform.real_width * .5); f64 dy = (g_platform.cursor_y * 1. - g_platform.real_height * .5); view_x -= view_s * dx; view_y -= view_s * dy; - view_s += ds; + if (view_s == view_s + ds) + inc_f64(&view_s, ds > 0 ? 1 : -1); + else + view_s += ds; view_x += view_s * dx; view_y += view_s * dy; } void update_and_render_frame(void) { - i32 num_events = p_handle_events(); + i32 num_events = handle_main_window_events(); - i64 time_elapsed = p_time() - time_0; + i64 time_elapsed = current_utc_time_in_milliseconds() - time_0; time_0 += time_elapsed; b8 left = g_platform.key_down[KEY_LEFT]; @@ -45,7 +55,7 @@ void update_and_render_frame(void) { b8 down = g_platform.key_down[KEY_DOWN]; if (!left && !right && !up && !down && num_events == 0) { - p_sleep_for(1); + suspend_thread_for_milliseconds(1); return; } @@ -98,7 +108,7 @@ void update_and_render_frame(void) { g_platform.pixels[j * g_platform.frame_width + i] = vec4_from_vec3_f32(rgb_f32_from_u32(c), 1.f); } - p_render_frame(); + render_main_window_frame(); } i32 main(i32 argc, c8 **argv) { @@ -109,9 +119,9 @@ i32 main(i32 argc, c8 **argv) { .title = "Julia Set", }; - time_0 = p_time(); + time_0 = current_utc_time_in_milliseconds(); - p_event_loop(); + run_main_window_event_loop(); return 0; } |